diff --git a/vscode-antimony/src/annotationRecommender.ts b/vscode-antimony/src/annotationRecommender.ts index b6d8aab7e..1acf72f4c 100644 --- a/vscode-antimony/src/annotationRecommender.ts +++ b/vscode-antimony/src/annotationRecommender.ts @@ -91,13 +91,11 @@ export async function singleStepInputRec(context: ExtensionContext, line: number const prefix = annotation.split(':')[0].toLowerCase(); const id = annotation.split(':')[1] var snippetText; - // if (prefix === 'rhea') { - // snippetText = `\n\${1:${initialQuery}} identity "https://www.rhea-db.org/rhea/${annotation}"`; - // } else if (prefix === 'ontology') { - // // snippetText = `\n\${1:${initialQuery}} identity "${entity['iri']}"`; - // } else { + if (prefix === 'rhea') { + snippetText = `\n\${1:${initialQuery}} identity "https://www.rhea-db.org/rhea/${id}"`; + } else { snippetText = `\n\${1:${initialQuery}} identity "http://identifiers.org/${prefix}/${annotation}"`; - // } + } const snippetStr = new vscode.SnippetString(snippetText); const doc = vscode.window.activeTextEditor.document; const pos = doc.lineAt(line).range.end; diff --git a/vscode-antimony/src/server/main.py b/vscode-antimony/src/server/main.py index 25b3a2862..54403be23 100644 --- a/vscode-antimony/src/server/main.py +++ b/vscode-antimony/src/server/main.py @@ -34,7 +34,7 @@ TextDocumentContentChangeEvent, TextDocumentPositionParams, Position) import threading import time -from AMAS import recommender, species_annotation +from AMAS import recommender, species_annotation, reaction_annotation from bioservices import ChEBI # TODO remove this for production @@ -283,31 +283,68 @@ def recommend(ls: LanguageServer, args): 'error': "Did not select a symbol" } symbol = symbols[0] - if symbol.type != SymbolType.Species: + if symbol.type != SymbolType.Species and symbol.type != SymbolType.Reaction: return { - 'error': "Did not select species" + 'error': "Please select species or reaction name" + } + if symbol.type == SymbolType.Species: + recom = recommender.Recommender() + display_name = symbol.display_name + if display_name is not None: + annotations = recom.getSpeciesAnnotation(pred_str=display_name.replace("\"", "")) + else: + annotations = recom.getSpeciesAnnotation(pred_str=symbol.name) + chebi = species_annotation.chebi_low_synonyms + ret = list() + limit = 0 + for annotation in annotations.candidates: + sorted_chebi = sorted(chebi[annotation[0]], key=len) + ret.append({ + 'label': sorted_chebi[0], + 'id': annotation[0] + }) + limit += 1 + if limit >= 10: + break + return { + 'annotations': ret } - recom = recommender.Recommender() - display_name = symbol.display_name - if display_name is not None: - annotations = recom.getSpeciesAnnotation(pred_str=display_name.replace("\"", "")) else: - annotations = recom.getSpeciesAnnotation(pred_str=symbol.name) - chebi = species_annotation.chebi_low_synonyms - ret = list() - limit = 0 - for annotation in annotations.candidates: - sorted_chebi = sorted(chebi[annotation[0]], key=len) - ret.append({ - 'label': sorted_chebi[0], - 'id': annotation[0] - }) - limit += 1 - if limit >= 10: - break - return { - 'annotations': ret - } + reaction = symbol.decl_node + species_list = [] + for reactant in reaction.get_reactants(): + species_list.append(reactant) + for product in reaction.get_products(): + species_list.append(reaction.get_products()) + species_dict = dict() + species_list = [] + for species in species_list: + species_list.append(species.get_name_text()) + species_dict[species.get_name_text()] = species.display_name + reaction_spec = dict() + reaction_spec[reaction.get_name_text()] = species_list + + model_specs = [] + model_specs.append((species_dict, dict())) + model_specs.append((reaction_spec, dict())) + recom = recommender.Recommender(model_specs=model_specs) + annotations = recom.getReactionAnnotation(reaction.get_name_text()) + # rhea = reaction_annotation.ref_rhea_to_chebi + ret = list() + limit = 0 + for annotation in annotations.candidates: + # sorted_rhea = sorted(rhea[annotation[0]], key=len) + ret.append({ + 'label': annotation[0], + 'id': annotation[0] + }) + limit += 1 + if limit >= 10: + break + return { + 'annotations': ret + } + #### Hover for displaying information #### @server.feature(HOVER)