How fish-quant/comseg works
Project Type and Purpose
• ComSeg is an open‐source Python library (spatial point‐cloud segmentation framework) for single‐cell spatial RNA profiling.
• It processes CSV spot coordinates + expression data → builds a graph → applies clustering algorithms → outputs an AnnData object (scanpy/Anndata format).
High-Level Architecture (Components)
a. User Interface / Entry Points
• CLI or Python API (import comseg)
• Scripts or Jupyter notebooks in docs/userguide for Quick_start
b. Data Ingestion & Preprocessing
• comseg.dataset: reads CSV, builds raw data structures
• comseg.utils.preprocessing: filters data, normalizes counts
c. Graph Construction & Utilities
• comseg.utils.utils_graph: builds spatial graph (nodes=spots or cells)
• comseg.utils.custom_louvain: community detection helpers
d. Core Algorithms
• comseg.clustering: main segmentation routines (Louvain, custom methods)
• comseg.model: higher-level orchestration (ties preprocessing + clustering + postprocessing)
• comseg.dictionary: building/comparing “cell signature” dictionaries
e. Output & Visualization
• Returns an AnnData object with .X (expression), .obs (coordinates), .obsm (.graph)
• comseg.utils.plot: plotting functions for QC and final segmentation maps
f. Packaging & Documentation
• pyproject.toml + requirements.txt: build and runtime dependencies
• docs/: Sphinx sources + build pipeline (readthedocs.yml)
• dist/ + old_dist/: published wheels and tarballs
Relationships & Data Flow
• User → CLI/API → dataset.read_csv
→ preprocessing.clean()
→ graph_utils.build_graph()
→ clustering.run()
→ model.aggregate_results()
→ dictionary.generate_signatures()
→ output: AnnData
• Packaging & docs sit alongside code; CI/CD (e.g., ReadTheDocs) consumes source to publish docs.
Architectural Patterns & Design Principles
• Modular design: each submodule encapsulates a single concern (SRP)
• Data‐flow pipeline: clear sequence of transformations