NCBI C Toolkit Cross Reference

C/algo/blast/api/blast_options_api.c


  1 /* $Id: blast_options_api.c,v 1.25 2007/12/14 17:11:29 madden Exp $
  2 ***************************************************************************
  3 *                                                                         *
  4 *                             COPYRIGHT NOTICE                            *
  5 *                                                                         *
  6 * This software/database is categorized as "United States Government      *
  7 * Work" under the terms of the United States Copyright Act.  It was       *
  8 * produced as part of the author's official duties as a Government        *
  9 * employee and thus can not be copyrighted.  This software/database is    *
 10 * freely available to the public for use without a copyright notice.      *
 11 * Restrictions can not be placed on its present or future use.            *
 12 *                                                                         *
 13 * Although all reasonable efforts have been taken to ensure the accuracy  *
 14 * and reliability of the software and data, the National Library of       *
 15 * Medicine (NLM) and the U.S. Government do not and can not warrant the   *
 16 * performance or results that may be obtained by using this software,     *
 17 * data, or derivative works thereof.  The NLM and the U.S. Government     *
 18 * disclaim any and all warranties, expressed or implied, as to the        *
 19 * performance, merchantability or fitness for any particular purpose or   *
 20 * use.                                                                    *
 21 *                                                                         *
 22 * In any work or product derived from this material, proper attribution   *
 23 * of the author(s) as the source of the software or data would be         *
 24 * appreciated.                                                            *
 25 *                                                                         *
 26 *  Author: Ilya Dondoshansky                                              *
 27 **************************************************************************/
 28 
 29 /** @file blast_options_api.c
 30  * Functions for C toolkit applications to perform a BLAST search, using the 
 31  * core engine, shared between C and C++ toolkits.
 32  */
 33 
 34 #include <algo/blast/api/blast_options_api.h>
 35 #include <algo/blast/core/blast_util.h>
 36 #include <algo/blast/core/blast_filter.h>
 37 #include <algo/blast/api/blast_seq.h>
 38 #include <algo/blast/core/gencode_singleton.h>
 39 
 40 /** @addtogroup CToolkitAlgoBlast
 41  *
 42  * @{
 43  */
 44 
 45 Int2 SBlastOptionsNew(const char* program_name, SBlastOptions** options_out,
 46                       Blast_SummaryReturn* extra_returns)
 47 {
 48    QuerySetUpOptions* query_options=NULL;       
 49    LookupTableOptions* lookup_options=NULL;
 50    BlastInitialWordOptions* word_options=NULL;
 51    BlastScoringOptions* score_options=NULL;
 52    BlastExtensionOptions* ext_options=NULL;
 53    BlastHitSavingOptions* hit_options=NULL;
 54    BlastEffectiveLengthsOptions* eff_len_options=NULL;
 55    PSIBlastOptions* psi_options = NULL;
 56    BlastDatabaseOptions* db_options = NULL;
 57    SBlastOptions* options;
 58    EBlastProgramType program = eBlastTypeUndefined;
 59    Int2 status = 0;
 60 
 61    if (!options_out || !extra_returns)
 62        return -1;
 63 
 64    BlastProgram2Number(program_name, &program);
 65    if (program == eBlastTypeUndefined) {
 66        char message[256];
 67 
 68        sprintf(message, 
 69                "Program name %s is not supported. The supported programs "
 70                "are blastn, blastp, blastx, tblastn, tblastx, rpsblast, "
 71                "rpstblastn\n", program_name);
 72        SBlastMessageWrite(&extra_returns->error, SEV_ERROR, message, NULL, FALSE);
 73        return -1;
 74    }
 75 
 76    status = 
 77        BLAST_InitDefaultOptions(program, &lookup_options, &query_options, 
 78            &word_options, &ext_options, &hit_options, &score_options, 
 79            &eff_len_options, &psi_options, &db_options);
 80    
 81    if (status) {
 82        *options_out = NULL;
 83        SBlastMessageWrite(&extra_returns->error, SEV_ERROR, "Failed to initialize default options\n", NULL, FALSE);
 84        return status;
 85    }
 86 
 87    if (Blast_SubjectIsTranslated(program) || program == eBlastTypeRpsTblastn) {
 88         Uint1* gc = NULL;
 89         BLAST_GeneticCodeFind(db_options->genetic_code, &gc);
 90         GenCodeSingletonAdd(db_options->genetic_code, gc);
 91         free(gc);
 92    }
 93    
 94    *options_out = options = (SBlastOptions*) calloc(1, sizeof(SBlastOptions));
 95    options->program = program;
 96    options->query_options = query_options;
 97    options->lookup_options = lookup_options;
 98    options->word_options = word_options;
 99    options->ext_options = ext_options;
100    options->score_options = score_options;
101    options->hit_options = hit_options;
102    options->eff_len_options = eff_len_options;
103    options->psi_options = psi_options;
104    options->db_options = db_options;
105    options->num_cpus = 1;
106    options->believe_query = FALSE;
107 
108    /* Set default filter string to low complexity filtering. */
109    SBlastOptionsSetFilterString(options, "T");
110 
111    return status;
112 }
113 
114 SBlastOptions* SBlastOptionsFree(SBlastOptions* options)
115 {
116     if (options) {
117         LookupTableOptionsFree(options->lookup_options);
118         BlastQuerySetUpOptionsFree(options->query_options);
119         BlastExtensionOptionsFree(options->ext_options);
120         BlastHitSavingOptionsFree(options->hit_options);
121         BlastInitialWordOptionsFree(options->word_options);
122         BlastScoringOptionsFree(options->score_options);
123         BlastEffectiveLengthsOptionsFree(options->eff_len_options);
124         PSIBlastOptionsFree(options->psi_options);
125         BlastDatabaseOptionsFree(options->db_options);
126         sfree(options);
127     }
128     return NULL;
129 }
130 
131 Int2 SBlastOptionsSetEvalue(SBlastOptions* options, double evalue)
132 {
133     if (options && options->hit_options) {
134         options->hit_options->expect_value = evalue;
135         return 0;
136     } else
137         return -1;
138 }
139 
140 Int2 SBlastOptionsSetWordSize(SBlastOptions* options, Int4 word_size)
141 {
142     if (options && options->lookup_options) {
143         options->lookup_options->word_size = word_size;
144         return 0;
145     } else
146         return -1;
147 }
148 
149 Int2 SBlastOptionsSetThreshold(SBlastOptions* options, double threshold)
150 {
151 
152     if (!options || !options->lookup_options || !options->score_options)
153         return -1;
154 
155     if (threshold < 0)
156        return -2;
157 
158     if (Blast_QueryIsNucleotide(options->program) == TRUE && Blast_QueryIsTranslated(options->program) == FALSE)
159         return 0;
160 
161    if (threshold == 0)
162    {
163      Int2 status=0;
164      if ((status=BLAST_GetSuggestedThreshold(options->program, options->score_options->matrix, &threshold)) != 0)
165          return status;
166    }
167 
168    options->lookup_options->threshold = threshold;
169 
170    return 0;
171 }
172 
173 Int2 SBlastOptionsSetWindowSize(SBlastOptions* options, Int4 window_size)
174 {
175 
176    if (!options || !options->score_options || !options->word_options)
177        return -1;
178 
179    if (window_size < 0)
180        return -2;
181 
182    if (Blast_QueryIsNucleotide(options->program) == TRUE && Blast_QueryIsTranslated(options->program) == FALSE)
183         return 0;
184 
185    if (window_size == 0)
186    {
187      Int2 status=0;
188      if ((status=BLAST_GetSuggestedWindowSize(options->program, options->score_options->matrix, &window_size)) != 0)
189          return status;
190    }
191 
192    options->word_options->window_size = window_size;
193 
194    return 0;
195 }
196 
197 Int2 SBlastOptionsSetDiscMbParams(SBlastOptions* options, Int4 template_length,
198                                  Int4 template_type)
199 {
200     if (!options || !options->lookup_options)
201         return -1;
202 
203     options->lookup_options->lut_type = eMBLookupTable;
204     options->lookup_options->mb_template_length = template_length;
205     options->lookup_options->mb_template_type = template_type;
206     
207     return 0;
208 }
209 
210 Int2 SBlastOptionsSetMatrixAndGapCosts(SBlastOptions* options, 
211                                        const char* matrix_name, 
212                                        Int4 gap_open, Int4 gap_extend)
213 {
214     Int2 status = 0;
215 
216     if (!matrix_name || !options || !options->score_options)
217         return -1;
218     
219     /* Reward penalty do not apply to blastn. */
220     if (options->program == eBlastTypeBlastn)
221         return 0;
222 
223     status = BLAST_FillScoringOptions(options->score_options, options->program,
224                         FALSE, -1, -1, matrix_name, gap_open, gap_extend);
225     if (status != 0)
226         return status;
227     
228     if (gap_open < 0 || gap_extend < 0)
229     {
230         Int4 gap_open_priv = 0;
231         Int4 gap_extend_priv = 0;
232 
233         BLAST_GetProteinGapExistenceExtendParams(matrix_name, &gap_open_priv, &gap_extend_priv);
234         if (gap_open < 0)
235             gap_open = gap_open_priv;
236         if (gap_extend < 0)
237             gap_extend = gap_extend_priv;
238     }
239 
240     options->score_options->gap_open = gap_open;
241     options->score_options->gap_extend = gap_extend;
242 
243     return status;
244 }
245 
246 Int2 SBlastOptionsSetRewardPenaltyAndGapCosts(SBlastOptions* options, 
247                                        Int4 reward, Int4 penalty,
248                                        Int4 gap_open, Int4 gap_extend,
249                                        Boolean greedy)
250 {
251     Int2 status = 0;
252 
253     if (reward <= 0 || penalty >= 0 || !options || !options->score_options)
254         return -1;
255 
256     /* Reward penalty only apply to blastn. */
257     if (options->program != eBlastTypeBlastn)
258         return 0;
259     
260     status = BLAST_FillScoringOptions(options->score_options, options->program,
261                         greedy, penalty, reward, NULL, gap_open, gap_extend);
262     if (status != 0)
263         return status;
264     
265     if (gap_open < 0 || gap_extend < 0)
266     {
267         Int4 gap_open_priv;
268         Int4 gap_extend_priv;
269       
270         if (greedy)
271         {
272              gap_open_priv = BLAST_GAP_OPEN_MEGABLAST;
273              gap_extend_priv = BLAST_GAP_EXTN_MEGABLAST;
274         }
275         else
276         {
277              gap_open_priv = BLAST_GAP_OPEN_NUCL;
278              gap_extend_priv = BLAST_GAP_EXTN_NUCL;
279         }
280 
281         status = BLAST_GetNucleotideGapExistenceExtendParams(reward, penalty, &gap_open_priv, &gap_extend_priv);
282         if (status)
283            return status;
284 
285         if (gap_open < 0)
286             gap_open = gap_open_priv;
287         if (gap_extend < 0)
288             gap_extend = gap_extend_priv;
289     }
290 
291     options->score_options->gap_open = gap_open;
292     options->score_options->gap_extend = gap_extend;
293 
294     return status;
295 }
296 
297 Int2 SBlastOptionsSetFilterString(SBlastOptions* options, const char* str)
298 {
299     Int2 status = 0;
300     if (!options || !options->query_options)
301         return -1;
302 
303     /* Reset filtering options */
304     sfree(options->query_options->filter_string);
305     options->query_options->filter_string = strdup(str);
306     options->query_options->filtering_options =
307          SBlastFilterOptionsFree(options->query_options->filtering_options);
308     status = BlastFilteringOptionsFromString(options->program, 
309         options->query_options->filter_string, 
310         &options->query_options->filtering_options, NULL);
311     return status;
312 }
313 
314 Int2 SBlastOptionsSetDbGeneticCode(SBlastOptions* options, Int4 gc)
315 {
316     Int2 status = 0;
317 
318     if (gc == 0)
319         return 0;
320 
321     if (!options || !options->db_options)
322         return -1;
323 
324     options->db_options->genetic_code = gc;
325 
326     if (GenCodeSingletonFind(gc) == NULL)
327     {
328        Uint1* gcode = NULL;
329        BLAST_GeneticCodeFind(options->db_options->genetic_code, &gcode);
330        GenCodeSingletonAdd(options->db_options->genetic_code, gcode);
331        free(gcode);
332     }
333 
334     return status;
335     
336 }
337 
338 Boolean SBlastOptionsGetMaskAtHash(const SBlastOptions* options)
339 {
340     ASSERT(options && options->query_options &&
341            options->query_options->filtering_options);
342 
343     return options->query_options->filtering_options->mask_at_hash;
344 }
345 
346 Int2 SBlastOptionsSetBelieveQuery(SBlastOptions* options, Boolean believe_query)
347 {
348     Int2 status = 0;
349 
350     if (!options)
351        return -1;
352 
353     options->believe_query = believe_query;
354 
355     return status;
356 }
357 
358 Boolean SBlastOptionsGetBelieveQuery(const SBlastOptions* options)
359 {
360 
361     ASSERT(options);
362 
363     return options->believe_query;
364 }
365 
366 /* @} */
367 
368 

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.