-
Notifications
You must be signed in to change notification settings - Fork 26
Searching the taxonomy
Stephen Smith edited this page Oct 11, 2015
·
2 revisions
Hopefully you have peyotl installed and if not check this out. So I assume that you have a working peyotl and you understand virtualenv (if you use it).
##Searching for taxa using the TNRS## In order to do a lot of things, we will need to get ottids, which are the unique ids for taxa in our taxonomy, for clades in which we are interested. This is quite simple with peyotl. The main function is in the taxomachine api and the function is TNRS. Here is an example of a simple script that just gets us an ottid for a particular clade.
from peyotl.api import APIWrapper
import sys
#contexts are from https://github.com/OpenTreeOfLife/opentree/wiki/Open-Tree-of-Life-APIs#contexts
# include
"""
"ANIMALS" : [ "Animals", "Birds", "Tetrapods", "Mammals", "Amphibians", "Vertebrates", "Arthropods", "Molluscs", "Nematodes", "Platyhelminthes", "Annelids", "Cnidarians", "Arachnides", "Insects" ],
"MICROBES" : [ "Bacteria", "SAR group", "Archaea", "Excavata", "Amoebae", "Centrohelida", "Haptophyta", "Apusozoa", "Diatoms", "Ciliates", "Forams" ],
"FUNGI" : [ "Fungi", "Basidiomycetes", "Ascomycetes" ],
"PLANTS" : [ "Land plants", "Hornworts", "Mosses", "Liverworts", "Vascular plants", "Club mosses", "Ferns", "Seed plants", "Flowering plants", "Monocots", "Eudicots", "Rosids", "Asterids", "Asterales", "Asteraceae", "Aster", "Symphyotrichum", "Campanulaceae", "Lobelia" ],
"LIFE" : [ "All life" ]
}
"""
if __name__ == "__main__":
if len(sys.argv) < 2:
print "python "+sys.argv[0]+" name (context)"
sys.exit(0)
nm = sys.argv[1]
tx = APIWrapper().taxomachine
context = None
if len(sys.argv) > 2:
context = " ".join(sys.argv[2:])
nms = tx.TNRS([nm],context)
for i in nms['results']:
for j in i['matches']:
print j['unique_name'],j['ot:ottId']
With this script, if we run
python get_ottid.py Lonicera Eudicots
We will get
Lonicera (genus in order Dipsacales) 649885
Dendrophthoe 1031066
as a result. We can then use these results for other analyses.