select_feature.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:8k
- /*
- * ===========================================================================
- * PRODUCTION $Log: select_feature.cpp,v $
- * PRODUCTION Revision 1000.1 2004/06/01 20:55:46 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: select_feature.cpp,v 1000.1 2004/06/01 20:55:46 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_SelectFeature -- implements the algorithm to calculate GC composition
- */
- #include <ncbi_pch.hpp>
- #include "select_feature.hpp"
- #include <gui/core/plugin_utils.hpp>
- #include <gui/core/version.hpp>
- #include <gui/dialogs/col/multi_col_dlg.hpp>
- #include <gui/plugin/AlgoCommand.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginValueConstraint.hpp>
- #include <gui/objutils/utils.hpp>
- #include <objects/seqfeat/SeqFeatData.hpp>
- #include <objects/seqfeat/Seq_feat.hpp>
- #include <objmgr/feat_ci.hpp>
- #include <util/static_map.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(objects);
- //
- // static lookup table for converting string-based feature type to actual
- // feature type
- //
- // these must be in "ASCIIbetical" order; beware of the fact that
- // closing quotes sort after spaces.
- //
- typedef pair<const char*, CSeqFeatData::E_Choice> TFeatType;
- static const TFeatType s_FeatureTypes[] = {
- TFeatType("Biological source", CSeqFeatData::e_Biosrc),
- TFeatType("Bond", CSeqFeatData::e_Bond),
- TFeatType("Coding region", CSeqFeatData::e_Cdregion),
- TFeatType("Comment", CSeqFeatData::e_Comment),
- TFeatType("Gene", CSeqFeatData::e_Gene),
- TFeatType("Heterogen", CSeqFeatData::e_Het),
- TFeatType("Imported feature", CSeqFeatData::e_Imp),
- TFeatType("Non-standard residue", CSeqFeatData::e_Non_std_residue),
- TFeatType("Numbering system", CSeqFeatData::e_Num),
- TFeatType("Organism", CSeqFeatData::e_Org),
- TFeatType("Protein", CSeqFeatData::e_Prot),
- TFeatType("Protein secondary structure", CSeqFeatData::e_Psec_str),
- TFeatType("Publication", CSeqFeatData::e_Pub),
- TFeatType("RNA", CSeqFeatData::e_Rna),
- TFeatType("Region", CSeqFeatData::e_Region),
- TFeatType("Restriction site", CSeqFeatData::e_Rsite),
- TFeatType("Sequence", CSeqFeatData::e_Seq),
- TFeatType("Site", CSeqFeatData::e_Site),
- TFeatType("Transcription Initiation", CSeqFeatData::e_Txinit),
- TFeatType("User-defined", CSeqFeatData::e_User)
- };
- typedef CStaticArrayMap<const char*, CSeqFeatData::E_Choice, PCase> TFeatTypeMap;
- static const TFeatTypeMap s_FeatureMap(s_FeatureTypes, sizeof(s_FeatureTypes));
- CAlgoPlugin_SelectFeature::~CAlgoPlugin_SelectFeature()
- {
- }
- // standard info boilerplate
- void CAlgoPlugin_SelectFeature::GetInfo(CPluginInfo& info)
- {
- info.Reset();
- // version info macro
- info.SetInfo(CPluginVersion::eMajor, CPluginVersion::eMinor, 0,
- string(__DATE__) + " " + string(__TIME__),
- "CAlgoPlugin_SelectFeature", "Search/Features",
- "Search for features matching particular critera",
- "");
- // command info
- CPluginCommandSet& cmds = info.SetCommands();
- CPluginCommand& args = cmds.AddAlgoCommand(eAlgoCommand_run);
- args.AddArgument("locs", "Locations to evaluate",
- CSeq_loc::GetTypeInfo(),
- CPluginArg::TData::e_Array);
- // create a constraint type for features
- CRef<CPluginValueConstraint> type_cons
- (CPluginValueConstraint::CreateSet());
- ITERATE (TFeatTypeMap, iter, s_FeatureMap) {
- *type_cons, iter->first;
- }
- // constrain to features of type
- args.AddOptionalArgument("type", "Feature type",
- CPluginArg::eString);
- args.SetConstraint("type", *type_cons);
- // constrain to features of subtype
- // constrain to features whose label matches a given pattern
- args.AddOptionalArgument("label_pattern",
- "Feature label like",
- CPluginArg::eString);
- // constrain to features within near_range bases of a feature of a given
- // type
- args.AddOptionalArgument("near_type", "Near features of type",
- CPluginArg::eString);
- args.SetConstraint("near_type", *type_cons);
- args.AddOptionalArgument("near_range", "Near range",
- CPluginArg::eInteger);
- }
- void CAlgoPlugin_SelectFeature::RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- reply.SetStatus(eMessageStatus_failed);
- plugin_args::TLocList locs;
- GetArgValue(args["locs"], locs);
- SAnnotSelector sel = CSeqUtils::GetAnnotSelector();
- if (args.HasArgument("type") && CPluginUtils::IsValid(args["type"])) {
- CSeqFeatData::E_Choice type =
- s_FeatureMap.find(args["type"].AsString().c_str())->second;
- sel.SetFeatType(type);
- }
- string pattern;
- if (args.HasArgument("label_pattern") &&
- CPluginUtils::IsValid(args["label_pattern"])) {
- pattern = args["label_pattern"].AsString();
- }
- ITERATE (plugin_args::TLocList, iter, locs) {
- const CSeq_loc& loc = *iter->second;
- const IDocument& doc = *iter->first;
- CFeat_CI feat_iter(doc.GetScope(), loc, sel);
- for ( ; feat_iter; ++feat_iter) {
- reply.AddObject(doc, feat_iter->GetOriginalFeature());
- }
- }
- reply.SetStatus(eMessageStatus_success);
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: select_feature.cpp,v $
- * Revision 1000.1 2004/06/01 20:55:46 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- *
- * Revision 1.6 2004/05/21 22:27:47 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.5 2004/05/03 13:05:42 dicuccio
- * gui/utils --> gui/objutils where needed
- *
- * Revision 1.4 2004/02/04 18:05:34 grichenk
- * Added annotation filtering by set of types/subtypes.
- * Renamed *Choice to *Type in SAnnotSelector.
- *
- * Revision 1.3 2004/01/29 17:27:18 ucko
- * Ensure that TFeatTypeMap specifies comparing C strings by value rather
- * than memory location.
- *
- * Revision 1.2 2004/01/28 03:59:43 ucko
- * Fix order of s_FeatureTypes.
- *
- * Revision 1.1 2004/01/27 18:38:31 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */