Ejemplo n.º 1
0
Int2 
BlastExtensionOptionsValidate(EBlastProgramType program_number, 
   const BlastExtensionOptions* options, Blast_Message* *blast_msg)

{
	if (options == NULL)
		return  BLASTERR_INVALIDPARAM;

	if (program_number != eBlastTypeBlastn &&
            (options->ePrelimGapExt == eGreedyScoreOnly ||
             options->eTbackExt == eGreedyTbck))
	{
		Blast_MessageWrite(blast_msg, eBlastSevWarning, 
                                   kBlastMessageNoContext,
                            "Greedy extension only supported for BLASTN");
			return BLASTERR_OPTION_PROGRAM_INVALID;
	}

        if ((options->ePrelimGapExt == eSmithWatermanScoreOnly &&
             options->eTbackExt != eSmithWatermanTbckFull) ||
            (options->ePrelimGapExt != eSmithWatermanScoreOnly &&
             options->eTbackExt == eSmithWatermanTbckFull))
	{
		Blast_MessageWrite(blast_msg, eBlastSevWarning, 
                                   kBlastMessageNoContext,
                           "Score-only and traceback Smith-Waterman must "
                           "both be specified");
		return BLASTERR_OPTION_VALUE_INVALID;
	}

	return 0;
}
Ejemplo n.º 2
0
/** Validate options for the discontiguous word megablast
 * Word size must be 11 or 12; template length 16, 18 or 21; 
 * template type 0, 1 or 2.
 * @param word_size Word size option [in]
 * @param template_length Discontiguous template length [in]
 * @param template_type Discontiguous template type [in]
 * @param blast_msg Used for storing error messages [in][out]
 * @return TRUE if options combination valid.
 */
static Boolean 
s_DiscWordOptionsValidate(Int4 word_size, Uint1 template_length,
                          Uint1 template_type,
                          Blast_Message** blast_msg)
{
   if (template_length == 0)
      return TRUE;


   if (word_size != 11 && word_size != 12) {
      Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Invalid discontiguous template parameters: word "
                         "size must be either 11 or 12");
      return FALSE;
   }

   if (template_length != 16 && template_length != 18 && 
       template_length != 21) {
      Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Invalid discontiguous template parameters: "
                         "template length must be 16, 18, or 21");
      return FALSE;
   }

   if (template_type > 2) {
     /* should never fail coming from the C++ APIs as we represent these as
      * strings */
      Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Invalid discontiguous template parameters: "
                         "template type must be 0, 1, or 2");
      return FALSE;
   }

   return TRUE;
}
Ejemplo n.º 3
0
Int2
BlastInitialWordOptionsValidate(EBlastProgramType program_number,
   const BlastInitialWordOptions* options, 
   Blast_Message* *blast_msg)
{

   ASSERT(options);

   /* PHI-BLAST has no ungapped extension phase.  Megablast may not have it,
    but generally does now. */
   if (program_number != eBlastTypeBlastn  &&
       (!Blast_ProgramIsPhiBlast(program_number)) &&
       options->x_dropoff <= 0.0)
   {
      Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                            "x_dropoff must be greater than zero");
         return BLASTERR_OPTION_VALUE_INVALID;
   }

   if (program_number == eBlastTypeBlastn && 
       options->scan_range && !options->window_size)
   {
      Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                            "off_diagonal_range is only useful in 2-hit algorithm");
         return BLASTERR_OPTION_VALUE_INVALID;
   }
                
   
   return 0;
}
Ejemplo n.º 4
0
Int2 SBlastFilterOptionsValidate(EBlastProgramType program_number, const SBlastFilterOptions* filter_options, Blast_Message* *blast_message)
{
       Int2 status = 0;

       if (filter_options == NULL)
       {
           Blast_MessageWrite(blast_message, eBlastSevWarning, kBlastMessageNoContext, 
              "SBlastFilterOptionsValidate: NULL filter_options");
           return BLASTERR_INVALIDPARAM;
       }

       if (filter_options->repeatFilterOptions)
       {
           if (program_number != eBlastTypeBlastn)
           {
               if (blast_message)
                  Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                   "SBlastFilterOptionsValidate: Repeat filtering only supported with blastn");
               return  BLASTERR_OPTION_PROGRAM_INVALID;
           }
           if (filter_options->repeatFilterOptions->database == NULL ||
               strlen(filter_options->repeatFilterOptions->database) == 0)
           {
               if (blast_message)
                  Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                   "SBlastFilterOptionsValidate: No repeat database specified for repeat filtering");
               return BLASTERR_INVALIDPARAM;
           }
       }

       if (filter_options->dustOptions)
       {
           if (program_number != eBlastTypeBlastn)
           {
               if (blast_message)
                  Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                   "SBlastFilterOptionsValidate: Dust filtering only supported with blastn");
               return BLASTERR_OPTION_PROGRAM_INVALID;
           }
       }
  
       if (filter_options->segOptions)
       {
           if (program_number == eBlastTypeBlastn)
           {
               if (blast_message)
                  Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                   "SBlastFilterOptionsValidate: SEG filtering is not supported with blastn");
               return BLASTERR_OPTION_PROGRAM_INVALID;
           }
       }

       return status;
}
Ejemplo n.º 5
0
/**  Checks that the extension and scoring options are consistent with each other
 * @param program_number identifies the program [in]
 * @param ext_options the extension options [in]
 * @param score_options the scoring options [in]
 * @param blast_msg returns a message on errors. [in|out]
 * @return zero on success, an error code otherwise. 
 */
static Int2 s_BlastExtensionScoringOptionsValidate(EBlastProgramType program_number,
                           const BlastExtensionOptions* ext_options,
                           const BlastScoringOptions* score_options, 
                           Blast_Message* *blast_msg)
{
    if (ext_options == NULL || score_options == NULL)
        return BLASTERR_INVALIDPARAM;

    if (program_number == eBlastTypeBlastn)
    {
        if (score_options->gap_open == 0 && score_options->gap_extend == 0)
        {
	    if (ext_options->ePrelimGapExt != eGreedyScoreOnly && 
                ext_options->eTbackExt != eGreedyTbck)
	    {
			Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                            "Greedy extension must be used if gap existence and extension options are zero");
			return BLASTERR_OPTION_VALUE_INVALID;
	    }
	}
    }

    if (ext_options->compositionBasedStats != eNoCompositionBasedStats)
    {
            if (!Blast_QueryIsPssm(program_number) && program_number != eBlastTypeTblastn && 
                 program_number != eBlastTypeBlastp) {
			Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                            "Compositional adjustments are only supported with blastp or tblastn");
			return BLASTERR_OPTION_VALUE_INVALID;
            }
            if (!score_options->gapped_calculation) {
			Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                            "Compositional adjustments are only supported for gapped searches");
			return BLASTERR_OPTION_VALUE_INVALID;
            }
            
    }

    return 0;
}
Ejemplo n.º 6
0
Int2
BlastHitSavingOptionsValidate(EBlastProgramType program_number,
   const BlastHitSavingOptions* options, Blast_Message* *blast_msg)
{
	if (options == NULL)
		return BLASTERR_INVALIDPARAM;

	if (options->hitlist_size < 1)
	{
		Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "No hits are being saved");
		return BLASTERR_OPTION_VALUE_INVALID;
	}

	if (options->expect_value <= 0.0 && options->cutoff_score <= 0)
	{
		Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
         "expect value or cutoff score must be greater than zero");
		return BLASTERR_OPTION_VALUE_INVALID;
	}	

   if (options->longest_intron != 0 &&
       program_number != eBlastTypeTblastn &&
       program_number != eBlastTypePsiTblastn &&
       program_number != eBlastTypeBlastx) {
                Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
         "Uneven gap linking of HSPs is allowed for blastx, "
         "tblastn, and psitblastn only");
                return BLASTERR_OPTION_PROGRAM_INVALID;
   }

	if (options->culling_limit < 0)
	{
		Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                    "culling limit must be greater than or equal to zero");
		return BLASTERR_OPTION_VALUE_INVALID;
	}	

	return 0;
}
Ejemplo n.º 7
0
Int2 PSIBlastOptionsValidate(const PSIBlastOptions* psi_options,
                             Blast_Message** blast_msg)
{
    Int2 retval = 1;    /* assume failure */

    if ( !psi_options ) {
        return retval;
    }

    if (psi_options->pseudo_count < 0) {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                           "Pseudo count must be greater than or equal to 0");
        return retval;
    }

    if (psi_options->inclusion_ethresh <= 0.0) {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                           "Inclusion threshold must be greater than 0");
        return retval;
    }

    retval = 0;
    return retval;
}
Ejemplo n.º 8
0
Int2
BlastSetUp_GetFilteringLocations(BLAST_SequenceBlk* query_blk, 
                                 const BlastQueryInfo* query_info, 
                                 EBlastProgramType program_number, 
                                 const SBlastFilterOptions* filter_options, 
                                 BlastMaskLoc** filter_maskloc, 
                                 Blast_Message** blast_message)
{
    Int2 status = 0;
    Int4 context = 0; /* loop variable. */
    const int kNumContexts = query_info->last_context + 1;

    ASSERT(query_info && query_blk && filter_maskloc);

    ASSERT(blast_message);
    ASSERT(kNumContexts == 
           query_info->num_queries*BLAST_GetNumberOfContexts(program_number));
    *filter_maskloc = BlastMaskLocNew(kNumContexts);

    for (context = query_info->first_context;
         context <= query_info->last_context; ++context) {
  
        BlastSeqLoc *filter_per_context = NULL;
        status = s_GetFilteringLocationsForOneContext(query_blk, 
                                                      query_info, 
                                                      context, 
                                                      program_number, 
                                                      filter_options, 
                                                      &filter_per_context, 
                                                      blast_message);
        if (status) {
            Blast_MessageWrite(blast_message, eBlastSevError, context,
                                   "Failure at filtering");
            return status;
        }

    /* NB: for translated searches filter locations are returned in 
           protein coordinates, because the DNA lengths of sequences are 
           not available here. The caller must take care of converting 
           them back to nucleotide coordinates. */
         (*filter_maskloc)->seqloc_array[context] = filter_per_context;
    }
    return 0;
}
Ejemplo n.º 9
0
Int2
BlastFilteringOptionsFromString(EBlastProgramType program_number, 
                                const char* instructions, 
                                SBlastFilterOptions* *filtering_options, 
                                Blast_Message* *blast_message)
{
        Boolean mask_at_hash = FALSE; /* the default. */
        char* buffer;
        const char* ptr = instructions;
        char error_buffer[1024];
        Int2 status = 0;
        SSegOptions* segOptions = NULL;
        SDustOptions* dustOptions = NULL;
        SRepeatFilterOptions* repeatOptions = NULL;
        SWindowMaskerOptions * winmaskOptions = NULL;
        
        *filtering_options = NULL;
        if (blast_message)
            *blast_message = NULL;

        if (instructions == NULL || strcasecmp(instructions, "F") == 0)
        {
             SBlastFilterOptionsNew(filtering_options, eEmpty);
             return status;
        }

        buffer = (char*) calloc(strlen(instructions), sizeof(char));
	/* allow old-style filters when m cannot be followed by the ';' */
	if (ptr[0] == 'm' && ptr[1] == ' ')
	{
		mask_at_hash = TRUE;
		ptr += 2;
	}

	while (*ptr != NULLB)
	{
		if (*ptr == 'S')
		{
                        SSegOptionsNew(&segOptions);
			ptr = s_LoadOptionsToBuffer(ptr+1, buffer);
			if (buffer[0] != NULLB)
			{
                                int window = 0;
                                double locut = .0, hicut = .0;
				status = s_ParseSegOptions(buffer, &window, &locut, &hicut);
                                if (status)
                                {
                                     segOptions = SSegOptionsFree(segOptions);
                                     sprintf(error_buffer, "Error parsing filter string: %s", buffer);
                                     if (blast_message)
                                       Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                                            error_buffer);
                                     sfree(buffer);
                                     return status;
                                }
                                segOptions->window = window;
                                segOptions->locut = locut;
                                segOptions->hicut = hicut;
			}
		}
		else if (*ptr == 'D')
		{
                        SDustOptionsNew(&dustOptions);
			ptr = s_LoadOptionsToBuffer(ptr+1, buffer);
			if (buffer[0] != NULLB)
                        {
                                int window = 0, level = 0, linker = 0;
				status = s_ParseDustOptions(buffer, &level, &window, &linker);
                                if (status)
                                {
                                     dustOptions = SDustOptionsFree(dustOptions);
                                     sprintf(error_buffer, "Error parsing filter string: %s", buffer);
                                     if (blast_message)
                                       Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                                            error_buffer);
                                     sfree(buffer);
                                     return status;
                                }
                                dustOptions->level = level;
                                dustOptions->window = window;
                                dustOptions->linker = linker;
                        }
		}
                else if (*ptr == 'R')
                {
                        SRepeatFilterOptionsNew(&repeatOptions);
			ptr = s_LoadOptionsToBuffer(ptr+1, buffer);
			if (buffer[0] != NULLB)
                        {
                             char* dbname = NULL;
                             status = s_ParseRepeatOptions(buffer, &dbname); 
                             if (status)
                             {
                                  repeatOptions = SRepeatFilterOptionsFree(repeatOptions);
                                  sprintf(error_buffer, "Error parsing filter string: %s", buffer);
                                  if (blast_message)
                                     Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                                            error_buffer);
                                   sfree(buffer);
                                   return status;
                             }
                             if (dbname)
                             {
                                 sfree(repeatOptions->database);
                                 repeatOptions->database = dbname;
                             }
                        }
                }
                else if (*ptr == 'W')
                {
                    SWindowMaskerOptionsNew(&winmaskOptions);
                    
                    ptr = s_LoadOptionsToBuffer(ptr+1, buffer);
                    if (buffer[0] != NULLB) {
                        char* dbname = NULL;
                        int taxid = 0;
                        
                        status = s_ParseWindowMaskerOptions(buffer, &dbname, &taxid);
                        if (status) {
                            winmaskOptions = SWindowMaskerOptionsFree(winmaskOptions);
                            sprintf(error_buffer, "Error parsing filter string: %s", buffer);
                            if (blast_message)
                                Blast_MessageWrite(blast_message, eBlastSevError, kBlastMessageNoContext,
                                                   error_buffer);
                            
                            sfree(buffer);
                            return status;
                        }
                        if (dbname) {
                            sfree(winmaskOptions->database);
                            winmaskOptions->database = dbname;
                        }
                        if (taxid) {
                            winmaskOptions->taxid = taxid;
                        }
                    }
                }
		else if (*ptr == 'L' || *ptr == 'T')
		{ /* do low-complexity filtering; dust for blastn, otherwise seg.*/
                        if (program_number == eBlastTypeBlastn)
                            SDustOptionsNew(&dustOptions);
                        else
                            SSegOptionsNew(&segOptions);
			ptr++;
		}
		else if (*ptr == 'm')
		{
		        mask_at_hash = TRUE;
                        ptr++;
                }
                else
                {    /* Nothing applied */
                         ptr++;
                }
	}
        sfree(buffer);

        status = SBlastFilterOptionsNew(filtering_options, eEmpty);
        if (status)
            return status;

        (*filtering_options)->dustOptions = dustOptions;
        (*filtering_options)->segOptions = segOptions;
        (*filtering_options)->repeatFilterOptions = repeatOptions;
        (*filtering_options)->windowMaskerOptions = winmaskOptions;
        (*filtering_options)->mask_at_hash = mask_at_hash;

        return status;
}
Ejemplo n.º 10
0
Int2 
BlastScoringOptionsValidate(EBlastProgramType program_number, 
   const BlastScoringOptions* options, Blast_Message* *blast_msg)

{
	if (options == NULL)
		return BLASTERR_INVALIDPARAM;

        if (program_number == eBlastTypeTblastx && options->gapped_calculation)
        {
            Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
               "Gapped search is not allowed for tblastx");
		return BLASTERR_OPTION_PROGRAM_INVALID;
        }

	if (program_number == eBlastTypeBlastn || program_number == eBlastTypePhiBlastn)
	{
		if (options->penalty >= 0)
		{
			Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                            "BLASTN penalty must be negative");
			return BLASTERR_OPTION_VALUE_INVALID;
		}

                if (options->gapped_calculation && !BLAST_CheckRewardPenaltyScores(options->reward, options->penalty))
                {
			Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                            "BLASTN reward/penalty combination not supported for gapped search");
			return BLASTERR_OPTION_VALUE_INVALID;
                }

                if (options->gapped_calculation && options->gap_open > 0 && options->gap_extend == 0) 
                {
                        Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
                           "BLASTN gap extension penalty cannot be 0");
                        return BLASTERR_OPTION_VALUE_INVALID;
                }
	}
	else
	{
                if (options->gapped_calculation && !Blast_ProgramIsRpsBlast(program_number))
                {
                    Int2 status=0;
                    if ((status=Blast_KarlinBlkGappedLoadFromTables(NULL, options->gap_open,
                     options->gap_extend, options->matrix)) != 0)
                     {
			if (status == 1)
			{
				char* buffer;

				buffer = BLAST_PrintMatrixMessage(options->matrix); 
                                Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext, buffer);
				sfree(buffer);
				return BLASTERR_OPTION_VALUE_INVALID;
				
			}
			else if (status == 2)
			{
				char* buffer;

				buffer = BLAST_PrintAllowedValues(options->matrix, 
                        options->gap_open, options->gap_extend);
                                Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext, buffer);
				sfree(buffer);
				return BLASTERR_OPTION_VALUE_INVALID;
			}
                    }
	       }
	}

	if (program_number != eBlastTypeBlastx && program_number != eBlastTypeTblastn && options->is_ooframe)
	{
            Blast_MessageWrite(blast_msg, eBlastSevWarning, kBlastMessageNoContext,
               "Out-of-frame only permitted for blastx and tblastn");
            return  BLASTERR_OPTION_PROGRAM_INVALID;
	}

	return 0;
}
Ejemplo n.º 11
0
Int2 
LookupTableOptionsValidate(EBlastProgramType program_number, 
   const LookupTableOptions* options, Blast_Message* *blast_msg)

{
   const Boolean kPhiBlast = Blast_ProgramIsPhiBlast(program_number);

    if (options == NULL)
        return BLASTERR_INVALIDPARAM;

    if (options->phi_pattern && !kPhiBlast) {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
            "PHI pattern can be specified only for blastp and blastn");
        return BLASTERR_OPTION_PROGRAM_INVALID;
    }

    /* For PHI BLAST, the subsequent word size tests are not needed. */
    if (kPhiBlast)
        return 0;

    if (program_number != eBlastTypeBlastn && 
        (!Blast_ProgramIsRpsBlast(program_number)) &&
        options->threshold <= 0)
    {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Non-zero threshold required");
        return BLASTERR_OPTION_VALUE_INVALID;
    }

    if (options->word_size <= 0)
    {
        if ( !Blast_ProgramIsRpsBlast(program_number)) {
            Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                                     "Word-size must be greater than zero");
            return BLASTERR_OPTION_VALUE_INVALID;
        }
    } else if (program_number == eBlastTypeBlastn && options->word_size < 4)
    {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext, 
                  "Word-size must be 4 or greater for nucleotide comparison");
        return BLASTERR_OPTION_VALUE_INVALID;
    } else if (program_number != eBlastTypeBlastn && options->word_size > 5)
    {
        if (program_number == eBlastTypeBlastp ||
            program_number == eBlastTypeTblastn ||
            program_number == eBlastTypeBlastx)
        {
            if (options->word_size > 7) {
                Blast_MessageWrite(blast_msg, eBlastSevError, 
                                   kBlastMessageNoContext,
                                   "Word-size must be less than "
                                   "8 for a tblastn, blastp or blastx search");
                return BLASTERR_OPTION_VALUE_INVALID;
            }
        }
        else {
            Blast_MessageWrite(blast_msg, eBlastSevError, 
                               kBlastMessageNoContext,
                               "Word-size must be less "
                               "than 6 for protein comparison");
            return BLASTERR_OPTION_VALUE_INVALID;
        }
    }

    if (program_number != eBlastTypeBlastn && 
       options->lut_type == eMBLookupTable)
    {
        Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Megablast lookup table only supported with blastn");
        return BLASTERR_OPTION_PROGRAM_INVALID;
    }

    if (program_number == eBlastTypeBlastp ||
        program_number == eBlastTypeTblastn ||
        program_number == eBlastTypeBlastx)
    {
        if (options->word_size > 5 &&
            options->lut_type != eCompressedAaLookupTable) {
           Blast_MessageWrite(blast_msg, eBlastSevError,
                              kBlastMessageNoContext,
                              "Blastp, Blastx or Tblastn with word size"
                              " > 5 requires a "
                              "compressed alphabet lookup table");
           return BLASTERR_OPTION_VALUE_INVALID;
        }
        else if (options->lut_type == eCompressedAaLookupTable &&
                 options->word_size != 6 && options->word_size != 7) {
           Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
                         "Compressed alphabet lookup table requires "
                         "word size 6 or 7");
           return BLASTERR_OPTION_VALUE_INVALID;
        }
    }

   if (program_number == eBlastTypeBlastn && options->mb_template_length > 0) {
      if (!s_DiscWordOptionsValidate(options->word_size,
              options->mb_template_length, 
              options->mb_template_type,
              blast_msg)) {
         return BLASTERR_OPTION_VALUE_INVALID;
      } else if (options->lut_type != eMBLookupTable) {
         Blast_MessageWrite(blast_msg, eBlastSevError, kBlastMessageNoContext,
            "Invalid lookup table type for discontiguous Mega BLAST");
         return BLASTERR_OPTION_VALUE_INVALID;
      } 
   }
    return 0;
}