Skip to content

Commit 0ce9dc3

Browse files
Merge branch 'main' into mackenzie/add-wetrun-testing
2 parents d1762b1 + c06018a commit 0ce9dc3

32 files changed

+592
-206
lines changed

.github/workflows/python-testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ jobs:
113113
run: |
114114
poetry run autoafids test_data/bids_wetrun_testing test_out participant --cores all --force-output \
115115
--stereotaxy STN --fidqc && \
116-
python ./tests/test_fcsv_output.py --autoafids_fcsv ./test_data/test_out/sub-001/afids-cnn/*.fcsv \
116+
python ./test_data/bids_wetrun_testing/test_fcsv_output.py --autoafids_fcsv ./test_data/test_out/sub-001/afids-cnn/*.fcsv \
117117
--baseline_fcsv ./test_data/bids_wetrun_testing/sub-001*.fcsv

.readthedocs.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
# .readthedocs.yml
3+
# Read the Docs configuration file
4+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
5+
6+
# Required
7+
version: 2
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
configuration: docs/conf.py
11+
# Build documentation with MkDocs
12+
# mkdocs:
13+
# configuration: mkdocs.yml
14+
15+
# Optionally build your docs in additional formats such as PDF
16+
formats: [pdf]
17+
build:
18+
os: ubuntu-20.04
19+
tools:
20+
python: '3.10'
21+
python:
22+
install:
23+
- requirements: docs/requirements.txt
24+
- method: pip
25+
path: .

README.md

+15-53
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,36 @@
11
# Automatic Anatomical Fiducials (AutoAFIDs)
2+
[![Documentation Status](https://readthedocs.org/projects/autoafids/badge/?version=stable)](https://autoafids.readthedocs.io/en/stable/?badge=stable)
3+
![Version](https://img.shields.io/github/v/tag/afids/autoafids?label=version)
4+
![Python3](https://img.shields.io/badge/python-_3.10_|_3.11-blue.svg)
5+
[![Tests](https://github.com/khanlab/scattr/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/khanlab/scattr/actions/workflows/test.yml?query=branch%3Amain)
6+
![Docker Pulls](https://img.shields.io/docker/pulls/mackenzieasnyder/autoafids)
7+
28
AIMS Lab Research Team at the Robarts Research Institute - 2023-2024
39

410
*This package is under active development. It should be stable and reproducible, but please let any of the active contributing members know if there are any bugs or unusual behaviour.*
511

612
This Python package is a standard 3D [U-Net](https://arxiv.org/abs/1505.04597) (Ronneberger et al. 2015) machine learning model based on Snakemake and SnakeBIDS workflow management tools that leverages the recent release of the anatomical fiducial framework to solve the landmark regression problem on 3D MRI images. It is currently in development phase and contains tunable parameters that are not normally exposed in most other machine learning models; the user is highly advised to get familiar with the above mentioned workflow managaments tools and read docstrings and relevant documentation before using this software. Please see the [changelog](CHANGELOG.md) for more details.
713

8-
## Table of Contents
9-
1. [Installation](#installation)
10-
2. [Workflow](#workflow)
11-
2. [Train](#train)
12-
3. [Apply](#apply)
13-
4. [Known issues](#known-issues)
14-
5. [Roadmap](#roadmap)
15-
6. [Questions, Issues, Suggestions, and Other Feedback](#questions--issues)
16-
17-
## Installation
18-
19-
### Installing Poetry
20-
We use poetry tool for dependency management and to package the python project. You can find step by step instructions on how to install it by visiting it's official [website](https://python-poetry.org/docs/).
21-
22-
### Local Installation
23-
24-
After installing poetry, clone this repository via:
25-
26-
```bash
27-
git clone https://github.com/afids/autoafids.git
28-
```
29-
30-
You can then install the python package using one of the following commands, which should be executed within the repository folder (i.e., autoafids/).
31-
32-
```bash
33-
poetry install
34-
```
35-
If you want to install in _develop mode_, use:
14+
## Workflow
3615

37-
```bash
38-
poetry install -e
39-
```
16+
A brief summary of the workflow can be found below along with its Directed Acyclic Graph (DAG) (see documentation for a detailed summary):
4017

41-
## Workflow
42-
Below is a simplified example of the workflow along with its Directed Acyclic Graph (DAG) for the `--procprofile` fast. Each rounded rectangle (vertex) in the DAG represents a rule, which encompasses some code or script that produces output file(s), and the arrows (edges) represent file inputs and outputs to these rules.
18+
<img src="docs/workflow/dag.svg" alt="Workflow DAG" width="600">
4319

44-
<img src="docs/dag.svg" alt="Workflow DAG" width="600">
20+
1. Preprocess input NIfTI files based on image modality
21+
2. Download and apply the fiducial model
4522

46-
### Processing landmark data (AFIDs)
23+
## Processing landmark data (AFIDs)
4724
1. Extract fiducial points from the landmark files (.fcsv is supported)
4825
2. Generate a landmark Euclidean distance/probability map with each voxel communicating distance to an AFID of interest
4926

50-
## Train
51-
Currently, we support generating your own models (i.e., training) in a sperate workflow (i.e., afids-cnn: https://github.com/afids/afids-CNN). For more details, see [Known Issues](#known-issues).
52-
53-
54-
## Apply
55-
Use the classic BIDS App syntax to genereate output AFID .fcsv files. For other derivative outputs, the following flags will be supported:
56-
57-
`--fidqc`: for quality control of landmark prediction in the form of (*html) format
58-
59-
`--regqc`: for quality control of registration on a BIDS dataset and its derivatives (e.g., fMRIPrep or LeadDBS derivative outputs)
60-
61-
`--stereotaxy`: predicts a .fcsv file with stereotactic targets (e.g., subthalamaic nucelus) also providing AC-PC transform files in the process
62-
63-
`--charing`: to make use of AFID charting analysis on a given dataset
64-
6527
## Known Issues
6628
- Factorize apply workflow to run per landmark of interest
6729

68-
## Roadmap
30+
### **Full documentation:** [here](https://autoafids.readthedocs.io/en/)
6931

70-
- Model optimization
71-
- Extension to incorporate new modalities (i.e., CT scans)
32+
## Revalent Papers:
33+
* Link relavent papers to autoafids here
7234

7335
## Questions, Issues, Suggestions, and Other Feedback
7436
Please reach out if you have any questions, suggestions, or other feedback related to this software—either through email (dbansal7@uwo.ca) or the discussions page. Larger issues or feature requests can be posted and tracked via the issues page. Finally, you can also reach out to Alaa Taha, the Science Lead.

autoafids/config/snakebids.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pybids_inputs:
5151
- reconstruction
5252
- run
5353

54-
CT:
54+
ct:
5555
filters:
5656
suffix: ct
5757
extension: .nii.gz

autoafids/run.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
from snakebids import bidsapp, plugins
55

6+
if "__file__" not in globals():
7+
__file__ = "../autoafids/run.py"
8+
69
app = bidsapp.app(
710
[
811
plugins.SnakemakeBidsApp(Path(__file__).resolve().parent),
@@ -15,7 +18,7 @@
1518

1619

1720
def get_parser():
18-
"""Exposes parser for sphinx doc generation, cwd is the docs dir."""
21+
"""Exposes parser for sphinx doc generation, cwd is the docs dir"""
1922
return app.build_parser().parser
2023

2124

autoafids/workflow/scripts/apply.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Suppresses INFO, WARNING, and ERROR logs.
99
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
10+
1011
import tarfile
1112
from os import PathLike
1213

docs/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for sphinx documentation
2+
3+
# You can set these variables from command line, and also
4+
# from the environment for the first two.
5+
SPHINXOPTS ?=
6+
SPHINXBUILD ?= sphinx-build
7+
SOURCEDIR = .
8+
BUILDDIR = _build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(0) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66

77
# -- Path setup --------------------------------------------------------------
88

9+
import datetime
10+
911
# If extensions (or modules to document with autodoc) are in another directory,
1012
# add these directories to sys.path here. If the directory is relative to the
1113
# documentation root, use os.path.abspath to make it absolute, like shown here.
1214
#
13-
# import os
14-
# import sys
15-
# sys.path.insert(0, os.path.abspath('.'))
15+
import os
16+
import sys
17+
18+
sys.path.insert(0, os.path.abspath('.'))
1619

1720
# -- Project information -----------------------------------------------------
1821

1922

2023
project = "autoafids"
21-
copyright = "2024, Alaa Taha"
24+
copyright = f"{datetime.date.today().year}, Alaa Taha"
2225
author = "Alaa Taha"
2326

2427

@@ -55,4 +58,4 @@
5558
# Add any paths that contain custom static files (such as style sheets) here,
5659
# relative to this directory. They are copied after the builtin static files,
5760
# so a file named "default.css" will overwrite the builtin "default.css".
58-
# html_static_path = ["_static"]
61+
html_static_path = ["_static"]

docs/contributing/contributing.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Contributing to Autoafids
2+
3+
Autoafids python package uses Poetry pacakge manager to manage its dependencies. You’ll need it installed on your machine before contributing to the software. Installation instructions can be found on the
4+
[Poetry website](https://python-poetry.org/docs/master/#installation).
5+
6+
Autoafids primarily caters to T1w modality images, in which case it doesn't need to depend on pacakges outside of python but for other modalities it has a single dependency outside of python, i.e., `synthsr`.
7+
8+
Note: These instructions are only recommended if you are making changes to the Autoafids codebase and committing these back to the repository or if you are using Snakemake’s cluster execution profiles.
9+
10+
## Setup the development environment
11+
12+
Once Poetry is available, clone this repository and install all dependencies (including `dev`):
13+
14+
```
15+
git clone https://github.com/afids/autoafids.git
16+
cd autoafids
17+
poetry install --with dev
18+
```
19+
20+
Poetry will automatically create a virtual environment. To customize where
21+
these virtual environments are stored, see the poetry docs
22+
[here](https://python-poetry.org/docs/configuration/).
23+
24+
Then, you can run autoafids:
25+
26+
```
27+
autoafids -h
28+
```
29+
30+
or you can activate a virtual environment shell and run autoafids directly:
31+
32+
```
33+
poetry shell
34+
autoafids
35+
```
36+
37+
You can exit the poetry shell with `exit`
38+
39+
## Running and fixing code format quality
40+
41+
Autoafids uses [poethepoet](https://github.com/nat-n/poethepoet) as a task runner.
42+
You can see what commands are available by running:
43+
44+
```
45+
poetry run poe
46+
```
47+
48+
We use a few tools, including `ruff`, `snakefmt`, and `yamlfix` to ensure
49+
formatting and style of our codebase is consistent. There are two task runners
50+
you can use to check and fix your code, which can be invoked with:
51+
52+
```
53+
poetry run poe quality-check
54+
poetry run poe quality
55+
```
56+
57+
_Note: If you are in a poetry shell, you do not need to prepend `poetry run` to
58+
the command._
59+
60+
## Dry-run / testing your workflow
61+
62+
Using Snakemake\'s dry-run option (`--dry-run`/`-n`) is an easy way to verify
63+
any changes made to the workflow are working direcctly. The `tests/data` folder
64+
contains a _fake_ BIDS dataset (i.e. dataset with zero-sized files) that is
65+
useful for verifying different aspects of the workflow. These dry-run tests are
66+
part of the automated Github actions that are run for every commit.
67+
68+
You can invoke the pre-configured task via
69+
[poethepoet](https://github.com/nat-n/poethepoet) to perform a dry-run:
70+
71+
```
72+
poetry run poe test_base
73+
```
74+
75+
This performs a number of tests, involving different scenarios in which a user
76+
may use autoafids.
77+
78+
## Questions, Issues, Suggestions, and Other Feedback
79+
Please reach out if you have any questions, suggestions, or other feedback related to this software—either through email (dbansal7@uwo.ca) or the discussions page. Larger issues or feature requests can be posted and tracked via the issues page. Finally, you can also reach out to Alaa Taha, the Science Lead.

docs/getting_started/docker.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Running Autoafids with Docker
2+
3+
Brief walkthrough on how to prepare the `autoafids` package in a Docker container.
4+
5+
## Local Build Instructions
6+
To build a docker image of the project locally, do the following:
7+
1. Download the git repo:
8+
9+
```
10+
git clone https://github.com/afids/autoafids.git
11+
```
12+
2. Ensure you have installed [Docker](https://docs.docker.com/engine/install/) and that it's up and running.
13+
14+
3. Build the docker image using the following command; it should be executed within the repository folder (i.e., autoafids/).
15+
16+
```
17+
docker build -t autoafids:<VERSION> -f ./docker/Dockerfile .
18+
```
19+
20+
4. Once the image is built, you can then run the pipeline as follows:
21+
22+
```
23+
docker run -it --rm \
24+
-v local/path/to/dataset:/bids_dataset \
25+
-v local/path/to/dataset/derivatives:/output \
26+
autoafids:<VERSION> \
27+
/bids_dataset /output participant --cores all
28+
```
29+
30+
The first time building this image may take some time because poetry takes a while to install all the required python packages.

0 commit comments

Comments
 (0)