Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • rcorbett
    Member
    • Sep 2009
    • 29

    get read position from Samtools pileup

    Hi all,
    Has anyone come across a way to get information about the location of a snp within the reads? I have the usual bam/sam/pileup files.

    For example,
    r1: GAG
    r2: GGG
    r3: AGA
    ref: AAAGGGTTTT

    In this very contrived example that was hopefully preserved by the editor we would have a single snp represented at pos 2 in read 1, and pos 3 in read 3 . What I am looking for is a way to get that information that says this snp is at pos 2 in r1, and position 3 in r3 from bam/sam/pileup files.

    Does anyone know of a tool that can do this?

    thanks for any help.
  • rcorbett
    Member
    • Sep 2009
    • 29

    #2
    Hmm. The editor ate the example.
    I'll use '#' to mark spaces:

    r1: ###GAG###
    r2: ###GGG###
    r3: ##AGA####
    rf: AAAGGGTTTT

    Comment

    • krobison
      Senior Member
      • Nov 2007
      • 734

      #3
      Probably not the answer you were looking for, but you could certainly roll your own using one of the SAMTools libraries for Perl, Python or Java. The Perl SNP caller example shows this:



      (I've added some additional comments; the code is not mine)

      Code:
       my @SNPs;  # this will be list of SNPs
       my $snp_caller = sub {
              my ($seqid,$pos,$p) = @_;
              my $refbase = $sam->segment($seqid,$pos,$pos)->dna;
              my ($total,$different);
              for my $pileup (@$p) {
                  my $b     = $pileup->b;
                  next if $pileup->indel;  # don't deal with these ;-)
      
                  # $pileup->qpos is the position in $b->qseq (the read)
                  my $qbase  = substr($b->qseq,$pileup->qpos,1);
                  next if $qbase =~ /[nN]/;
      
                  my $qscore = substr($b->qscore,$pileup->qpos,1);
                  next unless $qscore > 25;
      
                  $total++;
                 # next line finds the variant; 
                  $different++ if $refbase ne $qbase;
              }
              if ($total >= 4 && $different/$total >= 0.25) {
                 push @SNPs,"$seqid:$pos";
              }
          };
      
       $sam->pileup('seq1',$snp_caller);
       print "Found SNPs: @SNPs\n";

      Comment

      Latest Articles

      Collapse

      • GATTACAT
        Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
        by GATTACAT
        Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
        07-01-2026, 11:43 AM
      • SEQadmin2
        Nine Things a Sample Prep Scientist Thinks About Before Sequencing
        by SEQadmin2


        I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

        Here are nine questions we think about, in roughly the order they matter, before...
        06-18-2026, 07:11 AM

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, Yesterday, 11:08 AM
      0 responses
      6 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-30-2026, 05:37 AM
      0 responses
      11 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-26-2026, 11:10 AM
      0 responses
      19 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 06-17-2026, 06:09 AM
      0 responses
      53 views
      0 reactions
      Last Post SEQadmin2  
      Working...