Skip to content

Commit

Permalink
Add support for .txt files exported by older versions of jMRUI (#133)
Browse files Browse the repository at this point in the history
* Add support for .txt files exported by older versions of jMRUI

Expanded 'signal' regular expression to include syntax from earlier jMRUI versions (namely, 'Signal number: ' rather than 'Signal')

* Add test case

* Update changelog

---------

Co-authored-by: wtclarke <[email protected]>
  • Loading branch information
DC-3T and wtclarke authored Mar 26, 2024
1 parent e993d46 commit 306c039
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ This document contains the Spec2nii release history in reverse chronological ord

0.7.4 (WIP)
---------------------------------
- Refinements and improvements to the GE SVS pipeline from Mark Mikkelsen
- Refinements and improvements to the GE SVS pipeline from Mark Mikkelsen.
- Add support for older jMRUI text formats which have a slightly different syntax. With thanks to Donnie Cameron.

0.7.3 (Tuesday 12th March 2024)
-------------------------------
Expand Down
2 changes: 1 addition & 1 deletion spec2nii/jmrui.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def readjMRUItxt(filename):
Header information
"""
signalRe = re.compile(r'Signal (\d{1,}) out of (\d{1,}) in file')
signalRe = re.compile(r'Signal (?:number: |)(\d{1,}) out of (\d{1,}) in file')
headerRe = re.compile(r'(\w*):(.*)')
header = {}
data = []
Expand Down
2 changes: 1 addition & 1 deletion tests/spec2nii_test_data
Submodule spec2nii_test_data updated from 218160 to 12973b
22 changes: 21 additions & 1 deletion tests/test_jmrui.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
testdata = {'fida_single': file_path / 'spec2nii_test_data/jmrui/metab_jmrui.txt',
'txt_multi': file_path / 'spec2nii_test_data/jmrui/basis_woTMS.txt',
'mrui_single': file_path / 'spec2nii_test_data/jmrui/press2.mrui',
'mrui_multi': file_path / 'spec2nii_test_data/jmrui/ALLSIG.mrui'}
'mrui_multi': file_path / 'spec2nii_test_data/jmrui/ALLSIG.mrui',
'txt_old': file_path / 'spec2nii_test_data/jmrui/P31rest_proc_jmrui.txt'}


@pytest.fixture
Expand Down Expand Up @@ -106,3 +107,22 @@ def test_jmrui_multi_mrui(affine_file, tmp_path):
assert converted.shape == (1, 1, 1, 2048, 28)
assert np.iscomplexobj(converted.dataobj)
assert np.allclose(np.loadtxt(affine_file), converted.affine)


def test_jmrui_old(affine_file, tmp_path):
"""Test the 'jmrui' txt old format with different # signal syntax.
Namely, 'Signal number: ' rather than 'Signal')
"""
# Run spec2nii on text
subprocess.call(['spec2nii', 'jmrui',
'-f', 'txt_old',
'-o', str(tmp_path),
'-a', affine_file,
'-j', testdata['txt_old']])

# Load the new nifti file
converted = nib.load(tmp_path / 'txt_old.nii.gz')

assert converted.shape == (1, 1, 1, 2048)
assert np.iscomplexobj(converted.dataobj)
assert np.allclose(np.loadtxt(affine_file), converted.affine)

0 comments on commit 306c039

Please sign in to comment.