Question: How to use pysam to execute "samtools fastq xxx.sam>xxx.fastq"
0
gravatar for Zhixue
3 months ago by
Zhixue0
China/Shanghai/TJ
Zhixue0 wrote:

I want to use pysam(a module for reading, manipulating and writing genomic data sets) to get the fastq file from the sam file without samtools as well as shell '>' operation.

I guess the command may be like this

pysam.fastq(.....,"xxx.sam")

My sam file is single-end, so I use '-s' but the result outputs to standard output.

pysam samtools • 600 views
ADD COMMENTlink modified 3 months ago • written 3 months ago by Zhixue0
1

What have you tried and what happened?

ADD REPLYlink written 3 months ago by Matt Shirley8.4k
1

And what's the reason you don't want to use samtools

I also try this command samtools fastq -s xxx.fastq xxx.sam

I'd suggest:

samtools fastq input.sam > output.fastq
ADD REPLYlink written 3 months ago by WouterDeCoster30k

I use the following in my python script pysam.fastq("-s","xxx.fastq","xxx.sam") and there is a file named "xxx.sam"but it is Zero bytes.


I also try this command samtools fastq -s xxx.fastq xxx.sam The fastq fromat data is the standard output, and there is a file named "xxx.sam" with Zero bytes as well.

ADD REPLYlink written 3 months ago by Zhixue0

I would like to write a python script by pysam with lots of complex filtering steps which include a step of "sam "to "fastq". It ls said that Pysam can use samtools commands(but I only find an example of sort in the manual).

If I am not able to find a solution of this question,I may put samtools in the software requirement list and use the ">" at last. Thank you~

ADD REPLYlink written 3 months ago by Zhixue0

Please use ADD COMMENT/ADD REPLY when responding to existing posts to keep threads logically organized.

ADD REPLYlink written 3 months ago by genomax51k
2
gravatar for Matt Shirley
3 months ago by
Matt Shirley8.4k
Cambridge, MA
Matt Shirley8.4k wrote:

If you're going to make a script for this it's not much more effort to go all the way and do the conversion yourself:

This uses simplesam, which has a much simpler (get it?) API than pysam.

ADD COMMENTlink written 3 months ago by Matt Shirley8.4k
1

If the reads are paired, would this be much more complicated?

ADD REPLYlink written 3 months ago by igor6.3k
0
gravatar for Zhixue
3 months ago by
Zhixue0
China/Shanghai/TJ
Zhixue0 wrote:

ADD COMMENT It is pity that the add comment/add reply button may go wrong in my Google/Firefox browser.

To Matt Shirley: Thank you very much , simplesam is good but I have found the solution of this question.

When I use samtools fastq xxx.sam>xxx.fastq ,the standard output includes the fastq data and a message "[M::bam2fq_mainloop] processed 200000 reads".

I infer the return of pysam.fastq() function may be a string, and I try to store it in a var and print it in python like this out_str = pysam.fastq("xxx.sam") . print(out_str) . The result only includes the fastq data and it can be stored by python' s file write function easily.


In a word, thank you all and the question has been solved.

ADD COMMENTlink modified 3 months ago • written 3 months ago by Zhixue0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 999 users visited in the last hour