I have pretty simple problem. I have a large file that goes through three steps, a decoding step using an external program, some processing in python, and then recoding usi
I was using the .read() method on the stdout stream. Instead, I simply needed to read directly from the stream in the for loop above. The corrected code does what I expected.
#!/usr/bin/env python import os import sys import subprocess def main(infile,reflist): print infile,reflist samtoolsin = subprocess.Popen(["samtools","view",infile], stdout=subprocess.PIPE,bufsize=1) samtoolsout = subprocess.Popen(["samtools","import",reflist,"-", infile+".tmp"],stdin=subprocess.PIPE,bufsize=1) for line in samtoolsin.stdout: if(line.startswith("@")): samtoolsout.stdin.write(line) else: linesplit = line.split("\t") if(linesplit[10]=="*"): linesplit[9]="*" samtoolsout.stdin.write("\t".join(linesplit))