wbplg_splign.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:9k
- /*
- * ===========================================================================
- * PRODUCTION $Log: wbplg_splign.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:26:20 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.5
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: wbplg_splign.cpp,v 1000.0 2004/06/01 21:26:20 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: Yuri Kapustin
- *
- * File Description:
- * Splign Genome Workbench Plugin
- */
- #include <ncbi_pch.hpp>
- #include "wbplg_splign.hpp"
- #include <algo/align/splign/splign_simple.hpp>
- #include <corelib/ncbitime.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginArgSet.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginMessage.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/utils/message_box.hpp>
- #include <gui/objutils/label.hpp>
- #include <objects/seqalign/Dense_seg.hpp>
- #include <objects/seqalign/Seq_align.hpp>
- #include <objmgr/seq_vector.hpp>
- #include <objmgr/util/feature.hpp>
- #include <objmgr/util/sequence.hpp>
- //////////
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- const char kStrand_plus[] = "plus";
- const char kStrand_minus[] = "minus";
- // GetInfo()
- // static interface to retrieve plugin registration information
- void CAlgoPlugin_Splign::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_Splign",
- "Alignments/Spliced Alignment",
- "Compute cDNA-to-genomic alignments",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("seqs", "Sequences to align",
- CSeq_loc::GetTypeInfo(),
- CPluginArg::TData::e_Array);
- args.SetConstraint("seqs",
- (*CPluginValueConstraint::CreateSeqMol(),
- CSeq_inst::eMol_na,
- CSeq_inst::eMol_dna,
- CSeq_inst::eMol_rna));
- args.AddDefaultArgument("strand", "cDna strand",
- CPluginArg::eString,
- kStrand_plus);
- args.SetConstraint("strand", (*CPluginValueConstraint::CreateSet(),
- kStrand_plus, kStrand_minus));
- args.AddDefaultArgument("compartment_penalty",
- "Compartment penalty",
- CPluginArg::eDouble,
- ".75");
- args.SetConstraint("compartment_penalty",
- *(CPluginValueConstraint::CreateRange("0", "1")));
- args.AddDefaultArgument("min_idty",
- "Min exon identity",
- CPluginArg::eDouble,
- "0.75");
- args.SetConstraint("min_idty",
- *(CPluginValueConstraint::CreateRange("0", "1")));
- }
- void CAlgoPlugin_Splign::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& cmd = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- reply.SetStatus(eMessageStatus_failed);
- // check to see that we were passed sequences to begin with
- if ( !CPluginUtils::IsValid(cmd["seqs"]) ) {
- reply.SetStatus(eMessageStatus_failed);
- return;
- }
- // make sure we have exactly two sequences
- plugin_args::TLocList locs;
- GetArgValue(cmd["seqs"], locs);
- if (locs.size() != 2) {
- reply.SetStatus(eMessageStatus_ignored);
- return;
- }
- // make sure that the sequences are of a known type; fetch the seqlocs
- CRef<CScope> new_scope;
- ITERATE (plugin_args::TLocList, loc_iter, locs) {
- const CSeq_loc& loc = *loc_iter->second;
- const IDocument& doc = *loc_iter->first;
- CScope& scope = doc.GetScope();
- if ( !new_scope ) {
- new_scope.Reset(&scope);
- }
- if ( !sequence::IsOneBioseq(loc, &scope) ) {
- string msg = CPluginUtils::GetLabel(loc, &doc.GetScope());
- LOG_POST(Info << "CAlgoPlugin_Splign: "
- "location on multiple bioseqs ignored: " << msg);
- continue;
- }
- }
- CConstRef<CSeq_loc> seqloc_cDna (locs.front().second);
- CConstRef<CSeq_loc> seqloc_genomic (locs.back().second);
- try {
- CSplignSimple splign_simple (*seqloc_cDna, *seqloc_genomic,
- *new_scope);
- CSplign& splign = splign_simple.SetSplignObject();
- splign.SetEndGapDetection(true);
- splign.SetPolyaDetection(true);
- splign.SetStrand(cmd["strand"].AsString() == kStrand_plus);
- splign.SetMaxGenomicExtension(75000);
- splign.SetMinQueryCoverage(0.01);
- splign.SetCompartmentPenalty(cmd["compartment_penalty"].AsDouble());
- splign.SetMinExonIdentity(cmd["min_idty"].AsDouble());
- splign_simple.Run();
- CRef<CSeq_align_set> seqalign_set = splign_simple.GetResultsAsAln();
- // pack the alignment in a Seq-annot and label it appropriately
- CRef<CSeq_annot> seqannot (new CSeq_annot());
- CSeq_annot::TData::TAlign& seqannot_align =
- seqannot->SetData().SetAlign();
- ITERATE(CSeq_align_set::Tdata, align, seqalign_set->Get()) {
- seqannot_align.push_back(*align);
- }
- // prepare a title
- string str = "Spliced alignment of ";
- CLabel::GetLabel(*seqloc_cDna, &str,
- CLabel::eDefault, new_scope);
- str += " and ";
- CLabel::GetLabel(*seqloc_genomic, &str,
- CLabel::eDefault, new_scope);
-
- seqannot->AddTitle(str);
- CTime time;
- time.GetLocalTime();
- seqannot->SetCreateDate(time);
- //
- // 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, locs) {
- if ( !doc_ref ) {
- doc_ref.Reset(iter->first);
- } else if (iter->first != doc_ref) {
- doc_ref.Reset();
- break;
- }
- }
- 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, locs) {
- new_scope->AddScope(iter->first->GetScope());
- }
- doc_ref.Reset(CDocManager::CreateDocument(*new_scope, *seqannot));
- } else {
- reply.AddAction(CPluginReplyAction::e_Add_to_document);
- }
- reply.AddObject(*doc_ref, *seqannot);
- reply.SetStatus(eMessageStatus_success);
- }
- catch (CException& e) {
- NcbiMessageBox("Spliced alignment failed:n" + e.GetMsg());
- }
- catch(exception& e) {
- NcbiMessageBox(string("Spliced alignment failed:n") + e.what());
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: wbplg_splign.cpp,v $
- * Revision 1000.0 2004/06/01 21:26:20 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.5
- *
- * Revision 1.5 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.4 2004/05/20 12:36:43 dicuccio
- * Minor code clean-up. Reordered constraints to be next to arguments. Use
- * CLabel for labels instead of native label functions. Use
- * CSeq_annot::SetCreateTime() instead of doing this manually
- *
- * Revision 1.3 2004/05/18 17:49:47 kapustin
- * Shorten argument descriptions to fit workbench plugin title space
- *
- * Revision 1.2 2004/05/17 20:53:03 kapustin
- * Fix the seqs constraint
- *
- * Revision 1.1 2004/05/17 15:11:44 kapustin
- * Initial revision
- *
- * ===========================================================================
- */