diff --git a/hits.cc b/hits.cc index cf96e4c..548cb8f 100644 --- a/hits.cc +++ b/hits.cc @@ -34,6 +34,7 @@ long obvious; long opt_descriptions; long opt_alignments; +long opt_show_best; /* parameters for bit scores and expect values */ @@ -189,7 +190,26 @@ void hits_enter(long seqno, long score, long qstrand, long qframe, ((score == hits_list[place-1].score) && (seqno > hits_list[place-1].seqno)))) place--; - + + long Nbest = 1; + if (place > 0) + { + if (score < hits_list[place-1].score) + Nbest++; + + for (long j=(place-1); j>0; j--) + { + if (hits_list[j].score < hits_list[j-1].score) + Nbest++; + } + } + + if (Nbest > opt_show_best) + { + pthread_mutex_unlock(&hitsmutex); + return; + } + // move entries down long move = (hits_count < keephits ? hits_count : keephits - 1) - place; @@ -280,10 +300,11 @@ void hits_enter_align_string(long i, char * align, long align_len) // hits_list[i].alignment[align_len] = 0; } -void hits_init(long descriptions, long alignments, long minscore, long maxscore, double minexpect, double expect, int show_nostats) +void hits_init(long descriptions, long alignments, long show_best, long minscore, long maxscore, double minexpect, double expect, int show_nostats) { opt_descriptions = descriptions; opt_alignments = alignments; + opt_show_best = show_best; keephits = descriptions > alignments ? descriptions : alignments; long maxhits = db_getseqcount_masked(); @@ -2002,7 +2023,26 @@ void hits_show(long view, long show_gis) showalignments = hits_count; else showalignments = opt_alignments; + + long Nbest = 1; + long place = 1; + while (place < hits_count) + { + if (hits_list[place-1].score > hits_list[place].score) + Nbest++; + + if (Nbest <= opt_show_best) + place++; + else + break; + } + + if (showhits > place) + showhits = place; + if (showalignments > place) + showalignments = place; + struct db_thread_s * t = db_thread_create(); if(view == 0) diff --git a/swipe.cc b/swipe.cc index 3f75ce2..14587e9 100644 --- a/swipe.cc +++ b/swipe.cc @@ -28,6 +28,7 @@ /* ARGUMENTS AND THEIR DEFAULTS */ #define DEFAULT_MAXMATCHES 250 +#define DEFAULT_SHOW_BEST 250 #define DEFAULT_ALIGNMENTS 100 #define DEFAULT_MINSCORE 1 #define DEFAULT_MAXSCORE (LONG_MAX) @@ -64,6 +65,7 @@ double expect; double minexpect; long minscore; long maxscore; +long show_best; long alignments; long maxmatches; long gapopen; @@ -739,6 +741,7 @@ void args_show() fprintf(out, "Min score shown: %ld\n", minscore); fprintf(out, "Max matches shown: %ld\n", maxmatches); fprintf(out, "Alignments shown: %ld\n", alignments); + fprintf(out, "Best scores shown: %ld\n", show_best); fprintf(out, "Show gi's: %ld\n", show_gis); fprintf(out, "Show taxid's: %ld\n", show_taxid); fprintf(out, "Threads: %ld\n", threads); @@ -796,6 +799,7 @@ void args_usage() fprintf(out, " -G, --gapopen=NUM gap open penalty (11)\n"); fprintf(out, " -E, --gapextend=NUM gap extension penalty (1)\n"); fprintf(out, " -v, --num_descriptions=NUM sequence descriptions to show (250)\n"); + fprintf(out, " -B, --show_best=NUM number of different scoring sequences to show (250)\n"); fprintf(out, " -b, --num_alignments=NUM sequence alignments to show (100)\n"); fprintf(out, " -e, --evalue=REAL maximum expect value of sequences to show (10.0)\n"); fprintf(out, " -k, --minevalue=REAL minimum expect value of sequences to show (0.0)\n"); @@ -836,6 +840,7 @@ void args_init(int argc, char **argv) maxscore = DEFAULT_MAXSCORE; maxmatches = DEFAULT_MAXMATCHES; alignments = DEFAULT_ALIGNMENTS; + show_best = DEFAULT_SHOW_BEST; threads = DEFAULT_THREADS; view = DEFAULT_VIEW; symtype = DEFAULT_SYMTYPE; @@ -856,7 +861,7 @@ void args_init(int argc, char **argv) progname = argv[0]; opterr = 1; - char short_options[] = "d:i:M:q:r:G:E:S:v:b:c:u:e:k:a:m:p:x:C:Q:D:F:K:N:o:z:IHh"; + char short_options[] = "d:i:M:q:r:G:E:S:v:B:b:c:u:e:k:a:m:p:x:C:Q:D:F:K:N:o:z:IHh"; static struct option long_options[] = { @@ -869,6 +874,7 @@ void args_init(int argc, char **argv) {"gapextend", required_argument, NULL, 'E' }, {"strand", required_argument, NULL, 'S' }, {"num_descriptions", required_argument, NULL, 'v' }, + {"show_best", required_argument, NULL, 'B' }, {"num_alignments", required_argument, NULL, 'b' }, {"min_score", required_argument, NULL, 'c' }, {"max_score", required_argument, NULL, 'u' }, @@ -907,7 +913,12 @@ void args_init(int argc, char **argv) /* threads */ threads = atol(optarg); break; - + + case 'B': + /* show best */ + show_best = atol(optarg); + break; + case 'b': /* alignments */ alignments = atol(optarg); @@ -1157,6 +1168,9 @@ void args_init(int argc, char **argv) if ((dump<0) || (dump>2)) fatal("Illegal dump mode."); + + if (maxmatches < show_best) + maxmatches = show_best; translate_init(query_gencode, db_gencode); } @@ -1845,7 +1859,7 @@ void master(int size) /* init */ - hits_init(maxmatches, alignments, minscore, maxscore, minexpect, expect, view==0); + hits_init(maxmatches, alignments, show_best, minscore, maxscore, minexpect, expect, view==0); prepare_search(size-1); @@ -2179,7 +2193,7 @@ void slave(int rank, int size) // fprintf(out, "Node %d: SSE2: %ld SSSE3: %ld\n", rank, cpu_feature_sse2, cpu_feature_ssse3); // fprintf(out, "This is slave no %d.\n", rank); - hits_init(maxmatches, alignments, minscore, maxscore, minexpect, expect, 0); + hits_init(maxmatches, alignments, show_best, minscore, maxscore, minexpect, expect, 0); prepare_search(size-1); @@ -2436,7 +2450,7 @@ void slave(int rank, int size) void work() { args_show(); - hits_init(maxmatches, alignments, minscore, maxscore, minexpect, expect, view==0); + hits_init(maxmatches, alignments, show_best, minscore, maxscore, minexpect, expect, view==0); compute7 = 0; compute16 = 0; diff --git a/swipe.h b/swipe.h index 36c9dab..739c158 100644 --- a/swipe.h +++ b/swipe.h @@ -111,6 +111,7 @@ extern long maxmatches; extern long threads; extern const char * databasename; extern long alignments; +extern long show_best; extern long queryno; extern long compute7; extern long show_taxid; @@ -346,7 +347,7 @@ void db_getsequence(struct db_thread_s * t, long seqno, long strand, long frame, void db_getheader(struct db_thread_s * t, long seqno, char ** address, long * length); -void hits_init(long descriptions, long alignments, long minscore, +void hits_init(long descriptions, long alignments, long show_best, long minscore, long maxscore, double minexpect, double expect, int show_nostats); void hits_enter(long seqno, long score, long qstrand, long qframe, long dstrand, long dframe, long align_hint, long bestq);