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 '---'