Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rcapper
    Member
    • Sep 2011
    • 20

    #1

    Does Samtools mpileup command require a reference fasta?

    I performed an experiment to track mutation accumulation over time in a fungal population. I sequenced several individual genomes from different time points and would like to extract the SNP sites only.

    I currently have transformed my raw reads into *.sorted.bam files. I would like to use mpileup without a reference .fasta file because I'm only interested in the SNPs among *my* genomes, not between my genomes and the published reference genome. Is this possible?

    When I use the following commands without a supplied "-f ref.fasta" switch:
    samtools mpileup -ug sorted.bam1..3 | bcftools view -bcvg - > mpileup_noref.bcf
    bcftools view mpileup_noref.bcf | vcfutils varFilter > mpileup_noref.vcf

    I get zero SNPs in the .vcf file, though the .bcf file is enormous.

    When I use the commands:
    samtools mpileup -ugf ref.fasta sorted.bam1..3 | bcftools view -bcvg - > mpileup_ref.bcf
    bcftools view mpileup_ref.bcf | vcfutils varFilter > mpileup_ref.vcf

    I get 1700 SNPs in the .vcf, and the .bcf is much smaller than the no_ref.bcf file.

    Does anyone have any idea what is causing the discrepancy here? I would expect to find more SNPs between my samples and the reference.fasta than I would just among my samples, which are all related.

    Thank you!
  • swbarnes2
    Senior Member
    • May 2008
    • 910

    #2
    Just use the reference fasta. I'm not sure that bcftools is able to work with no reference fasta (though the regular pileup output can) Your vcf will not include all the sites where every sample matches the reference, it will only show the sites where it believes there are differences. That's what the -v switch is for.

    Comment

    • rcapper
      Member
      • Sep 2011
      • 20

      #3
      Thank you If my samples are different from each other they will also be different from the reference, so I should be able to see them in the with_reference.vcf.

      However, what if all of my samples are the same at one particular site, but different from the reference? It seems like I would recover irrelevant information this way, when I am only interested in sites that are different among my individuals and not between them and the ref. Is there a simple way to filter these variants out?

      Comment

      • swbarnes2
        Senior Member
        • May 2008
        • 910

        #4
        You just filter out SNPs found in every sample.

        Or, if your sample numbers are modest, and you are going to be doing more samples from this family, use the SNP data to tweak your reference genome to match the consensus, then realign everything to that consensus, and recall the SNPs.

        Comment

        • glados
          Member
          • Mar 2012
          • 59

          #5
          Originally posted by swbarnes2 View Post
          You just filter out SNPs found in every sample.
          How do I do this? Any suggestion? I can't seem to find a solution on how to do this.

          Comment

          • rcapper
            Member
            • Sep 2011
            • 20

            #6
            Are your coding skills modest? I wrote my own script to analyze the .vcf output to find guys who were all the same within the population, but different from the reference (and therefore not particularly interesting to me).

            Comment

            • glados
              Member
              • Mar 2012
              • 59

              #7
              Yes, my coding skills are poor. Is it possible to grep for any keyword related to homozygotic variants in the vcf-file?

              Comment

              • rcapper
                Member
                • Sep 2011
                • 20

                #8
                I'm not sure how you could use grep... I'm much more comfortable in perl This is a nice little practice problem for scripting, though, so you should try it on your own at some point.

                That said, working through other people's code was really helpful to me when I was first learning, so I wrote a version out for you. I think it works.
                Code:
                #!/usr/bin/env perl
                # Roxana Capper 28 May 2013, University of Texas at Austin
                
                # -- program description and required arguments
                
                unless ($#ARGV == 1)
                	{
                	print "\ntakes a .vcf file and prints only SNPs that are polymorphic\n";
                	print "WITHIN individuals, not just between all samples and the reference.\n";
                        print "\nUsage:\t script input.vcf polymorphs_only.vcf\n";
                        print "\n"; exit;
                        }
                
                open(VCF, "$ARGV[0]");
                open(OUT, ">$ARGV[1]");
                $one_allele=0; $mult_alleles=0; $total_snps=0;
                
                while (<VCF>)
                	{
                	chomp;
                	$count=0;
                	undef(%genotype);
                	if ($_=~/^#/) {print OUT "$_\n";next;} #print all the header stuff to the new file
                	$line = $_;
                	@columns = split(/\t/,$line);
                	foreach $sample (@columns[9..$#columns])
                		{
                		@ind=split(/:/,$sample); ($allele1, $allele2) = split(/\/|\|/,$ind[0]);
                		if (($allele1 | $allele2) eq ".") {next;}
                		$genotype{$allele1}++;$genotype{$allele2}++;
                		}
                	foreach $variant (keys %genotype) {$count++};  # how many alleles are seen for this SNP?
                	if ($count==1) {$one_allele++};
                	if ($count > 1) {$mult_alleles++; print OUT "$line\n";}  #if polymorphic, print out
                	$total_snps++;
                	}
                
                #output some stats to std out:
                print "There were $total_snps in $ARGV[0].\n";
                print "Of these, $one_allele were monomorphic among the samples\n";
                print "$mult_alleles were printed to $ARGV[1].";

                Comment

                • swbarnes2
                  Senior Member
                  • May 2008
                  • 910

                  #9
                  You don't even have to code; if your files are not titanic, you can drop them into Excel, and filter them there. I use conditional formatting to change all the "1/1" into red font, "0/1" into purple, and "0/0" blue. You can then use filters to filter by color. You'd want to get rid of all the entries that are all red.

                  I suppose you could grep for "0/0", that would mean that at least one sample of your bunch matches the reference, making it a meaningful SNP.

                  Comment

                  • glados
                    Member
                    • Mar 2012
                    • 59

                    #10
                    Roxana, I just tried out your perl script, and it worked perfectly! (didn't have time earlier)
                    Thank you so much! Very useful! I will definitely have more use of your code. Thanks again!

                    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
                    • SEQadmin2
                      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                      by SEQadmin2



                      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                      ...
                      07-09-2026, 11:10 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, Today, 07:41 AM
                    0 responses
                    9 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 08-03-2026, 10:13 AM
                    0 responses
                    23 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-31-2026, 02:55 AM
                    0 responses
                    36 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    25 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...