While using the pysam module I am trying to redirect stdout to a file as follows:
bam=sys.argv[1]
samfile = pysam.AlignmentFile(bam, "rb")
for alignment in samfile:
reverse=isReverse(alignment.flag)
if (reverse):
outfile = pysam.AlignmentFile("-", "w", template=samfile)
with open('reverse.sam', 'w') as f:
with (f):
for s in samfile:
print('HEY')
outfile.write(s)
While the "print('HEY')" is written to reverse.sam the "outfile.write(s)" is not. What should I do so that it is?
Thanks
Mark