-
Notifications
You must be signed in to change notification settings - Fork 2
/
bht_Spike2toManSort.py
161 lines (130 loc) · 5.62 KB
/
bht_Spike2toManSort.py
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
"""
Code that goes along with the Airflow located at:
http://airflow.readthedocs.org/en/latest/tutorial.html
"""
from airflow import DAG
from airflow.operators import BashOperator, EmailOperator, SlackAPIPostOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'btheilma',
'start_date': datetime(2015,12,01),
'email': ['btheilma@ucsd.edu'],
'email_on_failure': True,
'email_on_retry': True,
'retries': 0,
'retry_delay': timedelta(minutes=5),
}
USER = 'btheilma'
def as_user(cmd,username):
return "sudo -u %s sh -c '%s'" % (username,cmd)
SLACK_TOKEN = 'xoxp-8710210593-8710210785-17586684384-e5abadd63e'
ANACONDA_PATH = '/usr/local/anaconda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
PHY_PATH = "/usr/local/anaconda/envs/phy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
make_klustadir_cmd = "mkdir -p /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }}"
make_kwd_command = "make_kwd burung16 A1x16-5mm-50 /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/matfiles/{{ params.block }}/ /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }} -s 31250 -a none"
def on_kwd_failure(context):
# clear out the klusta dir
pass
# sort spikes
sort_spikes_command = "cd /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }} ; phy spikesort params.prm"
clear_phy_cmd = "rm -rf /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }}/*.phy"
# merge events
merge_events_cmd = "merge_stim_kwik /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/matfiles/{{ params.block }}/ /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }}"
# make kwik bakup dir
make_kwik_bak_dir_cmd = "mkdir -p /mnt/cube/btheilma/kwik_bak/{{ params.birdid }}"
#
mv_kwik_bak_cmd = "mv /mnt/lintu/home/btheilma/experiments/{{ params.birdid }}/klusta/{{ params.block }}/*.kwik.bak /mnt/cube/btheilma/kwik_bak/{{ params.birdid }}"
# rsync
rsync_command = "nice +5 rsync -azP --relative {{ params.klustadir }} {{ params.mansortdir }}"
with open('/mnt/lintu/home/Gentnerlab/airflow/dags/bht_birds.tsv','r') as f:
for line in f:
args = line.strip().split()
if len(args) < 2:
continue
BIRD = args[0]
BLOCK = args[1]
OMIT = ''
KLUSTA_DIR = '/mnt/lintu/home/btheilma/experiments/%s/klusta/%s/' % (BIRD, BLOCK)
MATFILE_DIR = '/mnt/lintu/home/btheilma/experiments/%s/matfiles/%s' % (BIRD, BLOCK)
KWIKBAK_DIR = '/mnt/cube/btheilma/kwik_bak/%s/' % BIRD
MANSORT_DIR = 'btheilma@niao.ucsd.edu:/home/btheilma/experiments/'
dag_id = USER + BLOCK
dag = DAG(dag_id,
default_args=default_args,
schedule_interval='@once',
)
make_klusta_dir_task = BashOperator(
task_id='make_klusta_dir',
bash_command=make_klustadir_cmd,
params={'block': BLOCK,
'birdid': BIRD},
dag=dag)
make_kwd_task = BashOperator(
task_id='make_kwd',
pool='make_kwd',
bash_command=make_kwd_command,
env={'PATH': ANACONDA_PATH},
params={'block': BLOCK,
'omit': OMIT,
'birdid': BIRD},
dag=dag)
phy_task = BashOperator(
task_id='phy_spikesort',
pool='phy',
env={'PATH': PHY_PATH},
bash_command=sort_spikes_command,
params={'block': BLOCK,
'birdid': BIRD},
dag=dag)
#merge_events_task = BashOperator(
# task_id='merge_events',
# bash_command=merge_events_cmd,
# env={'PATH': ANACONDA_PATH},
# params={'block': BLOCK},
# dag=dag)
clear_phy_task = BashOperator(
task_id='clear_phy',
bash_command=clear_phy_cmd,
params={'block': BLOCK,
'birdid': BIRD},
dag=dag)
make_kwik_bak_dir_task = BashOperator(
task_id='make_kwik_bak_dir',
bash_command=make_kwik_bak_dir_cmd,
params={'birdid': BIRD},
dag=dag)
mv_kwik_bak_task = BashOperator(
task_id='move_kwik_bak',
bash_command=mv_kwik_bak_cmd,
params={'block': BLOCK,
'birdid': BIRD},
dag=dag)
rsync_task = BashOperator(
task_id='rsync',
bash_command=rsync_command,
params={'block': BLOCK},
dag=dag)
email_me = EmailOperator(
task_id='email_me',
to=default_args['email'],
subject='%s is complete' % dag_id,
html_content='you can now manually sort on niao',
dag=dag)
slack_it = SlackAPIPostOperator(
task_id='slack_it',
token=SLACK_TOKEN,
text='%s is complete' % dag_id,
channel='#ephys',
dag=dag)
make_kwd_task.set_upstream(make_klusta_dir_task)
phy_task.set_upstream(make_kwd_task)
#merge_events_task.set_upstream(phy_task)
clear_phy_task.set_upstream(phy_task)
make_kwik_bak_dir_task.set_upstream(phy_task)
mv_kwik_bak_task.set_upstream(make_kwik_bak_dir_task)
#rsync_task.set_upstream(merge_events_task)
rsync_task.set_upstream(clear_phy_task)
rsync_task.set_upstream(mv_kwik_bak_task)
email_me.set_upstream(rsync_task)
slack_it.set_upstream(rsync_task)
globals()[dag_id] = dag