# nanostring-biostats/cosmx-analysis-scratch-space architecture

> Architecture diagram of the GitHub repository nanostring-biostats/cosmx-analysis-scratch-space, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nanostring-biostats/cosmx-analysis-scratch-space
- Repository: https://github.com/nanostring-biostats/cosmx-analysis-scratch-space

## Overview

This repository is an exploratory CosMx spatial-analysis resource, with HierAnnot as its principal package and a separate GeoMx scMask script. HierAnnot’s user workflow accepts expression data and marker hierarchies/programs, prepares and scores normal and malignant tracks, routes cluster decisions, integrates annotations, then supports inspection, plotting, and result export. The graph preserves documented built-in hierarchy/program capabilities and the separate scMask utility. Unsampled modules are represented by exact tree paths; their internal connections are omitted unless the README or indexed excerpts establish them.

Main entry points: [`_code/HierAnnot/hierannot/pipeline.py`](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/pipeline.py) (Analysis pipeline), [`_code/HierAnnot/hierannot/builtin/registry.py`](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/registry.py) (Hierarchy registry), [`_code/HierAnnot/hierannot/datamodels.py`](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/datamodels.py) (Annotation models), [`_code/HierAnnot/hierannot/malignant_scoring.py`](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/malignant_scoring.py) (Malignant scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs and models"]
  node_expr["Expression data"]
  node_models["Annotation models<br/>[datamodels.py]"]
end

subgraph group_hierarchy["Hierarchy resources"]
  node_builtin_hier["Built-in hierarchies<br/>[factories.py]"]
  node_builtin_registry["Hierarchy registry<br/>[registry.py]"]
  node_builtin_match["Hierarchy matching<br/>[matching.py]"]
  node_malig_programs["Malignant programs"]
end

subgraph group_analysis["Scoring and decisions"]
  node_preprocess["Input preprocessing<br/>[preprocessing.py]"]
  node_hierarchy_ops["Hierarchy routing<br/>[hierarchy.py]"]
  node_normal_score["Marker scoring<br/>[scoring.py]"]
  node_aggregate["Score aggregation<br/>[aggregate.py]"]
  node_pipeline["Analysis pipeline<br/>[pipeline.py]"]
  node_malig_score["Malignant scoring"]
  node_controls["Control selection<br/>[controls.py]"]
  node_workflow["Decision workflows<br/>[workflows.py]"]
  node_integration["Track integration"]
end

subgraph group_outputs["Results and reporting"]
  node_reporting["Malignant reporting"]
  node_inspection["Hierarchy inspection<br/>[inspect.py]"]
  node_plotting["Result plotting<br/>[plotting.py]"]
  node_result_io["Result persistence<br/>[result_io.py]"]
  node_io["Input/output helpers<br/>[io.py]"]
end

subgraph group_scripts["Spatial utilities"]
  node_scmask["GeoMx scMask generation"]
end

node_user(("Analyst"))

node_user -->|"provides data"| node_expr
node_user -.->|"selects models"| node_models
node_expr -.->|"supplies expression"| node_pipeline
node_models -.->|"configures analysis"| node_pipeline
node_pipeline -->|"calls preparation"| node_preprocess
node_pipeline -->|"builds controls"| node_controls
node_pipeline -->|"computes scores"| node_normal_score
node_pipeline -->|"routes annotations"| node_hierarchy_ops
node_pipeline -->|"scores programs"| node_malig_score
node_pipeline -->|"integrates tracks"| node_integration
node_pipeline -->|"runs workflows"| node_workflow
node_builtin_registry -->|"constructs hierarchies"| node_builtin_hier
node_builtin_registry -->|"matches queries"| node_builtin_match
node_builtin_registry -->|"creates models"| node_models
node_malig_score -->|"applies report rules"| node_reporting
node_integration -->|"resolves report preset"| node_reporting
node_workflow -->|"decides clusters"| node_hierarchy_ops
node_pipeline -.->|"exports results"| node_result_io
node_user -.->|"inspects results"| node_inspection
node_user -.->|"plots results"| node_plotting
node_result_io -->|"uses file helpers"| node_io
node_user -.->|"runs query script"| node_scmask

click node_models "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/datamodels.py"
click node_preprocess "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/preprocessing.py"
click node_builtin_hier "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/factories.py"
click node_builtin_registry "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/registry.py"
click node_builtin_match "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/matching.py"
click node_malig_programs "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/malignant_programs.py"
click node_hierarchy_ops "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/hierarchy.py"
click node_normal_score "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/scoring.py"
click node_aggregate "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/aggregate.py"
click node_pipeline "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/pipeline.py"
click node_malig_score "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/malignant_scoring.py"
click node_controls "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/controls.py"
click node_workflow "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/workflows.py"
click node_integration "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/integration/integrate_tracks.py"
click node_reporting "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/malignant_reporting.py"
click node_inspection "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/inspect.py"
click node_plotting "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/plotting.py"
click node_result_io "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/result_io.py"
click node_io "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/io.py"
click node_scmask "https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/GeoMx-scMask-generation/Generate_scMask_given_query.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_expr,node_models toneBlue
class node_builtin_hier,node_builtin_registry,node_builtin_match,node_malig_programs toneAmber
class node_preprocess,node_hierarchy_ops,node_normal_score,node_aggregate,node_pipeline,node_malig_score,node_controls,node_workflow,node_integration toneMint
class node_reporting,node_inspection,node_plotting,node_result_io,node_io toneRose
class node_scmask,node_user toneIndigo
```

## Components

### Inputs and models

- **Expression data**
- [Annotation models](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/datamodels.py): `_code/HierAnnot/hierannot/datamodels.py`

### Hierarchy resources

- [Built-in hierarchies](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/factories.py): `_code/HierAnnot/hierannot/builtin/factories.py`
- [Hierarchy registry](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/registry.py): `_code/HierAnnot/hierannot/builtin/registry.py`
- [Hierarchy matching](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/matching.py): `_code/HierAnnot/hierannot/builtin/matching.py`
- [Malignant programs](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/builtin/malignant_programs.py): `_code/HierAnnot/hierannot/builtin/malignant_programs.py`

### Scoring and decisions

- [Input preprocessing](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/preprocessing.py): `_code/HierAnnot/hierannot/preprocessing.py`
- [Hierarchy routing](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/hierarchy.py): `_code/HierAnnot/hierannot/hierarchy.py`
- [Marker scoring](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/scoring.py): `_code/HierAnnot/hierannot/scoring.py`
- [Score aggregation](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/aggregate.py): `_code/HierAnnot/hierannot/aggregate.py`
- [Analysis pipeline](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/pipeline.py): `_code/HierAnnot/hierannot/pipeline.py`
- [Malignant scoring](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/malignant_scoring.py): `_code/HierAnnot/hierannot/malignant_scoring.py`
- [Control selection](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/controls.py): `_code/HierAnnot/hierannot/controls.py`
- [Decision workflows](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/workflows.py): `_code/HierAnnot/hierannot/workflows.py`
- [Track integration](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/integration/integrate_tracks.py): `_code/HierAnnot/hierannot/integration/integrate_tracks.py`

### Results and reporting

- [Malignant reporting](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/malignant_reporting.py): `_code/HierAnnot/hierannot/malignant_reporting.py`
- [Hierarchy inspection](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/inspect.py): `_code/HierAnnot/hierannot/inspect.py`
- [Result plotting](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/plotting.py): `_code/HierAnnot/hierannot/plotting.py`
- [Result persistence](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/result_io.py): `_code/HierAnnot/hierannot/result_io.py`
- [Input/output helpers](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/HierAnnot/hierannot/io.py): `_code/HierAnnot/hierannot/io.py`

### Spatial utilities

- [GeoMx scMask generation](https://github.com/nanostring-biostats/cosmx-analysis-scratch-space/blob/Main/_code/GeoMx-scMask-generation/Generate_scMask_given_query.py): `_code/GeoMx-scMask-generation/Generate_scMask_given_query.py`

### Other components

- **Analyst**

## Connections

- Analyst → Expression data: provides data
- Analyst → Annotation models: selects models
- Expression data → Analysis pipeline: supplies expression
- Annotation models → Analysis pipeline: configures analysis (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Input preprocessing: calls preparation (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Control selection: builds controls (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Marker scoring: computes scores (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Hierarchy routing: routes annotations (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Malignant scoring: scores programs (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Track integration: integrates tracks (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Analysis pipeline → Decision workflows: runs workflows (evidence: `_code/HierAnnot/hierannot/pipeline.py`)
- Hierarchy registry → Built-in hierarchies: constructs hierarchies (evidence: `_code/HierAnnot/hierannot/builtin/registry.py`)
- Hierarchy registry → Hierarchy matching: matches queries (evidence: `_code/HierAnnot/hierannot/builtin/registry.py`)
- Hierarchy registry → Annotation models: creates models (evidence: `_code/HierAnnot/hierannot/builtin/registry.py`)
- Malignant scoring → Malignant reporting: applies report rules (evidence: `_code/HierAnnot/hierannot/malignant_scoring.py`)
- Track integration → Malignant reporting: resolves report preset (evidence: `_code/HierAnnot/hierannot/integration/integrate_tracks.py`)
- Decision workflows → Hierarchy routing: decides clusters (evidence: `_code/HierAnnot/hierannot/workflows.py`)
- Analysis pipeline → Result persistence: exports results
- Analyst → Hierarchy inspection: inspects results
- Analyst → Result plotting: plots results
- Result persistence → Input/output helpers: uses file helpers (evidence: `_code/HierAnnot/hierannot/result_io.py`)
- Analyst → GeoMx scMask generation: runs query script
