-
Notifications
You must be signed in to change notification settings - Fork 1
/
Subject.py
61 lines (50 loc) · 1.99 KB
/
Subject.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
import Scan
import os.path
import warnings
import string
class Subject(object):
def __init__(self, study, subid):
self.study = study
self.subid = subid
self.path = os.path.join(self.study.subjects_dir, subid)
self.scanlist = []
self.scans = {}
if not os.path.exists(self.path):
os.makedirs(self.path)
self.findScans()
def findScans(self):
'Returns a list of Scan objects at the subject dir'
try:
scanFiles = os.listdir(self.path)
except:
warnings.warn("\nCould not list files in: " + self.path)
return
for file in scanFiles:
fulldir = os.path.join(self.path, file)
if (not os.path.isdir(fulldir)):
continue
m = self.study.__scanfolderREC__.match(file)
if m:
newscan = Scan.Scan(self, m.group(0))
else:
raise Exception('could not parse ' + fulldir + '\n with regex\n' + self.study.scanfolderRE + '\n Should it be in this directory?\n')
self.scanlist.append(newscan)
self.scans[newscan.scanid] = newscan
def addScan(self, scanid, warn=False):
m = self.study.__scanfolderREC__.match(scanid)
if not m:
warnings.warn('Did not create scan with scanid ' + scanid + '\n::Scan Regex did not match.\n' + 'Regex:: ' + self.study.scanfolderRE)
return False
if (scanid not in self.scans):
newscan = Scan.Scan(self, scanid)
self.scanlist.append(newscan)
self.scans[newscan.scanid] = newscan
return True
elif warn == True:
warnings.warn('Did not create scan with scanid ' + scanid + '::Already Exists.')
return False
def __str__(self):
outstring = 'Subject: %s\n\t' % self.subid
for scan in self.scanlist:
outstring += '%s' % string.replace(scan.__str__(), '\n', '\n\t')
return outstring[0:-1]