The complete taxonomy tree as built from one or more files such as nodes.dmp. More...
#include <ms_taxonomyrules.hpp>
Public Member Functions | |
ms_taxonomytree (const ms_taxonomyrules *taxonomyRules, const char *taxonomyDirectory="../taxonomy", const bool useIndex=true, const bool createList=false, const char *preparingDirectory="../taxonomy/preparing", const char *oldDirectory="../taxonomy/old") | |
Create a taxonomy tree based on the rules specified in mascot.dat. | |
ms_taxonomytree (const ms_taxonomytree &src) | |
Copying constructor. | |
~ms_taxonomytree () | |
Destructor. | |
void | appendErrors (const ms_errors &src) |
Copies all errors from another instance and appends them at the end of own list. | |
void | clearAllErrors () |
Remove all errors from the current list of errors. | |
void | copyFrom (const ms_errors *right) |
Use this member to make a copy of another instance. | |
void | copyFrom (const ms_taxonomytree *right) |
Can be used to create a copy of another instance. | |
const ms_errs * | getErrorHandler () const |
Retrive the error object using this function to get access to all errors and error parameters. | |
int | getLastError () const |
Return the error description of the last error that occurred. | |
std::string | getLastErrorString () const |
Return the error description of the last error that occurred. | |
bool | getParent (const int id, int &ttParent, int &ttGenTable) const |
Return the parent id and translation table id for a species. | |
TAX_TREE_NODES * | getTaxIDArray () |
Return a raw array of TAX_TREE_NODE values, with the array index being the id. | |
bool | isIncludedIn (const int id, const ms_taxonomychoice *choice) const |
Return true if the taxonomy id is included in the choice. | |
bool | isSpeciesDescendantOf (const int parentID, const int id) const |
Determine if a particular id is a child of the parentID. | |
bool | isValid () const |
Call this function to determine if there have been any errors. | |
ms_taxonomytree & | operator= (const ms_taxonomytree &right) |
Assignment operator for C++ client applications. | |
The complete taxonomy tree as built from one or more files such as nodes.dmp.
Used for determining the taxonomy lineage. This class is used to load all of the files specified in a specified taxonomy section in mascot.dat, for example:
NodesFiles NCBI:nodes.dmp, NCBI:merged.dmp
Index files are created using ms_tinycdb to improve performance in cases where a moderate number of parent id's are required. Index files are created in the same directory as the text files, with an additional 'extension' of ".cdb". Error or warning messages in ms_tinycdb are concatenated into the ms_taxonomytree object. If, for example, the process does not have write access to the directory with the taxonomy files , then an error ms_errs:: is generated, but the object is still valid and will continue with just the text files.
Other possible errors include: ms_errs::ERR_MSP_TAXONOMY_CONFLICT_PARENTS ms_errs::ERR_MSP_TAXONOMY_INVALID_NODE_FILE ms_errs::ERR_MSP_TAXONOMY_MISSING_NODE_FILE
The nodes.dmp file also contains the genetic code translation table id to be used when translating from nucleic acid to protein.
Example code to see if Homo Sapiens (9606) are mammals (40674):
my $datfile = new msparser::ms_datfile("../config/mascot.dat"); my $taxonomy_rules = $datfile->getTaxonomyRules(3); my $tree = new msparser::ms_taxonomytree($taxonomy_rules); if ($tree->isValid()) { my $human = 9606; my $mammalia = 40674; if ($tree->isSpeciesDescendantOf($mammalia, $human)) { print "Indeed, we are mammals\n"; } }
ms_taxonomytree | ( | const ms_taxonomyrules * | taxonomyRules, |
const char * | taxonomyDirectory = "../taxonomy" , |
||
const bool | useIndex = true , |
||
const bool | createList = false , |
||
const char * | preparingDirectory = "../taxonomy/preparing" , |
||
const char * | oldDirectory = "../taxonomy/old" |
||
) |
Create a taxonomy tree based on the rules specified in mascot.dat.
The complete taxonomy tree as built from one or more files such as nodes.dmp
taxonomyRules | contains the list of NodesFiles specified in the taxonomy section of mascot.dat. These files are all loaded by this constructor. The names are retrieved using ms_taxonomyrules::getNodesFile |
taxonomyDirectory | specifies the directory to look in for the files. The names in mascot.dat do not normally include path information since the files are generally in the ../taxonomy directory |
useIndex | will normally be set to true. If just a handful of 'parent ids' are required, then it is most efficient to use the index files. See getTaxIDArray() for a situation where this should be set to false. |
createList | will normally be set to false. It is used to create the list of nodes in memory even if the cache file is used. |
preparingDirectory | optional parameter to specify a directory to look for new files and create temporary index files. Once the index files have been created, the new file and the created index files are moved to taxonomyDirectory. If this parameter is an empty string, or if there are no taxonomy files in this directory, new files will be looked for in taxonomyDirectory instead, and the index files will be created directly in taxonomyDirectory. |
oldDirectory | optional parameter to archive existing files once index files have been created for a new file. If this parameter is an empty string, no archiving will be done. |
|
inherited |
Copies all errors from another instance and appends them at the end of own list.
src | The object to copy the errors across from. See Maintaining object references: two rules of thumb. |
|
inherited |
Remove all errors from the current list of errors.
The list of 'errors' can include fatal errors, warning messages, information messages and different levels of debugging messages.
All messages are accumulated into a list in this object, until clearAllErrors() is called.
See Error Handling.
|
inherited |
Use this member to make a copy of another instance.
right | is the source to initialise from |
void copyFrom | ( | const ms_taxonomytree * | right | ) |
Can be used to create a copy of another instance.
Useful from Perl or scripting languages
right | is the object to copy from |
|
inherited |
Retrive the error object using this function to get access to all errors and error parameters.
See Error Handling.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
bool getParent | ( | const int | id, |
int & | ttParent, | ||
int & | ttGenTable | ||
) | const |
Return the parent id and translation table id for a species.
See Multiple return values in Perl, Java, Python and C#.
[in] | id | is the NCBI taxonomy id for which to find the parent and translation table. |
[out] | ttParent | is the parent id. This will be set to 0 if an entry is not found for id. |
[out] | ttGenTable | is the genetic code translation table to be used for converting nucleic acid sequences to protein sequences. |
ms_taxonomytree::TAX_TREE_NODES * getTaxIDArray | ( | ) |
Return a raw array of TAX_TREE_NODE values, with the array index being the id.
This function will only return a non zero value if the useIndex value passed to the constructor is set to false.
The calling function should not call delete on the pointer. The vector is deleted when the ms_taxonomytree object is deleted.
bool isIncludedIn | ( | const int | id, |
const ms_taxonomychoice * | choice | ||
) | const |
Return true if the taxonomy id is included in the choice.
For example, take the definition of "Other Mammalia":
Title:. . . . . . . . . . . . . . Other mammalia Include: 40674 Exclude: 9443, 9989
If you pass 9606 (Human) and a choice of "Other Mammalia", this function would return false, because in this case, 9606 is part of 9443 (Primates).
id | is the taxonomy id |
choice | is the return from calling ms_taxonomyfile::getEntryByName |
bool isSpeciesDescendantOf | ( | const int | parentID, |
const int | id | ||
) | const |
Determine if a particular id is a child of the parentID.
parentID | is the taxonomy id of the parent |
id | is the taxonomy id to be tested |
|
inherited |
Call this function to determine if there have been any errors.
This will return true unless there have been any fatal errors.
See Error Handling.
ms_taxonomytree & operator= | ( | const ms_taxonomytree & | right | ) |
Assignment operator for C++ client applications.
Cannot be used from scripting languages
right | is the object to copy from |