Skip to content

Commit a2c3ff8

Browse files
orphanet code support
1 parent 36d4603 commit a2c3ff8

File tree

5 files changed

+149
-14
lines changed

5 files changed

+149
-14
lines changed

app/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from flask_migrate import Migrate
1212
from flask_session import Session
1313
from flask_sqlalchemy import SQLAlchemy
14+
from flask_cors import CORS
1415
from sqlalchemy import MetaData
1516

1617
convention = {
@@ -30,6 +31,7 @@
3031
login.login_message_category = "info"
3132
mail = Mail()
3233
session = Session()
34+
cors = CORS()
3335

3436

3537
def create_app(config_class=Config):
@@ -53,6 +55,7 @@ def create_app(config_class=Config):
5355
login.init_app(app)
5456
mail.init_app(app)
5557
session.init_app(app)
58+
cors.init_app(app)
5659
register_dashapps(app)
5760

5861
# Configuration of our various flask-blueprint folders

app/historeport/forms.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,11 @@ class ReportForm(FlaskForm):
104104
},
105105
)
106106

107-
gene_diag = SelectField(
107+
gene_diag = StringField(
108108
"Diagnosed Gene",
109-
validators=[DataRequired()],
110-
choices=Common.create_list(os.path.join("config", "config_gene.txt")),
111109
render_kw={
112110
"placeholder": "Diagnosed Gene",
113-
"class": "form-control custom-select",
111+
"class": "form-control",
114112
},
115113
)
116114
ontology_tree = JSONField("Json Ontology Tree", render_kw={"type": "hidden"})
@@ -124,12 +122,11 @@ class ReportForm(FlaskForm):
124122
"placeholder": "Commentary",
125123
},
126124
)
127-
conclusion = SelectField(
125+
conclusion = StringField(
128126
"Final Diagnosis",
129-
choices=Common.create_diag_list(os.path.join("config", "diagnostic.tsv")),
130127
render_kw={
131128
"placeholder": "Final Diagnosis",
132-
"class": "form-control custom-select",
129+
"class": "form-control",
133130
},
134131
)
135132
# submit = SubmitField(

app/historeport/static/historeport.js

Lines changed: 122 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var input7 = document.querySelector("input[id=correlates_with]");
1818
var input7_tag = new Tagify(input7);
1919

2020
// HPO Terms Field Handler
21-
2221
// Load previous terms annotated to the report from DB as a list (whitelist for tagify)
2322
var term_previous_list = [];
2423
if ($("input[id=pheno_terms]").val() !== "") {
@@ -35,20 +34,18 @@ var pheno_terms = document.querySelector("input[id=pheno_terms]");
3534
var pheno_terms_tag = new Tagify(pheno_terms, {
3635
enforceWhitelist: true,
3736
whitelist: term_previous_list,
38-
dropdown: {
39-
enabled: 0,
40-
},
4137
}); // for aborting the call
4238

43-
pheno_terms_tag.on("input", onInput);
39+
pheno_terms_tag.on("input", onInputHPO);
4440

4541
// Tagify AJAX Function to get a list of HPO terms
4642
var delayTimer;
47-
function onInput(e) {
43+
function onInputHPO(e) {
4844
pheno_terms_tag.whitelist = null; // reset the whitelist
4945
// show loading animation and hide the suggestions dropdown
5046
pheno_terms_tag.loading(true).dropdown.hide();
5147
clearTimeout(delayTimer);
48+
5249
delayTimer = setTimeout(function () {
5350
var value = e.detail.value;
5451
fetch(
@@ -71,6 +68,125 @@ function onInput(e) {
7168
}, 700);
7269
}
7370

71+
// HNC Genes Names Field Handler
72+
// Tagify Field handler with whitelist and HPO ajax
73+
var previous_gene = $("input[id=gene_diag]").val();
74+
var previous_gene_list = [];
75+
if ($("input[id=gene_diag]").val() !== "") {
76+
var previous_gene_json = JSON.parse($("input[id=gene_diag]").val());
77+
var previous_gene_list = [];
78+
79+
for (var i = 0; i < previous_gene_json.length; i++) {
80+
previous_gene_list.push(previous_gene_json[i]["value"]);
81+
}
82+
}
83+
84+
var gene_diag_tag = new Tagify(gene_diag, {
85+
enforceWhitelist: true,
86+
whitelist: previous_gene_list,
87+
mode: "select",
88+
});
89+
90+
gene_diag_tag.on("input", onInputGene);
91+
92+
// Tagify AJAX Function to get a list of HPO terms
93+
var delayTimer;
94+
function onInputGene(e) {
95+
gene_diag_tag.whitelist = null; // reset the whitelist
96+
// show loading animation and hide the suggestions dropdown
97+
gene_diag_tag.loading(true).dropdown.hide();
98+
clearTimeout(delayTimer);
99+
var myHeaders = new Headers({
100+
"content-type": "application/json",
101+
"Access-Control-Allow-Origin": "*",
102+
});
103+
var options = {
104+
method: "GET",
105+
headers: myHeaders,
106+
mode: "cors",
107+
};
108+
delayTimer = setTimeout(function () {
109+
var value = e.detail.value;
110+
fetch(
111+
"https://rest.genenames.org/search/symbol/" +
112+
value +
113+
"*+AND+status:Approved",
114+
options
115+
)
116+
.then((RES) => RES.json())
117+
.then(function (newWhitelist) {
118+
var terms_list = [];
119+
for (var i = 0; i < 5; i++) {
120+
terms_list.push(
121+
newWhitelist.terms[i]["id"] + " " + newWhitelist.terms[i]["name"]
122+
);
123+
}
124+
gene_diag_tag.whitelist = terms_list;
125+
gene_diag_tag.loading(false);
126+
gene_diag_tag.dropdown.show(); // render the suggestions dropdown
127+
});
128+
}, 700);
129+
}
130+
131+
// Orphanet Disease Names Field Handler
132+
// Tagify Field handler with whitelist and Orphanet ajax
133+
var previous_conclusion = $("input[id=conclusion]").val();
134+
var previous_conclusion_list = [];
135+
if ($("input[id=conclusion]").val() !== "") {
136+
var previous_conclusion_json = JSON.parse($("input[id=conclusion]").val());
137+
var previous_conclusion_list = [];
138+
139+
for (var i = 0; i < previous_conclusion_json.length; i++) {
140+
previous_conclusion_list.push(previous_conclusion_json[i]["value"]);
141+
}
142+
}
143+
var conclusion = document.querySelector("input[id=conclusion]");
144+
var conclusion_tag = new Tagify(conclusion, {
145+
enforceWhitelist: true,
146+
whitelist: previous_conclusion_list,
147+
mode: "select",
148+
});
149+
150+
conclusion_tag.on("input", onInputConclusion);
151+
152+
// Tagify AJAX Function to get a list of Orphanet names
153+
var myHeaders_orpha = new Headers({
154+
apiKey: "ehroes",
155+
});
156+
var options_orpha = {
157+
headers: myHeaders_orpha,
158+
};
159+
160+
var delayTimer;
161+
function onInputConclusion(e) {
162+
conclusion_tag.whitelist = null; // reset the whitelist
163+
// show loading animation and hide the suggestions dropdown
164+
conclusion_tag.loading(true).dropdown.hide();
165+
clearTimeout(delayTimer);
166+
delayTimer = setTimeout(function () {
167+
var value = e.detail.value;
168+
169+
fetch(
170+
"https://api.orphacode.org/EN/ClinicalEntity/ApproximateName/" + value,
171+
options_orpha
172+
)
173+
.then((RES) => RES.json())
174+
.then(function (newWhitelist) {
175+
var terms_list = [];
176+
for (var i = 0; i < newWhitelist.length; i++) {
177+
terms_list.push(
178+
newWhitelist[i]["ORPHAcode"] +
179+
" " +
180+
newWhitelist[i]["Preferred term"]
181+
);
182+
}
183+
conclusion_tag.whitelist = terms_list;
184+
conclusion_tag.loading(false);
185+
conclusion_tag.dropdown.show(); // render the suggestions dropdown
186+
});
187+
}, 700);
188+
}
189+
74190
// Get the JSON of the JSTree (stored in hidden form input) as a variable.
75191
var json_tree = $("input[id=ontology_tree]").val();
76192

poetry.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ python-Levenshtein = "^0.12.2"
4343
PyJWT = "^2.3.0"
4444
en_core_web_sm = { url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.2.0/en_core_web_sm-3.2.0-py3-none-any.whl" }
4545
fr_core_news_sm = { url = "https://github.com/explosion/spacy-models/releases/download/fr_core_news_sm-3.2.0/fr_core_news_sm-3.2.0-py3-none-any.whl" }
46+
Flask-Cors = "^3.0.10"
4647

4748
[tool.poetry.dev-dependencies]
4849
black = {extras = ["jupyter"], version = "*"}

0 commit comments

Comments
 (0)