Re-running pyAFQ segmentation using Recobundles after initial run with AFQ-waypoints

Summary of what happened:

I am trying to re-run pyAFQ from the bundle recognition step on after initially running with AFQ-waypoints method, now switching to Recobundles method for comparison. I would like to use the outputs of the earlier steps (tensor fitting, tractography, etc) and avoid re-running the full pipeline. I initiated the original run with a config file using default parameters, and I am trying to use API to update the segmentation parameters for the rerun and remove the afq-waypoints method with clobber (I have already saved a copy of those).
This method is failing with an error that the ‘seg_algo’ argument is not recognized.

Command used (and if a helper script was used, a link to the helper script or the command generated):

from AFQ.api.group import GroupAFQ


# Initialize AFQ object

afq = GroupAFQ(
    bids_path="/bids",
    output_dir="/derivatives/afq",
    segmentation_params={
        'seg_algo': 'reco',
        'refine_reco': True, 
        'rb_recognize_params': {
            'model_clust_thr': 1.25,
            'pruning_thr': 12,
            'reduction_thr': 25,
        }
    }
)


# Remove old segmentation outputs only
afq.clobber(dependent_on="recog")


# Recompute segmentation and subsequent steps
afq.export_all()

Version:

Running via Singularity/Apptainer, pulled as follows:
apptainer pull docker://ghcr.io/nrdg/pyafq:latest

Environment (Docker, Singularity / Apptainer, custom installation):

Apptainer job file:

apptainer exec --containall \
    -B $HOME/elgan_dti/code:/code,$HOME/elgan_dti/data:/bids,$HOME/elgan_dti/data/derivatives:/derivatives,$HOME/elgan_dti/work:/work,$HOME:/home/meaghan.perdue-umw \
    pyafq_latest.sif python /code/afq_run_recobundles.py

where afq_run_recobundles.py contains the command code pasted above.

Data formatted according to a validatable standard? Please provide the output of the validator:

Yes, bids format is valide, pyAFQ runs correctly with waypoints method.

Relevant log outputs (up to 20 lines):

  File "/usr/local/lib/python3.11/site-packages/pimms/util.py", line 1132, in _choose_last
    return vs[-1][k]
           ~~~~~~^^^
  File "/usr/local/lib/python3.11/site-packages/pimms/calculation.py", line 470, in __getitem__
    self._run_node(self.plan.efferents[k])
  File "/usr/local/lib/python3.11/site-packages/pimms/calculation.py", line 534, in _run_node
    if not found: res = node(self)
                        ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pimms/calculation.py", line 91, in __call__
    result = self.function(*args)
             ^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in wrapper_has_args_func
  File "/usr/local/lib/python3.11/site-packages/AFQ/tasks/decorators.py", line 148, in wrapper_as_file
    gen, meta = func(*args[:og_arg_count], **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/AFQ/tasks/segmentation.py", line 94, in segment
    bundles, bundle_meta = recognize(
                           ^^^^^^^^^^
TypeError: recognize() got an unexpected keyword argument 'seg_algo'

Hi @MeaghanPerdue and welcome to neurostars!

Yes, the seg_algo keyword does not seem to be valid, according to what I see on GitHub. It looks like you can specify recobundles with the bundle_info keyword, as in pyAFQ/examples/howto_examples/plot_recobundles.py at ed2152ffd6c239723f03313043b23adfd9ad3064 · tractometry/pyAFQ · GitHub.

Best,
Steven

Hi Steven,
Thanks for your reply - I was indeed using a deprecated command ‘seg_algo’ (apparently I made my way to an outdated version of the pyafq documentation). I updated to bundle_info as you pointed out and things seem to be working correctly now. Sharing my updated code below in case it’s useful to other users:

# This script removes all outputs from bundle recognition on and re-runs with recobundles
# use this in order to run Recobundles segmentation on the same tractography used for AFQ-waypoints 

from AFQ.api.group import GroupAFQ
import AFQ.api.bundle_dict as abd

# Initialize AFQ object

afq = GroupAFQ(
    bids_path="/bids",
    output_dir="/derivatives/afq",
    bundle_info=abd.reco_bd(16),
    segmentation_params={
        'refine_reco': True, 
        'rb_recognize_params': {
            'model_clust_thr': 1.25,
            'pruning_thr': 12,
            'reduction_thr': 25,
        }
    }
)


# Remove old segmentation outputs only
afq.clobber(dependent_on="recog")


# Recompute segmentation and subsequent steps
afq.export_all()

Best,
Meaghan

2 Likes