# zhwm/rsparsepro_ld architecture

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

- Interactive diagram: https://gitdiagram.com/zhwm/rsparsepro_ld
- Repository: https://github.com/zhwm/rsparsepro_ld

## Overview

RSparsePro is a command-line tool for fine-mapping GWAS z-scores against an LD reference while accounting for LD mismatch. The workflow reads the two inputs, adaptively fits a variational model, and writes PIP, estimated z-scores, and credible-set assignments. The excerpt shows the inference and file-handling flow; README documents the output fields and fallback behavior. The source excerpt has gaps, so unsampled implementation details are not expanded.

Main entry points: [`src/rsparsepro_ld.py`](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py) (CLI and input loading), [`dat/EUR_1_25268937_26268937.rsparsepro.txt`](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.rsparsepro.txt) (Fine-mapping results), [`dat/EUR_1_25268937_26268937.txt`](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.txt) (GWAS z-scores), [`dat/EUR_1_25268937_26268937.ld`](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.ld) (LD matrix)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Analysis inputs"]
  node_z_input["GWAS z-scores"]
  node_ld_input["LD matrix"]
end

subgraph group_workflow["Fine-mapping workflow"]
  node_cli["CLI and input loading<br/>[rsparsepro_ld.py]"]
  node_adaptive["Adaptive training<br/>[rsparsepro_ld.py]"]
end

subgraph group_inference["Variational inference"]
  node_model["RSparsePro model<br/>[rsparsepro_ld.py]"]
  node_latent_update["Latent z update<br/>[rsparsepro_ld.py]"]
  node_beta_update["Effect updates<br/>[rsparsepro_ld.py]"]
end

subgraph group_results["Analysis results"]
  node_effects["Credible-set extraction<br/>[rsparsepro_ld.py]"]
  node_diagnostics["LD diagnostics<br/>[rsparsepro_ld.py]"]
  node_result["Fine-mapping results"]
end

node_user(("Analyst"))

node_user -->|"runs"| node_cli
node_cli -->|"reads z-scores"| node_z_input
node_cli -->|"reads LD"| node_ld_input
node_cli -->|"invokes"| node_adaptive
node_adaptive -->|"trains"| node_model
node_model -->|"updates latent z"| node_latent_update
node_model -->|"updates effects"| node_beta_update
node_adaptive -->|"extracts sets"| node_effects
node_adaptive -->|"checks LD"| node_diagnostics
node_cli -->|"writes results"| node_result
node_effects -->|"provides set assignments"| node_result
node_model -->|"provides PIP and z estimates"| node_result

click node_z_input "https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.txt"
click node_ld_input "https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.ld"
click node_cli "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_adaptive "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_model "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_latent_update "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_beta_update "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_effects "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_diagnostics "https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py"
click node_result "https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.rsparsepro.txt"

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_z_input,node_ld_input toneBlue
class node_cli,node_adaptive toneAmber
class node_model,node_latent_update,node_beta_update toneMint
class node_effects,node_diagnostics,node_result toneRose
class node_user toneIndigo
```

## Components

### Analysis inputs

- [GWAS z-scores](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.txt): `dat/EUR_1_25268937_26268937.txt`
- [LD matrix](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.ld): `dat/EUR_1_25268937_26268937.ld`

### Fine-mapping workflow

- [CLI and input loading](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`
- [Adaptive training](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`

### Variational inference

- [RSparsePro model](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`
- [Latent z update](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`
- [Effect updates](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`

### Analysis results

- [Credible-set extraction](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`
- [LD diagnostics](https://github.com/zhwm/rsparsepro_ld/blob/main/src/rsparsepro_ld.py): `src/rsparsepro_ld.py`
- [Fine-mapping results](https://github.com/zhwm/rsparsepro_ld/blob/main/dat/EUR_1_25268937_26268937.rsparsepro.txt): `dat/EUR_1_25268937_26268937.rsparsepro.txt`

### Other components

- **Analyst**

## Connections

- Analyst → CLI and input loading: runs (evidence: `README.md`)
- CLI and input loading → GWAS z-scores: reads z-scores (evidence: `src/rsparsepro_ld.py`)
- CLI and input loading → LD matrix: reads LD (evidence: `src/rsparsepro_ld.py`)
- CLI and input loading → Adaptive training: invokes (evidence: `src/rsparsepro_ld.py`)
- Adaptive training → RSparsePro model: trains (evidence: `src/rsparsepro_ld.py`)
- RSparsePro model → Latent z update: updates latent z (evidence: `src/rsparsepro_ld.py`)
- RSparsePro model → Effect updates: updates effects (evidence: `src/rsparsepro_ld.py`)
- Adaptive training → Credible-set extraction: extracts sets (evidence: `src/rsparsepro_ld.py`)
- Adaptive training → LD diagnostics: checks LD (evidence: `src/rsparsepro_ld.py`)
- CLI and input loading → Fine-mapping results: writes results (evidence: `src/rsparsepro_ld.py`)
- Credible-set extraction → Fine-mapping results: provides set assignments (evidence: `README.md`)
- RSparsePro model → Fine-mapping results: provides PIP and z estimates (evidence: `README.md`)
