From a6f27d0f24200b0c651573f1770c6fe6b92c9a6b Mon Sep 17 00:00:00 2001 From: 36000 Date: Thu, 9 Jul 2026 21:25:48 -0700 Subject: [PATCH 1/2] WIP/ENH option to auto delete full tractogram in export all --- AFQ/api/group.py | 28 +++++++++++++++++++++++++++- AFQ/api/participant.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/AFQ/api/group.py b/AFQ/api/group.py index 0a3ff3af..ab81085c 100644 --- a/AFQ/api/group.py +++ b/AFQ/api/group.py @@ -690,7 +690,14 @@ def export_up_to(self, attr_name="help"): for inputs in calcdata.calcs[idx].inputs: self.export(inputs) - def export_all(self, viz=True, afqbrowser=True, xforms=True, indiv=True): + def export_all( + self, + viz=True, + afqbrowser=True, + xforms=True, + indiv=True, + delete_full_tractogram=False, + ): """Exports all the possible outputs Parameters @@ -714,6 +721,14 @@ def export_all(self, viz=True, afqbrowser=True, xforms=True, indiv=True): the AFQ segmentation algorithm, individual ROIs are also output. Default: True + delete_full_tractogram : bool + Whether to delete the full, unsegmented tractogram (and its + associated json) after all other outputs have been generated. + This can be useful for saving disk space, as the full + tractogram is typically over 90 percent of the total output size. + Only the full tractogram and its json are deleted; all other + outputs are left in place. + Default: False """ start_time = time() @@ -722,8 +737,19 @@ def export_all(self, viz=True, afqbrowser=True, xforms=True, indiv=True): self.combine_profiles() if afqbrowser: self.assemble_AFQ_browser() + if delete_full_tractogram: + self.delete_full_tractogram() self.logger.info(f"Time taken for export all: {str(time() - start_time)}") + def delete_full_tractogram(self): + """ + Delete the full, unsegmented tractogram (and its associated json) + for every subject and session. Only the full tractogram and its + json are deleted; all other outputs are left in place. + """ + for pAFQ in self.pAFQ_list: + pAFQ.delete_full_tractogram() + def cmd_outputs( self, cmd="rm", dependent_on=None, up_to=None, exceptions=None, suffix="" ): diff --git a/AFQ/api/participant.py b/AFQ/api/participant.py index 194a3dba..1046355a 100644 --- a/AFQ/api/participant.py +++ b/AFQ/api/participant.py @@ -1,5 +1,6 @@ import logging import math +import os import os.path as op import tempfile from math import radians @@ -30,7 +31,7 @@ from AFQ.tasks.utils import get_base_fname from AFQ.tasks.viz import get_viz_plan from AFQ.utils.bin import pyafq_str_to_val -from AFQ.utils.path import apply_cmd_to_afq_derivs +from AFQ.utils.path import apply_cmd_to_afq_derivs, drop_extension from AFQ.viz.utils import BEST_BUNDLE_ORIENTATIONS, get_eye, trim __all__ = ["ParticipantAFQ"] @@ -240,7 +241,9 @@ def export_up_to(self, attr_name="help"): for inputs in calcdata.calcs[idx].inputs: self.export(inputs) - def export_all(self, viz=True, xforms=True, indiv=True): + def export_all( + self, viz=True, xforms=True, indiv=True, delete_full_tractogram=False + ): f""" Exports all the possible outputs {valid_exports_string} @@ -262,11 +265,33 @@ def export_all(self, viz=True, xforms=True, indiv=True): the AFQ segmentation algorithm, individual ROIs are also output. Default: True + delete_full_tractogram : bool + Whether to delete the full, unsegmented tractogram (and its + associated json) after all other outputs have been generated. + This can be useful for saving disk space, as the full + tractogram is typically over 90 percent of the total output size. + Only the full tractogram and its json are deleted; + all other outputs are left in place. + Default: False """ start_time = time() export_all_helper(self, xforms, indiv, viz) + if delete_full_tractogram: + self.delete_full_tractogram() self.logger.info(f"Time taken for export all: {time() - start_time}") + def delete_full_tractogram(self): + """ + Delete the full, unsegmented tractogram (and its associated json). + Only the full tractogram and its json are deleted; all other + outputs are left in place. + """ + tractogram_file = self.export("streamlines") + for fname in (tractogram_file, drop_extension(tractogram_file) + ".json"): + if op.exists(fname): + os.remove(fname) + self.logger.info(f"Deleted {fname}") + def participant_montage(self, images_per_row=3, anatomy=True, bundle_names=None): """ Generate montage of all bundles for a given subject. From c67d38f8c7ba8dae4e288c6470476b18e2f1290f Mon Sep 17 00:00:00 2001 From: 36000 Date: Wed, 22 Jul 2026 11:43:35 -0700 Subject: [PATCH 2/2] add pve download to hcp downloader --- AFQ/data/fetch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AFQ/data/fetch.py b/AFQ/data/fetch.py index a7f4f30d..7c18d258 100644 --- a/AFQ/data/fetch.py +++ b/AFQ/data/fetch.py @@ -2307,6 +2307,9 @@ def fetch_hcp( data_files[ op.join(sess_dir, "anat", f"sub-{subject}_aparc+aseg_seg.nii.gz") ] = f"{study}/{subject}/T1w/aparc+aseg.nii.gz" + data_files[ + op.join(sess_dir, "anat", f"sub-{subject}_desc-PVE_probseg.nii.gz") + ] = f"{study}/{subject}/T1w/wmparc.nii.gz" download_files = {} for k in data_files.keys():