Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
William Clarke
fsl_mrs
Commits
735e7b8f
Commit
735e7b8f
authored
Jun 20, 2021
by
William Clarke
Browse files
Add diff to basis tool script.
parent
85ad437f
Changes
2
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/scripts/basis_tools
View file @
735e7b8f
...
...
@@ -101,6 +101,23 @@ def main():
help
=
'Output location, can overwrite.'
)
scaleparser
.
set_defaults
(
func
=
rescale
)
# Differenceing (add/subtract)
diffparser
=
sp
.
add_parser
(
'diff'
,
help
=
'Form difference basis sepctra from two basis spectra.'
)
diffparser
.
add_argument
(
'file1'
,
type
=
Path
,
help
=
'Basis file one'
)
diffparser
.
add_argument
(
'file2'
,
type
=
Path
,
help
=
'Basis file two, if subtract file 2 is subtracted from file 1.'
)
diffparser
.
add_argument
(
'output'
,
type
=
Path
,
help
=
'Output fsl formatted folder, will be created if needed.'
)
diffparser
.
add_argument
(
'--add_or_sub'
,
type
=
str
,
default
=
'sub'
,
help
=
"'add' or 'sub'"
)
diffparser
.
add_argument
(
'--ignore_missing'
,
action
=
"store_true"
,
help
=
'Ignore missing basis sets in one basis.'
)
diffparser
.
set_defaults
(
func
=
diff
)
# Parse command-line arguments
args
=
p
.
parse_args
()
...
...
@@ -188,5 +205,26 @@ def rescale(args):
basis
.
save
(
args
.
output
,
overwrite
=
True
)
def
diff
(
args
):
from
fsl_mrs.utils
import
basis_tools
from
fsl_mrs.utils.mrs_io
import
read_basis
basis1
=
read_basis
(
args
.
file1
)
basis2
=
read_basis
(
args
.
file2
)
if
args
.
ignore_missing
:
missing_action
=
'ignore'
else
:
missing_action
=
'raise'
new
=
basis_tools
.
difference_basis_sets
(
basis1
,
basis2
,
add_or_subtract
=
args
.
add_or_sub
,
missing_metabs
=
missing_action
)
new
.
save
(
args
.
output
)
if
__name__
==
'__main__'
:
main
()
fsl_mrs/tests/test_scripts_basis_tools.py
View file @
735e7b8f
...
...
@@ -17,6 +17,8 @@ jmrui = testsPath / 'testdata/mrs_io/basisset_JMRUI'
lcm
=
testsPath
/
'testdata/mrs_io/basisset_LCModel.BASIS'
fsl
=
testsPath
/
'testdata/mrs_io/basisset_FSL'
mac
=
testsPath
/
'testdata/basis_tools/macSeed.json'
diff1
=
testsPath
/
'testdata/basis_tools/low_res_off'
diff2
=
testsPath
/
'testdata/basis_tools/low_res_on'
def
test_info
():
...
...
@@ -87,3 +89,16 @@ def test_rescale(tmp_path):
assert
out_loc
.
is_dir
()
assert
(
out_loc
/
'NAA.json'
).
is_file
()
def
test_diff
(
tmp_path
):
out_loc
=
tmp_path
/
'test_basis'
subprocess
.
check_call
([
'basis_tools'
,
'diff'
,
'--add_or_sub'
,
'sub'
,
str
(
diff1
),
str
(
diff2
),
str
(
out_loc
)])
assert
out_loc
.
is_dir
()
assert
(
out_loc
/
'NAA.json'
).
is_file
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment