blast_util.cpp
来自「ncbi源码」· C++ 代码 · 共 287 行
CPP
287 行
/* * =========================================================================== * PRODUCTION $Log: blast_util.cpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 20:54:19 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * PRODUCTION * =========================================================================== *//* $Id: blast_util.cpp,v 1000.2 2004/06/01 20:54:19 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include "blast_util.hpp"#include <objects/seqfeat/Genetic_code.hpp>#include <objects/seqfeat/Genetic_code_table.hpp>#include <gui/plugin/PluginValueConstraint.hpp>#include <gui/core/plugin_utils.hpp>#include <util/static_map.hpp>#include <algo/blast/api/blast_types.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);// figure out the id of the genetic code the user wantsinlineint x_DecodeGeneticCode(const string& s){ const CGenetic_code_table& code_table = CGen_code_table::GetCodeTable(); const CGenetic_code_table::Tdata& codes = code_table.Get(); ITERATE (CGenetic_code_table::Tdata, code, codes) { if ((*code)->GetName() == s) { return (*code)->GetId(); } } // if we got here, nothing matched NCBI_THROW(CException, eUnknown, "x_DecodeGeneticCode: no genetic code matched " + s);}void CBlastUtils::AddBlastArgs(CPluginCommand& args, blast::EProgram prog){ switch (prog) { case blast::eBlastn: args.AddDefaultArgument("word", "Word Size", CPluginArg::eInteger, "11"); args.AddDefaultArgument("expect", "Expect Value", CPluginArg::eDouble, "10.0"); args.AddArgument("greedy", "Perform a greedy alignment", CPluginArg::eBoolean); // // hidden argument for program type // {{ CPluginArg& arg = args.AddArgument("prog", "Program Type", CPluginArg::eString); arg.SetHidden(true); arg.SetString("blastn"); }} break; case blast::eBlastx: args.AddDefaultArgument("thresh", "Threshold", CPluginArg::eInteger, "12"); args.AddDefaultArgument("word", "Word Size", CPluginArg::eInteger, "3"); args.AddDefaultArgument("expect", "Expect Value", CPluginArg::eDouble, "10.0"); // genetic code argument {{ const CGenetic_code_table& code_table = CGen_code_table::GetCodeTable(); const list<CRef<CGenetic_code> >& codes = code_table.Get(); args.AddDefaultArgument("gencode", "Genetic code", CPluginArg::eString, codes.front()->GetName()); CPluginValueConstraint *code_list = CPluginValueConstraint::CreateSet(); ITERATE (list<CRef<CGenetic_code> >, code, codes) { code_list->SetSet().push_back((*code)->GetName()); } args.SetConstraint("gencode", *code_list); }} // // hidden argument for program type // {{ CPluginArg& arg = args.AddArgument("prog", "Program Type", CPluginArg::eString); arg.SetHidden(true); arg.SetString("blastx"); }} break; case blast::eBlastp: args.AddDefaultArgument("thresh", "Threshold", CPluginArg::eInteger, "11"); args.AddDefaultArgument("word", "Word Size", CPluginArg::eInteger, "3"); args.AddDefaultArgument("expect", "Expect Value", CPluginArg::eDouble, "10.0"); // // hidden argument for program type // {{ CPluginArg& arg = args.AddArgument("prog", "Program Type", CPluginArg::eString); arg.SetHidden(true); arg.SetString("blastp"); }} break; case blast::eTblastx: args.AddDefaultArgument("thresh", "Threshold", CPluginArg::eInteger, "13"); args.AddDefaultArgument("word", "Word Size", CPluginArg::eInteger, "3"); args.AddDefaultArgument("expect", "Expect Value", CPluginArg::eDouble, "10.0"); // genetic code argument {{ const CGenetic_code_table& code_table = CGen_code_table::GetCodeTable(); const list<CRef<CGenetic_code> >& codes = code_table.Get(); args.AddDefaultArgument("gencode", "Genetic code", CPluginArg::eString, codes.front()->GetName()); CPluginValueConstraint *code_list = CPluginValueConstraint::CreateSet(); ITERATE (list<CRef<CGenetic_code> >, code, codes) { code_list->SetSet().push_back((*code)->GetName()); } args.SetConstraint("gencode", *code_list); }} // // hidden argument for program type // {{ CPluginArg& arg = args.AddArgument("prog", "Program Type", CPluginArg::eString); arg.SetHidden(true); arg.SetString("tblastx"); }} break; default: LOG_POST(Error << "unhandled BLAST program"); break; }}void CBlastUtils::ArgsToBlastOptions(const CPluginCommand& cmd, blast::CBlastOptions& opts){ if (cmd.HasArgument("word") && CPluginUtils::IsValid(cmd["word"])) { int word_size = cmd["word"].AsInteger(); opts.SetWordSize(word_size); _TRACE("CBlastBase: word size = " << word_size); } if (cmd.HasArgument("expect") && CPluginUtils::IsValid(cmd["expect"])) { double expect = cmd["expect"].AsDouble(); opts.SetEvalueThreshold(expect); _TRACE("CBlastBase: expect = " << expect); } if (cmd.HasArgument("thresh") && CPluginUtils::IsValid(cmd["thresh"])) { int thresh = cmd["thresh"].AsInteger(); opts.SetWordThreshold(thresh); _TRACE("CBlastBase: threshold = " << thresh); } if (cmd.HasArgument("greedy") && CPluginUtils::IsValid(cmd["greedy"])) { bool greedy = cmd["greedy"].AsBoolean(); if (greedy) { opts.SetGapExtnAlgorithm(eGreedyWithTracebackExt); } _TRACE("CBlastBase: greedy = " << greedy); } if (cmd.HasArgument("gencode") && CPluginUtils::IsValid(cmd["gencode"])) { string code = cmd["gencode"].AsString(); opts.SetDbGeneticCode(x_DecodeGeneticCode(code.c_str())); _TRACE("CBlastBase: genetic code = " << code); }}blast::EProgram CBlastUtils::GetBlastProgram(const string& str){ typedef pair<const char*, blast::EProgram> TProgPair; static const TProgPair sc_ProgPairs[] = { TProgPair("blastn", blast::eBlastn), TProgPair("blastp", blast::eBlastp), TProgPair("blastx", blast::eBlastx), TProgPair("tblastn", blast::eTblastn), TProgPair("tblastx", blast::eTblastx) }; typedef CStaticArrayMap<const char*, blast::EProgram, PCase> TProgDictionary; static const TProgDictionary sc_Progs(sc_ProgPairs, sizeof(sc_ProgPairs)); TProgDictionary::const_iterator iter = sc_Progs.find(str.c_str()); if (iter != sc_Progs.end()) { return iter->second; } return blast::eBlastProgramMax;}END_NCBI_SCOPE/* * =========================================================================== * $Log: blast_util.cpp,v $ * Revision 1000.2 2004/06/01 20:54:19 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.4 * * Revision 1.4 2004/05/21 22:27:46 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.3 2004/05/17 18:00:09 ucko * Int algorithm_type replaced with enum EBlastPrelimGapExt * * Revision 1.2 2004/04/16 14:41:22 dicuccio * Added GetBlastProgram() - convert text-based program name to enum * * Revision 1.1 2004/01/13 20:35:27 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?