Skip to content

Commit

Permalink
Merge pull request #50 from Ian-Goodall-Halliwell/main
Browse files Browse the repository at this point in the history
added 7t compatability
  • Loading branch information
Ian-Goodall-Halliwell authored Jan 7, 2025
2 parents db39c43 + 19b49f2 commit dd6180c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/functions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
# Resolution
LOW_RESOLUTION_CTX = "5k"
HIGH_RESOLUTION_CTX = "32k"
LOW_RESOLUTION_HIP = "0p5mm"
HIGH_RESOLUTION_HIP = "2mm"
LOW_RESOLUTION_HIP = "2mm"
HIGH_RESOLUTION_HIP = "0p5mm"

map_resolution_ctx = {"low": LOW_RESOLUTION_CTX, "high": HIGH_RESOLUTION_CTX}
map_resolution_hip = {"low": LOW_RESOLUTION_HIP, "high": HIGH_RESOLUTION_HIP}
Expand Down
11 changes: 7 additions & 4 deletions src/functions/niidcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def transfer_nii_hdr_series_tags(ds, nii2dcm_parameters, file_meta):
ds.PatientName = nii2dcm_parameters["PatientName"]


def transfer_nii_hdr_instance_tags(ds, nii2dcm_parameters, instance_index, isbase=False):
def transfer_nii_hdr_instance_tags(
ds, nii2dcm_parameters, instance_index, isbase=False
):
"""
Transfer NIfTI header parameters applicable to Instance
Expand Down Expand Up @@ -289,12 +291,13 @@ def convert_nifti_to_dicom(
print("NIfTI header series tags transferred.")
from pydicom.uid import ExplicitVRLittleEndian, ImplicitVRLittleEndian

if not os.path.exists(out_dir):
os.makedirs(out_dir)

print("DICOM slices written.")
if compat == True:
for i in range(nii2dcm_parameters["NumberOfInstances"]):
write_slice_wrapper(
(ds, array, i, out_dir, nii2dcm_parameters)
)
write_slice_wrapper((ds, array, i, out_dir, nii2dcm_parameters))

else:
useFloat = False
Expand Down
25 changes: 25 additions & 0 deletions src/functions/run_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,31 @@ def run(
f"{BIDS_ID}_hemi-{hemi}_space-T1w_den-0p5mm_label-hipp_{surf}.surf.gii",
),
)
shutil.copyfile(
os.path.join(
subject_micapipe_dir,
"xfm",
f"{BIDS_ID}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_0GenericAffine.mat",
),
os.path.join(
subject_output_dir,
"structural",
f"{BIDS_ID}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_0GenericAffine.mat",
),
)
shutil.copyfile(
os.path.join(
subject_micapipe_dir,
"xfm",
f"{BIDS_ID}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_1Warp.nii.gz",
),
os.path.join(
subject_output_dir,
"structural",
f"{BIDS_ID}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_1Warp.nii.gz",
),
)

# do the mapping
for feat in features:
if structure == "cortex":
Expand Down
25 changes: 13 additions & 12 deletions src/functions/surface_to_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
settozero = True


def fixmatrix(path, subject, session, temppath, wb_path, rootzbrainfolder):
def fixmatrix(subject, session, temppath, wb_path, rootzbrainfolder):
# Load the .mat file
mat = scipy.io.loadmat(
os.path.join(
path,
"xfm",
rootzbrainfolder,
"structural",
f"{subject}_{session}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_0GenericAffine.mat",
)
),
)

# Extract variables from the .mat file
Expand Down Expand Up @@ -56,15 +56,16 @@ def fixmatrix(path, subject, session, temppath, wb_path, rootzbrainfolder):
"-convert-warpfield",
"-from-itk",
os.path.join(
path,
"xfm",
rootzbrainfolder,
"structural",
f"{subject}_{session}_from-nativepro_brain_to-MNI152_0.8mm_mode-image_desc-SyN_1Warp.nii.gz",
),
"-to-world",
os.path.join(temppath, "real_warp.nii.gz"),
]
subprocess.run(command)
command3 = [
# command = [f'"{arg}"' for arg in command]
subprocess.run(" ".join(command), shell=True)
command2 = [
os.path.join(wb_path, "wb_command"),
"-volume-resample",
f"{rootzbrainfolder}/structural/{subject}_{session}_space-nativepro_T1w_brain.nii.gz",
Expand All @@ -76,7 +77,7 @@ def fixmatrix(path, subject, session, temppath, wb_path, rootzbrainfolder):
"-warp",
os.path.join(temppath, "real_warp.nii.gz"),
]
subprocess.run(command3)
subprocess.run(" ".join(command2), shell=True)
command3 = [
os.path.join(wb_path, "wb_command"),
"-volume-resample",
Expand All @@ -90,7 +91,7 @@ def fixmatrix(path, subject, session, temppath, wb_path, rootzbrainfolder):
os.path.join(temppath, "real_warp.nii.gz"),
]

subprocess.run(command3)
subprocess.run(" ".join(command3), shell=True)


def float_array_to_hot_nonrgb(array):
Expand Down Expand Up @@ -1054,7 +1055,7 @@ def surface_to_volume(
# dicomify_base(outdir, rootzbrainfolder, subj=subj, ses=ses, px_demo=px_demo)

micapiperootfolder = os.path.join(rootfolder, micapipename, subj, ses)
fixmatrix(micapiperootfolder, subj, ses, tmp, workbench_path, rootzbrainfolder)
fixmatrix(subj, ses, tmp, workbench_path, rootzbrainfolder)
Parallel(n_jobs=n_jobs)(
delayed(process)(
feature,
Expand Down Expand Up @@ -1103,7 +1104,7 @@ def surface_to_volume(
)
if dicoms == 1:
os.makedirs(f"{outdir}/DICOM", exist_ok=True)
dicomify_base(outdir, subj, ses, tmp, thresh, px_demo=px_demo)
dicomify_base(outdir, rootzbrainfolder, subj, ses, px_demo=px_demo)
print("Converting to DICOM")
timepre = time()
Parallel(n_jobs=n_jobs)(
Expand Down
10 changes: 5 additions & 5 deletions src/zbrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,10 @@ def check_sub(args, sub, ses=None):
hippunfold_path = os.path.join(hippunfold_path, ses)
if not os.path.isdir(micapipe_path):
# print(f'Non proccessable micapipe output at {micapipe_path} for {sub}{f"-{ses}" if ses else ""}, skipping')
return False
if "proc" in args.run:
return False
if "proc" in args.run:

if "cortex" in args.struct or "subcortex" in args.struct:
if not os.path.exists(micapipe_path) or not os.path.isdir(micapipe_path):
print(
Expand All @@ -540,7 +541,6 @@ def check_sub(args, sub, ses=None):
f'No hippunfold at {hippunfold_path} for {sub}{f"-{ses}" if ses else ""}, skipping'
)
return False


return True

Expand All @@ -560,7 +560,7 @@ def create_jobs(args, subs, ses, run_type):
if check_sub(args, sub, s):
job = copy.copy(args)
job.sub, job.ses, job.run = sub, s, run_type
if args.patient_prefix in job.sub or run_type == "proc":
if args.control_prefix not in job.sub or run_type == "proc":
jobs.append(job)
return jobs

Expand Down Expand Up @@ -714,7 +714,7 @@ def print_help(self):
type=str,
default="/data/mica1/01_programs/workbench-1.4.2/bin_linux64",
)
parser.add_argument("--patient_prefix", type=str, default="PX")
parser.add_argument("--control_prefix", type=str, default="HC")
parser.add_argument("--verbose", type=int, default=-1)
parser.add_argument("--version", action="version", version="1.0.0")
parser.add_argument("--dicoms", type=int, default=1)
Expand Down

0 comments on commit dd6180c

Please sign in to comment.