Skip to content

Commit cd938f0

Browse files
authored
Merge pull request #124 from asherpasha/dev
ThaleMine gene information page is added.
2 parents 54b8aaf + 4749c82 commit cd938f0

5 files changed

Lines changed: 140 additions & 2 deletions

File tree

api/resources/thalemine.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,34 @@ def get(self, gene_id=""):
7575
)
7676

7777
return resp.json()
78+
79+
80+
@thalemine.route("/gene_information/<string:gene_id>")
81+
class ThaleMineGeneInformation(Resource):
82+
@thalemine.param("gene_id", _in="path", default="At1g01010")
83+
@cache.cached()
84+
def get(self, gene_id=""):
85+
"""This end point retrieves gene infromation from ThaleMine given an AGI ID"""
86+
gene_id = escape(gene_id)
87+
88+
# Is data valid
89+
if not BARUtils.is_arabidopsis_gene_valid(gene_id):
90+
return BARUtils.error_exit("Invalid gene id"), 400
91+
92+
query = (
93+
'<query name="" model="genomic" view="Gene.primaryIdentifier Gene.name Gene.secondaryIdentifier '
94+
"Gene.briefDescription Gene.symbol Gene.tairAliases Gene.tairComputationalDescription "
95+
'Gene.tairCuratorSummary Gene.tairShortDescription" longDescription="" sortOrder="Gene.briefDescription '
96+
'asc"><constraint path="Gene.primaryIdentifier" op="=" value="{}"/></query> '
97+
)
98+
query = query.format(gene_id)
99+
100+
# Now query the web service
101+
payload = {"format": "json", "query": query}
102+
resp = requests.post(
103+
"https://bar.utoronto.ca/thalemine/service/query/results",
104+
data=payload,
105+
headers=request_headers,
106+
)
107+
108+
return resp.json()

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cffi==1.15.0
77
chardet==4.0.0
88
charset-normalizer==2.0.10
99
click==8.0.3
10-
coverage==6.2
10+
coverage==6.3
1111
cryptography==36.0.1
1212
Deprecated==1.2.13
1313
docopt==0.6.2
@@ -46,7 +46,7 @@ pyrsistent==0.18.1
4646
pytest==6.2.5
4747
python-dateutil==2.8.2
4848
pytz==2021.3
49-
redis==4.1.1
49+
redis==4.1.2
5050
regex==2022.1.18
5151
requests==2.27.1
5252
scour==0.38.2
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"modelName": "genomic",
3+
"columnHeaders": [
4+
"Gene > DB identifier",
5+
"Gene > Name",
6+
"Gene > Secondary Identifier",
7+
"Gene > Brief Description",
8+
"Gene > Symbol",
9+
"Gene > TAIR Aliases",
10+
"Gene > TAIR Computational Description",
11+
"Gene > TAIR Curator Summary",
12+
"Gene > TAIR Short Description"
13+
],
14+
"rootClass": "Gene",
15+
"start": 0,
16+
"views": [
17+
"Gene.primaryIdentifier",
18+
"Gene.name",
19+
"Gene.secondaryIdentifier",
20+
"Gene.briefDescription",
21+
"Gene.symbol",
22+
"Gene.tairAliases",
23+
"Gene.tairComputationalDescription",
24+
"Gene.tairCuratorSummary",
25+
"Gene.tairShortDescription"
26+
],
27+
"results": [
28+
[
29+
"AT1G01010",
30+
"NAC domain containing protein 1",
31+
"locus:2200935",
32+
"NAC domain containing protein 1",
33+
"NAC001",
34+
"ANAC001, NAC001, NTL10",
35+
"NAC domain containing protein 1;(source:Araport11)",
36+
null,
37+
"NAC domain containing protein 1"
38+
]
39+
],
40+
"wasSuccessful": true,
41+
"error": null,
42+
"statusCode": 200
43+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"modelName": "genomic",
3+
"columnHeaders": [
4+
"Gene > DB identifier",
5+
"Gene > Name",
6+
"Gene > Secondary Identifier",
7+
"Gene > Brief Description",
8+
"Gene > Symbol",
9+
"Gene > TAIR Aliases",
10+
"Gene > TAIR Computational Description",
11+
"Gene > TAIR Curator Summary",
12+
"Gene > TAIR Short Description"
13+
],
14+
"rootClass": "Gene",
15+
"start": 0,
16+
"views": [
17+
"Gene.primaryIdentifier",
18+
"Gene.name",
19+
"Gene.secondaryIdentifier",
20+
"Gene.briefDescription",
21+
"Gene.symbol",
22+
"Gene.tairAliases",
23+
"Gene.tairComputationalDescription",
24+
"Gene.tairCuratorSummary",
25+
"Gene.tairShortDescription"
26+
],
27+
"results": [],
28+
"wasSuccessful": true,
29+
"error": null,
30+
"statusCode": 200
31+
}

tests/resources/test_thalemine.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,36 @@ def test_get_thalemine_publications(self):
8585
response = self.app_client.get("/thalemine/publications/At1g0101x")
8686
expected = {"wasSuccessful": False, "error": "Invalid gene id"}
8787
self.assertEqual(response.json, expected)
88+
89+
def test_get_thalemine_gene_information(self):
90+
"""This tests the data returned by the ThaleMine gene information endpoint
91+
:return:
92+
"""
93+
# Valid data
94+
response = self.app_client.get("/thalemine/gene_information/At1g01010")
95+
96+
# Delete query time data. It will always be different
97+
response = response.json
98+
response.pop("executionTime")
99+
100+
# Note: pytest is running from project root. So path is relative to project root
101+
# Also, delete execution time from output before saving.
102+
with open("tests/data/get_thalemine_gene_information_1.json") as json_file:
103+
expected = load(json_file)
104+
self.assertEqual(response, expected)
105+
106+
# Valid but does not exists
107+
response = self.app_client.get("/thalemine/gene_information/At1g01011")
108+
109+
# Again, delete time data.
110+
response = response.json
111+
response.pop("executionTime")
112+
113+
with open("tests/data/get_thalemine_gene_information_2.json") as json_file:
114+
expected = load(json_file)
115+
self.assertEqual(response, expected)
116+
117+
# Invalid gene id
118+
response = self.app_client.get("/thalemine/gene_information/At1g0101x")
119+
expected = {"wasSuccessful": False, "error": "Invalid gene id"}
120+
self.assertEqual(response.json, expected)

0 commit comments

Comments
 (0)