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

Adds ParallelGroupAFQ #1124

Merged
merged 19 commits into from
May 16, 2024
Merged
Changes from 5 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
83 changes: 83 additions & 0 deletions AFQ/api/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,89 @@ def assemble_AFQ_browser(self, output_path=None, metadata=None,
sublink=page_subtitle_link)


class ParallelGroupAFQ(GroupAFQ):
36000 marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, *args, **kwargs):
orig = GroupAFQ(*args, **kwargs)

if "submitter_params" not in orig.parallel_params:
orig.parallel_params["submitter_params"] = {"plugin": "cf"}

if "cache_dir" not in orig.parallel_params:
orig.parallel_params["cache_dir"] = None

self.parallel_params = orig.parallel_params
self.pAFQ_kwargs = [pAFQ.kwargs for pAFQ in orig.pAFQ_list]

# Rename kwargs and clear "bids_info" and "base_fname"
# ParticipantAFQ takes in these parameters under one name but stores
# and uses them under another
36000 marked this conversation as resolved.
Show resolved Hide resolved
for ii in range(len(self.pAFQ_kwargs)):
self.pAFQ_kwargs[ii]["dwi_data_file"] = \
self.pAFQ_kwargs[ii]["dwi_path"]

self.pAFQ_kwargs[ii]["bval_file"] = \
self.pAFQ_kwargs[ii]["bval"]

self.pAFQ_kwargs[ii]["bvec_file"] = \
self.pAFQ_kwargs[ii]["bvec"]

self.pAFQ_kwargs[ii]["output_dir"] = \
self.pAFQ_kwargs[ii]["results_dir"]

del self.pAFQ_kwargs[ii]["dwi_path"]
del self.pAFQ_kwargs[ii]["bval"]
del self.pAFQ_kwargs[ii]["bvec"]
del self.pAFQ_kwargs[ii]["results_dir"]
del self.pAFQ_kwargs[ii]["bids_info"]
del self.pAFQ_kwargs[ii]["base_fname"]

def export_all(self, viz=True, afqbrowser=True, xforms=True, indiv=True):
""" Exports all the possible outputs

Parameters
----------
viz : bool
Whether to output visualizations. This includes tract profile
plots, a figure containing all bundles, and, if using the AFQ
segmentation algorithm, individual bundle figures.
Default: True
afqbrowser : bool
Whether to output an AFQ-Browser from this AFQ instance.
Default: True
xforms : bool
Whether to output the reg_template image in subject space and,
depending on if it is possible based on the mapping used, to
output the b0 in template space.
Default: True
indiv : bool
Whether to output individual bundles in their own files, in
addition to the one file containing all bundles. If using
the AFQ segmentation algorithm, individual ROIs are also
output.
Default: True
"""
import pydra
36000 marked this conversation as resolved.
Show resolved Hide resolved

@pydra.mark.task
def export_sub(pAFQ_kwargs, viz, xforms, indiv):
pAFQ = ParticipantAFQ(**pAFQ_kwargs)
pAFQ.export_all(viz, xforms, indiv)

# Submit to pydra
export_sub_task = export_sub(
pAFQ_kwargs=self.pAFQ_kwargs,
viz=viz,
xforms=xforms,
indiv=indiv,
cache_dir=self.parallel_params["cache_dir"]
).split("pAFQ_kwargs")

with pydra.Submitter(
36000 marked this conversation as resolved.
Show resolved Hide resolved
**self.parallel_params["submitter_params"],
) as sub:
sub(runnable=export_sub_task)


def download_and_combine_afq_profiles(bucket,
study_s3_prefix="", deriv_name=None,
out_file=None,
Expand Down
Loading