Skip to content

Commit 78071ca

Browse files
authored
Merge pull request #281 from BioAnalyticResource/dev
Updates
2 parents e719beb + d89e2ee commit 78071ca

File tree

6 files changed

+63
-100
lines changed

6 files changed

+63
-100
lines changed

api/models/interactions_vincent_v2.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,34 @@ class TagLookupTable(db.Model):
3636
__tablename__ = "tag_lookup_table"
3737

3838
tag_name: db.Mapped[str] = db.mapped_column(db.String(20), nullable=False, primary_key=True)
39-
tag_group: db.Mapped[str] = db.mapped_column(Enum("Gene", "Experiment", "Condition", "Misc"), nullable=False, primary_key=False)
39+
tag_group: db.Mapped[str] = db.mapped_column(
40+
Enum("Gene", "Experiment", "Condition", "Misc"), nullable=False, primary_key=False
41+
)
4042

4143

4244
class ExternalSource(db.Model):
4345
__bind_key__ = "interactions_vincent_v2"
4446
__tablename__ = "external_source"
4547

4648
source_id: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False, comment="surrogate key", primary_key=True)
47-
source_name: db.Mapped[str] = db.mapped_column(db.String(500), nullable=False, comment="name of the source, can be a pubmed identifier like “PMIDXXXXXXX” or “Asher’s sql dump”", primary_key=False)
48-
comments: db.Mapped[str] = db.mapped_column(TEXT(), nullable=False, comment="Comments regarding the source", primary_key=False)
49-
date_uploaded: db.Mapped[datetime] = db.mapped_column(db.Date(), nullable=False, comment="When it was uploaded to database", primary_key=False)
50-
url: db.Mapped[str] = db.mapped_column(db.String(350), nullable=True, comment="URL if available to paper/source (does not have to be a DOI, can be a link to a databases’ source)", primary_key=False)
49+
source_name: db.Mapped[str] = db.mapped_column(
50+
db.String(500),
51+
nullable=False,
52+
comment="name of the source, can be a pubmed identifier like “PMIDXXXXXXX” or “Asher’s sql dump”",
53+
primary_key=False,
54+
)
55+
comments: db.Mapped[str] = db.mapped_column(
56+
TEXT(), nullable=False, comment="Comments regarding the source", primary_key=False
57+
)
58+
date_uploaded: db.Mapped[datetime] = db.mapped_column(
59+
db.Date(), nullable=False, comment="When it was uploaded to database", primary_key=False
60+
)
61+
url: db.Mapped[str] = db.mapped_column(
62+
db.String(350),
63+
nullable=True,
64+
comment="URL if available to paper/source (does not have to be a DOI, can be a link to a databases’ source)",
65+
primary_key=False,
66+
)
5167
image_url: db.Mapped[str] = db.mapped_column(db.String(300), nullable=True, primary_key=False)
5268
grn_title: db.Mapped[str] = db.mapped_column(db.String(200), nullable=True, primary_key=False)
5369
cyjs_layout: db.Mapped[str] = db.mapped_column(db.String(1000), nullable=True, primary_key=False)
@@ -59,12 +75,8 @@ class SourceTagJoinTable(db.Model):
5975
__tablename__ = "source_tag_join_table"
6076

6177
source_id: db.Mapped[int] = db.mapped_column(
62-
db.Integer(),
63-
db.ForeignKey("external_source.source_id"),
64-
primary_key=True
78+
db.Integer(), db.ForeignKey("external_source.source_id"), primary_key=True
6579
)
6680
tag_name: db.Mapped[str] = db.mapped_column(
67-
db.String(20),
68-
db.ForeignKey("tag_lookup_table.tag_name"),
69-
primary_key=True
81+
db.String(20), db.ForeignKey("tag_lookup_table.tag_name"), primary_key=True
7082
)

api/resources/efp_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get(self, species=""):
153153

154154
# This will only work on the BAR
155155
if os.environ.get("BAR"):
156-
if species in ["arabidopsis", "arachis", "cannabis", "maize", "rice", "sorghum", "soybean"]:
156+
if species in ["arabidopsis", "arachis", "cannabis", "grape", "maize", "rice", "sorghum", "soybean"]:
157157
efp_base_path = "/var/www/html/efp_" + species + "/data"
158158
else:
159159
return BARUtils.error_exit("Invalid species.")

api/resources/interactions.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,12 @@ def get(self, paper_id=""):
314314
try:
315315
interactions_database = PostInteractions
316316
itnsjoin_database = PostInteractionsSourceMiJoin
317-
query = db.select(
318-
interactions_database,
319-
itnsjoin_database
320-
).select_from(interactions_database).join(
321-
itnsjoin_database,
322-
interactions_database.interaction_id == itnsjoin_database.interaction_id
323-
).where(itnsjoin_database.source_id == paper_id)
317+
query = (
318+
db.select(interactions_database, itnsjoin_database)
319+
.select_from(interactions_database)
320+
.join(itnsjoin_database, interactions_database.interaction_id == itnsjoin_database.interaction_id)
321+
.where(itnsjoin_database.source_id == paper_id)
322+
)
324323
rows = db.session.execute(query).all()
325324
for i, m in rows:
326325
result.append(
@@ -382,9 +381,7 @@ def get(self, tag=""):
382381
# Step 1: Get source_ids that contain the searched tag
383382

384383
matching_source_ids = []
385-
query_source = db.select(src_tag_join_database.source_id).where(
386-
src_tag_join_database.tag_name == tag
387-
)
384+
query_source = db.select(src_tag_join_database.source_id).where(src_tag_join_database.tag_name == tag)
388385
rows_source = db.session.execute(query_source).all()
389386
matching_source_ids = [row[0] for row in rows_source]
390387

@@ -393,11 +390,7 @@ def get(self, tag=""):
393390

394391
# Step 2: Get all tags for those sources
395392
query = (
396-
db.select(
397-
ext_src_database,
398-
src_tag_join_database.tag_name,
399-
tag_lkup_database.tag_group
400-
)
393+
db.select(ext_src_database, src_tag_join_database.tag_name, tag_lkup_database.tag_group)
401394
.join(src_tag_join_database, ext_src_database.source_id == src_tag_join_database.source_id)
402395
.join(tag_lkup_database, src_tag_join_database.tag_name == tag_lkup_database.tag_name)
403396
.where(ext_src_database.source_id.in_(matching_source_ids)) # Keep all tags for matched sources
@@ -425,7 +418,7 @@ def get(self, tag=""):
425418
"image_url": ex.image_url,
426419
"grn_title": ex.grn_title,
427420
"cyjs_layout": ex.cyjs_layout,
428-
"tag": "|".join(src_tag_match[ex.source_id])
421+
"tag": "|".join(src_tag_match[ex.source_id]),
429422
}
430423
result.append(one_source[source_id])
431424

@@ -494,7 +487,7 @@ def get(self, number=""):
494487
"url": row.url,
495488
"image_url": row.image_url,
496489
"grn_title": row.grn_title,
497-
"cyjs_layout": row.cyjs_layout
490+
"cyjs_layout": row.cyjs_layout,
498491
}
499492
)
500493

@@ -530,7 +523,7 @@ def get(self, stringAGI=""):
530523
es.comments,
531524
es.cyjs_layout,
532525
stjt.tag_name,
533-
tlt.tag_group
526+
tlt.tag_group,
534527
)
535528
.join(i_s_mi_join_table, i_s_mi_join_table.source_id == es.source_id)
536529
.join(i, i.interaction_id == i_s_mi_join_table.interaction_id)
@@ -557,20 +550,14 @@ def get(self, stringAGI=""):
557550
"source_name": row.source_name,
558551
"comments": row.comments,
559552
"cyjs_layout": row.cyjs_layout,
560-
"tags": []
553+
"tags": [],
561554
}
562555

563556
tag_entry = f"{row.tag_name}:{row.tag_group}"
564557
if tag_entry not in result_dict[source_id]["tags"]: # DISTINCT
565558
result_dict[source_id]["tags"].append(tag_entry)
566559

567-
result = [
568-
{
569-
**data,
570-
"tags": "|".join(data["tags"]) # overwrites tags
571-
}
572-
for data in result_dict.values()
573-
]
560+
result = [{**data, "tags": "|".join(data["tags"])} for data in result_dict.values()] # overwrites tags
574561

575562
if len(result) == 0:
576563
return BARUtils.error_exit("Invalid AGI"), 400
@@ -603,7 +590,7 @@ def get(self, AGI_1="", AGI_2=""):
603590
es.comments,
604591
es.cyjs_layout,
605592
stjt.tag_name,
606-
tlt.tag_group
593+
tlt.tag_group,
607594
)
608595
.join(i_s_mi_join_table, i_s_mi_join_table.source_id == es.source_id)
609596
.join(i, i.interaction_id == i_s_mi_join_table.interaction_id)
@@ -630,18 +617,14 @@ def get(self, AGI_1="", AGI_2=""):
630617
"source_name": row.source_name,
631618
"comments": row.comments,
632619
"cyjs_layout": row.cyjs_layout,
633-
"tags": set()
620+
"tags": set(),
634621
}
635622

636-
result_dict[source_id]["tags"].add(f"{row.tag_name}:{row.tag_group}") # ensures uniqueness automatically with `set`
623+
result_dict[source_id]["tags"].add(
624+
f"{row.tag_name}:{row.tag_group}"
625+
) # ensures uniqueness automatically with `set`
637626

638-
result = [
639-
{
640-
**data,
641-
"tags": "|".join(sorted(data["tags"]))
642-
}
643-
for data in result_dict.values()
644-
]
627+
result = [{**data, "tags": "|".join(sorted(data["tags"]))} for data in result_dict.values()]
645628

646629
if len(result) == 0:
647630
return BARUtils.error_exit("Both AGI invalid"), 400
@@ -664,11 +647,7 @@ def get(self):
664647
stjt = SourceTagJoinTable
665648
tlt = TagLookupTable
666649
query = (
667-
db.select(
668-
es,
669-
stjt.tag_name,
670-
tlt.tag_group
671-
)
650+
db.select(es, stjt.tag_name, tlt.tag_group)
672651
.join(stjt, es.source_id == stjt.source_id)
673652
.join(tlt, stjt.tag_name == tlt.tag_name)
674653
)
@@ -695,7 +674,7 @@ def get(self):
695674
"image_url": ex.image_url,
696675
"grn_title": ex.grn_title,
697676
"cyjs_layout": ex.cyjs_layout,
698-
"tag": "|".join(src_tag_match[ex.source_id])
677+
"tag": "|".join(src_tag_match[ex.source_id]),
699678
}
700679
result.append(one_source[source_id])
701680

api/utils/mfinder_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def get_gene_id_hash_map(input):
150150
if item[1] not in hash_of_ids.values():
151151
hash_of_ids[iter] = item[1]
152152
iter += 1
153-
return_str += f"{MfinderUtils.find_key(hash_of_ids, item[0])} {MfinderUtils.find_key(hash_of_ids, item[1])} 1\n"
153+
return_str += (
154+
f"{MfinderUtils.find_key(hash_of_ids, item[0])} {MfinderUtils.find_key(hash_of_ids, item[1])} 1\n"
155+
)
154156

155157
return hash_of_ids, return_str
156158

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jsonschema==4.25.1
2727
jsonschema-specifications==2025.9.1
2828
limits==5.5.0
2929
markdown-it-py==4.0.0
30-
MarkupSafe==3.0.2
30+
MarkupSafe==3.0.3
3131
marshmallow==4.0.1
3232
mccabe==0.7.0
3333
mdurl==0.1.2

tests/resources/test_interactions.py

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,20 @@ def test_single_itrn(self):
210210
"pearson_correlation_coeff": None,
211211
"entity_1": "AT4G25470",
212212
"entity_2": "AT5G50720",
213-
"interaction_type_id": 1
213+
"interaction_type_id": 1,
214214
}
215-
]
215+
],
216216
}
217217
self.assertEqual(response.json, expected)
218218

219219
# Input not a number
220220
response = self.app_client.get("/interactions/single_interaction/g")
221-
expected = {
222-
"wasSuccessful": False,
223-
"error": "ID given was not a number!"
224-
}
221+
expected = {"wasSuccessful": False, "error": "ID given was not a number!"}
225222
self.assertEqual(response.json, expected)
226223

227224
# Not a valid interaction ID
228225
response = self.app_client.get("/interactions/single_interaction/3")
229-
expected = {
230-
"wasSuccessful": False,
231-
"error": "Invalid interaction ID"
232-
}
226+
expected = {"wasSuccessful": False, "error": "Invalid interaction ID"}
233227
self.assertEqual(response.json, expected)
234228

235229
def test_itrn_by_ref(self):
@@ -245,18 +239,12 @@ def test_itrn_by_ref(self):
245239

246240
# Input not a number
247241
response = self.app_client.get("/interactions/interactions_by_ref/k")
248-
expected = {
249-
"wasSuccessful": False,
250-
"error": "ID given was not a number!"
251-
}
242+
expected = {"wasSuccessful": False, "error": "ID given was not a number!"}
252243
self.assertEqual(response.json, expected)
253244

254245
# Not a valid paper ID
255246
response = self.app_client.get("/interactions/interactions_by_ref/1")
256-
expected = {
257-
"wasSuccessful": False,
258-
"error": "Invalid paper ID"
259-
}
247+
expected = {"wasSuccessful": False, "error": "Invalid paper ID"}
260248
self.assertEqual(response.json, expected)
261249

262250
def test_all_tags(self):
@@ -283,10 +271,7 @@ def test_search_by_tag(self):
283271

284272
# Invalid tag name
285273
response = self.app_client.get("/interactions/search_by_tag/p")
286-
expected = {
287-
"wasSuccessful": False,
288-
"error": "Invalid tag name"
289-
}
274+
expected = {"wasSuccessful": False, "error": "Invalid tag name"}
290275
self.assertEqual(response.json, expected)
291276

292277
def test_get_all_papers(self):
@@ -318,34 +303,25 @@ def test_get_paper(self):
318303
"url": "www.ncbi.nlm.nih.gov/pubmed/25736223",
319304
"image_url": "https://bar.utoronto.ca/GRN_Images/25736223%232.jpg",
320305
"grn_title": "Park et al.(The Plant Journal, 2015) CBF Regulon Low Temperature Network",
321-
"cyjs_layout": "{\"name\": \"breadthfirst\", \"animate\" : \"true\"}"
306+
"cyjs_layout": '{"name": "breadthfirst", "animate" : "true"}',
322307
}
323-
]
308+
],
324309
}
325310
self.assertEqual(response.json, expected)
326311

327312
# Input not an integer, a string
328313
response = self.app_client.get("/interactions/get_paper/p")
329-
expected = {
330-
"wasSuccessful": False,
331-
"error": "Input number is not an integer!"
332-
}
314+
expected = {"wasSuccessful": False, "error": "Input number is not an integer!"}
333315
self.assertEqual(response.json, expected)
334316

335317
# Input not an integer, a float
336318
response = self.app_client.get("/interactions/get_paper/2.2")
337-
expected = {
338-
"wasSuccessful": False,
339-
"error": "Input number is not an integer!"
340-
}
319+
expected = {"wasSuccessful": False, "error": "Input number is not an integer!"}
341320
self.assertEqual(response.json, expected)
342321

343322
# Invalid source ID
344323
response = self.app_client.get("/interactions/get_paper/3")
345-
expected = {
346-
"wasSuccessful": False,
347-
"error": "Invalid source ID"
348-
}
324+
expected = {"wasSuccessful": False, "error": "Invalid source ID"}
349325
self.assertEqual(response.json, expected)
350326

351327
def test_get_paper_by_agi(self):
@@ -361,10 +337,7 @@ def test_get_paper_by_agi(self):
361337

362338
# Invalid AGI
363339
response = self.app_client.get("/interactions/get_paper_by_agi/AT1G00000")
364-
expected = {
365-
"wasSuccessful": False,
366-
"error": "Invalid AGI"
367-
}
340+
expected = {"wasSuccessful": False, "error": "Invalid AGI"}
368341
self.assertEqual(response.json, expected)
369342

370343
def test_get_paper_by_agi_pair(self):
@@ -380,10 +353,7 @@ def test_get_paper_by_agi_pair(self):
380353

381354
# Both AGI invalid
382355
response = self.app_client.get("/interactions/get_paper_by_agi_pair/AT1G00000/AT2G00000")
383-
expected = {
384-
"wasSuccessful": False,
385-
"error": "Both AGI invalid"
386-
}
356+
expected = {"wasSuccessful": False, "error": "Both AGI invalid"}
387357
self.assertEqual(response.json, expected)
388358

389359
def test_get_all_grns(self):

0 commit comments

Comments
 (0)