Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Canadian_philosophy
    Junior Member
    • Apr 2010
    • 9

    BAM/SAM to Fasta

    Hi there,

    I have a couple of aligned sequences from BWA. I used samtools to get the BAM format. What I really need is the Fasta format of these aligned sequences. Is there a program that would help?

    Thanks.
  • maubp
    Peter (Biopython etc)
    • Jul 2009
    • 1544

    #2
    Yes, several, including one line shell scripts.

    Possibly seqret from EMBOSS 6.3.x will do what you want.

    See also this thread for SAM/BAM to FASTQ which is very relevant:
    Discussion of next-gen sequencing related bioinformatics: resources, algorithms, open source efforts, etc

    Comment

    • Canadian_philosophy
      Junior Member
      • Apr 2010
      • 9

      #3
      Thanks Maubp, I just downloaded Emboss. I will get back if I bump into trouble.
      Thanks very much.

      Comment

      • olus
        Member
        • Aug 2008
        • 22

        #4
        This one liner would give you a fasta formatted file from a bam alignment:

        samtools view filename.bam | awk '{OFS="\t"; print ">"$1"\n"$10}' - > filename.fasta

        Hope this helps.

        Gabriel
        gabriele bucci

        Comment

        • ulz_peter
          Senior Member
          • Feb 2010
          • 219

          #5
          Or picard SamToFastq:

          Works with BAM Files as well and supports some other options:

          Comment

          • tejaminnu
            Junior Member
            • May 2011
            • 4

            #6
            Hi Gabriel,

            Is there a way to do the opposite ? What i mean is that, i have a file called mrna_ref.fa (fasta file), can i convert it into a sam or a bam file using Samtools in the command line.

            Regards
            Teja

            Comment

            • olus
              Member
              • Aug 2008
              • 22

              #7
              Hi Teja.
              In theory you can convert a multifasta file in a sam (tabular) file, and then convert to bam with samtools view -b.
              But the fasta file only contains information on the nucletide sequence itself, nothing about the mapping, read quality etc... which are indeed the columns of the sam file (you will also need to rebuild the sam header).
              In conclusion I think it's useless to convert a fasta file into a sam file, but I can't exclude that you are dealing with something that requires such conversion.
              Would please briefly explain your case?

              Thank you.

              Best regards.
              Gabriel
              gabriele bucci

              Comment

              • tejaminnu
                Junior Member
                • May 2011
                • 4

                #8
                Hi

                Hi Gabriel,

                I want to send u the file. which is very small. Probably u can have a look at it .. Can u just send me a mail to this id, if its not a problem.

                [email protected]

                Regards
                Teja

                Comment

                • tejaminnu
                  Junior Member
                  • May 2011
                  • 4

                  #9
                  Basically i have a Stand Alone Blast program running. The "fasta" file served as a reference file using which i blasted the large database file that i had. I am trying to find out if i can call SNP's using "Blast" program.

                  And i want to confirm it by getting the SNP's using Samtools.

                  Is the above explanation even valid. ?

                  Do let me know

                  Regards
                  Teja

                  Comment

                  • tejaminnu
                    Junior Member
                    • May 2011
                    • 4

                    #10
                    Hi Gabriel,

                    I want to send u the file. which is very small. Probably u can have a look at it .. Can u just send me a mail to this id, if its not a problem.

                    [email protected]

                    Basically i have a Stand Alone Blast program running. The "fasta" file served as a reference file using which i blasted the large database file that i had. I am trying to find out if i can call SNP's using "Blast" program.

                    And i want to confirm it by getting the SNP's using Samtools.

                    Is the above explanation even valid. ?

                    Do let me know


                    Regards
                    Teja

                    Comment

                    • olus
                      Member
                      • Aug 2008
                      • 22

                      #11
                      Originally posted by tejaminnu View Post
                      Hi Gabriel,

                      I want to send u the file. which is very small. Probably u can have a look at it .. Can u just send me a mail to this id, if its not a problem.

                      [email protected]

                      Basically i have a Stand Alone Blast program running. The "fasta" file served as a reference file using which i blasted the large database file that i had. I am trying to find out if i can call SNP's using "Blast" program.

                      And i want to confirm it by getting the SNP's using Samtools.

                      Is the above explanation even valid. ?

                      Do let me know


                      Regards
                      Teja
                      Hi.
                      If I understand it right, you have to:
                      1) align your fasta query file (mrna_fa) to a reference with blast
                      2) parse the blast output to be compliant with sam
                      3) use samtools to call SNPs (to a properly indexed reference)

                      for point 2) you can look at here:
                      Discussion of next-gen sequencing related bioinformatics: resources, algorithms, open source efforts, etc


                      In general I can say that blast it's not suited for efficient SNP calling , but I may be wrong.

                      Gabriel
                      gabriele bucci

                      Comment

                      Latest Articles

                      Collapse

                      • SEQadmin2
                        From Collection to Sequencing: Why Sample Preparation and Preservation Define Sequencing Data
                        by SEQadmin2


                        Data variability is still an issue in sequencing technologies despite the advances in reproducibility and accuracy of these platforms. But the problem does not originate in the sequencing itself, but in the previous steps, before the sample reaches the sequencer.


                        The first step is collection, followed by preservation and sample preparation for analysis. Most scientists overlook those steps, but not being careful might just be skewing the experiment’s results.
                        ...
                        06-02-2026, 10:05 AM
                      • SEQadmin2
                        Single-Cell Sequencing at an Inflection Point: Early Impacts of New Platforms and Emerging Trends
                        by SEQadmin2


                        With the launch of new single-cell sequencing platforms in 2026, the field stands at an exciting inflection point. This article surveys the most impactful advances in the field and discusses how they’re reshaping research in cancer, immunology, and beyond.


                        Introduction

                        Single-cell sequencing technologies have undergone remarkable advances over the past decade, transitioning from low-throughput experimental approaches to highly scalable platforms capable of...
                        05-22-2026, 06:42 AM
                      • SEQadmin2
                        Environmental Genomics in the Age of NGS: From Microbes to Conservation Strategies
                        by SEQadmin2

                        Studying ecosystems means dealing with complex, multi-species communities that are hard to observe at scale. This complexity, however, hides many important questions to be answered, from how biogeochemical cycles work and how climate change can affect species distribution to how conservation strategies can work best.


                        Genomics, particularly since the expansion of NGS, has transformed ecosystem ecology. By sequencing environmental DNA, we can now assess biodiversity without direct...
                        05-06-2026, 09:04 AM

                      ad_right_rmr

                      Collapse

                      News

                      Collapse

                      Topics Statistics Last Post
                      Started by SEQadmin2, 06-02-2026, 12:03 PM
                      0 responses
                      21 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 06-02-2026, 11:40 AM
                      0 responses
                      14 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 05-28-2026, 11:40 AM
                      0 responses
                      29 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 05-26-2026, 10:12 AM
                      0 responses
                      31 views
                      0 reactions
                      Last Post SEQadmin2  
                      Working...