diff --git a/pytaxize/__init__.py b/pytaxize/__init__.py index d5ce394..82e0293 100644 --- a/pytaxize/__init__.py +++ b/pytaxize/__init__.py @@ -41,41 +41,6 @@ getfullrecordfromlsid, getfullrecordfromtsn, getgeographicdivisionsfromtsn, - getgeographicvalues, - getglobalspeciescompletenessfromtsn, - gethierarchydownfromtsn, - gethierarchyupfromtsn, - getitistermsfromcommonname, - getitisterms, - getitistermsfromscientificname, - hierarchy, - getjurisdictionaloriginfromtsn, - getjurisdictionoriginvalues, - getjurisdictionvalues, - getkingdomnamefromtsn, - getkingdomnames, - getlastchangedate, - getlsidfromtsn, - getothersourcesfromtsn, - getparenttsnfromtsn, - getpublicationsfromtsn, - getranknames, - getrecordfromlsid, - getreviewyearfromtsn, - getscientificnamefromtsn, - gettaxonauthorshipfromtsn, - gettaxonomicusagefromtsn, - gettsnbyvernacularlanguage, - gettsnfromlsid, - getunacceptabilityreasonfromtsn, - getvernacularlanguages, - searchbycommonname, - searchbycommonnamebeginswith, - searchbycommonnameendswith, - searchcommon, - searchbyscientificname, - searchforanymatch, - searchforanymatchpaged, ) -from .tax import names_list, vascan_search +from .tax import names_list, vascan_search, scrapenames from .taxo import taxo_datasources, taxo_resolve diff --git a/pytaxize/col/col.py b/pytaxize/col/col.py index e7da0da..c0a6e65 100644 --- a/pytaxize/col/col.py +++ b/pytaxize/col/col.py @@ -2,13 +2,17 @@ import requests import datetime from lxml import etree -import pandas as pd import re import json import pkg_resources from pytaxize.refactor import Refactor from pytaxize.utils import * +try: + import pandas as pd +except ImportError: + warnings.warn("Pandas library not installed, dataframes disabled") + pd = None def children(name=None, id=None, format=None, start=None, checklist=None): """ diff --git a/pytaxize/gbif/parse.py b/pytaxize/gbif/parse.py index 3ae67b4..9c91c9d 100644 --- a/pytaxize/gbif/parse.py +++ b/pytaxize/gbif/parse.py @@ -1,9 +1,13 @@ -import pandas as pd import json from pytaxize.refactor import Refactor +try: + import pandas as pd +except ImportError: + warnings.warn("Pandas library not installed, dataframes disabled") + pd = None -def parse(name): +def parse(name, as_dataframe=False): """ Parse taxon names using the GBIF name parser. @@ -11,6 +15,8 @@ def parse(name): Returns a DataFrame containing fields extracted from parsed taxon names. Fields returned are the union of fields extracted from all species names in scientificname + :param as_dataframe: (optional) Type: boolean. Return as pandas data frame? + default: False Author John Baumgartner (johnbb@student.unimelb.edu.au) @@ -19,14 +25,18 @@ def parse(name): Usage:: - import pytaxize - pytaxize.gbif_parse(name=['x Agropogon littoralis']) + from pytaxize import gbif + gbif.parse(name=['x Agropogon littoralis']) + names = ['x Agropogon littoralis', 'Helianthus annuus texanus'] + gbif.parse(names) + gbif.parse(names, as_dataframe=True) """ name = list(name) - url = "http://api.gbif.org/v0.9/parser/name" + url = "https://api.gbif.org/v0.9/parser/name" headers = {"content-type": "application/json"} tt = Refactor(url, payload={}, request="post").json( data=json.dumps(name), headers=headers ) - res = pd.DataFrame(tt) - return res + if as_dataframe: + tt = pd.DataFrame(tt) + return tt diff --git a/pytaxize/gn/gnr.py b/pytaxize/gn/gnr.py index aa83b1e..a867f50 100644 --- a/pytaxize/gn/gnr.py +++ b/pytaxize/gn/gnr.py @@ -1,16 +1,13 @@ import sys import requests -import pandas as pd import json import time from pytaxize.refactor import Refactor import os - class NoResultException(Exception): pass - def gnr_datasources(): """ Get data sources for the Global Names Resolver. diff --git a/pytaxize/itis/__init__.py b/pytaxize/itis/__init__.py index e5257a7..820ba45 100644 --- a/pytaxize/itis/__init__.py +++ b/pytaxize/itis/__init__.py @@ -17,39 +17,4 @@ getfullrecordfromlsid, getfullrecordfromtsn, getgeographicdivisionsfromtsn, - getgeographicvalues, - getglobalspeciescompletenessfromtsn, - gethierarchydownfromtsn, - gethierarchyupfromtsn, - getitistermsfromcommonname, - getitisterms, - getitistermsfromscientificname, - hierarchy, - getjurisdictionaloriginfromtsn, - getjurisdictionoriginvalues, - getjurisdictionvalues, - getkingdomnamefromtsn, - getkingdomnames, - getlastchangedate, - getlsidfromtsn, - getothersourcesfromtsn, - getparenttsnfromtsn, - getpublicationsfromtsn, - getranknames, - getrecordfromlsid, - getreviewyearfromtsn, - getscientificnamefromtsn, - gettaxonauthorshipfromtsn, - gettaxonomicusagefromtsn, - gettsnbyvernacularlanguage, - gettsnfromlsid, - getunacceptabilityreasonfromtsn, - getvernacularlanguages, - searchbycommonname, - searchbycommonnamebeginswith, - searchbycommonnameendswith, - searchcommon, - searchbyscientificname, - searchforanymatch, - searchforanymatchpaged, ) diff --git a/pytaxize/itis/itis.py b/pytaxize/itis/itis.py index d4330bf..ae9019b 100644 --- a/pytaxize/itis/itis.py +++ b/pytaxize/itis/itis.py @@ -11,23 +11,7 @@ except ImportError: warnings.warn("Pandas library not installed, dataframes disabled") pd = None -itis_base = "http://www.itis.gov/ITISWebService/services/ITISService/" - - -def itis_ping(**kwargs): - """ - Ping the ITIS API - - Usage:: - - import pytaxize - pytaxize.itis_ping() - """ - tt = Refactor(itis_base + "getDescription", payload={}, request="get").xml(**kwargs) - ns = {"ax26": "http://itis_service.itis.usgs.gov/xsd"} - nodes = tt.xpath("//ax26:description", namespaces=ns) - text = [x.text for x in nodes][0] - return text +itis_base = "http://www.itis.gov/ITISWebService/jsonservice/" def getacceptednamesfromtsn(tsn, **kwargs): @@ -40,22 +24,18 @@ def getacceptednamesfromtsn(tsn, **kwargs): from pytaxize import itis # TSN accepted - good name - itis.getacceptednamesfromtsn('208527') + itis.getacceptednamesfromtsn(tsn=208527) # TSN not accepted - input TSN is old name - itis.getacceptednamesfromtsn('504239') + itis.getacceptednamesfromtsn(tsn=504239) """ out = Refactor( itis_base + "getAcceptedNamesFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - temp = out.getchildren() - if temp[0].getchildren()[1].values()[0] == "true": - dat = temp[0].getchildren()[0].text + ).json(**kwargs) + if out["acceptedNames"][0] is None: + return {} else: - nodes = temp[0].getchildren()[1].getchildren() - dat = _parse_nodes(nodes) - dat.pop("author") - dat["submittedTsn"] = temp[0].getchildren()[0].text - return dat + out["acceptedNames"][0].pop("class") + return out["acceptedNames"][0] def getanymatchcount(x, **kwargs): @@ -73,11 +53,11 @@ def getanymatchcount(x, **kwargs): """ out = Refactor( itis_base + "getAnyMatchCount", payload={"srchKey": x}, request="get" - ).xml(**kwargs) - return int(out.getchildren()[0].text) + ).json(**kwargs) + return out["return"] -def getcommentdetailfromtsn(tsn, as_dataframe=True, **kwargs): +def getcommentdetailfromtsn(tsn, as_dataframe=False, **kwargs): """ Get comment detail from TSN @@ -92,26 +72,11 @@ def getcommentdetailfromtsn(tsn, as_dataframe=True, **kwargs): """ out = Refactor( itis_base + "getCommentDetailFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - matches = [ - "commentDetail", - "commentId", - "commentTimeStamp", - "commentator", - "updateDate", - ] - colnames = ["comment", "commid", "commtime", "commentator", "updatedate"] - data = _itisdict(out, ns, matches, colnames) - - if as_dataframe and pd: - df = pd.DataFrame.from_records(data) - return df - else: - return data - + ).json(**kwargs) + [z.pop("class") for z in out["comments"]] + return _df(out["comments"], as_dataframe) -def getcommonnamesfromtsn(tsn, as_dataframe=True, **kwargs): +def getcommonnamesfromtsn(tsn, as_dataframe=False, **kwargs): """ Get common names from tsn @@ -124,24 +89,13 @@ def getcommonnamesfromtsn(tsn, as_dataframe=True, **kwargs): from pytaxize import itis itis.getcommonnamesfromtsn(tsn=183833) """ - # out = _itisGET("getCommonNamesFromTSN", {'tsn': tsn}, **kwargs) out = Refactor( itis_base + "getCommonNamesFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - matches = ["commonName", "language", "tsn"] - colnames = ["comname", "lang", "tsn"] - res = _itisextract(out, ns, matches, colnames) - del res[2][-1] - if as_dataframe and pd: - df = pd.DataFrame.from_records(res).T - df.columns = colnames - return df - else: - return res, colnames + ).json(**kwargs) + [z.pop("class") for z in out["commonNames"]] + return _df(out["commonNames"], as_dataframe) - -def getcoremetadatafromtsn(tsn, **kwargs): +def getcoremetadatafromtsn(tsn, as_dataframe=False, **kwargs): """ Get core metadata from tsn @@ -155,20 +109,11 @@ def getcoremetadatafromtsn(tsn, **kwargs): """ out = Refactor( itis_base + "getCoreMetadataFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - toget = [ - "credRating", - "rankId", - "taxonCoverage", - "taxonCurrency", - "taxonUsageRating", - "tsn", - ] - return _itis_parse(toget, out, ns) - - -def getcoveragefromtsn(tsn, **kwargs): + ).json(**kwargs) + out.pop("class") + return _df([out], as_dataframe) + +def getcoveragefromtsn(tsn, as_dataframe=False, **kwargs): """ Get coverge from tsn @@ -179,54 +124,51 @@ def getcoveragefromtsn(tsn, **kwargs): itis.getcoveragefromtsn(tsn=28727) # no coverage data itis.getcoveragefromtsn(526852) + # as data_frame + itis.getcoveragefromtsn(526852, as_dataframe=True) """ out = Refactor( itis_base + "getCoverageFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - matches = ["rankId", "taxonCoverage", "tsn"] - df = _itisdict(out, ns21, matches, _tolower(matches)) - return df + ).json(**kwargs) + out.pop("class") + return _df(out, as_dataframe) -def getcredibilityratingfromtsn(tsn, **kwargs): +def getcredibilityratingfromtsn(tsn, as_dataframe=False, **kwargs): """ Get credibility rating from tsn Usage:: from pytaxize import itis - itis.getcredibilityratingfromtsn(526852) + itis.getcredibilityratingfromtsn(tsn=526852) itis.getcredibilityratingfromtsn(28727) """ out = Refactor( itis_base + "getCredibilityRatingFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - matches = ["credRating", "tsn"] - df = _itisdict(out, ns21, matches, _tolower(matches)) - return df - + ).json(**kwargs) + out.pop("class") + return _df(out, as_dataframe) def getcredibilityratings(**kwargs): """ Get possible credibility ratings :param **kwargs: Curl options passed on to `requests.get` + :return: a dict Usage:: from pytaxize import itis itis.getcredibilityratings() """ - out = Refactor(itis_base + "getCredibilityRatings", payload={}, request="get").xml( + out = Refactor(itis_base + "getCredibilityRatings", payload={}, request="get").json( **kwargs ) - nodes = out.xpath("//ax23:credibilityValues", namespaces=ns23) - return [x.text for x in nodes] - # df = pd.DataFrame(credibilityValues, columns=['credibilityValues']) - # return df - + out.pop("class") + return out["credibilityValues"] -def getcurrencyfromtsn(tsn, **kwargs): +def getcurrencyfromtsn(tsn, as_dataframe=False, **kwargs): """ Get currency from tsn @@ -237,49 +179,47 @@ def getcurrencyfromtsn(tsn, **kwargs): itis.getcurrencyfromtsn(28727) # no currency dat itis.getcurrencyfromtsn(526852) + # as data_frame + itis.getcurrencyfromtsn(526852, as_dataframe=True) """ out = Refactor( itis_base + "getCurrencyFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - matches = ["rankId", "taxonCurrency", "tsn"] - df = _itisdict(out, ns21, matches, _tolower(matches)) - return df + ).json(**kwargs) + out.pop("class") + return _df(out, as_dataframe) -def getdatedatafromtsn(tsn, **kwargs): +def getdatedatafromtsn(tsn, as_dataframe=False, **kwargs): """ Get date data from tsn Usage:: from pytaxize import itis - itis.getdatedatafromtsn(180543) + itis.getdatedatafromtsn(tsn=180543) """ out = Refactor( itis_base + "getDateDataFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - matches = ["initialTimeStamp", "updateDate", "tsn"] - df = _itisdict(out, ns21, matches, _tolower(matches)) - return df - + ).json(**kwargs) + out.pop("class") + return _df(out, as_dataframe) -def getexpertsfromtsn(tsn, **kwargs): +def getexpertsfromtsn(tsn, as_dataframe=False, **kwargs): """ Get expert information for the TSN. Usage:: from pytaxize import itis - itis.getexpertsfromtsn(180544) + itis.getexpertsfromtsn(tsn=180544) """ out = Refactor( itis_base + "getExpertsFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["comment", "expert", "name", "referredTsn", "referenceFor", "updateDate"] - return _itis_parse(toget, out, ns21) + ).json(**kwargs) + out.pop("class") + return _df(out["experts"], as_dataframe) - -def gettaxonomicranknamefromtsn(tsn, **kwargs): +def gettaxonomicranknamefromtsn(tsn, as_dataframe=False, **kwargs): """ Returns the kingdom and rank information for the TSN. @@ -292,13 +232,11 @@ def gettaxonomicranknamefromtsn(tsn, **kwargs): """ tt = Refactor( itis_base + "getTaxonomicRankNameFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - df = _parse2df(tt, ns) - return df - + ).json(**kwargs) + tt.pop("class") + return _df(tt, as_dataframe) -def getfullhierarchyfromtsn(tsn, **kwargs): +def getfullhierarchyfromtsn(tsn, as_dataframe=False, **kwargs): """ Get full hierarchy from ts @@ -309,47 +247,52 @@ def getfullhierarchyfromtsn(tsn, **kwargs): from pytaxize import itis itis.getfullhierarchyfromtsn(tsn = 37906) itis.getfullhierarchyfromtsn(tsn = 100800) + # as data_frame + itis.getfullhierarchyfromtsn(tsn = 100800, as_dataframe=True) """ tt = Refactor( itis_base + "getFullHierarchyFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - df = _parse_hier(tt, ns21) - return df - + ).json(**kwargs) + hier = tt["hierarchyList"] + [z.pop("class") for z in hier] + return _df(hier, as_dataframe) + +# def _fullrecord(verb, args, **kwargs): +# out = Refactor(itis_base + verb, payload=args, request="get").json(**kwargs) +# toget = [ +# "acceptedNameList", +# "commentList", +# "commonNameList", +# "completenessRating", +# "coreMetadata", +# "credibilityRating", +# "currencyRating", +# "dateData", +# "expertList", +# "geographicDivisionList", +# "hierarchyUp", +# "jurisdictionalOriginList", +# "kingdom", +# "otherSourceList", +# "parentTSN", +# "publicationList", +# "scientificName", +# "synonymList", +# "taxRank", +# "taxonAuthor", +# "unacceptReason", +# "usage", +# ] + +# def parsedat(x): +# ch = out.xpath("//ax21:" + x, namespaces=ns21)[0].getchildren() +# return _get_text(ch) + +# return [parsedat(x) for x in toget] def _fullrecord(verb, args, **kwargs): - out = Refactor(itis_base + verb, payload=args, request="get").xml(**kwargs) - toget = [ - "acceptedNameList", - "commentList", - "commonNameList", - "completenessRating", - "coreMetadata", - "credibilityRating", - "currencyRating", - "dateData", - "expertList", - "geographicDivisionList", - "hierarchyUp", - "jurisdictionalOriginList", - "kingdom", - "otherSourceList", - "parentTSN", - "publicationList", - "scientificName", - "synonymList", - "taxRank", - "taxonAuthor", - "unacceptReason", - "usage", - ] - - def parsedat(x): - ch = out.xpath("//ax21:" + x, namespaces=ns21)[0].getchildren() - return _get_text(ch) - - return [parsedat(x) for x in toget] - + out = Refactor(itis_base + verb, payload=args, request="get").json(**kwargs) + return out def getfullrecordfromlsid(lsid, **kwargs): """ @@ -363,7 +306,7 @@ def getfullrecordfromlsid(lsid, **kwargs): Usage:: from pytaxize import itis - itis.getfullrecordfromlsid("urn:lsid:itis.gov:itis_tsn:180543") + itis.getfullrecordfromlsid(lsid="urn:lsid:itis.gov:itis_tsn:180543") itis.getfullrecordfromlsid("urn:lsid:itis.gov:itis_tsn:37906") itis.getfullrecordfromlsid("urn:lsid:itis.gov:itis_tsn:100800") """ @@ -387,507 +330,507 @@ def getfullrecordfromtsn(tsn, **kwargs): return _fullrecord("getFullRecordFromTSN", {"tsn": tsn}, **kwargs) -def getgeographicdivisionsfromtsn(tsn, **kwargs): +def getgeographicdivisionsfromtsn(tsn, as_dataframe=False, **kwargs): """ Get geographic divisions from tsn Usage:: from pytaxize import itis - itis.getgeographicdivisionsfromtsn(180543) + itis.getgeographicdivisionsfromtsn(tsn=180543) """ out = Refactor( itis_base + "getGeographicDivisionsFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["geographicValue", "updateDate"] - return _itis_parse(toget, out, ns21) + ).json(**kwargs) + out.pop("class") + [z.pop("class") for z in out["geoDivisions"]] + return _df(out["geoDivisions"], as_dataframe) +# def getgeographicvalues(**kwargs): +# """ +# Get all possible geographic values -def getgeographicvalues(**kwargs): - """ - Get all possible geographic values +# :param **kwargs: Curl options passed on to `requests.get` - :param **kwargs: Curl options passed on to `requests.get` - - Usage:: +# Usage:: - from pytaxize import itis - itis.getgeographicvalues() - """ - out = Refactor(itis_base + "getGeographicValues", payload={}, request="get").xml( - **kwargs - ) - ns = {"ax21": "http://metadata.itis_service.itis.usgs.gov/xsd"} - nodes = out.xpath("//ax21:geographicValues", namespaces=ns) - return [x.text for x in nodes] +# from pytaxize import itis +# itis.getgeographicvalues() +# """ +# out = Refactor(itis_base + "getGeographicValues", payload={}, request="get").xml( +# **kwargs +# ) +# ns = {"ax21": "http://metadata.itis_service.itis.usgs.gov/xsd"} +# nodes = out.xpath("//ax21:geographicValues", namespaces=ns) +# return [x.text for x in nodes] -def getglobalspeciescompletenessfromtsn(tsn, **kwargs): - """ - Get global species completeness from tsn +# def getglobalspeciescompletenessfromtsn(tsn, **kwargs): +# """ +# Get global species completeness from tsn - Usage:: +# Usage:: - from pytaxize import itis - itis.getglobalspeciescompletenessfromtsn(180541) - """ - out = Refactor( - itis_base + "getGlobalSpeciesCompletenessFromTSN", - payload={"tsn": tsn}, - request="get", - ).xml(**kwargs) - toget = ["completeness", "rankId", "tsn"] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.getglobalspeciescompletenessfromtsn(180541) +# """ +# out = Refactor( +# itis_base + "getGlobalSpeciesCompletenessFromTSN", +# payload={"tsn": tsn}, +# request="get", +# ).json(**kwargs) +# toget = ["completeness", "rankId", "tsn"] +# return _itis_parse(toget, out, ns21) -def gethierarchydownfromtsn(tsn, **kwargs): - """ - Get hierarchy down from tsn +# def gethierarchydownfromtsn(tsn, **kwargs): +# """ +# Get hierarchy down from tsn - :param tsn: TSN for a taxonomic group (numeric) +# :param tsn: TSN for a taxonomic group (numeric) - Usage:: +# Usage:: - from pytaxize import itis - itis.gethierarchydownfromtsn(tsn = 161030) - """ - tt = Refactor( - itis_base + "getHierarchyDownFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - df = _parse_hier(tt, ns) - return df +# from pytaxize import itis +# itis.gethierarchydownfromtsn(tsn = 161030) +# """ +# tt = Refactor( +# itis_base + "getHierarchyDownFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} +# df = _parse_hier(tt, ns) +# return df -def gethierarchyupfromtsn(tsn, **kwargs): - """ - Get hierarchy up from tsn +# def gethierarchyupfromtsn(tsn, **kwargs): +# """ +# Get hierarchy up from tsn - :param tsn: TSN for a taxonomic group (numeric) +# :param tsn: TSN for a taxonomic group (numeric) - Usage:: +# Usage:: - from pytaxize import itis - itis.gethierarchyupfromtsn(tsn = 36485) - itis.gethierarchyupfromtsn(tsn = 37906) - """ - tt = Refactor( - itis_base + "getHierarchyUpFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - df = _parse2df(tt, ns) - return df - +# from pytaxize import itis +# itis.gethierarchyupfromtsn(tsn = 36485) +# itis.gethierarchyupfromtsn(tsn = 37906) +# """ +# tt = Refactor( +# itis_base + "getHierarchyUpFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} +# df = _parse2df(tt, ns) +# return df + + +# def _itisterms(endpt, args={}, **kwargs): +# """ +# Get itis term -def _itisterms(endpt, args={}, **kwargs): - """ - Get itis term - - Usage:: +# Usage:: - from pytaxize import itis - itis._itisterms("buya") - """ - out = Refactor(itis_base + endpt, payload=args, request="get").xml(**kwargs) - - nodes = out.xpath("//ax21:itisTerms", namespaces=ns21) - nodes2 = [x.getchildren() for x in nodes] - allnodes = [[_get_text_single(y) for y in x] for x in nodes2] - - output = [] - for x in allnodes: - kyz = [list(y.keys())[0] for y in x] - notuniq = set([v for v in kyz if kyz.count(v) > 1]) - if len(notuniq) > 0: - for z in notuniq: - tt = ",".join( - [list(m.values())[0] for m in x if list(m.keys())[0] == z] - ) - toadd = {z: tt} - uu = [v for v in x if list(v.keys())[0] not in z] - uu.append(toadd) - output.append(uu) - else: - output.append(x) - - df = pd.DataFrame([{k: v for d in R for k, v in d.items()} for R in output]) - return df[[list(x.keys())[0] for x in allnodes[0]]] - - -def _get_text_single(x): - vals = [x.text] - keys = [x.tag.split("}")[1]] - return dict(zip(keys, vals)) +# from pytaxize import itis +# itis._itisterms("buya") +# """ +# out = Refactor(itis_base + endpt, payload=args, request="get").json(**kwargs) + +# nodes = out.xpath("//ax21:itisTerms", namespaces=ns21) +# nodes2 = [x.getchildren() for x in nodes] +# allnodes = [[_get_text_single(y) for y in x] for x in nodes2] + +# output = [] +# for x in allnodes: +# kyz = [list(y.keys())[0] for y in x] +# notuniq = set([v for v in kyz if kyz.count(v) > 1]) +# if len(notuniq) > 0: +# for z in notuniq: +# tt = ",".join( +# [list(m.values())[0] for m in x if list(m.keys())[0] == z] +# ) +# toadd = {z: tt} +# uu = [v for v in x if list(v.keys())[0] not in z] +# uu.append(toadd) +# output.append(uu) +# else: +# output.append(x) + +# df = pd.DataFrame([{k: v for d in R for k, v in d.items()} for R in output]) +# return df[[list(x.keys())[0] for x in allnodes[0]]] + + +# def _get_text_single(x): +# vals = [x.text] +# keys = [x.tag.split("}")[1]] +# return dict(zip(keys, vals)) + + +# def getitistermsfromcommonname(x, **kwargs): +# """ +# Get itis terms from common names - -def getitistermsfromcommonname(x, **kwargs): - """ - Get itis terms from common names - - Usage:: +# Usage:: - from pytaxize import itis - itis.getitistermsfromcommonname("buya") - """ - return _itisterms(endpt="getITISTermsFromCommonName", args={"srchKey": x}, **kwargs) +# from pytaxize import itis +# itis.getitistermsfromcommonname("buya") +# """ +# return _itisterms(endpt="getITISTermsFromCommonName", args={"srchKey": x}, **kwargs) -def getitisterms(x, **kwargs): - """ - Get itis terms +# def getitisterms(x, **kwargs): +# """ +# Get itis terms - Usage:: +# Usage:: - from pytaxize import itis - # fails - itis.getitisterms("bear") - """ - return _itisterms(endpt="getITISTerms", args={"srchKey": x}, **kwargs) +# from pytaxize import itis +# # fails +# itis.getitisterms("bear") +# """ +# return _itisterms(endpt="getITISTerms", args={"srchKey": x}, **kwargs) -def getitistermsfromscientificname(x, **kwargs): - """ - Get itis terms from scientific names +# def getitistermsfromscientificname(x, **kwargs): +# """ +# Get itis terms from scientific names - Usage:: +# Usage:: - from pytaxize import itis - itis.getitistermsfromscientificname("ursidae") - itis.getitistermsfromscientificname("Ursus") - """ - return _itisterms( - endpt="getITISTermsFromScientificName", args={"srchKey": x}, **kwargs - ) +# from pytaxize import itis +# itis.getitistermsfromscientificname("ursidae") +# itis.getitistermsfromscientificname("Ursus") +# """ +# return _itisterms( +# endpt="getITISTermsFromScientificName", args={"srchKey": x}, **kwargs +# ) -def hierarchy(tsn=None, what="full"): - """ - Get hierarchies from TSN values, full, upstream only, or immediate downstream - only. Uses the ITIS database. +# def hierarchy(tsn=None, what="full"): +# """ +# Get hierarchies from TSN values, full, upstream only, or immediate downstream +# only. Uses the ITIS database. - :param tsn: One or more TSN's (taxonomic serial number) - :param what: One of full (full hierarchy), up (immediate upstream), or down - (immediate downstream) +# :param tsn: One or more TSN's (taxonomic serial number) +# :param what: One of full (full hierarchy), up (immediate upstream), or down +# (immediate downstream) - Details Note that `itis.itis_downstream` gets taxa downstream to a particular - rank, whilc this function only gets immediate names downstream. +# Details Note that `itis.itis_downstream` gets taxa downstream to a particular +# rank, whilc this function only gets immediate names downstream. - Usage:: +# Usage:: - from pytaxize import itis - # Get full hierarchy - itis.hierarchy(tsn=180543) - - # Get hierarchy upstream - itis.hierarchy(tsn=180543, "up") - - # Get hierarchy downstream - itis.hierarchy(tsn=180543, "down") - - # Many tsn's - itis.hierarchy(tsn=[180543,41074,36616]) - """ - tsn2 = convertsingle(tsn) - temp = [] - if what == "full": - for i in range(len(tsn2)): - temp.append(getfullhierarchyfromtsn(tsn2[i])) - elif what == "up": - for i in range(len(tsn2)): - temp.append(gethierarchyupfromtsn(tsn2[i])) - else: - for i in range(len(tsn2)): - temp.append(gethierarchydownfromtsn(tsn2[i])) - return temp +# from pytaxize import itis +# # Get full hierarchy +# itis.hierarchy(tsn=180543) + +# # Get hierarchy upstream +# itis.hierarchy(tsn=180543, "up") + +# # Get hierarchy downstream +# itis.hierarchy(tsn=180543, "down") + +# # Many tsn's +# itis.hierarchy(tsn=[180543,41074,36616]) +# """ +# tsn2 = convertsingle(tsn) +# temp = [] +# if what == "full": +# for i in range(len(tsn2)): +# temp.append(getfullhierarchyfromtsn(tsn2[i])) +# elif what == "up": +# for i in range(len(tsn2)): +# temp.append(gethierarchyupfromtsn(tsn2[i])) +# else: +# for i in range(len(tsn2)): +# temp.append(gethierarchydownfromtsn(tsn2[i])) +# return temp -def getjurisdictionaloriginfromtsn(tsn, **kwargs): - """ - Get jurisdictional origin from tsn +# def getjurisdictionaloriginfromtsn(tsn, **kwargs): +# """ +# Get jurisdictional origin from tsn - Usage:: +# Usage:: - from pytaxize import itis - itis.getjurisdictionaloriginfromtsn(180543) - """ - out = Refactor( - itis_base + "getJurisdictionalOriginFromTSN", - payload={"tsn": tsn}, - request="get", - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - toget = ["jurisdictionValue", "origin", "updateDate"] - return _itis_parse(toget, out, ns) +# from pytaxize import itis +# itis.getjurisdictionaloriginfromtsn(180543) +# """ +# out = Refactor( +# itis_base + "getJurisdictionalOriginFromTSN", +# payload={"tsn": tsn}, +# request="get", +# ).json(**kwargs) +# ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} +# toget = ["jurisdictionValue", "origin", "updateDate"] +# return _itis_parse(toget, out, ns) + + +# def getjurisdictionoriginvalues(**kwargs): +# """ +# Get jurisdiction origin values - -def getjurisdictionoriginvalues(**kwargs): - """ - Get jurisdiction origin values - - Usage:: +# Usage:: - from pytaxize import itis - itis.getjurisdictionoriginvalues() - """ - out = Refactor( - itis_base + "getJurisdictionalOriginValues", payload={}, request="get" - ).xml(**kwargs) - ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} - matches = ["jurisdiction", "origin"] - return _itisdf(out, ns, matches, matches, "ax23") +# from pytaxize import itis +# itis.getjurisdictionoriginvalues() +# """ +# out = Refactor( +# itis_base + "getJurisdictionalOriginValues", payload={}, request="get" +# ).json(**kwargs) +# ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} +# matches = ["jurisdiction", "origin"] +# return _itisdf(out, ns, matches, matches, "ax23") -def getjurisdictionvalues(**kwargs): - """ - Get possible jurisdiction values +# def getjurisdictionvalues(**kwargs): +# """ +# Get possible jurisdiction values - Usage:: +# Usage:: - from pytaxize import itis - itis.getjurisdictionvalues() - """ - out = Refactor(itis_base + "getJurisdictionValues", payload={}, request="get").xml( - **kwargs - ) - vals = [x.text for x in out.getchildren()[0].getchildren()] - return pd.DataFrame(vals, columns=["jurisdictionValues"]) +# from pytaxize import itis +# itis.getjurisdictionvalues() +# """ +# out = Refactor(itis_base + "getJurisdictionValues", payload={}, request="get").xml( +# **kwargs +# ) +# vals = [x.text for x in out.getchildren()[0].getchildren()] +# return pd.DataFrame(vals, columns=["jurisdictionValues"]) -def getkingdomnamefromtsn(tsn, **kwargs): - """ - Get kingdom names from tsn +# def getkingdomnamefromtsn(tsn, **kwargs): +# """ +# Get kingdom names from tsn - Usage:: +# Usage:: - from pytaxize import itis - itis.getkingdomnamefromtsn(202385) - """ - out = _itisGET("getKingdomNameFromTSN", {"tsn": tsn}, **kwargs) - out = Refactor( - itis_base + "getKingdomNameFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} - toget = ["kingdomId", "kingdomName", "tsn"] - return _itis_parse(toget, out, ns) - - -def getkingdomnames(**kwargs): - """ - Get all possible kingdom names +# from pytaxize import itis +# itis.getkingdomnamefromtsn(202385) +# """ +# out = _itisGET("getKingdomNameFromTSN", {"tsn": tsn}, **kwargs) +# out = Refactor( +# itis_base + "getKingdomNameFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# ns = {"ax21": "http://data.itis_service.itis.usgs.gov/xsd"} +# toget = ["kingdomId", "kingdomName", "tsn"] +# return _itis_parse(toget, out, ns) + + +# def getkingdomnames(**kwargs): +# """ +# Get all possible kingdom names - Usage:: +# Usage:: - from pytaxize import itis - itis.getkingdomnames() - """ - out = Refactor(itis_base + "getKingdomNames", payload={}, request="get").xml( - **kwargs - ) - ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} - matches = ["kingdomId", "kingdomName", "tsn"] - return _itisdf(out, ns, matches, _tolower(matches), "ax23") +# from pytaxize import itis +# itis.getkingdomnames() +# """ +# out = Refactor(itis_base + "getKingdomNames", payload={}, request="get").xml( +# **kwargs +# ) +# ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} +# matches = ["kingdomId", "kingdomName", "tsn"] +# return _itisdf(out, ns, matches, _tolower(matches), "ax23") -def getlastchangedate(**kwargs): - """ - Provides the date the ITIS database was last updated. +# def getlastchangedate(**kwargs): +# """ +# Provides the date the ITIS database was last updated. - Usage:: +# Usage:: - from pytaxize import itis - itis.getlastchangedate() - """ - out = Refactor(itis_base + "getLastChangeDate", payload={}, request="get").xml( - **kwargs - ) - ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} - nodes = out.xpath("//ax23:updateDate", namespaces=ns) - bb = nodes[0].text - dt = time.strptime(bb.split()[0], "%Y-%m-%d") - return dt - +# from pytaxize import itis +# itis.getlastchangedate() +# """ +# out = Refactor(itis_base + "getLastChangeDate", payload={}, request="get").xml( +# **kwargs +# ) +# ns = {"ax23": "http://metadata.itis_service.itis.usgs.gov/xsd"} +# nodes = out.xpath("//ax23:updateDate", namespaces=ns) +# bb = nodes[0].text +# dt = time.strptime(bb.split()[0], "%Y-%m-%d") +# return dt + + +# def getlsidfromtsn(tsn, **kwargs): +# """ +# Gets the unique LSID for the TSN, or an empty result if there is no match. -def getlsidfromtsn(tsn, **kwargs): - """ - Gets the unique LSID for the TSN, or an empty result if there is no match. - - Usage:: +# Usage:: - from pytaxize import itis - # valid TSN - itis.getlsidfromtsn(155166) - # invalid TSN, returns nothing - itis.getlsidfromtsn(0) - """ - out = _itisGET("getLSIDFromTSN", {"tsn": tsn}, **kwargs) - out = Refactor( - itis_base + "getLSIDFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - tt = out.getchildren()[0].text - if tt is None: - tt = "no match" - else: - pass - return tt +# from pytaxize import itis +# # valid TSN +# itis.getlsidfromtsn(155166) +# # invalid TSN, returns nothing +# itis.getlsidfromtsn(0) +# """ +# out = _itisGET("getLSIDFromTSN", {"tsn": tsn}, **kwargs) +# out = Refactor( +# itis_base + "getLSIDFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# tt = out.getchildren()[0].text +# if tt is None: +# tt = "no match" +# else: +# pass +# return tt -def getothersourcesfromtsn(tsn, **kwargs): - """ - Returns a list of the other sources used for the TSN. +# def getothersourcesfromtsn(tsn, **kwargs): +# """ +# Returns a list of the other sources used for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.getothersourcesfromtsn(182662) - """ - out = Refactor( - itis_base + "getOtherSourcesFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = [ - "acquisitionDate", - "name", - "referredTsn", - "source", - "sourceType", - "updateDate", - "version", - ] - return _itis_parse_2dict(toget, out, ns21) - - -def getparenttsnfromtsn(tsn, **kwargs): - """ - Returns the parent TSN for the entered TSN. +# from pytaxize import itis +# itis.getothersourcesfromtsn(182662) +# """ +# out = Refactor( +# itis_base + "getOtherSourcesFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = [ +# "acquisitionDate", +# "name", +# "referredTsn", +# "source", +# "sourceType", +# "updateDate", +# "version", +# ] +# return _itis_parse_2dict(toget, out, ns21) + + +# def getparenttsnfromtsn(tsn, **kwargs): +# """ +# Returns the parent TSN for the entered TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.getparenttsnfromtsn(202385) - """ - out = Refactor( - itis_base + "getParentTSNFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["parentTsn", "tsn"] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.getparenttsnfromtsn(202385) +# """ +# out = Refactor( +# itis_base + "getParentTSNFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = ["parentTsn", "tsn"] +# return _itis_parse(toget, out, ns21) -def getpublicationsfromtsn(tsn, **kwargs): - """ - Returns a list of the pulications used for the TSN. +# def getpublicationsfromtsn(tsn, **kwargs): +# """ +# Returns a list of the pulications used for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.getpublicationsfromtsn(70340) - """ - out = Refactor( - itis_base + "getPublicationsFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = [ - "actualPubDate", - "isbn", - "issn", - "listedPubDate", - "pages", - "pubComment", - "pubName", - "pubPlace", - "publisher", - "referenceAuthor", - "name", - "refLanguage", - "referredTsn", - "title", - "updateDate", - ] - return _itis_parse(toget, out, ns21) - - -def getranknames(**kwargs): - """ - Provides a list of all the unique rank names contained in the database and - their kingdom and rank ID values. +# from pytaxize import itis +# itis.getpublicationsfromtsn(70340) +# """ +# out = Refactor( +# itis_base + "getPublicationsFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = [ +# "actualPubDate", +# "isbn", +# "issn", +# "listedPubDate", +# "pages", +# "pubComment", +# "pubName", +# "pubPlace", +# "publisher", +# "referenceAuthor", +# "name", +# "refLanguage", +# "referredTsn", +# "title", +# "updateDate", +# ] +# return _itis_parse(toget, out, ns21) + + +# def getranknames(**kwargs): +# """ +# Provides a list of all the unique rank names contained in the database and +# their kingdom and rank ID values. - Usage:: +# Usage:: - from pytaxize import itis - itis.getranknames() - """ - out = Refactor(itis_base + "getRankNames", payload={}, request="get").xml(**kwargs) - matches = ["kingdomName", "rankId", "rankName"] - return _itisdf(out, ns23, matches, _tolower(matches), "ax23") +# from pytaxize import itis +# itis.getranknames() +# """ +# out = Refactor(itis_base + "getRankNames", payload={}, request="get").json(**kwargs) +# matches = ["kingdomName", "rankId", "rankName"] +# return _itisdf(out, ns23, matches, _tolower(matches), "ax23") -def getrecordfromlsid(lsid, **kwargs): - """ - Gets the partial ITIS record for the TSN in the LSID, found by comparing the - TSN in the search key to the TSN field. Returns an empty result set if - there is no match or the TSN is invalid. +# def getrecordfromlsid(lsid, **kwargs): +# """ +# Gets the partial ITIS record for the TSN in the LSID, found by comparing the +# TSN in the search key to the TSN field. Returns an empty result set if +# there is no match or the TSN is invalid. - Usage:: +# Usage:: - from pytaxize import itis - itis.getrecordfromlsid("urn:lsid:itis.gov:itis_tsn:180543") - """ - out = Refactor( - itis_base + "getRecordFromLSID", payload={"lsid": lsid}, request="get" - ).xml(**kwargs) - toget = [ - "authorship", - "genusPart", - "infragenericEpithet", - "infraspecificEpithet", - "lsid", - "nameComplete", - "nomenclaturalCode", - "rank", - "rankString", - "specificEpithet", - "uninomial", - "tsn", - ] - return _itis_parse(toget, out, ns21) - - -def getreviewyearfromtsn(tsn, **kwargs): - """ - Returns the review year for the TSN. +# from pytaxize import itis +# itis.getrecordfromlsid("urn:lsid:itis.gov:itis_tsn:180543") +# """ +# out = Refactor( +# itis_base + "getRecordFromLSID", payload={"lsid": lsid}, request="get" +# ).json(**kwargs) +# toget = [ +# "authorship", +# "genusPart", +# "infragenericEpithet", +# "infraspecificEpithet", +# "lsid", +# "nameComplete", +# "nomenclaturalCode", +# "rank", +# "rankString", +# "specificEpithet", +# "uninomial", +# "tsn", +# ] +# return _itis_parse(toget, out, ns21) + + +# def getreviewyearfromtsn(tsn, **kwargs): +# """ +# Returns the review year for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.getreviewyearfromtsn(180541) - """ - out = Refactor( - itis_base + "getReviewYearFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["rankId", "reviewYear", "tsn"] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.getreviewyearfromtsn(180541) +# """ +# out = Refactor( +# itis_base + "getReviewYearFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = ["rankId", "reviewYear", "tsn"] +# return _itis_parse(toget, out, ns21) -def getscientificnamefromtsn(tsn, **kwargs): - """ - Returns the scientific name for the TSN. Also returns the component parts - (names and indicators) of the scientific name. +# def getscientificnamefromtsn(tsn, **kwargs): +# """ +# Returns the scientific name for the TSN. Also returns the component parts +# (names and indicators) of the scientific name. - Usage:: +# Usage:: - from pytaxize import itis - itis.getscientificnamefromtsn(531894) - """ - out = Refactor( - itis_base + "getScientificNameFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = [ - "combinedName", - "unitInd1", - "unitInd3", - "unitName1", - "unitName2", - "unitName3", - "tsn", - ] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.getscientificnamefromtsn(531894) +# """ +# out = Refactor( +# itis_base + "getScientificNameFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = [ +# "combinedName", +# "unitInd1", +# "unitInd3", +# "unitName1", +# "unitName2", +# "unitName3", +# "tsn", +# ] +# return _itis_parse(toget, out, ns21) # def getsynonymnamesfromtsn(tsn, **kwargs): @@ -914,248 +857,248 @@ def getscientificnamefromtsn(tsn, **kwargs): # data.frame(name=name, tsn=tsn, stringsAsFactors = FALSE) -def gettaxonauthorshipfromtsn(tsn, **kwargs): - """ - Returns the author information for the TSN. +# def gettaxonauthorshipfromtsn(tsn, **kwargs): +# """ +# Returns the author information for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.gettaxonauthorshipfromtsn(183671) - """ - out = Refactor( - itis_base + "getTaxonAuthorshipFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["authorship", "updateDate", "tsn"] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.gettaxonauthorshipfromtsn(183671) +# """ +# out = Refactor( +# itis_base + "getTaxonAuthorshipFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = ["authorship", "updateDate", "tsn"] +# return _itis_parse(toget, out, ns21) -def gettaxonomicusagefromtsn(tsn, **kwargs): - """ - Returns the usage information for the TSN. +# def gettaxonomicusagefromtsn(tsn, **kwargs): +# """ +# Returns the usage information for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.gettaxonomicusagefromtsn(526852) - """ - out = Refactor( - itis_base + "getTaxonomicUsageFromTSN", payload={"tsn": tsn}, request="get" - ).xml(**kwargs) - toget = ["taxonUsageRating", "tsn"] - return _itis_parse(toget, out, ns21) +# from pytaxize import itis +# itis.gettaxonomicusagefromtsn(526852) +# """ +# out = Refactor( +# itis_base + "getTaxonomicUsageFromTSN", payload={"tsn": tsn}, request="get" +# ).json(**kwargs) +# toget = ["taxonUsageRating", "tsn"] +# return _itis_parse(toget, out, ns21) -def gettsnbyvernacularlanguage(language, **kwargs): - """ - Get tsn by vernacular language not the international language code (character) +# def gettsnbyvernacularlanguage(language, **kwargs): +# """ +# Get tsn by vernacular language not the international language code (character) - Usage:: +# Usage:: - from pytaxize import itis - itis.gettsnbyvernacularlanguage("french") - """ - out = Refactor( - itis_base + "getTsnByVernacularLanguage", - payload={"language": language}, - request="get", - ).xml(**kwargs) - matches = ["commonName", "language", "tsn"] - return _itisdf(out, ns21, matches, _tolower(matches)) - +# from pytaxize import itis +# itis.gettsnbyvernacularlanguage("french") +# """ +# out = Refactor( +# itis_base + "getTsnByVernacularLanguage", +# payload={"language": language}, +# request="get", +# ).json(**kwargs) +# matches = ["commonName", "language", "tsn"] +# return _itisdf(out, ns21, matches, _tolower(matches)) + + +# def gettsnfromlsid(lsid, **kwargs): +# """ +# Gets the TSN corresponding to the LSID, or an empty result if there is no match. -def gettsnfromlsid(lsid, **kwargs): - """ - Gets the TSN corresponding to the LSID, or an empty result if there is no match. - - Usage:: +# Usage:: - from pytaxize import itis - itis.gettsnfromlsid(lsid="urn:lsid:itis.gov:itis_tsn:28726") - itis.gettsnfromlsid("urn:lsid:itis.gov:itis_tsn:0") - """ - out = Refactor( - itis_base + "getTSNFromLSID", payload={"lsid": lsid}, request="get" - ).xml(**kwargs) - tt = out.getchildren()[0].text - if tt is None: - tt = "no match" - else: - pass - return tt +# from pytaxize import itis +# itis.gettsnfromlsid(lsid="urn:lsid:itis.gov:itis_tsn:28726") +# itis.gettsnfromlsid("urn:lsid:itis.gov:itis_tsn:0") +# """ +# out = Refactor( +# itis_base + "getTSNFromLSID", payload={"lsid": lsid}, request="get" +# ).json(**kwargs) +# tt = out.getchildren()[0].text +# if tt is None: +# tt = "no match" +# else: +# pass +# return tt -def getunacceptabilityreasonfromtsn(tsn, **kwargs): - """ - Returns the unacceptability reason, if any, for the TSN. +# def getunacceptabilityreasonfromtsn(tsn, **kwargs): +# """ +# Returns the unacceptability reason, if any, for the TSN. - Usage:: +# Usage:: - from pytaxize import itis - itis.getunacceptabilityreasonfromtsn(183671) - """ - out = Refactor( - itis_base + "getUnacceptabilityReasonFromTSN", - payload={"tsn": tsn}, - request="get", - ).xml(**kwargs) - toget = ["tsn", "unacceptReason"] - return _itis_parse(toget, out, ns21) - +# from pytaxize import itis +# itis.getunacceptabilityreasonfromtsn(183671) +# """ +# out = Refactor( +# itis_base + "getUnacceptabilityReasonFromTSN", +# payload={"tsn": tsn}, +# request="get", +# ).json(**kwargs) +# toget = ["tsn", "unacceptReason"] +# return _itis_parse(toget, out, ns21) + + +# def getvernacularlanguages(**kwargs): +# """ +# Provides a list of the unique languages used in the vernacular table. -def getvernacularlanguages(**kwargs): - """ - Provides a list of the unique languages used in the vernacular table. - - Usage:: +# Usage:: - from pytaxize import itis - itis.getvernacularlanguages() - """ - out = Refactor(itis_base + "getVernacularLanguages", payload={}, request="get").xml( - **kwargs - ) - matches = ["languageNames"] - return _itisdf(out, ns23, matches, _tolower(matches), "ax23") +# from pytaxize import itis +# itis.getvernacularlanguages() +# """ +# out = Refactor(itis_base + "getVernacularLanguages", payload={}, request="get").xml( +# **kwargs +# ) +# matches = ["languageNames"] +# return _itisdf(out, ns23, matches, _tolower(matches), "ax23") -def searchbycommonname(x, **kwargs): - """ - Search for tsn by common name +# def searchbycommonname(x, **kwargs): +# """ +# Search for tsn by common name - Usage:: +# Usage:: - from pytaxize import itis - itis.searchbycommonname(x="american bullfrog") - itis.searchbycommonname("ferret-badger") - itis.searchbycommonname("polar bear") - """ - out = Refactor( - itis_base + "searchByCommonName", payload={"srchKey": x}, request="get" - ).xml(**kwargs) - matches = ["commonName", "language", "tsn"] - tmp = out.xpath("//ax21:commonNames", namespaces=ns21) - return _itisdf(tmp[0], ns21, matches, _tolower(matches)) - - -def searchbycommonnamebeginswith(x, **kwargs): - """ - Search for tsn by common name beginning with +# from pytaxize import itis +# itis.searchbycommonname(x="american bullfrog") +# itis.searchbycommonname("ferret-badger") +# itis.searchbycommonname("polar bear") +# """ +# out = Refactor( +# itis_base + "searchByCommonName", payload={"srchKey": x}, request="get" +# ).json(**kwargs) +# matches = ["commonName", "language", "tsn"] +# tmp = out.xpath("//ax21:commonNames", namespaces=ns21) +# return _itisdf(tmp[0], ns21, matches, _tolower(matches)) + + +# def searchbycommonnamebeginswith(x, **kwargs): +# """ +# Search for tsn by common name beginning with - Usage:: +# Usage:: - from pytaxize import itis - itis.searchbycommonnamebeginswith("inch") - """ - out = Refactor( - itis_base + "searchByCommonNameBeginsWith", - payload={"srchKey": x}, - request="get", - ).xml(**kwargs) - matches = ["commonName", "language", "tsn"] - tmp = out.xpath("//ax21:commonNames", namespaces=ns21) - return _itisdf(tmp[0], ns21, matches, _tolower(matches)) +# from pytaxize import itis +# itis.searchbycommonnamebeginswith("inch") +# """ +# out = Refactor( +# itis_base + "searchByCommonNameBeginsWith", +# payload={"srchKey": x}, +# request="get", +# ).json(**kwargs) +# matches = ["commonName", "language", "tsn"] +# tmp = out.xpath("//ax21:commonNames", namespaces=ns21) +# return _itisdf(tmp[0], ns21, matches, _tolower(matches)) + + +# def searchbycommonnameendswith(x, **kwargs): +# """ +# Search for tsn by common name ending with - -def searchbycommonnameendswith(x, **kwargs): - """ - Search for tsn by common name ending with - - Usage:: +# Usage:: - from pytaxize import itis - itis.searchbycommonnameendswith("snake") - """ - out = Refactor( - itis_base + "searchByCommonNameEndsWith", payload={"srchKey": x}, request="get" - ).xml(**kwargs) - matches = ["commonName", "language", "tsn"] - tmp = out.xpath("//ax21:commonNames", namespaces=ns21) - return _itisdf(tmp[0], ns21, matches, _tolower(matches)) - +# from pytaxize import itis +# itis.searchbycommonnameendswith("snake") +# """ +# out = Refactor( +# itis_base + "searchByCommonNameEndsWith", payload={"srchKey": x}, request="get" +# ).json(**kwargs) +# matches = ["commonName", "language", "tsn"] +# tmp = out.xpath("//ax21:commonNames", namespaces=ns21) +# return _itisdf(tmp[0], ns21, matches, _tolower(matches)) + + +# def searchcommon(x, which="begin", **kwargs): +# """ +# Searches common name and acts as thin wrapper around +# `itis.searchbycommonnamebeginswith` and `itis.searchbycommonnameendswith` -def searchcommon(x, which="begin", **kwargs): - """ - Searches common name and acts as thin wrapper around - `itis.searchbycommonnamebeginswith` and `itis.searchbycommonnameendswith` - - Usage:: +# Usage:: - from pytaxize import itis - itis.searchcommon("inch") - itis.searchcommon("inch", which = "end") - """ - if which == "begin": - return searchbycommonnamebeginswith(x, **kwargs) - else: - return searchbycommonnameendswith(x, **kwargs) +# from pytaxize import itis +# itis.searchcommon("inch") +# itis.searchcommon("inch", which = "end") +# """ +# if which == "begin": +# return searchbycommonnamebeginswith(x, **kwargs) +# else: +# return searchbycommonnameendswith(x, **kwargs) -def searchbyscientificname(x, **kwargs): - """ - Search by scientific name +# def searchbyscientificname(x, **kwargs): +# """ +# Search by scientific name - Usage:: +# Usage:: - from pytaxize import itis - itis.searchbyscientificname(x="Tardigrada") - itis.searchbyscientificname("Quercus douglasii") - """ - out = Refactor( - itis_base + "searchByScientificName", payload={"srchKey": x}, request="get" - ).xml(**kwargs) - matches = ["combinedName", "tsn"] - return _itisdf(out, ns21, matches, _tolower(matches)) +# from pytaxize import itis +# itis.searchbyscientificname(x="Tardigrada") +# itis.searchbyscientificname("Quercus douglasii") +# """ +# out = Refactor( +# itis_base + "searchByScientificName", payload={"srchKey": x}, request="get" +# ).json(**kwargs) +# matches = ["combinedName", "tsn"] +# return _itisdf(out, ns21, matches, _tolower(matches)) -def searchforanymatch(x, **kwargs): - """ - Search for any match +# def searchforanymatch(x, **kwargs): +# """ +# Search for any match - Usage:: +# Usage:: - from pytaxize import itis - itis.searchforanymatch(x=202385) - itis.searchforanymatch(x="dolphin") - """ - out = Refactor( - itis_base + "searchForAnyMatch", payload={"srchKey": x}, request="get" - ).xml(**kwargs) - # if isinstance(x, basestring): - tmp = out.getchildren()[0].getchildren() - output = [] - for v in tmp: - tmp = v.getchildren() - for w in tmp: - output.append( - dict(zip([gettag(e) for e in w.iter()], [e.text for e in w.iter()])) - ) - return output - +# from pytaxize import itis +# itis.searchforanymatch(x=202385) +# itis.searchforanymatch(x="dolphin") +# """ +# out = Refactor( +# itis_base + "searchForAnyMatch", payload={"srchKey": x}, request="get" +# ).json(**kwargs) +# # if isinstance(x, basestring): +# tmp = out.getchildren()[0].getchildren() +# output = [] +# for v in tmp: +# tmp = v.getchildren() +# for w in tmp: +# output.append( +# dict(zip([gettag(e) for e in w.iter()], [e.text for e in w.iter()])) +# ) +# return output + + +# def searchforanymatchpaged(x, pagesize, pagenum, ascend, **kwargs): +# """ +# Search for any matched page for descending (logical) -def searchforanymatchpaged(x, pagesize, pagenum, ascend, **kwargs): - """ - Search for any matched page for descending (logical) - - Usage:: +# Usage:: - from pytaxize import itis - itis.searchforanymatchpaged(x=202385, pagesize=100, pagenum=1, ascend=False) - itis.searchforanymatchpaged("Zy", pagesize=100, pagenum=1, ascend=False) - """ - args = {"srchKey": x, "pageSize": pagesize, "pageNum": pagenum, "ascend": ascend} - out = Refactor( - itis_base + "searchForAnyMatchPaged", payload=args, request="get" - ).xml(**kwargs) - tmp = out.getchildren()[0].getchildren() - output = [] - for v in tmp: - tmp = v.getchildren() - for w in tmp: - output.append( - dict(zip([gettag(e) for e in w.iter()], [e.text for e in w.iter()])) - ) - return output +# from pytaxize import itis +# itis.searchforanymatchpaged(x=202385, pagesize=100, pagenum=1, ascend=False) +# itis.searchforanymatchpaged("Zy", pagesize=100, pagenum=1, ascend=False) +# """ +# args = {"srchKey": x, "pageSize": pagesize, "pageNum": pagenum, "ascend": ascend} +# out = Refactor( +# itis_base + "searchForAnyMatchPaged", payload=args, request="get" +# ).json(**kwargs) +# tmp = out.getchildren()[0].getchildren() +# output = [] +# for v in tmp: +# tmp = v.getchildren() +# for w in tmp: +# output.append( +# dict(zip([gettag(e) for e in w.iter()], [e.text for e in w.iter()])) +# ) +# return output ## helper functions and variables @@ -1286,6 +1229,14 @@ def _tolower(y): def gettag(y): return y.tag.split("}")[1] +def _df(x, as_dataframe=False): + if as_dataframe and pd: + if isinstance(x, dict): + x = [x] + df = pd.DataFrame.from_records(x) + return df + else: + return x if __name__ == "__main__": import doctest diff --git a/pytaxize/tax.py b/pytaxize/tax.py index c0fbeb5..fa64f0d 100644 --- a/pytaxize/tax.py +++ b/pytaxize/tax.py @@ -1,52 +1,65 @@ import sys import requests from lxml import etree -import pandas as pd import re import json from pkg_resources import resource_filename from pytaxize.refactor import Refactor +from pytaxize.itis.itis import _df +import csv +try: + import pandas as pd +except ImportError: + warnings.warn("Pandas library not installed, dataframes disabled") + pd = None class NoResultException(Exception): pass - -def names_list(rank="genus", size=10): +def names_list(rank="genus", size=10, as_dataframe=False): """ Get a random vector of species names. :param rank: Taxonomic rank, one of species, genus (default), family, order. :param size: Number of names to get. Maximum depends on the rank. + :param as_dataframe: (optional) Type: boolean. Return as pandas data frame? + default: False Usage:: import pytaxize - pytaxize.names_list() - pytaxize.names_list('species') - pytaxize.names_list('family') - pytaxize.names_list('order') + pytaxize.names_list(size=10) + pytaxize.names_list('species', size=10) + pytaxize.names_list('family', size=10) + pytaxize.names_list('order', size=10) pytaxize.names_list('order', 2) pytaxize.names_list('order', 15) """ if rank == "species": - return names_list_helper(size, "data/plantNames.csv") + return names_list_helper(size, "data/plantNames.csv", as_dataframe) if rank == "genus": - return names_list_helper(size, "data/plantGenusNames.csv") + return names_list_helper(size, "data/plantGenusNames.csv", as_dataframe) if rank == "family": - return names_list_helper(size, "data/apg_families.csv") + return names_list_helper(size, "data/apg_families.csv", as_dataframe) if rank == "order": - return names_list_helper(size, "data/apg_orders.csv") + return names_list_helper(size, "data/apg_orders.csv", as_dataframe) else: return "rank must be one of species, genus, family, or order" - -def names_list_helper(size, path): +def names_list_helper(size, path, as_dataframe=False): pnpath = resource_filename(__name__, path) - dat = pd.read_csv(pnpath, header=False) - dat2 = dat["names"][:size] - return [x for x in dat2] - + if as_dataframe: + dat = pd.read_csv(pnpath) + return dat["names"][:size].tolist() + else: + with open(pnpath, newline='') as f: + reader = csv.reader(f) + next(reader) + dat = [] + for row in reader: + dat.append(row) + return [w[0] for w in dat][:size] def vascan_search(q, format="json", raw=False): """ @@ -107,6 +120,7 @@ def scrapenames( detect_language=None, all_data_sources=None, data_source_ids=None, + as_dataframe=False ): """ Resolve names using Global Names Recognition and Discovery. @@ -115,29 +129,33 @@ def scrapenames( http://gnrd.globalnames.org/. :param url: An encoded URL for a web page, PDF, Microsoft Office document, or - image file, see examples + image file, see examples :param file: When using multipart/form-data as the content-type, a file may be sent. - This should be a path to your file on your machine. + This should be a path to your file on your machine. :param text: Type: string. Text content; best used with a POST request, see - examples + examples :param engine: (optional) Type: integer, Default: 0. Either 1 for TaxonFinder, - 2 for NetiNeti, or 0 for both. If absent, both engines are used. - :param unique: (optional) Type: boolean. If TRUE (default), - response has unique names without offsets. - :param verbatim: (optional) Type: boolean, If TRUE (default to FALSE), - response excludes verbatim strings. + 2 for NetiNeti, or 0 for both. If absent, both engines are used. + :param unique: (optional) Type: boolean. If True (default), + response has unique names without offsets. + :param verbatim: (optional) Type: boolean, If True (default to False), + response excludes verbatim strings. :param detect_language: (optional) Type: boolean, When - TRUE (default), NetiNeti is not used if the language of incoming text is - determined not to be English. When 'false', NetiNeti will be used if requested. + True (default), NetiNeti is not used if the language of incoming text is + determined not to be English. When 'false', NetiNeti will be used if requested. :param all_data_sources: (optional) Type: bolean. Resolve found - names against all available Data Sources. + names against all available Data Sources. :param data_source_ids: (optional) Type: string. Pipe separated list of data - source ids to resolve found names against. See list of Data Sources. + source ids to resolve found names against. See list of Data Sources. + :param as_dataframe: (optional) Type: boolean. Return as pandas data frame? + default: False Usage:: + + import pytaxize # Get data from a website using its URL - out = pytaxize.scrapenames(url = 'http://en.wikipedia.org/wiki/Araneae') + out = pytaxize.scrapenames(url = 'https://en.wikipedia.org/wiki/Spider') out['data'].head() # data out['meta'] # metadata @@ -147,9 +165,8 @@ def scrapenames( out['meta'] # metadata # With arguments - pytaxize.scrapenames(url = 'http://www.mapress.com/zootaxa/2012/f/z03372p265f.pdf', - unique=TRUE) - pytaxize.scrapenames(url = 'http://www.mapress.com/zootaxa/2012/f/z03372p265f.pdf', all_data_sources=TRUE) + pytaxize.scrapenames(url = 'http://www.mapress.com/zootaxa/2012/f/z03372p265f.pdf', unique=True) + pytaxize.scrapenames(url = 'http://www.mapress.com/zootaxa/2012/f/z03372p265f.pdf', all_data_sources=True) # Get data from text string as an R object pytaxize.scrapenames(text='A spider named Pardosa moesta Banks, 1892') @@ -170,24 +187,28 @@ def scrapenames( "all_data_sources": all_data_sources, "data_source_ids": data_source_ids, } - - ss = [] - for i in range(len(method.keys())): - ss.append(list(method.keys())[i] in ["url", "text"]) - out = requests_refactor(base, payload, "get", content=True) - - if out["status"] != 303: - sys.exit("Woops, something went wrong") - else: - token_url = out["token_url"] - st = 303 - while st == 303: - datout = requests_refactor(token_url, content=True) - st = datout["status"] - dd = pd.DataFrame(datout["names"]) - datout.pop("names") - meta = datout - return {"meta": meta, "data": dd} + payload = {key: value for key, value in payload.items() if value != None} + out = requests.get(base, params=payload) + out.raise_for_status() + res = out.json() + data = res["names"] + meta = res + meta.pop("names") + if as_dataframe: + data = _df(data, True) + return {"meta": meta, "data": data} + # if out["status"] != 303: + # sys.exit("Woops, something went wrong") + # else: + # token_url = out["token_url"] + # st = 303 + # while st == 303: + # datout = requests_refactor(token_url, content=True) + # st = datout["status"] + # dd = pd.DataFrame(datout["names"]) + # datout.pop("names") + # meta = datout + # return {"meta": meta, "data": dd} if __name__ == "__main__": diff --git a/pytaxize/taxo.py b/pytaxize/taxo.py index 451c356..9a15653 100644 --- a/pytaxize/taxo.py +++ b/pytaxize/taxo.py @@ -1,71 +1,70 @@ import sys import requests -import pandas as pd import json import time import os +try: + import pandas as pd +except ImportError: + warnings.warn("Pandas library not installed, dataframes disabled") + pd = None class NoResultException(Exception): pass -def taxo_datasources(todf=True): +def taxo_datasources(as_dataframe=False): """ Get data sources for Taxosaurus. Retrieve data sources used in Global Names Index, see http://taxosaurus.org/ for information. - Usage: # all data sources >>> import pytaxize - >>> out = pytaxize.taxo_datasources() - >>> out.head() + >>> pytaxize.taxo_datasources() id name 0 NCBI NCBI 1 iPlant_TNRS iPlant Collaborative TNRS v3.1 2 MSW3 Mammal Species of the World v3.0 - # Output json + # Output a dict >>> pytaxize.taxo_datasources(False) """ url = "http://taxosaurus.org/sources/" - if todf: - out = requests.get(url) - out.raise_for_status() - out = out.json() - out = out["sources"] + out = requests.get(url) + out.raise_for_status() + out = out.json()["sources"] + if as_dataframe: data = [] for i in range(len(out)): data.append([out[i]["sourceId"], out[i]["name"]]) df = pd.DataFrame(data, columns=["id", "name"]) return df else: - out = requests.get(url) - out.raise_for_status() - out = out.json() return out - -def taxo_resolve(query="Homo sapiens", source=None, code=None, http="get"): +def taxo_resolve(query, source=None, code=None, http="get"): """ Uses Taxosaurus to resolve scientific names :param query: List of taxonomic names :param source(optional): Source to pull from :param code(optional): the abbreviation for one of the nomenclature codes (ICZN: International Code of Zoological Nomenclature; ICN: International Code of Nomenclature for algae, fungi, and plants; ICNB: International Code of Nomenclature of Bacteria) :param http(optional): The HTTP method to use, one of "get" or "post". Default="get" + Usage: + >>> import pytaxize - >>> pytaxize.taxo_resolve('Helianthus annus') + >>> pytaxize.taxo_resolve(query='Helianthus annus') [[{u'sourceId': u'iPlant_TNRS', u'acceptedName': u'Helianthus annuus', u'uri': u'http://www.tropicos.org/Name/2700851', u'matchedName': u'Helianthus annuus', u'score': u'0.9694502693699', u'annotations': {u'Authority': u'L.'}}, {u'sourceId': u'NCBI', u'acceptedName': u'Helianthus annuus', u'uri': u'http://www.ncbi.nlm.nih.gov/taxonomy/4232', u'matchedName': u'Helianthus annus', u'score': u'1', u'annotations': {}}]] >>> pytaxize.gnr_resolve(['Helianthus annus','Poa annua']) [[{u'sourceId': u'iPlant_TNRS', u'acceptedName': u'Helianthus annuus', u'uri': u'http://www.tropicos.org/Name/2700851', u'matchedName': u'Helianthus annuus', u'score': u'0.9694502693699', u'annotations': {u'Authority': u'L.'}}, {u'sourceId': u'NCBI', u'acceptedName': u'Helianthus annuus', u'uri': u'http://www.ncbi.nlm.nih.gov/taxonomy/4232', u'matchedName': u'Helianthus annus', u'score': u'1', u'annotations': {}}], [{u'sourceId': u'iPlant_TNRS', u'acceptedName': u'Megalachne', u'uri': u'http://www.tropicos.org/Name/40015658', u'matchedName': u'Pantathera', u'score': u'0.47790686999749', u'annotations': {u'Authority': u'Steud.'}}, {u'sourceId': u'NCBI', u'acceptedName': u'Panthera tigris', u'uri': u'http://www.ncbi.nlm.nih.gov/taxonomy/9694', u'matchedName': u'Panthera tigris', u'score': u'1', u'annotations': {}}, {u'sourceId': u'MSW3', u'acceptedName': u'Panthera tigris', u'uri': u'http://www.bucknell.edu/msw3/browse.asp?id=14000259', u'matchedName': u'Panthera tigris', u'score': u'1', u'annotations': {}}]] """ url = "http://taxosaurus.org/submit" payload = {} - if query.__class__.__name__ == "list": + if isinstance(query, list): if len(query) > 300 and http == "get": http = "post" else: diff --git a/test/test_itis.py b/test/test_itis.py index 61d8558..cfabd85 100644 --- a/test/test_itis.py +++ b/test/test_itis.py @@ -5,43 +5,44 @@ import vcr from pytaxize import itis - class ITIS(unittest.TestCase): @vcr.use_cassette("test/vcr_cassettes/itis_getacceptednamesfromtsn.yml") def test_itis_getacceptednamesfromtsn(self): "ITIS: getaccepednamesfromtsn" - assert itis.getacceptednamesfromtsn("208527") == "208527" + assert itis.getacceptednamesfromtsn("208527") == {} @vcr.use_cassette("test/vcr_cassettes/itis_getcommentdetailfromtsn.yml") def test_itis_getcommentdetailfromtsn(self): "ITIS: getcommentdetailfromtsn" comments = itis.getcommentdetailfromtsn(tsn=180543) - assert set(comments.keys()) == set( - ["commentator", "comment", "commtime", "updatedate", "commid"] - ) + assert isinstance(comments, list) + assert isinstance(comments[0], dict) + assert len(comments) == 2 - @vcr.use_cassette("test/vcr_cassettes/itis_searchbycommonname.yml") - def test_itis_searchbycommonname(self): - "ITIS: searchbycommonname" - df = itis.searchbycommonname("grizzly") - assert set(list(df.columns)) == set(["tsn", "language", "commonname"]) + # @vcr.use_cassette("test/vcr_cassettes/itis_searchbycommonname.yml") + # def test_itis_searchbycommonname(self): + # "ITIS: searchbycommonname" + # df = itis.searchbycommonname("grizzly") + # assert set(list(df.columns)) == set(["tsn", "language", "commonname"]) - @vcr.use_cassette("test/vcr_cassettes/tis_gethierarchyupfromtsn.yml") - def test_itis_gethierarchyupfromtsn(self): - "ITIS: gethierarchyupfromtsn" - hierarchy = itis.gethierarchyupfromtsn(tsn=36485) - assert hierarchy[0]["rankName"] == "Genus" + # @vcr.use_cassette("test/vcr_cassettes/tis_gethierarchyupfromtsn.yml") + # def test_itis_gethierarchyupfromtsn(self): + # "ITIS: gethierarchyupfromtsn" + # hierarchy = itis.gethierarchyupfromtsn(tsn=36485) + # assert hierarchy[0]["rankName"] == "Genus" - def test_itis_getcommonnamesfromtsn(self): - """ - Basic test of its getcommonnamesfromtsn - """ - common_names = pytaxize.itis.getcommonnamesfromtsn( + @vcr.use_cassette("test/vcr_cassettes/itis_getcommonnamesfromtsn_dict.yml") + def test_itis_getcommonnamesfromtsn_dict(self): + "ITIS: getcommonnamesfromtsn" + common_names = itis.getcommonnamesfromtsn( tsn=180543, as_dataframe=False ) - assert set(common_names[1]) == set(["comname", "lang", "tsn"]) + assert set(common_names[1]) == set(["commonName", "language", "tsn"]) - common_names_df = pytaxize.itis.getcommonnamesfromtsn( - tsn=180543, as_dataframe=True + @vcr.use_cassette("test/vcr_cassettes/itis_getcommonnamesfromtsn_dataframe.yml") + def test_itis_getcommonnamesfromtsn_dataframe(self): + "ITIS: getcommonnamesfromtsn" + common_names = itis.getcommonnamesfromtsn( + tsn=180543, as_dataframe=False ) - assert set(common_names_df.columns) == set(["comname", "lang", "tsn"]) + assert set(common_names[1]) == set(["commonName", "language", "tsn"]) diff --git a/test/test_taxosaurus.py b/test/test_taxosaurus.py new file mode 100644 index 0000000..46995be --- /dev/null +++ b/test/test_taxosaurus.py @@ -0,0 +1,22 @@ +import os +from nose.tools import * +import unittest +import vcr +import pytaxize + +class Taxosaurus(unittest.TestCase): + @vcr.use_cassette("test/vcr_cassettes/taxo_datasources.yml") + def test_taxo_datasources(self): + "taxo_datasources" + res = pytaxize.taxo_datasources() + assert isinstance(res, list) + assert isinstance(res[0], dict) + assert [z["sourceId"] for z in res] == ['NCBI', 'iPlant_TNRS', 'MSW3'] + + @vcr.use_cassette("test/vcr_cassettes/taxo_resolve.yml") + def test_taxo_resolve(self): + "taxo_resolve" + res = pytaxize.taxo_resolve(query='Helianthus annus') + assert isinstance(res, list) + assert isinstance(res[0], list) + assert isinstance(res[0][0], dict) diff --git a/test/vcr_cassettes/itis_getacceptednamesfromtsn.yml b/test/vcr_cassettes/itis_getacceptednamesfromtsn.yml index 260b6df..69038b8 100644 --- a/test/vcr_cassettes/itis_getacceptednamesfromtsn.yml +++ b/test/vcr_cassettes/itis_getacceptednamesfromtsn.yml @@ -2,42 +2,64 @@ interactions: - request: body: null headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 method: GET - uri: http://www.itis.gov/ITISWebService/services/ITISService/getAcceptedNamesFromTSN?tsn=208527 + uri: http://www.itis.gov/ITISWebService/jsonservice/getAcceptedNamesFromTSN?tsn=208527 response: - body: {string: ''} + body: + string: '' headers: - Connection: [Close] - Location: ['https://www.itis.gov/ITISWebService/services/ITISService/getAcceptedNamesFromTSN?tsn=208527'] - status: {code: 302, message: Redirect} + Connection: + - Close + Location: + - https://www.itis.gov/ITISWebService/jsonservice/getAcceptedNamesFromTSN?tsn=208527 + status: + code: 302 + message: Redirect - request: body: null headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 method: GET - uri: https://www.itis.gov/ITISWebService/services/ITISService/getAcceptedNamesFromTSN?tsn=208527 + uri: https://www.itis.gov/ITISWebService/jsonservice/getAcceptedNamesFromTSN?tsn=208527 response: - body: {string: '208527'} + body: + string: '{"acceptedNames":[null],"class":"gov.usgs.itis.itis_service.data.SvcAcceptedNameList","tsn":"208527"} + + ' headers: - Connection: [keep-alive] - Content-Type: [application/xml;charset=UTF-8] - Date: ['Thu, 08 Aug 2019 00:34:33 GMT'] - Strict-Transport-Security: [max-age=63072000; includeSubdomains; preload, max-age=63072000; - includeSubdomains; preload] - Transfer-Encoding: [chunked] - X-Application: [itis_webservices] - X-Node-Name: [not shown] - X-Upstream-Member: [not shown] - status: {code: 200, message: ''} + Connection: + - keep-alive + Content-Length: + - '102' + Content-Type: + - text/json;charset=ISO-8859-1 + Date: + - Tue, 09 Jun 2020 20:14:58 GMT + Strict-Transport-Security: + - max-age=63072000; includeSubdomains; preload + - max-age=63072000; includeSubdomains; preload + X-Application: + - itis_webservices + X-Node-Name: + - not shown + X-Upstream-Member: + - not shown + status: + code: 200 + message: '' version: 1 diff --git a/test/vcr_cassettes/itis_getcommentdetailfromtsn.yml b/test/vcr_cassettes/itis_getcommentdetailfromtsn.yml index 23d80eb..c93c599 100644 --- a/test/vcr_cassettes/itis_getcommentdetailfromtsn.yml +++ b/test/vcr_cassettes/itis_getcommentdetailfromtsn.yml @@ -2,58 +2,85 @@ interactions: - request: body: null headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 method: GET - uri: http://www.itis.gov/ITISWebService/services/ITISService/getCommentDetailFromTSN?tsn=180543 + uri: http://www.itis.gov/ITISWebService/jsonservice/getCommentDetailFromTSN?tsn=180543 response: - body: {string: ''} + body: + string: '' headers: - Connection: [Close] - Location: ['https://www.itis.gov/ITISWebService/services/ITISService/getCommentDetailFromTSN?tsn=180543'] - status: {code: 302, message: Redirect} + Connection: + - Close + Location: + - https://www.itis.gov/ITISWebService/jsonservice/getCommentDetailFromTSN?tsn=180543 + status: + code: 302 + message: Redirect - request: body: null headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 method: GET - uri: https://www.itis.gov/ITISWebService/services/ITISService/getCommentDetailFromTSN?tsn=180543 + uri: https://www.itis.gov/ITISWebService/jsonservice/getCommentDetailFromTSN?tsn=180543 response: - body: {string: "180543Status: CITES - Appendix I as U. arctos (Mexico, Bhutan,\ - \ China, and Mongolia populations) and U. a. isabellinus; otherwise Appendix\ - \ II. U. S. ESA - Endangered as U. arctos pruinosus, as U. arctos in Mexico,\ - \ and as U. a. arctos in Italy. Threatened as U. a. ho...185562007-08-20\ - \ 15:06:38.0Wilson & Reeder,\ - \ eds. (2005)2014-02-03Comments: Reviewed\ - \ by Erdbrink (1953), Couturier (1954), Rausch (1963a), Kurt\xE9n (1973),\ - \ Hall (1984) and Pasitschniak-Arts (1993). Ognev (1931) and Allen (1938)\ - \ recognized U. pruinosus as distinct; not followed by Ellerman and Morrison-Scott\ - \ (1951), Gao (1987), and Stroganov (1962). L\xF6nnberg (1923b) believed that\ - \ differences between pruinosus and arctos warranted subgeneric distinction\ - \ as (Mylarctos) pruinosus; however, this was not supported by Pocock's (1932b)\ - \ thorough revision. Synonyms allocated a...185572007-08-20\ - \ 15:06:38.0Wilson & Reeder,\ - \ eds. (2005)2014-02-03"} + body: + string: !!binary | + eyJjbGFzcyI6Imdvdi51c2dzLml0aXMuaXRpc19zZXJ2aWNlLmRhdGEuU3ZjVGF4b25Db21tZW50 + TGlzdCIsImNvbW1lbnRzIjpbeyJjbGFzcyI6Imdvdi51c2dzLml0aXMuaXRpc19zZXJ2aWNlLmRh + dGEuU3ZjVGF4b25Db21tZW50IiwiY29tbWVudERldGFpbCI6IlN0YXR1czogQ0lURVMgLSBBcHBl + bmRpeCBJIGFzIFUuIGFyY3RvcyAoTWV4aWNvLCBCaHV0YW4sIENoaW5hLCBhbmQgTW9uZ29saWEg + cG9wdWxhdGlvbnMpIGFuZCBVLiBhLiBpc2FiZWxsaW51czsgb3RoZXJ3aXNlIEFwcGVuZGl4IElJ + LiBVLiBTLiBFU0EgLSBFbmRhbmdlcmVkIGFzIFUuIGFyY3RvcyBwcnVpbm9zdXMsIGFzIFUuIGFy + Y3RvcyBpbiBNZXhpY28sIGFuZCBhcyBVLiBhLiBhcmN0b3MgaW4gSXRhbHkuIFRocmVhdGVuZWQg + YXMgVS4gYS4gaG8uLi4iLCJjb21tZW50SWQiOiIxODU1NiIsImNvbW1lbnRUaW1lU3RhbXAiOiIy + MDA3LTA4LTIwIDE1OjA2OjM4LjAiLCJjb21tZW50YXRvciI6IldpbHNvbiAmIFJlZWRlciwgZWRz + LiAoMjAwNSkiLCJ1cGRhdGVEYXRlIjoiMjAxNC0wMi0wMyJ9LHsiY2xhc3MiOiJnb3YudXNncy5p + dGlzLml0aXNfc2VydmljZS5kYXRhLlN2Y1RheG9uQ29tbWVudCIsImNvbW1lbnREZXRhaWwiOiJD + b21tZW50czogUmV2aWV3ZWQgYnkgRXJkYnJpbmsgKDE5NTMpLCBDb3V0dXJpZXIgKDE5NTQpLCBS + YXVzY2ggKDE5NjNhKSwgS3VydOluICgxOTczKSwgSGFsbCAoMTk4NCkgYW5kIFBhc2l0c2Nobmlh + ay1BcnRzICgxOTkzKS4gT2duZXYgKDE5MzEpIGFuZCBBbGxlbiAoMTkzOCkgcmVjb2duaXplZCBV + LiBwcnVpbm9zdXMgYXMgZGlzdGluY3Q7IG5vdCBmb2xsb3dlZCBieSBFbGxlcm1hbiBhbmQgTW9y + cmlzb24tU2NvdHQgKDE5NTEpLCBHYW8gKDE5ODcpLCBhbmQgU3Ryb2dhbm92ICgxOTYyKS4gTPZu + bmJlcmcgKDE5MjNiKSBiZWxpZXZlZCB0aGF0IGRpZmZlcmVuY2VzIGJldHdlZW4gcHJ1aW5vc3Vz + IGFuZCBhcmN0b3Mgd2FycmFudGVkIHN1YmdlbmVyaWMgZGlzdGluY3Rpb24gYXMgKE15bGFyY3Rv + cykgcHJ1aW5vc3VzOyBob3dldmVyLCB0aGlzIHdhcyBub3Qgc3VwcG9ydGVkIGJ5IFBvY29jaydz + ICgxOTMyYikgdGhvcm91Z2ggcmV2aXNpb24uIFN5bm9ueW1zIGFsbG9jYXRlZCBhLi4uIiwiY29t + bWVudElkIjoiMTg1NTciLCJjb21tZW50VGltZVN0YW1wIjoiMjAwNy0wOC0yMCAxNTowNjozOC4w + IiwiY29tbWVudGF0b3IiOiJXaWxzb24gJiBSZWVkZXIsIGVkcy4gKDIwMDUpIiwidXBkYXRlRGF0 + ZSI6IjIwMTQtMDItMDMifV0sInRzbiI6IjE4MDU0MyJ9Cg== headers: - Connection: [keep-alive] - Content-Type: [application/xml;charset=UTF-8] - Date: ['Thu, 08 Aug 2019 00:34:33 GMT'] - Strict-Transport-Security: [max-age=63072000; includeSubdomains; preload, max-age=63072000; - includeSubdomains; preload] - Transfer-Encoding: [chunked] - X-Application: [itis_webservices] - X-Node-Name: [not shown] - X-Upstream-Member: [not shown] - status: {code: 200, message: ''} + Connection: + - keep-alive + Content-Length: + - '1288' + Content-Type: + - text/json;charset=ISO-8859-1 + Date: + - Tue, 09 Jun 2020 20:14:58 GMT + Strict-Transport-Security: + - max-age=63072000; includeSubdomains; preload + - max-age=63072000; includeSubdomains; preload + X-Application: + - itis_webservices + X-Node-Name: + - not shown + X-Upstream-Member: + - not shown + status: + code: 200 + message: '' version: 1 diff --git a/test/vcr_cassettes/itis_getcommonnamesfromtsn_dataframe.yml b/test/vcr_cassettes/itis_getcommonnamesfromtsn_dataframe.yml new file mode 100644 index 0000000..5a4052f --- /dev/null +++ b/test/vcr_cassettes/itis_getcommonnamesfromtsn_dataframe.yml @@ -0,0 +1,68 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + response: + body: + string: '' + headers: + Connection: + - Close + Location: + - https://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + status: + code: 302 + message: Redirect +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: https://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + response: + body: + string: '{"class":"gov.usgs.itis.itis_service.data.SvcCommonNameList","commonNames":[{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Brown + Bear","language":"English","tsn":"180543"},{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Grizzly + Bear","language":"English","tsn":"180543"},{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Oso + pardo","language":"Spanish","tsn":"180543"}],"tsn":"180543"} + + ' + headers: + Connection: + - keep-alive + Content-Length: + - '454' + Content-Type: + - text/json;charset=ISO-8859-1 + Date: + - Tue, 09 Jun 2020 20:22:56 GMT + Strict-Transport-Security: + - max-age=63072000; includeSubdomains; preload + - max-age=63072000; includeSubdomains; preload + X-Application: + - itis_webservices + X-Node-Name: + - not shown + X-Upstream-Member: + - not shown + status: + code: 200 + message: '' +version: 1 diff --git a/test/vcr_cassettes/itis_getcommonnamesfromtsn_dict.yml b/test/vcr_cassettes/itis_getcommonnamesfromtsn_dict.yml new file mode 100644 index 0000000..c80853d --- /dev/null +++ b/test/vcr_cassettes/itis_getcommonnamesfromtsn_dict.yml @@ -0,0 +1,68 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + response: + body: + string: '' + headers: + Connection: + - Close + Location: + - https://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + status: + code: 302 + message: Redirect +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: https://www.itis.gov/ITISWebService/jsonservice/getCommonNamesFromTSN?tsn=180543 + response: + body: + string: '{"class":"gov.usgs.itis.itis_service.data.SvcCommonNameList","commonNames":[{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Brown + Bear","language":"English","tsn":"180543"},{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Grizzly + Bear","language":"English","tsn":"180543"},{"class":"gov.usgs.itis.itis_service.data.SvcCommonName","commonName":"Oso + pardo","language":"Spanish","tsn":"180543"}],"tsn":"180543"} + + ' + headers: + Connection: + - keep-alive + Content-Length: + - '454' + Content-Type: + - text/json;charset=ISO-8859-1 + Date: + - Tue, 09 Jun 2020 20:24:00 GMT + Strict-Transport-Security: + - max-age=63072000; includeSubdomains; preload + - max-age=63072000; includeSubdomains; preload + X-Application: + - itis_webservices + X-Node-Name: + - not shown + X-Upstream-Member: + - not shown + status: + code: 200 + message: '' +version: 1 diff --git a/test/vcr_cassettes/itis_searchbycommonname.yml b/test/vcr_cassettes/itis_searchbycommonname.yml deleted file mode 100644 index 4151f79..0000000 --- a/test/vcr_cassettes/itis_searchbycommonname.yml +++ /dev/null @@ -1,52 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] - method: GET - uri: http://www.itis.gov/ITISWebService/services/ITISService/searchByCommonName?srchKey=grizzly - response: - body: {string: ''} - headers: - Connection: [Close] - Location: ['https://www.itis.gov/ITISWebService/services/ITISService/searchByCommonName?srchKey=grizzly'] - status: {code: 302, message: Redirect} -- request: - body: null - headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.22.0] - method: GET - uri: https://www.itis.gov/ITISWebService/services/ITISService/searchByCommonName?srchKey=grizzly - response: - body: {string: 'grizzly lancetoothunspecified76998Grizzly BearEnglish180543Mexican grizzly bearEnglish202384grizzly bearEnglish202385grizzlybear pricklypearEnglish195275Utah grizzlybear pricklypearEnglish195276grizzlybear pricklypearunspecified195272grizzlybear pricklypearEnglish19705grizzlybear pricklypearEnglish195273grizzlybear pricklypearEnglish195274'} - headers: - Connection: [keep-alive] - Content-Type: [application/xml;charset=UTF-8] - Date: ['Thu, 08 Aug 2019 00:34:34 GMT'] - Strict-Transport-Security: [max-age=63072000; includeSubdomains; preload, max-age=63072000; - includeSubdomains; preload] - Transfer-Encoding: [chunked] - X-Application: [itis_webservices] - X-Node-Name: [not shown] - X-Upstream-Member: [not shown] - status: {code: 200, message: ''} -version: 1 diff --git a/test/vcr_cassettes/taxo_datasources.yml b/test/vcr_cassettes/taxo_datasources.yml new file mode 100644 index 0000000..9e3b603 --- /dev/null +++ b/test/vcr_cassettes/taxo_datasources.yml @@ -0,0 +1,52 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://taxosaurus.org/sources/ + response: + body: + string: '{"sources":[{"name":"NCBI","description":"NCBI Taxonomy","annotations":{},"uri":"http://www.ncbi.nlm.nih.gov/taxonomy","sourceId":"NCBI","publication":"Federhen + S. The Taxonomy Project.2002 Oct 9 [Updated 2003 Aug 13]. In: McEntyre J., + Ostell J., editors. The NCBI Handbook [Internet]. Bethesda (MD): National + Center for Biotechnology Information (US);2002.","call":"python2.6 tnrs_adapter/ncbi_adapter/ncbi_adaptor.py","rank":3,"code":"ICZN,ICN,ICNB"},{"name":"iPlant + Collaborative TNRS v3.1","description":"The iPlant Collaborative TNRS provides + parsing and fuzzy matching for plant taxa.","annotations":{"Authority":"Author + attributed to the accepted name (where applicable)."},"uri":"http://tnrs.iplantcollaborative.org/","sourceId":"iPlant_TNRS","publication":"Boyle, + B. et.al. The taxonomic name resolution service: an online tool for automated + standardization of plant names. BMC Bioinformatics. 2013, 14:16. doi:10.1186/1471-2105-14-16. + If you use TNRS results in a publication, please also cite The Taxonomic Name + Resolution Service; http://tnrs.iplantcollaborative.org; version 3.1.","call":"perl + -Itnrs_adapter/iplant tnrs_adapter/iplant/iplant.pl","rank":2,"code":"ICN"},{"name":"Mammal + Species of the World v3.0","description":"Mammal Species of the World, 3rd + edition (MSW3) is a database of mammalian taxonomy. Our adaptor searches the + indexed database for both exact and loose mathces","annotations":{"Authority":"Don + E. Wilson & DeeAnn M. Reeder (editors). 2005. Mammal Species of the World. + A Taxonomic and Geographic Reference (3rd ed)"},"uri":"http://www.bucknell.edu/msw3/","sourceId":"MSW3","publication":"Don + E. Wilson & DeeAnn M. Reeder (editors). 2005. Mammal Species of the World. + A Taxonomic and Geographic Reference (3rd ed)","call":"python2.6 tnrs_adapter/MSW3/MSW3_adaptor.py","rank":4,"code":"ICZN"}],"status":"OK"}' + headers: + Connection: + - close + Content-Length: + - '1846' + Content-Type: + - text/json; charset=utf-8 + Date: + - Tue, 09 Jun 2020 20:36:31 GMT + Server: + - Apache/2.2.3 (CentOS) + X-Powered-By: + - Perl Dancer 1.3111 + status: + code: 200 + message: OK +version: 1 diff --git a/test/vcr_cassettes/taxo_resolve.yml b/test/vcr_cassettes/taxo_resolve.yml new file mode 100644 index 0000000..6f7cb78 --- /dev/null +++ b/test/vcr_cassettes/taxo_resolve.yml @@ -0,0 +1,127 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://taxosaurus.org/submit?query=Helianthus+annus + response: + body: + string: '{"submit date":"Tue Jun 9 13:36:32 2020","version":"2.2.2","status":"found","token":"2aab1e015acbd4ca3e8561999e983c52","message":"Your + request is being processed. You can retrieve the results at http://taxosaurus.org/retrieve/2aab1e015acbd4ca3e8561999e983c52.","uri":"http://taxosaurus.org/retrieve/2aab1e015acbd4ca3e8561999e983c52"}' + headers: + Connection: + - close + Content-Length: + - '334' + Content-Type: + - text/json; charset=utf-8 + Date: + - Tue, 09 Jun 2020 20:36:31 GMT + Location: + - http://taxosaurus.org/retrieve/2aab1e015acbd4ca3e8561999e983c52 + Server: + - Apache/2.2.3 (CentOS) + X-Powered-By: + - Perl Dancer 1.3111 + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://taxosaurus.org/retrieve/2aab1e015acbd4ca3e8561999e983c52 + response: + body: + string: '{"status":"found","message":"Job 2aab1e015acbd4ca3e8561999e983c52 is + still being processed. Please try refreshing in a few seconds."}' + headers: + Connection: + - close + Content-Length: + - '133' + Content-Type: + - text/json; charset=utf-8 + Date: + - Tue, 09 Jun 2020 20:36:32 GMT + Server: + - Apache/2.2.3 (CentOS) + X-Powered-By: + - Perl Dancer 1.3111 + status: + code: 302 + message: Found +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.23.0 + method: GET + uri: http://taxosaurus.org/retrieve/2aab1e015acbd4ca3e8561999e983c52 + response: + body: + string: '{"status":"OK","names":[{"matchCount":2,"matches":[{"acceptedName":"Helianthus + annuus","sourceId":"iPlant_TNRS","score":"0.9694502693699","matchedName":"Helianthus + annuus","annotations":{"Authority":"L."},"uri":"http://www.tropicos.org/Name/2700851"},{"acceptedName":"Helianthus + annuus","sourceId":"NCBI","score":"1","matchedName":"Helianthus annus","annotations":{},"uri":"https://www.ncbi.nlm.nih.gov/taxonomy/4232"}],"submittedName":"Helianthus + annus"}],"metadata":{"spellcheckers":[{"name":"NCBI","description":"NCBI Spell + Checker","annotations":{},"uri":"http://www.ncbi.nlm.nih.gov/","sourceId":1,"publication":"http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2578899/","call":"python2.6 + tnrs_spellchecker/ncbi_spell.py","rank":1}],"sources":[{"status":"200: OK","name":"NCBI","description":"NCBI + Taxonomy","uri":"http://www.ncbi.nlm.nih.gov/taxonomy","annotations":{},"sourceId":"NCBI","publication":"Federhen + S. The Taxonomy Project.2002 Oct 9 [Updated 2003 Aug 13]. In: McEntyre J., + Ostell J., editors. The NCBI Handbook [Internet]. Bethesda (MD): National + Center for Biotechnology Information (US);2002.","rank":3,"code":"ICZN,ICN,ICNB"},{"status":"200: + OK","name":"iPlant Collaborative TNRS v3.1","description":"The iPlant Collaborative + TNRS provides parsing and fuzzy matching for plant taxa.","uri":"http://tnrs.iplantcollaborative.org/","annotations":{"Authority":"Author + attributed to the accepted name (where applicable)."},"sourceId":"iPlant_TNRS","publication":"Boyle, + B. et.al. The taxonomic name resolution service: an online tool for automated + standardization of plant names. BMC Bioinformatics. 2013, 14:16. doi:10.1186/1471-2105-14-16. + If you use TNRS results in a publication, please also cite The Taxonomic Name + Resolution Service; http://tnrs.iplantcollaborative.org; version 3.1.","rank":2,"code":"ICN"},{"status":"200: + OK","name":"Mammal Species of the World v3.0","description":"Mammal Species + of the World, 3rd edition (MSW3) is a database of mammalian taxonomy. Our + adaptor searches the indexed database for both exact and loose mathces","uri":"http://www.bucknell.edu/msw3/","annotations":{"Authority":"Don + E. Wilson & DeeAnn M. Reeder (editors). 2005. Mammal Species of the World. + A Taxonomic and Geographic Reference (3rd ed)"},"sourceId":"MSW3","publication":"Don + E. Wilson & DeeAnn M. Reeder (editors). 2005. Mammal Species of the World. + A Taxonomic and Geographic Reference (3rd ed)","rank":4,"code":"ICZN"}],"sub_date":"Tue + Jun 9 13:36:32 2020","resolver_version":"1.2.0","jobId":"2aab1e015acbd4ca3e8561999e983c52"}}' + headers: + Connection: + - close + Content-Length: + - '2551' + Content-Type: + - text/json; charset=utf-8 + Date: + - Tue, 09 Jun 2020 20:36:34 GMT + Server: + - Apache/2.2.3 (CentOS) + X-Powered-By: + - Perl Dancer 1.3111 + status: + code: 200 + message: OK +version: 1