Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • 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

  • #2
    You can probably just use grep or awk.

    Comment


    • #3
      use:

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

      and just find which field is AS.

      Comment


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


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

          Comment


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


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

              • seqadmin
                Essential Discoveries and Tools in Epitranscriptomics
                by seqadmin




                The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
                04-22-2024, 07:01 AM
              • seqadmin
                Current Approaches to Protein Sequencing
                by seqadmin


                Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                04-04-2024, 04:25 PM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Today, 11:49 AM
              0 responses
              12 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 08:47 AM
              0 responses
              16 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-11-2024, 12:08 PM
              0 responses
              61 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              60 views
              0 likes
              Last Post seqadmin  
              Working...
              X