Skip to content

Commit 089126a

Browse files
authored
Merge pull request #233 from VinLau/dev
llama3 fetch GET endpoint with tests, flake8 tested
2 parents 84879bd + 7d55f38 commit 089126a

7 files changed

Lines changed: 153 additions & 0 deletions

File tree

api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def create_app():
6363
from api.resources.gene_localizations import loc
6464
from api.resources.efp_image import efp_image
6565
from api.resources.fastpheno import fastpheno
66+
from api.resources.llama3 import llama3
6667

6768
bar_api.add_namespace(gene_information)
6869
bar_api.add_namespace(rnaseq_gene_expression)
@@ -76,6 +77,7 @@ def create_app():
7677
bar_api.add_namespace(loc)
7778
bar_api.add_namespace(efp_image)
7879
bar_api.add_namespace(fastpheno)
80+
bar_api.add_namespace(llama3)
7981
bar_api.init_app(bar_app)
8082
return bar_app
8183

api/models/llama3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from api import db
2+
3+
4+
class Summaries(db.Model):
5+
__bind_key__ = "llama3"
6+
__tablename__ = "summaries"
7+
8+
gene_id: db.Mapped[str] = db.mapped_column(db.String(13), nullable=False, primary_key=True)
9+
summary: db.Mapped[int] = db.mapped_column(db.String(), nullable=False)
10+
bert_score: db.Mapped[str] = db.mapped_column(db.Float, nullable=False)

api/resources/llama3.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Date: Aug 2024
3+
Author: Vincent Lau
4+
LLaMA endpoiint for plant connectome GPT results
5+
"""
6+
7+
from flask_restx import Namespace, Resource
8+
from markupsafe import escape
9+
from api.utils.bar_utils import BARUtils
10+
from api import db
11+
from api.models.llama3 import Summaries
12+
13+
14+
llama3 = Namespace("LLaMA", description="Endpoint for retreiving LLaMA3 results", path="/LLaMA")
15+
16+
17+
@llama3.route("/<string:gene_id>")
18+
class Llama(Resource):
19+
@llama3.param("gene_id", _in="path", default="AT3G18850")
20+
def get(self, gene_id=""):
21+
"""
22+
Endpoint returns Llama3 summary of plant connectome for a given gene
23+
- Arabidopsis - e.g. AT3G18850
24+
"""
25+
26+
gene_id = escape(gene_id.upper())
27+
28+
if BARUtils.is_arabidopsis_gene_valid(gene_id):
29+
rows = (
30+
db.session.execute(db.select(Summaries).where(Summaries.gene_id == gene_id))
31+
.first()
32+
)
33+
34+
if len(rows) == 0:
35+
return (
36+
BARUtils.error_exit("There are no data found for the given gene"),
37+
400,
38+
)
39+
else:
40+
res = {
41+
"summary": rows[0].summary,
42+
"gene_id": rows[0].gene_id,
43+
"bert_score": rows[0].bert_score,
44+
}
45+
return BARUtils.success_exit(res)
46+
else:
47+
return BARUtils.error_exit("Invalid gene id"), 400

config/BAR_API.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SQLALCHEMY_BINDS = {
2626
'germination': 'mysql://root:root@localhost/germination',
2727
'kalanchoe': 'mysql://root:root@localhost/kalanchoe',
2828
'klepikova': 'mysql://root:root@localhost/klepikova',
29+
'llama3': 'mysql://root:root@localhost/llama3',
2930
'phelipanche' : 'mysql://root:root@localhost/phelipanche',
3031
'physcomitrella_db' : 'mysql://root:root@localhost/physcomitrella_db',
3132
'poplar_nssnp' : 'mysql://root:root@localhost/poplar_nssnp',

config/databases/llama3.sql

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
-- MySQL dump 10.13 Distrib 8.3.0, for macos14.2 (arm64)
2+
--
3+
-- Host: localhost Database: llama3_summaries
4+
-- ------------------------------------------------------
5+
-- Server version 8.3.0
6+
7+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10+
/*!50503 SET NAMES utf8mb4 */;
11+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12+
/*!40103 SET TIME_ZONE='+00:00' */;
13+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17+
18+
--
19+
-- Current Database: `llama3`
20+
--
21+
22+
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `llama3` /*!40100 DEFAULT CHARACTER SET latin1 */ /*!80016 DEFAULT ENCRYPTION='N' */;
23+
24+
USE `llama3`;
25+
26+
--
27+
-- Table structure for table `summaries`
28+
--
29+
30+
DROP TABLE IF EXISTS `summaries`;
31+
/*!40101 SET @saved_cs_client = @@character_set_client */;
32+
/*!50503 SET character_set_client = utf8mb4 */;
33+
CREATE TABLE `summaries` (
34+
`gene_id` varchar(13) NOT NULL,
35+
`summary` longtext NOT NULL,
36+
`bert_score` decimal(8,7) NOT NULL,
37+
PRIMARY KEY (`gene_id`)
38+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
39+
/*!40101 SET character_set_client = @saved_cs_client */;
40+
41+
--
42+
-- Dumping data for table `summaries`
43+
--
44+
45+
LOCK TABLES `summaries` WRITE;
46+
/*!40000 ALTER TABLE `summaries` DISABLE KEYS */;
47+
INSERT INTO `summaries` VALUES
48+
('AT3G18890','The gene AT3G18890, also known as TIC62, has been found to be correlated with PSII electron transfer rate and cyclic electron transport (PubMed ID 33118270). Additionally, TIC62 has been shown to repress protein import (PubMed ID 19403728). Research has also demonstrated that TIC62 shuttles between the envelope and stroma (PubMed ID 20040542), interacts with FNR (PubMed ID 20040542), localizes to thylakoids (PubMed ID 20040542), binds to FNR (PubMed ID 20040542), stabilizes FNR (PubMed ID 20040542), and dynamically regulates FNR (PubMed ID 20040542). Furthermore, TIC62 has been found to form complexes with LIR1 and TROL (PubMed ID 26941088), and LIR1 enhances the affinity of LFNR for TIC62 (PubMed ID 26941088). Moreover, TIC62 has been shown to participate in anchoring ATLFNRs (PubMed ID 36138316).',0.9898241),
49+
('AT3G17820','The gene AT3G17820, also known as GLN1;3, plays a crucial role in regulating glutamine biosynthesis, as demonstrated by research in PubMed ID 28007952, which shows that GLN1;3 represses glutamine biosynthesis. Additionally, GLN1;3 localizes to the pericycle (PubMed ID 28007952) and encodes for cytosolic GS (PubMed ID 31034969). Furthermore, ATPDF2.1 has been found to enhance the expression of GLN1.3 and GLN1.5 (PubMed ID 31842759), which produce glutamine synthetase (PubMed ID 31842759). Interestingly, the GLN1;1, GLN1;2, and GLN1;3 genes have been shown to affect N remobilization (PubMed ID 29873769), which is also linked to vegetative growth (PubMed ID 30649517).',0.9829522),
50+
('AT3G18850','The gene AT3G18850, also known as LPAT5, has been found to localize to the endoplasmic reticulum (ER) (PubMed ID 31211859). This localization is crucial for its function, as LPAT5 is responsible for producing phospholipids and triacylglycerol (TAG) (PubMed ID 31211859).',0.9839827);
51+
/*!40000 ALTER TABLE `summaries` ENABLE KEYS */;
52+
UNLOCK TABLES;
53+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
54+
55+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
56+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
57+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
58+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
59+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
60+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
61+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
62+
63+
-- Dump completed on 2024-07-26 22:23:56

config/init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mysql -u $DB_USER -p$DB_PASS < ./config/databases/fastpheno.sql
2525
mysql -u $DB_USER -p$DB_PASS < ./config/databases/germination.sql
2626
mysql -u $DB_USER -p$DB_PASS < ./config/databases/kalanchoe.sql
2727
mysql -u $DB_USER -p$DB_PASS < ./config/databases/klepikova.sql
28+
mysql -u $DB_USER -p$DB_PASS < ./config/databases/llama3.sql
2829
mysql -u $DB_USER -p$DB_PASS < ./config/databases/phelipanche.sql
2930
mysql -u $DB_USER -p$DB_PASS < ./config/databases/physcomitrella_db.sql
3031
mysql -u $DB_USER -p$DB_PASS < ./config/databases/poplar_nssnp.sql

tests/resources/test_llama3.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from api import app
2+
from unittest import TestCase
3+
4+
5+
class TestIntegrations(TestCase):
6+
def setUp(self):
7+
self.app_client = app.test_client()
8+
9+
def test_get_llama(self):
10+
"""
11+
This functions tests retrieving llama3 results.
12+
"""
13+
14+
# Valid request rice
15+
response = self.app_client.get("/LLaMA/AT3G18850")
16+
expected = {
17+
"wasSuccessful": True,
18+
"data": {
19+
"summary": "The gene AT3G18850, also known as LPAT5, has been found to localize to the endoplasmic reticulum (ER) (PubMed ID 31211859). This localization is crucial for its function, as LPAT5 is responsible for producing phospholipids and triacylglycerol (TAG) (PubMed ID 31211859).",
20+
"gene_id": "AT3G18850",
21+
"bert_score": 0.9839827
22+
}
23+
}
24+
self.assertEqual(response.json, expected)
25+
26+
# Gene does not exist
27+
response = self.app_client.get("/LLaMA/XX3G18850")
28+
expected = {"wasSuccessful": False, "error": "Invalid gene id"}
29+
self.assertEqual(response.json, expected)

0 commit comments

Comments
 (0)