Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3732d6a
Merge pull request #1 from levje/dev2023
levje Feb 19, 2025
f3dcd09
update deprecation warning
levje Feb 19, 2025
025499b
allow empty
levje Feb 19, 2025
62e0baf
Allow save_empty everywhere
levje Feb 20, 2025
9cb8603
Merge remote-tracking branch 'origin/dev2023'
levje May 28, 2025
8d089bf
Merge branch 'master' of github.com:levje/extractor_flow
levje Sep 16, 2025
115afba
Initial commit
arnaudbore Mar 6, 2025
46c687a
Basic registration T1 and TRK
levje Jul 18, 2025
457dd2a
Major filtering and first extraction steps
levje Jul 29, 2025
a63c549
Essential part of original extractor_flow is laid out, but seems to fail
levje Aug 7, 2025
f8bc7e2
Capitalize and start modularization of Merges
levje Aug 10, 2025
dee6e71
Simplify merges into a single module
levje Aug 10, 2025
1c5ecec
Bundle extraction modularization, written but still fails
levje Aug 10, 2025
f2cc785
Fix workflow extension, clean README.
levje Aug 11, 2025
b2bb67d
Cleanup README
levje Aug 11, 2025
d3a2f3a
Remove archives and previous main file
levje Aug 11, 2025
e4b408d
Remove templates and filtering lists
levje Aug 11, 2025
fcb40af
Clean README
levje Aug 11, 2025
a0115fa
Fix: config rename process
levje Aug 14, 2025
7e47c63
Fix end to orig tractogram registration
levje Aug 15, 2025
4d58ceb
Update output filenaming
levje Aug 15, 2025
6c8c46d
Use tmp fix container
levje Aug 20, 2025
c9954ec
Fix mixup of ""
levje Aug 21, 2025
e89bbe7
Fix invalid management
levje Aug 22, 2025
70d80cf
Add docker registry
levje Aug 22, 2025
b67941d
Fix registration problematic path
levje Aug 25, 2025
7969cc4
Update structure and update to newest scilpy container
levje Sep 15, 2025
3e71bb8
Usage comment for templates_dir
levje Sep 15, 2025
961ab37
Clean and use nf-neuro tractogram removeinvalid
levje Sep 16, 2025
8956e58
Fix output paths and module path
levje Sep 16, 2025
c983e31
Fix copy t1 to orig
levje Feb 3, 2026
3102713
Update citation and remove levje references
levje Feb 3, 2026
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
94 changes: 94 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
FROM ubuntu:24.04

USER root

RUN apt-get update --quiet && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install --quiet --yes \
apt-transport-https \
apt-utils \
sudo \
git \
less \
wget \
curl \
tree \
graphviz \
vim \
software-properties-common && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Apptainer (Singularity)
RUN add-apt-repository -y ppa:apptainer/ppa && \
apt-get update --quiet && \
apt install -y apptainer && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Set up directories
RUN mkdir -p /workspaces/.nextflow

# Install Seqera Platform "Tower Agent"
RUN curl -fSL https://github.com/seqeralabs/tower-agent/releases/latest/download/tw-agent-linux-x86_64 > tw-agent && \
chmod +x tw-agent && \
mv tw-agent /usr/local/bin/tw-agent

# Uncomment if we need to pin the Nextflow version
ENV NXF_EDGE=0
ENV NXF_VER=24.10.4
ENV NXF_HOME=/workspaces/.nextflow

ENV NFNEURO_RAW_REPOSITORY="https://raw.githubusercontent.com/scilus/nf-neuro/main"
ENV NFCORE_MODULES_GIT_REMOTE=https://github.com/scilus/nf-neuro.git
ENV NFCORE_MODULES_BRANCH=main
ENV NFCORE_SUBWORKFLOWS_GIT_REMOTE=https://github.com/scilus/nf-neuro.git
ENV NFCORE_SUBWORKFLOWS_BRANCH=main

# Install conda
ENV PATH="/root/miniconda3/bin:${PATH}"
RUN arch=$(uname -m) && \
if [ "$arch" = "x86_64" ]; then \
MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-py312_25.3.1-1-Linux-x86_64.sh"; \
elif [ "$arch" = "aarch64" ]; then \
MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-py312_25.3.1-1-Linux-aarch64.sh"; \
else \
echo "Unsupported architecture: $arch"; \
exit 1; \
fi && \
wget $MINICONDA_URL -O miniconda.sh && \
mkdir -p /root/.conda && \
bash miniconda.sh -b -p /root/miniconda3 && \
rm -f miniconda.sh

# Install nextflow, nf-core, Mamba, and pytest-workflow
RUN conda install --name=base conda-anaconda-tos && \
conda config --add channels bioconda && \
conda config --add channels conda-forge && \
conda config --set channel_priority strict && \
conda tos accept && \
conda update --quiet --yes --all && \
conda install --quiet --yes --name base \
mamba \
nextflow=$NXF_VER \
nf-core=2.14.1 \
nf-test=0.9.2 \
black \
prettier \
pre-commit \
linkify-it-py \
pytest-workflow && \
conda clean --all --force-pkgs-dirs --yes

# Cleanup
RUN printf 'unset JAVA_TOOL_OPTIONS\n' >> $HOME/.bashrc

# Update Nextflow
RUN nextflow self-update && nextflow -version

RUN unset JAVA_TOOL_OPTIONS
ENV PS1='\[\e[3;36m\]${PWD/*//} ->\[\e[0m\] '

# Get history
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
&& echo "$SNIPPET" >> "/root/.bashrc"
50 changes: 50 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "nextflow-training",
"build": { "dockerfile": "Dockerfile", "context": ".." },
"forwardPorts": [3000],
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"dockerDashComposeVersion": "none",
"installDockerComposeSwitch": false
}
},
"postCreateCommand": {
"identify": "if [ -z \"$CODESPACES\" ]; then echo \"Devcontainers Development\"; else echo \"Codespaces Development\"; fi",
"trust": "git config --global --add safe.directory /workspaces"
},
"mounts": [
{
"target": "/tmp",
"type": "volume"
},
{
"target": "/root/.vscode-server",
"type": "volume"
},
{
"target": "/commandhistory",
"type": "volume",
"source": "nf-neuro-tutorial-${devcontainerId}-bashhistory"
}
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/opt/conda/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"nf-core.nf-core-extensionpack", // nf-core recommended extensions
"nextflow.nextflow", // Nextflow VS Code extension
"codezombiech.gitignore", // Language support for .gitignore files
"cssho.vscode-svgviewer", // SVG viewer
"nf-neuro.nf-neuro-extensionpack"
]
}
}
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.nextflow.log*
.vscode
.nextflow
.nf-test.log

tests/.runs/
work/
.nf-test/
extractor_templates/
2 changes: 2 additions & 0 deletions .nf-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
repository_type: pipeline
119 changes: 98 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,118 @@
# Extractor Flow: streamline filtering pipeline

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/scilus/extractor_flow)](https://github.com/scilus/extractor_flow/releases)
[![Documentation Status](https://readthedocs.org/projects/extractor_flow/badge/?version=latest)](https://extractor_flow.readthedocs.io/en/latest/?badge=latest)
[![Docker container badge](https://img.shields.io/docker/v/scilus/scilus-flows?label=docker&logo=docker&logoColor=white)](https://hub.docker.com/r/scilus/scilus-flows)
ExtractorFlow is a streamline filtering pipeline written in nextflow. In essence, you provide any tractogram file (i.e. `*.trk`) as an input and this pipeline will output which streamlines are deemed as anatomically **plausible** and **implausible** as separate `.trk` files.

Additionnally, as described below, you can use this pipeline to extract recognized (i.e. plausible) bundles of streamlines.

ExtractorFlow pipeline
======================
When using this work, please cite using the following:

Usage
-----
```
PETIT, Laurent, ALI, Kariem Mahdy, RHEAULT, François, et al. The structural connectivity of the human angular gyrus as revealed by microdissection and diffusion tractography. Brain Structure and Function, 2023, vol. 228, no 1, p. 103-120.
```

See *USAGE* or run `nextflow run main.nf --help`
## Requirements
- [Nextflow](https://www.nextflow.io/docs/latest/install.html)
- [Docker](https://www.docker.com/get-started/) (recommended) or [Apptainer](https://apptainer.org/docs/admin/main/installation.html) depending on the runtime you choose.

Singularity
-----------
You should be able to run the following commands without any errors being printed:
```bash
# 1. Make sure Nextflow is installed.
nextflow -v

If you are on Linux, we recommend using the Singularity container to run ExtractorFlow
# 2a. Make sure Docker is installed.
docker ps

Run the command (your working directory has to be the "containers" directory):
# 2b. Make sure Apptainer is installed.
apptainer version
```

`sudo singularity build singularity_extractorflow.sif singularity_extractorflow.def`
## Getting started
### Understand the input
This nextflow pipeline has **two** mandatory arguments that any user has to provide in order to run the pipeline.
1. `--input`
2. `--templates_dir`

Then you can start the pipeline using this command line:
Both of these arguments point to two different directories that have their own particular structure:

#### `--input`
This argument points to the directory holding all the tractograms you wish to filter. Also, within this directory, each tractogram should probably be associated with a T1w image (in diffusion space). This T1w image is used to register your tractograms to MNI space, which is the space where the filtering is performed. **If no T1w image is provided, your tractograms are assumed to be already in the appropriate template (MNI) space**. This said, your directory structure should look like the following:
```
nextflow main.nf --root=/path_to_your_data/ -with-singularity singularity_extractorflow.sif -resume
input_example
├── subject-01
│   ├── subject-01__t1.nii.gz
│   └── subject-01_tracking.trk
├── subject-02
│   ├── subject-02__t1.nii.gz
│   └── subject-02_tracking.trk
├── ...
└── subject-n
├── subject-n__t1.nii.gz
└── subject-n_tracking.trk
```
If your tractograms are already in the right space, keep the same structure, but omit the `*t1.nii.gz` files.

#### `--templates_dir`
To simplify the usage of this pipeline and to avoid cluttering the containers used, the user must download extract the different templates used and the lists that are used during filtering in this pipeline (don't worry, it's a simple process).

All you have to do is execute the following commands to download and extract the needed files into a new directory that we called `extractor_templates`.

Docker
------
If you are on MacOS or Windows, we recommend using the Docker container to run ExtractorFlow.
```bash
wget https://github.com/scilus/extractor_flow/raw/refs/heads/master/containers/filtering_lists.tar.bz2 && wget https://github.com/scilus/extractor_flow/raw/refs/heads/master/containers/templates_and_ROIs.tar.bz2

mkdir -p extractor_templates

tar -xjf filtering_lists.tar.bz2 -C extractor_templates && rm filtering_lists.tar.bz2
tar -xjf templates_and_ROIs.tar.bz2 -C extractor_templates && rm templates_and_ROIs.tar.bz2
```

You can build docker image using this command (your working directory has to be the "containers" directory):
> If you don't have the `wget` and/or the `tar` commands and you don't want (or can't) to install them, you can always download the two archives manually from [here](https://github.com/scilus/extractor_flow/raw/refs/heads/master/containers/filtering_lists.tar.bz2) and [here](https://github.com/scilus/extractor_flow/raw/refs/heads/master/containers/templates_and_ROIs.tar.bz2) and extract them into a new directory called `extractor_templates`. Just make sure that you have the following directory structure.

`docker build -t extractor_flow .`
From this point, you should have a directory containing the following structure that you'll use to provide as a value to the `--template_dir` argument in the following steps:
```
extractor_templates/
├── filtering_lists
│ ├── ...
└── templates_and_ROIs
└── ...
```

#### Complete arguments list
To get a complete list of the available arguments you can provide, always refer to the usage printed by the nextflow script as follows:
```bash
nextflow run scilus/extractor_flow --help
```

### Standard filtering using Docker (recommended).
The following example gives a general idea on what arguments you can provide. The key part is to select the `docker` profile as well as providing the mandatory arguments (i.e. `--input` & `--templates_dir`):
```bash
nextflow run scilus/extractor_flow \
--input <input_folder> \
--templates_dir <path/to/extractor_templates> \
-profile docker \
[--orig]
[--keep_intermediate_steps]
[-resume]
```

### Standard filering using Apptainer/Singularity.
To use apptainer containers, you should only have to swap the profile used to `apptainer` as shown in the following example:
```bash
nextflow run scilus/extractor_flow \
--input <input_folder> \
--templates_dir <path/to/extractor_templates> \
-profile apptainer \
[--orig]
[--keep_intermediate_steps]
[-resume]
```
nextflow main.nf --root=/path_to_your_data/ -with-docker extractor_flow:latest -resume
### Filtering and bundle extraction.
Notice, in the following example, the addition of the `extract_bundles` profile. This will trigger a few additionnal processes that will separate and organize new files refering to the bundles identified by this flow. The example is using Docker (as the docker profile is enabled), but the same applies for Apptainer.
```bash
nextflow run scilus/extractor_flow \
--input <input_folder> \
--templates_dir <path/to/extractor_templates> \
-profile docker,extract_bundles \
[--orig]
[--keep_intermediate_steps]
[-resume]
```
16 changes: 13 additions & 3 deletions USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ DESCRIPTION
└── S2
└── *.trk
└── *_t1.nii.gz (diff space, optional)
--templates_dir=/path/to/templates_dir
ABSOLUTE PATH to directory containing the templates
and the filtering lists (e.g. JHU atlas). Structure
should look like:
[templates_dir]
├── templates_and_ROIs
│ ├── JHU*.nii.gz
└── filtering_lists
└── filtering_list_*.txt


OPTIONAL ARGUMENTS (current value)

Expand All @@ -33,13 +43,13 @@ OPTIONAL ARGUMENTS (current value)

--quick_registration If set, will choose antsRegistrationSyNQuick.sh instead of antsRegistrationSyN.sh ($quick_registration).

--processes_bet_register_t1 Number of processes for T1 brain extraction task ($processes_bet_register_t1).
--processes_major_filtering Number of processes for the major filtering task ($processes_major_filtering).
--processes The number of parallel processes to launch ($cpu_count).
Only affects the local scheduler.

AVAILABLE PROFILES (using -profile option (e.g. -profile macos,extract_bundles))

macos When this profile is used, ExtractorFlow will modify a parameter (scratch) for MacOS users.
docker When this profile is used, all processes will execute within Docker containers (recommended).
apptainer When this profile is used, all processes will execute within Apptainer containers.
fully_reproducible When this profile is used, all the parameters will be set to have 100% reproducible results.
extract_bundles Extract bundles
extract_bundles The flow will perform additional processing to extract all recognized bundles.
18 changes: 18 additions & 0 deletions config/resources.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


params.max_cpus = 4
params.max_time = 24.h


profiles {
default_github_runner {
params.max_memory = 5.GB
}
big_mem_github_runner {
params.max_memory = 16.GB
}
devcontainer {
params.max_cpus = query_container_limits('cpus')
params.max_memory = query_container_limits('memory')
}
}
Binary file removed containers/filtering_lists.tar.bz2
Binary file not shown.
11 changes: 0 additions & 11 deletions containers/singularity_extractorflow.def

This file was deleted.

Binary file removed containers/templates_and_ROIs.tar.bz2
Binary file not shown.
Loading