Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Correct oblique #327

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Install a few minimal AFNI components
RUN curl -L -O https://afni.nimh.nih.gov/pub/dist/tgz/linux_ubuntu_16_64.tgz && \
mkdir -p /opt/afni && \
tar xzvf linux_ubuntu_16_64.tgz -C /opt/afni linux_ubuntu_16_64/{libmri.so,libf2c.so,3dDespike,3dTshift,3dAutobox} --strip-components=1 && \
tar xzvf linux_ubuntu_16_64.tgz -C /opt/afni linux_ubuntu_16_64/{libmri.so,libf2c.so,3dDespike,3dTshift,3dWarp,3dAutobox} --strip-components=1 && \
rm -f linux_ubuntu_16_64.tgz
ENV PATH=/opt/afni${PATH:+:$PATH}

Expand Down
15 changes: 13 additions & 2 deletions rabies/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ def get_parser():
"(default: %(default)s)\n"
"\n"
)
preprocess.add_argument(
'--oblique2card', dest='oblique2card', action='store_true',
help=
"Applies AFNI's 3dWarp -oblique2card on all structural and functional data to \n"
"convert oblique data to cartesian (see https://github.com/CoBrALab/RABIES/issues/160). \n"
"WARNING: this is modifying the original data by resampling on a new grid, only apply if necessary. \n"
"(default: %(default)s)\n"
"\n"
)
preprocess.add_argument(
'--apply_despiking', dest='apply_despiking', action='store_true',
help=
Expand Down Expand Up @@ -457,7 +466,8 @@ def get_parser():
g_stc.add_argument(
'--TR', type=str, default='auto',
help=
"Specify repetition time (TR) in seconds. (e.g. --TR 1.2)\n"
"Specify repetition time (TR) in seconds. (e.g. --TR 1.2). 'auto' will read the TR from \n"
"the nifti header. \n"
"(default: %(default)s)\n"
"\n"
)
Expand Down Expand Up @@ -659,7 +669,8 @@ def get_parser():
confound_correction.add_argument(
'--TR', type=str, default='auto',
help=
"Specify repetition time (TR) in seconds. (e.g. --TR 1.2)\n"
"Specify repetition time (TR) in seconds. (e.g. --TR 1.2). 'auto' will read the TR from \n"
"the nifti header. \n"
"(default: %(default)s)\n"
"\n"
)
Expand Down
47 changes: 41 additions & 6 deletions rabies/preprocess_pkg/main_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .inho_correction import init_inho_correction_wf
from .commonspace_reg import init_commonspace_reg_wf
from .bold_main_wf import init_bold_main_wf
from .utils import BIDSDataGraber, prep_bids_iter, convert_to_RAS, resample_template, apply_autobox
from .utils import BIDSDataGraber, prep_bids_iter, convert_to_RAS, convert_oblique2card, apply_autobox, resample_template
from . import preprocess_visual_QC

def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
Expand Down Expand Up @@ -170,6 +170,26 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
function=convert_to_RAS),
name='bold_convert_to_RAS')

if opts.oblique2card:
bold_oblique2card_node = pe.Node(Function(input_names=['input'],
output_names=['output'],
function=convert_oblique2card),
name='bold_oblique2card')
workflow.connect([
(bold_selectfiles, bold_oblique2card_node, [
('out_file', 'input'),
]),
(bold_oblique2card_node, bold_convert_to_RAS_node, [
('output', 'img_file'),
]),
])
else:
workflow.connect([
(bold_selectfiles, bold_convert_to_RAS_node, [
('out_file', 'img_file'),
]),
])

format_bold_buffer = pe.Node(niu.IdentityInterface(fields=['formatted_bold']),
name="format_bold_buffer")

Expand Down Expand Up @@ -244,9 +264,6 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
(main_split, bold_selectfiles, [
("scan_info", "scan_info"),
]),
(bold_selectfiles, bold_convert_to_RAS_node, [
('out_file', 'img_file'),
]),
(bold_selectfiles, outputnode, [
('out_file', 'input_bold'),
]),
Expand Down Expand Up @@ -334,6 +351,26 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
function=convert_to_RAS),
name='anat_convert_to_RAS')

if opts.oblique2card:
anat_oblique2card_node = pe.Node(Function(input_names=['input'],
output_names=['output'],
function=convert_oblique2card),
name='anat_oblique2card')
workflow.connect([
(anat_selectfiles, anat_oblique2card_node, [
('out_file', 'input'),
]),
(anat_oblique2card_node, anat_convert_to_RAS_node, [
('output', 'img_file'),
]),
])
else:
workflow.connect([
(anat_selectfiles, anat_convert_to_RAS_node, [
('out_file', 'img_file'),
]),
])

format_anat_buffer = pe.Node(niu.IdentityInterface(fields=['formatted_anat']),
name="format_anat_buffer")

Expand Down Expand Up @@ -369,8 +406,6 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
(run_split, bold_selectfiles, [
("run", "run"),
]),
(anat_selectfiles, anat_convert_to_RAS_node,
[("out_file", "img_file")]),
(format_anat_buffer, anat_inho_cor_wf, [
("formatted_anat", "inputnode.target_img"),
("formatted_anat", "inputnode.name_source"),
Expand Down
12 changes: 12 additions & 0 deletions rabies/preprocess_pkg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ def convert_to_RAS(img_file, out_dir=None):
return out_file


def convert_oblique2card(input):
import pathlib
import os
from rabies.utils import run_command
# apply AFNI's 3dWarp to convert from oblique to cartesian
split = pathlib.Path(input).name.rsplit(".nii")[0]
output = os.path.abspath(f"{split}_2card.nii.gz")
command = f'3dWarp -oblique2card -prefix {output} {input}'
rc = run_command(command)
return output


def resample_template(template_file, mask_file, file_list, spacing='inputs_defined', rabies_data_type=8):
import os
import SimpleITK as sitk
Expand Down
2 changes: 1 addition & 1 deletion scripts/error_check_rabies.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_parser():
command = f"rabies --inclusion_ids {tmppath}/inputs/sub-token1_bold.nii.gz --verbose 1 --force preprocess {tmppath}/inputs {tmppath}/outputs --anat_inho_cor method=disable,otsu_thresh=2,multiotsu=false --bold_inho_cor method=disable,otsu_thresh=2,multiotsu=false \
--anat_template {tmppath}/inputs/sub-token1_T1w.nii.gz --brain_mask {tmppath}/inputs/token_mask.nii.gz --WM_mask {tmppath}/inputs/token_mask.nii.gz --CSF_mask {tmppath}/inputs/token_mask.nii.gz --vascular_mask {tmppath}/inputs/token_mask.nii.gz --labels {tmppath}/inputs/token_mask.nii.gz \
--bold2anat_coreg registration=no_reg,masking=true,brain_extraction=true --commonspace_reg masking=true,brain_extraction=true,fast_commonspace=true,template_registration=no_reg --data_type int16 \
--HMC_option 0 --apply_despiking --anat_autobox --bold_autobox"
--HMC_option 0 --oblique2card --apply_despiking --anat_autobox --bold_autobox"
process = subprocess.run(
command,
check=True,
Expand Down