NCBI C++ ToolKit
local_taxon.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: local_taxon.hpp 99097 2023-02-13 20:02:01Z mozese2 $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or requeryion.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Eyal Mozes
27  *
28  * File Description:
29  * Class for getting Taxonomy data from local SQLite file
30  */
31 
32 #ifndef LOCAL_TAXON_HPP
33 #define LOCAL_TAXON_HPP
34 
35 #include <corelib/ncbiargs.hpp>
36 #include <corelib/ncbiexpt.hpp>
37 #include <corelib/ncbimtx.hpp>
38 #include <corelib/ncbiobj.hpp>
39 
41 class CSQLITE_Connection;
42 
44 class COrg_ref;
45 class CTaxon1;
47 
48 
50 {
51 public:
52  typedef TTaxId TTaxid;
53  typedef vector<TTaxid> TLineage;
54 
55  static void AddArguments(CArgDescriptions& arg_desc);
56 
57  CLocalTaxon();
58  CLocalTaxon(const CArgs &args);
59 
60  ~CLocalTaxon();
61 
62  bool IsValidTaxid(TTaxid taxid);
63 
64  TTaxid GetParent(TTaxid taxid);
65  string GetRank(TTaxid taxid);
66  TTaxid GetAncestorByRank(TTaxid taxid, const string &rank);
67 
68  TTaxid GetTaxIdByOrgRef(const objects::COrg_ref &inp_orgRef);
69 
71  { return GetAncestorByRank(taxid, "species"); }
73  { return GetAncestorByRank(taxid, "genus"); }
75  { return GetAncestorByRank(taxid, "order"); }
76 
77  TLineage GetLineage(TTaxid taxid);
78  TTaxid Join(TTaxid taxid1, TTaxid taxid2);
79 
80  string GetScientificName(TTaxid taxid);
81  short int GetGeneticCode(TTaxid taxid);
83  void LookupMerge(objects::COrg_ref& org);
84  list<string> GetSynonyms(TTaxId taxid);
85 
86 public: // lookups other than taxid
87 
88  TTaxid GetTaxIdByName(const string& orgname);
89 
90 private: // data types
91  struct STaxidNode;
96  typedef list<TNodeRef> TInternalLineage;
97 
98  struct STaxidNode {
100  bool is_valid;
102  list<string> synonyms;
103  string rank;
105  short int genetic_code;
107 
108  STaxidNode();
109  ~STaxidNode();
110  };
111 private: // static
114 
115 private: // data model
118  unique_ptr<CSQLITE_Connection> m_SqliteConn;
119  unique_ptr<objects::CTaxon1> m_TaxonConn;
122 private: // implementation
123  TNodeRef x_Cache(TTaxid taxid, bool including_org_ref = false);
124  TScientificNameRef x_Cache(const string& orgname);
125  void x_GetLineage(TTaxid taxid, TInternalLineage &lineage);
126  bool x_SupportsSynonym();
127 };
128 
129 
131 
132 
133 #endif /// LOCAL_TAXON_HPP
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
TTaxid GetGenus(TTaxid taxid)
Definition: local_taxon.hpp:72
unique_ptr< objects::CTaxon1 > m_TaxonConn
static TNodeRef s_InvalidNode
list< TNodeRef > TInternalLineage
Definition: local_taxon.hpp:96
map< string, STaxidNode > TScientificNameIndex
Definition: local_taxon.hpp:93
TTaxid GetOrder(TTaxid taxid)
Definition: local_taxon.hpp:74
TNodes::const_iterator TNodeRef
Definition: local_taxon.hpp:94
bool m_db_supports_synonym
TTaxid GetSpecies(TTaxid taxid)
Definition: local_taxon.hpp:70
vector< TTaxid > TLineage
Definition: local_taxon.hpp:53
TNodes m_Nodes
map< TTaxId, STaxidNode > TNodes
Definition: local_taxon.hpp:91
TTaxId TTaxid
Definition: local_taxon.hpp:52
unique_ptr< CSQLITE_Connection > m_SqliteConn
TScientificNameIndex m_ScientificNameIndex
TScientificNameIndex::const_iterator TScientificNameRef
Definition: local_taxon.hpp:95
static TNodes s_DummyNodes
Connection to SQLite database.
CConstRef< COrg_ref > GetOrgRef(TTaxId tax_id, bool &is_species, bool &is_uncultured, string &blast_name, bool *is_specified=NULL)
Definition: taxon1.cpp:704
TTaxId GetTaxIdByName(const string &orgname)
Definition: taxon1.cpp:523
TTaxId GetTaxIdByOrgRef(const COrg_ref &inp_orgRef)
Definition: taxon1.cpp:489
CConstRef< CTaxon2_data > LookupMerge(COrg_ref &inp_orgRef, string *psLog=0, TOrgRefStatus *pStatusOut=0)
Definition: taxon1.cpp:429
TTaxId GetParent(TTaxId id_tax)
Definition: taxon1.cpp:761
bool GetScientificName(TTaxId tax_id, string &name_out)
Definition: taxon1.cpp:2390
TTaxId Join(TTaxId taxid1, TTaxId taxid2)
Definition: taxon1.cpp:1220
TTaxId GetAncestorByRank(TTaxId id_tax, const char *rank_name)
Definition: taxon1.cpp:942
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
int GetGeneticCode(const CBioseq_Handle &bsh)
Defines command line argument related classes.
Defines NCBI C++ exception handling.
Multi-threading – mutexes; rw-locks; semaphore.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CConstRef< objects::COrg_ref > org_ref
list< string > synonyms
Modified on Wed Feb 28 07:11:14 2024 by modify_doxy.py rev. 669887