-
Notifications
You must be signed in to change notification settings - Fork 0
/
lc_calc_multiple_cnr.py
53 lines (46 loc) · 2.01 KB
/
lc_calc_multiple_cnr.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
"""
Takes a list of subjects and calculates neuromelanin CNR for each. These values
are saved out to a file in each subject's directory.
"""
import os, sys
import argparse
import lc_calc_cnr
from glob import glob
def calc_multiple_cnr(basedir, mask_name, sublist, force=False):
for subj in sublist:
subjdir = os.path.join(basedir, subj)
infileglob = os.path.join(subjdir, 'LC_[FT]SE.nii*')
infile = glob(infileglob)
if len(infile) > 1:
raise ValueError('Multiple image files found! %s' % infile)
elif len(infile) == 0:
continue
else:
infile = infile[0]
maskglob = os.path.join(subjdir, mask_name.split(".")[0] + ".nii*")
mask_file = glob(maskglob)
if len(mask_file) > 1:
raise ValueError('Multiple mask files found! %s' % mask_file)
elif len(mask_file) == 0:
continue
elif os.path.isfile(mask_file[0]):
mask_file = mask_file[0]
lc_calc_cnr.cnr_to_file(infile, mask_file, force=force)
else:
continue
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""This is a script to calculate LC CNR for multiple subjects and save to file.""")
parser.add_argument('-d', '--basedir', type=str, required=True,
help='Base directory containing subject folders.')
parser.add_argument('-m', '--mask',required=True, type=str,
help='Mask file name. (File containing marked ROIs)')
parser.add_argument('-s','--subjects', nargs='+', required=True,
help='List of subject names')
parser.add_argument('-f','--force', action="store_true", default=False,
help='Force overwrite of existing results file (default = False)')
if len(sys.argv) == 1:
parser.print_help()
else:
args = parser.parse_args()
### Begin running script ###
calc_multiple_cnr(args.basedir, args.mask, args.subjects, args.force)