Skip to content

Commit

Permalink
Merge pull request #77 from Remi-Gau/method
Browse files Browse the repository at this point in the history
[ENH] add methods section
  • Loading branch information
Remi-Gau authored Jan 8, 2024
2 parents b1e68b7 + 7d8113c commit 22a4ae0
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
32 changes: 32 additions & 0 deletions giga_connectome/data/methods/template.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
These results were generated with
giga_connectome (version {{ data.version }}, https://giga-connectome.readthedocs.io/en/latest/)
using Nilearn (version {{ data.nilearn_version }}, RRID:SCR_001362)
and TemplateFlow (version {{ data.templateflow_version }}).

The following steps were followed.

1. Created subject specific grey matter mask in MNI space ({{ data.mni_space }}).

1. Sampled the {{ data.atlas }} atlas to the space of subject specific grey matter mask in MNI space.

1. Calculated the conjunction of the customised grey matter mask and resampled atlas to find valid parcels.

1. Used the new input specific grey matter mask and atlas to extract time series and connectomes for each subject.
The time series data were denoised as follow:

- Time series extractions through label or map maskers are performed on the denoised nifti file.
- Denoising steps were performed on the voxel level:
- spatial smoothing (FWHM: {{ data.smoothing_fwhm }} mm)
- detrending, only if high pass filter was not applied through confounds
- regressing out confounds (using a {{ data.strategy }} strategy)
- standardized (using {{ data.standardize }})
- Extracted time series from atlas
- Computed correlation matrix (Pearson's correlation with LedoitWolf covariance estimator)

{% if data.average_correlation %}
1. Calculate intranetwork correlation of each parcel. The values replace the diagonal of the connectomes.
{% endif %}

{% if data.analysis_level %}
1. Create a group average connectome.
{% endif %}
52 changes: 52 additions & 0 deletions giga_connectome/methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Module responsible for generating method section."""

from pathlib import Path

from jinja2 import Environment, FileSystemLoader, select_autoescape

from nilearn import __version__ as nilearn_version
from templateflow import __version__ as templateflow_version

from giga_connectome import __version__


def generate_method_section(
output_dir: Path,
atlas: str,
smoothing_fwhm: float,
strategy: str,
standardize: str,
mni_space: str,
average_correlation: bool,
analysis_level: bool,
) -> None:

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__,
"nilearn_version": nilearn_version,
"templateflow_version": templateflow_version,
"atlas": atlas,
"smoothing_fwhm": smoothing_fwhm,
"strategy": strategy,
"standardize": "percent signal change"
if standardize == "psc"
else standardize,
"mni_space": mni_space,
"average_correlation": average_correlation,
"analysis_level": analysis_level,
}

with open(output_file, "w") as f:
print(template.render(data=data), file=f)
14 changes: 14 additions & 0 deletions giga_connectome/tests/test_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from giga_connectome import methods


def test_generate_method_section(tmp_path):
methods.generate_method_section(
output_dir=tmp_path,
atlas="DiFuMo",
smoothing_fwhm=5,
standardize="psc",
strategy="simple",
mni_space="MNI152NLin6Asym",
average_correlation=True,
analysis_level=True,
)
13 changes: 12 additions & 1 deletion giga_connectome/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)

from giga_connectome.denoise import is_ica_aroma
from giga_connectome import utils
from giga_connectome import utils, methods
from giga_connectome.logger import gc_logger


Expand Down Expand Up @@ -63,6 +63,17 @@ def workflow(args):

gc_log.info(f"Indexing BIDS directory:\n\t{bids_dir}")

methods.generate_method_section(
output_dir=output_dir,
atlas=atlas["name"],
smoothing_fwhm=smoothing_fwhm,
standardize=args.standardize,
strategy=args.denoise_strategy,
mni_space=template,
average_correlation=calculate_average_correlation,
analysis_level=analysis_level == "group",
)

# create subject ts and connectomes
# refactor the two cases into one

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies = [
"templateflow < 23.0.0",
"tqdm",
"setuptools",
"jinja2 >= 2.0",
"rich",
]
dynamic = ["version"]
Expand Down

0 comments on commit 22a4ae0

Please sign in to comment.