Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #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


    • #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


      • #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


        • #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


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

            Comment

            Latest Articles

            Collapse

            • seqadmin
              Recent Innovations in Spatial Biology
              by seqadmin


              Spatial biology is an exciting field that encompasses a wide range of techniques and technologies aimed at mapping the organization and interactions of various biomolecules in their native environments. As this area of research progresses, new tools and methodologies are being introduced, accompanied by efforts to establish benchmarking standards and drive technological innovation.

              3D Genomics
              While spatial biology often involves studying proteins and RNAs in their...
              Yesterday, 07:30 PM
            • seqadmin
              Advancing Precision Medicine for Rare Diseases in Children
              by seqadmin




              Many organizations study rare diseases, but few have a mission as impactful as Rady Children’s Institute for Genomic Medicine (RCIGM). “We are all about changing outcomes for children,” explained Dr. Stephen Kingsmore, President and CEO of the group. The institute’s initial goal was to provide rapid diagnoses for critically ill children and shorten their diagnostic odyssey, a term used to describe the long and arduous process it takes patients to obtain an accurate...
              12-16-2024, 07:57 AM

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, 12-30-2024, 01:35 PM
            0 responses
            23 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-17-2024, 10:28 AM
            0 responses
            41 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-13-2024, 08:24 AM
            0 responses
            55 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 12-12-2024, 07:41 AM
            0 responses
            41 views
            0 likes
            Last Post seqadmin  
            Working...
            X