Open robertwhbaldwin opened 10 months ago
By default, pysam.view()
captures the output and returns it as the function's value. So you would see the output with print(pysam.view(…))
.
You can prevent this by adding …, catch_stdout=False
to enable your -o
option to take effect. See also #1096.
At present pysam.samtools.*(…)
and pysam.bcftools.*(…)
are a bit too clever with I/O redirection. In particular, pysam.view()
/pysam.samtools.view()
will add its own -o
output to effect the default redirection, which overrides your -o
option and filename — hence why you need catch_stdout=False
explicitly. In future I plan to change this to use more straightforward descriptor dup(2)
-ing, which will make this more reliable and remove the need for this extra argument.
greetings,
I was using the samtools view command as follows: samtools view -@ 10 -O BAM -o paired.bam -f 1 fixed.bam and it worked fine the output bam is there.
But when I use the same command in pysam: pysam.view("-@",str(threads), "-o", "test2.bam", "-O", "BAM", "-f","1","fixed.bam")
There's no output. Even when I remove the -o there's nothing to the terminal window. This is true even if I change the command to just convert a sam to bam. Running other samtools commands inside pysam like sort and index do work however.