glycoforge 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 BojarLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+ recursive-include glycoforge *.py
5
+ recursive-include sample_config *.yaml
6
+ recursive-exclude tests *
7
+ recursive-exclude results *
8
+ recursive-exclude .venv *
9
+ recursive-exclude use_cases *
10
+ global-exclude __pycache__
11
+ global-exclude *.py[cod]
12
+ global-exclude *.so
13
+ global-exclude .DS_Store
@@ -0,0 +1,155 @@
1
+ Metadata-Version: 2.4
2
+ Name: glycoforge
3
+ Version: 0.1.0
4
+ Summary: A simulation tool for generating glycomic relative abundance datasets with customizable biological group differences and controllable batch-effect injection
5
+ Author-email: "Zoe (Siyu) Hu" <zoe.sy.hu@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/BojarLab/GlycoForge
8
+ Project-URL: Repository, https://github.com/BojarLab/GlycoForge
9
+ Project-URL: Documentation, https://github.com/BojarLab/GlycoForge#readme
10
+ Project-URL: Bug Tracker, https://github.com/BojarLab/GlycoForge/issues
11
+ Keywords: glycomics,simulation,batch-effect,compositional-data,bioinformatics,MNAR,relative-abundance data
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: <3.13,>=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.21.0
23
+ Requires-Dist: pandas>=1.3.0
24
+ Requires-Dist: scipy>=1.7.0
25
+ Requires-Dist: scikit-learn>=1.0.0
26
+ Requires-Dist: matplotlib>=3.5.0
27
+ Requires-Dist: seaborn>=0.11.0
28
+ Requires-Dist: glycowork>=1.6.4
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: jupyter>=1.0.0; extra == "dev"
32
+ Requires-Dist: notebook>=6.4.0; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ <img src="glycoforge_logo.jpg" alt="GlycoForge logo" width="200">
36
+
37
+ GlycoForge is a simulation tool for **generating glycomic relative-abundance datasets** with customizable biological group differences and controllable batch-effect injection.
38
+
39
+ ## Key Features
40
+
41
+ - **Two simulation modes**: Fully synthetic or hybrid (extract factor from input reference data + simulate batch effect)
42
+ - **Controllable effects injection**: Systematic grid search over biological effect or batch effect strength parameters
43
+ - **MNAR missing data simulation**: Mimics left-censored patterns biased toward low-abundance glycans
44
+
45
+ ## Quick Start
46
+
47
+ ### Installation
48
+
49
+ * Python >= 3.10 required.
50
+ * Core dependency: `glycowork>=1.6.4`
51
+
52
+ ```bash
53
+ git clone https://github.com/BojarLab/GlycoForge.git
54
+ cd GlycoForge
55
+ python3.10 -m venv .venv
56
+ source .venv/bin/activate
57
+ pip install -e .
58
+ ```
59
+
60
+ ### Usage
61
+
62
+ See [run_simulation.ipynb](run_simulation.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/BojarLab/GlycoForge/blob/main/run_simulation.ipynb)for interactive examples, or [use_cases/batch_correction/](use_cases/batch_correction) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/BojarLab/GlycoForge/blob/main/use_cases/batch_correction/run_correction.ipynb) for batch correction workflows.
63
+
64
+
65
+
66
+
67
+ ## How the simulator works
68
+
69
+ We keep everything in the CLR (centered log-ratio) space:
70
+
71
+ - First, draw a healthy baseline composition from a Dirichlet prior: `p_H ~ Dirichlet(alpha_H)`.
72
+ - Flip to CLR: `z_H = clr(p_H)`.
73
+ - For selected glycans, push the signal using real or synthetic effect sizes: `z_U = z_H + m * lambda * d_robust`, where `m` is the differential mask, `lambda` is `bio_strength`, and `d_robust` is the effect vector after `robust_effect_size_processing`.
74
+ - **Simplified mode**: draw synthetic effect sizes (log-fold changes) and pass them through the same robust processing pipeline.
75
+ - **Hybrid mode**: start from the Cohen’s *d* values returned by `glycowork.get_differential_expression`; `define_differential_mask` lets you restrict the injection to significant hits or top-*N* glycans before scaling.
76
+ - Invert back to proportions: `p_U = invclr(z_U)` and scale by `k_dir` to get `alpha_U`, note that the healthy and unhealthy Dirichlet strengths use different `k_dir` values, and a separate `variance_ratio` controls their relative magnitude.
77
+ - Batch effects ride on top as direction vectors `u_b`, so a clean CLR sample `Y_clean` becomes `Y_with_batch = Y_clean + kappa_mu * u_b + epsilon`, with `var_b` controlling spread.
78
+
79
+
80
+ ## Simulation Modes
81
+
82
+ The pipeline entry point is `glycoforge.simulate()` with two modes controlled by `data_source`. Configuration files are in `sample_config/`.
83
+
84
+ <details>
85
+ <summary><b>Simplified mode (<code>data_source="simulated"</code>)</b> – Fully synthetic simulation (click to show detail introduction)</summary>
86
+
87
+ <br>
88
+
89
+ No real data dependency. Ideal for controlled experiments with known ground truth.
90
+
91
+ **Pipeline steps:**
92
+
93
+ 1. Initializes uniform healthy baseline: `alpha_H = ones(n_glycans) * 10`
94
+ 2. For each random seed, generates `alpha_U` by randomly scaling `alpha_H`:
95
+ - `up_frac` (default 30%) upregulated with scale factors from `up_scale_range=(1.1, 3.0)`
96
+ - `down_frac` (default 30%) downregulated with scale factors from `down_scale_range=(0.3, 0.9)`
97
+ - Remaining glycans (~40%) stay unchanged
98
+ 3. Samples clean cohorts from `Dirichlet(alpha_H)` and `Dirichlet(alpha_U)` with `n_H` healthy and `n_U` unhealthy samples
99
+ 4. Defines batch effect direction vectors `u_dict` once per simulation run (fixed seed ensures reproducible batch geometry across parameter sweep)
100
+ 5. Applies batch effects controlled by `kappa_mu` (shift strength) and `var_b` (variance scaling)
101
+ 6. Optionally applies MNAR (Missing Not At Random) missingness:
102
+ - `missing_fraction`: proportion of missing values (0.0-1.0)
103
+ - `mnar_bias`: intensity-dependent bias (default 2.0, range 0.5-5.0)
104
+ - Left-censored pattern: low-abundance glycans more likely to be missing
105
+ 7. Grid search over `kappa_mu` and `var_b` produces multiple datasets under identical batch effect structure
106
+
107
+ **Key parameters:** `n_glycans`, `n_H`, `n_U`, `kappa_mu`, `var_b`, `missing_fraction`, `mnar_bias`
108
+
109
+ </details>
110
+
111
+ <details>
112
+ <summary><b>Hybrid mode (<code>data_source="real"</code>)</b> – Extract biological effect from input reference data + simulate batch effect (click to show detail introduction) </summary>
113
+
114
+ <br>
115
+
116
+ Starts from real glycomics data to preserve biological signal structure. Accepts CSV file or `glycowork.glycan_data` datasets.
117
+
118
+ **Pipeline steps:**
119
+
120
+ 1. Loads CSV and extracts healthy/unhealthy sample columns by prefix (configurable via `column_prefix`)
121
+ 2. Runs CLR-based differential expression via `glycowork.get_differential_expression` to compute Cohen's d effect sizes
122
+ 3. Reindexes effect sizes to match input glycan order (fills missing glycans with 0.0)
123
+ 4. Applies `differential_mask` to select which glycans receive biological signal injection:
124
+ - `"All"`: inject into all glycans
125
+ - `"significant"`: only glycans marked significant by glycowork
126
+ - `"Top-N"`: top N glycans by absolute effect size (e.g., `"Top-10"`)
127
+ 5. Processes effect sizes through `robust_effect_size_processing`:
128
+ - Centers effect sizes to remove global shift
129
+ - Applies Winsorization to clip extreme outliers (auto-selects percentile 85-99, or uses `winsorize_percentile`)
130
+ - Normalizes by baseline (`baseline_method`: median, MAD, or p75)
131
+ - Returns normalized `d_robust` scaled by `bio_strength`
132
+ 6. Injects effects in CLR space: `z_U = z_H + mask * bio_strength * d_robust`
133
+ 7. Converts back to proportions: `p_U = invclr(z_U)`
134
+ 8. Scales by Dirichlet concentration: `alpha_H = k_dir * p_H` and `alpha_U = (k_dir / variance_ratio) * p_U`
135
+ 9. Samples clean cohorts from `Dirichlet(alpha_H)` and `Dirichlet(alpha_U)` with `n_H` healthy and `n_U` unhealthy samples
136
+ 10. Defines batch effect direction vectors `u_dict` once per run (fixed seed ensures fair comparison across parameter combinations)
137
+ 11. Applies batch effects: `y_batch = y_clean + kappa_mu * sigma * u_b + epsilon`, where `epsilon ~ N(0, sqrt(var_b) * sigma)`
138
+ 12. Optionally applies MNAR missingness (same as Simplified mode: left-censored pattern biased toward low-abundance glycans)
139
+ 13. Grid search over `bio_strength`, `k_dir`, `variance_ratio`, `kappa_mu`, `var_b` to systematically test biological signal and batch effect interactions
140
+
141
+ **Key parameters:** `data_file`, `column_prefix`, `bio_strength`, `k_dir`, `variance_ratio`, `differential_mask`, `winsorize_percentile`, `baseline_method`, `kappa_mu`, `var_b`, `missing_fraction`, `mnar_bias`
142
+
143
+ </details>
144
+
145
+ ## Use Cases
146
+
147
+ The [use_cases/batch_correction/](use_cases/batch_correction) directory demonstrates:
148
+ - Call `glycoforge` simulation + ComBat correction workflow
149
+ - Batch correction effectiveness metrics visualization
150
+
151
+
152
+ ## Limitations and Future Work
153
+
154
+ 1. **Two biological groups only**: Current implementation targets healthy/unhealthy setup. Supporting multi-stage disease (>=3 groups) requires refactoring Dirichlet parameter generation and evaluation metrics.
155
+ 2. **Packaging**: Source-first distribution for now. PyPI release planned once API stabilizes.
@@ -0,0 +1,121 @@
1
+ <img src="glycoforge_logo.jpg" alt="GlycoForge logo" width="200">
2
+
3
+ GlycoForge is a simulation tool for **generating glycomic relative-abundance datasets** with customizable biological group differences and controllable batch-effect injection.
4
+
5
+ ## Key Features
6
+
7
+ - **Two simulation modes**: Fully synthetic or hybrid (extract factor from input reference data + simulate batch effect)
8
+ - **Controllable effects injection**: Systematic grid search over biological effect or batch effect strength parameters
9
+ - **MNAR missing data simulation**: Mimics left-censored patterns biased toward low-abundance glycans
10
+
11
+ ## Quick Start
12
+
13
+ ### Installation
14
+
15
+ * Python >= 3.10 required.
16
+ * Core dependency: `glycowork>=1.6.4`
17
+
18
+ ```bash
19
+ git clone https://github.com/BojarLab/GlycoForge.git
20
+ cd GlycoForge
21
+ python3.10 -m venv .venv
22
+ source .venv/bin/activate
23
+ pip install -e .
24
+ ```
25
+
26
+ ### Usage
27
+
28
+ See [run_simulation.ipynb](run_simulation.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/BojarLab/GlycoForge/blob/main/run_simulation.ipynb)for interactive examples, or [use_cases/batch_correction/](use_cases/batch_correction) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/BojarLab/GlycoForge/blob/main/use_cases/batch_correction/run_correction.ipynb) for batch correction workflows.
29
+
30
+
31
+
32
+
33
+ ## How the simulator works
34
+
35
+ We keep everything in the CLR (centered log-ratio) space:
36
+
37
+ - First, draw a healthy baseline composition from a Dirichlet prior: `p_H ~ Dirichlet(alpha_H)`.
38
+ - Flip to CLR: `z_H = clr(p_H)`.
39
+ - For selected glycans, push the signal using real or synthetic effect sizes: `z_U = z_H + m * lambda * d_robust`, where `m` is the differential mask, `lambda` is `bio_strength`, and `d_robust` is the effect vector after `robust_effect_size_processing`.
40
+ - **Simplified mode**: draw synthetic effect sizes (log-fold changes) and pass them through the same robust processing pipeline.
41
+ - **Hybrid mode**: start from the Cohen’s *d* values returned by `glycowork.get_differential_expression`; `define_differential_mask` lets you restrict the injection to significant hits or top-*N* glycans before scaling.
42
+ - Invert back to proportions: `p_U = invclr(z_U)` and scale by `k_dir` to get `alpha_U`, note that the healthy and unhealthy Dirichlet strengths use different `k_dir` values, and a separate `variance_ratio` controls their relative magnitude.
43
+ - Batch effects ride on top as direction vectors `u_b`, so a clean CLR sample `Y_clean` becomes `Y_with_batch = Y_clean + kappa_mu * u_b + epsilon`, with `var_b` controlling spread.
44
+
45
+
46
+ ## Simulation Modes
47
+
48
+ The pipeline entry point is `glycoforge.simulate()` with two modes controlled by `data_source`. Configuration files are in `sample_config/`.
49
+
50
+ <details>
51
+ <summary><b>Simplified mode (<code>data_source="simulated"</code>)</b> – Fully synthetic simulation (click to show detail introduction)</summary>
52
+
53
+ <br>
54
+
55
+ No real data dependency. Ideal for controlled experiments with known ground truth.
56
+
57
+ **Pipeline steps:**
58
+
59
+ 1. Initializes uniform healthy baseline: `alpha_H = ones(n_glycans) * 10`
60
+ 2. For each random seed, generates `alpha_U` by randomly scaling `alpha_H`:
61
+ - `up_frac` (default 30%) upregulated with scale factors from `up_scale_range=(1.1, 3.0)`
62
+ - `down_frac` (default 30%) downregulated with scale factors from `down_scale_range=(0.3, 0.9)`
63
+ - Remaining glycans (~40%) stay unchanged
64
+ 3. Samples clean cohorts from `Dirichlet(alpha_H)` and `Dirichlet(alpha_U)` with `n_H` healthy and `n_U` unhealthy samples
65
+ 4. Defines batch effect direction vectors `u_dict` once per simulation run (fixed seed ensures reproducible batch geometry across parameter sweep)
66
+ 5. Applies batch effects controlled by `kappa_mu` (shift strength) and `var_b` (variance scaling)
67
+ 6. Optionally applies MNAR (Missing Not At Random) missingness:
68
+ - `missing_fraction`: proportion of missing values (0.0-1.0)
69
+ - `mnar_bias`: intensity-dependent bias (default 2.0, range 0.5-5.0)
70
+ - Left-censored pattern: low-abundance glycans more likely to be missing
71
+ 7. Grid search over `kappa_mu` and `var_b` produces multiple datasets under identical batch effect structure
72
+
73
+ **Key parameters:** `n_glycans`, `n_H`, `n_U`, `kappa_mu`, `var_b`, `missing_fraction`, `mnar_bias`
74
+
75
+ </details>
76
+
77
+ <details>
78
+ <summary><b>Hybrid mode (<code>data_source="real"</code>)</b> – Extract biological effect from input reference data + simulate batch effect (click to show detail introduction) </summary>
79
+
80
+ <br>
81
+
82
+ Starts from real glycomics data to preserve biological signal structure. Accepts CSV file or `glycowork.glycan_data` datasets.
83
+
84
+ **Pipeline steps:**
85
+
86
+ 1. Loads CSV and extracts healthy/unhealthy sample columns by prefix (configurable via `column_prefix`)
87
+ 2. Runs CLR-based differential expression via `glycowork.get_differential_expression` to compute Cohen's d effect sizes
88
+ 3. Reindexes effect sizes to match input glycan order (fills missing glycans with 0.0)
89
+ 4. Applies `differential_mask` to select which glycans receive biological signal injection:
90
+ - `"All"`: inject into all glycans
91
+ - `"significant"`: only glycans marked significant by glycowork
92
+ - `"Top-N"`: top N glycans by absolute effect size (e.g., `"Top-10"`)
93
+ 5. Processes effect sizes through `robust_effect_size_processing`:
94
+ - Centers effect sizes to remove global shift
95
+ - Applies Winsorization to clip extreme outliers (auto-selects percentile 85-99, or uses `winsorize_percentile`)
96
+ - Normalizes by baseline (`baseline_method`: median, MAD, or p75)
97
+ - Returns normalized `d_robust` scaled by `bio_strength`
98
+ 6. Injects effects in CLR space: `z_U = z_H + mask * bio_strength * d_robust`
99
+ 7. Converts back to proportions: `p_U = invclr(z_U)`
100
+ 8. Scales by Dirichlet concentration: `alpha_H = k_dir * p_H` and `alpha_U = (k_dir / variance_ratio) * p_U`
101
+ 9. Samples clean cohorts from `Dirichlet(alpha_H)` and `Dirichlet(alpha_U)` with `n_H` healthy and `n_U` unhealthy samples
102
+ 10. Defines batch effect direction vectors `u_dict` once per run (fixed seed ensures fair comparison across parameter combinations)
103
+ 11. Applies batch effects: `y_batch = y_clean + kappa_mu * sigma * u_b + epsilon`, where `epsilon ~ N(0, sqrt(var_b) * sigma)`
104
+ 12. Optionally applies MNAR missingness (same as Simplified mode: left-censored pattern biased toward low-abundance glycans)
105
+ 13. Grid search over `bio_strength`, `k_dir`, `variance_ratio`, `kappa_mu`, `var_b` to systematically test biological signal and batch effect interactions
106
+
107
+ **Key parameters:** `data_file`, `column_prefix`, `bio_strength`, `k_dir`, `variance_ratio`, `differential_mask`, `winsorize_percentile`, `baseline_method`, `kappa_mu`, `var_b`, `missing_fraction`, `mnar_bias`
108
+
109
+ </details>
110
+
111
+ ## Use Cases
112
+
113
+ The [use_cases/batch_correction/](use_cases/batch_correction) directory demonstrates:
114
+ - Call `glycoforge` simulation + ComBat correction workflow
115
+ - Batch correction effectiveness metrics visualization
116
+
117
+
118
+ ## Limitations and Future Work
119
+
120
+ 1. **Two biological groups only**: Current implementation targets healthy/unhealthy setup. Supporting multi-stage disease (>=3 groups) requires refactoring Dirichlet parameter generation and evaluation metrics.
121
+ 2. **Packaging**: Source-first distribution for now. PyPI release planned once API stabilizes.
@@ -0,0 +1,18 @@
1
+ """GlycoForge - Simulation and batch correction pipeline for glycomics data"""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ # Core simulation interface
6
+ from .pipeline import simulate
7
+
8
+ # Utility functions
9
+ from .utils import clr, invclr, parse_simulation_config, plot_pca
10
+
11
+ # Expose core API
12
+ __all__ = [
13
+ 'simulate',
14
+ 'clr',
15
+ 'invclr',
16
+ 'parse_simulation_config',
17
+ 'plot_pca'
18
+ ]