query.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: query.cpp,v $
- * PRODUCTION Revision 1000.3 2004/06/01 20:56:52 gouriano
- * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: query.cpp,v 1000.3 2004/06/01 20:56:52 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 "query.hpp"
- #include "utils.hpp"
- #include <gui/plugin/PluginInfo.hpp>
- #include <gui/plugin/PluginRequest.hpp>
- #include <gui/plugin/PluginCommand.hpp>
- #include <gui/plugin/PluginCommandSet.hpp>
- #include <gui/plugin/PluginArgSet.hpp>
- #include <gui/plugin/PluginArg.hpp>
- #include <gui/core/version.hpp>
- #include <gui/core/idocument.hpp>
- #include <gui/core/plugin_utils.hpp>
- #include <gui/utils/app_popup.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <corelib/ncbireg.hpp>
- #include <objmgr/util/feature.hpp>
- #include <objmgr/util/sequence.hpp>
- #include <objects/seqfeat/Org_ref.hpp>
- BEGIN_NCBI_SCOPE
- USING_SCOPE(ncbi::objects);
- // standard info boilerplate
- void CAlgoLinkOut_Query::x_AddStandardArgs(CPluginCommand& command)
- {
- // database to search
- command.AddDefaultArgument("db", "Database", CPluginArg::eString,
- "PubMed");
- command.SetConstraint("db",
- (*CPluginValueConstraint::CreateSet(),
- "3D Domains",
- "Books",
- "GEO Data Sets",
- "GEO",
- "Genome",
- "Journals",
- "MeSH",
- "NCBI Web Site",
- "Nucleotide",
- "Online Mendelian Inheritance in Man (OMIM)",
- "Population Studies (PopSet)",
- "Protein",
- "PubMed Central (PMC)",
- "PubMed",
- "Structure",
- "Taxonomy",
- "UniGene",
- "UniSTS"
- "dbSNP"));
- command.AddArgument("org", "Limit to organism", CPluginArg::eBoolean);
- }
- // run our plugin
- void CAlgoLinkOut_Query::x_RunCommand(CPluginMessage& msg)
- {
- const CPluginCommand& args = msg.GetRequest().GetCommand();
- CPluginReply& reply = msg.SetReply();
- // retrieve the default link for Query
- CNcbiApplication* app = CNcbiApplication::Instance();
- _ASSERT(app);
- const CNcbiRegistry& reg = app->GetConfig();
- string query_url =
- reg.GetString("LINKOUT", "Query",
- "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi"
- "?cmd=<cmd>&db=<db>&term=<term>");
- string terms;
- string org;
- bool org_limit = args["org"].AsBoolean();
- //
- // were we called with args = seq-id?
- //
- if (args.HasArgument("seq-id")) {
- // retrieve the seq-id
- plugin_args::TIdList ids;
- GetArgValue(args["seq-id"], ids);
- const CSeq_id& id = *ids.front().second;
- const IDocument& doc = *ids.front().first;
- // get a title from the sequence and use that as the terms
- CBioseq_Handle handle = doc.GetScope().GetBioseqHandle(id);
- if ( !handle ) {
- reply.SetStatus(eMessageStatus_failed);
- return;
- }
- terms = sequence::GetTitle(handle);
- if (org_limit) {
- CConstRef<COrg_ref> ref = GetOrganism(handle);
- if (ref) {
- ref->GetLabel(&org);
- }
- }
- }
- //
- // were we called with args = feat?
- //
- if (args.HasArgument("feat")) {
- // retrieve the feature
- plugin_args::TFeatList feats;
- GetArgValue(args["feat"], feats);
- const CSeq_feat& feat = *feats.front().second;
- const IDocument& doc = *feats.front().first;
- // get a label from the feature and use that as the terms
- feature::GetLabel(feat, &terms, feature::eContent, &doc.GetScope());
- if (org_limit) {
- CBioseq_Handle handle = doc.GetScope().GetBioseqHandle(feat.GetLocation());
- CConstRef<COrg_ref> ref = GetOrganism(handle);
- if (ref) {
- ref->GetLabel(&org);
- }
- }
- }
- //
- // encode our white-space
- if ( !org.empty() ) {
- org = " AND "" + org + "" [ORGN]";
- terms += org;
- }
- string::size_type pos = 0;
- while ( (pos = terms.find_first_of(" ", pos)) != string::npos) {
- terms[pos] = '+';
- }
- //
- // retrieve the database
- //
- string db = args["db"].AsString();
- //
- // what command do we run?
- //
- string cmd = "search";
- //
- // finalize our URL and launch!
- //
- query_url = NStr::Replace(query_url, "<db>", db);
- query_url = NStr::Replace(query_url, "<term>", terms);
- query_url = NStr::Replace(query_url, "<cmd>", cmd);
- if ( !CAppPopup::PopupURL(query_url) ) {
- reply.SetStatus(eMessageStatus_failed);
- } else {
- reply.SetStatus(eMessageStatus_success);
- }
- }
- END_NCBI_SCOPE
- /*
- * ===========================================================================
- * $Log: query.cpp,v $
- * Revision 1000.3 2004/06/01 20:56:52 gouriano
- * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.6
- *
- * Revision 1.6 2004/05/21 22:27:48 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.5 2004/01/27 18:45:27 dicuccio
- * Added missing header files
- *
- * Revision 1.4 2003/11/04 17:49:24 dicuccio
- * Changed calling parameters for plugins - pass CPluginMessage instead of paired
- * CPluginCommand/CPluginReply
- *
- * Revision 1.3 2003/10/07 13:47:04 dicuccio
- * Renamed CPluginURL* to CPluginValue*
- *
- * Revision 1.2 2003/09/25 17:49:17 dicuccio
- * Cleaned up handling of org-refs - implemented private function to return the
- * apporpriate COrg_ref. Added virtual destructors where necessary
- *
- * Revision 1.1 2003/09/23 19:45:45 dicuccio
- * Initial revision
- *
- * ===========================================================================
- */