Skip to content

Commit 837366e

Browse files
authored
Merge pull request #221 from TeresasaZ/dev
publications endpoint and tests
2 parents b09b18a + cb8d72f commit 837366e

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

api/models/eplant2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ class GeneRIFs(db.Model):
3737
gene: db.Mapped[str] = db.mapped_column(db.String(11), nullable=False, primary_key=True)
3838
pubmed: db.Mapped[str] = db.mapped_column(db.String(11), nullable=False, primary_key=True)
3939
RIF: db.Mapped[str] = db.mapped_column(TEXT(), nullable=False, primary_key=True)
40+
41+
42+
class Publications(db.Model):
43+
__bind_key__ = "eplant2"
44+
__tablename__ = "publications"
45+
46+
gene: db.Mapped[str] = db.mapped_column(db.String(12), nullable=False, primary_key=True)
47+
author: db.Mapped[str] = db.mapped_column(db.String(64), nullable=False, primary_key=True)
48+
year: db.Mapped[str] = db.mapped_column(db.String(6), nullable=False, primary_key=True)
49+
journal: db.Mapped[str] = db.mapped_column(db.String(64), nullable=False, primary_key=True)
50+
title: db.Mapped[str] = db.mapped_column(TEXT(), nullable=False, primary_key=True)
51+
pubmed: db.Mapped[str] = db.mapped_column(db.String(16), nullable=False, primary_key=True)

api/resources/gene_information.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from markupsafe import escape
44
from api.models.annotations_lookup import AgiAlias
55
from api.models.eplant2 import Isoforms as EPlant2Isoforms
6+
from api.models.eplant2 import Publications as EPlant2Publications
67
from api.models.eplant_poplar import Isoforms as EPlantPoplarIsoforms
78
from api.models.eplant_tomato import Isoforms as EPlantTomatoIsoforms
89
from api.models.eplant_soybean import Isoforms as EPlantSoybeanIsoforms
@@ -86,6 +87,37 @@ def post(self):
8687
return BARUtils.error_exit("No data for the given species/genes"), 400
8788

8889

90+
@gene_information.route("/gene_publications/<string:gene_id>")
91+
class GenePublications(Resource):
92+
# @gene_information.param("species", _in="path", default="arabidopsis")
93+
@gene_information.param("gene_id", _in="path", default="AT1G01010")
94+
def get(self, gene_id=""):
95+
"""This end point provides publications given a gene ID."""
96+
publications = []
97+
98+
# Escape input
99+
gene_id = escape(gene_id)
100+
101+
# truncate
102+
for i in range(len(gene_id)):
103+
if gene_id[i] == ".":
104+
gene_id = gene_id[0:i]
105+
break
106+
107+
if BARUtils.is_arabidopsis_gene_valid(gene_id):
108+
rows = db.session.execute(db.select(EPlant2Publications).where(EPlant2Publications.gene == gene_id)).scalars().all()
109+
for row in rows:
110+
publications.append({"gene_id": row.gene, "author": row.author, "year": row.year, "journal": row.journal, "title": row.title, "pubmed": row.pubmed})
111+
else:
112+
return BARUtils.error_exit("Invalid gene id"), 400
113+
114+
# Return results if there are data
115+
if len(publications) > 0:
116+
return BARUtils.success_exit(publications)
117+
else:
118+
return BARUtils.error_exit("There are no data found for the given gene")
119+
120+
89121
@gene_information.route("/gene_isoforms/<string:species>/<string:gene_id>")
90122
class GeneIsoforms(Resource):
91123
@gene_information.param("species", _in="path", default="arabidopsis")

config/databases/eplant2.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,43 @@ INSERT INTO `isoforms` VALUES ('AT1G01010','AT1G01010.1'),('AT1G01020','AT1G0102
4747
/*!40000 ALTER TABLE `isoforms` ENABLE KEYS */;
4848
UNLOCK TABLES;
4949

50+
--
51+
-- Table structure for table `publications`
52+
--
53+
54+
CREATE TABLE `publications` (
55+
`gene` varchar(12) CHARACTER SET latin1 NOT NULL,
56+
`author` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
57+
`year` varchar(6) CHARACTER SET latin1 NOT NULL,
58+
`journal` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
59+
`title` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
60+
`pubmed` varchar(16) CHARACTER SET latin1 NOT NULL
61+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
62+
/*!40101 SET character_set_client = @saved_cs_client */;
63+
64+
65+
--
66+
-- Dumping data for table `publications`
67+
--
68+
69+
LOCK TABLES `publications` WRITE;
70+
/*!40000 ALTER TABLE `publications` DISABLE KEYS */;
71+
INSERT INTO `publications` VALUES
72+
('AT1G01010', 'Arabidopsis Interactome Mapping Consortium', '2011', 'Science', 'Evidence for network evolution in an Arabidopsis interactome map.', '21798944'),
73+
('AT1G01010', 'Gaudinier A', '2018', 'Nature', 'Transcriptional regulation of nitrogen-associated metabolism and growth.', '30356219'),
74+
('AT1G01010', 'Riechmann JL', '2000', 'Science', 'Arabidopsis transcription factors: genome-wide comparative analysis among eukaryotes.', '11118137'),
75+
('AT1G01010', 'Theologis A', '2000', 'Nature', 'Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.', '11130712'),
76+
('AT1G01010', 'Trigg SA', '2017', 'Nat. Methods', 'CrY2H-seq: a massively multiplexed assay for deep-coverage interactome mapping.', '28650476'),
77+
('AT1G01020', 'Forés O', '2006', 'Biochim. Biophys. Acta', 'Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.', '16725371'),
78+
('AT1G01020', 'Theologis A', '2000', 'Nature', 'Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.', '11130712'),
79+
('AT4G10090', 'Gaudet P', '2011', 'Brief. Bioinformatics', 'Phylogenetic-based propagation of functional annotations within the Gene Ontology consortium.', '21873635'),
80+
('AT4G10090', 'Leitner J', '2015', 'Cell Rep', 'Meta-regulation of Arabidopsis auxin responses depends on tRNA maturation.', '25892242'),
81+
('AT4G10090', 'Mayer K', '1999', 'Nature', 'Sequence and analysis of chromosome 4 of the plant Arabidopsis thaliana.', '10617198'),
82+
('AT4G10090', 'Nelissen H', '2010', 'Proc. Natl. Acad. Sci. U.S.A.', 'Plant Elongator regulates auxin-related genes during RNA polymerase II transcription elongation.', '20080602'),
83+
('AT4G10090', 'Zhou X', '2009', 'Plant J.', 'Elongator mediates ABA responses, oxidative stress resistance and anthocyanin biosynthesis in Arabidopsis.', '19500300');
84+
/*!40000 ALTER TABLE `publications` ENABLE KEYS */;
85+
UNLOCK TABLES;
86+
5087
--
5188
-- Table structure for table `agi_annotation`
5289
--

tests/resources/test_gene_information.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,151 @@ def test_post_gene_aliases(self):
4343
self.assertEqual(response.status_code, 400)
4444
self.assertEqual(response.json, expected)
4545

46+
def test_get_arabidopsis_gene_publications(self):
47+
"""This tests checks GET request for gene publications Arabidopsis
48+
:return:
49+
"""
50+
# Valid data
51+
response = self.app_client.get("/gene_information/gene_publications/AT1G01020")
52+
expected = {
53+
"wasSuccessful": True,
54+
"data": [
55+
{
56+
"gene_id": "AT1G01020",
57+
"author": "Forés O",
58+
"year": "2006",
59+
"journal": "Biochim. Biophys. Acta",
60+
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
61+
"pubmed": "16725371"
62+
},
63+
{
64+
"gene_id": "AT1G01020",
65+
"author": "Theologis A",
66+
"year": "2000",
67+
"journal": "Nature",
68+
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
69+
"pubmed": "11130712"
70+
}
71+
]
72+
}
73+
self.assertEqual(response.json, expected)
74+
75+
response = self.app_client.get("/gene_information/gene_publications/AT1G01020.")
76+
expected = {
77+
"wasSuccessful": True,
78+
"data": [
79+
{
80+
"gene_id": "AT1G01020",
81+
"author": "Forés O",
82+
"year": "2006",
83+
"journal": "Biochim. Biophys. Acta",
84+
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
85+
"pubmed": "16725371"
86+
},
87+
{
88+
"gene_id": "AT1G01020",
89+
"author": "Theologis A",
90+
"year": "2000",
91+
"journal": "Nature",
92+
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
93+
"pubmed": "11130712"
94+
}
95+
]
96+
}
97+
self.assertEqual(response.json, expected)
98+
99+
response = self.app_client.get("/gene_information/gene_publications/AT1G01020.0")
100+
expected = {
101+
"wasSuccessful": True,
102+
"data": [
103+
{
104+
"gene_id": "AT1G01020",
105+
"author": "Forés O",
106+
"year": "2006",
107+
"journal": "Biochim. Biophys. Acta",
108+
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
109+
"pubmed": "16725371"
110+
},
111+
{
112+
"gene_id": "AT1G01020",
113+
"author": "Theologis A",
114+
"year": "2000",
115+
"journal": "Nature",
116+
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
117+
"pubmed": "11130712"
118+
}
119+
]
120+
}
121+
self.assertEqual(response.json, expected)
122+
123+
response = self.app_client.get("/gene_information/gene_publications/AT1G01020.1")
124+
expected = {
125+
"wasSuccessful": True,
126+
"data": [
127+
{
128+
"gene_id": "AT1G01020",
129+
"author": "Forés O",
130+
"year": "2006",
131+
"journal": "Biochim. Biophys. Acta",
132+
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
133+
"pubmed": "16725371"
134+
},
135+
{
136+
"gene_id": "AT1G01020",
137+
"author": "Theologis A",
138+
"year": "2000",
139+
"journal": "Nature",
140+
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
141+
"pubmed": "11130712"
142+
}
143+
]
144+
}
145+
self.assertEqual(response.json, expected)
146+
147+
response = self.app_client.get("/gene_information/gene_publications/AT1G01020.12345")
148+
expected = {
149+
"wasSuccessful": True,
150+
"data": [
151+
{
152+
"gene_id": "AT1G01020",
153+
"author": "Forés O",
154+
"year": "2006",
155+
"journal": "Biochim. Biophys. Acta",
156+
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
157+
"pubmed": "16725371"
158+
},
159+
{
160+
"gene_id": "AT1G01020",
161+
"author": "Theologis A",
162+
"year": "2000",
163+
"journal": "Nature",
164+
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
165+
"pubmed": "11130712"
166+
}
167+
]
168+
}
169+
self.assertEqual(response.json, expected)
170+
171+
# Data not found, but gene is valid
172+
response = self.app_client.get("/gene_information/gene_publications/AT1G01035")
173+
expected = {
174+
"wasSuccessful": False,
175+
"error": "There are no data found for the given gene",
176+
}
177+
self.assertEqual(response.json, expected)
178+
179+
response = self.app_client.get("/gene_information/gene_publications/AT1G010400")
180+
expected = {
181+
"wasSuccessful": False,
182+
"error": "There are no data found for the given gene",
183+
}
184+
self.assertEqual(response.json, expected)
185+
186+
# Invalid Gene
187+
response = self.app_client.get("/gene_information/gene_publications/001G01030")
188+
expected = {"wasSuccessful": False, "error": "Invalid gene id"}
189+
self.assertEqual(response.json, expected)
190+
46191
def test_get_arabidopsis_gene_isoform(self):
47192
"""This tests checks GET request for gene isoforms Arabidopsis
48193
:return:

0 commit comments

Comments
 (0)