Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sjackman
    Member
    • Mar 2009
    • 15

    #1

    Filter a SAM file by alignment score (AS)

    Hi,

    I have a SAM file with the alignment score tag (AS) set appropriately (mapped by BWA-SW). I want to filter out all alignments with an alignment score (note: not mapping quality) less than a threshold. samtools doesn't seem to have this feature. Do you know of a software package that does?

    Thanks,
    Shaun
  • swbarnes2
    Senior Member
    • May 2008
    • 910

    #2
    You can probably just use grep or awk.

    Comment

    • nanto
      Member
      • Sep 2012
      • 19

      #3
      use:

      samtools view -S file.sam | awk '{print $numberoffield}' > file

      and just find which field is AS.

      Comment

      • Kulvait
        Member
        • Aug 2012
        • 11

        #4
        Solution

        It is not so straightforward but for my bam file works well

        samtools view -S file.bam | awk '{split($14, subfield, ":"); if(subfield[3]>120) print $0}', where 14 field match AS:i:NUM
        Data analysis www.persmed.eu

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          I would normally use pysam for something like this, just for the sake of simplicity.

          Comment

          • Kulvait
            Member
            • Aug 2012
            • 11

            #6
            Can you please provide full code you would use for filtering based on this paramter XS? This is sample row from my sam file to be used for filtering:

            Code:
            M03094:5:000000000-ALEAW:1:1102:21888:24571	16	chr9	139396897	60	27S213M27S	*	0	0	AAGCACAAAGGCGGCCGCCGCCACGTACATGAAGTGCAGCTGCGCTGGCGGGGGCGGCCCCCCGGGCTCACCTGCGGGCACGGGGGCCAGGGGCAGGGGCCCGGACATTAGGCAGCGGCTACGCAGCAGGCTGGTGGCCGGGGGGCGGCGGACTGGCTCCGCGTCCGGGCGCCTCCTCACCCACTCTCCTCCATCCCGCCCTCCAAAATAAGGTCATTCTCTACGCGATTAATCAGAATTGCAAACTATCGCTAAATTCTCTCCTGC	CCBBCFFFFFFCGGGGGGGGGGGGGHHHGHHHHHHHHHHHHHHGGGGGGGGGGG/<C--<A-:-----:0;F0/;-@F--..;[email protected];@-:-:-:BB0B009:FFF:FFFFFFFFFFFFFF9FG;FGGGGGG;GGGHHHHHGGGGGGGGGGGGGGGFGGGHHHHGGHGHHGHGGGHHGGGGGGGGGGHHGHHHHHHHHHHHHHHHHGGGGGGGHHHHHHHHHHHHHHHHHHHGGGGGGGGGGFFDCCDDDDDDC	MD:Z:45C12T2A3T31T10C109T48	NM:i:7	AS:i:232	XS:i:19
            Data analysis www.persmed.eu

            Comment

            • dpryan
              Devon Ryan
              • Jul 2011
              • 3478

              #7
              Code:
              import pysam
              bam = pysam.AlignmentFile("foo.bam", "rb")
              for read in bam.fetch():
                  if read.has_tag('XS'):
                      XS = read.get_tag('XS')
                      # do something
                  else:
                      # do something else
              bam.close()

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                16S/ITS Profiling vs. Shotgun Metagenomics: What Changes in Your Workflow?
                by SEQadmin2





                NGS has revolutionized clinical microbiology by offering new ways to identify and surveil pathogens without prior knowledge of the target. One popular approach is 16S rRNA and ITS amplicon sequencing, which targets specific microbial markers. But studies are increasingly incorporating shotgun metagenomics, a technique that sequences all DNA from a sample without targeting specific microbial markers. This approach allows more detailed taxonomic classification,...
                10-30-2026, 06:46 AM
              • 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

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 11-05-2026, 09:25 AM
              0 responses
              20 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 11-03-2026, 11:54 AM
              0 responses
              34 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-28-2026, 09:57 AM
              0 responses
              82 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 10-28-2026, 09:51 AM
              0 responses
              50 views
              0 reactions
              Last Post SEQadmin2  
              Working...