52 "SQLite file containing taxon database, to use "
53 "instead of CTaxon1 service",
56 arg_desc.
AddFlag(
"fallback-to-taxon-service",
57 "If organism not found in SQLIlte database, fall back to "
72 if (args[
"taxon-db"]) {
80 m_fallback = args[
"fallback-to-taxon-service"];
101 , parent(GetInvalidNode())
138 auto node =
m_TaxonConn->GetTreeIterator(taxid)->GetNode();
151 return m_Nodes.
find(taxid)->second.scientific_name;
153 string scientific_name;
154 m_TaxonConn->GetScientificName(taxid, scientific_name);
155 return scientific_name;
165 return m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
178 new_org.
SetDb().insert(
179 new_org.
SetDb().end(),
185 it1 != new_org.
SetDb().end(); ++it1) {
187 vector<CRef<CDbtag> >::iterator it2 = it1;
188 for (++it2; it2 != new_org.
SetDb().end(); ) {
189 if ((*it1)->Equals(**it2)) {
190 it2 = new_org.
SetDb().erase(it2);
204 vector<CRef<CDbtag> >& dbs = org.
SetDb();
206 if ( (*it)->GetDb() ==
"taxon" ) {
221 if( ! org.IsSetDb() ) {
224 taxid = org.GetTaxId();
232 new_org->
Assign(*public_org);
233 if (org.IsSetOrgname() && org.GetOrgname().IsSetMod()) {
235 org.GetOrgname().GetMod();
237 if ( !new_org->
Equals(org) ) {
239 s_CopyDbTags(org, *new_org);
240 org.Assign(*new_org);
255 bool is_species, is_uncultured;
257 return m_TaxonConn->GetOrgRef(taxid, is_species, is_uncultured, blast_name);
267 if (ancestor->second.rank == rank) {
268 return ancestor->first;
278 return m_TaxonConn->GetAncestorByRank(taxid, rank.c_str());
297 "GetTaxIdByOrgRef not supported for local execution");
307 for (
TNodeRef ancestor : internal_lineage) {
308 lineage.push_back(ancestor->first);
314 lineage.push_back(ancestor);
316 reverse(lineage.begin(), lineage.end());
326 TLineage::const_iterator it1 = lineage1.begin();
327 TLineage::const_iterator it2 = lineage2.begin();
329 for ( ; it1 != lineage1.end() && it2 != lineage2.end() &&
381 string sql =
"SELECT taxid FROM TaxidInfo WHERE scientific_name = ?1 COLLATE NOCASE ";
384 "SELECT taxid FROM Synonym WHERE scientific_name = ?1 COLLATE NOCASE ";
388 stmt.Bind(1, orgname);
419 if (it !=
m_Nodes.
end() && (!including_org_ref || it->second.org_ref))
431 it->second.taxid = taxid;
435 "SELECT scientific_name, rank, parent, genetic_code "
441 it->second.is_valid =
true;
442 it->second.scientific_name =
stmt.GetString(0);
443 it->second.rank =
stmt.GetString(1);
444 if (it->second.rank.empty()) {
445 it->second.rank =
"no rank";
448 it->second.genetic_code =
stmt.GetInt(3);
451 "SELECT scientific_name "
456 while (syn_stmt.
Step()) {
457 it->second.synonyms.push_back( syn_stmt.
GetString(0));
465 it->second.scientific_name))
467 it->second.is_valid =
true;
469 ->GetNode()->GetRank();
470 m_TaxonConn->GetRankName(rank_id, it->second.rank);
471 it->second.genetic_code =
472 m_TaxonConn->GetTreeIterator(taxid)->GetNode()->GetGC();
473 m_TaxonConn->GetAllNames(taxid, it->second.synonyms,
true);
482 it->second.parent =
x_Cache(parent);
486 if (it->second.is_valid && including_org_ref) {
489 "SELECT org_ref_asn "
495 string org_ref_asn =
stmt.GetString(0);
496 if (!org_ref_asn.empty()) {
500 it->second.org_ref = org_ref;
506 bool is_species, is_uncultured;
508 it->second.org_ref =
m_TaxonConn->GetOrgRef(taxid, is_species,
509 is_uncultured, blast_name);
519 if (!it->second.is_valid) {
522 lineage.push_front(it);
524 lineage.push_front(lineage.front()->second.parent);
531 "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='Synonym'");
534 return stmt.GetInt(0) > 0;
string GetRank(TTaxid taxid)
unique_ptr< objects::CTaxon1 > m_TaxonConn
short int GetGeneticCode(TTaxid taxid)
TTaxid Join(TTaxid taxid1, TTaxid taxid2)
static TNodeRef GetInvalidNode()
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
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
static bool is_valid(const char *num, int type, CONV_RESULT *cr)
#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.
Static variables safety - create on demand, destroy on application termination.
short int TTaxRank
Primitive types for some taxon1 object fields.