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)
144 return m_Nodes.
find(taxid)->second.scientific_name;
146 string scientific_name;
147 m_TaxonConn->GetScientificName(taxid, scientific_name);
148 return scientific_name;
158 return m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
171 new_org.
SetDb().insert(
172 new_org.
SetDb().end(),
178 it1 != new_org.
SetDb().end(); ++it1) {
180 vector<CRef<CDbtag> >::iterator it2 = it1;
181 for (++it2; it2 != new_org.
SetDb().
end(); ) {
182 if ((*it1)->Equals(**it2)) {
183 it2 = new_org.
SetDb().erase(it2);
197 vector<CRef<CDbtag> >& dbs = org.
SetDb();
199 if ( (*it)->GetDb() ==
"taxon" ) {
214 if( ! org.IsSetDb() ) {
217 taxid = org.GetTaxId();
225 new_org->
Assign(*public_org);
226 if (org.IsSetOrgname() && org.GetOrgname().IsSetMod()) {
228 org.GetOrgname().GetMod();
230 if ( !new_org->
Equals(org) ) {
232 s_CopyDbTags(org, *new_org);
233 org.Assign(*new_org);
248 bool is_species, is_uncultured;
250 return m_TaxonConn->GetOrgRef(taxid, is_species, is_uncultured, blast_name);
260 if (ancestor->second.rank == rank) {
261 return ancestor->first;
266 return m_TaxonConn->GetAncestorByRank(taxid, rank.c_str());
283 "GetTaxIdByOrgRef not supported for local execution");
293 for (
TNodeRef ancestor : internal_lineage) {
294 lineage.push_back(ancestor->first);
300 lineage.push_back(ancestor);
302 reverse(lineage.begin(), lineage.end());
312 TLineage::const_iterator it1 = lineage1.begin(),
313 it2 = lineage2.begin();
314 for (; it1 != lineage1.end() && it2 != lineage2.end() && *it1 == *it2;
363 string sql =
"SELECT taxid FROM TaxidInfo WHERE scientific_name = ?1 COLLATE NOCASE ";
366 "SELECT taxid FROM Synonym WHERE scientific_name = ?1 COLLATE NOCASE ";
370 stmt.Bind(1, orgname);
401 if (it !=
m_Nodes.
end() && (!including_org_ref || it->second.org_ref))
413 it->second.taxid = taxid;
417 "SELECT scientific_name, rank, parent, genetic_code "
423 it->second.is_valid =
true;
424 it->second.scientific_name =
stmt.GetString(0);
425 it->second.rank =
stmt.GetString(1);
426 if (it->second.rank.empty()) {
427 it->second.rank =
"no rank";
430 it->second.genetic_code =
stmt.GetInt(3);
433 "SELECT scientific_name "
438 while (syn_stmt.
Step()) {
439 it->second.synonyms.push_back( syn_stmt.
GetString(0));
447 it->second.scientific_name))
449 it->second.is_valid =
true;
451 ->GetNode()->GetRank();
452 m_TaxonConn->GetRankName(rank_id, it->second.rank);
453 it->second.genetic_code =
454 m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
455 m_TaxonConn->GetAllNames(taxid, it->second.synonyms,
true);
464 it->second.parent =
x_Cache(parent);
468 if (it->second.is_valid && including_org_ref) {
471 "SELECT org_ref_asn "
477 string org_ref_asn =
stmt.GetString(0);
478 if (!org_ref_asn.empty()) {
482 it->second.org_ref = org_ref;
488 bool is_species, is_uncultured;
490 it->second.org_ref =
m_TaxonConn->GetOrgRef(taxid, is_species,
491 is_uncultured, blast_name);
501 if (!it->second.is_valid) {
504 lineage.push_front(it);
506 lineage.push_front(lineage.front()->second.parent);
513 "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Synonym'");
516 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.