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
                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
              25 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              28 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 09:21 AM
              0 responses
              24 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