RNA-lexis 0.2.5__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 (32) hide show
  1. rna_lexis-0.2.5/LICENSE +19 -0
  2. rna_lexis-0.2.5/PKG-INFO +353 -0
  3. rna_lexis-0.2.5/README.md +330 -0
  4. rna_lexis-0.2.5/pyproject.toml +33 -0
  5. rna_lexis-0.2.5/setup.cfg +4 -0
  6. rna_lexis-0.2.5/src/RNA_lexis.egg-info/PKG-INFO +353 -0
  7. rna_lexis-0.2.5/src/RNA_lexis.egg-info/SOURCES.txt +30 -0
  8. rna_lexis-0.2.5/src/RNA_lexis.egg-info/dependency_links.txt +1 -0
  9. rna_lexis-0.2.5/src/RNA_lexis.egg-info/entry_points.txt +4 -0
  10. rna_lexis-0.2.5/src/RNA_lexis.egg-info/requires.txt +12 -0
  11. rna_lexis-0.2.5/src/RNA_lexis.egg-info/top_level.txt +1 -0
  12. rna_lexis-0.2.5/src/rna_lexis/RNAlang.py +86 -0
  13. rna_lexis-0.2.5/src/rna_lexis/__init__.py +10 -0
  14. rna_lexis-0.2.5/src/rna_lexis/__main__.py +5 -0
  15. rna_lexis-0.2.5/src/rna_lexis/algorithms.py +1429 -0
  16. rna_lexis-0.2.5/src/rna_lexis/alignment.py +357 -0
  17. rna_lexis-0.2.5/src/rna_lexis/data/NORAD_human.fasta +79 -0
  18. rna_lexis-0.2.5/src/rna_lexis/data/NORAD_mouse.fasta +72 -0
  19. rna_lexis-0.2.5/src/rna_lexis/data/README.md +56 -0
  20. rna_lexis-0.2.5/src/rna_lexis/dialogs.py +67 -0
  21. rna_lexis-0.2.5/src/rna_lexis/io.py +653 -0
  22. rna_lexis-0.2.5/src/rna_lexis/menu.py +2955 -0
  23. rna_lexis-0.2.5/src/rna_lexis/plots.py +1683 -0
  24. rna_lexis-0.2.5/src/rna_lexis/statistical.py +831 -0
  25. rna_lexis-0.2.5/src/rna_lexis/test_cli.py +223 -0
  26. rna_lexis-0.2.5/tests/test_algorithms.py +291 -0
  27. rna_lexis-0.2.5/tests/test_alignment.py +68 -0
  28. rna_lexis-0.2.5/tests/test_batch_cli.py +152 -0
  29. rna_lexis-0.2.5/tests/test_io.py +194 -0
  30. rna_lexis-0.2.5/tests/test_norad_integration.py +94 -0
  31. rna_lexis-0.2.5/tests/test_plots.py +195 -0
  32. rna_lexis-0.2.5/tests/test_statistical.py +110 -0
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,353 @@
1
+ Metadata-Version: 2.4
2
+ Name: RNA_lexis
3
+ Version: 0.2.5
4
+ Summary: A python package to explore RNA data
5
+ Author-email: Haim Bar <haim.bar@uconn.edu>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: matplotlib>=3.5.0
13
+ Requires-Dist: numpy
14
+ Requires-Dist: plotly>=5
15
+ Requires-Dist: pandas
16
+ Requires-Dist: weblogo
17
+ Requires-Dist: scipy
18
+ Requires-Dist: kaleido<1,>=0.2
19
+ Requires-Dist: markdown
20
+ Requires-Dist: platformdirs
21
+ Requires-Dist: pywin32; sys_platform == "win32"
22
+ Dynamic: license-file
23
+
24
+ # RNA_lexis
25
+
26
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21744120.svg)](https://doi.org/10.5281/zenodo.21744120)
27
+
28
+ **RNA_lexis** is an interactive command-line tool for exploring RNA (or DNA) sequence data.
29
+
30
+ Starting from a nucleotide sequence, it automatically identifies repeating subsequences
31
+ called **xmotifs** and extracts their shorter conserved cores. From there you can:
32
+
33
+ - Visualise the neighbourhood of any core sequence
34
+ - Study k-mer frequency distributions (z-score, rank-frequency, histograms)
35
+ - Test k-mer enrichment analytically with Markov-model p-values (no shuffling)
36
+ - Generate sequence logos
37
+ - Inspect coverage across the full transcript
38
+ - Align pairs of subsequences (Gotoh global / Smith–Waterman local)
39
+ - Search for exact and approximate (mutation-tolerant) matches
40
+ - Extend matching pairs greedily to find the longest shared context
41
+ - **Plot self-similarity as a semicircular arc diagram** — pairwise Hamming-bounded extensions among every occurrence of a seed motif, colored by tandem-repeat hop distance
42
+ - **Plot a shared-motif diagram against a second sequence** — connects every exact-match motif shared between the loaded sequence and a comparison sequence (paste, file, Ensembl ENST, genomic coordinates, or an ENCODE cCRE accession) as a two-row arc diagram
43
+ - **Compare motif-coverage sliding-window curves** — against another transcript (e.g. a cross-species ortholog, with automatic length-mismatch warnings), or against the same sequence's own GC-content or homopolymer/low-complexity-run density
44
+ - Fetch sequences directly from the Ensembl REST API by transcript ID
45
+ - **Score motifs against a transcript-specific Markov background with FDR correction**
46
+ - **Test mutation-tolerant motif families for statistical enrichment**
47
+ - **Search for anchor-gap-anchor gapped motif patterns**
48
+ - **Test whether motif occurrences are spaced periodically (gap-cluster and Rayleigh tests)**
49
+ - Clear workspace (remove all generated files while preserving the input sequence)
50
+ - **Try it instantly on a real dataset** — human and mouse NORAD transcripts
51
+ ship with the package itself (`pip install` and go, no fetching or
52
+ pasting required); see *Load example dataset* below.
53
+
54
+ ## Documentation
55
+
56
+ This README covers installation, features, and troubleshooting. Two other
57
+ docs go deeper:
58
+
59
+ - **[docs/user_guide.md](docs/user_guide.md)** — full menu-by-menu walkthrough
60
+ of the interactive tool, with every prompt, default, and output format
61
+ documented (also available as `docs/user_guide.html`/`.pdf`, or via the
62
+ app's own *Open User Guide* menu item).
63
+ - **[llms.txt](llms.txt)** — API reference for using RNA_lexis as a Python
64
+ library (functions, data structures, worked examples), written for both
65
+ developers and AI coding agents.
66
+
67
+ ## Initialisation summary (`_test_init.csv`)
68
+
69
+ When a sequence is loaded for the first time, an initialisation CSV is written that
70
+ characterises every xmotif and core. The file is named `<session>_test_init.csv`.
71
+
72
+ ### Core columns (all sequences)
73
+
74
+ | column | description |
75
+ |---|---|
76
+ | `xm` | 1 if the sequence is an xmotif, 0 otherwise |
77
+ | `core` | 1 if the sequence is a core (a sequence can be both) |
78
+ | `count` | number of exact occurrences in the transcript |
79
+ | `n_approx` | number of approximate occurrences (Hamming distance ≤ `maxmut`) |
80
+ | `cover` | `len × count` — nucleotides covered by exact matches |
81
+ | `numt` | total Hamming distance across all approximate matches |
82
+ | `pmut` | observed mutation rate per site: `numt / (len × (count + n_approx))` |
83
+ | `p_stable` | Binomial p-value for sequence stability (see below) |
84
+ | `maxmut` | maximum mutations allowed by the search (`floor(len × mutr)`, capped at `M`) |
85
+
86
+ ### Statistical columns (RNA/DNA sequences only)
87
+
88
+ For sequences whose alphabet is a subset of `{a, c, g, t, u}`, the following
89
+ columns are also added by scoring each motif against a transcript-specific
90
+ first-order Markov background:
91
+
92
+ | column | description |
93
+ |---|---|
94
+ | `expected_markov` | Expected count under the Markov null |
95
+ | `enrichment_markov` | `observed / expected` enrichment ratio |
96
+ | `p_markov` | Poisson upper-tail p-value for motif enrichment |
97
+ | `q_markov` | Benjamini–Hochberg FDR-adjusted p-value across all tested motifs |
98
+ | `statistically_supported` | `True` if `q_markov` is below threshold and the motif is enriched |
99
+ | `core_class` | `'supported'`, `'enriched_only'`, or `'not_supported'` |
100
+ | `rank_statistical` | Primary rank (by statistical support) |
101
+ | `rank_coverage` | Secondary rank (by coverage) |
102
+ | `coverage_bp` | Base-pairs covered by non-overlapping occurrences |
103
+ | `xmotif_type_support` | Number of distinct xmotif families containing this core |
104
+
105
+ When statistical columns are present the CSV is sorted by `statistically_supported`
106
+ (descending) then `q_markov` (ascending). Otherwise it is sorted by `p_stable`.
107
+
108
+ ### Stability p-value (`p_stable`)
109
+
110
+ Each sequence is tested against the null hypothesis that every site mutates independently
111
+ at the background rate `mutr` (default 1/6 — the same tolerance used during the search):
112
+
113
+ ```
114
+ p_stable = P(X ≤ numt) where X ~ Bin(len × N_total, mutr)
115
+ ```
116
+
117
+ `N_total = count + n_approx` is the total number of occurrences used as evidence.
118
+ A small `p_stable` means the sequence appears **more conserved than expected by
119
+ chance**, i.e., it is stable.
120
+ A sequence with no strong conservation signal will have `p_stable ≈ 0.5`.
121
+
122
+ ## Maximal core extension
123
+
124
+ Cores are automatically extended to their **maximal unique form** before being
125
+ reported. Starting from a raw core, the algorithm grows the string one character
126
+ at a time in each direction for as long as every occurrence in the transcript
127
+ shares the same flanking character. Multiple raw cores that collapse to the same
128
+ maximal string are deduplicated, eliminating the sliding-window redundancy common
129
+ in repeat-rich sequences.
130
+
131
+ ## K-mer Markov analysis
132
+
133
+ The *K-mer Markov analysis* menu option tests every observed k-mer analytically —
134
+ no shuffling or random seeds required. For each k-mer the expected count is
135
+ computed from the Prum/Schbath formula under a configurable-order Markov null and
136
+ tested with a Poisson exact p-value. The output CSV reports **two one-sided
137
+ p-values** per k-mer:
138
+
139
+ | column | description |
140
+ |---|---|
141
+ | `expected_count` | Expected count under the Markov null |
142
+ | `pvalue_over` | P(X ≥ obs) — small = **over-represented** |
143
+ | `evalue_over` | `pvalue_over × m` (expected false positives among *m* k-mers tested) |
144
+ | `pvalue_over_bh` | BH-adjusted p-value for over-representation (FDR) |
145
+ | `pvalue_under` | P(X ≤ obs) — small = **under-represented** |
146
+ | `evalue_under` | `pvalue_under × m` |
147
+ | `pvalue_under_bh` | BH-adjusted p-value for under-representation (FDR) |
148
+ | `direction` | `'over'` or `'under'` — which effect is stronger |
149
+
150
+ The **Markov background order** controls the null: `order=0` conditions only on
151
+ nucleotide frequencies (equivalent to the shuffle null); `order=1` (default)
152
+ conditions on dinucleotide frequencies and is recommended for transcripts of a
153
+ few kilobases. BH correction is applied separately for each direction across all
154
+ *m* k-mers. Rows are sorted by `min(pvalue_over, pvalue_under)`.
155
+
156
+ ## Statistical motif analysis
157
+
158
+ ### Rank core motifs (Markov/FDR)
159
+
160
+ The *Rank core motifs (Markov/FDR)* option (Sequence operations → 9) enumerates
161
+ all shared substrings of the current xmotifs within a configurable length range,
162
+ scores each candidate against the transcript-specific Markov background, and saves
163
+ a ranked CSV. Candidates are ranked first by statistical support (`q_markov` below
164
+ threshold, enrichment above threshold), then by coverage.
165
+
166
+ ### Mutation-family scoring
167
+
168
+ The *Mutation-family scoring* option (Sequence operations → 10) tests one or more
169
+ motifs at every Hamming radius allowed by the mutation cap. For each motif and
170
+ radius, the full neighbourhood of sequences within that distance is counted and
171
+ scored against the Markov background. The result shows whether the approximate
172
+ family as a whole is enriched beyond chance — going beyond simply allowing
173
+ mismatches. The best-supported radius per motif is saved to a `_best.csv` file.
174
+
175
+ ### Gapped motif search
176
+
177
+ The *Gapped motif search* option (Sequence operations → 6) finds all occurrences
178
+ of a pattern of the form `LEFT[gap:min–max]RIGHT`: two exact anchor sequences
179
+ separated by a variable-length gap. The whole family is scored under the Markov
180
+ background, and individual hits (with exact positions and gap lengths) are saved
181
+ to a CSV.
182
+
183
+ ### Motif spacing / periodicity test
184
+
185
+ The *Motif spacing / periodicity test* option (Sequence operations → 5) takes a
186
+ motif, finds all exact occurrences, and tests whether their spacing is more
187
+ periodic than expected by chance. Two complementary tests are applied:
188
+
189
+ **Gap cluster test** — counts how many consecutive gaps fall within a tolerance
190
+ window δ = max(5, 5 % × T) of the candidate period T (median gap). Tested against
191
+ a Binomial null Bin(n\_gaps, 2δ/L) with Bonferroni correction for estimating T
192
+ from the same data.
193
+
194
+ **Rayleigh test** — maps occurrence positions modulo T to angles and measures the
195
+ mean resultant length R (0 = random, 1 = perfectly periodic). A large R indicates
196
+ that positions cluster at a consistent phase relative to T.
197
+
198
+ Either test reaching p < 0.05 is reported as a positive periodicity signal.
199
+ Requires at least 3 exact occurrences.
200
+
201
+ ### Batch CLI (`rna_lexis_stat_cli`)
202
+
203
+ A separate command-line interface supports batch statistical workflows without
204
+ entering the interactive menu:
205
+
206
+ ```
207
+ rna_lexis_stat_cli score-exact --fasta FILE --motifs m1 m2 …
208
+ rna_lexis_stat_cli rank-cores --fasta FILE
209
+ rna_lexis_stat_cli mutation-families --fasta FILE --motifs m1 m2 …
210
+ rna_lexis_stat_cli gapped-motif --fasta FILE --left LEFT --right RIGHT
211
+ ```
212
+
213
+ ## Requirements
214
+
215
+ - Python 3.10 or newer
216
+ - Windows 10/11, macOS, or Linux
217
+
218
+ ### System (non-pip) requirements
219
+
220
+ A few features depend on tools that live outside the Python packaging
221
+ ecosystem, so `pip install` can't provide them:
222
+
223
+ - **`tkinter`** — required for the native file/folder picker dialogs. Bundled
224
+ with the standard Python installer on Windows and macOS, but many minimal
225
+ Linux installs (e.g. server/Docker base images) ship Python without it.
226
+ Install separately if dialogs silently return "no selection":
227
+ `sudo apt install python3-tk` (Debian/Ubuntu) or
228
+ `sudo dnf install python3-tkinter` (Fedora).
229
+ - **`pdf2svg`** (optional) — only needed for SVG-format sequence logo output;
230
+ without it, logo plots fall back to PDF automatically. Install via
231
+ `apt install pdf2svg` / `brew install pdf2svg`, or download a Windows build
232
+ manually.
233
+ - **`xdg-utils`** (Linux only, optional) — provides `xdg-open`, used to
234
+ auto-open saved plots/CSVs in their default application. Present on
235
+ virtually all Linux desktops by default; may be missing on minimal/headless
236
+ servers or containers, in which case files are still saved normally, just
237
+ not auto-opened.
238
+
239
+ ## Installation
240
+
241
+ ```
242
+ pip install .
243
+ ```
244
+
245
+ ## Usage
246
+
247
+ After installation, launch the interactive menu with:
248
+
249
+ ```
250
+ rna_lexis
251
+ ```
252
+
253
+ Or with the statistical-workflow alias:
254
+
255
+ ```
256
+ rna_lexis_stat
257
+ ```
258
+
259
+ Or, without installing:
260
+
261
+ ```
262
+ python -m rna_lexis
263
+ ```
264
+
265
+ ## Example dataset
266
+
267
+ Two real datasets ship inside the package itself — no internet connection,
268
+ account, or file to prepare — so you can try RNA_lexis immediately after
269
+ installing:
270
+
271
+ - **NORAD (human)** — Ensembl transcript `ENST00000565493`, 5401 nt.
272
+ - **NORAD (mouse)** — Ensembl transcript `ENSMUST00000192863`, 4945 nt.
273
+
274
+ From the interactive menu, choose **Load example dataset (NORAD)** at the
275
+ input-source prompt. NORAD is a well-studied lncRNA with a tandem repeat of
276
+ the Pumilio Response Element (core motif `tgtatata`), so the default
277
+ discovery pipeline reliably surfaces a real, biologically meaningful
278
+ repeat structure — a good way to confirm your installation works and see
279
+ what the tool finds on real data. Programmatically — note that `read_text()` strips non-alphabetic
280
+ characters but doesn't know about FASTA headers, so strip the header line
281
+ first:
282
+
283
+ ```python
284
+ from rna_lexis.io import example_dataset_path
285
+
286
+ path = example_dataset_path("NORAD_human")
287
+ with open(path, encoding="utf-8") as f:
288
+ txt = "".join(line for line in f if not line.startswith(">"))
289
+ txt = "".join(c for c in txt.lower() if c.isalpha())
290
+ ```
291
+
292
+ See `src/rna_lexis/data/README.md` in the package source for full
293
+ provenance (exact transcript IDs, assembly versions, fetch date).
294
+
295
+ ## Troubleshooting
296
+
297
+ - **Plots fail to export as PNG/SVG, or you see a kaleido/plotly version-mismatch
298
+ warning.** RNA_lexis pins `kaleido<1` deliberately (see `CHANGELOG.md` 0.1.11) —
299
+ `kaleido>=1` requires a separate Chrome install and only works with Plotly ≥ 6.
300
+ If your environment ends up with an incompatible kaleido anyway (e.g. another
301
+ project in the same environment upgraded it), reinstall with
302
+ `pip install "kaleido>=0.2,<1"`. Do **not** follow kaleido's own suggested fix
303
+ of `pip install -U kaleido` — that installs the incompatible version.
304
+ - **A saved plot or CSV doesn't open automatically, or you see "Could not open
305
+ file automatically."** This is expected on headless/SSH/Docker Linux systems
306
+ without `xdg-open`, or if no default application is registered for the file
307
+ type. The file is still saved correctly in both cases — only the auto-open
308
+ convenience step failed.
309
+ - **The file/folder picker dialog does nothing — no window appears, the prompt
310
+ just returns immediately.** Usually means `tkinter` isn't installed (common on
311
+ minimal Linux images — see *System requirements* above), or you're in an SSH
312
+ session without X11 forwarding / a display. Paste a file path directly, or
313
+ add `-X` to your SSH command.
314
+ - **Logo plots say `Can't find the 'weblogo' executable`.** `pip install` puts
315
+ the `weblogo` script in a directory that may not be on `PATH` — e.g.
316
+ `~/.local/bin` on Linux (user installs) or `Scripts\` inside a Windows venv.
317
+ Activate your venv, or add that directory to `PATH`.
318
+ - **SVG logo output comes out as PDF instead.** SVG requires the external
319
+ `pdf2svg` binary (see *System requirements* above); without it, RNA_lexis
320
+ silently falls back to PDF and prints a note explaining why.
321
+ - **A `UserWarning: Unable to import Axes3D... multiple versions of Matplotlib`
322
+ appears on every plot.** Harmless — it means both a system package (e.g.
323
+ `apt`'s `python3-matplotlib`) and a pip-installed `matplotlib` are present.
324
+ Plotting still works; to silence it, remove one of the two installations.
325
+ - **Menu colors show up as garbled text like `[1;36m`, and the screen doesn't
326
+ clear between menus.** Your terminal isn't interpreting ANSI/VT100 escape
327
+ codes — typical of legacy Windows `cmd.exe`. Use Windows Terminal or
328
+ PowerShell 7+ instead.
329
+ - **Can't overwrite the summary CSV on Windows — `PermissionError`.** The file
330
+ is usually open in Excel. RNA_lexis will try to close it automatically via
331
+ `pywin32` (installed automatically on Windows); if that fails, close the
332
+ workbook manually and retry.
333
+
334
+ ## Updating the documentation
335
+
336
+ After editing `docs/user_guide.md`, regenerate the checked-in HTML/PDF
337
+ snapshots before committing:
338
+
339
+ ```
340
+ python docs/build_docs.py
341
+ ```
342
+
343
+ (The HTML also regenerates itself automatically any time a user opens it
344
+ from the app's *Open User Guide* menu item — this script exists mainly to
345
+ keep the PDF, which has no built-in refresh path, from going stale.)
346
+
347
+ ## Authors
348
+
349
+ Haim Bar (haim.bar@uconn.edu) and Assaf Bester (bestera@technion.ac.il)
350
+
351
+ ## License
352
+
353
+ MIT