NCBI C Toolkit Cross Reference

C/algo/blast/api/blast_returns.c


  1 /* $Id: blast_returns.c,v 1.38 2007/07/10 15:28:07 papadopo Exp $
  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 offical 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 *  Author: Ilya Dondoshansky
 25 * ===========================================================================*/
 26 
 27 /** @file blast_returns.c
 28  * Manipulating data returned from BLAST other than Seq-aligns
 29  */
 30 
 31 #ifndef SKIP_DOXYGEN_PROCESSING
 32 static char const rcsid[] = "$Id: blast_returns.c,v 1.38 2007/07/10 15:28:07 papadopo Exp $";
 33 #endif /* SKIP_DOXYGEN_PROCESSING */
 34 
 35 #include <algo/blast/api/blast_returns.h>
 36 #include <algo/blast/api/blast_seq.h>
 37 #include <algo/blast/core/blast_filter.h>
 38 #include <algo/blast/core/blast_util.h>
 39 #include <algo/blast/core/pattern.h>
 40 
 41 /** @addtogroup CToolkitAlgoBlast
 42  *
 43  * @{
 44  */
 45 
 46 TxDfDbInfo* Blast_GetDbInfo(ReadDBFILE* rdfp)
 47 {
 48    TxDfDbInfo* dbinfo = NULL;
 49    char* chptr = NULL;
 50 
 51    if (!rdfp)
 52       return NULL;
 53 
 54    dbinfo = calloc(1, sizeof(TxDfDbInfo));
 55 
 56    dbinfo->name = strdup(readdb_get_filename(rdfp));
 57       
 58    if (((chptr = readdb_get_title(rdfp)) == NULL) && dbinfo->name)
 59       dbinfo->definition = strdup(dbinfo->name);
 60    else
 61       dbinfo->definition = strdup(chptr);       
 62       
 63    dbinfo->date = strdup(readdb_get_date(rdfp));
 64 
 65    dbinfo->is_protein = readdb_is_prot(rdfp);
 66      
 67    readdb_get_totals_ex(rdfp, &dbinfo->total_length, &dbinfo->number_seqs, TRUE);
 68    
 69    return dbinfo;
 70 }
 71 
 72 char*
 73 Blast_GetParametersBuffer(EBlastProgramType program_number, 
 74         const Blast_SummaryReturn* sum_returns)
 75 {
 76    char buffer[128];
 77    char* ret_buffer=NULL;
 78    Int2 ret_buffer_length=0;
 79    BlastUngappedStats* ungapped_stats = NULL;
 80    BlastGappedStats* gapped_stats = NULL;
 81    BlastRawCutoffs* raw_cutoffs = NULL;
 82    Blast_SearchParams* search_params=NULL;
 83    Blast_DatabaseStats* db_stats = NULL;
 84    BlastDiagnostics* diagnostics = NULL;
 85    
 86 
 87    if (!sum_returns || !sum_returns->search_params || !sum_returns->db_stats)
 88      return NULL;
 89 
 90    search_params = sum_returns->search_params;
 91    db_stats = sum_returns->db_stats;
 92    diagnostics = sum_returns->diagnostics;
 93 
 94    if (diagnostics) {
 95       ungapped_stats = diagnostics->ungapped_stat;
 96       gapped_stats = diagnostics->gapped_stat;
 97       raw_cutoffs = diagnostics->cutoffs;
 98    }
 99 
100    if (program_number == eBlastTypeBlastn ||
101        program_number == eBlastTypePhiBlastn)
102    {
103       sprintf(buffer, "Matrix: blastn matrix:%d %d", search_params->match, search_params->mismatch);
104       add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
105    } 
106    else if (search_params->matrix) 
107    {
108       sprintf(buffer, "Matrix: %s", search_params->matrix);
109       add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
110    }
111 
112    if (search_params->gapped_search) {
113       sprintf(buffer, "Gap Penalties: Existence: %ld, Extension: %ld",
114               (long) search_params->gap_open, 
115               (long) search_params->gap_extension);
116       add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
117    }
118    
119    sprintf(buffer, "Number of Sequences: %ld", (long) db_stats->dbnum);
120    add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
121 
122    if (ungapped_stats) {
123       sprintf(buffer, "Number of Hits to DB: %s", 
124               Nlm_Int8tostr(ungapped_stats->lookup_hits, 1));
125       add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
126    
127       if (ungapped_stats->init_extends) {
128           sprintf(buffer, "Number of extensions: %ld", 
129                   (long) ungapped_stats->init_extends);
130           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
131       }
132       if (ungapped_stats->good_init_extends) {
133           sprintf(buffer, "Number of successful extensions: %ld", 
134                   (long) ungapped_stats->good_init_extends);
135           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
136       }
137    }
138 
139    if (gapped_stats) {
140       if (search_params->expect > 0.1) {
141          sprintf(buffer, "Number of sequences better than %4.1f: %ld", 
142                  search_params->expect, 
143                  (long) gapped_stats->num_seqs_passed);
144       } else {
145          sprintf(buffer, "Number of sequences better than %3.1e: %ld", 
146                  search_params->expect, 
147                  (long) gapped_stats->num_seqs_passed);
148       }
149       add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
150    
151       if (search_params->gapped_search) {
152           if (gapped_stats->seqs_ungapped_passed) {
153               sprintf(buffer, 
154                       "Number of HSP's better than %4.1f without gapping: %ld", 
155                       search_params->expect, 
156                       (long) gapped_stats->seqs_ungapped_passed);
157               add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
158           }
159           sprintf(buffer, "Number of HSP's gapped: %ld", 
160                   (long) gapped_stats->extensions);
161           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
162           sprintf(buffer, "Number of HSP's successfully gapped: %ld", 
163                   (long) gapped_stats->good_extensions);
164           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
165       }
166    }
167 
168    /* Query length makes sense only for single query sequence. */
169    if (db_stats->qlen > 0) {
170        sprintf(buffer, "Length of query: %ld", (long)db_stats->qlen);
171        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
172    }
173    
174    sprintf(buffer, "Length of database: %s", 
175            Nlm_Int8tostr (db_stats->dblength, 1));
176    add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
177    
178    if (db_stats->qlen > 0) {
179        sprintf(buffer, "Length adjustment: %ld", (long) db_stats->hsp_length);
180        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
181        
182        sprintf(buffer, "Effective length of query: %ld", 
183                (long) db_stats->eff_qlen);
184        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
185        
186        sprintf(buffer, "Effective length of database: %s", 
187                Nlm_Int8tostr (db_stats->eff_dblength , 1));
188        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
189        sprintf(buffer, "Effective search space: %8.0f", 
190                (double) db_stats->eff_searchsp);
191        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
192        sprintf(buffer, "Effective search space used: %8.0f", 
193                (double) db_stats->eff_searchsp_used);
194        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
195    }
196    if (search_params->threshold) {
197        if (search_params->threshold == floor(search_params->threshold))
198            sprintf(buffer, "Neighboring words threshold: %ld", 
199                    (long)search_params->threshold);
200        else
201            sprintf(buffer, "Neighboring words threshold: %.2f", 
202                    search_params->threshold);
203        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
204    }
205    if (search_params->window_size) {
206        sprintf(buffer, "Window for multiple hits: %ld", 
207                (long) search_params->window_size);
208        add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
209    }
210    if (raw_cutoffs) {
211       BLAST_KAParameters* ka_params_gap = sum_returns->ka_params_gap;
212       BLAST_KAParameters* ka_params = sum_returns->ka_params;
213 
214       if (raw_cutoffs->x_drop_ungapped) {
215           sprintf(buffer, "X1: %ld (%4.1f bits)", 
216                   (long)raw_cutoffs->x_drop_ungapped, 
217                   (raw_cutoffs->x_drop_ungapped)*(ka_params->Lambda)/NCBIMATH_LN2);
218           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
219       }
220       if (search_params->gapped_search) {
221          sprintf(buffer, "X2: %ld (%4.1f bits)", 
222                  (long)raw_cutoffs->x_drop_gap, raw_cutoffs->x_drop_gap*(ka_params_gap->Lambda)/NCBIMATH_LN2);
223          add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
224          sprintf(buffer, "X3: %ld (%4.1f bits)", 
225                  (long)raw_cutoffs->x_drop_gap_final, 
226                  raw_cutoffs->x_drop_gap_final*(ka_params_gap->Lambda) /
227                  NCBIMATH_LN2);
228          add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
229       
230          if (raw_cutoffs->ungapped_cutoff) {
231              sprintf(buffer, "S1: %ld (%4.1f bits)", 
232                      (long)raw_cutoffs->ungapped_cutoff, 
233                      ((raw_cutoffs->ungapped_cutoff*(ka_params->Lambda)) -
234                       (log(ka_params->K)))/NCBIMATH_LN2);
235              add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
236          }
237       }
238       if (raw_cutoffs->cutoff_score) {
239           if (search_params->gapped_search) {
240               sprintf(buffer, "S2: %ld (%4.1f bits)", 
241                       (long) raw_cutoffs->cutoff_score, 
242                       (((raw_cutoffs->cutoff_score)*(ka_params_gap->Lambda)) -
243                        (log(ka_params_gap->K)))/NCBIMATH_LN2);
244           } else {
245               sprintf(buffer, "S2: %ld (%4.1f bits)", 
246                       (long) raw_cutoffs->cutoff_score, 
247                       (((raw_cutoffs->cutoff_score)*(ka_params->Lambda)) - 
248                        (log(ka_params->K)))/NCBIMATH_LN2);
249           }
250           add_string_to_buffer(buffer, &ret_buffer, &ret_buffer_length);
251       }
252    }
253 
254    return ret_buffer;
255 }
256 
257 /** Save the Karlin-Altschul parameters calculated in the BLAST search.
258  * @param sbp Internal scoring block structure [in]
259  * @param query_info info about query for use in fetching 
260  *                Karlin-Altschul parameters [in]
261  * @param sum_returns Returns summary structure [out]
262 */
263 static void 
264 s_SummaryKAParametersFill(const BlastScoreBlk* sbp, const BlastQueryInfo* query_info,
265                           Blast_SummaryReturn* sum_returns)
266 {
267    Blast_KarlinBlk* kbp;
268    int index;
269    int context = -1;
270 
271    if (!sbp || !query_info)
272       return;
273 
274     for (index=query_info->first_context; index<=query_info->last_context; index++)
275        if (query_info->contexts[index].is_valid == TRUE)
276        {
277           context = index;
278           break;
279        }
280  
281    if (sbp->kbp) {
282         sum_returns->ka_params = 
283              (BLAST_KAParameters*) calloc(1, sizeof(BLAST_KAParameters));
284         if (context >= 0)
285         {
286           kbp = sbp->kbp[context];
287           sum_returns->ka_params->Lambda = kbp->Lambda;
288           sum_returns->ka_params->K = kbp->K;
289           sum_returns->ka_params->H = kbp->H;
290         }
291         else
292         {
293           sum_returns->ka_params->Lambda = -1.0;
294           sum_returns->ka_params->K = -1.0;
295           sum_returns->ka_params->H = -1.0;
296         }
297    }
298 
299    if (sbp->kbp_gap) {
300         sum_returns->ka_params_gap = 
301              (BLAST_KAParameters*) calloc(1, sizeof(BLAST_KAParameters));
302         if (context >= 0)
303         {
304           kbp = sbp->kbp_gap[context];
305           sum_returns->ka_params_gap->Lambda = kbp->Lambda;
306           sum_returns->ka_params_gap->K = kbp->K;
307           sum_returns->ka_params_gap->H = kbp->H;
308           sum_returns->ka_params_gap->C = kbp->paramC; /* Needed only in PHI BLAST */
309         }
310         else
311         {
312           sum_returns->ka_params_gap->Lambda = -1.0;
313           sum_returns->ka_params_gap->K = -1.0;
314           sum_returns->ka_params_gap->H = -1.0;
315           sum_returns->ka_params_gap->C = -1.0;
316         }
317    }
318 }
319 
320 /** Frees Blast_DatabaseStats object
321  * @param db_stats object to be freed [in]
322  * @return NULL pointer 
323  */
324 static Blast_DatabaseStats*
325 s_SummaryDBStatsFree(Blast_DatabaseStats* db_stats)
326 {
327     sfree(db_stats);
328     return NULL;
329 }
330 
331 /** Allocates and fills in Blast_DatabaseStats
332  * @param program_number blastn/blastp/etc. [in]
333  * @param eff_len_options pointer to effective length options [in]
334  * @param query_info information about query [in]
335  * @param seq_src Source of subject sequences [in]
336  * @param db_stats object to be returned [out]
337  * @return zero on success
338  */
339 static Int2 
340 s_SummaryDBStatsFill(EBlastProgramType program_number, 
341    const BlastEffectiveLengthsOptions* eff_len_options,
342    const BlastQueryInfo* query_info, const BlastSeqSrc* seq_src,
343    Blast_DatabaseStats** db_stats)
344 {
345    Int8 total_length=0;  /* total length of database. */
346    Int4 num_entries=0;   /* number of entries in database. */
347    Int4 num_frames;      /* number of frames allowed. */
348    
349 
350    ASSERT(db_stats);
351 
352    *db_stats = (Blast_DatabaseStats*) calloc(1, sizeof(Blast_DatabaseStats));
353    if (*db_stats == NULL)
354      return -1;
355 
356    if (eff_len_options->db_length) {
357       total_length = eff_len_options->db_length;
358    } else {
359       total_length = BlastSeqSrcGetTotLen(seq_src);
360 
361       if (total_length == 0) {
362          /* If total length cannot be retrieved directly, calculate it by
363             adding individual sequence lengths. */
364          BlastSeqSrcIterator* itr = BlastSeqSrcIteratorNew();
365          Int4 oid;
366          while ( (oid = BlastSeqSrcIteratorNext(seq_src, itr)) 
367                  != BLAST_SEQSRC_EOF) {
368             total_length += BlastSeqSrcGetSeqLen(seq_src, (void*) &oid);
369          }
370          itr = BlastSeqSrcIteratorFree(itr);
371       }
372    }
373 
374    if (Blast_SubjectIsTranslated(program_number) ||
375        program_number == eBlastTypeRpsTblastn)
376       total_length /= 3;
377 
378    (*db_stats)->dblength = total_length;
379 
380 
381    if (eff_len_options->dbseq_num)
382       num_entries = eff_len_options->dbseq_num;
383    else
384       num_entries = BlastSeqSrcGetNumSeqs(seq_src);
385 
386    (*db_stats)->dbnum = num_entries;
387 
388    if (program_number == eBlastTypeBlastx ||
389        program_number == eBlastTypeRpsTblastn ||
390        program_number == eBlastTypeTblastx)
391       num_frames = NUM_FRAMES;
392    else if (program_number == eBlastTypeBlastn ||
393             program_number == eBlastTypePhiBlastn)
394       num_frames = 2;
395    else
396       num_frames = 1;
397 
398    
399    if (query_info->last_context < num_frames) {  /* Only one query here. */
400       Int4 qlen = query_info->contexts[query_info->first_context].query_length;
401       (*db_stats)->hsp_length = 
402           query_info->contexts[query_info->first_context].length_adjustment;
403       /** FIXME: Should this be different for RPS BLAST? */
404       (*db_stats)->qlen = qlen;
405       (*db_stats)->eff_qlen = qlen - ((*db_stats)->hsp_length);
406       (*db_stats)->eff_dblength = total_length;
407       if (eff_len_options->db_length == 0) {
408          (*db_stats)->eff_dblength -= (Int8)num_entries *
409                                         ((*db_stats)->hsp_length);
410       }
411       (*db_stats)->eff_searchsp = 
412           query_info->contexts[query_info->first_context].eff_searchsp;
413       if (eff_len_options && 
414           eff_len_options->num_searchspaces &&
415           eff_len_options->searchsp_eff[0])
416          (*db_stats)->eff_searchsp_used = eff_len_options->searchsp_eff[0];
417       else
418          (*db_stats)->eff_searchsp_used = (*db_stats)->eff_searchsp;
419    }
420 
421    return 0;
422 }
423 
424 /** Free Blast_SearchParams structure and underlying data
425  *
426  * @param search_params the object to be freed [in]
427  * @return NULL pointer 
428  */
429 static Blast_SearchParams*
430 s_SummarySearchParamsFree(Blast_SearchParams* search_params)
431 {
432 
433    if (search_params == NULL)
434       return NULL;
435 
436    sfree(search_params->matrix);
437    sfree(search_params->entrez_query);
438    sfree(search_params->filter_string);
439    sfree(search_params->pattern);
440    sfree(search_params);
441 
442    return NULL;
443 }
444 
445 /** Allocated and fills some search parameters.  
446  * 
447  * @param program_number identifies blastn/blastp/etc. [in]
448  * @param score_options pointer to scoring options [in]
449  * @param lookup_options pointer to options for lookup table creation [in]
450  * @param hit_options options for saving and evaluating hits [in]
451  * @param query_setup options for filtering etc. [in]
452  * @param word_options options for processing initial hits [in]
453  * @param entrez_query limit search by this query [in]
454  * @param search_params object to be allocated and filled [out]
455  * @return zero on success
456  */
457 Int2 
458 Blast_SearchParamsFill(EBlastProgramType program_number,
459    const BlastScoringOptions* score_options,
460    const LookupTableOptions* lookup_options,
461    const BlastHitSavingOptions* hit_options,
462    const QuerySetUpOptions* query_setup, 
463    const BlastInitialWordOptions* word_options,
464    const char* entrez_query,
465    Blast_SearchParams** search_params)
466 {
467    Blast_SearchParams* search_params_lcl;
468 
469    ASSERT(search_params);
470    ASSERT(score_options && lookup_options && hit_options && query_setup);
471 
472    *search_params = search_params_lcl = (Blast_SearchParams*) calloc(1, sizeof(Blast_SearchParams));
473    if (search_params_lcl == NULL)
474      return -1;
475 
476    if (program_number == eBlastTypeBlastn ||
477        program_number == eBlastTypePhiBlastn)
478    {
479       search_params_lcl->match = score_options->reward;
480       search_params_lcl->mismatch = score_options->penalty;
481    } 
482    else if (score_options->matrix) 
483    {
484       search_params_lcl->matrix = StringSave(score_options->matrix);
485    }
486 
487    if (score_options->gapped_calculation) 
488    {
489       search_params_lcl->gapped_search = TRUE;
490       search_params_lcl->gap_open = score_options->gap_open;
491       search_params_lcl->gap_extension = score_options->gap_extend;
492    }
493    else
494       search_params_lcl->gapped_search = FALSE;
495 
496    if (query_setup && query_setup->filter_string)
497       search_params_lcl->filter_string = StringSave(query_setup->filter_string);
498    else
499       search_params_lcl->filter_string = StringSave("F");
500 
501    search_params_lcl->expect = hit_options->expect_value;
502 
503    if (lookup_options->phi_pattern)
504       search_params_lcl->pattern = StringSave(lookup_options->phi_pattern); 
505 
506    search_params_lcl->threshold = lookup_options->threshold;
507 
508    search_params_lcl->window_size = word_options->window_size;
509 
510    if (entrez_query)
511       search_params_lcl->entrez_query = StringSave(entrez_query);
512 
513    return 0;
514 }
515 
516 Blast_SummaryReturn* Blast_SummaryReturnNew()
517 {
518     return (Blast_SummaryReturn*) calloc(1, sizeof(Blast_SummaryReturn));
519 }
520 
521 void 
522 Blast_SummaryReturnClean(Blast_SummaryReturn* sum_returns)
523 {
524    if (sum_returns) {
525       sfree(sum_returns->ka_params);
526       sfree(sum_returns->ka_params_gap);
527       sum_returns->db_stats = s_SummaryDBStatsFree(sum_returns->db_stats);
528       sum_returns->search_params = 
529           s_SummarySearchParamsFree(sum_returns->search_params);
530       sum_returns->diagnostics = Blast_DiagnosticsFree(sum_returns->diagnostics);
531       sum_returns->error = SBlastMessageFree(sum_returns->error);
532       sum_returns->pattern_info = 
533           SPHIQueryInfoFree(sum_returns->pattern_info);
534    }
535 }
536 
537 Blast_SummaryReturn* 
538 Blast_SummaryReturnFree(Blast_SummaryReturn* sum_returns)
539 {
540     Blast_SummaryReturnClean(sum_returns);
541     sfree(sum_returns);
542     return NULL;
543 }
544 
545 Int2 Blast_SummaryReturnFill(EBlastProgramType program_number, 
546         const BlastScoringOptions* score_options, 
547         const BlastScoreBlk* sbp,
548         const LookupTableOptions* lookup_options,
549         const BlastInitialWordOptions* word_options,
550         const BlastExtensionOptions* ext_options,
551         const BlastHitSavingOptions* hit_options,
552         const BlastEffectiveLengthsOptions* eff_len_options,
553         const QuerySetUpOptions* query_setup,
554         const BlastQueryInfo* query_info,
555         const BlastSeqSrc* seq_src,
556         BlastDiagnostics** diagnostics,
557         Blast_SummaryReturn* sum_returns)
558 {
559     if (!sum_returns)
560         return -1;
561 
562    if (score_options == NULL || sbp == NULL || lookup_options == NULL || 
563       word_options == NULL || ext_options == NULL || hit_options == NULL ||
564       eff_len_options == NULL || query_info == NULL)
565      return -1;
566 
567    s_SummaryKAParametersFill(sbp, query_info, sum_returns);
568    s_SummaryDBStatsFill(program_number, eff_len_options, query_info, 
569                             seq_src, &(sum_returns->db_stats));
570    
571    Blast_SearchParamsFill(program_number, score_options,
572             lookup_options, hit_options, query_setup, word_options,
573             NULL, &(sum_returns->search_params));
574    if (diagnostics)
575    {
576       sum_returns->diagnostics = *diagnostics;
577       *diagnostics = NULL;
578    }
579 
580    if (Blast_ProgramIsPhiBlast(program_number)) {
581        /* Copy the pattern information structure. */
582        sum_returns->pattern_info = 
583            SPHIQueryInfoCopy(query_info->pattern_info);
584    }
585 
586    return 0;
587 }
588 
589 /** Duplicates the Blast_SearchParams structure.
590  * @param params Search parameters structure [in]
591  * @return New copy of the search parameters structure.
592  */
593 static Blast_SearchParams* 
594 s_SearchParamsDup(const Blast_SearchParams* params)
595 {
596     Blast_SearchParams* new_params;
597 
598     if (!params)
599         return NULL;
600 
601     new_params = (Blast_SearchParams*)
602         BlastMemDup(params, sizeof(Blast_SearchParams));
603     if (params->filter_string)
604         new_params->filter_string = strdup(params->filter_string);
605     if (params->matrix)
606         new_params->matrix = strdup(params->matrix);
607     if (params->pattern)
608         new_params->pattern = strdup(params->pattern);
609     if (params->entrez_query)
610         new_params->entrez_query = strdup(params->entrez_query);
611 
612     return new_params;
613 }
614 
615 int Blast_SummaryReturnUpdate(const Blast_SummaryReturn* new_return,
616                               Blast_SummaryReturn* *full_return_out)
617 {
618     Blast_SummaryReturn* full_return;
619  
620     if (!new_return)
621         return 0;
622     if (!full_return_out)
623         return -1;
624 
625     /* If aggregate returns have not been allocated yet, do it here. Otherwise,
626      * remove all previously saved data, except for the diagnostics structure.
627      * Note that diagnostics structure must be allocated before the call to 
628      * Blast_DiagnosticsUpdate.
629      */
630     if (*full_return_out == NULL) {
631         *full_return_out = full_return = Blast_SummaryReturnNew();
632         full_return->diagnostics = Blast_DiagnosticsInit();
633     } else {
634         BlastDiagnostics* diagnostics;
635         full_return = *full_return_out;
636         /* Save the diagnostics structure before cleaning the previous data. */
637         diagnostics = full_return->diagnostics;
638         full_return->diagnostics = NULL;
639         Blast_SummaryReturnClean(full_return);
640         full_return->diagnostics = diagnostics;
641     }
642 
643     full_return->ka_params = (BLAST_KAParameters*) 
644         BlastMemDup(new_return->ka_params, sizeof(BLAST_KAParameters));
645     full_return->ka_params_gap = (BLAST_KAParameters*) 
646         BlastMemDup(new_return->ka_params_gap, sizeof(BLAST_KAParameters));
647     full_return->db_stats = (Blast_DatabaseStats*) 
648         BlastMemDup(new_return->db_stats, sizeof(Blast_DatabaseStats));
649     full_return->search_params = 
650         s_SearchParamsDup(new_return->search_params);
651 
652     Blast_DiagnosticsUpdate(full_return->diagnostics, new_return->diagnostics);
653     
654     if (new_return->error)
655         full_return->error = SBlastMessageDup(new_return->error);
656 
657     full_return->pattern_info = SPHIQueryInfoCopy(new_return->pattern_info);
658 
659     return 0;
660 }
661 
662 /* @} */
663 
664 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.