Skip to content

Commit cb8d72f

Browse files
committed
added publications endpoint in gene_information
added publications table in eplant2.sql added class Publications in eplant2.py added tests for publications endpoint in test_gene_information
1 parent a7d7db5 commit cb8d72f

4 files changed

Lines changed: 226 additions & 0 deletions

File tree

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
@@ -70,6 +71,37 @@ def get(self, species="", gene_id=""):
7071
return BARUtils.error_exit("There are no data found for the given gene")
7172

7273

74+
@gene_information.route("/gene_publications/<string:gene_id>")
75+
class GenePublications(Resource):
76+
# @gene_information.param("species", _in="path", default="arabidopsis")
77+
@gene_information.param("gene_id", _in="path", default="AT1G01010")
78+
def get(self, gene_id=""):
79+
"""This end point provides publications given a gene ID."""
80+
publications = []
81+
82+
# Escape input
83+
gene_id = escape(gene_id)
84+
85+
# truncate
86+
for i in range(len(gene_id)):
87+
if gene_id[i] == ".":
88+
gene_id = gene_id[0:i]
89+
break
90+
91+
if BARUtils.is_arabidopsis_gene_valid(gene_id):
92+
rows = db.session.execute(db.select(EPlant2Publications).where(EPlant2Publications.gene == gene_id)).scalars().all()
93+
for row in rows:
94+
publications.append({"gene_id": row.gene, "author": row.author, "year": row.year, "journal": row.journal, "title": row.title, "pubmed": row.pubmed})
95+
else:
96+
return BARUtils.error_exit("Invalid gene id"), 400
97+
98+
# Return results if there are data
99+
if len(publications) > 0:
100+
return BARUtils.success_exit(publications)
101+
else:
102+
return BARUtils.error_exit("There are no data found for the given gene")
103+
104+
73105
@gene_information.route("/gene_isoforms/<string:species>/<string:gene_id>")
74106
class GeneIsoforms(Resource):
75107
@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
@@ -41,6 +41,151 @@ def test_get_arabidopsis_gene_alias(self):
4141
expected = {"wasSuccessful": False, "error": "No data for the given species"}
4242
self.assertEqual(response.json, expected)
4343

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

0 commit comments

Comments
 (0)