Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JPreston
    Member
    • Jun 2013
    • 17

    #1

    Filtering SAM files by base quality (QUAL)?

    Hello,

    I need to filter my SAM/BAM files to remove bases below a certain base quality (QUAL) threshold, eg. Q30. Does anybody know if there any tools for this available?

    Thanks in advance!
  • Brian Bushnell
    Super Moderator
    • Jan 2014
    • 2709

    #2
    BBTools can discard reads from a sam file with average quality below a threshold:

    reformat.sh in=reads.sam out=filtered.sam maq=30

    However, pairing would get messed up, if the reads are paired. It's easier to do quality-related stuff on the fastq file, then map.

    Comment

    • JPreston
      Member
      • Jun 2013
      • 17

      #3
      OK thanks a lot! Do you know of any programs that can mask fastq bases by quality, rather than discarding the read?

      Comment

      • Brian Bushnell
        Super Moderator
        • Jan 2014
        • 2709

        #4
        The same tool can trim low-quality bases, rather than discarding reads:

        reformat.sh in=reads.fastq out=trimmed.fastq qtrim=rl trimq=30

        (include in2 and out2 if you have paired reads in 2 files)

        That command would trim the right and left sides of each read with a quality threshold of 30. Masking would be less useful, normally. And by the way, 30 is typically way too high of a threshold for trimming; I recommend around 10 for most uses.

        Comment

        • JPreston
          Member
          • Jun 2013
          • 17

          #5
          Thanks again. I need a way to keep all of the bases above the quality threshold, rather than trimming the ends. I also want the quality scores to be very high for this application. It should be straightforward to write a script to filter and premask a fastq file, but I was hoping there was already a tool for this available. I wasn't sure how to deal with the quality scores of the masked bases.

          Comment

          • Brian Bushnell
            Super Moderator
            • Jan 2014
            • 2709

            #6
            I'm not sure what you could do with fastq reads that have all bases with quality below some threshold masked... so I have not written anything to do that. What are you trying to accomplish?

            Comment

            • JPreston
              Member
              • Jun 2013
              • 17

              #7
              I am working on a method to call low-frequency SNPs in heterogeneous populations. The method is based on using overlapping paired-end reads to sequence each DNA molecule twice. This eliminates sequencing errors because an error will only occur in one of the reads. We use a program called SeqPrep to overlap the reads and generate a consensus sequence with very high quality. I have been using a program called LoFreq to call these low frequency SNPs but there is no way to filter the calls based on quality. I want to filter my reads by base quality in order to see how the various methods compare at various quality thresholds.
              Last edited by JPreston; 04-08-2014, 09:04 PM.

              Comment

              • Brian Bushnell
                Super Moderator
                • Jan 2014
                • 2709

                #8
                reformat.sh works with paired reads, it's just that the sam/bam format does not ensure paired reads are together, so it's possible for a read to be filtered out and its mate to be kept, which may or may not matter, depending on the application.

                I also have a program called "bbmerge" which will merge overlapped reads to create a consensus:

                bbmerge.sh in=read1.fq in2=read2.fq out=merged.fq outu=unmerged.fq

                It's very fast and much more accurate than another commonly used tool, Flash (I have not tried SeqPrep, though). The output (merged.fq) is no longer paired, because the merged reads only create 1 consensus sequence, so it seems odd to output two copies of it. So the bam file would be filled with single-ended reads anyway, at least for the reads that were successfully merged.

                Comment

                • GenoMax
                  Senior Member
                  • Feb 2008
                  • 7142

                  #9
                  It is odd that you are not doing your quality filtering up front. With SeqPrep you should be able to do that as you overlap the reads.

                  Comment

                  • JPreston
                    Member
                    • Jun 2013
                    • 17

                    #10
                    I do some quality filtering before mapping but I know of no program that will mask the bases rather than trim or remove the reads completely. I don't want to trim reads at such a high quality threshold because I will lose too many bases.
                    Also, I don't know of an option in seqprep that works to quality filter the output.

                    Comment

                    • yueluo
                      Member
                      • Aug 2013
                      • 82

                      #11
                      You can specify your threshold for base-trimming.
                      Anyway, what do you mean by masking bases?

                      Comment

                      • JPreston
                        Member
                        • Jun 2013
                        • 17

                        #12
                        By masking I mean replacing low quality bases with an N.

                        Comment

                        • JPreston
                          Member
                          • Jun 2013
                          • 17

                          #13
                          I used BBmap to trim the reads. It worked well. Thanks!

                          Comment

                          • Brian Bushnell
                            Super Moderator
                            • Jan 2014
                            • 2709

                            #14
                            Originally posted by JPreston View Post
                            I used BBmap to trim the reads. It worked well. Thanks!
                            You're welcome!

                            Comment

                            • MNMoller
                              Junior Member
                              • Oct 2018
                              • 3

                              #15
                              Dear JPreston

                              Did you find a solution to your problem. I have the same issue and is looking for a tool to filter out bases within a read with low quality value. The tool should be able to do this on the SAM file, or on the FASTQ file, as long as it wont affect the alignment; for example by replacing it with an N like you suggest.

                              Comment

                              Latest Articles

                              Collapse

                              • SEQadmin2
                                Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                                by SEQadmin2



                                CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                                Despite this, “CRISPR helped turn genome editing from a specialized technique into
                                ...
                                07-31-2026, 11:01 AM
                              • SEQadmin2
                                Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                                by SEQadmin2


                                Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                                The systematic characterization of the human proteome has
                                ...
                                07-20-2026, 11:48 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, 08-06-2026, 07:41 AM
                              0 responses
                              16 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 08-03-2026, 10:13 AM
                              0 responses
                              32 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-31-2026, 02:55 AM
                              0 responses
                              42 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-24-2026, 12:17 PM
                              0 responses
                              26 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...