From 02f2109425455719993e2be0c30eaa7614fdc4b0 Mon Sep 17 00:00:00 2001 From: Blampey Quentin Date: Mon, 8 Apr 2024 15:51:41 +0200 Subject: [PATCH] v1.0.10 --- CHANGELOG.md | 3 ++- pyproject.toml | 2 +- sopa/io/report/generate.py | 35 ++++++++++++++++++----------------- sopa/utils/data.py | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7101ffe3..74e2bb7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [1.0.10] - tbd +## [1.0.10] - 2024-04-08 ### Added - CosMX reader with image stitching (experimental) @@ -8,6 +8,7 @@ - Minimum number of transcripts per patch set to 4000 (#41) - Config files refactoring (configs added or renamed) - Readers refactoring +- Section with error during report are not displayed (instead of throwing an error) ## [1.0.9] - 2024-04-03 diff --git a/pyproject.toml b/pyproject.toml index 51b77ca6..657797fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sopa" -version = "1.0.9" +version = "1.0.10" description = "Spatial-omics pipeline and analysis" documentation = "https://gustaveroussy.github.io/sopa" homepage = "https://gustaveroussy.github.io/sopa" diff --git a/sopa/io/report/generate.py b/sopa/io/report/generate.py index 71f7bc86..5d78c431 100644 --- a/sopa/io/report/generate.py +++ b/sopa/io/report/generate.py @@ -54,6 +54,14 @@ def _kdeplot_vmax_quantile(values: np.ndarray, quantile: float = 0.95): class SectionBuilder: + SECTION_NAMES = [ + "general_section", + "cell_section", + "channel_section", + "transcripts_section", + "representation_section", + ] + def __init__(self, sdata: SpatialData): self.sdata = sdata self.adata = self.sdata.tables.get(SopaKeys.TABLE) @@ -64,8 +72,6 @@ def _table_has(self, key, default=False): return self.adata.uns[SopaKeys.UNS_KEY].get(key, default) def general_section(self): - log.info("Writing general section") - return Section( "General", [ @@ -82,8 +88,6 @@ def general_section(self): ) def cell_section(self): - log.info("Writing cell section") - shapes_key, _ = get_boundaries(self.sdata, return_key=True) coord_system = get_intrinsic_cs(self.sdata, shapes_key) @@ -111,8 +115,6 @@ def cell_section(self): ) def channel_section(self): - log.info("Writing channel section") - image = get_spatial_image(self.sdata) subsections = [ @@ -154,8 +156,6 @@ def transcripts_section(self): if not self._table_has(SopaKeys.UNS_HAS_TRANSCRIPTS): return None - log.info("Writing transcript section") - mean_transcript_count = self.adata.X.mean(0).A1 low_average = mean_transcript_count < LOW_AVERAGE_COUNT @@ -183,8 +183,6 @@ def transcripts_section(self): return Section("Transcripts", [SubSection("Quality controls", QC_subsubsections)]) def representation_section(self, max_obs: int = 400_000): - log.info("Writing representation section") - if self._table_has(SopaKeys.UNS_HAS_TRANSCRIPTS): sc.pp.normalize_total(self.adata) sc.pp.log1p(self.adata) @@ -209,11 +207,14 @@ def representation_section(self, max_obs: int = 400_000): ) def compute_sections(self) -> list[Section]: - sections = [ - self.general_section(), - self.cell_section(), - self.channel_section(), - self.transcripts_section(), - self.representation_section(), - ] + sections = [] + + for name in self.SECTION_NAMES: + try: + log.info(f"Writing {name}") + section = getattr(self, name)() + sections.append(section) + except Exception as e: + log.warn(f"Section {name} failed with error {e}") + return [section for section in sections if section is not None] diff --git a/sopa/utils/data.py b/sopa/utils/data.py index 13435950..efbdf467 100644 --- a/sopa/utils/data.py +++ b/sopa/utils/data.py @@ -21,7 +21,7 @@ def uniform( *_, length: int = 2_048, cell_density: float = 1e-4, - n_points_per_cell: int = 50, + n_points_per_cell: int = 100, c_coords: list[str] = ["DAPI", "CK", "CD3", "CD20"], genes: int | list[str] = ["EPCAM", "CD3E", "CD20", "CXCL4", "CXCL10"], sigma_factor: float = 0.05,