55 "SQLite file containing taxon database, to use "
56 "instead of CTaxon1 service",
59 arg_desc.
AddFlag(
"fallback-to-taxon-service",
60 "If organism not found in SQLIlte database, fall back to "
75 if (args[
"taxon-db"]) {
83 m_fallback = args[
"fallback-to-taxon-service"];
97 , parent(s_InvalidNode)
134 auto node =
m_TaxonConn->GetTreeIterator(taxid)->GetNode();
147 return m_Nodes.
find(taxid)->second.scientific_name;
149 string scientific_name;
150 m_TaxonConn->GetScientificName(taxid, scientific_name);
151 return scientific_name;
161 return m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
174 new_org.
SetDb().insert(
175 new_org.
SetDb().end(),
181 it1 != new_org.
SetDb().end(); ++it1) {
183 vector<CRef<CDbtag> >::iterator it2 = it1;
184 for (++it2; it2 != new_org.
SetDb().
end(); ) {
185 if ((*it1)->Equals(**it2)) {
186 it2 = new_org.
SetDb().erase(it2);
200 vector<CRef<CDbtag> >& dbs = org.
SetDb();
202 if ( (*it)->GetDb() ==
"taxon" ) {
217 if( ! org.IsSetDb() ) {
220 taxid = org.GetTaxId();
228 new_org->
Assign(*public_org);
229 if (org.IsSetOrgname() && org.GetOrgname().IsSetMod()) {
231 org.GetOrgname().GetMod();
233 if ( !new_org->
Equals(org) ) {
235 s_CopyDbTags(org, *new_org);
236 org.Assign(*new_org);
251 bool is_species, is_uncultured;
253 return m_TaxonConn->GetOrgRef(taxid, is_species, is_uncultured, blast_name);
263 if (ancestor->second.rank == rank) {
264 return ancestor->first;
269 return m_TaxonConn->GetAncestorByRank(taxid, rank.c_str());
286 "GetTaxIdByOrgRef not supported for local execution");
296 for (
TNodeRef ancestor : internal_lineage) {
297 lineage.push_back(ancestor->first);
303 lineage.push_back(ancestor);
305 reverse(lineage.begin(), lineage.end());
315 TLineage::const_iterator it1 = lineage1.begin(),
316 it2 = lineage2.begin();
317 for (; it1 != lineage1.end() && it2 != lineage2.end() && *it1 == *it2;
366 string sql =
"SELECT taxid FROM TaxidInfo WHERE scientific_name = ?1 COLLATE NOCASE ";
369 "SELECT taxid FROM Synonym WHERE scientific_name = ?1 COLLATE NOCASE ";
373 stmt.Bind(1, orgname);
404 if (it !=
m_Nodes.
end() && (!including_org_ref || it->second.org_ref))
416 it->second.taxid = taxid;
420 "SELECT scientific_name, rank, parent, genetic_code "
426 it->second.is_valid =
true;
427 it->second.scientific_name =
stmt.GetString(0);
428 it->second.rank =
stmt.GetString(1);
429 if (it->second.rank.empty()) {
430 it->second.rank =
"no rank";
433 it->second.genetic_code =
stmt.GetInt(3);
436 "SELECT scientific_name "
441 while (syn_stmt.
Step()) {
442 it->second.synonyms.push_back( syn_stmt.
GetString(0));
450 it->second.scientific_name))
452 it->second.is_valid =
true;
454 ->GetNode()->GetRank();
455 m_TaxonConn->GetRankName(rank_id, it->second.rank);
456 it->second.genetic_code =
457 m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
458 m_TaxonConn->GetAllNames(taxid, it->second.synonyms,
true);
467 it->second.parent =
x_Cache(parent);
471 if (it->second.is_valid && including_org_ref) {
474 "SELECT org_ref_asn "
480 string org_ref_asn =
stmt.GetString(0);
481 if (!org_ref_asn.empty()) {
485 it->second.org_ref = org_ref;
491 bool is_species, is_uncultured;
493 it->second.org_ref =
m_TaxonConn->GetOrgRef(taxid, is_species,
494 is_uncultured, blast_name);
504 if (!it->second.is_valid) {
507 lineage.push_front(it);
509 lineage.push_front(lineage.front()->second.parent);
516 "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Synonym'");
519 return stmt.GetInt(0) > 0;
string GetRank(TTaxid taxid)
unique_ptr< objects::CTaxon1 > m_TaxonConn
short int GetGeneticCode(TTaxid taxid)
static TNodeRef s_InvalidNode
TTaxid Join(TTaxid taxid1, TTaxid taxid2)
void LookupMerge(objects::COrg_ref &org)
list< TNodeRef > TInternalLineage
TLineage GetLineage(TTaxid taxid)
string GetScientificName(TTaxid taxid)
static void AddArguments(CArgDescriptions &arg_desc)
list< string > GetSynonyms(TTaxId taxid)
TNodeRef x_Cache(TTaxid taxid, bool including_org_ref=false)
CConstRef< objects::COrg_ref > GetOrgRef(TTaxid taxid)
TNodes::const_iterator TNodeRef
bool m_db_supports_synonym
vector< TTaxid > TLineage
TTaxid GetTaxIdByOrgRef(const objects::COrg_ref &inp_orgRef)
void x_GetLineage(TTaxid taxid, TInternalLineage &lineage)
TTaxid GetAncestorByRank(TTaxid taxid, const string &rank)
unique_ptr< CSQLITE_Connection > m_SqliteConn
TTaxid GetParent(TTaxid taxid)
TScientificNameIndex m_ScientificNameIndex
TScientificNameIndex::const_iterator TScientificNameRef
static TNodes s_DummyNodes
bool IsValidTaxid(TTaxid taxid)
TTaxid GetTaxIdByName(const string &orgname)
Connection to SQLite database.
@ fExternalMT
Object and all statements and blobs created on top of it will not be used from different threads simu...
@ fJournalOff
Journaling is completely off (not recommended - transactions cannot be rollbacked unless they consist...
@ fSyncOff
Synchronization is off, database can be corrupted on OS crash or power outage.
@ fVacuumOff
Vacuuming is off, database file can only grow.
@ fTempToMemory
Mode of storing temporary data.
SQL statement executing on SQLite database.
void Bind(int index, int val)
Bind integer value to parameter index.
bool Step(void)
Step through results of the statement.
void Execute(void)
Execute statement without returning any result.
string GetString(int col_ind) const
Get text value from column col_ind in current row.
container_type::iterator iterator
const_iterator end() const
iterator_bool insert(const value_type &val)
container_type::value_type value_type
const_iterator find(const key_type &key) const
constexpr auto end(const ct_const_array< T, N > &in) noexcept
#define ERASE_ITERATE(Type, Var, Cont)
Non-constant version with ability to erase current element, if container permits.
#define TAX_ID_TO(T, tax_id)
#define VECTOR_ERASE(Var, Cont)
Use this macro inside body of ERASE_ITERATE cycle to erase from vector-like container.
SStrictId_Tax::TId TTaxId
Taxon id type.
#define TAX_ID_FROM(T, value)
void AddFlag(const string &name, const string &comment, CBoolEnum< EFlagValue > set_value=eFlagHasValueIfSet, TFlags flags=0)
Add description for flag argument.
void SetDependency(const string &arg1, EDependency dep, const string &arg2)
Define a dependency.
void AddOptionalKey(const string &name, const string &synopsis, const string &comment, EType type, TFlags flags=0)
Add description for optional key without default value.
@ eRequires
One argument requires another.
@ eInputFile
Name of file (must exist and be readable)
#define NCBI_ASSERT(expr, mess)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#define MSerial_AsnText
I/O stream manipulators –.
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
bool IsSetDb(void) const
ids in taxonomic or culture dbases Check if a value has been assigned to Db data member.
TDb & SetDb(void)
Assign a value to Db data member.
void SetOrgname(TOrgname &value)
Assign a value to Orgname data member.
short int TTaxRank
Primitive types for some taxon1 object fields.