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

changed functions for fmriprep #8

Merged
merged 5 commits into from
Feb 28, 2024
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
24 changes: 20 additions & 4 deletions contarg/normgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from mixedvines.copula import GaussianCopula
from scipy.stats import norm
from scipy import stats
import bids


GII_PATTERN = ['sub-{subject}[/ses-{session}]/{datatype<anat>|anat}/sub-{subject}[_ses-{session}][_task-{task}][_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_hemi-{hemi}][_space-{space}][_den-{density}][_desc-{desc}][_part-{part}]_{suffix<T1w|T2w|T2star|T2starw|FLAIR|FLASH|PD|PDw|PDT2|inplaneT[12]|angio|curv|inflated|midthickness|pial|sulc|thickness|white|mask>}{extension<.nii|.nii.gz|.surf.gii|.shape.gii>}']
Expand Down Expand Up @@ -452,6 +453,8 @@ def load_surfaces(subject, layout, anat_dir, overwrite=False):
anat_dir = Path(anat_dir)
anat_out_dir = anat_dir / f'sub-{subject}/anat'
anat_out_dir.mkdir(exist_ok=True, parents=True)
if isinstance(layout,str):
layout = bids.BIDSLayout( database_path=layout)
# transform surface to fsLR
tmpsurfaces = {}
for H in ['L', 'R']:
Expand All @@ -463,13 +466,14 @@ def load_surfaces(subject, layout, anat_dir, overwrite=False):
datatype='anat',
hemi=H,
suffix=surface,
space=None,
extension='.surf.gii'
)[0].path
current_sphere = layout.get(
subject=subject,
datatype='anat',
space='fsLR',
desc='reg',
desc='msmsulc',
hemi=H,
suffix='sphere',
extension='.surf.gii'
Expand Down Expand Up @@ -678,7 +682,7 @@ def calc_stimgrid(subject, src_surf_dir, surf_info_dir,
raise ValueError("Must pass a layout if fmriprep is True")
if anat_dir is None:
raise ValueError("Must pass an anat_dir if ")
surfaces = load_surfaces(subject=subject, layout=layout, anat_dir=anat_dir)
surfaces = load_surfaces(subject=subject, layout=layout, overwrite=overwrite, anat_dir=anat_dir)
else:
surfaces = load_liston_surfs(subject, src_surf_dir)

Expand Down Expand Up @@ -1225,6 +1229,8 @@ def run_clusters(subject, concat_nii, clust_outdir, src_surf_dir,
refroi='bilateralfullSGCsphere',
stimroi='expandedcoleBA46',
out_prefix='',
layout=None,
anat_dir=None,
overwrite=False):
"""
subject : str
Expand All @@ -1247,6 +1253,10 @@ def run_clusters(subject, concat_nii, clust_outdir, src_surf_dir,
name of the roi where stimulation will be delivered
out_prefix : str
string preprended to output files
layout : bids.layout.layout.BIDSLayout | str
The layout object or a path to a saved bids layout
anat_dir : Pathlib path | str
Upper level directory under which new surfaces will be saved if needed. Files will be saved to anat_dir / f'sub-{subject}/anat'
overwrite : bool
Should files be overwritten
"""
Expand All @@ -1273,7 +1283,13 @@ def run_clusters(subject, concat_nii, clust_outdir, src_surf_dir,
if not outputs_present or overwrite:

# load surfaces
if surf_source == 'liston':
if surf_source == 'fmriprep':
if layout is None:
raise ValueError("Must pass a layout if fmriprep is True")
if anat_dir is None:
raise ValueError("Must pass an anat_dir if ")
surfaces = load_surfaces(subject=subject, layout=layout, anat_dir=anat_dir, overwrite=overwrite)
elif surf_source == 'liston':
surfaces = load_liston_surfs(subject, src_surf_dir)
else:
raise NotImplementedError
Expand Down Expand Up @@ -1508,4 +1524,4 @@ def make_uncert_surfaces(subject, src_surf_dir, uncert_dir, overwrite=False, fmr
]
subprocess.run(create_cifti_cmd, check=True)
cifti_outs.append(cifti_out)
return cifti_outs
return cifti_outs
Loading
Loading