Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TabeaK
    Member
    • Oct 2012
    • 48

    #1

    Advice on tools sought - exporting consensus sequences with coverage & SNPs?

    Hi all!

    I need some tools advice.
    So; I have mapped reads in BAM format.
    I have called SNPs using samtools/bcftools.

    Are there any good tools for exporting consensus sequences from; say a vcf file; in; say fasta format; that maintain infos like coverage?

    Hope I am making sense here. Feel free to point me to appropriate threads on seqanswers; my crappy searching has not turned up anything!
  • TabeaK
    Member
    • Oct 2012
    • 48

    #2
    Okay: after a lot of reading around here on seqanswers, I think I have managed to some of this with samtools - always helps to read the manual carefully.

    Only thing where I am stuck is the consensus. My current read library has okay-ish, but not great, coverage which means there are gaps in my alignment to the reference. These gaps might be there because of extensive deletion or something: but lets not even worry about that now...

    So, if I call a consensus from the vcf file; how are the regions having no coverage treated? Is the sequence just taken from the ref sequence? Can I track/visualise that somehow? Just so I know which bit in the consensus came from the actual bam (i.e. has experimental evidence from my sequencing runs) and which bit came from the reference and has no experimental evidence?

    Comment

    • TabeaK
      Member
      • Oct 2012
      • 48

      #3
      Some progress.

      Apologies if it seems like I am talking to myself; but maybe at some point someone will search for the same issue and this may help...

      So; after using the vcfutils and f2q conversion in samtools; I have ended up with a consensus fastq file.

      The file contains: Upper case letters (good quality?); lower case letters (low quality?) and - most interestingly - a bunch of Ns (lower case) where my reads do not cover the reference.

      After converting this to fasta (seqtk) - which obviously looses the upper/lower case info - I have something I can work with reasonably well for now!

      2 Questions remain for me:

      1. Is there a description of what vcfutils actually does in detail somewhere? So, when does it call upper/lower case?
      2. Is there any way to force it to use the reference sequence when it does not find coverage? So; it prints the ref sequence instead of an N?

      Maybe I need another tool for that.

      Comment

      • swbarnes2
        Senior Member
        • May 2008
        • 910

        #4
        Originally posted by TabeaK View Post
        Some progress.

        Apologies if it seems like I am talking to myself; but maybe at some point someone will search for the same issue and this may help...

        So; after using the vcfutils and f2q conversion in samtools; I have ended up with a consensus fastq file.

        The file contains: Upper case letters (good quality?); lower case letters (low quality?) and - most interestingly - a bunch of Ns (lower case) where my reads do not cover the reference.

        After converting this to fasta (seqtk) - which obviously looses the upper/lower case info - I have something I can work with reasonably well for now!

        2 Questions remain for me:

        1. Is there a description of what vcfutils actually does in detail somewhere? So, when does it call upper/lower case?
        2. Is there any way to force it to use the reference sequence when it does not find coverage? So; it prints the ref sequence instead of an N?

        Maybe I need another tool for that.
        I have an older version of samtools but vcfutils is in perl, so it's human readable. If you are using vcf2fastq, the key lines are these:

        Code:
        my ($b, $q);
        	  $q = $1 if ($t[7] =~ /FQ=(-?[\d\.]+)/);
        	  if ($q < 0) {
        		$_ = ($t[7] =~ /AF1=([\d\.]+)/)? $1 : 0;
        		[B]$b = ($_ < .5 || $alt eq '.')? $ref : $alt;[/B]
        		$q = -$q;
        	  } else {
        		[B]$b = $het{"$ref$alt"};
        		$b ||= 'N';[/B]
        	  }
        	  $b = lc($b);
        	  $b = uc($b) if (($t[7] =~ /MQ=(\d+)/ && $1 >= $_Q) && ($t[7] =~ /DP=(\d+)/ && $1 >= $_d && $1 <= $_D));
        $b is depending on the vcf entry, either the reference letter, or the alt letter, or a letter representing both letters, if the vcf thinks its a mixed SNP, or an N, if there's nothing at all for that letter. Those lines are the first 3 bolded lines.

        The last line determines if $b is uppercase or lowercase, which basically happens if the mapping quality is above the minimum you specified, and the coverage is between the min and max you specified.

        The other place in the program where it will make your sequence lowercase is here:

        Code:
        for my $g (@$gaps) {
        	my $beg = $g->[0] > $l? $g->[0] - $l : 0;
        	my $end = $g->[0] + $g->[1] + $l;
        	$end = length($$seq) if ($end > length($$seq));
        	substr($$seq, $beg, $end - $beg) = lc(substr($$seq, $beg, $end - $beg));
          }
        And @gaps is populated here:

        Code:
        	} elsif ($t[4] ne '.') { # an INDEL
        	  push(@gaps, [$t[1], length($t[3])]);
        	}
        So around indels, the software will make a window of lowercase letters.

        And if you have no coverage for a region, I'm not sure you necessarily want the software to just tell you that it's reference, because what if there's a deletion?

        Comment

        • ekg
          Member
          • Apr 2010
          • 36

          #5
          If you have a haploid sample, and only one sample, and the VCF reflects that fact (e.g. you called with freebayes --ploidy 1) then you can use vcfgeno2haplo (https://github.com/ekg/vcflib/blob/m...geno2haplo.cpp) with an arbitrary window size to get a consensus sequence. It will be recorded in your "ALT" in the only line of the output VCF. This works with indels.

          If you have diploid samples, you'll have to phase them somehow. This method won't work if your samples aren't phased.

          For coverage, you can get statistics in a number of ways. I'm not sure the best for your usage.

          Comment

          Latest Articles

          Collapse

          • SEQadmin2
            Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
            by SEQadmin2



            Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

            Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
            ...
            10-14-2026, 09:55 AM
          • SEQadmin2
            New Genomics Technologies Take Aim at Long-Standing Limits
            by SEQadmin2


            Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

            We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
            ...
            09-28-2026, 10:25 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, Yesterday, 11:13 AM
          0 responses
          17 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, Yesterday, 10:48 AM
          0 responses
          18 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-15-2026, 10:52 AM
          0 responses
          36 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 10-14-2026, 05:39 AM
          0 responses
          42 views
          0 reactions
          Last Post SEQadmin2  
          Working...