forked from ChangLabSNU/VaxPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnakefile
135 lines (118 loc) · 5.04 KB
/
Snakefile
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
import os
import subprocess
import pathlib
from time import localtime
from snakemake.utils import min_version
PROJECT = "hybrid-sentry-434815-v3"
MACHINE_TYPE = "c2d-highcpu-56"
IMAGE = "ubuntu-2204-lts"
BOOT_DISK_SIZE = "10GB"
min_version("8.17.0")
rule all:
input: "instance_deleted.txt"
rule create_instance:
params:
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "instance_created.txt"
shell:
"""
gcloud compute --project={PROJECT} instances create {params.INSTANCE_NAME} \
--zone={params.ZONE} --machine-type={MACHINE_TYPE} \
--image-family={IMAGE} --image-project=ubuntu-os-cloud \
--boot-disk-size={BOOT_DISK_SIZE} \
&& touch {output}
"""
rule add_ssh_key_to_instance:
input: "instance_created.txt"
params:
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "ssh_key_added.txt"
shell:
"""
gcloud compute instances add-metadata {params.INSTANCE_NAME} \
--zone={params.ZONE} --metadata "ssh-keys=$(whoami):$(cat ~/.ssh/id_rsa.pub)"
maxtries=12
count=0
until gcloud compute ssh {params.INSTANCE_NAME} --zone={params.ZONE} --command "echo 'SSH key applied'" >/dev/null 2>&1 || [ $count -ge $maxtries ]; do
sleep 3
count=$((count+1))
done
if [ $count -ge $maxtries ]; then
echo "SSH key propagation failed after $maxtries attempts." && exit 1;
fi
touch {output}
"""
rule broadcast_data:
input: "ssh_key_added.txt"
params:
seq=config['input'],
config=config['vaxpress-config'],
SCRIPT = workflow.source_path("./gcloud-setup.sh"),
LD_PATH = os.path.join(workflow.basedir, "contrib", "LinearDesign")
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "copied_data.txt"
shell:
"""
gcloud compute scp --strict-host-key-checking=no {params.seq} {params.INSTANCE_NAME}:sequence.fasta\
--zone={params.ZONE} \
&& gcloud compute scp --strict-host-key-checking=no {params.config} {params.INSTANCE_NAME}:config.json \
--zone={params.ZONE} \
&& gcloud compute scp --strict-host-key-checking=no {params.SCRIPT} {params.INSTANCE_NAME}:~ \
--zone={params.ZONE} \
&& gcloud compute scp --recurse --strict-host-key-checking=no {params.LD_PATH} {params.INSTANCE_NAME}:~ \
--zone={params.ZONE} \
&& touch {output}
"""
rule run_shell_script:
input: "copied_data.txt"
params:
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "ran_script.txt"
shell:
"""
gcloud compute ssh --strict-host-key-checking=no {params.INSTANCE_NAME} --zone={params.ZONE} --command \
'bash gcloud-setup.sh' \
&& gcloud compute ssh {params.INSTANCE_NAME} --command "cd ./LinearDesign && make" \
--zone={params.ZONE} \
&& touch {output}
"""
rule run_vaxpress:
input: "ran_script.txt"
params:
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "simulation_complete.txt"
shell:
"""
gcloud compute ssh --strict-host-key-checking=no {params.INSTANCE_NAME} --zone={params.ZONE} --command \
'source VaxPress/.venv/bin/activate && vaxpress -p $(nproc) -i sequence.fasta -o results --preset config.json --lineardesign-dir ~/LinearDesign' \
&& touch {output}
"""
rule download_output:
input: "simulation_complete.txt"
params:
output=config['output-dir'],
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "output_downloaded.txt"
shell:
"""
gcloud compute scp --strict-host-key-checking=no --recurse {params.INSTANCE_NAME}:results {params.output} --zone={params.ZONE}\
&& touch {output}
"""
rule delete_instance:
input: "output_downloaded.txt"
params:
INSTANCE_NAME=config.get("instance-name", f"vaxpress-instance-{localtime().tm_hour}-{localtime().tm_min}-{localtime().tm_sec}"),
ZONE=config.get("zone", "asia-south1-a")
output: "instance_deleted.txt"
shell:
"""
gcloud compute instances delete {params.INSTANCE_NAME} \
--zone={params.ZONE} --quiet \
&& touch {output}
"""