Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BIP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
BIP
Commits
b29ea4d2
Commit
b29ea4d2
authored
2 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Make Context sub-class from Config, and a few associated changes
parent
d0cba1fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Config file templating
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bip/__init__.py
+2
-2
2 additions, 2 deletions
bip/__init__.py
bip/main.py
+17
-22
17 additions, 22 deletions
bip/main.py
bip/utils/__init__.py
+8
-0
8 additions, 0 deletions
bip/utils/__init__.py
with
27 additions
and
24 deletions
bip/__init__.py
+
2
−
2
View file @
b29ea4d2
import
os.path
as
op
import
os.path
as
op
basedir
=
op
.
dirname
(
__file__
)
BIPDIR
=
op
.
dirname
(
__file__
)
__version__
=
open
(
op
.
join
(
basedir
,
'
VERSION
'
)).
read
()
__version__
=
open
(
op
.
join
(
BIPDIR
,
'
VERSION
'
)).
read
()
This diff is collapsed.
Click to expand it.
bip/main.py
+
17
−
22
View file @
b29ea4d2
...
@@ -25,6 +25,8 @@ import json
...
@@ -25,6 +25,8 @@ import json
from
file_tree
import
FileTree
from
file_tree
import
FileTree
from
pipe_tree
import
Pipeline
,
Ref
from
pipe_tree
import
Pipeline
,
Ref
import
bip
import
bip
from
bip.utils
import
get_data
from
bip.utils.config
import
Config
from
bip.utils.log_utils
import
setup_logging
from
bip.utils.log_utils
import
setup_logging
from
bip.pipelines
import
struct_T1
,
struct_T2_FLAIR
,
struct_FS
from
bip.pipelines
import
struct_T1
,
struct_T2_FLAIR
,
struct_FS
from
bip.pipelines
import
struct_swMRI
,
struct_asl
,
IDPs_gen
from
bip.pipelines
import
struct_swMRI
,
struct_asl
,
IDPs_gen
...
@@ -44,14 +46,17 @@ class Usage(Exception):
...
@@ -44,14 +46,17 @@ class Usage(Exception):
def
__init__
(
self
,
msg
):
def
__init__
(
self
,
msg
):
self
.
msg
=
msg
self
.
msg
=
msg
class
Context
:
def
__init__
(
self
,
subject
=
""
):
self
.
subject
=
subject
class
Context
(
Config
):
self
.
BIPDIR
=
bip
.
__path__
[
0
]
self
.
FSLDIR
=
os
.
environ
[
'
FSLDIR
'
]
def
__init__
(
self
,
subject
,
*
args
,
**
kwargs
):
self
.
gdc
=
self
.
get_data
(
'
GDC/UKB.txt
'
)
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
'
,
with
open
(
self
.
get_data
(
'
dMRI/autoptx/struct_list.json
'
),
'
r
'
,
encoding
=
"
utf-8
"
)
as
f
:
encoding
=
"
utf-8
"
)
as
f
:
...
@@ -76,16 +81,10 @@ class Context:
...
@@ -76,16 +81,10 @@ class Context:
return
basedir
+
fileName
return
basedir
+
fileName
def
get_data
(
self
,
fileName
):
def
get_data
(
self
,
fileName
):
fileName
.
replace
(
'
/
'
,
os
.
sep
)
return
bip
.
utils
.
get_data
(
fileName
)
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())
def
parseArguments
(
ctx
):
def
parseArguments
():
#########################
#########################
# ARGUMENT PARSING CODE #
# ARGUMENT PARSING CODE #
...
@@ -103,7 +102,7 @@ def parseArguments(ctx):
...
@@ -103,7 +102,7 @@ def parseArguments(ctx):
help
=
'
Number of echo times for SWI data (default: 2)
'
,
help
=
'
Number of echo times for SWI data (default: 2)
'
,
dest
=
"
echoes_SWI
"
)
dest
=
"
echoes_SWI
"
)
parser
.
add_argument
(
"
-Q
"
,
"
--basic_QC_file
"
,
action
=
"
store
"
,
nargs
=
"
?
"
,
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 +
'
\
help
=
'
File with the ideal configuration of the files +
'
\
'
(default: UKB)
'
,
'
(default: UKB)
'
,
dest
=
"
basic_QC_file
"
)
dest
=
"
basic_QC_file
"
)
...
@@ -161,9 +160,6 @@ def parseArguments(ctx):
...
@@ -161,9 +160,6 @@ def parseArguments(ctx):
if
subject
[
-
1
]
==
'
/
'
:
if
subject
[
-
1
]
==
'
/
'
:
subject
=
subject
[
0
:
len
(
subject
)
-
1
]
subject
=
subject
[
0
:
len
(
subject
)
-
1
]
ctx
.
subject
=
subject
ctx
.
argsa
=
argsa
# Parsing number of SWI coils argument
# Parsing number of SWI coils argument
if
not
argsa
.
coils_SWI
:
if
not
argsa
.
coils_SWI
:
coils_SWI
=
32
coils_SWI
=
32
...
@@ -285,10 +281,9 @@ def parseArguments(ctx):
...
@@ -285,10 +281,9 @@ def parseArguments(ctx):
def
main
():
def
main
():
#ctx = Context(gdc=)
args
=
parseArguments
()
ctx
=
Context
()
ctx
=
Context
(
args
.
subject
)
ctx
.
argsa
=
args
parseArguments
(
ctx
)
setup_logging
(
op
.
join
(
ctx
.
subject
,
'
logs
'
,
'
main.log
'
))
setup_logging
(
op
.
join
(
ctx
.
subject
,
'
logs
'
,
'
main.log
'
))
...
...
This diff is collapsed.
Click to expand it.
bip/utils/__init__.py
+
8
−
0
View file @
b29ea4d2
...
@@ -14,6 +14,8 @@ import os
...
@@ -14,6 +14,8 @@ import os
import
time
import
time
import
errno
import
errno
import
bip
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -49,3 +51,9 @@ def lockdir(dirname, delay=5):
...
@@ -49,3 +51,9 @@ def lockdir(dirname, delay=5):
log
.
debug
(
'
Relinquishing lock on %s
'
,
dirname
)
log
.
debug
(
'
Relinquishing lock on %s
'
,
dirname
)
os
.
close
(
fd
)
os
.
close
(
fd
)
os
.
unlink
(
lockfile
)
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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment