Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reaction recommender #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions vscode-antimony/src/annotationRecommender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
83 changes: 60 additions & 23 deletions vscode-antimony/src/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down