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
                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
              • seqadmin
                Strategies for Sequencing Challenging Samples
                by seqadmin


                Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                03-22-2024, 06:39 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, 04-11-2024, 12:08 PM
              0 responses
              27 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              30 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 09:21 AM
              0 responses
              26 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-04-2024, 09:00 AM
              0 responses
              52 views
              0 likes
              Last Post seqadmin  
              Working...
              X