Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • krapulaxdoctor
    Member
    • May 2015
    • 22

    Samtools filter reads based on CIGAR values

    Dear all,

    I would like to ask for some help with samtools:

    I found many threads about using samtools to filter reads based on some criteria, however, I did not find any clue how to filter reads based on the CIGAR value.

    How can I filter reads (from a BAM) from RNA-seq files that are non-splitted / non-gapped?

    From one BAM, I would like to have two BAMs ne with gapped reads and one with non-gapped reads.

    Could someone write an example?
    Thank you for the help in advance,
  • dariober
    Senior Member
    • May 2010
    • 311

    #2
    Gapped reads are those containing the N operator in the cigar string right? You could do this:

    Code:
    samtools view -h in.bam \
    | awk '{if($0 ~ /^@/ || $6 ~ /N/) {print $0}}' \
    | samtools view -Sb - > gapped.bam
    And for ungapped reads:

    Code:
    samtools view -h in.bam \
    | awk '{if($0 ~ /^@/ || $6 !~ /N/) {print $0}}' \
    | samtools view -Sb - > ungapped.bam

    Comment

    • HESmith
      Senior Member
      • Oct 2009
      • 512

      #3
      Be aware that deletions (CIGAR string D) also give rise to gapped alignments, and the representation as N vs. D depends on the gap length and the aligner.

      Comment

      • dariober
        Senior Member
        • May 2010
        • 311

        #4
        Originally posted by HESmith View Post
        Be aware that deletions (CIGAR string D) also give rise to gapped alignments, and the representation as N vs. D depends on the gap length and the aligner.
        True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case, I think tophat uses N to mark gaps between exons (don't know other aligners).

        Comment

        • dpryan
          Devon Ryan
          • Jul 2011
          • 3478

          #5
          Originally posted by dariober View Post
          True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case, I think tophat uses N to mark gaps between exons (don't know other aligners).
          Realistically, any aligner that advertises the ability to handle spliced reads will do this too. If not, it shouldn't be used.

          Comment

          • krapulaxdoctor
            Member
            • May 2015
            • 22

            #6
            Thank you for all the quick responses.
            It is a great help for me.

            dariober:
            True, but I surmise the OP wants to select reads spanning different exons as opposed those only assigned to one exon. If this is the case...
            Yes, that would be the main goal. Thanks.

            Comment

            • HESmith
              Senior Member
              • Oct 2009
              • 512

              #7
              Originally posted by dpryan View Post
              Realistically, any aligner that advertises the ability to handle spliced reads will do this too. If not, it shouldn't be used.
              I agree 100%, but it would not be the first time that someone used an inappropriate tool for the job. The alert was directed at the OP, in case the awk filter did not produce the expected results.

              Comment

              Latest Articles

              Collapse

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, 06-05-2026, 10:09 AM
              0 responses
              15 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-04-2026, 08:59 AM
              0 responses
              33 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-02-2026, 12:03 PM
              0 responses
              35 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-02-2026, 11:40 AM
              0 responses
              23 views
              0 reactions
              Last Post SEQadmin2  
              Working...