-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
171 lines (144 loc) · 5.06 KB
/
Makefile
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
SHELL:=/bin/bash
UNAME:=$(shell uname)
HOSTNAME:=$(shell hostname)
# app locations and configs
export LOG_DIR:=logs
export DB_DIR:=db
export DJANGO_DB:=db.sqlite3
export INTERPRETER_DB:=interpreter.sqlite3
export SECRET_KEY_FILE:=$(HOME)/.ir-interpreter.txt
export SECRET_KEY="$(shell head -1 "$(SECRET_KEY_FILE)")"
TIMESTAMP:=$(shell date '+%Y-%m-%d-%H-%M-%S')
DB_BACKUP_DIR:=$(DB_DIR)/backup
DB_BACKUP_PATH:=$(DB_BACKUP_DIR)/$(TIMESTAMP)
DJANGO_DB_PATH:=$(DB_DIR)/$(DJANGO_DB)
INTERPRETER_DB_PATH:=$(DB_DIR)/$(INTERPRETER_DB)
# ~~~~~~ FIRST TIME INITIAL INSTALLATION ~~~~~~ #
install: conda-install init import static-files
static-files:
python manage.py collectstatic
# ~~~~~ Setup Conda ~~~~~ #
PATH:=$(CURDIR)/conda/bin:$(PATH)
unexport PYTHONPATH
unexport PYTHONHOME
# install versions of conda for Mac or Linux
ifeq ($(UNAME), Darwin)
CONDASH:=Miniconda3-4.5.4-MacOSX-x86_64.sh
endif
ifeq ($(UNAME), Linux)
CONDASH:=Miniconda3-4.5.4-Linux-x86_64.sh
endif
CONDAURL:=https://repo.continuum.io/miniconda/$(CONDASH)
conda:
@echo ">>> Setting up conda..."
@wget "$(CONDAURL)" && \
bash "$(CONDASH)" -b -p conda && \
rm -f "$(CONDASH)"
conda-install: conda
conda install -y -c anaconda \
django=2.1.5 \
pandas=0.23.4 \
'xlrd>=0.9.0' \
gunicorn=19.9.0
pip install django-ipware==2.1.0
# ~~~~~ SETUP DJANGO APP ~~~~~ #
# create the app for development
# start:
# django-admin startproject webapp .
# python manage.py startapp interpreter
# make sure db dir exists
$(DB_DIR):
mkdir -p "$(DB_DIR)"
# create secret key file
$(SECRET_KEY_FILE):
python manage.py shell -c 'from django.core.management import utils; print(utils.get_random_secret_key())' > "$(SECRET_KEY_FILE)"
secret-key: $(SECRET_KEY_FILE)
# initialize app databases for the first time
init: secret-key $(DB_DIR)
python manage.py makemigrations
python manage.py migrate
python manage.py migrate interpreter --database=interpreter_db
python manage.py createsuperuser
# import data from PMKB .xlsx into database
import: export DJANGO_DEBUG:=True
import:
python interpreter/importer.py --type tumor_type
python interpreter/importer.py --type tissue_type
python interpreter/importer.py --type nyu_tier
python interpreter/importer.py --type nyu_interpretation
python interpreter/importer.py --type PMKB
DJANGO_DB_BACKUP_SQL:=$(DB_BACKUP_PATH)/db.sql.gz
DJANGO_DB_BACKUP_JSON:=$(DB_BACKUP_PATH)/db.json.gz
INTERPRETER_DB_BACKUP_SQL:=$(DB_BACKUP_PATH)/interpreter.sql.gz
INTERPRETER_DB_BACKUP_JSON:=$(DB_BACKUP_PATH)/interpreter.json.gz
backup:
mkdir -p "$(DB_BACKUP_PATH)" && \
sqlite3 "$(DJANGO_DB_PATH)" '.dump' | gzip > "$(DJANGO_DB_BACKUP_SQL)" && \
sqlite3 "$(INTERPRETER_DB_PATH)" '.dump' | gzip > "$(INTERPRETER_DB_BACKUP_SQL)" && \
python manage.py dumpdata --indent 4 --traceback | gzip > "$(DJANGO_DB_BACKUP_JSON)" && \
python manage.py dumpdata --database=interpreter_db interpreter --indent 4 --traceback | gzip > "$(INTERPRETER_DB_BACKUP_JSON)"
# ~~~~~ RUN ~~~~~ #
# runs the web server locally for debugging
runserver: export DJANGO_DEBUG:=True
runserver: secret-key
python manage.py runserver
# production app deployment
# socket must match what is in nginx config
SOCKET:=unix:$(CURDIR)/IR-interpreter.sock
GUNICORN_NAME:=gunicorn-IR-interpreter
# gunicorn config stored separately
GUNICORN_CONFIG:=../server-conf/$(HOSTNAME)/IR-interpreter/gunicorn_config.py
GUNICORN_PIDFILE:=logs/gunicorn.pid
GUNICORN_ACCESS_LOG:=logs/gunicorn.access.log
GUNICORN_ERROR_LOG:=logs/gunicorn.error.log
GUNICORN_LOG:=logs/gunicorn.log
deploy: $(GUNICORN_CONFIG) secret-key
gunicorn webapp.wsgi \
--bind "$(SOCKET)" \
--config "$(GUNICORN_CONFIG)" \
--pid "$(GUNICORN_PIDFILE)" \
--access-logfile "$(GUNICORN_ACCESS_LOG)" \
--error-logfile "$(GUNICORN_ERROR_LOG)" \
--log-file "$(GUNICORN_LOG)" \
--name "$(GUNICORN_NAME)" \
--daemon
check:
ps -ax | grep gunicorn
kill: GUNICORN_PID=$(shell head -1 $(GUNICORN_PIDFILE))
kill: $(GUNICORN_PIDFILE)
kill "$(GUNICORN_PID)"
# start interactive shell
shell:
python manage.py shell
# run arbitrary user-passed command
CMD:=
cmd:
$(CMD)
# run the app's test suite
test:
python manage.py test
# test report output
test-report:
interpreter/report.py "interpreter/fixtures/SeraSeq.tsv" > report.html
# test variant interpretation
test-interpret:
python -c 'import interpreter.interpret'
interpreter/interpret.py "interpreter/fixtures/SeraSeq.tsv"
# write the unique tumor and tissue types to JSON files in the current directory from the PMKB file
get-pmkb-tumor-tissue-types:
interpreter/scripts/get_tissue_tumor_types.py
# ~~~~~ RESET ~~~~~ #
# re-initialize just the databases
reinit: nuke
python manage.py makemigrations
python manage.py migrate
python manage.py migrate interpreter --database=interpreter_db
# destroy app database
nuke:
@echo ">>> Removing database items:"; \
rm -rfv interpreter/migrations/__pycache__ && \
rm -fv interpreter/migrations/0*.py && \
rm -fv "$$(python -c 'import os; print(os.path.join("$(DB_DIR)", "$(INTERPRETER_DB)"))')"
# delete the main Django database as well..
nuke-all: nuke
rm -fv "$$(python -c 'import os; print(os.path.join("$(DB_DIR)", "$(DJANGO_DB)"))')"