Skip to content

Commit

Permalink
add method section
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Sep 16, 2024
1 parent 6c5d460 commit 4d8148b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 6 deletions.
8 changes: 6 additions & 2 deletions code/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from argparse import ArgumentParser, HelpFormatter

from _version import __version__
from defaults import supported_batches
from defaults import CAT_VERSION, MCR_VERSION, supported_batches


def _base_parser(
Expand All @@ -17,7 +17,11 @@ def _base_parser(
"--version",
action="version",
help="Show program's version number and exit.",
version=__version__,
version=f"""
BIDS app: {__version__};
CAT12: {CAT_VERSION};
MATLAB MCR: {MCR_VERSION}
""",
)
parser.add_argument(
"bids_dir",
Expand Down
8 changes: 8 additions & 0 deletions code/data/methods/template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
These results were generated with the BIDS app for Computational Anatomy Toolbox
(BIDS app: {{version}}; CAT12: {{cat_version}}; MATLAB MCR: {{mcr_version}})

The following steps were followed.

1. ...

2. ...
11 changes: 7 additions & 4 deletions code/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from __future__ import annotations

import os

MCR_VERSION = os.getenv("MCR_VERSION")
CAT_VERSION = " ".join(os.getenv("CAT_VERSION")[1:10].split("_"))


def log_levels() -> list[str]:
"""Return a list of log levels."""
Expand All @@ -16,9 +21,7 @@ def supported_batches() -> list[str]:
"segment_long",
"segment_enigma",
"resample",
"tfce",
"get_IQR",
"smooth",
"get_TIV",
"get_quality",
"get_ROI_values",
Expand All @@ -31,13 +34,13 @@ def supported_batches() -> list[str]:
# cat_standalone_segment_long.m

# cat_standalone_resample.m
# cat_standalone_tfce.m
# cat_standalone_get_IQR.m
# cat_standalone_smooth.m
# cat_standalone_get_TIV.m
# cat_standalone_get_quality.m
# cat_standalone_get_ROI_values.m

# WON'T DO
# cat_standalone_smooth.m
# cat_standalone_tfce.m
# cat_standalone_dicom2nii.m
# cat_standalone_deface.m
3 changes: 3 additions & 0 deletions code/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)
from cat_logging import cat12_log
from defaults import log_levels
from methods import generate_method_section
from rich import print
from rich_argparse import RichHelpFormatter
from utils import progress_bar
Expand Down Expand Up @@ -118,6 +119,8 @@ def main():

logger.info(f"{segment_type=} - using batch {batch}.")

generate_method_section(output_dir=output_dir, batch=batch)

text = "processing subjects"
with progress_bar(text=text) as progress:

Expand Down
38 changes: 38 additions & 0 deletions code/methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Module responsible for generating method section."""

from pathlib import Path

from _version import __version__
from defaults import CAT_VERSION, MCR_VERSION
from jinja2 import Environment, FileSystemLoader, select_autoescape


def generate_method_section(
output_dir: Path,
version: str = __version__,
cat_version: str = CAT_VERSION,
mcr_version: str = MCR_VERSION,
batch: str = None,
) -> None:
"""Add a method section to the output dataset."""
env = Environment(
loader=FileSystemLoader(Path(__file__).parent),
autoescape=select_autoescape(),
lstrip_blocks=True,
trim_blocks=True,
)

template = env.get_template("data/methods/template.jinja")

output_file = output_dir / "logs" / "CITATION.md"
output_file.parent.mkdir(parents=True, exist_ok=True)

data = {
"version": version,
"cat_version": cat_version,
"mcr_version": mcr_version,
"batch": batch,
}

with open(output_file, "w") as f:
print(template.render(data=data), file=f)
1 change: 1 addition & 0 deletions code/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rich_argparse
pybids
nibabel
jinja2
3 changes: 3 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ tests/data/MoAEpilot:
build:
docker build . --tag cat12

version:
docker run --rm -it cat12 . . participant --version

view:
docker run --rm -it cat12 . . participant view tfce --verbose 3

Expand Down

0 comments on commit 4d8148b

Please sign in to comment.