Skip to content

Commit

Permalink
added synthseg options to contianers
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza committed Sep 9, 2024
1 parent e2a2a5f commit db56fae
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 26 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ data directory structure (press enter for default) (alfe, bids) [alfe]:
The directory structure that pyALFE expects in the input directory and will follow when creating the output. See [Inupt directory](#input-directory) for information on ALFE and BIDS.
This config value can be overwritten when calling `payalfe run` via `-dds` or `--data-dir-structure` option.

#### Tissue Segmentation
```bash
tissue segmentation method (press enter for default) (prior, synthseg) [prior]:
```

The tissue segmentation method that will be used by pyALFE. The default is based on the method described in this [paper](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8346689/), a UNet
that receives a template-based **prior** map tissue alongside the image . pyALFE
also supports [SynthSeg](https://www.sciencedirect.com/science/article/pii/S1361841523000506) via [FreeSurfer](https://surfer.nmr.mgh.harvard.edu/fswiki/SynthSeg). To use SynthSeg, you have to have FreeSurfer >= v7
installed.

### Running the pipeline
To run PyALFE for an accession

Expand Down
45 changes: 41 additions & 4 deletions docs/guides/tutorial.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Tutorial

In this tutorial, you will download sample data, install pyalfe, and run it on this data.
This tutorial requires `git`, `python>=3.9`, [greedy](https://sourceforge.net/projects/greedy-reg/files/),
and [c3d](https://sourceforge.net/projects/c3d/).
In this tutorial, you will download sample data, install pyalfe, configure it, and run it on this data.
This tutorial requires `git`, `python>=3.9`, [greedy](https://sourceforge.net/projects/greedy-reg/files/).


## Data download and directory setup
Expand All @@ -15,7 +14,7 @@ This will create a directory named `pyalfe-test-data` and downloads the tutorial
data inside it. The data is the MRI scan of a glioblastoma patient and is
taken from the [UPenn-GBM dataset](https://www.nature.com/articles/s41597-022-01560-7).

2. Create an output directory where you have write access
2. Create the output directory
```bash
mkdir -p pyalfe-output
```
Expand All @@ -38,8 +37,46 @@ Download models
pyalfe download models
```

Configure pyalfe by running
```bash
pyalfe configrue
```
and simply pressing enter for all the prompts for default values.

## Run
```bash
pyalfe run UPENNGBM0000511 --input-dir pyalfe-test-data --output-dir pyalfe-output
```

## Pipeline output
You can now inspect the pipeline output by changing directory to

```bash
cd pyalfe-output/UPENNGBM0000511
```
and exploring the `FLAIR`, `T1`, `T1Post`, `T2`, `ADC` subdirectories.

For instance, the individual FLAIR lesion measures can be found at:
```bash
FLAIR/quantification/UPENNGBM0000511_SummaryLesionMeasures.csv
```

FLAIR lesion segmentation can be found at:
```bash
FLAIR/abnormalmap/UPENNGBM0000511_FLAIR_abnormal_seg.nii.gz
```

Summary T1Post (enhancing) lesion measures can be found at:
```bash
T1Post/quantification/UPENNGBM0000511_IndividualLesionMeasures.csv
```

Brain volumetric measures can be found at:
```bash
T1/quantification/UPENNGBM0000511_volumeMeasures.csv
```

The tissue segmentation can be found at:
```bash
T1/UPENNGBM0000511_T1_tissue_seg.nii.gz
```
8 changes: 8 additions & 0 deletions docs/guides/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ The directory structure that pyALFE expects in the input directory and will foll
This config value can be overwritten when calling `payalfe run` via `-dds` or `--data-dir-structure` option.

#### Tissue Segmentation
```bash
tissue segmentation method (press enter for default) (prior, synthseg) [prior]:
```

The tissue segmentation method that will be used by pyALFE. The default is based on the method described in this [paper](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8346689/), a UNet
that receives a template-based **prior** map tissue alongside the image . pyALFE
also supports [SynthSeg](https://www.sciencedirect.com/science/article/pii/S1361841523000506) via [FreeSurfer](https://surfer.nmr.mgh.harvard.edu/fswiki/SynthSeg). To use SynthSeg, you have to have FreeSurfer >= v7
installed.

### Running the pipeline
To run PyALFE for an accession
Expand Down
67 changes: 47 additions & 20 deletions pyalfe/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)
from pyalfe.image_processing import Convert3DProcessor, NilearnProcessor
from pyalfe.image_registration import GreedyRegistration, AntsRegistration
from pyalfe.inference import NNUnetV2
from pyalfe.inference import NNUnetV2, SynthSeg
from pyalfe.models import MODELS_PATH
from pyalfe.pipeline import PyALFEPipelineRunner, DicomProcessingPipelineRunner
from pyalfe.tasks.dicom_processing import DicomProcessing
Expand All @@ -26,6 +26,7 @@
TissueWithPriorSegementation,
SingleModalitySegmentation,
MultiModalitySegmentation,
SynthSegTissueSegmentation,
)
from pyalfe.tasks.skullstripping import Skullstripping
from pyalfe.tasks.t1_postprocessing import T1Postprocessing
Expand Down Expand Up @@ -92,6 +93,10 @@ def image_processor(self):
return Convert3DProcessor()
elif self.config.options.image_processor == 'nilearn':
return NilearnProcessor()
else:
raise ValueError(
f'Invalid image processor {self.config.options.image_processor}'
)

@property
def image_registration(self):
Expand Down Expand Up @@ -145,16 +150,23 @@ def enhancement_model(self):

@cached_property
def tissue_model(self):
return NNUnetV2(
model_dir=str(
MODELS_PATH.joinpath(
'nnunetv2',
'Dataset510_Tissue_W_Prior',
'nnUNetTrainer__nnUNetPlans__3d_fullres',
)
),
folds=(3,),
)
if self.config.options.tissue_segmentation == 'prior':
return NNUnetV2(
model_dir=str(
MODELS_PATH.joinpath(
'nnunetv2',
'Dataset510_Tissue_W_Prior',
'nnUNetTrainer__nnUNetPlans__3d_fullres',
)
),
folds=(3,),
)
elif self.config.options.tissue_segmentation == 'synthseg':
return SynthSeg()
else:
raise ValueError(
f'Invalid tissue segmentation {self.config.options.tissue_segmentation}'
)

@cached_property
def initialization(self):
Expand Down Expand Up @@ -225,15 +237,30 @@ def enhancement_segmentation(self):

@cached_property
def tissue_segmentation(self):
return TissueWithPriorSegementation(
inference_model=self.tissue_model,
image_processor=self.image_processor,
pipeline_dir=self.pipeline_dir,
image_type_input='trim_upsampled',
image_type_output='tissue_seg',
template_name='Tissue',
overwrite=self.config.options.overwrite_images,
)
if self.config.options.tissue_segmentation == 'prior':
return TissueWithPriorSegementation(
inference_model=self.tissue_model,
image_processor=self.image_processor,
pipeline_dir=self.pipeline_dir,
image_type_input='trim_upsampled',
image_type_output='tissue_seg',
template_name='Tissue',
overwrite=self.config.options.overwrite_images,
)
elif self.config.options.tissue_segmentation == 'synthseg':
return SynthSegTissueSegmentation(
inference_model=self.tissue_model,
image_processor=self.image_processor,
pipeline_dir=self.pipeline_dir,
image_type_input='trim_upsampled',
image_type_output='tissue_seg',
template_name='Tissue',
overwrite=self.config.options.overwrite_images,
)
else:
raise ValueError(
f'Invalid tissue segmentation {self.config.options.tissue_segmentation}'
)

@cached_property
def t1_postprocessing(self):
Expand Down
8 changes: 6 additions & 2 deletions pyalfe/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,14 @@ def configure():
None
"""
input_dir = click.prompt(
'Enter input image directory', type=click.Path(exists=True, resolve_path=True)
'Enter input image directory ' '(press enter to skip)',
default='',
type=click.Path(resolve_path=True),
)
output_dir = click.prompt(
'Enter output image directory', type=click.Path(exists=True, resolve_path=True)
'Enter output image directory' '(press enter to skip)',
default='',
type=click.Path(resolve_path=True),
)
modalities = click.prompt(
'Enter modalities separated by comma (press enter for default)',
Expand Down

0 comments on commit db56fae

Please sign in to comment.