def getacceptednamesfromtsn(tsn, **kwargs): ''' Get accepted names from tsn :param tsn: taxonomic serial number (TSN) (character or numeric) Usage:: # TSN accepted - good name pytaxize.getacceptednamesfromtsn('208527') # TSN not accepted - input TSN is old name pytaxize.getacceptednamesfromtsn('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 else: nodes = temp[0].getchildren()[1].getchildren() dat = _parse_nodes(nodes) dat.pop('author') dat['submittedTsn'] = temp[0].getchildren()[0].text return dat
def searchforanymatch(x, **kwargs): ''' Search for any match Usage:: pytaxize.searchforanymatch(x=202385) pytaxize.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
def searchforanymatchpaged(x, pagesize, pagenum, ascend, **kwargs): ''' Search for any matched page for descending (logical) Usage:: pytaxize.searchforanymatchpaged(x=202385, pagesize=100, pagenum=1, ascend=False) pytaxize.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
def getjurisdictionvalues(**kwargs): ''' Get possible jurisdiction values Usage: pytaxize.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 getanymatchcount(x, **kwargs): ''' Get any match count. :param x: text or taxonomic serial number (TSN) (character or numeric) :param **kwargs: optional additional curl options (debugging tools mostly) Usage: pytaxize.getanymatchcount(x=202385) pytaxize.getanymatchcount(x="dolphin") ''' out = Refactor(itis_base + 'getAnyMatchCount', payload={'srchKey': x}, request='get').xml(**kwargs) return int(out.getchildren()[0].text)
def getjurisdictionvalues(**kwargs): ''' Get possible jurisdiction values Usage:: pytaxize.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 gettsnfromlsid(lsid, **kwargs): ''' Gets the TSN corresponding to the LSID, or an empty result if there is no match. Usage: pytaxize.gettsnfromlsid(lsid="urn:lsid:itis.gov:itis_tsn:28726") pytaxize.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
def searchforanymatch(x, **kwargs): ''' Search for any match pytaxize.searchforanymatch(x=202385) pytaxize.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
def searchforanymatchpaged(x, pagesize, pagenum, ascend, **kwargs): ''' Search for any matched page for descending (logical) Usage: pytaxize.searchforanymatchpaged(x=202385, pagesize=100, pagenum=1, ascend=False) pytaxize.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
def getanymatchcount(x, **kwargs): ''' Get any match count. :param x: text or taxonomic serial number (TSN) (character or numeric) :param **kwargs: Curl options passed on to `requests.get` Usage:: pytaxize.getanymatchcount(x=202385) pytaxize.getanymatchcount(x="dolphin") ''' out = Refactor(itis_base + 'getAnyMatchCount', payload={ 'srchKey': x }, request='get').xml(**kwargs) return int(out.getchildren()[0].text)
def getlsidfromtsn(tsn, **kwargs): ''' Gets the unique LSID for the TSN, or an empty result if there is no match. Usage: # valid TSN pytaxize.getlsidfromtsn(155166) # invalid TSN, returns nothing pytaxize.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
def gettsnfromlsid(lsid, **kwargs): ''' Gets the TSN corresponding to the LSID, or an empty result if there is no match. Usage:: pytaxize.gettsnfromlsid(lsid="urn:lsid:itis.gov:itis_tsn:28726") pytaxize.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
def getacceptednamesfromtsn(tsn, **kwargs): ''' Get accepted names from tsn :param tsn: taxonomic serial number (TSN) (character or numeric) Usage: # TSN accepted - good name pytaxize.getacceptednamesfromtsn('208527') # TSN not accepted - input TSN is old name pytaxize.getacceptednamesfromtsn('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 else: nodes = temp[0].getchildren()[1].getchildren() dat = _parse_nodes(nodes) dat.pop('author') dat['submittedTsn'] = temp[0].getchildren()[0].text return dat
def getlsidfromtsn(tsn, **kwargs): ''' Gets the unique LSID for the TSN, or an empty result if there is no match. Usage:: # valid TSN pytaxize.getlsidfromtsn(155166) # invalid TSN, returns nothing pytaxize.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