Commit 02852ab1 authored by William Clarke's avatar William Clarke
Browse files

Merge branch 'enh/vespa_jmrui_basis' into 'master'

ENH: Vespa generate jMRUI basis handling

See merge request fsl/fsl_mrs!58
parents cb7b259b acb129a3
Pipeline #15406 failed with stage
......@@ -62,7 +62,7 @@ flake8:
stage: style
before_script:
- python --version
- pip install flake8
- pip install flake8==4.0.1
script:
- flake8 fsl_mrs
- flake8 fsl_mrs/scripts/*
......
This document contains the FSL-MRS release history in reverse chronological order.
2.0.2 (Monday 1st August 2022)
------------------------------
- Handle jMRUI basis sets generated in VESPA which lack the SignalNames field.
- Add utility function parse_metab_groups to MRS class.
2.0.1 (Thursday 28th July 2022)
-------------------------------
- Fix results list generation from metropolis hastings dynamic optimisation
......
......@@ -494,6 +494,25 @@ class MRS(object):
self.ppmAxisShift = self.ppmAxisShift[:, None]
# Other methods
def parse_metab_groups(self, metab_grp_str):
"""Utility function for generating metabolite groups
Input (metab_grp_str) may be:
- A single string : corresponding metab(s) in own group.
Multiple metabs may be combined into one group with '+'.
- The strings 'separate_all' or 'combine_all'
- A list of:
* integers : output same as input
* strings : each string is interpreted as metab name and has own group
:param metab_grp_str:metabolite groups
:type metab_grp_str: str or list
:return: metabolite group indices
:rtype: list
"""
from fsl_mrs.utils.misc import parse_metab_groups
return parse_metab_groups(self, metab_grp_str)
def ppmlim_to_range(self, ppmlim=None, shift=True):
"""
turns ppmlim into data range
......
......@@ -244,3 +244,44 @@ def test_process_for_fitting(synth_data):
mrs.check_FID(repair=True)
mrs.check_Basis(repair=True)
mrs.processForFitting()
def test_parse_metab_groups():
mrs = mrs_from_files(str(svs_metab),
str(svs_basis))
# combine all
assert mrs.parse_metab_groups('combine_all')\
== [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# separate all
assert mrs.parse_metab_groups('separate_all')\
== [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
# One metabolite
assert mrs.parse_metab_groups('Mac')\
== [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]
# Two metabolites
assert mrs.parse_metab_groups(['Mac', 'NAA'])\
== [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0]
# Combine two
assert mrs.parse_metab_groups('NAA+NAAG')\
== [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
# Combine three
assert mrs.parse_metab_groups(['NAA+NAAG+Cr'])\
== [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
# Combine three and separate
assert mrs.parse_metab_groups(['Mac', 'NAA+NAAG+Cr'])\
== [0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 0, 0, 0, 0, 0]
# Single integer
assert mrs.parse_metab_groups(1)\
== [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# List of integers
assert mrs.parse_metab_groups([0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0])\
== [0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0]
......@@ -20,6 +20,7 @@ fsl_basis_path = testsPath / 'testdata' / 'fsl_mrs' / 'steam_basis'
lcm_basis_path = testsPath / 'testdata' / 'basis_tools' / '3T_slaser_32vespa_1250.BASIS'
raw_basis_path = testsPath / 'testdata' / 'basis_tools' / 'RawBasis_for_PRESSGE_TE_35_BW_4000_NPts_2048'
jmrui_basis_path = testsPath / 'testdata' / 'mrs_io' / 'basisset_JMRUI'
jmrui_vespa_basis_path = testsPath / 'testdata' / 'mrs_io' / 'basisset_JMRUI_vespa'
extra_basis = testsPath / 'testdata' / 'basis_tools' / 'macSeed.json'
......@@ -63,6 +64,18 @@ def test_convert_jmrui(tmp_path):
assert new_basis.original_basis_array.shape == (2048, 21)
def test_convert_jmrui_vespa(tmp_path):
out_loc = tmp_path / 'test_basis_jmrui_vespa'
basis_tools.convert_jmrui_basis(
jmrui_vespa_basis_path,
out_loc)
new_basis = mrs_io.read_basis(out_loc)
assert new_basis.original_basis_array.shape == (4096, 2)
assert new_basis.names == ['creatine', 'n-acetylaspartate']
def test_add_basis():
basis = mrs_io.read_basis(fsl_basis_path)
......
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
This source diff could not be displayed because it is stored in LFS. You can view the blob instead.
......@@ -52,14 +52,21 @@ def read_txtBasis_files(txtfiles):
names = []
header = []
for file in txtfiles:
# Special case for the VESPA information file that can be packaged in JMRUI basisets
if op.basename(file) == 'jmrui-text_output_summary.txt':
continue
b, h = readjMRUItxt(file)
basis.append(b)
split_str = h['jmrui']['SignalNames'].split(';')
if split_str[-1] == '':
split_str.pop()
names += split_str
try:
split_str = h['jmrui']['SignalNames'].split(';')
if split_str[-1] == '':
split_str.pop()
names += split_str
except KeyError:
names.append(
op.splitext(h['jmrui']['Filename'])[0])
header += [h, ] * b.shape[0]
basis = np.concatenate(basis, axis=0)
basis = basis.conj().T
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment