Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running samtools view command produces no output #1241

Closed
robertwhbaldwin opened this issue Oct 30, 2023 · 1 comment
Closed

running samtools view command produces no output #1241

robertwhbaldwin opened this issue Oct 30, 2023 · 1 comment

Comments

@robertwhbaldwin
Copy link

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.

@jmarshall
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants