-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc04_desc-CognitionNetwork_qsub.py
57 lines (52 loc) · 2.32 KB
/
c04_desc-CognitionNetwork_qsub.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
'''
Author: Feng Sang ([email protected])
Date: 2021-10-08 18:56:00
LastEditTime: 2021-10-10 10:40:57
FilePath: /S_task-StrucCovNet/Analysis/a08_desc-dk40/c04_desc-CognitionNetwork_qsub.py
'''
import os
import re
import time
import logging
logging.basicConfig(level=logging.INFO)
def func_submit(mission_name, shell_path, error_path, log_path, num_nodes=1, ppn=2, servername='zhang'):
n_core = f'nodes={num_nodes}:ppn={ppn}'
cmd = f'qsub -N {mission_name} -l {n_core} -q {servername} -e {error_path} -o {log_path} {shell_path}'
logging.info(cmd)
os.system(cmd)
def func_generate_script(template_path, root, cog, pre, n_cores, data_path, output):
with open(template_path, 'r') as f:
lines = f.readlines()
# replace variable
lines = [re.sub('{@root&}', root, i) for i in lines]
lines = [re.sub('{@cog&}', cog, i) for i in lines]
lines = [re.sub('{@ncores&}', str(n_cores), i) for i in lines]
lines = [re.sub('{@datapath&}', data_path, i) for i in lines]
new_lines = [re.sub('{@pre&}', pre, i) for i in lines]
with open(output, 'w') as f:
f.writelines(new_lines)
return output
if __name__ == '__main__':
root = '/brain/babri_in/sangf/Projects/S_task-StrucCovNet'
template_path = 'c04_desc-CognitionNetwork.sh'
n_cores = 12
servername = 'zhang'
cogs = ['Global', 'Memory', 'Attention', 'Execution', 'Language', 'Visualspatial']
pres = ['deg', 'hub_n', 'nonhub_n', 'feedn_n', 'feedh_n']
for cog in cogs:
for pre in pres:
logging.info(f"{cog}: {pre}")
log_path = os.path.join(root, 'Derivation', 'Tmp', 'atl-dk40')
if not os.path.exists(log_path):
os.makedirs(log_path)
shell_path = func_generate_script(
template_path=os.path.abspath(template_path),
root=root,
cog=cog,
pre=pre,
n_cores=n_cores,
data_path=os.path.join(root, 'Derivation', 'ana-net', 'atl-dk40_node-68', 'subs_meas-elasticnet_net-js_thrd-bootstrap.csv'),
output=os.path.join(log_path, f'{cog}_{pre}.sh'))
error_path = os.path.join(log_path, f'{cog}_{pre}_error.log')
func_submit(f'{cog}-{pre}', shell_path, error_path, log_path, ppn=n_cores, servername=servername)
time.sleep(1)