-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
168 lines (136 loc) · 4.74 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
SHELL:=/bin/bash
UNAME:=$(shell uname)
TIMESTAMP=$(shell date '+%Y-%m-%d-%H-%M-%S')
# ~~~~~ Setup Conda ~~~~~ #
PATH:=$(CURDIR)/conda/bin:$(PATH)
unexport PYTHONPATH
unexport PYTHONHOME
# install versions of conda for Mac or Linux, Python 2 or 3
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 \
django=2.2.5 \
conda=4.5.4 \
sqlparse=0.3.0
# ~~~~~ SETUP DJANGO APP ~~~~~ #
# setting up & re-setting up the app
# setup:
# django-admin startproject tuco .
# python manage.py startapp lims
init:
python manage.py makemigrations
python manage.py migrate
python manage.py migrate lims --database=lims_db
python manage.py createsuperuser
# re-initialize just the databases
reinit:
python manage.py makemigrations
python manage.py migrate
python manage.py migrate lims --database=lims_db
# ~~~~~ RUN ~~~~~ #
# shortcut commands for running and managing the app
# export SECRET_KEY:=$(shell cat ../secret-key.txt)
export DB_DIR:=$(CURDIR)/db
export DB_BACKUP_BASEDIR:=$(CURDIR)/backup
export DB_BACKUP_DIR:=$(DB_BACKUP_BASEDIR)/$(TIMESTAMP)
export SECRET_KEY:=foo
export LIMS_DB:=$(DB_DIR)/lims.sqlite3
export DJANGO_DB:=$(DB_DIR)/db.sqlite3
export MEDIA_ROOT:=uploads
export MEDIA_ROOT_TEST:=uploads-test
export DJANGO_ENABLE_DEBUG:=1
export FIXTURES_DIR:=fixtures
# dirs containing sequencing samplesheets and runs
export SAMPLESHEETS_EXTERNAL_DIR:=$(CURDIR)/examples/samplesheets
# _SAMPLESHEETS:=$(shell python -c 'import os; print(os.path.realpath("$(SAMPLESHEETS)"));')
export RUNS:=example-data/runs
# _RUNS:=$(shell python -c 'import os; print(os.path.realpath("$(RUNS)"));')
CMD:=
# run Django 'manage'
manage:
python manage.py $(CMD)
# create admin user
createsuperuser:
python manage.py createsuperuser
# runs the web server
runserver:
python manage.py runserver
# start interactive shell
shell:
python manage.py shell
# prepare database migrations
makemigrations:
python manage.py makemigrations $(CMD)
# migrate databses
migrate:
python manage.py migrate $(CMD)
backup: $(DB_BACKUP_DIR)
gzip "$(LIMS_DB)" -c > "$(DB_BACKUP_DIR)/$$(basename $(LIMS_DB)).gz"
gzip "$(DJANGO_DB)" -c > "$(DB_BACKUP_DIR)/$$(basename $(DJANGO_DB)).gz"
$(DB_BACKUP_DIR):
mkdir -p "$(DB_BACKUP_DIR)"
# ~~~~~ IMPORT/EXPORT DATA ~~~~~ #
# add, remove, delete entries from the database
# batch import into the database
import:
python lims/importer.py fixtures/experiments/Experiment1/SampleSheet.csv
python lims/importer.py fixtures/experiments/Experiment2/SampleSheet.csv
python lims/importer.py fixtures/experiments/Experiment3/SampleSheet.csv
# dump the database for viewing
dump:
sqlite3 -column -header lims.sqlite3 "select * from lims_experiment"
sqlite3 -column -header lims.sqlite3 "select * from lims_ngs580experiment"
sqlite3 -column -header lims.sqlite3 "select * from lims_ngs580samplesheet"
sqlite3 -column -header lims.sqlite3 "select * from lims_ngs580sample"
# sqlite3 lims.sqlite3 .dump
# quick search for terms among the project files for refactoring, etc
VAR:=
search:
find . -type f ! -name "*.pyc" ! -name '*.sqlite3*' ! -path '*.git/*' ! -path '*/conda/*' ! -path '*/migrations/*' -exec grep -wl "$(VAR)" {} \;
# ~~~~~ DEBUGGING ~~~~~ #
# destroy lims database
nuke:
rm -rf lims/migrations/__pycache__
rm -f lims/migrations/0*.py
rm -f "$(LIMS_DB)"
# run unit tests
test:
python manage.py test lims
# run a command in the environment set up with conda
run:
$(CMD)
# for debugging; start interactive shells with environment setup
python:
python
bash:
bash
# ~~~~~ DONT USE THESE:
# remove all entries from data db's
clear-db-runs:
echo 'from lims.models import SequencingRun; SequencingRun.objects.all().delete();' | python manage.py shell
clear-db-samples:
echo 'from lims.models import SequencingSample; SequencingSample.objects.all().delete();' | python manage.py shell
clear-db-samplesheets:
echo 'from lims.models import SequencingSampleSheet; SequencingSampleSheet.objects.all().delete();' | python manage.py shell
clear-db: clear-db-runs clear-db-samplesheets clear-db-samples
# delete all db contents then re-import
reset-lims-db: clear-db
$(MAKE) import-lims-db
# print db contents
all-runs:
echo 'from lims.models import SequencingRun; print(SequencingRun.objects.all());' | python manage.py shell
all-samples:
echo 'from lims.models import DemuxSample; print(DemuxSample.objects.all());' | python manage.py shell
all-samplesheets:
echo 'from lims.models import SequencingSampleSheet; print(SequencingSampleSheet.objects.all());' | python manage.py shell