aboutsummaryrefslogtreecommitdiff
path: root/README.org
blob: 2daaae9a840c9d42773cd32eefea5906c62285be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#+STARTUP: inlineimages
#+TITLE: GeneNetwork Quality Control Application
#+OPTIONS: ^:{}

** Project Goals

The project seeks to handle the checking of data files for correct syntax and
other errors before allowing the code to be uploaded.

The files are *"tab-separated"* values (TSV) files, and must conform to the
following criteria:

*** Line-Level Checks

- Must be tab-separated
-

*** Cell-Level Checks

- No empty data cells
- no data cells with spurious characters like `eeeee`, `5.555iloveguix`, etc.
- decimal numbers must conform to the following criteria:
-   - when checking an average file decimal numbers must contain exactly three places to the right side of the dot.
-   - when checking a standard error file decimal numbers must contain six or greater places to the right side of the dot.
-   - there must be a number to the left side of the dot (e.g. 0.55555 is allowed but .55555 is not).
- check line endings to make sure they are Unix and not DOS
- check strain headers against a source of truth (see strains.csv)

** Guix Channel

This repository can be used as a guix channel.

#+BEGIN_SRC scheme
  (channel
   (name 'gn-uploader)
   (url "https://git.genenetwork.org/gn-uploader")
   (branch "main")
   (introduction
    (make-channel-introduction
     "93c77842315d304abbfc27d78d98b7d42da32a61"
     (openpgp-fingerprint
      "F370 F409 854B 90E3 52F3  AB01 362B 0BB8 B81D 5A42"))))
#+END_SRC

** Configuration

This system requires that some configurations be in place to operate correctly.
The following sections detail the configuration variables.

*** System Configurations

**** *Config*: =LOG_LEVEL=
*Default*: WARNING

We use logging to track the operation of the system, noting major events, and
conditions in the system as it runs. The =LOG_LEVEL= variable controls how much
of that information we want to track, and the severity of said information.

**** *Config*: =SECRET_KEY=

*Mandatory*

This is a key used for signing cookies for more secure tamper-proof sessions.
Without it, Flask will generate a random key for each running thread/process of
the system, leading to some really difficult to debug consequences.

/Avoid the aggravation! Just set a secret key and be done with it/.

For some more information on Flask's =SECRET_KEY= have a look at the following
resources:

- https://flask.palletsprojects.com/en/3.0.x/config/#SECRET_KEY
- https://flask.palletsprojects.com/en/3.0.x/quickstart/#sessions
- https://stackoverflow.com/a/48596852

**** *Config*: `UPLOAD_FOLDER`

*Default*: /tmp/qc_app_files

This is the directory where all uploaded files are stored.

Files are to be stored here temporary, while they are still being processed.
Down the line, we will probably have a different location for files that have
passed QC and whose data has been accepted into the system.

*Development Note*: Other files we store here that we will need to extract to a
separate configuration are:

- Files with outputs from background processes triggered by this system
- /list others hereā€¦/

**** *Config*: =SQL_URI=
*Mandatory*

This defines the connection URI to the database.

This is a *MANDATORY* configuration variable: without it, the uploader will not
work as expected, if at all.

Presently, we use the MariaDB database, and thus, the URI to the database will
take the form

#+BEGIN_EXAMPLE
mysql://<username>:<password>@<hostname-or-ip>:<port>/<database-name>
#+END_EXAMPLE

The parts of the URI of note are:

- =<username>=: This is the username to use to connect to the MariaDB server
- =<password>=: A password to authenticate the user with the MariaDB server
- =<hostname-or-ip>=: The domain name or IP address of the computer hosting the
  MariaDB server
- =<port>=: The port to connect to for the MariaDB server, on the computer
  hosting MariaDB
- =<database-name>=: The database to connect to

*** Redis Configurations

**** *Config*: =REDIS_URL=

*Default*: redis://

This is the connection URI to the Redis server. The default connection parameter
above tries to connect to a redis server on the same host that the uploader is
running on.

*Note to Fred*: We should probably rename this =REDIS_URI= for consistency.

The Redis connection URI has the general form:

#+BEGIN_EXAMPLE
redis://<username>:<password>@<hostname-or-ip>:<port>/<dbnum>
#+END_EXAMPLE

and the parts of the URI of note are:

- =<username>=: This is the username to use to connect to the Redis server
- =<password>=: A password to authenticate the user with the Redis server
- =<hostname-or-ip>=: The domain name or IP address of the computer hosting the
  Redis server
- =<port>=: The port to connect to for the Redis server, on the computer
  hosting Redis
- =<dbnum>=: A number identifying the database to connect to

  Here is [a resource](https://github.com/lettuce-io/lettuce-core/wiki/Redis-URI-and-connection-details)
  on other ways to construct Redis connection URIs.

**** *Config*: =JOBS_TTL_SECONDS=

*Default*: 1209600 seconds (14 days)

This is the "Time-To-Live" for the keys in redis. Most of the keys we store in
Redis from this system do not need to be retained forever. The TTL determines
how long (in seconds) to keep the keys around for.

**** *Config*: =GNQC_REDIS_PREFIX=

*Default*: GNQC

This system could find itself sharing a Redis server with other (related)
applications such as [GN2](https://github.com/genenetwork/genenetwork2) and
[GN3](https://github.com/genenetwork/genenetwork3).

The =GNQC_REDIS_PREFIX= configuration is prepended to the keys being saved by
this system to redis. For example, if ~GNQC_REDIS_PREFIX=GNQC~ and you want to
set up a hash with the key =users=, the effective key in redis will be
~GNQC:users~.

** Development

For reproducibility, this project is developed using guix.

To launch a guix shell for development, do
#+BEGIN_SRC shell
  guix shell --container --network --share=/some/host/directory=/the/upload/directory --development --file=guix.scm
#+END_SRC
which environment that is isolated from the rest of your system.

We share a host directory with the container (that is writeable by the user that
started the web application) to serve as the upload directory for the
application.

*** Run the CLI version

Run the CLI version of the application, with
#+BEGIN_SRC shell
python3 -m scripts.qc --help
#+END_SRC

*** Run the web version

You need to have a running Redis instance, and configure the application to
connect to it.

To run the web-version of the qc app in development mode, you need to set up a
few environment variables
#+BEGIN_SRC shell
export FLASK_APP=wsgi.py
export FLASK_ENV=development
export QCAPP_INSTANCE_PATH=/path/to/directory/with/config.py
#+END_SRC
then you can run the application with
#+BEGIN_SRC shell
flask run
#+END_SRC

*** Checks

To run the linter over the code base, run:
#+BEGIN_SRC shell
  pylint setup.py wsgi.py tests quality_control qc_app r_qtl scripts
#+END_SRC

To check for correct type usage in the application, run:
#+BEGIN_SRC shell
  mypy --show-error-codes .
#+END_SRC

Run unit tests with:
#+BEGIN_SRC shell
  $ export QCAPP_CONF=</path/to/configuration/file.py>
  $ pytest -m unit_test
#+END_SRC

To run ALL tests (not just unit tests):
#+BEGIN_SRC shell
  $ export QCAPP_CONF=</path/to/configuration/file.py>
  $ pytest
#+END_SRC

** Deploying/Installing QC

**NOTE**: All tests should pass before you deploy the uploader!

*** CLI: Docker

Generate the docker image file with
#+BEGIN_SRC shell
guix pack -f docker -S /bin=bin genenetwork-qc
#+END_SRC

That creates the image file with a path such as:
#+BEGIN_EXAMPLE
/gnu/store/ibz5qlwzv0lyply2by7422z0c6jfaa6s-genenetwork-qc-docker-pack.tar.gz
#+END_EXAMPLE

You can now load this file into docker withe
#+BEGIN_SRC shell
docker load < /gnu/store/ibz5qlwzv0lyply2by7422z0c6jfaa6s-genenetwork-qc-docker-pack.tar.gz
#+END_SRC

and from there, you can run the application as detailed in the
[[#run-cli-version][Running QC: CLI-Version]] section below

*** CLI: Guix

The application can be installed using guix by pointing to the [[./guix.scm][guix.scm]] file as
follows:
#+BEGIN_SRC shell
guix package [-p /path/to/qc/profile] -f guix.scm
#+END_SRC

*** Web-Version

**** TODO Document deployment details for the web version of GeneNetwork QC better

** Running QC

*** Command-Line Version
:PROPERTIES:
:CUSTOM_ID: run-cli-version
:END:

Install the application as shown in the /Installing QC/ section above.

To run qc against a file, the syntax is:
#+BEGIN_SRC shell
 qc [--strainsfile <strainsfile-path>] [--verbose] <filetype> <filepath>
#+END_SRC
where
- ~<filetype>~ is one of "*average*" or "*standard-error*"
- ~<filepath>~ is either an absolute path to the file, or a path relative to the
  current working directory
- if the ~--strainsfile~ option is not provided, it will default to the one in
  the root directory of this repository
- the ~--verbose~ option is a flag, defaulting to ~False~ that controls the
  display of optional progress messages

To view the usage information for the application, run
#+BEGIN_SRC shell
qc --help
#+END_SRC

*** Web Version

**** TODO Document usage of the web-UI version of the application

*** Docker

Download the docker image file from [[https://git.genenetwork.org/fredmanglis/gnqc_py/releases][the releases page]] of the application and
load it to docker with something like:
#+BEGIN_SRC shell
  docker load < genenetwork-qc-0.0.1-1-oxu472i-docker.tar.gz
#+END_SRC
replacing ~genenetwork-qc-0.0.1-1-oxu472i.tar.gz~ with the actual name of the
release you downloaded

Run the application with something like:
#+BEGIN_SRC shell
docker run -v /path/to/qnqc_py/tests/test_data:/data -ti \
    genenetwork-qc:latest /bin/qc average /data/average_error_at_end_200MB.tsv
#+END_SRC
replacing ~/path/to/qnqc_py/tests/test_data~ with the path to the folder where
the file you want to check is in, and ~average_error_at_end_200MB.tsv~ with the
name of the file you want to check for errors.