Question: BAM/SAM to FASTA conversion
1
gravatar for biolab
2.5 years ago by
biolab900
China
biolab900 wrote:

Hi everone,

I searched Biostars for BAM/SAM to FASTA conversion method, and found the tools EMBOSS Picard could do this (Convert Bam File To Fasta File)   I am wondering is there any perl script to complish this work?   I should note that my seq data is strand-specific seq, so the command samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' may not be very good.

I appreciate any of your solutions. Thanks a lot!

sam bam • 12k views
ADD COMMENTlink modified 17 days ago by Chadi Saad30 • written 2.5 years ago by biolab900
1
gravatar for Chadi Saad
17 days ago by
Chadi Saad30
France
Chadi Saad30 wrote:

you need to add '-' fot seqtk in order to read from pipe :

samtools bam2fq input.bam | seqtk seq -A - > output.fa
ADD COMMENTlink modified 10 days ago • written 17 days ago by Chadi Saad30

Please use ADD COMMENT or ADD REPLY to answer to previous reactions, as such this thread remains logically structured and easy to follow. I have now moved your post but as you can see it's not optimal. Adding an answer should only be used for providing a solution to the question asked.

ADD REPLYlink written 17 days ago by WouterDeCoster20k
9
gravatar for Istvan Albert
2.5 years ago by
Istvan Albert ♦♦ 73k
University Park, USA
Istvan Albert ♦♦ 73k wrote:

The advice in the post you link to is greatly outdated. One of the reasons we should revisit these posts. There are far easier/faster ways to accomplish the same task.

The latest versions of samtools have the bam2fq command. Chain that to seqtk seq like so:

samtools bam2fq input.bam | seqtk seq -A > output.fa
ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by Istvan Albert ♦♦ 73k

Hi Istvan, thank you very much for your answer.  It's much helpful for my work.  I just have two more minor questions: (1) my samtools version is Version: 0.1.8 (r613).  I did not see samtools bam2fq function, so I need to update samtools?  (2) Additionally is seqtk inside samtools? If not, where to get it?  Thanks a lot!

ADD REPLYlink written 2.5 years ago by biolab900
1

You need to update samtools to at least 1.1 http://www.htslib.org/

Get seqtk from https://github.com/lh3/seqtk see also  How To Obtain And Install Seqtk

ADD REPLYlink written 2.5 years ago by Istvan Albert ♦♦ 73k

Hi Istvan, your answer is really helpful.

ADD REPLYlink written 2.5 years ago by biolab900
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: 1171 users visited in the last hour