Skip to content

Commit 620ad88

Browse files
authored
Fixed #141; fixed #145 (#153)
* Fixed #141 * Fixed #145 * Starting to address #38
1 parent f7dc527 commit 620ad88

File tree

11 files changed

+236
-60
lines changed

11 files changed

+236
-60
lines changed

README.md

Lines changed: 100 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
<p align="center">
44
<a href="https://github.com/precisiontox/ptox-metadata-manager/actions/workflows/build.yml" target="_blank" rel="noopener noreferrer">
5-
<img src="https://github.com/precisiontox/ptox-metadata-manager/actions/workflows/build.yml/badge.svg" alt="Build Badge" />
5+
<img src="https://github.com/precisiontox/ptox-metadata-manager/actions/workflows/build.yml/badge.svg" alt="Build Badge" />
66
</a>
77
<a href="https://coveralls.io/github/precisiontox/ptox-metadata-manager?branch=main" target="_blank" rel="noopener noreferrer">
8-
<img src="https://coveralls.io/repos/github/precisiontox/ptox-metadata-manager/badge.svg?branch=terazus-badges" alt="Coverage Report Badge" />
8+
<img src="https://coveralls.io/repos/github/precisiontox/ptox-metadata-manager/badge.svg?branch=terazus-badges" alt="Coverage Report Badge" />
99
</a>
1010
<a href="https://app.codacy.com/gh/precisiontox/ptox-metadata-manager/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade">
11-
<img src="https://app.codacy.com/project/badge/Grade/1503dc8bf33c40bbb474ec328ba90219"/>
11+
<img src="https://app.codacy.com/project/badge/Grade/1503dc8bf33c40bbb474ec328ba90219" alt="Code Quality badge"/>
12+
</a>
13+
<a href="https://mm.precisiontox.org" target="_blank">
14+
<img src="https://img.shields.io/badge/Status-production-green" alt="Status Badge" />
1215
</a>
13-
<img src="https://img.shields.io/badge/Status-production-green" alt="Status Badge" />
1416
<a href="https://raw.githubusercontent.com/precisiontox/ptox-metadata-manager/main/docs_badge.svg" target="_blank" rel="noopener noreferrer">
1517
<img src="https://raw.githubusercontent.com/precisiontox/ptox-metadata-manager/main/docs_badge.svg" alt="Docstring Coverage Badge"/>
1618
</a>
@@ -24,30 +26,56 @@
2426
<img src="https://img.shields.io/badge/licence-AGPL-blue" alt="Licence Badge"/>
2527
</a>
2628
<a href="https://pretox.isa-tools.org/apidocs/" target="_blank" rel="noopener noreferrer">
27-
<img src="https://img.shields.io/badge/API-Swagger-blue" alt="Licence Badge"/>
29+
<img src="https://img.shields.io/badge/API-Swagger-blue" alt="API Doc Badge"/>
2830
</a>
2931
</p>
3032

33+
<p align="center">
34+
The PrecisionTox Metadata Manager is a tool to help manage metadata about samples collected in the lab. It is part of the
35+
<a href="https://precisiontox.org/" target="_blank">PrecisionTox Consortium</a> and is used to ensure that metadata
36+
are correct and can be used to find data files.
37+
</p>
3138

39+
## Table of contents
40+
- [Introduction](#introduction)
41+
- [Video tutorial](#video-tutorial)
42+
- [Objectives](#objectives)
43+
- [Getting started](#getting-started)
44+
- [Requirements](#requirements)
45+
- [Setup](#setup)
46+
- [Production](#production)
47+
- [Architecture](#architecture)
48+
- [Development process](#development-process)
49+
- [Components](#components)
50+
- [Database: Entity Relationship Diagram (ERD)](#database-entity-relationship-diagram-erd)
51+
- [Development](#development)
52+
- [Testing](#testing)
53+
- [Documentation](#verify-and-generate-the-documentation)
54+
- [Static typing](#verify-type-hints)
3255

3356
## Introduction
57+
58+
### Video tutorial
3459
<p align="center">
3560
<a href="https://www.youtube.com/watch?v=XWItfWplwT0&hd=1" target="_blank">
36-
<img src="./docs/source/_static/img/video_thumbnail.jpg"
61+
<img src="https://raw.githubusercontent.com/precisiontox/ptox-metadata-manager/DomDoc/docs/source/_static/img/video_thumbnail.jpg"
3762
alt="Click to view the tool presentation video on youtube">
63+
<br>
64+
<span> Click to view video tutorial</span>
3865
</a>
3966
</p>
4067

4168
### Objectives
42-
The precision toxicology metadata manager is a tool created to help consortium partners of the [PrecisionTox](https://precisiontox.org/) who produce
43-
data to create, find, validate and share metadata about samples they collect in the lab. The idea behind the tool is to
44-
operate at planning stage, before organisms are even exposed to compounds and samples are collected. These samples are meant to be shipped
45-
to a central partner who will perform material extractions for *RNAseq* and *mass-spectrometry* data acquisitions.
46-
The tool ensures that metadata do not contain any error, can be used to find physical samples in the boxes shipped to the core facility and that the experimental results can be produced in
47-
a FAIR and publishable way.
69+
The precision toxicology metadata manager was created to help partners producing data in the
70+
[PrecisionTox Consortium](https://precisiontox.org/) to create, find, validate and share metadata
71+
about samples they collect in the lab. The idea behind the tool is to operate at planning stage, before organisms are
72+
even exposed to compounds and samples are collected. These samples are meant to be shipped to a central partner who
73+
will perform material extractions for *RNAseq* and *mass-spectrometry* data acquisitions. The tool ensures that
74+
metadata do not contain any error, can be used to find physical samples in the boxes shipped to the core facility
75+
and that the experimental results can be produced in a FAIR and publishable way.
4876
<br>
4977
Consortium partners producing samples are invited to fill a form based on an experimental design defined by the consortium.
50-
The form generates excel files containing metadata about sample exposition and collection divided into
78+
The form generates Excel files containing metadata about sample exposition and collection divided into
5179
two sheets:
5280
- a first sheet containing specific information about the samples. This includes which replicates are exposed
5381
to which compound, at which dose, with which vehicle, and after how long they were collected. It also includes a unique
@@ -75,42 +103,6 @@ and unique identifiers for each record.
75103

76104
<img src="./docs/source/_static/img/user_story.png" alt="Metadata pipeline for sample exposure and collection" style="max-width:700px; margin:auto; display:block;"/>
77105

78-
79-
### Components:
80-
81-
#### The frontend client
82-
A NuxtJS web application accessible at https://ptmm.netlify.app.
83-
It is responsible for the user interface and the communication with the API.
84-
85-
#### The backend API
86-
It is hosted in this repository. It contains a [Flask](https://flask.palletsprojects.com/en/2.3.x/) application exposing a REST API and is plugged to a relational
87-
database through [SQLAlchemy](https://www.sqlalchemy.org/).
88-
89-
It is responsible for authentication, all functionalities logic and the persistence of
90-
(meta)-data. It provides a Swagger documentation accessible at https://pretox.isa-tools.org/apidocs. The documentation
91-
describes the API usage and provides a way to run queries through a web UI. The code is documented using ``docstrings``
92-
and the documentation is available on ``readthedocs``. The application is entirely unit-tested, typehints are checked
93-
with ``mypy``, code quality is surveyed by ``Codacy`` and styles are enforced by ``flake8``, all as part of the
94-
continuous integration pipeline.
95-
<br> <br>
96-
The application source code is contained in the ``ptmd`` directory and divided as such:
97-
- The ``api`` directory contains the flask application exposing the REST API. It includes routes definitions, the
98-
JSON Web Token authentication logic and the validation of user inputs through JSON Schema.
99-
- The ``boot`` directory contains the code responsible for booting the application, like seeding the initial data into
100-
the database.
101-
- The ``const`` directory contains the constants used throughout the application.
102-
- The ``database`` directory contains the database models and complex queries. Interactions with the database is mostly
103-
defined as methods of the model classes.
104-
- The ``lib`` directory contains the code responsible for the business logic, like the interactions with the spreadsheets
105-
and the Google Drive API, sending emails and generating ISA-JSON files.
106-
- The ``resources`` directory contains the assets used by the application, like JSON schemas, swagger yaml files, data
107-
files for organisations and chemicals, etc.
108-
109-
Tests are contained in the ``tests`` directory and divided mirroring the application exact structure. They require no
110-
data files and no interaction with the database to be executed.
111-
112-
113-
114106
## Getting started
115107
### Requirements:
116108
- Python 3.9 or newer
@@ -126,6 +118,7 @@ python -m venv venv
126118
source venv/bin/activate
127119
pip install -r requirements.txt # for production
128120
pip install -r requirements-dev.txt # for development
121+
mv ptmd/resources/.env.example ptmd/resources/.env # Create the .env file
129122
```
130123

131124
Before running the application you need to obtain a Google Drive ID and secret: head to your Google Cloud console and
@@ -156,32 +149,78 @@ The environment variables are divided into three categories:
156149
- `SQLALCHEMY_DATABASE_URL`: this is the URL to your database. You can use sqlite, postgres, mysql, etc., e.g.
157150
sqlite:///ptmd.db, and will need to change this before running the application.
158151
- `SQLALCHEMY_SECRET_KEY`: this is the secret key used to encrypt hashes and other sensitive data.
159-
- `SITE_URL`: the URL of the site.
152+
- `SITE_URL`: the URL of the JavaScript client (used for sending activation and reset links through emails).
160153
- The Google Drive API configuration variables:
161154
- `GOOGLE_DRIVE_CLIENT_ID`: the Google Drive client ID obtainable in your Google Cloud Console (see above).
162155
- `GOOGLE_DRIVE_CLIENT_SECRET`: the Google Drive client secret obtaining in your Google Cloud Console (see above).
163156
- `GOOGLE_DRIVE_CREDENTIALS_FILEPATH`: the path where to store the credentials file created during first boot. This needs to
164157
be a json file (e.g. credentials.json).
165-
- `GOOGLE_DRIVE_SETTINGS_FILEPATH`: the path where to store the settings file created during first seed_db
166-
e.g. settings.yaml) Not that a `.yml` extension <b>will not be accepted</b>, please use `.yaml` instead.
158+
- `GOOGLE_DRIVE_SETTINGS_FILEPATH`: the path where to store the settings file created during first initialization
159+
(e.g. settings.yaml). Note that a `.yml` extension <b>will not be accepted</b>, please use `.yaml` instead.
167160
- The admin account configuration variables.
168161
- `ADMIN_EMAIL`: the email address of the admin user. This is used to send emails to the admin user when a new user
169162
registers.
170163
- `ADMIN_USERNAME`: the username of the admin user. This is used to create the first admin user. Cannot be changed.
171164
- `ADMIN_PASSWORD`: the password of the admin user. This is used to create the first admin user. Can be changed later.
172165

173-
You can now run the following command and accept the application in your browser. This is done once only during first seed_db.
166+
You can now run the following command and accept the application in your browser. This is done once only during first initialization.
174167
It will download the Google API credentials file and generate the database once you are done.
175-
Finally, it will seed_db the flask API.
168+
Finally, it will boot the flask API in your local host.
169+
170+
<u>Note</u>: The Google credentials can be generated on any machine and then copied to the server where the application is
171+
running if path in the `.env` file matches the path on the server.
172+
176173
```shell
177174
python -m app
178175
```
179176

180177
Once the API is booted go to http://localhost:5000/apidocs to see the Swagger documentation.
181178

182-
## Database: Entity Relationship Diagram (ERD)
183-
<img src="./docs/source/_static/img/database.png" alt="Database Entity Relationship Diagram (ERD)"/>
179+
### Production
180+
In order to run the application in production you will need a web server and a WSGI. It has been tested with
181+
Apache/Passenger and Nginx/Gunicorn. You will also want to configure your web server so that files under
182+
the `ptmd/resources/` directory are served.
183+
Finally, you need to set the publishing status of your application status to 'In Production' in your Google Cloud
184+
Console. This will allow the application to refresh authentication tokens automatically.
184185

186+
## Architecture
187+
188+
### The frontend client
189+
A NuxtJS web application accessible in [development](https://ptmm.netlify.app)
190+
and [production](https://mm.precisiontox.org).
191+
It is responsible for the user interface and the communication with the API.
192+
193+
### The backend API
194+
It is hosted in this repository. It contains a [Flask](https://flask.palletsprojects.com/en/2.3.x/) application exposing a REST API and is plugged to a relational
195+
database through [SQLAlchemy](https://www.sqlalchemy.org/).
196+
197+
### Development process
198+
It is responsible for authentication, all functionalities logic and the persistence of
199+
(meta)-data. It provides a [Swagger documentation](http://mmapi.precisiontox.org/apidocs/) describing the API usage
200+
and enabling to build and run queries through a web UI. The code is documented using ``docstrings``
201+
and the documentation is available on [readTheDocs](https://pretox-metadata-manager.readthedocs.io/en/latest/?badge=latest).
202+
The application is entirely unit-tested, typehints are checked with ``mypy``, code quality is surveyed by ``Codacy``
203+
and styles are enforced by ``flake8``, all as part of the continuous integration pipeline.
204+
205+
#### Components
206+
The application source code is contained in the ``ptmd`` directory and divided as such:
207+
- The ``api`` directory contains the flask application exposing the REST API. It includes routes definitions, the
208+
JSON Web Token authentication logic and the validation of user inputs through JSON Schema.
209+
- The ``boot`` directory contains the code responsible for booting the application, like seeding the initial data into
210+
the database.
211+
- The ``const`` directory contains the constants used throughout the application.
212+
- The ``database`` directory contains the database models and complex queries. Interactions with the database is mostly
213+
defined as methods of the model classes.
214+
- The ``lib`` directory contains the code responsible for the business logic, like the interactions with the spreadsheets
215+
and the Google Drive API, sending emails and generating ISA-JSON files.
216+
- The ``resources`` directory contains the assets used by the application, like JSON schemas, swagger yaml files, data
217+
files for organisations and chemicals, etc.
218+
219+
Tests are contained in the ``tests`` directory and divided mirroring the application exact structure. They require no
220+
data files and no interaction with the database to be executed.
221+
222+
### Database: Entity Relationship Diagram (ERD)
223+
<img src="./docs/source/_static/img/database.png" alt="Database Entity Relationship Diagram (ERD)"/>
185224

186225
## Development
187226

@@ -194,7 +233,8 @@ coverage report -m
194233

195234

196235
### Verify and generate the documentation
197-
You will need the development dependencies installed to generate the documentation.
236+
The documentation is generated using Sphinx and hosted on [ReadTheDocs](https://pretox-metadata-manager.readthedocs.io/en/latest/).
237+
It can also be generated locally after installing the development dependencies.
198238
For Unix based systems:
199239
```shell
200240
docstr-coverage ptmd/ --fail-under=100
@@ -216,5 +256,6 @@ mypy --config-file=./mypy.ini
216256
```
217257

218258

219-
## Authors:
220-
- [B. Dominique](https://github.com/terazus), University of Oxford (orcid: [0000-0002-2109-489X](https://orcid.org/0000-0002-2109-489X))
259+
## Authors and publications:
260+
- [B. Dominique](https://github.com/terazus), University of Oxford (orcid: [0000-0002-2109-489X](https://orcid.org/0000-0002-2109-489X))
261+
- Poster: [FAIR by design: study design-driven creation of standards compliant metadata](https://doi.org/10.5281/zenodo.7847619)

docs/source/index.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Welcome to Precision Toxicology Metadata Manager's documentation!
99

1010
user_guide
1111
ptmd/models/index
12+
ptmd/libraries/creator
13+
ptmd/libraries/data_extractor
14+
ptmd/libraries/email
15+
ptmd/libraries/excel
16+
ptmd/libraries/gdrive
17+
ptmd/libraries/isa
18+
ptmd/libraries/updater
19+
ptmd/libraries/validation
1220
API Documentation <https://pretox.isa-tools.org/apidocs/>
1321

1422

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
----------
2+
Spreadsheet Creator
3+
----------
4+
.. automodule:: ptmd.lib.creator.core
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.creator.dataframes
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
----------
2+
Data Extraction
3+
----------
4+
.. automodule:: ptmd.lib.data_extractor.core
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
----------
2+
Email/GMail
3+
----------
4+
.. automodule:: ptmd.lib.email.const
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.email.core
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
15+
16+
.. automodule:: ptmd.lib.email.load_templates
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:
21+
22+
.. automodule:: ptmd.lib.email.utils
23+
:members:
24+
:undoc-members:
25+
:show-inheritance:
26+
:inherited-members:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
----------
2+
Creation of Excel spreadsheets
3+
----------
4+
.. automodule:: ptmd.lib.excel.formats
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.excel.save
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
15+
16+
.. automodule:: ptmd.lib.excel.styles
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
----------
2+
Interaction with Google Drive
3+
----------
4+
.. automodule:: ptmd.lib.gdrive.const
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.gdrive.core
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
15+
16+
.. automodule:: ptmd.lib.gdrive.utils
17+
:members:
18+
:undoc-members:
19+
:show-inheritance:
20+
:inherited-members:

docs/source/ptmd/libraries/isa.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
----------
2+
Investigations, Studies And Assays: the ISA format
3+
----------
4+
.. automodule:: ptmd.lib.isa.core
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.isa.ontologies
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
15+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
----------
2+
Updater for existing spreadsheets
3+
----------
4+
.. automodule:: ptmd.lib.updater.batch
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
----------
2+
Spreadsheet validation
3+
----------
4+
.. automodule:: ptmd.lib.validator.core
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:inherited-members:
9+
10+
.. automodule:: ptmd.lib.validator.validate_identifier
11+
:members:
12+
:undoc-members:
13+
:show-inheritance:
14+
:inherited-members:
15+

0 commit comments

Comments
 (0)