Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publications endpoint and tests #221

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/models/eplant2.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ class GeneRIFs(db.Model):
gene: db.Mapped[str] = db.mapped_column(db.String(11), nullable=False, primary_key=True)
pubmed: db.Mapped[str] = db.mapped_column(db.String(11), nullable=False, primary_key=True)
RIF: db.Mapped[str] = db.mapped_column(TEXT(), nullable=False, primary_key=True)


class Publications(db.Model):
__bind_key__ = "eplant2"
__tablename__ = "publications"

gene: db.Mapped[str] = db.mapped_column(db.String(12), nullable=False, primary_key=True)
author: db.Mapped[str] = db.mapped_column(db.String(64), nullable=False, primary_key=True)
year: db.Mapped[str] = db.mapped_column(db.String(6), nullable=False, primary_key=True)
journal: db.Mapped[str] = db.mapped_column(db.String(64), nullable=False, primary_key=True)
title: db.Mapped[str] = db.mapped_column(TEXT(), nullable=False, primary_key=True)
pubmed: db.Mapped[str] = db.mapped_column(db.String(16), nullable=False, primary_key=True)
32 changes: 32 additions & 0 deletions api/resources/gene_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from markupsafe import escape
from api.models.annotations_lookup import AgiAlias
from api.models.eplant2 import Isoforms as EPlant2Isoforms
from api.models.eplant2 import Publications as EPlant2Publications
from api.models.eplant_poplar import Isoforms as EPlantPoplarIsoforms
from api.models.eplant_tomato import Isoforms as EPlantTomatoIsoforms
from api.models.eplant_soybean import Isoforms as EPlantSoybeanIsoforms
Expand Down Expand Up @@ -70,6 +71,37 @@ def get(self, species="", gene_id=""):
return BARUtils.error_exit("There are no data found for the given gene")


@gene_information.route("/gene_publications/<string:gene_id>")
class GenePublications(Resource):
# @gene_information.param("species", _in="path", default="arabidopsis")
@gene_information.param("gene_id", _in="path", default="AT1G01010")
def get(self, gene_id=""):
"""This end point provides publications given a gene ID."""
publications = []

# Escape input
gene_id = escape(gene_id)

# truncate
for i in range(len(gene_id)):
if gene_id[i] == ".":
gene_id = gene_id[0:i]
break

if BARUtils.is_arabidopsis_gene_valid(gene_id):
rows = db.session.execute(db.select(EPlant2Publications).where(EPlant2Publications.gene == gene_id)).scalars().all()
for row in rows:
publications.append({"gene_id": row.gene, "author": row.author, "year": row.year, "journal": row.journal, "title": row.title, "pubmed": row.pubmed})
else:
return BARUtils.error_exit("Invalid gene id"), 400

# Return results if there are data
if len(publications) > 0:
return BARUtils.success_exit(publications)
else:
return BARUtils.error_exit("There are no data found for the given gene")


@gene_information.route("/gene_isoforms/<string:species>/<string:gene_id>")
class GeneIsoforms(Resource):
@gene_information.param("species", _in="path", default="arabidopsis")
Expand Down
37 changes: 37 additions & 0 deletions config/databases/eplant2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,43 @@ INSERT INTO `isoforms` VALUES ('AT1G01010','AT1G01010.1'),('AT1G01020','AT1G0102
/*!40000 ALTER TABLE `isoforms` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `publications`
--

CREATE TABLE `publications` (
`gene` varchar(12) CHARACTER SET latin1 NOT NULL,
`author` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`year` varchar(6) CHARACTER SET latin1 NOT NULL,
`journal` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`title` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`pubmed` varchar(16) CHARACTER SET latin1 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;


--
-- Dumping data for table `publications`
--

LOCK TABLES `publications` WRITE;
/*!40000 ALTER TABLE `publications` DISABLE KEYS */;
INSERT INTO `publications` VALUES
('AT1G01010', 'Arabidopsis Interactome Mapping Consortium', '2011', 'Science', 'Evidence for network evolution in an Arabidopsis interactome map.', '21798944'),
('AT1G01010', 'Gaudinier A', '2018', 'Nature', 'Transcriptional regulation of nitrogen-associated metabolism and growth.', '30356219'),
('AT1G01010', 'Riechmann JL', '2000', 'Science', 'Arabidopsis transcription factors: genome-wide comparative analysis among eukaryotes.', '11118137'),
('AT1G01010', 'Theologis A', '2000', 'Nature', 'Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.', '11130712'),
('AT1G01010', 'Trigg SA', '2017', 'Nat. Methods', 'CrY2H-seq: a massively multiplexed assay for deep-coverage interactome mapping.', '28650476'),
('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'),
('AT1G01020', 'Theologis A', '2000', 'Nature', 'Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.', '11130712'),
('AT4G10090', 'Gaudet P', '2011', 'Brief. Bioinformatics', 'Phylogenetic-based propagation of functional annotations within the Gene Ontology consortium.', '21873635'),
('AT4G10090', 'Leitner J', '2015', 'Cell Rep', 'Meta-regulation of Arabidopsis auxin responses depends on tRNA maturation.', '25892242'),
('AT4G10090', 'Mayer K', '1999', 'Nature', 'Sequence and analysis of chromosome 4 of the plant Arabidopsis thaliana.', '10617198'),
('AT4G10090', 'Nelissen H', '2010', 'Proc. Natl. Acad. Sci. U.S.A.', 'Plant Elongator regulates auxin-related genes during RNA polymerase II transcription elongation.', '20080602'),
('AT4G10090', 'Zhou X', '2009', 'Plant J.', 'Elongator mediates ABA responses, oxidative stress resistance and anthocyanin biosynthesis in Arabidopsis.', '19500300');
/*!40000 ALTER TABLE `publications` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `agi_annotation`
--
Expand Down
145 changes: 145 additions & 0 deletions tests/resources/test_gene_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,151 @@ def test_get_arabidopsis_gene_alias(self):
expected = {"wasSuccessful": False, "error": "No data for the given species"}
self.assertEqual(response.json, expected)

def test_get_arabidopsis_gene_publications(self):
"""This tests checks GET request for gene publications Arabidopsis
:return:
"""
# Valid data
response = self.app_client.get("/gene_information/gene_publications/AT1G01020")
expected = {
"wasSuccessful": True,
"data": [
{
"gene_id": "AT1G01020",
"author": "Forés O",
"year": "2006",
"journal": "Biochim. Biophys. Acta",
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
"pubmed": "16725371"
},
{
"gene_id": "AT1G01020",
"author": "Theologis A",
"year": "2000",
"journal": "Nature",
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
"pubmed": "11130712"
}
]
}
self.assertEqual(response.json, expected)

response = self.app_client.get("/gene_information/gene_publications/AT1G01020.")
expected = {
"wasSuccessful": True,
"data": [
{
"gene_id": "AT1G01020",
"author": "Forés O",
"year": "2006",
"journal": "Biochim. Biophys. Acta",
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
"pubmed": "16725371"
},
{
"gene_id": "AT1G01020",
"author": "Theologis A",
"year": "2000",
"journal": "Nature",
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
"pubmed": "11130712"
}
]
}
self.assertEqual(response.json, expected)

response = self.app_client.get("/gene_information/gene_publications/AT1G01020.0")
expected = {
"wasSuccessful": True,
"data": [
{
"gene_id": "AT1G01020",
"author": "Forés O",
"year": "2006",
"journal": "Biochim. Biophys. Acta",
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
"pubmed": "16725371"
},
{
"gene_id": "AT1G01020",
"author": "Theologis A",
"year": "2000",
"journal": "Nature",
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
"pubmed": "11130712"
}
]
}
self.assertEqual(response.json, expected)

response = self.app_client.get("/gene_information/gene_publications/AT1G01020.1")
expected = {
"wasSuccessful": True,
"data": [
{
"gene_id": "AT1G01020",
"author": "Forés O",
"year": "2006",
"journal": "Biochim. Biophys. Acta",
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
"pubmed": "16725371"
},
{
"gene_id": "AT1G01020",
"author": "Theologis A",
"year": "2000",
"journal": "Nature",
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
"pubmed": "11130712"
}
]
}
self.assertEqual(response.json, expected)

response = self.app_client.get("/gene_information/gene_publications/AT1G01020.12345")
expected = {
"wasSuccessful": True,
"data": [
{
"gene_id": "AT1G01020",
"author": "Forés O",
"year": "2006",
"journal": "Biochim. Biophys. Acta",
"title": "Arabidopsis thaliana expresses two functional isoforms of Arvp, a protein involved in the regulation of cellular lipid homeostasis.",
"pubmed": "16725371"
},
{
"gene_id": "AT1G01020",
"author": "Theologis A",
"year": "2000",
"journal": "Nature",
"title": "Sequence and analysis of chromosome 1 of the plant Arabidopsis thaliana.",
"pubmed": "11130712"
}
]
}
self.assertEqual(response.json, expected)

# Data not found, but gene is valid
response = self.app_client.get("/gene_information/gene_publications/AT1G01035")
expected = {
"wasSuccessful": False,
"error": "There are no data found for the given gene",
}
self.assertEqual(response.json, expected)

response = self.app_client.get("/gene_information/gene_publications/AT1G010400")
expected = {
"wasSuccessful": False,
"error": "There are no data found for the given gene",
}
self.assertEqual(response.json, expected)

# Invalid Gene
response = self.app_client.get("/gene_information/gene_publications/001G01030")
expected = {"wasSuccessful": False, "error": "Invalid gene id"}
self.assertEqual(response.json, expected)

def test_get_arabidopsis_gene_isoform(self):
"""This tests checks GET request for gene isoforms Arabidopsis
:return:
Expand Down
Loading