Skip to content

Commit

Permalink
Merge pull request #15 from VUIIS/suffix_proc
Browse files Browse the repository at this point in the history
Suffix proc
  • Loading branch information
bud42 committed Jul 2, 2015
2 parents dab01d6 + aaad51a commit 502d5dd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
3 changes: 2 additions & 1 deletion bin/dax_tools/dax_manager
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ def check_number_process(project_settings, proc_name):
""" return the number of processes if more than just one set """
proc_name_tags = project_settings[proc_name[8:]+'_proc_name'].split(';')
spider_tags = project_settings[proc_name[8:]+'_spider_path'].split(';')
suffix_tags = project_settings[proc_name[8:]+'_suffix_proc'].split(';')
version_tags = project_settings[proc_name[8:]+'_version'].split(';')
return max(len(l) for l in [proc_name_tags, spider_tags, version_tags])
return max(len(l) for l in [proc_name_tags, spider_tags, suffix_tags, version_tags])

def read_procname(project_settings, index, field_name, field_note):
""" return procname from REDCap"""
Expand Down
17 changes: 15 additions & 2 deletions dax/XnatUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
5) Other Methods
6) Cached Class for DAX
7) Old download functions still used in some spiders
"""

import re
Expand Down Expand Up @@ -125,7 +127,7 @@ def select_assessor(self, intf):

class SpiderProcessHandler:
""" Handle the results of a spider """
def __init__(self, script_name, project, subject, experiment, scan=None):
def __init__(self, script_name, suffix, project, subject, experiment, scan=None):
""" initialization """
#Variables:
self.error = 0
Expand All @@ -140,12 +142,23 @@ def __init__(self, script_name, project, subject, experiment, scan=None):

#ge the processname from spider
if len(re.split("/*_v[0-9]/*", script_name)) > 1:
self.version = script_name.split('_v')[-1]
self.version = script_name.split('_v')[-1].replace('_','.')
proctype = re.split("/*_v[0-9]/*", script_name)[0]+'_v'+self.version.split('.')[0]
else:
self.version = '1.0.0'
proctype = script_name

#if suffix:
if suffix:
if suffix[0] !='_': #check that it starts with an underscore
suffix = '_'+suffix
suffix = suffix.strip().replace(" ","")\
.replace('/','_').replace('*','_')\
.replace('.','_').replace(',','_')\
.replace('?','_').replace('!','_')\
.replace(';','_').replace(':','_')
proctype = proctype + suffix

#Create the assessor handler
if not scan:
assessor_label = project+'-x-'+subject+'-x-'+experiment+'-x-'+proctype
Expand Down
52 changes: 37 additions & 15 deletions dax/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,35 @@
class Processor(object):
""" Base class for processor """
def __init__(self, walltime_str, memreq_mb, spider_path,
version=None, ppn=1, xsitype='proc:genProcData'):
version=None, ppn=1, suffix_proc='',
xsitype='proc:genProcData'):
""" init function """
self.walltime_str = walltime_str # 00:00:00 format
self.memreq_mb = memreq_mb # memory required in megabytes
#default values
self.version = '1.0.0'
#default values:
self.version = "1.0.0"
if not suffix_proc:
self.suffix_proc=''
else:
if suffix_proc and suffix_proc[0] != '_':
self.suffix_proc = '_'+suffix_proc
else:
self.suffix_proc = suffix_proc

self.suffix_proc = self.suffix_proc.strip().replace(" ","")\
.replace('/','_').replace('*','_')\
.replace('.','_').replace(',','_')\
.replace('?','_').replace('!','_')\
.replace(';','_').replace(':','_')
self.name = None
self.spider_path = spider_path
#getting name and version from spider_path
self.set_spider_settings(spider_path, version)
self.ppn = ppn
self.xsitype = xsitype
#getting name and version from spider_path
self.set_spider_settings(spider_path, version)
#if suffix_proc is empty, set it to "" for the spider call:
if not suffix_proc:
self.suffix_proc = '""'

#get the spider_path right with the version:
def set_spider_settings(self, spider_path, version):
Expand All @@ -34,9 +51,12 @@ def set_spider_settings(self, spider_path, version):
proc_name = re.split("/*_v[0-9]/*", proc_name)[0]
#setting the version and name of the spider
self.version = version
self.name = proc_name+'_v'+self.version.split('.')[0]
self.spider_path = os.path.join(os.path.dirname(spider_path),
'Spider_'+proc_name+'_v'+version+'.py')
self.name = '''{procname}_v{version}{suffix}'''.format(procname=proc_name,
version=self.version.split('.')[0],
suffix=self.suffix_proc)
spider_name = '''Spider_{procname}_v{version}.py'''.format(procname=proc_name,
version=version.replace('.', '_'))
self.spider_path = os.path.join(os.path.dirname(spider_path), spider_name)
else:
self.default_settings_spider(spider_path)

Expand All @@ -46,11 +66,13 @@ def default_settings_spider(self, spider_path):
self.spider_path = spider_path
#set the name and the version of the spider
if len(re.split("/*_v[0-9]/*", spider_path)) > 1:
self.version = os.path.basename(spider_path)[7:-3].split('_v')[-1]
self.version = os.path.basename(spider_path)[7:-3].split('_v')[-1].replace('_','.')
spidername = os.path.basename(spider_path)[7:-3]
self.name = re.split("/*_v[0-9]/*", spidername)[0]+'_v'+self.version.split('.')[0]
self.name = '''{procname}_v{version}{suffix}'''.format(procname=re.split("/*_v[0-9]/*", spidername)[0],
version=self.version.split('.')[0],
suffix=self.suffix_proc)
else:
self.name = os.path.basename(spider_path)[7:-3]
self.name = os.path.basename(spider_path)[7:-3]+self.suffix_proc

# has_inputs - does this object have the required inputs?
# e.g. NIFTI format of the required scan type and quality and are there no conflicting inputs.
Expand Down Expand Up @@ -79,9 +101,9 @@ def has_inputs(self):
"""
raise NotImplementedError()

def __init__(self, scan_types, walltime_str, memreq_mb, spider_path, version=None, ppn=1):
def __init__(self, scan_types, walltime_str, memreq_mb, spider_path, version=None, ppn=1, suffix_proc=''):
""" init function overridden from base class """
super(ScanProcessor, self).__init__(walltime_str, memreq_mb, spider_path, version, ppn)
super(ScanProcessor, self).__init__(walltime_str, memreq_mb, spider_path, version, ppn, suffix_proc)
if isinstance(scan_types, list):
self.scan_types = scan_types
elif isinstance(scan_types, str):
Expand Down Expand Up @@ -127,9 +149,9 @@ def has_inputs(self):
"""
raise NotImplementedError()

def __init__(self, walltime_str, memreq_mb, spider_path, version=None, ppn=1):
def __init__(self, walltime_str, memreq_mb, spider_path, version=None, ppn=1, suffix_proc=''):
""" init function overridden from base class """
super(SessionProcessor, self).__init__(walltime_str, memreq_mb, spider_path, version, ppn)
super(SessionProcessor, self).__init__(walltime_str, memreq_mb, spider_path, version, ppn, suffix_proc)

def should_run(self, session_dict):
""" return if the assessor should exist. Always true on a session """
Expand Down

0 comments on commit 502d5dd

Please sign in to comment.