net_blast_req_base.cpp

来自「ncbi源码」· C++ 代码 · 共 434 行

CPP
434
字号
/* * =========================================================================== * PRODUCTION $Log: net_blast_req_base.cpp,v $ * PRODUCTION Revision 1000.4  2004/06/01 20:54:39  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * PRODUCTION * =========================================================================== *//*  $Id: net_blast_req_base.cpp,v 1000.4 2004/06/01 20:54:39 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:  Clifford Clausen, Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include "net_blast_req_base.hpp"#include "blast_util.hpp"#include <gui/objutils/label.hpp>#include <gui/core/doc_manager.hpp>#include <gui/core/version.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginCommand.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <gui/plugin/PluginRequest.hpp>#include <gui/utils/message_box.hpp>#include <algo/blast/api/bl2seq.hpp>#include <algo/blast/api/blast_options.hpp>#include <objects/seq/seqport_util.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/IUPACaa.hpp>#include <objects/seq/IUPACna.hpp>#include <objects/seq/Seq_descr.hpp>#include <objects/seq/Seqdesc.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seqset/Bioseq_set.hpp>#include <objects/blast/Blast4_cutoff.hpp>#include <objects/blast/Blast4_error.hpp>#include <objects/blast/Blast4_database.hpp>#include <objects/blast/Blast4_parameter.hpp>#include <objects/blast/Blast4_parameters.hpp>#include <objects/blast/Blast4_queue_search_reply.hpp>#include <objects/blast/Blast4_queue_search_reques.hpp>#include <objects/blast/Blast4_reply.hpp>#include <objects/blast/Blast4_reply_body.hpp>#include <objects/blast/Blast4_request.hpp>#include <objects/blast/Blast4_request_body.hpp>#include <objects/blast/Blast4_subject.hpp>#include <objects/blast/Blast4_value.hpp>#include <objects/blast/blastclient.hpp>#include <objmgr/seq_vector.hpp>#include <algo/blast/api/blastx_options.hpp>#include <algo/blast/api/tblastn_options.hpp>#include <algo/blast/api/tblastx_options.hpp>#include <algo/blast/api/blast_nucl_options.hpp>#include <algo/blast/api/blast_prot_options.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);CRef<CPluginValueConstraint>      CNetBlastReq_Base::sm_DbConstraint_Nucs;CRef<CPluginValueConstraint>      CNetBlastReq_Base::sm_DbConstraint_Prots;CNetBlastReq_Base::TDbMap         CNetBlastReq_Base::sm_DbMap;CRef<CBlast4_get_databases_reply> CNetBlastReq_Base::sm_Databases;void CNetBlastReq_Base::RunCommand(CPluginMessage& msg){    const CPluginCommand& args  = msg.GetRequest().GetCommand();    CPluginReply&         reply = msg.SetReply();    reply.SetStatus(eMessageStatus_failed);    //    // retrieve our locations    //    bool nuc = true;    plugin_args::TLocList locs;    if (args.HasArgument("nucleotide")) {        GetArgValue(args["nucleotide"], locs);    } else if (args.HasArgument("protein")){        GetArgValue(args["protein"],    locs);        nuc = false;    } else {        NcbiMessageBox("Plugin called without sequences set.");        return;    }    try {        blast::CBlastOptions opts;        CRef<blast::CRemoteBlast> cli(x_GetClient(args));        if (args.HasArgument("query")  &&            CPluginUtils::IsValid(args["query"])) {            cli->SetEntrezQuery(args["query"].AsString().c_str());        }        bool error = false;        string err_locs;        ITERATE (plugin_args::TLocList, iter, locs) {            const CSeq_loc&  loc = *iter->second;            const IDocument& doc = *iter->first;            // convert the location to a sequence            // this is a constructed bioseq containing only the covered sequence...            CRef<CBioseq> bioseq(x_SeqLocToBioseq(loc, doc.GetScope()));            if ( !bioseq ) {                string str;                CLabel::GetLabel(loc, &str, CLabel::eDefault, &doc.GetScope());                LOG_POST(Error << "can't create bioseq for location: "                         << str);                continue;            }            CObjectConverter::TObjList objs;            CObjectConverter::Convert(doc.GetScope(), *bioseq,                                      CBioseq_set::GetTypeInfo(), objs);            NON_CONST_ITERATE (CObjConverter::TObjList, bs_iter, objs) {                const CBioseq_set& bs =                    dynamic_cast<const CBioseq_set&>(**bs_iter);                CRef<CBioseq_set> ref(&const_cast<CBioseq_set&>(bs));                cli->SetQueries(ref);                if (cli->Submit()) {                    // Set up arguments for framework to call                    // CDataPlugin_BlastReply plugin                    CRef<CPluginMessage> msg(new CPluginMessage);                    msg->SetDestination("CDataPlugin_BlastReply");                    // we pass in our arguments verbatim                    CPluginCommand& data_cmd = msg->SetRequest().SetData();                    data_cmd.SetCommand(eDataCommand_load);                    data_cmd.SetArgs().Assign(args.GetArgs());                    // add the RID argument                    data_cmd.SetArgs().AddArgument("RID", "Request Id",                                                    CPluginArg::eString);                    data_cmd.SetArgs()["RID"].SetString(cli->GetRID());                    // pass the query location separately                    data_cmd.SetArgs().AddArgument("query_loc", "Query Seq-loc",                                                   CSeq_loc::GetTypeInfo());                    data_cmd.SetArgs()["query_loc"].SetObject(doc, loc);                    // once done, fire off our message                    CPluginUtils::CallPlugin(*msg);                } else {                    loc.GetLabel(&err_locs);                    err_locs += "\n";                    error = true;                }            }        }        if (error) {            NcbiMessageBox("Error submitting locations:\n" + err_locs);        } else {            reply.SetStatus(eMessageStatus_success);        }        }    catch (CException& e) {        NcbiMessageBox("Failed to submit BLAST search:\n" + e.GetMsg());    }    catch (std::exception& e) {        NcbiMessageBox(string("Failed to submit BLAST search:\n") + e.what());    }}void CNetBlastReq_Base::FinalizeArgs(objects::CPluginMessage& msg){    // determine which BLAST program we're looking at    // this will determine which set of constraints (if any) we impose    string program = msg.GetRequest().GetCommand()["prog"].AsString();    blast::EProgram prog = CBlastUtils::GetBlastProgram(program);    if (prog == blast::eBlastProgramMax) {        return;    }    if ( !sm_Databases ) {        CBlast4Client client;        sm_Databases = client.AskGet_databases();        if ( !sm_Databases ) {            NcbiMessageBox("Failed to contact BLAST server.\n"                           "Network BLAST searches will be disabled.");            return;        }        /**        auto_ptr<CObjectOStream> os            (CObjectOStream::Open(eSerial_AsnText, "c:/temp/blast-dbs.asn"));        *os << *sm_Databases;        **/        sm_DbConstraint_Nucs.Reset(CPluginValueConstraint::CreateSet());        sm_DbConstraint_Prots.Reset(CPluginValueConstraint::CreateSet());        NON_CONST_ITERATE (CBlast4_get_databases_reply::Tdata, iter,                           sm_Databases->Set()) {            const CBlast4_database_info& info = **iter;            // map description -> name            string name = info.GetDatabase().GetName();            sm_DbMap[name] = *iter;            if (info.GetDatabase().GetType() == eBlast4_residue_type_protein) {                *sm_DbConstraint_Prots, info.GetDatabase().GetName();            } else {                *sm_DbConstraint_Nucs, info.GetDatabase().GetName();            }        }    }    switch (prog) {    case blast::eBlastn:    case blast::eTblastn:        msg.SetRequest().SetCommand()            .SetConstraint("subject", *sm_DbConstraint_Nucs);        break;    case blast::eBlastx:    case blast::eBlastp:    case blast::eTblastx:        msg.SetRequest().SetCommand()            .SetConstraint("subject", *sm_DbConstraint_Prots);        break;    default:        break;    }}CBioseq* CNetBlastReq_Base::x_SeqLocToBioseq(const CSeq_loc& loc,                                             CScope& scope){    // Build a Seq-entry for the query Seq-loc    CBioseq_Handle handle = scope.GetBioseqHandle(loc);    if ( !handle ) {        return CRef<CBioseq>();    }    CSeqVector vec =        handle.GetSequenceView(loc,                               CBioseq_Handle::eViewConstructed,                               CBioseq_Handle::eCoding_Iupac);    string seq_string;    vec.GetSeqData(0, vec.size(), seq_string);    CRef<CBioseq> bioseq(new CBioseq());    // curate our inst    bioseq->SetInst().SetRepr(CSeq_inst::eRepr_raw);    bioseq->SetInst().SetLength(seq_string.size());    if (vec.IsProtein()) {        bioseq->SetInst().SetMol(CSeq_inst::eMol_aa);        bioseq->SetInst().SetSeq_data().SetIupacaa(*new CIUPACaa(seq_string));    } else {        bioseq->SetInst().SetMol(CSeq_inst::eMol_na);        bioseq->SetInst().SetSeq_data().SetIupacna(*new CIUPACna(seq_string));        CSeqportUtil::Pack(&bioseq->SetInst().SetSeq_data());    }    // add an ID for our sequence    CRef<CSeq_id> id(new CSeq_id());    id->Assign(*handle.GetSeqId());    bioseq->SetId().push_back(id);    // a title    CRef<CSeqdesc> title(new CSeqdesc);    string title_str;    id->GetLabel(&title_str);    title_str += ": ";    loc.GetLabel(&title_str);    title->SetTitle(title_str);    bioseq->SetDescr().Set().push_back(title);    return bioseq.Release();}blast::CRemoteBlast* CNetBlastReq_Base::x_GetClient(const CPluginCommand& args){    string program = args["prog"].AsString();    blast::EProgram prog = CBlastUtils::GetBlastProgram(program);    if (prog == blast::eBlastProgramMax) {        return NULL;    }    CRef<blast::CRemoteBlast> rb;    switch (prog) {    case blast::eBlastn:        {{            CRef<blast::CBlastNucleotideOptionsHandle> opts                (new blast::CBlastNucleotideOptionsHandle                 (blast::CBlastOptions::eRemote));            opts->SetWordSize       (args["word"].AsInteger());            opts->SetEvalueThreshold(args["expect"].AsDouble());            rb.Reset(new blast::CRemoteBlast(opts));        }}        break;    case blast::eBlastp:        {{            CRef<blast::CBlastProteinOptionsHandle> opts                (new blast::CBlastProteinOptionsHandle                 (blast::CBlastOptions::eRemote));            opts->SetWordSize       (args["word"].AsInteger());            opts->SetEvalueThreshold(args["expect"].AsDouble());            rb.Reset(new blast::CRemoteBlast(opts));        }}        break;    case blast::eBlastx:        {{            CRef<blast::CBlastxOptionsHandle> opts                (new blast::CBlastxOptionsHandle                 (blast::CBlastOptions::eRemote));            opts->SetWordSize       (args["word"].AsInteger());            opts->SetEvalueThreshold(args["expect"].AsDouble());            rb.Reset(new blast::CRemoteBlast(opts));        }}        break;    case blast::eTblastn:        {{            CRef<blast::CTBlastnOptionsHandle> opts                (new blast::CTBlastnOptionsHandle                 (blast::CBlastOptions::eRemote));            opts->SetWordSize       (args["word"].AsInteger());            opts->SetEvalueThreshold(args["expect"].AsDouble());            rb.Reset(new blast::CRemoteBlast(opts));        }}        break;    case blast::eTblastx:        {{            CRef<blast::CTBlastxOptionsHandle> opts                (new blast::CTBlastxOptionsHandle                 (blast::CBlastOptions::eRemote));            opts->SetWordSize       (args["word"].AsInteger());            opts->SetEvalueThreshold(args["expect"].AsDouble());            rb.Reset(new blast::CRemoteBlast(opts));        }}        break;    }    if ( !rb ) {        return NULL;    }    rb->SetDatabase(args["subject"].AsString().c_str());    return rb.Release();}END_NCBI_SCOPE/* * =========================================================================== * $Log: net_blast_req_base.cpp,v $ * Revision 1000.4  2004/06/01 20:54:39  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.16 * * Revision 1.16  2004/05/21 22:27:46  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.15  2004/05/07 15:42:35  dicuccio * Use CLabel instead of CSeqUtils::GetLabel() * * Revision 1.14  2004/05/03 13:05:42  dicuccio * gui/utils --> gui/objutils where needed * * Revision 1.13  2004/04/22 12:22:08  dicuccio * Added BLAST RID caching.  Added better formatting for BLAST results * * Revision 1.12  2004/04/16 14:43:02  dicuccio * Code clean-up.  Separated databases into protein and nucleotide types, provided * separate constraint objects for each. * * Revision 1.11  2004/04/07 20:58:01  ucko * Qualify "exception" with std:: (otherwise ambiguous on some platforms) * * Revision 1.10  2004/04/07 12:54:44  dicuccio * Rewrote submission interface to use CRemoteBlast.  Added FinalizeArgs() to * ping the blast service for the available databases. * * =========================================================================== */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?