vmwhere 0.2.0__tar.gz → 0.3.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.
Files changed (51) hide show
  1. vmwhere-0.3.0/CHANGELOG.md +72 -0
  2. vmwhere-0.3.0/PKG-INFO +243 -0
  3. vmwhere-0.3.0/README.md +222 -0
  4. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/_version.py +3 -3
  5. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/genotyper.py +21 -10
  6. vmwhere-0.3.0/src/vmwhere.egg-info/PKG-INFO +243 -0
  7. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere.egg-info/SOURCES.txt +7 -2
  8. vmwhere-0.3.0/src/vmwhere.egg-info/scm_file_list.json +40 -0
  9. vmwhere-0.3.0/src/vmwhere.egg-info/scm_version.json +8 -0
  10. vmwhere-0.3.0/tests/test_identify_alleles.py +65 -0
  11. vmwhere-0.3.0/tests/test_primary_alignment.py +26 -0
  12. vmwhere-0.3.0/vmwhere_logo_sky.png +0 -0
  13. vmwhere-0.2.0/PKG-INFO +0 -166
  14. vmwhere-0.2.0/README.md +0 -145
  15. vmwhere-0.2.0/src/vmwhere.egg-info/PKG-INFO +0 -166
  16. vmwhere-0.2.0/vmwhere_sky_logo.png +0 -0
  17. {vmwhere-0.2.0 → vmwhere-0.3.0}/.github/workflows/ci.yml +0 -0
  18. {vmwhere-0.2.0 → vmwhere-0.3.0}/.github/workflows/release.yml +0 -0
  19. {vmwhere-0.2.0 → vmwhere-0.3.0}/.gitignore +0 -0
  20. {vmwhere-0.2.0 → vmwhere-0.3.0}/LICENSE +0 -0
  21. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/data/.gitattributes +0 -0
  22. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/data/A673_sampled_reads.sorted.bam +0 -0
  23. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/data/A673_sampled_reads.sorted.bam.bai +0 -0
  24. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/data/GCF_009914755.1_T2T-CHM13v2.0_chr6_chr10.fasta +0 -0
  25. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/data/T2T_regions.bed +0 -0
  26. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/output/chr6_example_region_visualization.pdf +0 -0
  27. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/output/example_sample_vmwhere_results.tsv +0 -0
  28. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/output/microsatellite_coordinates.bed +0 -0
  29. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/run_vmwhere_find.sh +0 -0
  30. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/run_vmwhere_genotype.sh +0 -0
  31. {vmwhere-0.2.0 → vmwhere-0.3.0}/examples/run_vmwhere_visualize.sh +0 -0
  32. {vmwhere-0.2.0 → vmwhere-0.3.0}/pyproject.toml +0 -0
  33. {vmwhere-0.2.0 → vmwhere-0.3.0}/requirements-r.txt +0 -0
  34. {vmwhere-0.2.0 → vmwhere-0.3.0}/setup.cfg +0 -0
  35. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/__init__.py +0 -0
  36. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/chr_mapping_simple.txt +0 -0
  37. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/cli.py +0 -0
  38. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/find.py +0 -0
  39. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere/visualize_region.R +0 -0
  40. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere.egg-info/dependency_links.txt +0 -0
  41. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere.egg-info/entry_points.txt +0 -0
  42. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere.egg-info/requires.txt +0 -0
  43. {vmwhere-0.2.0 → vmwhere-0.3.0}/src/vmwhere.egg-info/top_level.txt +0 -0
  44. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/A673_sampled_reads.sorted.bam +0 -0
  45. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/A673_sampled_reads.sorted.bam.bai +0 -0
  46. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/T2T_regions.bed +0 -0
  47. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/__init__.py +0 -0
  48. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/conftest.py +0 -0
  49. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/test_cluster_reads.py +0 -0
  50. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/test_decompose_reads.py +0 -0
  51. {vmwhere-0.2.0 → vmwhere-0.3.0}/tests/test_find.py +0 -0
@@ -0,0 +1,72 @@
1
+ # Changelog
2
+
3
+ All notable changes to vmwhere are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2026-12-03
9
+
10
+ Both genotyping changes below can alter results relative to 0.2.1: read support (`RS`),
11
+ which microsatellites are reported, and which alleles are called.
12
+
13
+ ### Changed
14
+
15
+ - `vmwhere genotype` now reports at most two alleles per microsatellite. When more than two
16
+ alleles pass `--minor_threshold`, the two with the most read support are kept (ties go to
17
+ the allele listed first). Microsatellites with one or two alleles are unchanged.
18
+
19
+ ### Fixed
20
+
21
+ - `vmwhere genotype` now uses only primary alignments. Previously, supplementary alignments
22
+ were genotyped, and secondary and supplementary alignments counted toward the minimum of
23
+ 3 reads required to genotype a microsatellite.
24
+
25
+ ### Documentation
26
+
27
+ - README: added supported sequencing platforms and input requirements, a description of
28
+ which reads are used, guidance for choosing `find` and `genotype` parameters, a worked
29
+ example of an output row, and runtime and memory usage on representative samples.
30
+ - README: added the preprint citation and bioRxiv/Zenodo DOI badges.
31
+
32
+ ## [0.2.1] - 2026-04-07
33
+
34
+ ### Fixed
35
+
36
+ - README logo now uses an absolute URL so it renders on PyPI.
37
+
38
+ ## [0.2.0] - 2026-04-07
39
+
40
+ ### Changed
41
+
42
+ - Dependency versions for pysam, biopython and python-Levenshtein are now lower bounds
43
+ (`>=`) rather than exact pins, so pip can use pre-built wheels.
44
+
45
+ ### Fixed
46
+
47
+ - `vmwhere find` now writes its BED columns in the order `vmwhere genotype` expects
48
+ (`chr`, `start`, `end`, `region_id`, `motif`); `region_id` and `motif` were swapped.
49
+ - Corrected the package-data entry for `visualize_region.R`, the script used by
50
+ `vmwhere visualize` (it pointed to a filename that does not exist).
51
+
52
+ ### Documentation
53
+
54
+ - README rewritten for public release, with corrected parameter names and complete
55
+ parameter descriptions.
56
+
57
+ ## [0.1.0] - 2026-02-06
58
+
59
+ First tagged release.
60
+
61
+ ### Added
62
+
63
+ - `vmwhere find`: discover microsatellites for a motif in a reference FASTA.
64
+ - `vmwhere genotype`: sequence-resolved genotyping of microsatellites from long-read BAM files.
65
+ - `vmwhere visualize`: allele structure and frequency plots for a microsatellite.
66
+ - Automatic versioning from git tags (setuptools-scm) and GitHub Actions workflows for
67
+ tests and PyPI release.
68
+
69
+ [0.3.0]: https://github.com/pirl-unc/vmwhere/compare/v0.2.1...v0.3.0
70
+ [0.2.1]: https://github.com/pirl-unc/vmwhere/compare/v0.2.0...v0.2.1
71
+ [0.2.0]: https://github.com/pirl-unc/vmwhere/compare/v0.1.0...v0.2.0
72
+ [0.1.0]: https://github.com/pirl-unc/vmwhere/releases/tag/v0.1.0
vmwhere-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: vmwhere
3
+ Version: 0.3.0
4
+ Summary: Genotyping and sequence-resolved allele calling for tandem repeat regions
5
+ Author-email: Sara Peterson <skpet@unc.edu>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/pirl-unc/vmwhere
8
+ Project-URL: Bug Tracker, https://github.com/pirl-unc/vmwhere
9
+ Keywords: genotyping,tandem repeats,sequence decomposition,ewing sarcoma,microsatellite
10
+ Requires-Python: >=3.12.4
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: pandas>=2.2.0
14
+ Requires-Dist: pysam>=0.22.1
15
+ Requires-Dist: biopython>=1.84
16
+ Requires-Dist: python-Levenshtein>=0.27.1
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
19
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ [![Preprint](https://img.shields.io/badge/bioRxiv-10.64898%2F2026.04.08.717017-D9A441)](https://doi.org/10.64898/2026.04.08.717017)
23
+ [![Zenodo](https://img.shields.io/badge/Zenodo-10.5281%2Fzenodo.21999505-2A7F7F)](https://doi.org/10.5281/zenodo.21999505)
24
+ [![PyPI](https://img.shields.io/pypi/v/vmwhere?color=C8642A)](https://pypi.org/project/vmwhere/)
25
+ [![Tests](https://github.com/pirl-unc/vmwhere/actions/workflows/ci.yml/badge.svg)](https://github.com/pirl-unc/vmwhere/actions/workflows/ci.yml)
26
+
27
+ <div align="center">
28
+ <img src="https://raw.githubusercontent.com/pirl-unc/vmwhere/main/vmwhere_logo_sky.png" alt="logo" width="400"/>
29
+ </div>
30
+
31
+ # variant motif where? variant motif here!
32
+
33
+ vmwhere (VariantMotifwhere) is a tool for analyzing tandem repeat (microsatellite) regions from long-read sequencing data (PacBio and ONT). It provides three core capabilities:
34
+
35
+ 1. **Discovery** — identify microsatellite coordinates in a reference genome
36
+ 2. **Genotyping** — call allele length, repeath length, and motif-level sequence decomposition at each locus
37
+ 3. **Visualization** — generate sequence-resolved allele frequency plots
38
+
39
+ ---
40
+ ## Citation
41
+
42
+ If you use vmwhere, please cite our pre-print:
43
+
44
+ > Peterson SK, Massie AM, Rubinsteyn A, Wang JR, Davis IJ. Long-read analysis of tetrameric microsatellites with vmwhere supports GGAA repeat length–dependent chromatin state association in Ewing sarcoma. *bioRxiv* (2026). https://doi.org/10.64898/2026.04.08.717017
45
+
46
+ ## Installation
47
+
48
+ VMwhere is available as a Python package:
49
+
50
+ ```bash
51
+ pip install vmwhere
52
+ ```
53
+
54
+ ---
55
+ ## Requirements
56
+
57
+ - **Python** >= 3.12.4
58
+
59
+ - **R** (>= 4.0) — required only for the `visualize` subcommand.
60
+ Install required R packages:
61
+
62
+ ```bash
63
+ Rscript -e "install.packages(readLines('requirements-r.txt'), repos='https://cloud.r-project.org')"
64
+ ```
65
+
66
+ ---
67
+
68
+ ## Usage
69
+
70
+ ### 1. Find microsatellites
71
+
72
+ Scan a reference FASTA for tandem repeat regions matching a given motif.
73
+
74
+ ```bash
75
+ vmwhere find \
76
+ --motif GGAA \
77
+ --perfect_repeats 2 \
78
+ --max_gap 50 \
79
+ --buffer_size 50 \
80
+ --fasta data/reference.fasta \
81
+ --output_dir output/
82
+ ```
83
+
84
+ This outputs a BED file (`microsatellite_coordinates.bed`) with columns: `chr`, `start`, `end`, `region_id`, `motif`.
85
+
86
+ #### Parameters
87
+ | Flag | Description |
88
+ |------|-------------|
89
+ | `--motif` / `-m` | Repeat motif sequence to search for (e.g., `GGAA`) |
90
+ | `--fasta` / `-f` | Path to the reference genome FASTA |
91
+ | `--output_dir` / `-o` | Output directory |
92
+ | `--perfect_repeats` / `-r` | Minimum number of consecutive repeats to report a microsatellite loci (default: 2) |
93
+ | `--max_gap` / `-g` | Maximum base pairs between adjacent microsatellites before they are treated as distinct loci (default: 50) |
94
+ | `--buffer_size` / `-b` | Base pairs to extend beyond the outermost repeat on each side (default: 50) |
95
+
96
+ See [`examples/run_vmwhere_find.sh`](examples/run_vmwhere_find.sh) for a runnable example.
97
+
98
+ #### Choosing parameters
99
+
100
+ **`--perfect_repeats`** — the minimum number of consecutive repeats a locus must contain somewhere. The number of minimum consecutive repeats will change the number of microsatellites identified. As an example, for GGAA repeat loci on T2T-CHM13v2 (`--max_gap 100`), 4, 3 and 2 repeats give 13,687, 25,126 and 283,997 loci respectively.
101
+
102
+ **`--max_gap`** — repeat runs closer than this are reported as one locus. Larger values join interrupted repeats into a single locus but lengthen the interval that every read must span. For GGAA on T2T-CHM13v2 with at least 4 perfect repeats:
103
+
104
+ | `--max_gap` (bp) | Loci | Interval length, median (bp) | 95th percentile (bp) | Longest (bp) |
105
+ |---|---|---|---|---|
106
+ | 0 | 17,695 | 120 | 156 | 308 |
107
+ | 25 | 15,402 | 120 | 168 | 492 |
108
+ | 50 | 14,513 | 124 | 185 | 1,640 |
109
+ | 100 | 13,687 | 124 | 219 | 1,640 |
110
+ | 200 | 13,138 | 124 | 259 | 2,033 |
111
+
112
+ **`--buffer_size`** — flanking sequence added on each side. 50 bp is recommended. In simulated data (140 loci, 30X), a 25 bp buffer gave the same call as 50 bp at 97-98% of loci, while 100 and 200 bp gave the same call at 89-92% and lowered exact allele-length accuracy from 94-97% to 88-90%, because longer intervals include more flanking sequence that can be mistaken for part of the repeat.
113
+
114
+ ### 2. Genotype microsatellites
115
+
116
+ Extract reads overlapping each locus, decompose sequences into motif and non-motif segments, cluster reads by Levenshtein distance, and call alleles.
117
+
118
+ ```bash
119
+ vmwhere genotype \
120
+ --sample_id example_sample \
121
+ --bed_file data/T2T_regions.bed \
122
+ --bam_file data/A673_sampled_reads.sorted.bam \
123
+ --fasta data/GCF_009914755.1_T2T-CHM13v2.0_chr6_chr10.fasta \
124
+ --cluster_distance 0 \
125
+ --minor_threshold 0.20 \
126
+ --major_threshold 0.80 \
127
+ --output_dir output/ \
128
+ --num_processes 2
129
+ ```
130
+
131
+ See [`examples/run_vmwhere_genotype.sh`](examples/run_vmwhere_genotype.sh) for a runnable example.
132
+
133
+ #### Input data
134
+
135
+ | Input | Requirement |
136
+ |-------|-------------|
137
+ | Reads | Whole-genome long reads, Oxford Nanopore or PacBio HiFi, aligned to the reference (for example `minimap2 -ax map-ont` or `-ax map-hifi`), coordinate-sorted and indexed |
138
+ | Reference | The FASTA the reads were aligned to |
139
+ | Regions | Headerless 5-column BED: `chr`, `start`, `end`, `region_id`, `motif`. Any BED in this format can be genotyped, not only the output of `vmwhere find` |
140
+
141
+ vmwhere has been tested on simulated Oxford Nanopore and PacBio HiFi reads and on real Oxford Nanopore data aligned to T2T-CHM13v2. The BED file uses UCSC-style chromosome names (`chr1`); the BAM and FASTA may use the same names or the T2T-CHM13v2 RefSeq accessions (`NC_060925.1`).
142
+
143
+ #### Which reads are used to determine genotype
144
+
145
+ - A read is used at a microsatellite only if its primary alignment spans the whole BED interval, including the buffer. Secondary and supplementary alignments are ignored.
146
+ - vmwhere does not filter on mapping quality. In regions that cannot be mapped uniquely (for example the short arms of the acrocentric chromosomes), filter the BAM or the results.
147
+ - A microsatellite is skipped if fewer than 3 primary alignments overlap it.
148
+ - A sequence observed in a single read at a microsatellite is discarded as likely error.
149
+ - At most two alleles are reported per microsatellite.
150
+
151
+ #### Parameters
152
+
153
+ **Required:**
154
+
155
+ | Flag | Description |
156
+ |------|-------------|
157
+ | `--sample_id` | Sample identifier (used in output filename) |
158
+ | `--bam_file` | Path to sorted, indexed BAM file (PacBio or ONT data) |
159
+ | `--fasta` | Path to the reference genome FASTA |
160
+ | `--bed_file` | Headerless BED file with columns: `chr`, `start`, `end`, `region_id`, `motif` |
161
+ | `--output_dir` | Output directory (file will be named `<sample_id>_vmwhere_results.tsv`) |
162
+
163
+ **Optional:**
164
+
165
+ | Flag | Description | Default |
166
+ |------|-------------|---------|
167
+ | `--cluster_distance` | Maximum Levenshtein distance for grouping reads into a cluster | 0 |
168
+ | `--minor_threshold` | Minimum read support fraction to call a minor allele | 0.20 |
169
+ | `--major_threshold` | Minimum read support fraction to call a homozygous genotype | 0.80 |
170
+ | `--num_processes` | Number of parallel processes | 24 |
171
+
172
+ The defaults for `--cluster_distance`, `--minor_threshold` and `--major_threshold` (0, 0.20, 0.80) suit a diploid sample. A larger clustering distance merges reads that differ by a few bases into one allele and can merge true alleles that differ by one repeat.
173
+
174
+
175
+ #### Output TSV columns
176
+
177
+ The output follows VCF-style conventions but is written as a TSV for simpler parsing.
178
+
179
+ | Column | Description |
180
+ |--------|-------------|
181
+ | `CHROM` | Chromosome |
182
+ | `POS` | Start coordinate of the microsatellite |
183
+ | `ID` | Locus identifier from the input BED file |
184
+ | `REF` | Reference allele sequence |
185
+ | `ALT` | Alternate allele sequence(s); `.` if none |
186
+ | `END` | End coordinate of the microsatellite |
187
+ | `MOTIF` | Primary repeat motif |
188
+ | `GT` | Genotype (e.g., `0/0` = homozygous reference, `0/1` = heterozygous) |
189
+ | `AL` | Allele length (in base pairs) |
190
+ | `CN` | Total repeats (motif units) of the primary motif (consecutive and interrupted occurrences contained within the allele length sequence) |
191
+ | `CNM` | Number of maximum consecutive repeats (motif units) of the primary motif (e.g., `6GGAA_1GGAT_2GGAA` = 6) |
192
+ | `MD` | Motif density — fraction of base pairs that match the primary motif |
193
+ | `DS_READ` | Decomposed sequence of the allele |
194
+ | `DS_REF` | Decomposed sequence of the reference |
195
+ | `RS` | Read support for the allele |
196
+
197
+
198
+ #### Reading the output
199
+
200
+ One row of the example output ([`examples/output/example_sample_vmwhere_results.tsv`](examples/output/example_sample_vmwhere_results.tsv)):
201
+
202
+ | Column | Value | Meaning |
203
+ |--------|-------|---------|
204
+ | `ID` | `chr10_region_100` | Microsatellite identifier from the BED file |
205
+ | `GT` | `1/2` | Two alleles, both different from the reference |
206
+ | `AL` | `60,68` | Allele lengths in base pairs |
207
+ | `CN` | `15,17` | Number of GGAAs in each allele (regardless of sequence interruptions) |
208
+ | `CNM` | `15,17` | Number of maximum consecutive repeats of GGAA in each allele |
209
+ | `MD` | `1.0,1.0` | Fraction of each allele comprised of GGAAs |
210
+ | `DS_READ` | `15GGAA,17GGAA` | Decomposed alleles: 15 and 17 consecutive GGAA repeats |
211
+ | `DS_REF` | `8GGAA_1TGAA_7GGAA` | Decomposed reference: 8 GGAA, one TGAA, 7 GGAA |
212
+ | `RS` | `15,11` | Reads supporting each allele |
213
+
214
+ In the decomposed notation each segment is a count followed by a sequence, and segments are joined by `_`. The reference here has 15 GGAA repeat motifs but a maximum consecutive repeat number of 8, because a single TGAA interrupts it; both alleles in the sample lack the interruption, so the maximum consecutive repeat number is larger.
215
+
216
+ #### Notes on runtime and memory usage
217
+
218
+ Measured at 13,687 GGAA microsatellites on T2T-CHM13v2 (Intel Xeon, Python 3.12).
219
+
220
+ | Step | Data | Processes | Wall time | Peak memory |
221
+ |------|------|-----------|-----------|-------------|
222
+ | `find` | T2T-CHM13v2, one motif | 1 | 3 min | 28 GB |
223
+ | `genotype` | Oxford Nanopore, 45X, read N50 62 kb | 24 | 28 min | 102 GB |
224
+ | `genotype` | Oxford Nanopore, 43X, read N50 19 kb | 24 | 10 min | 92 GB |
225
+ | `genotype` | Oxford Nanopore, 30X | 24 | 5 min | 52 GB |
226
+
227
+
228
+
229
+ ### 3. Visualize alleles at a microsatellite
230
+
231
+ Generate a PDF showing sequence-resolved allele structures and their frequencies at a given locus.
232
+
233
+ ```bash
234
+ vmwhere visualize \
235
+ --genotype_tsv output/example_sample_vmwhere_results.tsv \
236
+ --microsatellite_id chr6_region_41 \
237
+ --min_allele_count 0 \
238
+ --output_pdf output/chr6_region_41_visualization.pdf
239
+ ```
240
+
241
+ See [`examples/run_vmwhere_visualize.sh`](examples/run_vmwhere_visualize.sh) for a runnable example.
242
+
243
+
@@ -0,0 +1,222 @@
1
+ [![Preprint](https://img.shields.io/badge/bioRxiv-10.64898%2F2026.04.08.717017-D9A441)](https://doi.org/10.64898/2026.04.08.717017)
2
+ [![Zenodo](https://img.shields.io/badge/Zenodo-10.5281%2Fzenodo.21999505-2A7F7F)](https://doi.org/10.5281/zenodo.21999505)
3
+ [![PyPI](https://img.shields.io/pypi/v/vmwhere?color=C8642A)](https://pypi.org/project/vmwhere/)
4
+ [![Tests](https://github.com/pirl-unc/vmwhere/actions/workflows/ci.yml/badge.svg)](https://github.com/pirl-unc/vmwhere/actions/workflows/ci.yml)
5
+
6
+ <div align="center">
7
+ <img src="https://raw.githubusercontent.com/pirl-unc/vmwhere/main/vmwhere_logo_sky.png" alt="logo" width="400"/>
8
+ </div>
9
+
10
+ # variant motif where? variant motif here!
11
+
12
+ vmwhere (VariantMotifwhere) is a tool for analyzing tandem repeat (microsatellite) regions from long-read sequencing data (PacBio and ONT). It provides three core capabilities:
13
+
14
+ 1. **Discovery** — identify microsatellite coordinates in a reference genome
15
+ 2. **Genotyping** — call allele length, repeath length, and motif-level sequence decomposition at each locus
16
+ 3. **Visualization** — generate sequence-resolved allele frequency plots
17
+
18
+ ---
19
+ ## Citation
20
+
21
+ If you use vmwhere, please cite our pre-print:
22
+
23
+ > Peterson SK, Massie AM, Rubinsteyn A, Wang JR, Davis IJ. Long-read analysis of tetrameric microsatellites with vmwhere supports GGAA repeat length–dependent chromatin state association in Ewing sarcoma. *bioRxiv* (2026). https://doi.org/10.64898/2026.04.08.717017
24
+
25
+ ## Installation
26
+
27
+ VMwhere is available as a Python package:
28
+
29
+ ```bash
30
+ pip install vmwhere
31
+ ```
32
+
33
+ ---
34
+ ## Requirements
35
+
36
+ - **Python** >= 3.12.4
37
+
38
+ - **R** (>= 4.0) — required only for the `visualize` subcommand.
39
+ Install required R packages:
40
+
41
+ ```bash
42
+ Rscript -e "install.packages(readLines('requirements-r.txt'), repos='https://cloud.r-project.org')"
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Usage
48
+
49
+ ### 1. Find microsatellites
50
+
51
+ Scan a reference FASTA for tandem repeat regions matching a given motif.
52
+
53
+ ```bash
54
+ vmwhere find \
55
+ --motif GGAA \
56
+ --perfect_repeats 2 \
57
+ --max_gap 50 \
58
+ --buffer_size 50 \
59
+ --fasta data/reference.fasta \
60
+ --output_dir output/
61
+ ```
62
+
63
+ This outputs a BED file (`microsatellite_coordinates.bed`) with columns: `chr`, `start`, `end`, `region_id`, `motif`.
64
+
65
+ #### Parameters
66
+ | Flag | Description |
67
+ |------|-------------|
68
+ | `--motif` / `-m` | Repeat motif sequence to search for (e.g., `GGAA`) |
69
+ | `--fasta` / `-f` | Path to the reference genome FASTA |
70
+ | `--output_dir` / `-o` | Output directory |
71
+ | `--perfect_repeats` / `-r` | Minimum number of consecutive repeats to report a microsatellite loci (default: 2) |
72
+ | `--max_gap` / `-g` | Maximum base pairs between adjacent microsatellites before they are treated as distinct loci (default: 50) |
73
+ | `--buffer_size` / `-b` | Base pairs to extend beyond the outermost repeat on each side (default: 50) |
74
+
75
+ See [`examples/run_vmwhere_find.sh`](examples/run_vmwhere_find.sh) for a runnable example.
76
+
77
+ #### Choosing parameters
78
+
79
+ **`--perfect_repeats`** — the minimum number of consecutive repeats a locus must contain somewhere. The number of minimum consecutive repeats will change the number of microsatellites identified. As an example, for GGAA repeat loci on T2T-CHM13v2 (`--max_gap 100`), 4, 3 and 2 repeats give 13,687, 25,126 and 283,997 loci respectively.
80
+
81
+ **`--max_gap`** — repeat runs closer than this are reported as one locus. Larger values join interrupted repeats into a single locus but lengthen the interval that every read must span. For GGAA on T2T-CHM13v2 with at least 4 perfect repeats:
82
+
83
+ | `--max_gap` (bp) | Loci | Interval length, median (bp) | 95th percentile (bp) | Longest (bp) |
84
+ |---|---|---|---|---|
85
+ | 0 | 17,695 | 120 | 156 | 308 |
86
+ | 25 | 15,402 | 120 | 168 | 492 |
87
+ | 50 | 14,513 | 124 | 185 | 1,640 |
88
+ | 100 | 13,687 | 124 | 219 | 1,640 |
89
+ | 200 | 13,138 | 124 | 259 | 2,033 |
90
+
91
+ **`--buffer_size`** — flanking sequence added on each side. 50 bp is recommended. In simulated data (140 loci, 30X), a 25 bp buffer gave the same call as 50 bp at 97-98% of loci, while 100 and 200 bp gave the same call at 89-92% and lowered exact allele-length accuracy from 94-97% to 88-90%, because longer intervals include more flanking sequence that can be mistaken for part of the repeat.
92
+
93
+ ### 2. Genotype microsatellites
94
+
95
+ Extract reads overlapping each locus, decompose sequences into motif and non-motif segments, cluster reads by Levenshtein distance, and call alleles.
96
+
97
+ ```bash
98
+ vmwhere genotype \
99
+ --sample_id example_sample \
100
+ --bed_file data/T2T_regions.bed \
101
+ --bam_file data/A673_sampled_reads.sorted.bam \
102
+ --fasta data/GCF_009914755.1_T2T-CHM13v2.0_chr6_chr10.fasta \
103
+ --cluster_distance 0 \
104
+ --minor_threshold 0.20 \
105
+ --major_threshold 0.80 \
106
+ --output_dir output/ \
107
+ --num_processes 2
108
+ ```
109
+
110
+ See [`examples/run_vmwhere_genotype.sh`](examples/run_vmwhere_genotype.sh) for a runnable example.
111
+
112
+ #### Input data
113
+
114
+ | Input | Requirement |
115
+ |-------|-------------|
116
+ | Reads | Whole-genome long reads, Oxford Nanopore or PacBio HiFi, aligned to the reference (for example `minimap2 -ax map-ont` or `-ax map-hifi`), coordinate-sorted and indexed |
117
+ | Reference | The FASTA the reads were aligned to |
118
+ | Regions | Headerless 5-column BED: `chr`, `start`, `end`, `region_id`, `motif`. Any BED in this format can be genotyped, not only the output of `vmwhere find` |
119
+
120
+ vmwhere has been tested on simulated Oxford Nanopore and PacBio HiFi reads and on real Oxford Nanopore data aligned to T2T-CHM13v2. The BED file uses UCSC-style chromosome names (`chr1`); the BAM and FASTA may use the same names or the T2T-CHM13v2 RefSeq accessions (`NC_060925.1`).
121
+
122
+ #### Which reads are used to determine genotype
123
+
124
+ - A read is used at a microsatellite only if its primary alignment spans the whole BED interval, including the buffer. Secondary and supplementary alignments are ignored.
125
+ - vmwhere does not filter on mapping quality. In regions that cannot be mapped uniquely (for example the short arms of the acrocentric chromosomes), filter the BAM or the results.
126
+ - A microsatellite is skipped if fewer than 3 primary alignments overlap it.
127
+ - A sequence observed in a single read at a microsatellite is discarded as likely error.
128
+ - At most two alleles are reported per microsatellite.
129
+
130
+ #### Parameters
131
+
132
+ **Required:**
133
+
134
+ | Flag | Description |
135
+ |------|-------------|
136
+ | `--sample_id` | Sample identifier (used in output filename) |
137
+ | `--bam_file` | Path to sorted, indexed BAM file (PacBio or ONT data) |
138
+ | `--fasta` | Path to the reference genome FASTA |
139
+ | `--bed_file` | Headerless BED file with columns: `chr`, `start`, `end`, `region_id`, `motif` |
140
+ | `--output_dir` | Output directory (file will be named `<sample_id>_vmwhere_results.tsv`) |
141
+
142
+ **Optional:**
143
+
144
+ | Flag | Description | Default |
145
+ |------|-------------|---------|
146
+ | `--cluster_distance` | Maximum Levenshtein distance for grouping reads into a cluster | 0 |
147
+ | `--minor_threshold` | Minimum read support fraction to call a minor allele | 0.20 |
148
+ | `--major_threshold` | Minimum read support fraction to call a homozygous genotype | 0.80 |
149
+ | `--num_processes` | Number of parallel processes | 24 |
150
+
151
+ The defaults for `--cluster_distance`, `--minor_threshold` and `--major_threshold` (0, 0.20, 0.80) suit a diploid sample. A larger clustering distance merges reads that differ by a few bases into one allele and can merge true alleles that differ by one repeat.
152
+
153
+
154
+ #### Output TSV columns
155
+
156
+ The output follows VCF-style conventions but is written as a TSV for simpler parsing.
157
+
158
+ | Column | Description |
159
+ |--------|-------------|
160
+ | `CHROM` | Chromosome |
161
+ | `POS` | Start coordinate of the microsatellite |
162
+ | `ID` | Locus identifier from the input BED file |
163
+ | `REF` | Reference allele sequence |
164
+ | `ALT` | Alternate allele sequence(s); `.` if none |
165
+ | `END` | End coordinate of the microsatellite |
166
+ | `MOTIF` | Primary repeat motif |
167
+ | `GT` | Genotype (e.g., `0/0` = homozygous reference, `0/1` = heterozygous) |
168
+ | `AL` | Allele length (in base pairs) |
169
+ | `CN` | Total repeats (motif units) of the primary motif (consecutive and interrupted occurrences contained within the allele length sequence) |
170
+ | `CNM` | Number of maximum consecutive repeats (motif units) of the primary motif (e.g., `6GGAA_1GGAT_2GGAA` = 6) |
171
+ | `MD` | Motif density — fraction of base pairs that match the primary motif |
172
+ | `DS_READ` | Decomposed sequence of the allele |
173
+ | `DS_REF` | Decomposed sequence of the reference |
174
+ | `RS` | Read support for the allele |
175
+
176
+
177
+ #### Reading the output
178
+
179
+ One row of the example output ([`examples/output/example_sample_vmwhere_results.tsv`](examples/output/example_sample_vmwhere_results.tsv)):
180
+
181
+ | Column | Value | Meaning |
182
+ |--------|-------|---------|
183
+ | `ID` | `chr10_region_100` | Microsatellite identifier from the BED file |
184
+ | `GT` | `1/2` | Two alleles, both different from the reference |
185
+ | `AL` | `60,68` | Allele lengths in base pairs |
186
+ | `CN` | `15,17` | Number of GGAAs in each allele (regardless of sequence interruptions) |
187
+ | `CNM` | `15,17` | Number of maximum consecutive repeats of GGAA in each allele |
188
+ | `MD` | `1.0,1.0` | Fraction of each allele comprised of GGAAs |
189
+ | `DS_READ` | `15GGAA,17GGAA` | Decomposed alleles: 15 and 17 consecutive GGAA repeats |
190
+ | `DS_REF` | `8GGAA_1TGAA_7GGAA` | Decomposed reference: 8 GGAA, one TGAA, 7 GGAA |
191
+ | `RS` | `15,11` | Reads supporting each allele |
192
+
193
+ In the decomposed notation each segment is a count followed by a sequence, and segments are joined by `_`. The reference here has 15 GGAA repeat motifs but a maximum consecutive repeat number of 8, because a single TGAA interrupts it; both alleles in the sample lack the interruption, so the maximum consecutive repeat number is larger.
194
+
195
+ #### Notes on runtime and memory usage
196
+
197
+ Measured at 13,687 GGAA microsatellites on T2T-CHM13v2 (Intel Xeon, Python 3.12).
198
+
199
+ | Step | Data | Processes | Wall time | Peak memory |
200
+ |------|------|-----------|-----------|-------------|
201
+ | `find` | T2T-CHM13v2, one motif | 1 | 3 min | 28 GB |
202
+ | `genotype` | Oxford Nanopore, 45X, read N50 62 kb | 24 | 28 min | 102 GB |
203
+ | `genotype` | Oxford Nanopore, 43X, read N50 19 kb | 24 | 10 min | 92 GB |
204
+ | `genotype` | Oxford Nanopore, 30X | 24 | 5 min | 52 GB |
205
+
206
+
207
+
208
+ ### 3. Visualize alleles at a microsatellite
209
+
210
+ Generate a PDF showing sequence-resolved allele structures and their frequencies at a given locus.
211
+
212
+ ```bash
213
+ vmwhere visualize \
214
+ --genotype_tsv output/example_sample_vmwhere_results.tsv \
215
+ --microsatellite_id chr6_region_41 \
216
+ --min_allele_count 0 \
217
+ --output_pdf output/chr6_region_41_visualization.pdf
218
+ ```
219
+
220
+ See [`examples/run_vmwhere_visualize.sh`](examples/run_vmwhere_visualize.sh) for a runnable example.
221
+
222
+
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.2.0'
22
- __version_tuple__ = version_tuple = (0, 2, 0)
21
+ __version__ = version = '0.3.0'
22
+ __version_tuple__ = version_tuple = (0, 3, 0)
23
23
 
24
- __commit_id__ = commit_id = 'gd8ff59d55'
24
+ __commit_id__ = commit_id = 'g87e63656f'
@@ -1,13 +1,10 @@
1
1
  import pysam
2
- import argparse
3
2
  import pandas as pd
4
3
  from importlib.resources import files
5
- import glob
6
4
  import os
7
5
  from Bio.Seq import Seq
8
6
  from Bio import SeqIO
9
7
  import multiprocessing as mp
10
- from multiprocessing import Pool
11
8
  import Levenshtein
12
9
  import re
13
10
 
@@ -479,6 +476,10 @@ def cluster_consolidated_reads_by_edit_distance(consolidated_results, cluster_di
479
476
 
480
477
  return centroids_df_final
481
478
 
479
+ def is_primary_alignment(read):
480
+ """Return True only for mapped, primary alignments (not secondary, supplementary, or unmapped)."""
481
+ return not (read.is_secondary or read.is_supplementary or read.is_unmapped)
482
+
482
483
  def process_reads_overlapping_regions(chr_map, regions, bamfile, reference_sequence, cluster_distance):
483
484
  """
484
485
  Processes reads for regions specified in a BED-like dataframe.
@@ -526,7 +527,6 @@ def process_reads_overlapping_regions(chr_map, regions, bamfile, reference_seque
526
527
  'RS': []
527
528
  }
528
529
 
529
- suss_dels=0
530
530
  reverse_motif = str(Seq(motif).reverse_complement())
531
531
 
532
532
  # analyse one region at a time
@@ -540,7 +540,7 @@ def process_reads_overlapping_regions(chr_map, regions, bamfile, reference_seque
540
540
 
541
541
  primary_reads = 0
542
542
  for read in bamfile.fetch(chrom_bam, start_coord, end_coord):
543
- if not read.is_secondary or not read.is_unmapped:
543
+ if is_primary_alignment(read):
544
544
  primary_reads += 1
545
545
  if primary_reads >= 3:
546
546
  break
@@ -568,8 +568,8 @@ def process_reads_overlapping_regions(chr_map, regions, bamfile, reference_seque
568
568
 
569
569
  # Fetch reads from BAM file overlapping current region
570
570
  for read in bamfile.fetch(chrom_bam, start_coord, end_coord):
571
- # Only count reads where this is the primary alignment (skip secondary alignments)
572
- if read.is_secondary or read.is_unmapped:
571
+ # Only use primary alignments (skip secondary, supplementary, and unmapped reads)
572
+ if not is_primary_alignment(read):
573
573
  continue
574
574
 
575
575
  qstart = None
@@ -730,7 +730,7 @@ def process_reads_overlapping_regions(chr_map, regions, bamfile, reference_seque
730
730
 
731
731
  # perform decomposition of the read sequence and identify variants present
732
732
  read_structure, allele_length, read_microsat_seq = decompose_seq_with_motif_anchors(query_seq_microsat, motif)
733
- perfect_motif_count_decomp, count_max_consecutive_motif_repeats_decomp, snp_variant_count, multi_bp_variant_count, single_bp_inbetween_count, multi_bp_inbetween_count = classify_variants_from_structure(read_structure, motif)
733
+ perfect_motif_count_decomp, count_max_consecutive_motif_repeats_decomp, _, _, _, _ = classify_variants_from_structure(read_structure, motif)
734
734
 
735
735
  # determine total number of prefect motifs present and max consecutive by counting them in the original string
736
736
  max_consecutive_repeats = count_max_consecutive_motifs(query_seq_microsat, motif)
@@ -826,8 +826,17 @@ def process_single_chromosome(args):
826
826
  return motif, chromosome_curr, query_read_results_df
827
827
 
828
828
 
829
+ MAX_ALLELES_PER_LOCUS = 2 # calls are diploid
830
+
831
+
829
832
  def identify_alleles(read_summary_df, minor_thresh=0.20, homozygous_thresh=0.8):
830
- """Determine alleles based on read support."""
833
+ """
834
+ Determine alleles based on read support.
835
+
836
+ At most two alleles are called per locus. When more than two pass the minor
837
+ threshold, the two with the most read support are kept (ties go to the allele
838
+ listed first) and their original order is preserved.
839
+ """
831
840
 
832
841
  read_summary_df['RC'] = read_summary_df.groupby('ID')['RS'].transform('sum')
833
842
  read_summary_df['PS'] = read_summary_df['RS'] / read_summary_df['RC']
@@ -840,6 +849,9 @@ def identify_alleles(read_summary_df, minor_thresh=0.20, homozygous_thresh=0.8):
840
849
  filtered = group[group['PS'] >= homozygous_thresh]
841
850
  else:
842
851
  filtered = group[(group['PS'] >= minor_thresh)]
852
+ if len(filtered) > MAX_ALLELES_PER_LOCUS:
853
+ best_supported = filtered['RS'].nlargest(MAX_ALLELES_PER_LOCUS, keep='first').index
854
+ filtered = filtered.loc[filtered.index.isin(best_supported)]
843
855
  allele_dfs.append(filtered)
844
856
 
845
857
  return pd.concat(allele_dfs, ignore_index=True)
@@ -952,7 +964,6 @@ def run_genotyper(
952
964
 
953
965
  # Load BED file with all regions
954
966
  regions_df = pd.read_csv(BED_FILE, sep='\t', header=None)
955
- chromosomes = regions_df[0].unique()
956
967
 
957
968
  # determine all motifs present in the bed file
958
969
  all_motifs = regions_df[4].unique()