Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
03c310d6
Commit
03c310d6
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Adjust unit tests for melodicimage/analysis modules
parent
4fb33a00
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_melodicanalysis.py
+62
-21
62 additions, 21 deletions
tests/test_melodicanalysis.py
tests/test_melodicimage.py
+17
-12
17 additions, 12 deletions
tests/test_melodicimage.py
with
79 additions
and
33 deletions
tests/test_melodicanalysis.py
+
62
−
21
View file @
03c310d6
...
@@ -21,11 +21,23 @@ def test_isMelodicImage():
...
@@ -21,11 +21,23 @@ def test_isMelodicImage():
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_FTmix
'
,
'
analysis.ica/melodic_FTmix
'
,
'
analysis.blica/melodic_IC.nii.gz
'
]
'
analysis.blica/melodic_IC.nii.gz
'
,
'
analysis2.ica/melodic_oIC.nii.gz
'
,
'
analysis2.ica/melodic_mix
'
,
'
analysis2.ica/melodic_FTmix
'
,
'
analysis3.ica/melodic_IC.nii.gz
'
,
'
analysis3.ica/melodic_oIC.nii.gz
'
,
'
analysis3.ica/melodic_mix
'
,
'
analysis3.ica/melodic_FTmix
'
]
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
for
p
in
paths
:
for
p
in
paths
:
expected
=
p
==
'
analysis.ica/melodic_IC.nii.gz
'
expected
=
any
([
p
==
'
analysis.ica/melodic_IC.nii.gz
'
,
p
==
'
analysis2.ica/melodic_oIC.nii.gz
'
,
p
==
'
analysis3.ica/melodic_IC.nii.gz
'
,
p
==
'
analysis3.ica/melodic_oIC.nii.gz
'
])
assert
mela
.
isMelodicImage
(
op
.
join
(
testdir
,
p
))
==
expected
assert
mela
.
isMelodicImage
(
op
.
join
(
testdir
,
p
))
==
expected
...
@@ -38,6 +50,11 @@ def test_isMelodicDir():
...
@@ -38,6 +50,11 @@ def test_isMelodicDir():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
mela
.
isMelodicDir
(
meldir
)
assert
mela
.
isMelodicDir
(
meldir
)
# melodic_oIC is ok
with
tests
.
testdir
([
p
.
replace
(
'
ic_IC
'
,
'
ic_oIC
'
)
for
p
in
paths
])
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
mela
.
isMelodicDir
(
meldir
)
# Directory must end in .ica
# Directory must end in .ica
with
tests
.
testdir
([
p
.
replace
(
'
.ica
'
,
'
.blob
'
)
for
p
in
paths
])
as
testdir
:
with
tests
.
testdir
([
p
.
replace
(
'
.ica
'
,
'
.blob
'
)
for
p
in
paths
])
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.blob
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.blob
'
)
...
@@ -54,6 +71,12 @@ def test_isMelodicDir():
...
@@ -54,6 +71,12 @@ def test_isMelodicDir():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
not
mela
.
isMelodicDir
(
meldir
)
assert
not
mela
.
isMelodicDir
(
meldir
)
# same test for melodic_oIC
for
p
in
perms
:
with
tests
.
testdir
([
pp
.
replace
(
'
ic_IC
'
,
'
ic_oIC
'
)
for
pp
in
p
])
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
not
mela
.
isMelodicDir
(
meldir
)
def
test_getAnalysisDir
():
def
test_getAnalysisDir
():
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
...
@@ -70,20 +93,30 @@ def test_getAnalysisDir():
...
@@ -70,20 +93,30 @@ def test_getAnalysisDir():
for
tp
in
testpaths
:
for
tp
in
testpaths
:
assert
mela
.
getAnalysisDir
(
op
.
join
(
testdir
,
tp
))
==
expected
assert
mela
.
getAnalysisDir
(
op
.
join
(
testdir
,
tp
))
==
expected
paths
=
[
'
analysis.ica/melodic_blob.nii.gz
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_FTmix
'
]
with
tests
.
testdir
(
paths
)
as
testdir
:
for
tp
in
testpaths
:
assert
mela
.
getAnalysisDir
(
op
.
join
(
testdir
,
tp
))
is
None
def
test_getTopLevelAnalysisDir
():
def
test_getTopLevelAnalysisDir
():
testpaths
=
[
testpaths
=
[
(
'
REST.ica/filtered_func_data.ica/melodic_IC.nii.gz
'
,
'
REST.ica
'
),
(
'
REST.ica/filtered_func_data.ica/melodic_IC.nii.gz
'
,
'
REST.ica
'
),
(
'
REST.ica/filtered_func_data.ica/melodic_mix
'
,
'
REST.ica
'
),
(
'
REST.ica/filtered_func_data.ica/melodic_mix
'
,
'
REST.ica
'
),
(
'
analysis.gica/groupmelodic.ica/melodic_IC.nii.gz
'
,
'
analysis.gica
'
),
(
'
analysis.gica/groupmelodic.ica/melodic_IC.nii.gz
'
,
'
analysis.gica
'
),
(
'
analysis.feat/filtered_func_data.ica/melodic_mix
'
,
'
analysis.feat
'
)]
(
'
analysis.feat/filtered_func_data.ica/melodic_mix
'
,
'
analysis.feat
'
),
(
'
not/any/analysis/directories/here/melodic_IC.nii.gz
'
,
None
),
]
for
tp
,
expected
in
testpaths
:
for
tp
,
expected
in
testpaths
:
assert
mela
.
getTopLevelAnalysisDir
(
tp
)
==
expected
assert
mela
.
getTopLevelAnalysisDir
(
tp
)
==
expected
def
test_getDataFile
():
def
test_getDataFile
():
testcases
=
[([
'
analysis.ica/filtfunc.ica/melodic_IC.nii.gz
'
,
testcases
=
[([
'
analysis.ica/filtfunc.ica/melodic_IC.nii.gz
'
,
'
analysis.ica/filtfunc.ica/melodic_mix
'
,
'
analysis.ica/filtfunc.ica/melodic_mix
'
,
'
analysis.ica/filtfunc.ica/melodic_FTmix
'
,
'
analysis.ica/filtfunc.ica/melodic_FTmix
'
,
...
@@ -95,15 +128,23 @@ def test_getDataFile():
...
@@ -95,15 +128,23 @@ def test_getDataFile():
'
analysis.feat/filtfunc.ica/melodic_FTmix
'
,
'
analysis.feat/filtfunc.ica/melodic_FTmix
'
,
'
analysis.feat/filtered_func_data.nii.gz
'
],
'
analysis.feat/filtered_func_data.nii.gz
'
],
'
analysis.feat/filtfunc.ica
'
,
'
analysis.feat/filtfunc.ica
'
,
'
analysis.feat/filtered_func_data.nii.gz
'
)]
'
analysis.feat/filtered_func_data.nii.gz
'
),
([
'
no/analysis/dirs/here/melodic_IC.nii.gz
'
],
'
no/analysis/dirs/here/
'
,
None
),
([
'
analysis.feat/analysis.ica/melodic_IC.nii.gz
'
,
'
analysis.feat/analysis.ica/melodic_mix
'
,
'
analysis.feat/analysis.ica/melodic_FTmix
'
],
'
analysis.feat/analysis.ica
'
,
None
),
]
for
paths
,
meldir
,
expected
in
testcases
:
for
paths
,
meldir
,
expected
in
testcases
:
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
meldir
=
op
.
join
(
testdir
,
meldir
)
expected
=
op
.
join
(
testdir
,
expected
)
assert
mela
.
getDataFile
(
meldir
)
==
expected
assert
mela
.
getDataFile
(
meldir
)
==
expected
def
test_getMeanFile
():
def
test_getMeanFile
():
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_mix
'
,
...
@@ -113,9 +154,9 @@ def test_getMeanFile():
...
@@ -113,9 +154,9 @@ def test_getMeanFile():
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/mean.nii.gz
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/mean.nii.gz
'
)
assert
mela
.
getMeanFile
(
meldir
)
==
expected
assert
mela
.
getMeanFile
(
meldir
)
==
expected
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_FTmix
'
,
'
analysis.ica/melodic_FTmix
'
,
...
@@ -136,7 +177,7 @@ def test_getICFile():
...
@@ -136,7 +177,7 @@ def test_getICFile():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_IC.nii.gz
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_IC.nii.gz
'
)
assert
mela
.
getICFile
(
meldir
)
==
expected
assert
mela
.
getICFile
(
meldir
)
==
expected
paths
=
[
'
analysis.ica/melodic_IC.txt
'
,
paths
=
[
'
analysis.ica/melodic_IC.txt
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_mix
'
,
'
analysis.ica/melodic_FTmix
'
]
'
analysis.ica/melodic_FTmix
'
]
...
@@ -144,8 +185,8 @@ def test_getICFile():
...
@@ -144,8 +185,8 @@ def test_getICFile():
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
with
pytest
.
raises
(
fslpath
.
PathError
):
with
pytest
.
raises
(
fslpath
.
PathError
):
mela
.
getICFile
(
meldir
)
mela
.
getICFile
(
meldir
)
def
test_getMixFile
():
def
test_getMixFile
():
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.nii.gz
'
,
...
@@ -156,7 +197,7 @@ def test_getMixFile():
...
@@ -156,7 +197,7 @@ def test_getMixFile():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_mix
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_mix
'
)
assert
mela
.
getMixFile
(
meldir
)
==
expected
assert
mela
.
getMixFile
(
meldir
)
==
expected
paths
=
[
'
analysis.ica/melodic_IC.ni.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.ni.gz
'
,
'
analysis.ica/melodic_FTmix
'
]
'
analysis.ica/melodic_FTmix
'
]
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
...
@@ -172,12 +213,12 @@ def test_getFTMixFile():
...
@@ -172,12 +213,12 @@ def test_getFTMixFile():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_FTmix
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/melodic_FTmix
'
)
assert
mela
.
getFTMixFile
(
meldir
)
==
expected
assert
mela
.
getFTMixFile
(
meldir
)
==
expected
paths
=
[
'
analysis.ica/melodic_IC.ni.gz
'
,
paths
=
[
'
analysis.ica/melodic_IC.ni.gz
'
,
'
analysis.ica/melodic_mix
'
]
'
analysis.ica/melodic_mix
'
]
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
mela
.
getFTMixFile
(
meldir
)
is
None
assert
mela
.
getFTMixFile
(
meldir
)
is
None
def
test_getReportFile
():
def
test_getReportFile
():
paths
=
[
'
analysis.ica/filtfunc.ica/melodic_IC.nii.gz
'
,
paths
=
[
'
analysis.ica/filtfunc.ica/melodic_IC.nii.gz
'
,
...
@@ -189,13 +230,13 @@ def test_getReportFile():
...
@@ -189,13 +230,13 @@ def test_getReportFile():
meldir
=
op
.
join
(
testdir
,
'
analysis.ica/filtfunc.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica/filtfunc.ica
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/report.html
'
)
expected
=
op
.
join
(
testdir
,
'
analysis.ica/report.html
'
)
assert
op
.
abspath
(
mela
.
getReportFile
(
meldir
))
==
expected
assert
op
.
abspath
(
mela
.
getReportFile
(
meldir
))
==
expected
paths
=
[
'
analysis.ica/filtfunc.ica/melodic_IC.ni.gz
'
,
paths
=
[
'
analysis.ica/filtfunc.ica/melodic_IC.ni.gz
'
,
'
analysis.ica/filtfunc.ica/melodic_mix
'
,
'
analysis.ica/filtfunc.ica/melodic_mix
'
,
'
analysis.ica/filtfunc.ica/melodic_FTmix
'
]
'
analysis.ica/filtfunc.ica/melodic_FTmix
'
]
with
tests
.
testdir
(
paths
)
as
testdir
:
with
tests
.
testdir
(
paths
)
as
testdir
:
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
testdir
,
'
analysis.ica
'
)
assert
mela
.
getReportFile
(
meldir
)
is
None
assert
mela
.
getReportFile
(
meldir
)
is
None
def
test_getNumComponents
():
def
test_getNumComponents
():
...
...
This diff is collapsed.
Click to expand it.
tests/test_melodicimage.py
+
17
−
12
View file @
03c310d6
...
@@ -26,14 +26,15 @@ def _create_dummy_melodic_analysis(basedir,
...
@@ -26,14 +26,15 @@ def _create_dummy_melodic_analysis(basedir,
tr
=
2
,
tr
=
2
,
with_data
=
True
,
with_data
=
True
,
with_reportfile
=
True
,
with_reportfile
=
True
,
with_meanfile
=
True
):
with_meanfile
=
True
,
ic_prefix
=
'
melodic_IC
'
):
tldir
=
op
.
join
(
basedir
,
'
toplevel.ica
'
)
tldir
=
op
.
join
(
basedir
,
'
toplevel.ica
'
)
meldir
=
op
.
join
(
tldir
,
'
analysis.ica
'
)
meldir
=
op
.
join
(
tldir
,
'
analysis.ica
'
)
datafile
=
op
.
join
(
tldir
,
'
filtered_func_data.nii.gz
'
)
datafile
=
op
.
join
(
tldir
,
'
filtered_func_data.nii.gz
'
)
reportfile
=
op
.
join
(
tldir
,
'
report.html
'
)
reportfile
=
op
.
join
(
tldir
,
'
report.html
'
)
meanfile
=
op
.
join
(
meldir
,
'
mean.nii.gz
'
)
meanfile
=
op
.
join
(
meldir
,
'
mean.nii.gz
'
)
icfile
=
op
.
join
(
meldir
,
'
melodic_IC.nii.gz
'
)
icfile
=
op
.
join
(
meldir
,
'
{}.nii.gz
'
.
format
(
ic_prefix
)
)
mixfile
=
op
.
join
(
meldir
,
'
melodic_mix
'
)
mixfile
=
op
.
join
(
meldir
,
'
melodic_mix
'
)
ftmixfile
=
op
.
join
(
meldir
,
'
melodic_FTmix
'
)
ftmixfile
=
op
.
join
(
meldir
,
'
melodic_FTmix
'
)
...
@@ -102,16 +103,20 @@ def test_MelodicImage_create():
...
@@ -102,16 +103,20 @@ def test_MelodicImage_create():
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
meli
.
MelodicImage
(
path
)
meli
.
MelodicImage
(
path
)
with
tests
.
testdir
()
as
testdir
:
meldir
=
_create_dummy_melodic_analysis
(
testdir
)
for
ic_prefix
in
[
'
melodic_IC
'
,
'
melodic_oIC
'
]:
icfile
=
op
.
join
(
meldir
,
'
melodic_IC.nii.gz
'
)
icfilenosuf
=
op
.
join
(
meldir
,
'
melodic_IC
'
)
with
tests
.
testdir
()
as
testdir
:
meldir
=
_create_dummy_melodic_analysis
(
testdir
,
# Should be able to specify the
ic_prefix
=
ic_prefix
)
# melodic dir, or the IC image
icfile
=
op
.
join
(
meldir
,
'
{}.nii.gz
'
.
format
(
ic_prefix
))
meli
.
MelodicImage
(
meldir
)
icfilenosuf
=
op
.
join
(
meldir
,
ic_prefix
)
meli
.
MelodicImage
(
icfile
)
meli
.
MelodicImage
(
icfilenosuf
)
# Should be able to specify the
# melodic dir, or the IC image
meli
.
MelodicImage
(
meldir
)
meli
.
MelodicImage
(
icfile
)
meli
.
MelodicImage
(
icfilenosuf
)
def
test_MelodicImage_atts
():
def
test_MelodicImage_atts
():
...
...
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