SThreadLocalData* SThreadLocalDataFree(SThreadLocalData* tld) { if (tld) { /* Do not destruct score block here, it was just assigned */ if (tld->gap_align != NULL) { tld->gap_align->sbp = NULL; } tld->gap_align = BLAST_GapAlignStructFree(tld->gap_align); tld->score_params = BlastScoringParametersFree(tld->score_params); tld->ext_params = BlastExtensionParametersFree(tld->ext_params); tld->hit_params = BlastHitSavingParametersFree(tld->hit_params); tld->eff_len_params = BlastEffectiveLengthsParametersFree(tld->eff_len_params); tld->query_info = BlastQueryInfoFree(tld->query_info); tld->seqsrc = BlastSeqSrcFree(tld->seqsrc); tld->results = Blast_HSPResultsFree(tld->results); sfree(tld); } return NULL; }
/** Free the BlastHSPStream with its HSP list collector data structure. * @param hsp_stream The HSP stream to free [in] * @return NULL. */ BlastHSPStream* BlastHSPStreamFree(BlastHSPStream* hsp_stream) { int index=0; BlastHSPPipe *p; if (!hsp_stream) { return NULL; } hsp_stream->x_lock = MT_LOCK_Delete(hsp_stream->x_lock); Blast_HSPResultsFree(hsp_stream->results); for (index=0; index < hsp_stream->num_hsplists; index++) { hsp_stream->sorted_hsplists[index] = Blast_HSPListFree(hsp_stream->sorted_hsplists[index]); } sfree(hsp_stream->sort_by_score); sfree(hsp_stream->sorted_hsplists); if (hsp_stream->writer) { (hsp_stream->writer->FreeFnPtr) (hsp_stream->writer); hsp_stream->writer = NULL; } /* free un-used pipes */ while (hsp_stream->pre_pipe) { p = hsp_stream->pre_pipe; hsp_stream->pre_pipe = p->next; sfree(p); } while (hsp_stream->tback_pipe) { p = hsp_stream->tback_pipe; hsp_stream->tback_pipe = p->next; sfree(p); } sfree(hsp_stream); return NULL; }
Int2 PHIBlastRunSearch(SeqLoc* query_seqloc, char* db_name, SeqLoc* masking_locs, const SBlastOptions* options, ValNode* *phivnps, SeqLoc** filter_out, Blast_SummaryReturn* extra_returns) { BlastSeqSrc *seq_src = NULL; Boolean is_prot; Int2 status = 0; BlastHSPResults* results = NULL; ReadDBFILE* rdfp = NULL; if (!options || !query_seqloc || !db_name || !extra_returns || !phivnps) return -1; ASSERT(Blast_ProgramIsPhiBlast(options->program)); is_prot = (options->program == eBlastTypePhiBlastp); rdfp = readdb_new(db_name, is_prot); seq_src = ReaddbBlastSeqSrcAttach(rdfp); if (seq_src == NULL) { SBlastMessageWrite(&extra_returns->error, SEV_WARNING, "Initialization of subject sequences source failed", NULL, options->believe_query); } else { char* error_str = BlastSeqSrcGetInitError(seq_src); if (error_str) SBlastMessageWrite(&extra_returns->error, SEV_WARNING, error_str, NULL, options->believe_query); } /* If there was an error initializing the sequence source, return without doing the search. */ if (extra_returns->error) return -1; /* Masking at hash and on-the-fly tabular output are not applicable for PHI BLAST, so pass NULL in corresponding arguments. */ status = Blast_RunSearch(query_seqloc, (Blast_PsiCheckpointLoc *) NULL, seq_src, masking_locs, options, (BlastTabularFormatData*) NULL, &results, filter_out, extra_returns); /* The ReadDBFILE structure will not be destroyed here, because the initialising function used readdb_attach */ BlastSeqSrcFree(seq_src); *phivnps = NULL; if (!status) { status = s_PHIResultsToSeqAlign(results, extra_returns->pattern_info, options->program, query_seqloc, rdfp, phivnps); } results = Blast_HSPResultsFree(results); readdb_destruct(rdfp); return status; }
BlastHSPResults* SThreadLocalDataArrayConsolidateResults(SThreadLocalDataArray* array) { BlastHSPResults* retval = NULL; Int4 num_queries = 0, query_idx = 0, hitlist_size = 0; Uint4* num_hsplists_per_query = NULL; if ( !array ) { return retval; } num_hsplists_per_query = s_CountHspListsPerQuery(array, &num_queries); if ( !(retval = Blast_HSPResultsNew(num_queries)) ) { sfree(num_hsplists_per_query); return retval; } hitlist_size = array->tld[0]->hit_params->options->hitlist_size; for (query_idx = 0; query_idx < num_queries; query_idx++) { Uint4 tid = 0; BlastHitList* hits4query = retval->hitlist_array[query_idx] = Blast_HitListNew(hitlist_size); if ( !hits4query ) { retval = Blast_HSPResultsFree(retval); break; } hits4query->hsplist_array = (BlastHSPList**) calloc(num_hsplists_per_query[query_idx], sizeof(BlastHSPList*)); if ( !hits4query->hsplist_array ) { retval = Blast_HSPResultsFree(retval); break; } /* Consolidate the results for query_idx from all threads */ for (tid = 0; tid < array->num_elems; tid++) { BlastHSPResults* thread_results = array->tld[tid]->results; BlastHitList* thread_hitlist = thread_results->hitlist_array[query_idx]; Int4 i; if ( !thread_hitlist ) { continue; } /* transfer the BlastHSPList to the consolidated structure */ for (i = 0; i < thread_hitlist->hsplist_count; i++) { if ( !Blast_HSPList_IsEmpty(thread_hitlist->hsplist_array[i])) { hits4query->hsplist_array[hits4query->hsplist_count++] = thread_hitlist->hsplist_array[i]; thread_hitlist->hsplist_array[i] = NULL; } } hits4query->worst_evalue = !tid ? thread_hitlist->worst_evalue : MAX(thread_hitlist->worst_evalue, hits4query->worst_evalue); hits4query->low_score = !tid ? thread_hitlist->low_score : MAX(thread_hitlist->low_score, hits4query->low_score); } } sfree(num_hsplists_per_query); return retval; }