seedmatch 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.
- seedmatch-0.1.0/LICENSE +22 -0
- seedmatch-0.1.0/PKG-INFO +367 -0
- seedmatch-0.1.0/README.md +349 -0
- seedmatch-0.1.0/pyproject.toml +157 -0
- seedmatch-0.1.0/rust/Cargo.lock +228 -0
- seedmatch-0.1.0/rust/Cargo.toml +23 -0
- seedmatch-0.1.0/rust/src/hamming.rs +109 -0
- seedmatch-0.1.0/rust/src/indel.rs +282 -0
- seedmatch-0.1.0/rust/src/kernels.rs +197 -0
- seedmatch-0.1.0/rust/src/letters.rs +81 -0
- seedmatch-0.1.0/rust/src/lib.rs +23 -0
- seedmatch-0.1.0/rust/src/python.rs +143 -0
- seedmatch-0.1.0/rust/tests/common/mod.rs +101 -0
- seedmatch-0.1.0/rust/tests/hamming_paths.rs +66 -0
- seedmatch-0.1.0/rust/tests/indel_paths.rs +121 -0
- seedmatch-0.1.0/rust-toolchain.toml +4 -0
- seedmatch-0.1.0/src/seedmatch/__init__.py +148 -0
- seedmatch-0.1.0/src/seedmatch/_checks.py +388 -0
- seedmatch-0.1.0/src/seedmatch/_frames.py +35 -0
- seedmatch-0.1.0/src/seedmatch/_io.py +176 -0
- seedmatch-0.1.0/src/seedmatch/_lines.py +209 -0
- seedmatch-0.1.0/src/seedmatch/_pool.py +41 -0
- seedmatch-0.1.0/src/seedmatch/_rmath.py +83 -0
- seedmatch-0.1.0/src/seedmatch/alignment.py +129 -0
- seedmatch-0.1.0/src/seedmatch/annotation/__init__.py +21 -0
- seedmatch-0.1.0/src/seedmatch/annotation/ensdb.py +516 -0
- seedmatch-0.1.0/src/seedmatch/annotation/extract.py +97 -0
- seedmatch-0.1.0/src/seedmatch/annotation/fasta_genome.py +463 -0
- seedmatch-0.1.0/src/seedmatch/annotation/features.py +335 -0
- seedmatch-0.1.0/src/seedmatch/annotation/filters.py +107 -0
- seedmatch-0.1.0/src/seedmatch/annotation/genome.py +123 -0
- seedmatch-0.1.0/src/seedmatch/annotation/genome_file.py +37 -0
- seedmatch-0.1.0/src/seedmatch/annotation/gtf.py +443 -0
- seedmatch-0.1.0/src/seedmatch/annotation/reference.py +212 -0
- seedmatch-0.1.0/src/seedmatch/annotation/twobit.py +173 -0
- seedmatch-0.1.0/src/seedmatch/de.py +175 -0
- seedmatch-0.1.0/src/seedmatch/distances.py +107 -0
- seedmatch-0.1.0/src/seedmatch/divergences.md +936 -0
- seedmatch-0.1.0/src/seedmatch/errors.py +33 -0
- seedmatch-0.1.0/src/seedmatch/evalue.py +261 -0
- seedmatch-0.1.0/src/seedmatch/fetch/__init__.py +14 -0
- seedmatch-0.1.0/src/seedmatch/fetch/__main__.py +5 -0
- seedmatch-0.1.0/src/seedmatch/fetch/cli.py +134 -0
- seedmatch-0.1.0/src/seedmatch/fetch/download.py +328 -0
- seedmatch-0.1.0/src/seedmatch/fetch/http.py +99 -0
- seedmatch-0.1.0/src/seedmatch/guide.md +159 -0
- seedmatch-0.1.0/src/seedmatch/kmers.py +283 -0
- seedmatch-0.1.0/src/seedmatch/mirdb.py +190 -0
- seedmatch-0.1.0/src/seedmatch/network/__init__.py +22 -0
- seedmatch-0.1.0/src/seedmatch/network/messages.py +65 -0
- seedmatch-0.1.0/src/seedmatch/network/stringdb.py +587 -0
- seedmatch-0.1.0/src/seedmatch/network/trrust.py +252 -0
- seedmatch-0.1.0/src/seedmatch/noncanonical/__init__.py +20 -0
- seedmatch-0.1.0/src/seedmatch/noncanonical/compensatory.py +381 -0
- seedmatch-0.1.0/src/seedmatch/noncanonical/wobble.py +342 -0
- seedmatch-0.1.0/src/seedmatch/plot/__init__.py +29 -0
- seedmatch-0.1.0/src/seedmatch/plot/_style.py +303 -0
- seedmatch-0.1.0/src/seedmatch/plot/alignment.py +68 -0
- seedmatch-0.1.0/src/seedmatch/plot/benchmark.py +148 -0
- seedmatch-0.1.0/src/seedmatch/plot/ecdf.py +212 -0
- seedmatch-0.1.0/src/seedmatch/plot/kmers.py +98 -0
- seedmatch-0.1.0/src/seedmatch/plot/ranges.py +144 -0
- seedmatch-0.1.0/src/seedmatch/plot/wasserstein.py +176 -0
- seedmatch-0.1.0/src/seedmatch/py.typed +0 -0
- seedmatch-0.1.0/src/seedmatch/r-map.md +885 -0
- seedmatch-0.1.0/src/seedmatch/report/__init__.py +35 -0
- seedmatch-0.1.0/src/seedmatch/report/annotate.py +109 -0
- seedmatch-0.1.0/src/seedmatch/report/grid.py +327 -0
- seedmatch-0.1.0/src/seedmatch/report/html.py +179 -0
- seedmatch-0.1.0/src/seedmatch/report/report.py +167 -0
- seedmatch-0.1.0/src/seedmatch/resources/__init__.py +12 -0
- seedmatch-0.1.0/src/seedmatch/resources/registry.py +304 -0
- seedmatch-0.1.0/src/seedmatch/search/__init__.py +11 -0
- seedmatch-0.1.0/src/seedmatch/search/_kernels.pyi +37 -0
- seedmatch-0.1.0/src/seedmatch/search/api.py +182 -0
- seedmatch-0.1.0/src/seedmatch/search/compat.py +35 -0
- seedmatch-0.1.0/src/seedmatch/seed.py +183 -0
- seedmatch-0.1.0/src/seedmatch/sequence/__init__.py +7 -0
- seedmatch-0.1.0/src/seedmatch/sequence/alphabet.py +137 -0
- seedmatch-0.1.0/src/seedmatch/sequence/fasta.py +131 -0
- seedmatch-0.1.0/src/seedmatch/sequence/sequence_set.py +120 -0
- seedmatch-0.1.0/src/seedmatch/stats/__init__.py +32 -0
- seedmatch-0.1.0/src/seedmatch/stats/benchmark.py +85 -0
- seedmatch-0.1.0/src/seedmatch/stats/curves.py +284 -0
- seedmatch-0.1.0/src/seedmatch/stats/density.py +77 -0
- seedmatch-0.1.0/src/seedmatch/stats/dts.py +114 -0
- seedmatch-0.1.0/src/seedmatch/stats/ecdf.py +305 -0
- seedmatch-0.1.0/src/seedmatch/stats/ks.py +117 -0
- seedmatch-0.1.0/src/seedmatch/stats/types.py +129 -0
- seedmatch-0.1.0/src/seedmatch/stats/wasserstein.py +244 -0
- seedmatch-0.1.0/src/seedmatch/stats/wilcoxon.py +138 -0
seedmatch-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inflexa, Inc.
|
|
4
|
+
Copyright (c) 2025 Eli Lilly and Company
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
seedmatch-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: seedmatch
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Requires-Dist: numpy>=2.0
|
|
5
|
+
Requires-Dist: pandas>=2.2
|
|
6
|
+
Requires-Dist: scipy>=1.14
|
|
7
|
+
Requires-Dist: matplotlib>=3.8 ; extra == 'plot'
|
|
8
|
+
Provides-Extra: plot
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Summary: Agent-sandbox-ready Python port of SeedMatchR: seed matches of an siRNA guide strand and their effect on differential expression.
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
Requires-Python: >=3.12
|
|
13
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
14
|
+
Project-URL: Changelog, https://github.com/inflexa-ai/seedmatch/releases
|
|
15
|
+
Project-URL: Homepage, https://github.com/inflexa-ai/seedmatch
|
|
16
|
+
Project-URL: Issues, https://github.com/inflexa-ai/seedmatch/issues
|
|
17
|
+
|
|
18
|
+
# seedmatch
|
|
19
|
+
|
|
20
|
+
[](https://github.com/inflexa-ai/seedmatch/actions/workflows/test.yml)
|
|
21
|
+
[](https://scorecard.dev/viewer/?uri=github.com/inflexa-ai/seedmatch)
|
|
22
|
+
[](https://github.com/inflexa-ai/seedmatch/blob/main/LICENSE)
|
|
23
|
+
|
|
24
|
+
seedmatch is a Python port of the R package [SeedMatchR](https://github.com/tacazares/SeedMatchR), ready for AI agent sandboxes. It finds the seed matches of an siRNA guide strand in transcript sequences. It then joins the matches with the results of a differential expression (DE) analysis. Thus you can see which genes with a seed match go down.
|
|
25
|
+
|
|
26
|
+
The output is the same as the output of SeedMatchR on the core paths. R golden files in `tests/golden/` keep this true. The installed package holds these documents, and `importlib.resources.files("seedmatch").joinpath(name).read_text()` reads each one without network:
|
|
27
|
+
|
|
28
|
+
- [`guide.md`](https://github.com/inflexa-ai/seedmatch/blob/main/src/seedmatch/guide.md): the options, the limits, and the edge cases of each function.
|
|
29
|
+
- [`r-map.md`](https://github.com/inflexa-ai/seedmatch/blob/main/src/seedmatch/r-map.md): the Python name of each R function, and the changes of the arguments.
|
|
30
|
+
- [`divergences.md`](https://github.com/inflexa-ai/seedmatch/blob/main/src/seedmatch/divergences.md): each change of behavior from R, with its ID `D-NNN`.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Python 3.12 or later is necessary. Install seedmatch from PyPI:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv pip install seedmatch
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
To draw the figures of `seedmatch.plot`, install the extra `plot`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv pip install "seedmatch[plot]"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
PyPI has a wheel for Linux x86_64 and Linux aarch64 (glibc 2.28 or later), and for macOS arm64. On a different platform, the install builds the Rust extension from the sdist. To install the code of `main`, use `uv pip install git+https://github.com/inflexa-ai/seedmatch.git`. A build from the source needs [rustup](https://rustup.rs) and a C linker. [`CONTRIBUTING.md`](https://github.com/inflexa-ai/seedmatch/blob/main/CONTRIBUTING.md) gives the setup of the build.
|
|
47
|
+
|
|
48
|
+
## A part of an agentic toolchain for bioinformatics
|
|
49
|
+
|
|
50
|
+
Inflexa, Inc. builds an agentic toolchain for bioinformatics. The toolchain ports existing tools to languages and architectures that an agent sandbox can run. An example of such a sandbox is the sandbox of [Inflexa](https://github.com/inflexa-ai/inflexa). seedmatch is a tool of this toolchain.
|
|
51
|
+
|
|
52
|
+
A sandbox such as the Inflexa sandbox has no network egress, and an agent corrects its calls from the error messages. Thus seedmatch obeys these rules:
|
|
53
|
+
|
|
54
|
+
- **No network in the core.** The core modules never use the network. Each function reads its input from a path or an object that you give. The separate module `seedmatch.fetch` downloads the resources (see [Resources](#resources)).
|
|
55
|
+
- **No R and no system library.** The package is Python on numpy, pandas, and scipy, with a compiled extension for the search kernels. It does not use R or a system library. The extra `plot` adds matplotlib.
|
|
56
|
+
- **Errors that an agent can use.** Each `InputError` names the bad value and the expected value. Thus an agent can correct the call. Each error class that seedmatch defines is a `SeedMatchError`, and `InputError` is also a `ValueError`. If a file does not exist, the function raises `FileNotFoundError`.
|
|
57
|
+
|
|
58
|
+
## Example
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from seedmatch import (
|
|
62
|
+
Guide,
|
|
63
|
+
SearchOptions,
|
|
64
|
+
Seed,
|
|
65
|
+
annotate_seed_counts,
|
|
66
|
+
count_matches,
|
|
67
|
+
filter_de,
|
|
68
|
+
find_matches,
|
|
69
|
+
read_deseq2_table,
|
|
70
|
+
read_fasta,
|
|
71
|
+
seed_match_report,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# The ID of each FASTA record is the gene ID of its sequence.
|
|
75
|
+
sequences = read_fasta("transcripts.fa")
|
|
76
|
+
|
|
77
|
+
# The guide strand, 5' to 3'. The target is the DNA site that the seed pairs with.
|
|
78
|
+
guide = Guide("UUAUAGAGCAAGAACACUGUUUU")
|
|
79
|
+
target = guide.target(Seed.MER7M8)
|
|
80
|
+
|
|
81
|
+
# The number of matches in each sequence, and the 1-based range of each match.
|
|
82
|
+
counts = count_matches(target, sequences)
|
|
83
|
+
ranges = find_matches(target, sequences, SearchOptions(max_mismatch=1))
|
|
84
|
+
|
|
85
|
+
# A DESeq2 table with 8 columns, filtered as filter_res does it in R.
|
|
86
|
+
de = filter_de(read_deseq2_table("deseq2_results.tsv"))
|
|
87
|
+
|
|
88
|
+
# Add the column "mer7m8": the count of the seed matches of each gene.
|
|
89
|
+
de = annotate_seed_counts(de, sequences, target)
|
|
90
|
+
|
|
91
|
+
# The SeedMatchReport of R: the genes of each match class, and the off-targets among them.
|
|
92
|
+
report = seed_match_report(de, sequences, guide)
|
|
93
|
+
summary = report.report
|
|
94
|
+
matches = report.matches
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`ecdf_test` compares the `log2FoldChange` values of two gene sets. This example compares the genes with a seed match to the genes without a match. With the default KS test, a small p-value shows that the genes with a seed match go down.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from seedmatch import ecdf_test
|
|
101
|
+
|
|
102
|
+
# The genes with a seed match, and the genes without a match.
|
|
103
|
+
seed_genes = de.loc[de["mer7m8"] >= 1, "gene_id"]
|
|
104
|
+
background = de.loc[de["mer7m8"] == 0, "gene_id"]
|
|
105
|
+
|
|
106
|
+
# The KS test of R. The default alternative is GREATER, as in R.
|
|
107
|
+
ecdf_result = ecdf_test(de, target=seed_genes, background=background)
|
|
108
|
+
print(ecdf_result.statistic, ecdf_result.p_value)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
To get the sequences from an annotation, open a `Reference`. A `Reference` joins an EnsDb file and a genome file of the same build.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from seedmatch import FeatureType, Reference, count_matches
|
|
115
|
+
|
|
116
|
+
with Reference.from_paths(ensdb="ensdb.sqlite", genome="genome.2bit") as ref:
|
|
117
|
+
# The 3' UTR of each canonical protein-coding transcript.
|
|
118
|
+
# The ID of a sequence is its transcript ID.
|
|
119
|
+
utr3 = ref.sequences(FeatureType.UTR3)
|
|
120
|
+
|
|
121
|
+
# The number of seed matches in each 3' UTR, with the target of the example above.
|
|
122
|
+
utr3_counts = count_matches(target, utr3)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Other analyses
|
|
126
|
+
|
|
127
|
+
Each example uses the objects of the examples above. [`guide.md`](https://github.com/inflexa-ai/seedmatch/blob/main/src/seedmatch/guide.md) gives the options and the edge cases of each function.
|
|
128
|
+
|
|
129
|
+
`kmer_counts` counts the k-mers of each sequence, and `kmer_gene_counts` gives the number of genes that have each k-mer.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from seedmatch import kmer_counts, kmer_gene_counts
|
|
133
|
+
|
|
134
|
+
# The 7-mers of the sequences. The default k is 7, the default of R.
|
|
135
|
+
kmers = kmer_counts(sequences)
|
|
136
|
+
|
|
137
|
+
# The number of genes with each 7-mer, as a Series. The index is the 7-mer.
|
|
138
|
+
genes_with_kmer = kmer_gene_counts(kmers)
|
|
139
|
+
|
|
140
|
+
# The number of genes that have the 7-mer of the target.
|
|
141
|
+
print(genes_with_kmer[target.sequence])
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
`alignment_text` shows how the guide pairs with the sequence at one match.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from seedmatch import alignment_text
|
|
148
|
+
|
|
149
|
+
# The three lines: the guide, the pairs, and the sequence. The default seed is Seed.MER7M8.
|
|
150
|
+
alignment = alignment_text(find_matches(target, sequences).iloc[0], guide, sequences)
|
|
151
|
+
print(alignment)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`match_distances` gives the distance between each pair of matches in one sequence.
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from seedmatch import match_distances
|
|
158
|
+
|
|
159
|
+
# One row for each pair of matches in a sequence. A sequence with one match has no row (D-011).
|
|
160
|
+
distances = match_distances(find_matches(guide.target(Seed.MER6), sequences))
|
|
161
|
+
print(distances.head())
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`e_values` gives the e-value of the seed count of each gene against a null of shuffled guides from `e_value_null`.
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from seedmatch import e_value_null, e_values
|
|
168
|
+
|
|
169
|
+
# The null: the seed count of each gene for each of 100 shuffles of the guide.
|
|
170
|
+
null = e_value_null(guide, sequences, rng=1, n_random=100)
|
|
171
|
+
|
|
172
|
+
# The e-value of the column "mer7m8". A small e-value shows a count that shuffles rarely reach.
|
|
173
|
+
scored = e_values(de, null, column="mer7m8")
|
|
174
|
+
print(scored[["gene_id", "mer7m8", "e_value"]].head())
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`benchmark_predictions` scores the seed counts against a gold standard of genes that go down.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from seedmatch import benchmark_predictions
|
|
181
|
+
|
|
182
|
+
# The scores are the seed counts of the column "mer7m8". The cutoffs are the R defaults: 0.15 and 0.
|
|
183
|
+
benchmark = benchmark_predictions(de)
|
|
184
|
+
print(benchmark.pr.auc_integral, benchmark.roc.auc)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`read_mirdb` reads the miRDB table of predicted miRNA targets. This example keeps the rows of the rat, which has the species code `rno`.
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from seedmatch import read_mirdb
|
|
191
|
+
|
|
192
|
+
# The columns: mirdb_id, target_refseq_id, target_score, species, and mirna_name.
|
|
193
|
+
rat_targets = read_mirdb("miRDB_v6.0_prediction_result.txt.gz", species="rno")
|
|
194
|
+
print(rat_targets.head())
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`wobble_bulge_matches` finds the sites that have G:U pairs or a bulge in the seed region.
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from seedmatch import annotate_wobble_bulge_counts, wobble_bulge_matches
|
|
201
|
+
|
|
202
|
+
# One row for each distinct start of a site, with the place and the size of its bulge.
|
|
203
|
+
wobble_matches = wobble_bulge_matches(guide, sequences)
|
|
204
|
+
print(wobble_matches.head())
|
|
205
|
+
|
|
206
|
+
# The column "overall_matches": for each gene, the largest number of rows of one of its sequences (D-003).
|
|
207
|
+
wobble_de = annotate_wobble_bulge_counts(de, sequences, guide)
|
|
208
|
+
print(wobble_de[["gene_id", "overall_matches"]].head())
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`compensatory_sites` finds the sites with a seed match and a second region of the guide that pairs with the sequence before the match.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from seedmatch import compensatory_sites, ecdf_test
|
|
215
|
+
|
|
216
|
+
# One row for each pair of a seed match and a region of one sequence.
|
|
217
|
+
sites = compensatory_sites(guide, sequences)
|
|
218
|
+
print(sites.head())
|
|
219
|
+
|
|
220
|
+
# As in the R vignette: the genes with a site against the other genes of the DE table.
|
|
221
|
+
site_genes = sites["gene_id"].unique()
|
|
222
|
+
other_genes = de.loc[~de["gene_id"].isin(site_genes), "gene_id"]
|
|
223
|
+
site_result = ecdf_test(de, target=site_genes, background=other_genes)
|
|
224
|
+
print(site_result.p_value)
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`read_trrust` reads the TRRUST table of regulators and their targets. `trrust_scores` gives each gene of the table a repression score and an activation score.
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from seedmatch import read_trrust, trrust_scores
|
|
231
|
+
|
|
232
|
+
# The columns: source, target, edge_type, and evidence.
|
|
233
|
+
trrust = read_trrust("trrust_rawdata.human.tsv")
|
|
234
|
+
|
|
235
|
+
# TRRUST names a gene by its symbol, not by its Ensembl gene ID.
|
|
236
|
+
# Replace the symbols of the example with the symbols of your seed genes.
|
|
237
|
+
trrust_result = trrust_scores(trrust, ["TFA", "GC", "TFC"])
|
|
238
|
+
print(trrust_result.head())
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
`read_string_links` reads the STRING protein links. `string_gene_network` maps the proteins to genes, and `string_scores` gives each gene of the network a score.
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
import pandas as pd
|
|
245
|
+
|
|
246
|
+
from seedmatch import Reference, read_string_links, string_gene_network, string_scores
|
|
247
|
+
|
|
248
|
+
# The links with a score of 400 or more, and then the links above the 95th percentile of these scores.
|
|
249
|
+
links = read_string_links("10116.protein.links.v12.5.txt.gz")
|
|
250
|
+
|
|
251
|
+
# The EnsDb of the same species and build gives the gene of each protein.
|
|
252
|
+
with Reference.from_paths(ensdb="ensdb.sqlite", genome="genome.2bit") as ref:
|
|
253
|
+
network = string_gene_network(links.links, ref)
|
|
254
|
+
|
|
255
|
+
# The seed count of each 3' UTR, with the gene ID of the UTR. A gene with more than one row keeps the highest count (D-062).
|
|
256
|
+
utr3_de = pd.DataFrame({"gene_id": utr3.gene_ids, "mer7m8": utr3_counts})
|
|
257
|
+
string_result = string_scores(network.edges, utr3_de, column="mer7m8")
|
|
258
|
+
print(string_result.head())
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Plots and the HTML report
|
|
262
|
+
|
|
263
|
+
The functions of `seedmatch.plot` work only with the extra `plot`. A plot function returns a `matplotlib.figure.Figure`, and `report_html` returns the report table as HTML.
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from pathlib import Path
|
|
267
|
+
|
|
268
|
+
from seedmatch import report_html
|
|
269
|
+
from seedmatch.plot import (
|
|
270
|
+
plot_alignment,
|
|
271
|
+
plot_benchmark,
|
|
272
|
+
plot_ecdf,
|
|
273
|
+
plot_kmer_histogram,
|
|
274
|
+
plot_ranges,
|
|
275
|
+
plot_wasserstein,
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
# The ECDF of the two gene sets of the ecdf_test example, with the result of the test.
|
|
279
|
+
ecdf_figure = plot_ecdf(de, {"Background": background, "mer7m8": seed_genes}, ecdf_result)
|
|
280
|
+
ecdf_figure.savefig("ecdf.png", dpi=300)
|
|
281
|
+
|
|
282
|
+
# The density, the ECDF, and the ECDF difference of the Wasserstein areas.
|
|
283
|
+
wasserstein_figure = plot_wasserstein(
|
|
284
|
+
de.loc[de["mer7m8"] >= 1, "log2FoldChange"], de.loc[de["mer7m8"] == 0, "log2FoldChange"]
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# The number of genes with each 7-mer, with a line at the target.
|
|
288
|
+
kmer_figure = plot_kmer_histogram(genes_with_kmer, target.sequence)
|
|
289
|
+
|
|
290
|
+
# The alignment text of the example above.
|
|
291
|
+
alignment_figure = plot_alignment(alignment)
|
|
292
|
+
|
|
293
|
+
# One bar for each match range of the first example.
|
|
294
|
+
ranges_figure = plot_ranges(ranges)
|
|
295
|
+
|
|
296
|
+
# The PR curve and the ROC curve of the benchmark example.
|
|
297
|
+
benchmark_figure = plot_benchmark(benchmark)
|
|
298
|
+
|
|
299
|
+
# The SeedMatchReport table as HTML.
|
|
300
|
+
Path("report.html").write_text(report_html(report, guide), encoding="utf-8")
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Resources
|
|
304
|
+
|
|
305
|
+
The sandbox of an agent has no network access. Thus a machine with network access runs `seedmatch-fetch`, and the sandbox reads the files from a path. The registry in `seedmatch.resources` pins the URL, the size, and the SHA-256 digest of each file.
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
# The 2bit file and the EnsDb file of one genome build.
|
|
309
|
+
seedmatch-fetch reference rnor7 refs/rnor7
|
|
310
|
+
|
|
311
|
+
# The DESeq2 tables of the siRNA example (GEO series GSE184929).
|
|
312
|
+
seedmatch-fetch example sirna data/sirna
|
|
313
|
+
|
|
314
|
+
# The miRDB v6.0 predictions.
|
|
315
|
+
seedmatch-fetch mirdb data/mirdb
|
|
316
|
+
|
|
317
|
+
# The TRRUST table of human or mouse.
|
|
318
|
+
seedmatch-fetch trrust human data/trrust
|
|
319
|
+
|
|
320
|
+
# The STRING protein links of one NCBI taxon.
|
|
321
|
+
seedmatch-fetch string 10116 data/string
|
|
322
|
+
|
|
323
|
+
# One line for each file: the group, the key, the file name, the size in bytes, and the description.
|
|
324
|
+
seedmatch-fetch list
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
[`guide.md`](https://github.com/inflexa-ai/seedmatch/blob/main/src/seedmatch/guide.md) gives the output and the exit status of the command, and the Python API of the registry.
|
|
328
|
+
|
|
329
|
+
## Differences from SeedMatchR
|
|
330
|
+
|
|
331
|
+
seedmatch corrects the defects of SeedMatchR that it finds. These changes are the most important for a user:
|
|
332
|
+
|
|
333
|
+
- The ranges of a search obey the same rules as the counts. In R, `vmatchPattern2` uses the indel algorithm also when `with.indels` is `FALSE`, if the pattern is longer than `max.mismatch`. Thus the ranges and the counts do not agree (D-001).
|
|
334
|
+
- A result for a gene uses all the sequences of the gene. R uses the first sequence for the seed count, and it counts each sequence in the report (D-003).
|
|
335
|
+
- `full_search_ranges` gives a result for each input. R stops if each search finds a match, or if no search finds a match (D-022).
|
|
336
|
+
- `wobble=True` with `fixed_pattern=True` raises `InputError`, because a fixed pattern matches the wobble letter R only to the letter R (D-026).
|
|
337
|
+
- A sequence from an annotation keeps its transcript ID and its gene ID. In R, `load_annotations` gives the name `NA` to each sequence of a gene union (D-002), and `tx.names` is `NULL` (D-009).
|
|
338
|
+
- `ecdf_test` drops the rows without a fold change for each test. R drops them for the KS and Wilcoxon tests only, and it stops for DTS and Wasserstein (D-036). `ecdf_test` raises `InputError` for an `alternative` with DTS or Wasserstein, but R ignores it without a message (D-035).
|
|
339
|
+
- `kmer_gene_counts` counts the genes with a k-mer. The histogram of R counts the sequences, but its label says genes (D-042).
|
|
340
|
+
- `benchmark_predictions` applies the `padj` cutoff. In R, `padj <= padj` compares the column with itself, thus each row with a `padj` passes. R also gives the labels to the ROC curve as the scores of the negative class (D-006).
|
|
341
|
+
- `alignment_text` shows the full guide, from g1 to the last base. In R, the guide line of `plotAlignment` has no g1, and the function stops for the default positions (D-045).
|
|
342
|
+
- The wobble and bulge search runs. In R, each call of `run_wobble_bulges_pipeline` stops with an error. The port counts each distinct start of a site one time, and a bulge is a run of extra target bases (D-005).
|
|
343
|
+
- The 3' compensatory search runs. R returns 0 rows for each input. Without the early return, its code stops at the first site. The port gives each pair of a seed match and a region (D-004).
|
|
344
|
+
- `trrust_scores` takes the messages of a gene from its regulators. R takes them from the targets of the gene (D-007).
|
|
345
|
+
- `plot_ecdf` gives a figure for each p-value, and its legend counts the values of each line. R stops for a p-value of 0.01, and its legend counts the gene lists (D-063, D-064).
|
|
346
|
+
- An input that R accepts in silence, but that gives a wrong result, raises `InputError`. The message gives the bad value. Examples are a gap letter in a sequence (D-017), a DESeq2 table with the wrong columns (D-021), and a NaN cutoff (D-024).
|
|
347
|
+
|
|
348
|
+
## Performance
|
|
349
|
+
|
|
350
|
+
seedmatch is faster than SeedMatchR, and its process uses less memory. The table gives the values of `seed_match_report` with the default options, on the canonical 3' UTRs of the rat genome build `rnor7`. This input has 18,614 sequences and 17,913,962 bases. The machine is an Apple M2 Max with 12 CPUs. Each run makes three calls in one process, and a cell gives the range of two runs. SeedMatchR uses one thread.
|
|
351
|
+
|
|
352
|
+
| Measure | seedmatch, all CPUs | seedmatch, 1 thread | SeedMatchR |
|
|
353
|
+
|---|---|---|---|
|
|
354
|
+
| Time of one call | 0.18 to 0.20 s | 1.19 to 1.22 s | 9.32 to 9.63 s |
|
|
355
|
+
| Speedup over SeedMatchR | 47× to 54× | 7.6× to 8.1× | 1× |
|
|
356
|
+
| Peak resident memory of the process | 137 to 140 MiB | 135 to 136 MiB | 432 to 443 MiB |
|
|
357
|
+
|
|
358
|
+
[`docs/performance.md`](https://github.com/inflexa-ai/seedmatch/blob/main/docs/performance.md) gives the versions, the commands that measure these values, and the time of each search of `full_search`.
|
|
359
|
+
|
|
360
|
+
## Development
|
|
361
|
+
|
|
362
|
+
[`CONTRIBUTING.md`](https://github.com/inflexa-ai/seedmatch/blob/main/CONTRIBUTING.md) gives the setup, the checks, and the rules for a contribution. To report a security problem, obey [`SECURITY.md`](https://github.com/inflexa-ai/seedmatch/blob/main/SECURITY.md).
|
|
363
|
+
|
|
364
|
+
## License
|
|
365
|
+
|
|
366
|
+
seedmatch uses the MIT License, the same license as SeedMatchR. See [`LICENSE`](https://github.com/inflexa-ai/seedmatch/blob/main/LICENSE).
|
|
367
|
+
|