Callosal bundles using AFQ API

An example using the AFQ API to find callosal bundles using the templates from: http://hdl.handle.net/1773/34926

import os.path as op

import plotly

from AFQ import api
from AFQ.definitions.mask import RoiMask
import AFQ.data as afd

Get some example data

Retrieves Stanford HARDI dataset.

afd.organize_stanford_data(clear_previous_afq=True)

Set tractography parameters (optional)

We make this tracking_params which we will pass to the AFQ object which specifies that we want 100,000 seeds randomly distributed in the ROIs of every bundle.

We only do this to make this example faster and consume less space.

tracking_params = dict(seed_mask=RoiMask(),
                       n_seeds=10000,
                       random_seeds=True,
                       rng_seed=42)

Initialize an AFQ object:

We specify bundle_info as the callosal bundles only (api.CALLOSUM_BUNDLES). If we want to segment both the callosum and the other bundles, we would pass api.CALLOSUM_BUNDLES + api.BUNDLES instead. This would tell the AFQ object to use bundles from both the standard and callosal templates.

myafq = api.AFQ(bids_path=op.join(afd.afq_home,
                                  'stanford_hardi'),
                preproc_pipeline='vistasoft',
                bundle_info=api.CALLOSUM_BUNDLES,
                tracking_params=tracking_params,
                viz_backend='plotly_no_gif')

# Calling export all produces all of the outputs of processing, including
# tractography, scalar maps, tract profiles and visualizations:
myafq.export_all()

Out:

Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]
Optimizing level 2 [max iter: 10000]
Optimizing level 1 [max iter: 1000]
Optimizing level 0 [max iter: 100]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 2/4966 [00:00<07:43, 10.70it/s]
  0%|          | 4/4966 [00:06<2:45:24,  2.00s/it]
  0%|          | 6/4966 [00:06<1:32:18,  1.12s/it]
  8%|8         | 400/4966 [00:07<00:40, 112.62it/s]
 21%|##        | 1040/4966 [00:07<00:11, 354.77it/s]
 42%|####1     | 2064/4966 [00:07<00:03, 824.45it/s]
 62%|######2   | 3088/4966 [00:07<00:01, 1377.33it/s]
 72%|#######2  | 3600/4966 [00:07<00:00, 1670.17it/s]
 83%|########2 | 4112/4966 [00:07<00:00, 1987.07it/s]
 93%|#########3| 4624/4966 [00:07<00:00, 2327.68it/s]
100%|##########| 4966/4966 [00:07<00:00, 624.90it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
 21%|##        | 1020/4966 [00:00<00:00, 9257.47it/s]
 62%|######1   | 3068/4966 [00:00<00:00, 14728.33it/s]
 91%|#########1| 4541/4966 [00:00<00:00, 13960.33it/s]
100%|##########| 4966/4966 [00:00<00:00, 14875.01it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
 10%|#         | 508/4966 [00:00<00:01, 4279.99it/s]
 31%|###       | 1532/4966 [00:00<00:00, 5701.86it/s]
 42%|####2     | 2088/4966 [00:00<00:00, 5473.99it/s]
 62%|######1   | 3068/4966 [00:00<00:00, 5431.43it/s]
 82%|########2 | 4092/4966 [00:00<00:00, 5496.57it/s]
100%|##########| 4966/4966 [00:00<00:00, 6602.24it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 8/4966 [00:00<01:08, 72.31it/s]
 21%|##        | 1020/4966 [00:00<00:00, 5638.70it/s]
 62%|######1   | 3068/4966 [00:00<00:00, 11245.95it/s]
 84%|########3 | 4169/4966 [00:00<00:00, 10909.34it/s]
100%|##########| 4966/4966 [00:00<00:00, 11295.73it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 8/4966 [00:00<01:12, 68.78it/s]
 15%|#5        | 760/4966 [00:00<00:01, 3892.29it/s]
 41%|####1     | 2040/4966 [00:00<00:00, 5881.66it/s]
 82%|########2 | 4088/4966 [00:00<00:00, 6978.64it/s]
100%|##########| 4966/4966 [00:00<00:00, 7508.90it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 8/4966 [00:00<01:14, 66.24it/s]
  8%|7         | 380/4966 [00:00<00:02, 1931.37it/s]
 15%|#5        | 764/4966 [00:00<00:01, 2704.88it/s]
 31%|###       | 1532/4966 [00:00<00:01, 3418.21it/s]
 41%|####1     | 2044/4966 [00:00<00:00, 3131.31it/s]
 51%|#####1    | 2556/4966 [00:00<00:00, 2963.81it/s]
 62%|######1   | 3068/4966 [00:01<00:00, 2906.84it/s]
 72%|#######2  | 3580/4966 [00:01<00:00, 2872.53it/s]
 82%|########2 | 4092/4966 [00:01<00:00, 2305.18it/s]
 93%|#########2| 4604/4966 [00:01<00:00, 2346.94it/s]
100%|##########| 4966/4966 [00:01<00:00, 2768.43it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 8/4966 [00:00<01:12, 68.03it/s]
 15%|#5        | 764/4966 [00:00<00:01, 3768.47it/s]
 41%|####1     | 2044/4966 [00:00<00:00, 5817.20it/s]
 82%|########2 | 4092/4966 [00:00<00:00, 7159.68it/s]
100%|##########| 4966/4966 [00:00<00:00, 7599.75it/s]

  0%|          | 0/4966 [00:00<?, ?it/s]
  0%|          | 8/4966 [00:00<01:13, 67.11it/s]
 15%|#5        | 764/4966 [00:00<00:01, 3857.50it/s]
 31%|###1      | 1543/4966 [00:00<00:00, 5508.28it/s]
 62%|######1   | 3068/4966 [00:00<00:00, 7157.43it/s]
 82%|########2 | 4092/4966 [00:00<00:00, 6837.30it/s]
100%|##########| 4966/4966 [00:00<00:00, 7416.73it/s]

  0%|          | 0/8 [00:00<?, ?it/s]
 12%|#2        | 1/8 [00:00<00:03,  2.25it/s]
 25%|##5       | 2/8 [00:00<00:02,  2.96it/s]
 38%|###7      | 3/8 [00:00<00:01,  3.37it/s]
 50%|#####     | 4/8 [00:01<00:01,  3.58it/s]
 62%|######2   | 5/8 [00:01<00:00,  3.65it/s]
 75%|#######5  | 6/8 [00:01<00:00,  3.65it/s]
 88%|########7 | 7/8 [00:01<00:00,  3.76it/s]
100%|##########| 8/8 [00:02<00:00,  3.76it/s]
100%|##########| 8/8 [00:02<00:00,  3.54it/s]

  0%|          | 0/8 [00:00<?, ?it/s]
 12%|#2        | 1/8 [00:00<00:01,  4.04it/s]
 25%|##5       | 2/8 [00:00<00:01,  4.13it/s]
 38%|###7      | 3/8 [00:00<00:01,  4.31it/s]
 50%|#####     | 4/8 [00:00<00:00,  4.24it/s]
 62%|######2   | 5/8 [00:01<00:00,  4.25it/s]
 75%|#######5  | 6/8 [00:01<00:00,  4.17it/s]
 88%|########7 | 7/8 [00:01<00:00,  4.20it/s]
100%|##########| 8/8 [00:01<00:00,  4.18it/s]
100%|##########| 8/8 [00:01<00:00,  4.20it/s]

Visualizing bundles and tract profiles:

This would run the script and visualize the bundles using the plotly interactive visualization, which should automatically open in a new browser window.

bundle_html = myafq.all_bundles_figure
plotly.io.show(bundle_html["01"])