methylseg 0.1.8__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,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Clement Lab
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: methylseg
3
+ Version: 0.1.8
4
+ Summary: Methylation segmentation utilities used in the TCGA methylation analysis repo.
5
+ Project-URL: Documentation, https://clementlab.github.io/MethylSeg/
6
+ Project-URL: Repository, https://github.com/clementlab/MethylSeg
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: cthmm>=0.0.3
11
+ Requires-Dist: hmmlearn>=0.3.3
12
+ Requires-Dist: joblib>=1.5
13
+ Requires-Dist: matplotlib>=3.8
14
+ Requires-Dist: numba>=0.60
15
+ Requires-Dist: numpy>=1.26
16
+ Requires-Dist: pandas>=2.2
17
+ Requires-Dist: panel>=1.4
18
+ Requires-Dist: plotly>=5.24
19
+ Requires-Dist: pybedtools>=0.12.0
20
+ Requires-Dist: pyarrow>=17.0
21
+ Requires-Dist: PyYAML>=6.0
22
+ Requires-Dist: scikit-learn>=1.5
23
+ Requires-Dist: seaborn>=0.13
24
+ Requires-Dist: tqdm>=4.66
25
+ Requires-Dist: umap-learn>=0.5
26
+ Requires-Dist: gdown>=6.0
27
+ Requires-Dist: nbformat>=4.2.0
28
+ Provides-Extra: docs
29
+ Requires-Dist: ipykernel; extra == "docs"
30
+ Requires-Dist: myst-parser>=4.0; extra == "docs"
31
+ Requires-Dist: nbsphinx>=0.9.6; extra == "docs"
32
+ Requires-Dist: Sphinx>=7.4.7; extra == "docs"
33
+ Requires-Dist: sphinx-autobuild>=2024.4.16; extra == "docs"
34
+ Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == "docs"
35
+ Provides-Extra: test
36
+ Requires-Dist: pytest>=8.0; extra == "test"
37
+ Dynamic: license-file
38
+
39
+ # MethylSeg
40
+
41
+ ![logo](https://raw.githubusercontent.com/clementlab/MethylSeg/main/logo.png)
42
+
43
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22904886.svg)](https://doi.org/10.5281/zenodo.22904886)
44
+
45
+ MethylSeg is a Python toolkit for identifying methylation domains from
46
+ whole-genome bisulfite sequencing (WGBS) and microarray methylation data. It
47
+ supports data preparation, methylation-state model training, genome
48
+ segmentation, region cleaning, and visualization.
49
+
50
+ This introduces the standard workflow. For the complete API reference
51
+ and example notebooks, see the [MethylSeg documentation](https://clementlab.github.io/MethylSeg/).
52
+
53
+ > [!IMPORTANT]
54
+ > Microarray support has currently been tested with Illumina HumanMethylation450 BeadChip (HM450K) data. Other methylation microarrays, such as Illumina HumanMethylation27 and MethylationEPIC, can be used, but array-specific defaults are not yet available and these platforms have not been formally tested.
55
+
56
+ ## Hardware requirements
57
+
58
+ Memory usage depends on the input data type and dataset size. The following
59
+ values were observed during testing:
60
+
61
+ | Data type | Typical memory usage | Recommended system memory |
62
+ | --- | ---: | ---: |
63
+ | WGBS | ~12 GB average; up to ~15 GB peak | ≥16 GB |
64
+ | HM450K | <1 GB | ≥8 GB |
65
+
66
+ > [!NOTE]
67
+ > Numba has known compatibility issues on ARM-based systems. See the
68
+ > [Troubleshooting guide](https://github.com/clementlab/MethylSeg/blob/main/TROUBLESHOOTING.md)
69
+ > for installation guidance.
70
+
71
+ ## Installation
72
+
73
+ Install from PyPI
74
+
75
+ ```bash
76
+ python -m pip install methylseg
77
+ ```
78
+
79
+ or install the current version from GitHub:
80
+
81
+ ```bash
82
+ python -m pip install "git+https://github.com/clementlab/MethylSeg.git"
83
+ ```
84
+
85
+ ## Reference files
86
+
87
+ ### Sample data
88
+
89
+ Three reference samples are available for use in tutorials and testing.
90
+
91
+ ```bash
92
+ methylseg download_data_files
93
+ ```
94
+
95
+ The two colon cancer samples were originally generated by Hansen et al. (2011) and were obtained from the data distributed with MethyLasso (Balaramane et al., 2024).
96
+
97
+ The liver cancer sample, `TCGA-BD-A3EP-01A`, was obtained from the [TCGA-LIHC project through the NCI Genomic Data Commons](https://portal.gdc.cancer.gov/cases/de302b98-250d-42fe-9945-11e1b2bbd3c6).
98
+
99
+ | Sample name | WGBS filename | HM450K filename |
100
+ | --- | --- | --- |
101
+ | `WGBS_colon-primary-tumor_1` | `WGBS_colon-primary-tumor_1_wgbs.tsv` | `WGBS_colon-primary-tumor_1_450k.beta` |
102
+ | `WGBS_colon-primary-tumor_2` | `WGBS_colon-primary-tumor_2_wgbs.tsv` | `WGBS_colon-primary-tumor_2_450k.beta` |
103
+ | `TCGA-BD-A3EP-01A` | N/A | `TCGA-BD-A3EP-01A_450k.tsv` |
104
+
105
+ #### References
106
+
107
+ 1. Hansen, K. D., et al. Increased methylation variation in epigenetic domains across cancer types. *Nature Genetics* **43**, 768–775 (2011).
108
+ 2. Balaramane, D., Spill, Y. G., Weber, M. & Bardet, A. F. MethyLasso: a segmentation approach to analyze DNA methylation patterns and identify differentially methylated regions from whole-genome datasets. *Nucleic Acids Research* **52**, e98 (2024).
109
+
110
+ ### Pretrained models
111
+
112
+ Two pretrained models are provided for tutorials, testing, and exploratory
113
+ analysis:
114
+
115
+ | Model filename | Training data |
116
+ | --- | --- |
117
+ | `wgbs_colon_model` | `WGBS_colon-primary-tumor_1_wgbs.tsv` |
118
+ | `tcga_hm450k_model` | `TCGA-BD-A3EP-01A_450k.tsv` |
119
+
120
+ Load a pretrained model with `get_pretrained_model`:
121
+
122
+ ```python
123
+ # WGBS model
124
+ wgbs_saved = MethylSegPathway.get_pretrained_model(
125
+ out_dir=OUTPUT_DIR,
126
+ resolution="wgbs",
127
+ )
128
+
129
+ # HM450K model
130
+ hm450k_saved = MethylSegPathway.get_pretrained_model(
131
+ out_dir=OUTPUT_DIR,
132
+ resolution="450k",
133
+ )
134
+ ```
135
+
136
+ ## Quickstart
137
+
138
+ The default workflow trains a model on your input, segments the sample,
139
+ cleans the calls, and draws a cleaned methylation state overlay.
140
+
141
+ Use `resolution="wgbs"` for WGBS count tables or `resolution="450k"` for HM450K
142
+ beta-value tables. Other microarray platforms may require manually configured
143
+ parameters until array-specific defaults are added.
144
+
145
+ ```python
146
+ from pathlib import Path
147
+
148
+ from methylseg import MethylSegPathway, MethylationStates
149
+ from methylseg.helper_classes import DATA_DIR
150
+
151
+ reference_dir = DATA_DIR / "reference_files"
152
+
153
+ # WGBS: replace these with your own sample name and count table.
154
+ # sample_name = "WGBS_colon-primary-tumor_1"
155
+ # sample_file = reference_dir / "WGBS_colon-primary-tumor_1_wgbs.tsv.gz"
156
+ # resolution = "wgbs"
157
+
158
+ # TCGA/HM450K alternative:
159
+ sample_name = "TCGA-BD-A3EP-01A"
160
+ sample_file = reference_dir / "TCGA-BD-A3EP-01A_450k.tsv.gz"
161
+ resolution = "450k"
162
+
163
+ sample_info, removed_df = MethylSegPathway.prepare_sample_info(
164
+ sample_name=sample_name,
165
+ sample_file=sample_file,
166
+ resolution=resolution,
167
+ remove_low_coverage_like_cpgs=True,
168
+ )
169
+
170
+ pathway = MethylSegPathway(
171
+ train_sample_info=sample_info,
172
+ out_dir=Path("out/quickstart") / sample_name,
173
+ )
174
+
175
+ pathway.run_pathway()
176
+
177
+ fig = pathway.plot_labels(
178
+ sample_info=sample_info,
179
+ sample_info_removed=removed_df,
180
+ chrom="chr1",
181
+ region_start=2_200_000,
182
+ region_end=3_700_000
183
+ )
184
+ ```
185
+
186
+ ![quickstart output](https://raw.githubusercontent.com/clementlab/MethylSeg/main/quickstart.png)
187
+
188
+ `run_pathway(sample_info=sample_info, chroms=["chr1"])` performs fitting,
189
+ segmentation, cleaning, and summary-file writing in one call.
190
+
191
+ ## Input formats
192
+
193
+ MethylSeg accepts tab-delimited `.tsv` and `.tsv.gz` files containing DNA methylation measurements. Genomic coordinates must use the 0-based, half-open coordinate system, and chromosome names must be consistent throughout each file.
194
+
195
+ Two BED-like input formats are supported.
196
+
197
+ ### Beta-value format
198
+
199
+ This format can be used for either WGBS or microarray data. It contains four required columns:
200
+
201
+ 1. chromosome;
202
+ 2. CpG start position;
203
+ 3. CpG end position; and
204
+ 4. methylation beta value.
205
+
206
+ For microarray data, an optional fifth column containing the probe identifier may be included. Probe identifiers are retained as metadata.
207
+
208
+ | CpG_chrm | CpG_beg | CpG_end | beta | probe |
209
+ | -------- | ------: | ------: | ---: | ---------- |
210
+ | chr1 | 15864 | 15866 | 0.0 | cg13869341 |
211
+ | chr1 | 29406 | 29408 | 0.0 | cg12045430 |
212
+ | chr1 | 29424 | 29426 | 0.0 | cg20826792 |
213
+
214
+
215
+ ### WGBS count format
216
+
217
+ This format contains five required columns:
218
+
219
+ 1. chromosome;
220
+ 2. CpG start position;
221
+ 3. CpG end position;
222
+ 4. methylated read count; and
223
+ 5. total read coverage.
224
+
225
+ MethylSeg calculates the beta value internally as:
226
+ $
227
+ \mathrm{beta} = \frac{\mathrm{methylated\ reads}}{\mathrm{total\ coverage}}.
228
+ $
229
+
230
+ | CpG_chrm | CpG_beg | CpG_end | meth | coverage |
231
+ | -------- | ------: | ------: | ---: | -------: |
232
+ | chr1 | 10468 | 10470 | 14 | 15 |
233
+ | chr1 | 10470 | 10472 | 10 | 10 |
234
+ | chr1 | 10483 | 10485 | 23 | 28 |
235
+
236
+
237
+ ## Outputs
238
+
239
+ The final output of MethylSeg consists primarily of BED files containing the
240
+ identified methylation domains. Separate files are generated for each
241
+ methylation state: `HIGH`, `INTERMEDIATE`, `LOW`, and `PMD`.
242
+
243
+ For each chromosome and state, MethylSeg writes:
244
+
245
+ | Output | Filename pattern | Description |
246
+ | --- | --- | --- |
247
+ | Raw regions | `segments_{chrom}_{sample_id}_{resolution}_{state}.bed` | Regions produced directly by genome segmentation |
248
+ | Cleaned regions | `clean_regions/segments_cleaned_{chrom}_{sample_id}_{resolution}_{state}.bed` | Regions retained after merging and filtering |
249
+ | Cleaned metadata | `clean_regions/metadata_cleaned_{chrom}_{sample_id}_{resolution}_{state}.tsv` | Additional information about the cleaned regions |
250
+
251
+ After all requested chromosomes have been processed, MethylSeg also creates
252
+ genome-wide files for each state under `summary_files/`:
253
+
254
+ | Output | Filename pattern |
255
+ | --- | --- |
256
+ | Genome-wide raw regions | `segments_raw_{state}.bed` |
257
+ | Genome-wide cleaned regions | `segments_cleaned_{state}.bed` |
258
+ | Genome-wide cleaned metadata | `metadata_cleaned_{state}.tsv` |
259
+
260
+ A simplified output directory has the following structure:
261
+
262
+ ```text
263
+ methylseg_output/
264
+ ├── segments_chr1_sample.wgbs_PMD.bed
265
+ ├── segments_chr1_sample.wgbs_LOW.bed
266
+ ├── clean_regions/
267
+ │ ├── segments_cleaned_chr1_sample.wgbs_PMD.bed
268
+ │ ├── segments_cleaned_chr1_sample.wgbs_LOW.bed
269
+ │ ├── metadata_cleaned_chr1_sample.wgbs_PMD.tsv
270
+ │ └── metadata_cleaned_chr1_sample.wgbs_LOW.tsv
271
+ └── summary_files/
272
+ ├── segments_raw_PMD.bed
273
+ ├── segments_raw_LOW.bed
274
+ ├── segments_cleaned_PMD.bed
275
+ ├── segments_cleaned_LOW.bed
276
+ ├── metadata_cleaned_PMD.tsv
277
+ └── metadata_cleaned_LOW.tsv
278
+ ```
279
+
280
+ Each BED file contains 0-based, half-open genomic coordinates and the assigned
281
+ methylation state. For example, segments_cleaned_PMD.bed may contain:
282
+
283
+ | Chromosome | Start | End | State |
284
+ | ---------- | --------: | --------: | ----- |
285
+ | `chr1` | 1,261,344 | 1,323,691 | `PMD` |
286
+ | `chr1` | 2,789,167 | 2,999,312 | `PMD` |
287
+ | `chr1` | 3,885,138 | 3,916,529 | `PMD` |
288
+ | `chr1` | 6,167,866 | 6,186,177 | `PMD` |
289
+
290
+ The BED files themselves are tab-delimited and do not contain a header.
291
+
292
+ ## Citation
293
+
294
+ If you use MethylSeg, please cite the software using the
295
+ [CITATION.cff](https://github.com/clementlab/MethylSeg/blob/main/CITATION.cff)
296
+ metadata. On GitHub, select **Cite this repository** to copy the citation in APA
297
+ or BibTeX format.
298
+
299
+ A manuscript describing MethylSeg is in preparation. Its citation will be added
300
+ when available.
301
+
302
+ ## Planned support
303
+
304
+ See [ROADMAP.md](https://github.com/clementlab/MethylSeg/blob/main/ROADMAP.md)
305
+
306
+ ## Reporting issues
307
+
308
+ To report a bug, request a feature, or ask a question about MethylSeg, open an
309
+ issue on the [GitHub issue tracker](https://github.com/clementlab/MethylSeg/issues).
310
+
311
+ When reporting a bug, please include:
312
+
313
+ - Your MethylSeg version
314
+ - Your Python version and operating system
315
+ - The complete error message or traceback
316
+ - A minimal example that reproduces the problem, when possible
317
+
318
+ ## License
319
+
320
+ MethylSeg is distributed under the [BSD 3-Clause License](LICENSE.md).
@@ -0,0 +1,282 @@
1
+ # MethylSeg
2
+
3
+ ![logo](https://raw.githubusercontent.com/clementlab/MethylSeg/main/logo.png)
4
+
5
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22904886.svg)](https://doi.org/10.5281/zenodo.22904886)
6
+
7
+ MethylSeg is a Python toolkit for identifying methylation domains from
8
+ whole-genome bisulfite sequencing (WGBS) and microarray methylation data. It
9
+ supports data preparation, methylation-state model training, genome
10
+ segmentation, region cleaning, and visualization.
11
+
12
+ This introduces the standard workflow. For the complete API reference
13
+ and example notebooks, see the [MethylSeg documentation](https://clementlab.github.io/MethylSeg/).
14
+
15
+ > [!IMPORTANT]
16
+ > Microarray support has currently been tested with Illumina HumanMethylation450 BeadChip (HM450K) data. Other methylation microarrays, such as Illumina HumanMethylation27 and MethylationEPIC, can be used, but array-specific defaults are not yet available and these platforms have not been formally tested.
17
+
18
+ ## Hardware requirements
19
+
20
+ Memory usage depends on the input data type and dataset size. The following
21
+ values were observed during testing:
22
+
23
+ | Data type | Typical memory usage | Recommended system memory |
24
+ | --- | ---: | ---: |
25
+ | WGBS | ~12 GB average; up to ~15 GB peak | ≥16 GB |
26
+ | HM450K | <1 GB | ≥8 GB |
27
+
28
+ > [!NOTE]
29
+ > Numba has known compatibility issues on ARM-based systems. See the
30
+ > [Troubleshooting guide](https://github.com/clementlab/MethylSeg/blob/main/TROUBLESHOOTING.md)
31
+ > for installation guidance.
32
+
33
+ ## Installation
34
+
35
+ Install from PyPI
36
+
37
+ ```bash
38
+ python -m pip install methylseg
39
+ ```
40
+
41
+ or install the current version from GitHub:
42
+
43
+ ```bash
44
+ python -m pip install "git+https://github.com/clementlab/MethylSeg.git"
45
+ ```
46
+
47
+ ## Reference files
48
+
49
+ ### Sample data
50
+
51
+ Three reference samples are available for use in tutorials and testing.
52
+
53
+ ```bash
54
+ methylseg download_data_files
55
+ ```
56
+
57
+ The two colon cancer samples were originally generated by Hansen et al. (2011) and were obtained from the data distributed with MethyLasso (Balaramane et al., 2024).
58
+
59
+ The liver cancer sample, `TCGA-BD-A3EP-01A`, was obtained from the [TCGA-LIHC project through the NCI Genomic Data Commons](https://portal.gdc.cancer.gov/cases/de302b98-250d-42fe-9945-11e1b2bbd3c6).
60
+
61
+ | Sample name | WGBS filename | HM450K filename |
62
+ | --- | --- | --- |
63
+ | `WGBS_colon-primary-tumor_1` | `WGBS_colon-primary-tumor_1_wgbs.tsv` | `WGBS_colon-primary-tumor_1_450k.beta` |
64
+ | `WGBS_colon-primary-tumor_2` | `WGBS_colon-primary-tumor_2_wgbs.tsv` | `WGBS_colon-primary-tumor_2_450k.beta` |
65
+ | `TCGA-BD-A3EP-01A` | N/A | `TCGA-BD-A3EP-01A_450k.tsv` |
66
+
67
+ #### References
68
+
69
+ 1. Hansen, K. D., et al. Increased methylation variation in epigenetic domains across cancer types. *Nature Genetics* **43**, 768–775 (2011).
70
+ 2. Balaramane, D., Spill, Y. G., Weber, M. & Bardet, A. F. MethyLasso: a segmentation approach to analyze DNA methylation patterns and identify differentially methylated regions from whole-genome datasets. *Nucleic Acids Research* **52**, e98 (2024).
71
+
72
+ ### Pretrained models
73
+
74
+ Two pretrained models are provided for tutorials, testing, and exploratory
75
+ analysis:
76
+
77
+ | Model filename | Training data |
78
+ | --- | --- |
79
+ | `wgbs_colon_model` | `WGBS_colon-primary-tumor_1_wgbs.tsv` |
80
+ | `tcga_hm450k_model` | `TCGA-BD-A3EP-01A_450k.tsv` |
81
+
82
+ Load a pretrained model with `get_pretrained_model`:
83
+
84
+ ```python
85
+ # WGBS model
86
+ wgbs_saved = MethylSegPathway.get_pretrained_model(
87
+ out_dir=OUTPUT_DIR,
88
+ resolution="wgbs",
89
+ )
90
+
91
+ # HM450K model
92
+ hm450k_saved = MethylSegPathway.get_pretrained_model(
93
+ out_dir=OUTPUT_DIR,
94
+ resolution="450k",
95
+ )
96
+ ```
97
+
98
+ ## Quickstart
99
+
100
+ The default workflow trains a model on your input, segments the sample,
101
+ cleans the calls, and draws a cleaned methylation state overlay.
102
+
103
+ Use `resolution="wgbs"` for WGBS count tables or `resolution="450k"` for HM450K
104
+ beta-value tables. Other microarray platforms may require manually configured
105
+ parameters until array-specific defaults are added.
106
+
107
+ ```python
108
+ from pathlib import Path
109
+
110
+ from methylseg import MethylSegPathway, MethylationStates
111
+ from methylseg.helper_classes import DATA_DIR
112
+
113
+ reference_dir = DATA_DIR / "reference_files"
114
+
115
+ # WGBS: replace these with your own sample name and count table.
116
+ # sample_name = "WGBS_colon-primary-tumor_1"
117
+ # sample_file = reference_dir / "WGBS_colon-primary-tumor_1_wgbs.tsv.gz"
118
+ # resolution = "wgbs"
119
+
120
+ # TCGA/HM450K alternative:
121
+ sample_name = "TCGA-BD-A3EP-01A"
122
+ sample_file = reference_dir / "TCGA-BD-A3EP-01A_450k.tsv.gz"
123
+ resolution = "450k"
124
+
125
+ sample_info, removed_df = MethylSegPathway.prepare_sample_info(
126
+ sample_name=sample_name,
127
+ sample_file=sample_file,
128
+ resolution=resolution,
129
+ remove_low_coverage_like_cpgs=True,
130
+ )
131
+
132
+ pathway = MethylSegPathway(
133
+ train_sample_info=sample_info,
134
+ out_dir=Path("out/quickstart") / sample_name,
135
+ )
136
+
137
+ pathway.run_pathway()
138
+
139
+ fig = pathway.plot_labels(
140
+ sample_info=sample_info,
141
+ sample_info_removed=removed_df,
142
+ chrom="chr1",
143
+ region_start=2_200_000,
144
+ region_end=3_700_000
145
+ )
146
+ ```
147
+
148
+ ![quickstart output](https://raw.githubusercontent.com/clementlab/MethylSeg/main/quickstart.png)
149
+
150
+ `run_pathway(sample_info=sample_info, chroms=["chr1"])` performs fitting,
151
+ segmentation, cleaning, and summary-file writing in one call.
152
+
153
+ ## Input formats
154
+
155
+ MethylSeg accepts tab-delimited `.tsv` and `.tsv.gz` files containing DNA methylation measurements. Genomic coordinates must use the 0-based, half-open coordinate system, and chromosome names must be consistent throughout each file.
156
+
157
+ Two BED-like input formats are supported.
158
+
159
+ ### Beta-value format
160
+
161
+ This format can be used for either WGBS or microarray data. It contains four required columns:
162
+
163
+ 1. chromosome;
164
+ 2. CpG start position;
165
+ 3. CpG end position; and
166
+ 4. methylation beta value.
167
+
168
+ For microarray data, an optional fifth column containing the probe identifier may be included. Probe identifiers are retained as metadata.
169
+
170
+ | CpG_chrm | CpG_beg | CpG_end | beta | probe |
171
+ | -------- | ------: | ------: | ---: | ---------- |
172
+ | chr1 | 15864 | 15866 | 0.0 | cg13869341 |
173
+ | chr1 | 29406 | 29408 | 0.0 | cg12045430 |
174
+ | chr1 | 29424 | 29426 | 0.0 | cg20826792 |
175
+
176
+
177
+ ### WGBS count format
178
+
179
+ This format contains five required columns:
180
+
181
+ 1. chromosome;
182
+ 2. CpG start position;
183
+ 3. CpG end position;
184
+ 4. methylated read count; and
185
+ 5. total read coverage.
186
+
187
+ MethylSeg calculates the beta value internally as:
188
+ $
189
+ \mathrm{beta} = \frac{\mathrm{methylated\ reads}}{\mathrm{total\ coverage}}.
190
+ $
191
+
192
+ | CpG_chrm | CpG_beg | CpG_end | meth | coverage |
193
+ | -------- | ------: | ------: | ---: | -------: |
194
+ | chr1 | 10468 | 10470 | 14 | 15 |
195
+ | chr1 | 10470 | 10472 | 10 | 10 |
196
+ | chr1 | 10483 | 10485 | 23 | 28 |
197
+
198
+
199
+ ## Outputs
200
+
201
+ The final output of MethylSeg consists primarily of BED files containing the
202
+ identified methylation domains. Separate files are generated for each
203
+ methylation state: `HIGH`, `INTERMEDIATE`, `LOW`, and `PMD`.
204
+
205
+ For each chromosome and state, MethylSeg writes:
206
+
207
+ | Output | Filename pattern | Description |
208
+ | --- | --- | --- |
209
+ | Raw regions | `segments_{chrom}_{sample_id}_{resolution}_{state}.bed` | Regions produced directly by genome segmentation |
210
+ | Cleaned regions | `clean_regions/segments_cleaned_{chrom}_{sample_id}_{resolution}_{state}.bed` | Regions retained after merging and filtering |
211
+ | Cleaned metadata | `clean_regions/metadata_cleaned_{chrom}_{sample_id}_{resolution}_{state}.tsv` | Additional information about the cleaned regions |
212
+
213
+ After all requested chromosomes have been processed, MethylSeg also creates
214
+ genome-wide files for each state under `summary_files/`:
215
+
216
+ | Output | Filename pattern |
217
+ | --- | --- |
218
+ | Genome-wide raw regions | `segments_raw_{state}.bed` |
219
+ | Genome-wide cleaned regions | `segments_cleaned_{state}.bed` |
220
+ | Genome-wide cleaned metadata | `metadata_cleaned_{state}.tsv` |
221
+
222
+ A simplified output directory has the following structure:
223
+
224
+ ```text
225
+ methylseg_output/
226
+ ├── segments_chr1_sample.wgbs_PMD.bed
227
+ ├── segments_chr1_sample.wgbs_LOW.bed
228
+ ├── clean_regions/
229
+ │ ├── segments_cleaned_chr1_sample.wgbs_PMD.bed
230
+ │ ├── segments_cleaned_chr1_sample.wgbs_LOW.bed
231
+ │ ├── metadata_cleaned_chr1_sample.wgbs_PMD.tsv
232
+ │ └── metadata_cleaned_chr1_sample.wgbs_LOW.tsv
233
+ └── summary_files/
234
+ ├── segments_raw_PMD.bed
235
+ ├── segments_raw_LOW.bed
236
+ ├── segments_cleaned_PMD.bed
237
+ ├── segments_cleaned_LOW.bed
238
+ ├── metadata_cleaned_PMD.tsv
239
+ └── metadata_cleaned_LOW.tsv
240
+ ```
241
+
242
+ Each BED file contains 0-based, half-open genomic coordinates and the assigned
243
+ methylation state. For example, segments_cleaned_PMD.bed may contain:
244
+
245
+ | Chromosome | Start | End | State |
246
+ | ---------- | --------: | --------: | ----- |
247
+ | `chr1` | 1,261,344 | 1,323,691 | `PMD` |
248
+ | `chr1` | 2,789,167 | 2,999,312 | `PMD` |
249
+ | `chr1` | 3,885,138 | 3,916,529 | `PMD` |
250
+ | `chr1` | 6,167,866 | 6,186,177 | `PMD` |
251
+
252
+ The BED files themselves are tab-delimited and do not contain a header.
253
+
254
+ ## Citation
255
+
256
+ If you use MethylSeg, please cite the software using the
257
+ [CITATION.cff](https://github.com/clementlab/MethylSeg/blob/main/CITATION.cff)
258
+ metadata. On GitHub, select **Cite this repository** to copy the citation in APA
259
+ or BibTeX format.
260
+
261
+ A manuscript describing MethylSeg is in preparation. Its citation will be added
262
+ when available.
263
+
264
+ ## Planned support
265
+
266
+ See [ROADMAP.md](https://github.com/clementlab/MethylSeg/blob/main/ROADMAP.md)
267
+
268
+ ## Reporting issues
269
+
270
+ To report a bug, request a feature, or ask a question about MethylSeg, open an
271
+ issue on the [GitHub issue tracker](https://github.com/clementlab/MethylSeg/issues).
272
+
273
+ When reporting a bug, please include:
274
+
275
+ - Your MethylSeg version
276
+ - Your Python version and operating system
277
+ - The complete error message or traceback
278
+ - A minimal example that reproduces the problem, when possible
279
+
280
+ ## License
281
+
282
+ MethylSeg is distributed under the [BSD 3-Clause License](LICENSE.md).
@@ -0,0 +1,38 @@
1
+ """Public package exports for the reusable methylseg workflow."""
2
+
3
+ from .helper_classes import (
4
+ MethylStateAssignmentMethod,
5
+ MethylationStates,
6
+ MethylDataPrep,
7
+ SampleInfo,
8
+ HMMType,
9
+ )
10
+ from .methylseg_hmm import (
11
+ CTMethylSegHMM,
12
+ MethylSegHMM,
13
+ StickyCategoricalMethylSegHMM,
14
+ )
15
+ from .methyl_state_assigner import MethylStateAssigner
16
+ from .methyl_state_analyzer import MethylStateAnalyzer
17
+ from .methyl_segmentor import MethylSegmentor
18
+ from .methylseg_pathway import MethylSegPathway
19
+ from .methylseg_config import MethylSegConfig
20
+ from .utils import get_biological_state_colors, get_cluster_colors
21
+
22
+ __all__ = [
23
+ "CTMethylSegHMM",
24
+ "MethylDataPrep",
25
+ "MethylSegConfig",
26
+ "MethylSegHMM",
27
+ "MethylSegPathway",
28
+ "MethylSegmentor",
29
+ "MethylStateAnalyzer",
30
+ "MethylStateAssigner",
31
+ "MethylStateAssignmentMethod",
32
+ "MethylationStates",
33
+ "HMMType",
34
+ "SampleInfo",
35
+ "StickyCategoricalMethylSegHMM",
36
+ "get_biological_state_colors",
37
+ "get_cluster_colors",
38
+ ]
@@ -0,0 +1,32 @@
1
+ from .data_manager import download_data_files
2
+ import argparse
3
+
4
+ #TODO - add subcommands for pathway running, segmentation and plotting
5
+ def main():
6
+ """
7
+ Run the ``methylseg`` command-line interface.
8
+
9
+ Returns
10
+ -------
11
+ None
12
+ Parses CLI arguments, executes the requested subcommand, and prints
13
+ help text when no subcommand is provided.
14
+ """
15
+ parser = argparse.ArgumentParser(prog="methylseg")
16
+
17
+ subparsers = parser.add_subparsers(dest="command")
18
+
19
+ # subcommand: download_data_files
20
+ dl_parser = subparsers.add_parser("download_data_files")
21
+ dl_parser.add_argument(
22
+ "--cleanup_existing",
23
+ action="store_true",
24
+ help="Delete existing files before downloading",
25
+ )
26
+
27
+ args = parser.parse_args()
28
+
29
+ if args.command == "download_data_files":
30
+ download_data_files(cleanup_existing=args.cleanup_existing)
31
+ else:
32
+ parser.print_help()