Seqanswers Leaderboard Ad

Collapse

Announcement

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

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

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


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


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


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


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


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

              • seqadmin
                Recent Advances in Sequencing Analysis Tools
                by seqadmin


                The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
                Yesterday, 07:48 AM
              • 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

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Today, 06:57 AM
              0 responses
              9 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 07:17 AM
              0 responses
              13 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 05-02-2024, 08:06 AM
              0 responses
              19 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-30-2024, 12:17 PM
              0 responses
              22 views
              0 likes
              Last Post seqadmin  
              Working...
              X