Ejemplo n.º 1
0
def _get_data_sources(params, headers):
    """
    Returns a list of all Taxonomy Sources
    """
    schema = _SCHEMAS['get_data_sources']

    # parameters for get_data_sources are not actually required, as omitting
    # the parameters (which filter the sources) implies returning all.
    if params is not None:
        jsonschema.validate(instance=params, schema=schema)

    re_params = {
        'type': 'taxonomy',
    }

    # Be nice. Filtering by ns can be skipped by either setting 'ns' to null, or
    # omitting it from the params object.
    if params is not None and params.get('ns') is not None:
        re_params['ns'] = params.get('ns')
        response = re_api.query("data_sources_get_data_sources", re_params,
                                headers.get('Authorization'))
    else:
        response = re_api.query("data_sources_get_all_data_sources", re_params,
                                headers.get('Authorization'))

    sources = []
    for source in response['results']:
        del source['_id']
        del source['_key']
        del source['_rev']
        sources.append(source)

    return {'sources': sources}
Ejemplo n.º 2
0
def _get_associated_ws_objects(params, headers):
    """
    Get any versioned workspace objects associated with a taxon.
    """
    schema = _SCHEMAS['get_associated_ws_objects']
    jsonschema.validate(instance=params, schema=schema)
    (ns, ns_config) = transform_params(params, ('@taxon_coll', ),
                                       {'id': 'taxon_id'})
    results = re_api.query("taxonomy_get_associated_ws_objects", params,
                           headers.get('Authorization'))
    res = results['results'][0]
    transform_taxon_results(results['results'], ns, ns_config)
    for res in results['results']:
        # Write some extra metadata about the workspace for each object
        for elem in res['results']:
            obj = elem['ws_obj']
            obj['workspace'] = {
                'refdata_source':
                obj['ws_info'].get('metadata', {}).get('refdata_source'),
                'narr_name':
                obj['ws_info'].get('metadata', {}).get('narrative_nice_Name'),
            }
            del obj['ws_info']
    return {
        'stats': results['stats'],
        'total_count': res['total_count'],
        'results': res['results']
    }
Ejemplo n.º 3
0
def _search_species(params, headers):
    """
    Search for a species or strain. Similar to search_taxa, but a stripped down, faster query
    Returns (result, err), one of which will be None.
    """
    schema = _SCHEMAS['search_species']
    jsonschema.validate(instance=params, schema=schema)
    params['ts'] = params.get('ts', int(time.time() * 1000))
    (ns, ns_config) = transform_params(params,
                                       ('@taxon_coll', 'sciname_field'))
    resp = re_api.query("taxonomy_search_species", params)
    results = resp['results']
    transform_taxon_results(results, ns, ns_config)
    return {'stats': resp['stats'], 'results': results, 'ts': params['ts']}
Ejemplo n.º 4
0
def _get_taxon(params, headers):
    """
    Fetch a taxon by ID.
    Returns (result, err), one of which will be None.
    """
    schema = _SCHEMAS['get_taxon']
    jsonschema.validate(instance=params, schema=schema)
    (ns, ns_config) = transform_params(params, ('@taxon_coll', ))
    results = re_api.query("taxonomy_fetch_taxon", params)
    transform_taxon_results(results['results'], ns, ns_config)
    return {
        'stats': results['stats'],
        'results': results['results'],
        'ts': params['ts']
    }
Ejemplo n.º 5
0
def _get_taxon_from_ws_obj(params, headers):
    """
    Fetch the taxon document from a workspace object reference.
    """
    schema = _SCHEMAS['get_taxon_from_ws_obj']
    jsonschema.validate(instance=params, schema=schema)
    (ns, ns_config) = transform_params(params, ('@taxon_coll', ))
    params['obj_ref'] = params['obj_ref'].replace('/', ':')
    results = re_api.query("taxonomy_get_taxon_from_ws_obj", params)
    transform_taxon_results(results['results'], ns, ns_config)
    return {
        'stats': results['stats'],
        'results': results['results'],
        'ts': params['ts']
    }
Ejemplo n.º 6
0
def _get_lineage(params, headers):
    """
    Fetch ancestor lineage for a taxon by ID.
    Returns (result, err), one of which will be None.
    """
    schema = _SCHEMAS['get_lineage']
    jsonschema.validate(instance=params, schema=schema)
    params['ts'] = params.get('ts', int(time.time() * 1000))
    (ns, ns_config) = transform_params(params,
                                       ('@taxon_coll', '@taxon_child_of'))
    results = re_api.query("taxonomy_get_lineage", params)
    transform_taxon_results(results['results'], ns, ns_config)
    return {
        'stats': results['stats'],
        'results': results['results'],
        'ts': params['ts']
    }
Ejemplo n.º 7
0
def _search_taxa(params, headers):
    """
    Search for a taxon vertex by scientific name.
    Returns (result, err), one of which will be None.
    """
    schema = _SCHEMAS['search_taxa']
    jsonschema.validate(instance=params, schema=schema)
    (ns, ns_config) = transform_params(params,
                                       ('@taxon_coll', 'sciname_field'))
    results = re_api.query("taxonomy_search_sci_name", params)
    res = results['results'][0]
    transform_taxon_results(res['results'], ns, ns_config)
    return {
        'stats': results['stats'],
        'total_count': res.get('total_count'),
        'results': res['results'],
        'ts': params['ts']
    }
Ejemplo n.º 8
0
def _get_siblings(params, headers):
    """
    Fetch the siblings for a taxon by ID.
    Returns (result, err), one of which will be None.
    """
    schema = _SCHEMAS['get_siblings']
    jsonschema.validate(instance=params, schema=schema)
    (ns, ns_config) = transform_params(
        params, ('@taxon_coll', '@taxon_child_of', 'sciname_field'))
    results = re_api.query("taxonomy_get_siblings", params)
    res = results['results'][0]
    transform_taxon_results(res['results'], ns, ns_config)
    return {
        'stats': results['stats'],
        'total_count': res['total_count'],
        'results': res['results'],
        'ts': params['ts']
    }