Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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'])
Beispiel #5
0
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)
Beispiel #6
0
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'])
Beispiel #7
0
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
Beispiel #8
0
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
Beispiel #9
0
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
Beispiel #10
0
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)
Beispiel #11
0
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
Beispiel #12
0
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
Beispiel #13
0
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
Beispiel #14
0
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