def search(args):
    """
    args contains a dict with one or key:values

    locus is AGI identifier and is mandatory
    """
    locus = args['locus']

    """
    Make the request to the remote service
    """
    response = tools.do_request('LineIDPerLocus.php', locus=locus)

    """
    Iterate through the results
    Foreach record from the remote service, build the response json
    Print this json to stdout followed by a record separator "---"
    ADAMA takes care of serializing these results
    """
    for result in response['lines']:

        record = {
                'locus': locus,
                'class': 'locus_property',
                'source_text_description': 'Reporter_Image_data',
                'line_record': {
                        'line_id': result['line_id']
                }
            }
        print json.dumps(record, indent=2)
        print '---'
def search(args):
    """
    args contains a dict with one or key:values

    line is a combination of plate, well, plant & dip number (mandatory)
    """
    line_id = args['line_id']

    """
    Make the request to the remote service
    """
    response = tools.do_request('ImageIDPerLineID.php', line_id=line_id)

    """
    Iterate through the results
    Foreach record from the remote service, build the response json
    Print this json to stdout followed by a record separator "---"
    ADAMA takes care of serializing these results
    """
    for result in response['images']:

        record = {
                'line_id': line_id,
                'class': 'line_property',
                'source_text_description': 'Reporter_Image_data',
                'image_record': {
                        'image_id': result['image_id'],
                        'image_url': result['image_url']
                }
            }
        print json.dumps(record, indent=2)
        print '---'
def search(args):
    """
    args contains a dict with one or key:values

    po_code is a PO code and is mandatory
    """
    po_code = args['po_code']

    """
    Make the request to the remote service
    """
    response = tools.do_request('POInfoPerCode.php', po_code=po_code)

    """
    Iterate through the results
    Foreach record from the remote service, build the response json
    Print this json to stdout followed by a record separator "---"
    ADAMA takes care of serializing these results
    """
    record = {
            'po_code': po_code,
            'class': 'po_code_property',
            'source_text_description': 'Reporter_Image_data',
            'po_definition_record': {
                    'po_name': response['po_name'],
                    'po_def': response['po_def'],
                    'po_namespace': response['po_namespace']
            }
        }
    print json.dumps(record, indent=2)
    print '---'
def search(args):
    """
    args contains a dict with one or key:values

    locus is AGI identifier and is mandatory
    """
    search_locus = args['locus']
    _url, token = args['_url'], args['_token']

    # get the chromosome coordinates of the specified locus
    coordinates = utils.get_gene_coordinates(search_locus)
    if not coordinates:
        raise Exception("Locus '%s' could not be found!" % search_locus)

    # get all of the overlapping features in jBrowse format from the araport11_gff_to_jbrowse service
    url = op.join(_url, 'araport', 'araport11_gff_region_to_jbrowse_v0.1', 'search')
    payload = {
        'q': 'features',
        'chr': coordinates['chromosome'],
        'start': coordinates['start'],
        'end': coordinates['end'],
        'strand': coordinates['strand'],
        'featuretype': 'gene',
        'level': 2,
        'completely_within': True,
        'interbase' : False
    }
    data = tools.do_request(url, token, **payload)
    return 'application/json', json.dumps(data)
def get_features(refseq, start, end, strand, featuretype, completely_within=True, level=1):
    """
    Return the features within a given set of chromosome coordinates
    """
    url = urljoin(THALEMINE_BASE_URL, "jbrowse", TAXID, "features", refseq)
    data = tools.do_request(url, None, start=start, end=end, type=featuretype)

    elems_to_delete = []
    for x, elem0 in enumerate(data['features']):
        # remove feature if not completely_within specified chromosome coordinates
        if completely_within and (elem0['start'] < start or elem0['end'] > end):
            elems_to_delete.append(x)
            continue
        # remove all subfeatures below 0th-level object
        if level == 0:
            data['features'][x]['subfeatures'] = []
        # remove all subfeatures below 1st-level object
        elif level == 1:
            for y, elem1 in enumerate(elem0['subfeatures']):
                data['features'][x]['subfeatures'][y]['subfeatures'] = []

    for i in sorted(elems_to_delete, reverse=True):
        del data['features'][i]

    return data
def get_region_feature_densities(refseq, start, end, featuretype):
    """
    Return binned density stats for features within a given set of chromosome coordinates
    """
    url = urljoin(THALEMINE_BASE_URL, "jbrowse", TAXID, "stats", "regionFeatureDensities", refseq)
    region_feature_densities = tools.do_request(url, None, start=start, end=end, type=featuretype)

    return region_feature_densities
def get_global_stats(featuretype):
    """
    Return global stats for features of specific type
    """
    url = urljoin(THALEMINE_BASE_URL, "jbrowse", TAXID, "stats", "global")
    global_stats = tools.do_request(url, None, type=featuretype)

    return global_stats
def list(args):
    """
    List all of the valid Arabidopsis chromosomes and their lengths
    """
    _url, token = args['_url'], args['_token']
    url = op.join(_url, 'aip', 'get_sequence_by_coordinate_v0.3', 'list')

    data = tools.do_request(url, token)

    return 'application/json', json.dumps(data)
def search(args):
    """
    args contains a dict with one or key:values

    locus is AGI identifier and is mandatory
    """
    locus = args["locus"].upper()
    dedupe = args["dedupe"]

    """
    Make the request to the remote service
    """
    response = tools.do_request(locus)

    """
    Iterate through the results
    Foreach record from the remote service, build the response json
    Print this json to stdout followed by a record separator "---"
    ADAMA takes care of serializing these results
    """
    nodes = []
    edges = []
    proteins = {}
    for result in response.iter_lines():
        fields = result.strip().split("\t")
        id_a = (tools.getProteinXref(fields[0]))[0]
        id_b = (tools.getProteinXref(fields[1]))[0]
        locus_a = tools.getLocus(fields[4])
        locus_b = tools.getLocus(fields[5])

        # handle nodes
        if not proteins.has_key(id_a["id"]):
            nodes.append(tools.createNodeRecord(id_a, locus_a))
            proteins[id_a["id"]] = 1
        if not proteins.has_key(id_b["id"]):
            nodes.append(tools.createNodeRecord(id_b, locus_b))
            proteins[id_b["id"]] = 1

        # handle edges
        edge = tools.createEdgeRecord(fields)
        if dedupe:
            if not tools.isEdgeDuplicate(edges, edge):
                edges.append(edge)
        else:
            edges.append(edge)

    elements = {"nodes": nodes, "edges": edges}
    return "application/json", json.dumps(elements)
def search(args):
    """
    args contains a dict with one or key:values

    locus is AGI identifier and is mandatory
    """

    locus = args['locus'].upper()

    """
    Make the request to the remote service
    """
    response = tools.do_request(locus)

    """
    Iterate through the results
    Foreach record from the remote service, build the response json
    Print this json to stdout followed by a record separator "---"
    ADAMA takes care of serializing these results
    """
    for result in response.iter_lines():
        fields = result.strip().split('\t')
        record = {
                'locus': locus,
                'class': 'locus_property',
                'source_text_description': 'Molecular Interactions',
                'interaction_record': {
                    'unique_identifier_for_interactor_a': tools.getProteinXref(fields[0]),
                    'unique_identifier_for_interactor_b': tools.getProteinXref(fields[1]),
                    'alt_identifier_for_interactor_a': tools.getValue(fields[2]),
                    'alt_identifier_for_interactor_b': tools.getValue(fields[3]),
                    'aliases_for_a': tools.getValue(fields[4]),
                    'aliases_for_b': tools.getValue(fields[5]),
                    'interaction_detection_methods': tools.getDescriptionValueXref(fields[6]),
                    'first_author': fields[7],
                    'publication_identifier': tools.getValueXref(fields[8]),
                    'ncbi_tax_identifier_for_interactor_a': tools.getDescriptionValueXref(fields[9]),
                    'ncbi_tax_identifier_for_interactor_b': tools.getDescriptionValueXref(fields[10]),
                    'interaction_types': tools.getDescriptionValueXref(fields[11]),
                    'source_databases': tools.getDescriptionValueXref(fields[12]),
                    'interaction_identifiers_in_source': tools.getInteractionXref(fields[13]),
                    'confidence_score': tools.getRawValue(fields[14])
                }
            }
        print json.dumps(record, indent=2)
        print '---'