Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] add HTML reports for each atlas / masked image #115

Merged
merged 3 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading