cdd_search.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:11k
- /*
- * ===========================================================================
- * PRODUCTION $Log: cdd_search.cpp,v $
- * PRODUCTION Revision 1000.6 2004/06/01 20:54:50 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: cdd_search.cpp,v 1000.6 2004/06/01 20:54:50 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:
- * CAlgoPlugin_CDDSearch - load sequence information from a file.
- */
- #include <ncbi_pch.hpp>
- #include "cdd_search.hpp"
- #include <connect/ncbi_conn_stream.hpp>
- #include <gui/core/doc_manager.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/version.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/utils/message_box.hpp>
- #include <objects/seqalign/Dense_seg.hpp>
- #include <objects/seqalign/Std_seg.hpp>
- #include <objects/seqalign/Seq_align.hpp>
- #include <objmgr/bioseq_handle.hpp>
- #include <objmgr/object_manager.hpp>
- #include <objmgr/seq_vector.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <objtools/data_loaders/cdd/cdd.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- CCddDataLoader* CAlgoPlugin_CDDSearch::sm_Loader = NULL;
- CAlgoPlugin_CDDSearch::~CAlgoPlugin_CDDSearch()
- {
- }
- void CAlgoPlugin_CDDSearch::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_CDDSearch",
- "Search/Conserved Domains",
- "Search for conserved domains in this protein",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("id", "Sequence to search",
- CSeq_id::GetTypeInfo());
- args.SetConstraint("id",
- (*CPluginValueConstraint::CreateSeqMol(),
- CSeq_inst::eMol_aa));
- args.AddDefaultArgument("expect", "Expect value",
- CPluginArg::eDouble, "0.01");
- args.AddArgument("filter", "Filter results",
- CPluginArg::eBoolean);
- args.AddDefaultArgument("type", "Type to retrieve",
- CPluginArg::eString,
- "Alignment");
- args.SetConstraint("type",
- (*CPluginValueConstraint::CreateSet(),
- "Alignment", "Feature table"));
- }
- //
- // Save()
- // Save the information in a given document into a file
- //
- void CAlgoPlugin_CDDSearch::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- reply.SetStatus(eMessageStatus_failed);
- const CSeq_id& id = dynamic_cast<const CSeq_id&>(args["id"].AsObject());
- const IDocument* doc = args["id"].GetDocument();
- if ( !doc ) {
- NcbiMessageBox("No valid sequence found.");
- return;
- }
- bool filter = args["filter"].AsBoolean();
- string type = args["type" ].AsString();
- double expect = args["expect"].AsDouble();
- string filter_str("T");
- if ( !filter ) {
- filter_str = "F";
- }
- if (type == "Alignment") {
- type = "LONLY";
- } else if (type == "Feature table") {
- type = "AONLY";
- }
- CScope& scope = doc->GetScope();
- //
- // retrieve our protein sequence
- // we must pass the sequence in IUPACaa format
- //
- CBioseq_Handle handle = scope.GetBioseqHandle(id);
- CSeqVector vec = handle.GetSeqVector();
- vec.SetCoding(CSeq_data::e_Iupacaa);
- string data;
- vec.GetSeqData(0, vec.size(), data);
- //
- // compose our parameters
- //
- string params("SEQUENCE=");
- params += data + "&";
- params += "NOHTML&";
- params += "DATALIB=cdd&";
- params += "EXPECT=" + NStr::DoubleToString(expect) + "&";
- params += "GRAPH=1&";
- params += "FILTER=" + filter_str + "&";
- params += type;
- //
- // CConn_ServiceStream i/o
- //
- CConn_ServiceStream cdd_str("CddSearch");
- cdd_str << params;
- CRef<CSeq_annot> annot(new CSeq_annot());
- try {
- auto_ptr<CObjectIStream> is
- (CObjectIStream::Open(eSerial_AsnText, cdd_str));
- *is >> *annot;
- }
- catch (...) {
- // our read failed - it is likely that our output was not ASN.1
- string msg("No conserved domains were found for sequencen");
- msg += sequence::GetTitle(handle);
- NcbiMessageBox(msg);
- return;
- }
- //
- // fix our IDs
- //
- if (annot->GetData().IsFtable()) {
- if (annot->GetData().GetFtable().size() == 0) {
- annot.Reset();
- } else {
- NON_CONST_ITERATE (CSeq_annot::TData::TFtable, iter,
- annot->SetData().SetFtable()) {
- CSeq_feat* feat = *iter;
- const CSeq_id& this_id = sequence::GetId(feat->SetLocation());
- if (this_id.IsLocal()) {
- feat->SetLocation().SetId(id);
- }
- }
- }
- } else if (annot->GetData().IsAlign()) {
- if (annot->GetData().GetAlign().size() == 0) {
- annot.Reset();
- } else {
- NON_CONST_ITERATE (CSeq_annot::TData::TAlign, iter,
- annot->SetData().SetAlign()) {
- CSeq_align& align = **iter;
- switch (align.GetSegs().Which()) {
- case CSeq_align::TSegs::e_Denseg:
- {{
- CDense_seg& seg = align.SetSegs().SetDenseg();
- NON_CONST_ITERATE(CDense_seg::TIds, id_iter, seg.SetIds()) {
- CSeq_id& this_id = **id_iter;
- if (this_id.IsLocal()) {
- this_id.Assign(id);
- }
- }
- }}
- break;
- case CSeq_align::TSegs::e_Std:
- NON_CONST_ITERATE (CSeq_align::TSegs::TStd, iter,
- align.SetSegs().SetStd()) {
- CStd_seg& seg = **iter;
- NON_CONST_ITERATE(CStd_seg::TIds, id_iter, seg.SetIds()) {
- CSeq_id& this_id = **id_iter;
- if (this_id.IsLocal()) {
- this_id.Assign(id);
- }
- }
- }
- break;
- default:
- LOG_POST(Error << "unhandled seq-align type in CDDSearch");
- break;
- }
- }
- }
- }
- if ( !annot ) {
- string msg("No conserved domains were found for sequencen");
- msg += sequence::GetTitle(handle);
- NcbiMessageBox(msg);
- reply.SetStatus(eMessageStatus_failed);
- return;
- }
- //
- // return our object to the framework
- //
- reply.AddObject(*doc, *annot);
- reply.AddAction(CPluginReplyAction::e_Add_to_document);
- //
- // take care of our data loader
- if ( !sm_Loader ) {
- DEFINE_STATIC_FAST_MUTEX(s_Mutex);
- CFastMutexGuard LOCK(s_Mutex);
- if ( !sm_Loader ) {
- sm_Loader = new CCddDataLoader();
- CDocManager::GetObjectManager().RegisterDataLoader(*sm_Loader);
- }
- }
- scope.AddDataLoader("CDD_DataLoader");
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: cdd_search.cpp,v $
- * Revision 1000.6 2004/06/01 20:54:50 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.13
- *
- * Revision 1.13 2004/05/21 22:27:46 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.12 2004/04/16 14:43:15 dicuccio
- * Deleted dead code
- *
- * Revision 1.11 2004/03/24 13:57:19 friedman
- * Fixed mutex comment
- *
- * Revision 1.10 2004/03/23 19:55:18 friedman
- * Replaced 'static CFastMutex' with DEFINE_STATIC_FAST_MUTEX
- *
- * Revision 1.9 2004/03/16 15:37:22 vasilche
- * Added required include
- *
- * Revision 1.8 2004/01/27 18:37:32 dicuccio
- * Code clean-up. Use standard names for plugins. Removed unnecessary #includes
- *
- * Revision 1.7 2003/11/24 15:45:25 dicuccio
- * Renamed CVersion to CPluginVersion
- *
- * Revision 1.6 2003/11/18 17:47:57 dicuccio
- * Made data loader static and thread-safe. Added standard processing for return values
- *
- * Revision 1.5 2003/11/06 20:12:12 dicuccio
- * Cleaned up handling of USING_SCOPE - removed from all headers
- *
- * Revision 1.4 2003/11/04 17:49:22 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.3 2003/10/20 18:30:56 dicuccio
- * Added CDD data laoder for retrieval of CDD alignment sequences. Cleaned up
- * handling of imput streams
- *
- * Revision 1.2 2003/10/16 19:38:43 dicuccio
- * Removed old debugging code
- *
- * Revision 1.1 2003/10/16 12:56:35 dicuccio
- * Added CDD Search facility. Cleaned up dll_register.cpp
- *
- * Revision 1.2 2003/10/07 13:47:05 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.1 2003/09/16 14:06:48 dicuccio
- * Initial revision - split from CFileLoader
- *
- * ===========================================================================
- */