Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Danko1
    Junior Member
    • Mar 2014
    • 6

    #1

    Extract consensus from BAM + fill gaps from reference

    Hi everyone!

    I am new to this forum and have the following question:

    How can I extract the consensus sequence from a BAM alignment AND fill positions where there might be gaps in the alignment with the reference sequence from the alignment?

    I know that there is a way using samtools mpileup to extract a consensus sequence from a BAM file but the "fill from reference" option is very important to me.

    Any ideas what tools I could use to easily extract the consensus this way?

    Thanks for your help!
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    Quoting from one of the samtools pages:

    Code:
    samtools mpileup -uf ref.fa aln.bam | bcftools view -cg - | vcfutils.pl vcf2fq > cns.fq

    Comment

    • Danko1
      Junior Member
      • Mar 2014
      • 6

      #3
      Thanks for your quick answer dpryan!

      I know this samtools code, but this won't allow to fill gaps in the alignment with the reference sequence of the alignment at that position so that I end up with a consensus fasta file without any gaps, right?

      How can I extract the consensus sequence from an alignment where positions where there are gaps are filled with the corresponding nucleotide(s) from the reference sequence of the alignment?

      Comment

      • dpryan
        Devon Ryan
        • Jul 2011
        • 3478

        #4
        That actually should produce a consensus file. At least the output from bcftools will contain the SNP calls for every base and the reference sequence (regardless of whether the base is covered or not), so if that's not working correctly then presumably there's been a change in vcfutils.pl. To confirm this, what happens if you:

        Code:
        samtools mpileup -uf ref.fa aln.bam | bcftools view -cg - >foo.vcf
        and then look at one of the gaps? It should be covered in the VCF (if not, then I likely mistyped something). The only trick then is converting the reference given the VCF file, which which there are other options (GATK has a tool for that).

        Comment

        • Danko1
          Junior Member
          • Mar 2014
          • 6

          #5
          So I tested the proposed code to generate a consensus from a BAM alignment:

          samtools mpileup -uf ref.fa aln.bam | bcftools view -cg - | vcfutils.pl vcf2fq > cns.fq

          It works fine, despite the fact that I end up with 'N' at every position where my reads don't map to the reference in the alignment.

          How can I replace those 'N's' by the original nucleotides from the reference at this position? I am glad for any help!

          @dpryan: Did you mean the FastaAlternateReferenceMaker by GATK? Have you used this tool before?

          Comment

          • Danko1
            Junior Member
            • Mar 2014
            • 6

            #6
            Figured it out! The GATK tool did the trick! Thanks for your help!

            Comment

            Latest Articles

            Collapse

            • SEQadmin2
              Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
              by SEQadmin2



              CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

              Despite this, “CRISPR helped turn genome editing from a specialized technique into
              ...
              07-31-2026, 11:01 AM
            • SEQadmin2
              Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
              by SEQadmin2


              Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

              The systematic characterization of the human proteome has
              ...
              07-20-2026, 11:48 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by SEQadmin2, Yesterday, 10:35 AM
            0 responses
            7 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 08-06-2026, 07:41 AM
            0 responses
            25 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 08-03-2026, 10:13 AM
            0 responses
            45 views
            0 reactions
            Last Post SEQadmin2  
            Started by SEQadmin2, 07-31-2026, 02:55 AM
            0 responses
            48 views
            0 reactions
            Last Post SEQadmin2  
            Working...