Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kga1978
    Senior Member
    • Nov 2010
    • 100

    #1

    BLAST filtering out 'no hits' in output

    Hi,

    I am using a local install of blastn to look for hits to a custom database from a bunch of short reads. In my final output file, I really only care about reads that found a 'hit' and so want to filter out all reads with 'no hits'. My strategy is as follows:

    Read 1
    Read 2
    .
    .
    Read X

    -> Put into one big FASTA file
    -> Run blastn against the custom database
    -> Save to file reads with hits only.

    Right now (the standard blast output) would be:
    Read 1 -> hit 1
    Read 2 -> no hit
    . -> no hit
    . -> no hit
    Read X -> hit X

    But I want my output to only show:
    Read 1 -> hit 1
    Read x -> hit X

    Since I have many reads and very few hits, my output file very rapidly gets filled with all the 'no hits' reads slowing down the whole process. Is there a way to filter my output directly via the command line, or do I need to build a script to do this?

    Thanks in advance,
    Kristian
  • maubp
    Peter (Biopython etc)
    • Jul 2009
    • 1544

    #2
    I would use the tabular output, which just writes nothing at all for no hits.

    Comment

    • kga1978
      Senior Member
      • Nov 2010
      • 100

      #3
      Hmm, tried that and I get the following error:
      BLAST query/options error: No hits are being saved

      I run the following command:
      blastn -query reads.fasta -db nt -num_descriptions 1 -num_alignments 0 -out reads_blastNT.txt -num_threads 8 -outfmt 6

      Instead of "-outfmt 6", I have also used:
      "7 sseqid ssac qstart qend sstart send qseq evalue bitscore"

      but I get the same result. Any thoughts? The output file is also empty.

      Thanks very much.

      Comment

      • kga1978
        Senior Member
        • Nov 2010
        • 100

        #4
        Okay, so I solved the error, which was caused by my "-num_alignments 0" handle. However, the output still contains my reads with no hits - it just writes '0 hits found' under the read. This is not what I am after - I want to completely ignore '0 hits' reads so they don't even get written to the file.

        Comment

        • maubp
          Peter (Biopython etc)
          • Jul 2009
          • 1544

          #5
          What exactly is the new command line you are running?

          Comment

          • kga1978
            Senior Member
            • Nov 2010
            • 100

            #6
            Hi maubp.

            Sorry, I don't understand that question - I'm not running a new command line - I'm just trying to figure out whether I can tell blastn not to store my 'no hits' hits in the output file.

            Comment

            • maubp
              Peter (Biopython etc)
              • Jul 2009
              • 1544

              #7
              I would expect you to use something like this command line:

              blastn -query reads.fasta -db nt -out reads_blastNT.txt -num_threads 8 -outfmt 6

              Rather than messing about with -num_descriptions and/or -num_alignments which only really apply to the plain text and HTML output, from memory I would use -max_target_seqs instead.

              Comment

              • kga1978
                Senior Member
                • Nov 2010
                • 100

                #8
                I tried that one, but I still have the same problem - the '0 hits' hits are still recorded in the output file, rather than discarded.

                I guess I just have to pipe it and make a script - but it would have been easier if it could have been done directly from the command line.

                Comment

                • maubp
                  Peter (Biopython etc)
                  • Jul 2009
                  • 1544

                  #9
                  I am surprised. What version of BLAST+ do you have? And could you post a bit of the example output?

                  Comment

                  • kga1978
                    Senior Member
                    • Nov 2010
                    • 100

                    #10
                    I should have the newest version:
                    blastn: 2.2.25+
                    Package: blast 2.2.25, build Mar 21 2011 12:21:32

                    An example output looks like this (tabular format):
                    # BLASTN 2.2.25+
                    # Query: ILLUMINA:203:C07LRACXX:5:1101:1348:1952 1:N:0:TAGCTT
                    # Database: custom
                    # 0 hits found
                    # BLASTN 2.2.25+
                    # Query: ILLUMINA:203:C07LRACXX:5:1101:1366:1952 1:Y:0:TAGCTT
                    # Database: custom
                    # 0 hits found
                    # BLASTN 2.2.25+
                    # Query: ILLUMINA:203:C07LRACXX:5:1101:1472:1955 1:N:0:TAGCTT
                    # Database: custom
                    # 0 hits found
                    # BLASTN 2.2.25+
                    # Query: ILLUMINA:203:C07LRACXX:5:1101:1456:1981 1:N:0:TAGCTT
                    # Database: custom
                    # 0 hits found
                    # BLASTN 2.2.25+
                    # Query: ILLUMINA:203:C07LRACXX:5:1101:1414:1981 1:N:0:TAGCTT
                    # Database: custom
                    # 0 hits found

                    Basically, these are all the reads I don't want listed in the file as they have no hits.

                    Thanks a bunch.

                    Comment

                    • maubp
                      Peter (Biopython etc)
                      • Jul 2009
                      • 1544

                      #11
                      All those lines starting with a hash (#) are comments which you asked BLAST to produce by using -outfmt 7,
                      Code:
                      $ blastn -help
                      ...
                       *** Formatting options
                       -outfmt <String>
                         alignment view options:
                           0 = pairwise,
                           1 = query-anchored showing identities,
                           2 = query-anchored no identities,
                           3 = flat query-anchored, show identities,
                           4 = flat query-anchored, no identities,
                           5 = XML Blast output,
                           6 = tabular,
                           7 = tabular with comment lines,
                           8 = Text ASN.1,
                           9 = Binary ASN.1,
                          10 = Comma-separated values,
                          11 = BLAST archive format (ASN.1)
                      Use -outfmt 6 as I suggested, and they'll go away.

                      P.S. That does mean for this example as there are no hits at all, the output file will be empty.

                      Comment

                      • kga1978
                        Senior Member
                        • Nov 2010
                        • 100

                        #12
                        Yes! That worked - thanks so much. I skipped the -outfmt 6 handle when it initially failed due to my "-num_alignments 0".

                        Thanks for your help - that's exactly what I needed.

                        Comment

                        • maubp
                          Peter (Biopython etc)
                          • Jul 2009
                          • 1544

                          #13
                          Great

                          Thanks for confirming it worked.

                          Comment

                          • jmjensen
                            Junior Member
                            • Sep 2011
                            • 3

                            #14
                            I made the same mistake just now by choosing -outfmt 7

                            However, it's a rather easy fix to remove the comments:

                            Code:
                            awk '!/^\#/' file > newfile
                            Should do the trick.
                            Last edited by jmjensen; 06-01-2013, 12:50 AM.

                            Comment

                            • JonB
                              Member
                              • Jan 2010
                              • 85

                              #15
                              This is maybe not the right thread, but I am interested in only the queries with 'no hits'. So far I can only extract the reads with hits, and then compare the differences between the original query file and the file with hits only.

                              Any good tips on how to directly extract the queries with no hits?

                              Thanks, Jon

                              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
                              15 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 08-03-2026, 10:13 AM
                              0 responses
                              31 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-31-2026, 02:55 AM
                              0 responses
                              41 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...