1 /* $Id: blast_diagnostics.c 500404 2016-05-04 14:59:01Z camacho $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Ilya Dondoshansky
27 *
28 */
29
30 /** @file blast_diagnostics.c
31 * Manipulating diagnostics data returned from BLAST
32 */
33
34
35 #include <algo/blast/core/blast_diagnostics.h>
36 #include <algo/blast/core/blast_def.h>
37
Blast_DiagnosticsFree(BlastDiagnostics * diagnostics)38 BlastDiagnostics* Blast_DiagnosticsFree(BlastDiagnostics* diagnostics)
39 {
40 if (diagnostics) {
41 sfree(diagnostics->ungapped_stat);
42 sfree(diagnostics->gapped_stat);
43 sfree(diagnostics->cutoffs);
44 if (diagnostics->mt_lock)
45 diagnostics->mt_lock = MT_LOCK_Delete(diagnostics->mt_lock);
46 sfree(diagnostics);
47 }
48 return NULL;
49 }
50
Blast_DiagnosticsCopy(const BlastDiagnostics * diagnostics)51 BlastDiagnostics* Blast_DiagnosticsCopy(const BlastDiagnostics* diagnostics)
52 {
53 BlastDiagnostics* retval = NULL;
54 if (diagnostics == NULL) {
55 return retval;
56 }
57 retval = Blast_DiagnosticsInit();
58 if (diagnostics->ungapped_stat) {
59 memcpy((void*)retval->ungapped_stat, (void*)diagnostics->ungapped_stat,
60 sizeof(*retval->ungapped_stat));
61 } else {
62 sfree(diagnostics->ungapped_stat);
63 }
64 if (diagnostics->gapped_stat) {
65 memcpy((void*)retval->gapped_stat, (void*)diagnostics->gapped_stat,
66 sizeof(*retval->gapped_stat));
67 } else {
68 sfree(diagnostics->gapped_stat);
69 }
70 if (diagnostics->cutoffs) {
71 memcpy((void*)retval->cutoffs, (void*)diagnostics->cutoffs,
72 sizeof(*retval->cutoffs));
73 } else {
74 sfree(diagnostics->cutoffs);
75 }
76 return retval;
77 }
78
Blast_DiagnosticsInit()79 BlastDiagnostics* Blast_DiagnosticsInit()
80 {
81 BlastDiagnostics* diagnostics =
82 (BlastDiagnostics*) calloc(1, sizeof(BlastDiagnostics));
83
84 diagnostics->ungapped_stat =
85 (BlastUngappedStats*) calloc(1, sizeof(BlastUngappedStats));
86 diagnostics->gapped_stat =
87 (BlastGappedStats*) calloc(1, sizeof(BlastGappedStats));
88 diagnostics->cutoffs =
89 (BlastRawCutoffs*) calloc(1, sizeof(BlastRawCutoffs));
90
91 return diagnostics;
92 }
93
Blast_DiagnosticsInitMT(MT_LOCK mt_lock)94 BlastDiagnostics* Blast_DiagnosticsInitMT(MT_LOCK mt_lock)
95 {
96 BlastDiagnostics* retval = Blast_DiagnosticsInit();
97 retval->mt_lock = mt_lock;
98
99 return retval;
100 }
101
Blast_UngappedStatsUpdate(BlastUngappedStats * ungapped_stats,Int4 total_hits,Int4 extended_hits,Int4 saved_hits)102 void Blast_UngappedStatsUpdate(BlastUngappedStats* ungapped_stats,
103 Int4 total_hits, Int4 extended_hits,
104 Int4 saved_hits)
105 {
106 if (!ungapped_stats || total_hits == 0)
107 return;
108
109 ungapped_stats->lookup_hits += total_hits;
110 ++ungapped_stats->num_seqs_lookup_hits;
111 ungapped_stats->init_extends += extended_hits;
112 ungapped_stats->good_init_extends += saved_hits;
113 if (saved_hits > 0)
114 ++ungapped_stats->num_seqs_passed;
115 }
116
117 void
Blast_DiagnosticsUpdate(BlastDiagnostics * global,BlastDiagnostics * local)118 Blast_DiagnosticsUpdate(BlastDiagnostics* global, BlastDiagnostics* local)
119 {
120 if (!local)
121 return;
122
123 if (global->mt_lock)
124 MT_LOCK_Do(global->mt_lock, eMT_Lock);
125
126 if (global->ungapped_stat && local->ungapped_stat) {
127 global->ungapped_stat->lookup_hits +=
128 local->ungapped_stat->lookup_hits;
129 global->ungapped_stat->num_seqs_lookup_hits +=
130 local->ungapped_stat->num_seqs_lookup_hits;
131 global->ungapped_stat->init_extends +=
132 local->ungapped_stat->init_extends;
133 global->ungapped_stat->good_init_extends +=
134 local->ungapped_stat->good_init_extends;
135 global->ungapped_stat->num_seqs_passed +=
136 local->ungapped_stat->num_seqs_passed;
137 }
138
139 if (global->gapped_stat && local->gapped_stat) {
140 global->gapped_stat->seqs_ungapped_passed +=
141 local->gapped_stat->seqs_ungapped_passed;
142 global->gapped_stat->extensions +=
143 local->gapped_stat->extensions;
144 global->gapped_stat->good_extensions +=
145 local->gapped_stat->good_extensions;
146 global->gapped_stat->num_seqs_passed +=
147 local->gapped_stat->num_seqs_passed;
148 }
149
150 if (global->cutoffs && local->cutoffs) {
151 global->cutoffs->x_drop_ungapped = local->cutoffs->x_drop_ungapped;
152 global->cutoffs->x_drop_gap = local->cutoffs->x_drop_gap;
153 global->cutoffs->x_drop_gap_final = local->cutoffs->x_drop_gap_final;
154 global->cutoffs->ungapped_cutoff = local->cutoffs->ungapped_cutoff;
155 global->cutoffs->cutoff_score = local->cutoffs->cutoff_score;
156 }
157
158 if (global->mt_lock)
159 MT_LOCK_Do(global->mt_lock, eMT_Unlock);
160 }
161