Skip to content

Commit c0e8772

Browse files
authored
Merge pull request #228 from VinLau/dev
PR: Added world eFP endpoint, skipped tests that no longer work due to /DATA folder
2 parents 837366e + 10549a2 commit c0e8772

13 files changed

Lines changed: 611 additions & 1 deletion

api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def create_app():
5353
# Now add routes
5454
from api.resources.gene_information import gene_information
5555
from api.resources.rnaseq_gene_expression import rnaseq_gene_expression
56+
from api.resources.microarray_gene_expression import microarray_gene_expression
5657
from api.resources.proxy import bar_proxy
5758
from api.resources.thalemine import thalemine
5859
from api.resources.snps import snps
@@ -65,6 +66,7 @@ def create_app():
6566

6667
bar_api.add_namespace(gene_information)
6768
bar_api.add_namespace(rnaseq_gene_expression)
69+
bar_api.add_namespace(microarray_gene_expression)
6870
bar_api.add_namespace(bar_proxy)
6971
bar_api.add_namespace(thalemine)
7072
bar_api.add_namespace(snps)

api/models/annotations_lookup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ class AgiAlias(db.Model):
1010
agi: db.Mapped[str] = db.mapped_column(db.String(30), primary_key=True, nullable=False)
1111
alias: db.Mapped[str] = db.mapped_column(db.String(30), primary_key=True, nullable=False)
1212
date: db.Mapped[datetime] = db.mapped_column(db.Date, primary_key=True, nullable=False)
13+
14+
15+
class AtAgiLookup(db.Model):
16+
__bind_key__ = "annotations_lookup"
17+
__tablename__ = "at_agi_lookup"
18+
__table_args__ = (db.Index("probeset_date_agi", "probeset", "agi", "date"),)
19+
20+
probeset: db.Mapped[str] = db.mapped_column(db.String(60), primary_key=True, nullable=False)
21+
agi: db.Mapped[str] = db.mapped_column(db.String(30), primary_key=True, nullable=False)
22+
date: db.Mapped[datetime] = db.mapped_column(db.Date, primary_key=True, nullable=False)

api/models/arabidopsis_ecotypes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from api import db
2+
3+
4+
class SampleData(db.Model):
5+
__bind_key__ = "arabidopsis_ecotypes"
6+
__tablename__ = "sample_data"
7+
8+
sample_id: db.Mapped[int] = db.mapped_column(db.Integer, nullable=False)
9+
proj_id: db.Mapped[str] = db.mapped_column(db.String(15), nullable=False)
10+
sample_file_name: db.Mapped[str] = db.mapped_column(db.String)
11+
data_probeset_id: db.Mapped[str] = db.mapped_column(db.String(30), nullable=False, primary_key=True)
12+
data_signal: db.Mapped[float] = db.mapped_column(db.Float)
13+
data_call: db.Mapped[str] = db.mapped_column(db.String)
14+
data_p_val: db.Mapped[float] = db.mapped_column(db.Float)
15+
data_bot_id: db.Mapped[str] = db.mapped_column(db.String(16), nullable=False)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from flask_restx import Namespace, Resource
2+
from markupsafe import escape
3+
from api import db
4+
from api.models.annotations_lookup import AtAgiLookup
5+
from api.models.arabidopsis_ecotypes import SampleData as EcotypesSampleData
6+
from api.utils.bar_utils import BARUtils
7+
from api.utils.world_efp_utils import WorldeFPUtils
8+
9+
10+
microarray_gene_expression = Namespace(
11+
"Microarray Gene Expression",
12+
description="Microarray (probe-based) Gene Expression data from the BAR Databases",
13+
path="/microarray_gene_expression",
14+
)
15+
16+
17+
@microarray_gene_expression.route("/world_efp/<string:species>/<string:gene_id>")
18+
class GetWorldeFPExpression(Resource):
19+
@microarray_gene_expression.param("species", _in="path", default="arabidopsis")
20+
@microarray_gene_expression.param("gene_id", _in="path", default="At1g01010")
21+
def get(self, species="", gene_id=""):
22+
"""This end point returns World Efp gene expression data"""
23+
species = escape(species)
24+
gene_id = escape(gene_id)
25+
26+
if species == "arabidopsis":
27+
if not BARUtils.is_arabidopsis_gene_valid(gene_id):
28+
return BARUtils.error_exit("Invalid gene id")
29+
else:
30+
return BARUtils.error_exit("Invalid species")
31+
subquery = db.select(AtAgiLookup.probeset).where(AtAgiLookup.agi == gene_id).order_by(AtAgiLookup.date.desc()).limit(1).subquery()
32+
33+
sq_query = db.session.query(subquery)
34+
if sq_query.count() > 0:
35+
sq_result = sq_query[0][0]
36+
else:
37+
return BARUtils.error_exit("There are no data found for the given gene")
38+
39+
rows = db.session.execute(
40+
db.select(EcotypesSampleData.data_probeset_id, EcotypesSampleData.data_signal, EcotypesSampleData.data_bot_id).where(EcotypesSampleData.data_probeset_id == sq_result)
41+
).all()
42+
final_json = {}
43+
44+
if len(rows) > 0:
45+
for row in rows:
46+
if row[2][5:8] not in final_json:
47+
final_json[row[2][5:8]] = WorldeFPUtils.wrap_json(row[2][5:8], row[2], row[1], row[0])
48+
elif row[2][5:8] in final_json:
49+
final_json[row[2][5:8]]['values'].update({row[2] : row[1]})
50+
return BARUtils.success_exit(final_json)
51+
else:
52+
return BARUtils.error_exit("There are no data found for the given gene")

0 commit comments

Comments
 (0)