blast_base.cpp

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

CPP
304
字号
/* * =========================================================================== * PRODUCTION $Log: blast_base.cpp,v $ * PRODUCTION Revision 1000.5  2004/06/01 20:54:12  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== *//*  $Id: blast_base.cpp,v 1000.5 2004/06/01 20:54:12 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_base.hpp"#include "blast_util.hpp"#include <gui/core/doc_manager.hpp>#include <gui/plugin/PluginInfo.hpp>#include <gui/plugin/PluginCommandSet.hpp>#include <gui/plugin/PluginCommand.hpp>#include <gui/plugin/PluginRequest.hpp>#include <gui/plugin/PluginArgSet.hpp>#include <gui/core/version.hpp>#include <gui/utils/message_box.hpp>#include <gui/core/plugin_utils.hpp>#include <algo/blast/api/bl2seq.hpp>#include <algo/blast/api/blast_options.hpp>#include <objects/seq/Bioseq.hpp>#include <objects/seq/Seq_inst.hpp>#include <objects/seqalign/Seq_align_set.hpp>#include <objects/seqalign/Seq_align.hpp>#include <serial/serial.hpp>#include <serial/objostrasn.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);//// utility function for translating between plugin arg loc-lists// and BLAST loc vectors//inlineblast::TSeqLocVector x_ToBlastVec(const plugin_args::TLocList& locs){    blast::SSeqLoc loc;    blast::TSeqLocVector vec;    vec.reserve(locs.size());    ITERATE (plugin_args::TLocList, iter, locs) {        loc.seqloc = iter->second;        loc.scope = &(iter->first->GetScope());        vec.push_back(loc);    }    return vec;}// standard info boilerplatevoid CAlgoBlast_Base::x_AddStandardArgs(CPluginCommand& command){}void CAlgoBlast_Base::RunCommand(CPluginMessage& msg){    const CPluginCommand& cmd   = msg.GetRequest().GetCommand();    CPluginReply&         reply = msg.SetReply();    //    // retrieve our query sequences    //    plugin_args::TLocList query;    GetArgValue(cmd["query"], query);    //    // retrieve our target sequences    //    plugin_args::TLocList targets;    GetArgValue(cmd["targets"], targets);    //    // compose the query and target sequences into BLAST forms    //    blast::TSeqLocVector query_vec  = x_ToBlastVec(query);    blast::TSeqLocVector target_vec = x_ToBlastVec(targets);    //    // retrieve the program type we're running    //    string prog_name = cmd["prog"].AsString();    //    // switch based on the program    //    CRef<CSeq_annot> annot(new CSeq_annot());    if ( !annot ) {        reply.SetStatus(eMessageStatus_failed);        return;    }    blast::EProgram prog = blast::eBlastn;    if (prog_name == "blastn") {        annot->AddTitle("BLASTn Output");        prog = blast::eBlastn;    } else if (prog_name == "blastp") {        annot->AddTitle("BLASTp Output");        prog = blast::eBlastp;    } else if (prog_name == "blastx") {        annot->AddTitle("BLASTx Output");        prog = blast::eBlastx;    } else {        annot->AddTitle("tBLASTx Output");        prog = blast::eTblastx;    }    //    // parse our options    //    blast::CBl2Seq blaster(query_vec, target_vec, prog);    CBlastUtils::ArgsToBlastOptions(cmd, blaster.SetOptions());    //    // blast!    //    // run blast	blast::TSeqAlignVector aligns = blaster.Run();    // make an annotation	ITERATE (blast::TSeqAlignVector, iter, aligns) {        ITERATE (CSeq_align_set::Tdata, align_iter, (*iter)->Get()) {            if ((*align_iter)->GetSegs().IsDisc()) {                annot->SetData().SetAlign()                    .insert(annot->SetData().SetAlign().end(),                            (*align_iter)->GetSegs().GetDisc().Get().begin(),                            (*align_iter)->GetSegs().GetDisc().Get().end());            } else {                annot->SetData().SetAlign().push_back(*align_iter);            }        }	}    _TRACE("CAlgoBlastBase: found " << annot->GetData().GetAlign().size()           << " alignments");    if (annot->GetData().GetAlign().size() == 0) {        NcbiMessageBox("No alignments found.");        return;    }    //    // pass back to the system.  We may use the same scope and just attach,    // if that is appropriate    //    CConstRef<IDocument> doc_ref;    ITERATE (plugin_args::TLocList, iter, query) {        if ( !doc_ref ) {            doc_ref.Reset(iter->first);        } else if (iter->first != doc_ref) {            doc_ref.Reset();            break;        }    }    if (doc_ref) {        ITERATE (plugin_args::TLocList, iter, targets) {            if (iter->second != doc_ref) {                doc_ref.Reset();                break;            }        }    }    //    // create a new document and launch a viewer for our alignment    //    if ( !doc_ref ) {        //        // query and targets come from different documents        // create a new one to handle the results        //        CRef<CScope> new_scope(new CScope(CDocManager::GetObjectManager()));        ITERATE (plugin_args::TLocList, iter, query) {            new_scope->AddScope(iter->first->GetScope());        }        ITERATE (plugin_args::TLocList, iter, targets) {            new_scope->AddScope(iter->first->GetScope());        }        doc_ref.Reset(CDocManager::CreateDocument(*new_scope, *annot));    }    CRef<CSelectionBuffer> buf(new CSelectionBuffer());    buf->AddSelection(doc_ref, *annot);    CPluginUtils::CallPlugin("CAlnMultiView",                             eViewCommand_new_view, *buf);    reply.AddAction(CPluginReplyAction::e_Add_to_document);    reply.AddObject(*doc_ref, *annot);    reply.SetStatus(eMessageStatus_success);}END_NCBI_SCOPE/* * =========================================================================== * $Log: blast_base.cpp,v $ * Revision 1000.5  2004/06/01 20:54:12  gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * * Revision 1.10  2004/05/21 22:27:46  gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.9  2004/04/07 12:51:48  dicuccio * Removed dead code * * Revision 1.8  2004/01/27 18:40:04  dicuccio * Code clean-up.  Renamed plugin classes to follow standard pattern * * Revision 1.7  2004/01/13 20:36:30  dicuccio * Use CBlastUtils for standard argument processing.  Make sure to pass the new * objects back to the framework with the appropriate action set (add to the * document specified) * * Revision 1.6  2003/12/22 19:25:56  dicuccio * Added check to see if no alignments were produced * * Revision 1.5  2003/11/26 21:08:07  ucko * Adjust for current CBlastOptions location and API. * * Revision 1.4  2003/11/06 20:12:12  dicuccio * Cleaned up handling of USING_SCOPE - removed from all headers * * Revision 1.3  2003/11/04 17:49:22  dicuccio * Changed calling parameters for plugins - pass CPluginMessage instead of paired * CPluginCommand/CPluginReply * * Revision 1.2  2003/11/03 17:41:19  dicuccio * Fixed to match changes in BLAST API * * Revision 1.1  2003/10/23 16:23:04  dicuccio * Moved code from algo/blast to algo/align * * Revision 1.3  2003/09/29 20:01:37  dicuccio * Fixed null dereference - must allocate annot.  Cleaned up access to parameters * * Revision 1.2  2003/09/29 19:28:01  dicuccio * Implemented variants of BLAST * * Revision 1.1  2003/09/25 17:41:10  dicuccio * Split BLAST plugin into three plugins, one each for BLASTn, BLASTp, and tBLASTn * * Revision 1.5  2003/09/04 18:36:23  dicuccio * Changed to use plugin_args namespace * * Revision 1.4  2003/09/04 14:05:24  dicuccio * Use IDocument instead of CDocument * * Revision 1.3  2003/08/21 12:03:08  dicuccio * Make use of new typedef in plugin_utils.hpp for argument values. * * Revision 1.2  2003/08/18 14:44:00  dicuccio * Partial fix for compilation issues * * Revision 1.1  2003/08/15 18:59:14  dicuccio * Initial revision * * =========================================================================== */

⌨️ 快捷键说明

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