Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG]: Replace FSL std2imgcoord with img2imgcoord #281

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/newsfragments/281.enh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace FSL ``std2imgcoord`` with ``img2imgcoord`` as the former is incorrect for coordinates transformation to other template spaces.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/281.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for accessing FSL ``img2imgcoord`` via Docker wrapper command by `Synchon Mandal`_
3 changes: 3 additions & 0 deletions junifer/api/res/fsl/img2imgcoord
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

run_fsl_docker.sh img2imgcoord "$@"
37 changes: 19 additions & 18 deletions junifer/data/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,45 +257,46 @@ def get_coordinates(
)

# Create an element-scoped tempfile for transformed coordinates output
std2imgcoord_out_path = element_tempdir / "coordinates_transformed.txt"
# Set std2imgcoord command
std2imgcoord_cmd = [
img2imgcoord_out_path = element_tempdir / "coordinates_transformed.txt"
# Set img2imgcoord command
img2imgcoord_cmd = [
"cat",
f"{pretransform_coordinates_path.resolve()}",
"| std2imgcoord -mm",
f"-img {target_data['reference_path'].resolve()}",
f"-std {target_data['path'].resolve()}",
"| img2imgcoord -mm",
f"-src {target_data['path'].resolve()}",
f"-dest {target_data['reference_path'].resolve()}",
f"-warp {extra_input['Warp']['path'].resolve()}",
f"- > {std2imgcoord_out_path.resolve()}",
f"> {img2imgcoord_out_path.resolve()};",
f"sed -i 1d {img2imgcoord_out_path.resolve()}",
]
# Call std2imgcoord
std2imgcoord_cmd_str = " ".join(std2imgcoord_cmd)
# Call img2imgcoord
img2imgcoord_cmd_str = " ".join(img2imgcoord_cmd)
logger.info(
f"std2imgcoord command to be executed: {std2imgcoord_cmd_str}"
f"img2imgcoord command to be executed: {img2imgcoord_cmd_str}"
)
std2imgcoord_process = subprocess.run(
std2imgcoord_cmd_str, # string needed with shell=True
img2imgcoord_process = subprocess.run(
img2imgcoord_cmd_str, # string needed with shell=True
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True, # needed for respecting $PATH
check=False,
)
# Check for success or failure
if std2imgcoord_process.returncode == 0:
if img2imgcoord_process.returncode == 0:
logger.info(
"std2imgcoord succeeded with the following output: "
f"{std2imgcoord_process.stdout}"
"img2imgcoord succeeded with the following output: "
f"{img2imgcoord_process.stdout}"
)
else:
raise_error(
msg="std2imgcoord failed with the following error: "
f"{std2imgcoord_process.stdout}",
msg="img2imgcoord failed with the following error: "
f"{img2imgcoord_process.stdout}",
klass=RuntimeError,
)

# Load coordinates
seeds = np.loadtxt(std2imgcoord_out_path)
seeds = np.loadtxt(img2imgcoord_out_path)

# Delete tempdir
WorkDirManager().delete_tempdir(tempdir)
Expand Down