Skip to content

Commit

Permalink
[ENH] add HTML reports for each atlas / masked image (#115)
Browse files Browse the repository at this point in the history
* add reports

* add matploblib

* spelling
  • Loading branch information
Remi-Gau authored Mar 25, 2024
1 parent 6f1184f commit fd1ae30
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions giga_connectome/connectome.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def generate_timeseries_connectomes(
group_mask: str | Path,
correlation_measure: ConnectivityMeasure,
calculate_average_correlation: bool,
) -> tuple[np.ndarray[Any, Any], np.ndarray[Any, Any]]:
) -> tuple[np.ndarray[Any, Any], np.ndarray[Any, Any], NiftiMasker]:
"""Generate timeseries-based connectomes from functional data.
Parameters
Expand Down Expand Up @@ -159,4 +159,4 @@ def generate_timeseries_connectomes(
# convert to float 32 instead of 64
time_series_atlas = time_series_atlas.astype(np.float32)
correlation_matrix = correlation_matrix.astype(np.float32)
return correlation_matrix, time_series_atlas
return correlation_matrix, time_series_atlas, masker
38 changes: 27 additions & 11 deletions giga_connectome/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,14 @@ def run_postprocessing_dataset(
continue

# extract timeseries and connectomes
(
correlation_matrix,
time_series_atlas,
) = generate_timeseries_connectomes(
masker,
denoised_img,
group_mask,
correlation_measure,
calculate_average_correlation,
(correlation_matrix, time_series_atlas, masker) = (
generate_timeseries_connectomes(
masker,
denoised_img,
group_mask,
correlation_measure,
calculate_average_correlation,
)
)

# dump correlation_matrix to tsv
Expand Down Expand Up @@ -198,6 +197,17 @@ def run_postprocessing_dataset(
df = pd.DataFrame(time_series_atlas)
df.to_csv(timeseries_filename, sep="\t", index=False)

report = masker.generate_report()
report_filename = connectome_path / utils.output_filename(
source_file=Path(img.filename).stem,
atlas=atlas["name"],
suffix="report",
extension="html",
strategy=strategy["name"],
desc=desc,
)
report.save_as_html(report_filename)

progress.update(task, advance=1)

gc_log.info(f"Saved to:\n{connectome_path}")
Expand All @@ -208,8 +218,14 @@ def _get_masker(atlas_path: Path) -> NiftiLabelsMasker | NiftiMapsMasker:
atlas_type = atlas_path.name.split("_")[-1].split(".nii")[0]
if atlas_type == "dseg":
atlas_masker = NiftiLabelsMasker(
labels_img=atlas_path, standardize=False
labels_img=atlas_path,
standardize=False,
cmap="gray",
)
elif atlas_type == "probseg":
atlas_masker = NiftiMapsMasker(maps_img=atlas_path, standardize=False)
atlas_masker = NiftiMapsMasker(
maps_img=atlas_path,
standardize=False,
cmap="gray",
)
return atlas_masker
2 changes: 1 addition & 1 deletion giga_connectome/tests/test_connectome.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_calculate_intranetwork_correlation():
correlation_measure = ConnectivityMeasure(
kind="correlation", vectorize=False, discard_diagonal=False
)
conn, tseries = generate_timeseries_connectomes(
conn, _, _ = generate_timeseries_connectomes(
masker=NiftiLabelsMasker(labels_img=atlas),
denoised_img=denoised_img,
group_mask=mask,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
]
dependencies = [
"h5py",
"nilearn >=0.10.2",
"nilearn[plotting] >=0.10.2",
"pybids >=0.15.0, <0.16.0",
"templateflow < 23.0.0",
"setuptools",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface-meta==1.3.0
joblib==1.3.2
lxml==4.9.3
nibabel==5.2.0
nilearn==0.10.2
nilearn[plotting]==0.10.2
num2words==0.5.13
numpy==1.26.2
packaging==23.2
Expand Down

0 comments on commit fd1ae30

Please sign in to comment.