CBICA / BrainMaGe

Brain extraction in presence of abnormalities, using single and multiple MRI modalities
Other
32 stars 7 forks source link

Turn BrainMaGe into a BIDS app #3

Closed Terf closed 4 years ago

Terf commented 4 years ago

This PR adds a "BIDS" mode so rather than reading subjects from a provided CSV users could simply specify the path to their (BIDS) dataset, then individual image paths can be extracted using pybids. For example,

docker run \
-v $PWD/ds000001-download:/bids_dataset:ro \
-v $PWD/out:/path/to/output/directory \
cbica/brainmage -params ./BrainMaGe/config/test_params_ma.cfg -test True -mode BIDS -dev 0

with test_dir = /bids_dataset in test_params_ma.cfg will use all available modalities, writing out a CSV as the other modes do.

I noticed one of the TODOs in the README is to "Remove -mode parameter in brain_mage_run," so I'm not sure if this is the best approach, but if you are interested in incorporating a BIDS mode, I could refactor it to work another way.

Geeks-Sid commented 4 years ago

@sarthakpati Can you take a look?

Geeks-Sid commented 4 years ago

@Terf Can you create a dummy dataset so that I can unit test this too?

Terf commented 4 years ago

Ahh, I had missed your comments until now, @Geeks-Sid and @sarthakpati . OpenNeuro (formerly OpenfMRI) is a great resource for publicly available datasets, and they're all in the BIDS format. I arbitrarily chose "ds000001" but you can download any of their datasets using the AWS CLI. Using Docker, you could download ds000001 (in the background with -d)

docker run -d --rm -v $PWD:/aws amazon/aws-cli s3 sync \
--no-sign-request s3://openneuro.org/ds000001 ds000001-download/

or on the cluster using singularity:

qsub -b y -cwd -o /dev/null -e /dev/null \
singularity run --cleanenv -B $PWD:/aws docker://amazon/aws-cli s3 sync \
--no-sign-request s3://openneuro.org/ds000001 ds000001-download/

Then if the contents of ./BrainMaGe/config/test_params_ma.cfg are set to (but otherwise unchanged)

results_dir = /out
test_dir = /bids_dataset
mode = bids
csv_provided = False

you should be able to run (this time explicitly bind mounting the config in case you don't build it into the image that way):

docker run \
-v $PWD/ds000001-download:/bids_dataset:ro \
-v $PWD/out:/out \
-v $PWD/BrainMaGe/config/test_params_ma.cfg:/src/BrainMaGe/config/test_params_ma.cfg
cbica/brainmage -params ./BrainMaGe/config/test_params_ma.cfg -test True -mode BIDS -dev 0

or on the cluster using singularity:

qsub -b y -cwd -l h_vmem=32G -l V100 -l short \
singularity run --nv --cleanenv \
-B $PWD/ds000001-download:/bids_dataset:ro \
-B $PWD/out:/out \
-B $PWD/BrainMaGe/config/test_params_ma.cfg:/src/BrainMaGe/config/test_params_ma.cfg \
~/simg/brainmage_latest.sif -params ./BrainMaGe/config/test_params_ma.cfg -test True -mode BIDS -dev 0

(/cbica/home/robertft/simg/brainmage_latest.sif is where I pulled the image to with singularity pull docker://pennsive/brainmage if you want to try this yourself) The skull strips on this particular dataset don't look great, however, because they aren't registered to the SRI 24 atlas (or oriented in RAI/LPS space?). Beyond the scope of this PR, but I was hoping to include a wrapper for preprocessing but am having some trouble figuring out the CaPTk preprocessing pipeline. Initially I used my own tools for registration but think it would be good for reproducibility to use the exact tools you used. The CaPTk page on the BraTS Pre-processing Pipeline references a BraTSPipeline.exe executable, but I can't find this anywhere in the CaPTk version available on CUBIC through environment models or in the docker container. In the docker containers /work/CaPTk/bin path, I can see an executable called Preprocessing (docker run --rm -it --entrypoint="" cbica/captk bash -c "/work/CaPTk/bin/Preprocessing"), but it doesn't seem to be the same thing as the BraTSPipeline.exe -- where would I find the BraTS pre-processing pipeline?