Skip to content

Commit acf7770

Browse files
authored
Merge pull request #237 from BioAnalyticResource/dev
Update main ...
2 parents 3131d5d + ddcf94e commit acf7770

File tree

10 files changed

+167
-18
lines changed

10 files changed

+167
-18
lines changed

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

docker-compose.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
version: "3.7"
2-
31
services:
42

53
mysqldb:
64
image: mysql:9.0.1
75
container_name: BAR_mysqldb
8-
# Must use this for mariadb client to connect
9-
command: --default-authentication-plugin=mysql_native_password
106
restart: always
117
environment:
128
- MYSQL_ROOT_PASSWORD=root

docs/source/installation_guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Run on your own computer with Docker
1111

1212
.. code-block:: bash
1313
14-
docker-compose build
14+
docker compose build
1515
1616
6. Run docker containers (-d is detached)
1717

1818
.. code-block:: bash
1919
20-
docker-compose up -d
20+
docker compose up -d
2121
2222
7. Load ``http://localhost:5000/`` in a web browser. Enjoy :)
2323

requirements.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
aniso8601==9.0.1
22
async-timeout==4.0.3
3-
attrs==23.2.0
4-
black==24.4.2
3+
attrs==24.2.0
4+
black==24.8.0
55
blinker==1.8.2
66
cachelib==0.9.0
77
certifi==2024.7.4
88
charset-normalizer==3.3.2
99
click==8.1.7
10-
coverage==7.6.0
10+
coverage==7.6.1
1111
Deprecated==1.2.14
12-
flake8==7.1.0
12+
flake8==7.1.1
1313
Flask==3.0.3
1414
Flask-Caching==2.3.0
1515
Flask-Cors==4.0.1
@@ -19,7 +19,7 @@ flask-restx==1.3.0
1919
Flask-SQLAlchemy==3.1.1
2020
greenlet==3.0.3
2121
idna==3.7
22-
importlib_resources==6.4.0
22+
importlib_resources==6.4.3
2323
iniconfig==2.0.0
2424
itsdangerous==2.2.0
2525
Jinja2==3.1.4
@@ -28,7 +28,7 @@ jsonschema-specifications==2023.12.1
2828
limits==3.13.0
2929
markdown-it-py==3.0.0
3030
MarkupSafe==2.1.5
31-
marshmallow==3.21.3
31+
marshmallow==3.22.0
3232
mccabe==0.7.0
3333
mdurl==0.1.2
3434
mypy-extensions==1.0.0
@@ -38,23 +38,23 @@ packaging==24.1
3838
pathspec==0.12.1
3939
platformdirs==4.2.2
4040
pluggy==1.5.0
41-
pycodestyle==2.12.0
41+
pycodestyle==2.12.1
4242
pyflakes==3.2.0
4343
Pygments==2.18.0
4444
pyrsistent==0.20.0
4545
pytest==8.3.2
4646
python-dateutil==2.9.0.post0
4747
pytz==2024.1
48-
redis==5.0.7
48+
redis==5.0.8
4949
referencing==0.35.1
5050
requests==2.32.3
5151
rich==13.7.1
52-
rpds-py==0.19.1
53-
setuptools==71.1.0
52+
rpds-py==0.20.0
53+
setuptools==73.0.1
5454
six==1.16.0
55-
SQLAlchemy==2.0.31
55+
SQLAlchemy==2.0.32
5656
typing_extensions==4.12.2
5757
urllib3==2.2.2
5858
Werkzeug==3.0.3
59-
wheel==0.43.0
59+
wheel==0.44.0
6060
wrapt==1.16.0

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)