Skip to content
Snippets Groups Projects
Commit b29ea4d2 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

RF: Make Context sub-class from Config, and a few associated changes

parent d0cba1fc
No related branches found
No related tags found
1 merge request!4ENH: Config file templating
import os.path as op
basedir = op.dirname(__file__)
__version__ = open(op.join(basedir, 'VERSION')).read()
BIPDIR = op.dirname(__file__)
__version__ = open(op.join(BIPDIR, 'VERSION')).read()
......@@ -25,6 +25,8 @@ import json
from file_tree import FileTree
from pipe_tree import Pipeline, Ref
import bip
from bip.utils import get_data
from bip.utils.config import Config
from bip.utils.log_utils import setup_logging
from bip.pipelines import struct_T1, struct_T2_FLAIR, struct_FS
from bip.pipelines import struct_swMRI, struct_asl, IDPs_gen
......@@ -44,14 +46,17 @@ class Usage(Exception):
def __init__(self, msg):
self.msg = msg
class Context:
def __init__(self, subject=""):
self.subject = subject
self.BIPDIR = bip.__path__[0]
self.FSLDIR = os.environ['FSLDIR']
self.gdc = self.get_data('GDC/UKB.txt')
class Context(Config):
def __init__(self, subject, *args, **kwargs):
Config.__init__(self, *args, **kwargs)
self.subject = subject
self.BIPDIR = bip.BIPDIR
self.FSLDIR = os.environ['FSLDIR']
with open(self.get_data('dMRI/autoptx/struct_list.json'), 'r',
encoding="utf-8") as f:
......@@ -76,16 +81,10 @@ class Context:
return basedir + fileName
def get_data(self, fileName):
fileName.replace('/', os.sep)
basedir = self.BIPDIR + os.sep + 'data' + os.sep
return basedir + fileName
#def save_context(self, file_name):
# with open(file_name, "wt") as config_file:
# config_file.write(self.to_json())
return bip.utils.get_data(fileName)
def parseArguments(ctx):
def parseArguments():
#########################
# ARGUMENT PARSING CODE #
......@@ -103,7 +102,7 @@ def parseArguments(ctx):
help='Number of echo times for SWI data (default: 2)',
dest="echoes_SWI")
parser.add_argument("-Q", "--basic_QC_file", action="store", nargs="?",
default=ctx.get_data("config/ideal_config_sizes_UKBB.json"),
default=utils.get_data("config/ideal_config_sizes_UKBB.json"),
help='File with the ideal configuration of the files +'\
'(default: UKB)',
dest="basic_QC_file")
......@@ -161,9 +160,6 @@ def parseArguments(ctx):
if subject[-1] =='/':
subject = subject[0:len(subject)-1]
ctx.subject = subject
ctx.argsa = argsa
# Parsing number of SWI coils argument
if not argsa.coils_SWI:
coils_SWI = 32
......@@ -285,10 +281,9 @@ def parseArguments(ctx):
def main():
#ctx = Context(gdc=)
ctx = Context()
parseArguments(ctx)
args = parseArguments()
ctx = Context(args.subject)
ctx.argsa = args
setup_logging(op.join(ctx.subject, 'logs', 'main.log'))
......
......@@ -14,6 +14,8 @@ import os
import time
import errno
import bip
log = logging.getLogger(__name__)
......@@ -49,3 +51,9 @@ def lockdir(dirname, delay=5):
log.debug('Relinquishing lock on %s', dirname)
os.close( fd)
os.unlink(lockfile)
def get_data(filename):
"""Return the filename, prefixed with the bip/data/ directory path. """
filename.replace('/', os.sep)
return op.join(bipdir, 'data', filename)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment