Skip to content

Commit

Permalink
Multiple fixes
Browse files Browse the repository at this point in the history
- Pull in latest code changes at MRtrix3/mrtrix3#3011 to ensure no regression has occurred in fixing other issues.
- Fix invocation of peakscheck for dwi2tensor outputs.
- Fix container entrypoint.
- Fix README to include invocation of container and reflect fix to container entrypoint.
  • Loading branch information
Lestropie committed Nov 17, 2024
1 parent 967025f commit 41dff10
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ RUN apt-get -qq update \

FROM mrtrix3-builder AS mrtrix3-eval-builder
# Version of MRtrix3 to be evaluated
# This is branch "dwi_metadata_master" as at 2024-09-19
ARG MRTRIX3_GIT_COMMITISH="01a09b8985568b52ad81fd1a499c3feab872881b"
# This is branch "dwi_metadata_master" as at 2024-11-16
ARG MRTRIX3_GIT_COMMITISH="fc0e8f144b161a594eda733ebc9cb4eb6b72e8cb"
#ARG MRTRIX3_GIT_COMMITISH="dwi_metadata_master"
# Command-line arguments for `./configure`
ARG MRTRIX3_CONFIGURE_FLAGS="-nogui"
Expand Down Expand Up @@ -146,4 +146,5 @@ ENV FSLDIR="/opt/fsl" \
FSLWISH="/opt/fsl/bin/fslwish" \
PATH="/opt/mrtrix3/bin:/opt/peakscmds/build/bin:/opt/dcm2niix/build/bin:/opt/fsl/share/fsl/bin:$PATH"

CMD ["/main.py"]
ENTRYPOINT ["/main.py"]

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ This can be done via eg.:
```ShellSession
docker build . -t dwi_metadata:latest
mkdir scratch
docker run -it --rm -v $(pwd)/scratch:/scratch /main.py /data /scratch /scratch/log.log
docker run -it --rm -v $(pwd)/scratch:/scratch dwi_metadata:latest /data /scratch /scratch/log.log
```

The `main.py` script currently expects all relevant commands to be present in `PATH`.
The execution scripts expect all relevant commands to be present in `PATH`.
This includes the `peakscheck` and `peaksconvert` commands proposed for *MRtrix3*,
which currently necessitates installation of the following branch:
https://github.com/MRtrix3/mrtrix3/pull/2918
https://github.com/MRtrix3/mrtrix3/pull/2918.
The container environment ensures that this is all set up as required.

## Software dependencies

Expand Down
18 changes: 15 additions & 3 deletions dwi_metadata/fsl/fsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def execute(inputname, inputdir, maskdir, scratchdir):
dtifit.run(inputdir, maskdir, dtifitdir)
conversiondir = op.join(scratchdir, f'dtifit_{op.basename(inputdir)}_to_scannerspace')
dtifit.convert(dtifitdir, conversiondir)
tests.peaks(f'FSL dtifit from {inputname}', conversiondir, maskdir, 'nii')
tests.peaks(f'FSL dtifit from {inputname}',
conversiondir,
maskdir,
'mif',
'nii')
execute('dcm2niix',
op.join(scratchdir, 'dcm2niix'),
op.join(scratchdir, 'mask_dcm2niix'),
Expand All @@ -39,10 +43,18 @@ def execute(inputname, inputdir, maskdir, scratchdir):
bedpostx.run(inputdir, maskdir, bedpostxdir)
conversiondir = op.join(scratchdir, f'bedpostx_from_{op.basename(inputdir)}_sph2peaks')
bedpostx.convert(bedpostxdir, conversiondir, False)
tests.peaks(f'bedpostx from {inputname}; spherical coordinates', conversiondir, maskdir, 'nii')
tests.peaks(f'bedpostx from {inputname}; spherical coordinates',
conversiondir,
maskdir,
'mif',
'nii')
conversiondir = op.join(scratchdir, f'bedpostx_from_{op.basename(inputdir)}_dyads2peaks')
bedpostx.convert(bedpostxdir, conversiondir, True)
tests.peaks(f'bedpostx from {inputname}; 3-vectors', conversiondir, maskdir, 'nii')
tests.peaks(f'bedpostx from {inputname}; 3-vectors',
conversiondir,
maskdir,
'mif',
'nii')
execute('dcm2niix',
op.join(scratchdir, 'dcm2niix'),
op.join(scratchdir, 'mask_dcm2niix'),
Expand Down
2 changes: 1 addition & 1 deletion dwi_metadata/mrtrix3/dwi2tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run(indir, extensions, maskdir, dwi2tensordir):
+ grad_option,
check=True)
subprocess.run(['tensor2metric', tensor_image_path,
'-vector', op.join(dwi2tensordir, f'{v}_vector.{extensions[0]}'),
'-vector', op.join(dwi2tensordir, f'{v}.{extensions[0]}'),
'-mask', mask_path,
'-modulate', 'fa',
'-quiet'],
Expand Down
7 changes: 6 additions & 1 deletion dwi_metadata/mrtrix3/mrtrix3.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_dwi2tensor(scratchdir):
tests.peaks(f'MRtrix3 dwi2tensor from dcm2niix',
op.join(scratchdir, 'dwi2tensor_from_dcm2niix'),
op.join(scratchdir, 'mask_dcm2niix'),
'nii',
'nii')
for extensions, reorient in tqdm(itertools.product(EXTENSIONS, (False, True)),
desc='Running MRtrix3 dwi2tensor on MRtrix3 mrconvert outputs',
Expand All @@ -126,5 +127,9 @@ def test_dwi2tensor(scratchdir):
extensions,
maskdir,
outdir)
tests.peaks(f'MRtrix3 dwi2tensor from mrconvert {version_string}', outdir, maskdir, extensions[0])
tests.peaks(f'MRtrix3 dwi2tensor from mrconvert {version_string}',
outdir,
maskdir,
extensions[0],
extensions[0])

4 changes: 2 additions & 2 deletions dwi_metadata/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def metadata(testname, inputdir, file_extensions):



def peaks(testname, inputdir, maskdir, mask_extension):
def peaks(testname, inputdir, maskdir, image_extension, mask_extension):
errors = []
logger.info(f'Verifying peak orientations for {testname}')
for v in tqdm(VARIANTS, desc=f'Verifying peak orientations for {testname}', leave=False):
Expand All @@ -189,7 +189,7 @@ def peaks(testname, inputdir, maskdir, mask_extension):
'-npass', '2',
'-config', 'RealignTransform', 'False',
'-quiet'])
proc = subprocess.run(['peakscheck', op.join(inputdir, f'{v}.mif'),
proc = subprocess.run(['peakscheck', op.join(inputdir, f'{v}.{image_extension}'),
'-mask', maskpath,
'-quiet'],
capture_output=True)
Expand Down

0 comments on commit 41dff10

Please sign in to comment.