API reference¶
sioff ¶
siOFF: siRNA off-target discovery pipeline.
The package exposes four in-memory functions, re-exported from sioff.api:
off_targets (intersect RIsearch predictions with a transcriptome, add
accessibility penalties and compute off-target probabilities),
accessibility (per-chromosome opening-energy profiles), index
(build a RIsearch index) and search (run RIsearch and return the hits).
They return Polars DataFrames (or a Path for index), write
no files and raise ordinary Python exceptions; the sioff command line is a
file-writing wrapper over the same core. __version__ reports the installed
distribution version.
accessibility ¶
accessibility(
genome: Union[str, Path],
window_size: int = 80,
max_span: int = 40,
unpaired_prob: int = 30,
temperature: float = 37.0,
strand: str = "both",
) -> dict[str, pl.DataFrame]
Compute per-chromosome accessibility profiles in memory.
Folds every sequence in genome with ViennaRNA (local folding, both
strands unless strand="+") and returns the opening-energy profiles in the same schema the
sioff accessibility command streams to {chrom}.accessibility.parquet.
Writes no files. The result is the accessibility argument of
off_targets. Every profile stays resident at once, so for
genome-scale inputs the CLI's streaming path (then accessibility_dir) is
the cheaper route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genome
|
str or Path
|
Genome or transcriptome FASTA; one profile is produced per record.
CLI: |
required |
window_size
|
int
|
Local-folding window size |
80
|
max_span
|
int
|
Maximum base-pair span |
40
|
unpaired_prob
|
int
|
Length |
30
|
temperature
|
float
|
Folding temperature in degrees Celsius. CLI: |
37.0
|
strand
|
(both, '+')
|
|
"both"
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Chromosome (FASTA record ID) to profile, in file order. Each frame has
the columns |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When genome does not exist. |
AccessibilityError
|
|
See Also
off_targets : Consumes the returned dict through its accessibility argument.
Examples:
>>> import sioff
>>> profiles = sioff.accessibility("genome.fa", unpaired_prob=30)
>>> profiles["chr1"].columns[:4]
['position', 'strand', 'u1', 'u2']
>>> df = sioff.off_targets(risearch_file="predictions.tsv", accessibility=profiles)
Source code in src/sioff/api.py
index ¶
Build (or reuse) a RIsearch index for a target FASTA.
Runs the in-process risearch indexer and returns the index location. An
existing index that is newer than target is reused as is; an outdated one
is rebuilt. The function returns a Path rather than data
because a RIsearch index is a binary on-disk artifact consumed by
search. Mirrors the sioff index command and, like it, requires
the external risearch package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str or Path
|
Target FASTA file to index. CLI: the |
required |
output
|
str or Path
|
Index path. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path of the (new or reused) index file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When target does not exist. |
RIsearchError
|
|
See Also
search : Query the returned index.
Examples:
>>> import sioff
>>> idx = sioff.index("target.fa")
>>> idx.name
'target.idx'
>>> hits = sioff.search("sirnas.fa", idx, target="target.fa")
Source code in src/sioff/api.py
off_targets ¶
off_targets(
risearch_file: Optional[Union[str, Path]] = None,
predictions: Optional[DataFrame] = None,
sirna_fasta: Optional[Union[str, Path]] = None,
target_fasta: Optional[Union[str, Path]] = None,
target_index: Optional[Union[str, Path]] = None,
gtf_file: Optional[Union[str, Path]] = None,
feature_type: Optional[str] = None,
expression_metric: str = "RPKM",
transcriptome_format: str = "auto",
accessibility: Optional[Mapping[str, DataFrame]] = None,
accessibility_dir: Optional[Union[str, Path]] = None,
accessibility_cache_dir: Optional[
Union[str, Path]
] = None,
genome_file: Optional[Union[str, Path]] = None,
window_size: int = 80,
max_span: int = 40,
unpaired_prob: int = 30,
temperature: float = 37.0,
matrix: Union[str, Path] = "t04",
sirna_table: Optional[Union[str, Path]] = None,
alpha: str = "1.0",
gamma: str = "1.0",
theta: str = "",
sense_only: bool = False,
predictions_type: str = "gw",
n_workers: int = 1,
detailed_report: bool = False,
stream: bool = False,
) -> Union[pl.DataFrame, Iterator[pl.DataFrame]]
Analyse siRNA off-target predictions, returning results in memory.
Intersects RIsearch predictions with a transcriptome annotation, adds an
accessibility (opening-energy) penalty, and computes partition-function
off-target probabilities. This is the in-memory counterpart of the
sioff off-targets command; the defaults reproduce its behaviour, and each
parameter below names its CLI flag.
Predictions come from exactly one of:
risearch_file: a predictions file, or a directory of them. Each file may hold one siRNA or many.predictions: an in-memorypolars.DataFramein thesearchschema (sirna_id, chrom, start, end, strand, energy), typically the value returned bysearch.sirna_fasta+target_fasta: run RIsearch in-process first (requires therisearchpackage).
Every form takes the same path: the predictions are split into one part
per siRNA, and each siRNA is scored on its own, in n_workers
processes. The result is one DataFrame, or with stream=True one
DataFrame per siRNA as each is scored.
The siRNA table (sirna_table) gives each siRNA its on-target and
its guide sequence. E_min, the reference energy of the alpha/gamma
clamp, is the lower of the siRNA's perfect-match energy (its sequence
searched against itself with matrix) and its strongest hit left after
sense_only and the intersection. Every alpha/gamma pair other than
(1, 1) needs it, so every siRNA with predictions then needs a table row.
Accessibility profiles come from at most one of accessibility (the
dict[chrom -> DataFrame] returned by accessibility),
accessibility_dir (the packed cache or per-chromosome Parquet files)
or genome_file (fold during the call). Without any profile source the
probabilities are computed from hybridisation energy alone.
Writes no output files and prints nothing. The in-process search builds
the index <target>.idx next to target_fasta when target_index
is omitted, and accessibility_dir gets its packed cache; temporary
files are removed before the call returns (with stream=True, when the
stream is exhausted or closed).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
risearch_file
|
str or Path
|
Pre-computed predictions: a file, or a directory of files. Read are
RIsearch2 output (plain or |
None
|
predictions
|
DataFrame
|
In-memory predictions in the |
None
|
sirna_fasta
|
str or Path
|
siRNA FASTA with one or more sequences and unique IDs, searched
in-process against |
None
|
target_fasta
|
str or Path
|
Target FASTA (genome or transcriptome) for the in-process RIsearch
run; required together with |
None
|
target_index
|
str or Path
|
Pre-built RIsearch index of |
None
|
gtf_file
|
str or Path
|
Transcriptome annotation (GTF or GFF3). Predictions are
intersected with its features, which adds |
None
|
feature_type
|
str
|
Feature type (column 3) of the annotation rows to use. Default:
|
None
|
expression_metric
|
str
|
Annotation attribute used as the expression score ( |
"RPKM"
|
transcriptome_format
|
str
|
One of |
"auto"
|
accessibility
|
dict[str, DataFrame]
|
In-memory accessibility profiles keyed by chromosome, each frame with
columns |
None
|
accessibility_dir
|
str or Path
|
The packed npy cache from |
None
|
accessibility_cache_dir
|
str or Path
|
Where the cache of |
None
|
genome_file
|
str or Path
|
Genome FASTA to fold during the call; the profiles go to a temporary
directory that is removed when the run ends. Refused with
|
None
|
window_size
|
int
|
Local-folding window size |
80
|
max_span
|
int
|
Maximum base-pair span |
40
|
unpaired_prob
|
int
|
Length |
30
|
temperature
|
float
|
Temperature in degrees Celsius of everything this run computes: the
|
37.0
|
matrix
|
str or Path
|
Energy parameter set for the in-process search and for the
perfect-match energies of E_min: a bundled id or the path of a DSM
TSV table. Use the set the predictions were searched with; E_min is
the reference energy of the alpha/gamma clamp. CLI: |
"t04"
|
sirna_table
|
str or Path
|
Tab-separated siRNA table with a header row: |
None
|
alpha
|
str
|
Alpha clamping parameter(s) as semicolon-separated floats, e.g.
|
"1.0"
|
gamma
|
str
|
Gamma clamping parameter(s), same format as |
"1.0"
|
theta
|
str
|
Theta scaling parameter(s) as semicolon-separated floats, e.g.
|
""
|
sense_only
|
bool
|
Keep only sense-strand ( |
False
|
predictions_type
|
str
|
|
"gw"
|
n_workers
|
int
|
Worker processes that split the inputs and score the siRNAs, one
siRNA per task, for every input form. A pool is started only when
more than one task can run at once. CLI: |
1
|
detailed_report
|
bool
|
Keep the raw |
False
|
stream
|
bool
|
Return a generator of one DataFrame per siRNA, in the order they are
scored, instead of one DataFrame. The worker pool and the temporary
files live as long as the generator: consume it fully, or close it
( |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame or Iterator[DataFrame]
|
One DataFrame holding every siRNA's rows (an empty DataFrame with no
columns when nothing was scored), or with |
Raises:
| Type | Description |
|---|---|
ValueError
|
When no predictions source is given; when an argument would go
unused: |
FileNotFoundError
|
When |
RIsearchError
|
|
AccessibilityError
|
|
WorkerFailureError
|
|
See Also
search : Produce a predictions frame in the schema this function accepts.
accessibility : Produce the in-memory accessibility profiles.
Examples:
A predictions file with annotation, pre-computed accessibility, a siRNA table and an alpha sweep:
>>> import sioff
>>> df = sioff.off_targets(
... risearch_file="predictions.tsv",
... gtf_file="annotation.gtf",
... accessibility_dir="accessibility/",
... sirna_table="sirna_table.tsv",
... alpha="0.8;1.0",
... gamma="1.0",
... )
>>> df.select("sirna_id", "transcript_id", "P_off_target").head()
A directory of per-siRNA files, consumed as a stream and torn down promptly:
>>> import contextlib
>>> gen = sioff.off_targets(risearch_file="predictions/", n_workers=8, stream=True)
>>> with contextlib.closing(gen) as frames:
... for frame in frames:
... print(frame["sirna_id"][0], frame.height)
Source code in src/sioff/api.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
search ¶
search(
query: Union[str, Path],
index: Union[str, Path],
target: Optional[Union[str, Path]] = None,
seed_length: int = 6,
max_extension: int = 20,
energy_threshold: float = -10.0,
seed_start: Optional[int] = None,
seed_end: Optional[int] = None,
seed_wobble: bool = True,
matrix: Union[str, Path] = "t04",
mismatches: int = 0,
mismatch_prefix: int = 1,
mismatch_suffix: int = 0,
temperature: int = 37,
penalty: float = 0.0,
seed_energy: float = 0.0,
no_max_prune: bool = False,
no_dedup: bool = False,
alignment: bool = False,
threads: Optional[int] = None,
sense_only: bool = False,
) -> pl.DataFrame
Run a RIsearch search and return the hits as a DataFrame.
Searches every sequence in query against a RIsearch index in-process
(no subprocess, no intermediate file) and returns the hits in the schema
off_targets accepts through its predictions argument. Mirrors
the sioff search command; the defaults reproduce its behaviour, and the
function requires the external risearch package.
seed_start / seed_end / seed_length are the RIsearch2
-s n:m/l seed specification and seed_wobble=False is
--noGUseed; both affect where seeds may be placed, not the energy
model. matrix (-z) selects the nearest-neighbour parameter set: a
bundled id (see sioff.services.risearch_service.VALID_DSM_IDS for
the models risearch ships) or, given a path, a custom long-form DSM TSV
table. Every other risearch.search option is passed through too, each
with siOFF's own default, so an upstream default change cannot move the
results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str or Path
|
Query siRNA FASTA. CLI: the |
required |
index
|
str or Path
|
RIsearch index built by |
required |
target
|
str or Path
|
FASTA the index was built from, used to map RIsearch's integer target
indices back to sequence names. Optional in the signature, but required
in practice through this function: the name registry that could resolve
it lives in a service instance this call does not keep, so omitting it
raises |
None
|
seed_length
|
int
|
Seed length |
6
|
max_extension
|
int
|
Maximum extension length on each side of the seed. CLI:
|
20
|
energy_threshold
|
float
|
Energy threshold in kcal/mol; only hits with energy below this value
are kept. CLI: |
-10.0
|
seed_start
|
int
|
First 1-based query position the seed may occupy ( |
None
|
seed_end
|
int
|
Last 1-based query position the seed may occupy ( |
None
|
seed_wobble
|
bool
|
Allow G:U wobble pairs inside the seed. |
True
|
matrix
|
str or Path
|
Nearest-neighbour energy parameter set: one of the bundled ids
|
"t04"
|
mismatches
|
int
|
Mismatches allowed inside a seed (RIsearch's |
0
|
mismatch_prefix
|
int
|
Matches required at the seed's 5' end before any mismatch. CLI:
|
1
|
mismatch_suffix
|
int
|
Matches required at the seed's 3' end after any mismatch. CLI:
|
0
|
temperature
|
int
|
Energy-model temperature in °C, 0 to 50; a custom DSM table ignores it.
CLI: |
37
|
penalty
|
float
|
kcal/mol added per extended nucleotide, included in the reported
energy. RIsearch2's C |
0.0
|
seed_energy
|
float
|
Accepted by risearch for compatibility; it has no effect in risearch
3.0.0a4/a5. CLI: |
0.0
|
no_max_prune
|
bool
|
Also extend non-maximal seeds, which gives redundant hits. CLI:
|
False
|
no_dedup
|
bool
|
Report every seed's hit instead of one best hit per duplex. CLI:
|
False
|
alignment
|
bool
|
Add the columns |
False
|
threads
|
int
|
Worker threads; |
None
|
sense_only
|
bool
|
Keep only |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per hit with the columns |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When query or index does not exist. |
RIsearchError
|
|
See Also
index : Build the index this function queries.
off_targets : Accepts the returned frame as predictions.
Examples:
>>> import sioff
>>> idx = sioff.index("target.fa")
>>> hits = sioff.search(
... "sirnas.fa",
... idx,
... target="target.fa",
... seed_start=2,
... seed_end=8,
... seed_length=7,
... seed_wobble=False,
... energy_threshold=-15.0,
... )
>>> hits.columns
['sirna_id', 'chrom', 'start', 'end', 'strand', 'energy']
>>> df = sioff.off_targets(predictions=hits, gtf_file="annotation.gtf")
Source code in src/sioff/api.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
Core layer¶
The pure, file-free core that sioff.off_targets, sioff.accessibility,
sioff.index and sioff.search wrap. Functions here take and return in-memory
objects (Polars DataFrames, dicts, generators) and raise plain Python
exceptions.
sioff.core.off_targets ¶
Pure core for off-target analysis.
The entry point is free of CLI concerns (no stdout, no Typer/Click
exceptions): compute_off_targets
is the one engine. A predictions file, a folder of them, an in-memory frame or
the hits of an in-process search is split into one part per siRNA, and every
siRNA is scored as its own task; it is a generator yielding
(pl.DataFrame, meta) per siRNA.
The core writes no output files, with two exceptions. The in-process search
builds the RIsearch index <target>.idx next to target_fasta when no
target_index is given (and reuses it later). And there are temporary
files: the Arrow-IPC copy of the transcriptome that every task memory-maps,
the per-siRNA split parts (none for a Parquet input that already holds one
siRNA), and accessibility profiles spilled to disk so
workers can memory-map them. They live inside the generator's try/finally
and are removed when the run ends, on error too, so callers should consume
the generator fully (or close it) for deterministic cleanup. The
accessibility cache built next to -a profiles is kept: it is reused by
later runs.
meta carries the partition-function state downstream formatters need:
z_per_sirna and on_target_weights.
The public wrapper sioff.off_targets adds path
coercion and the choice between one DataFrame and a stream on top of this
layer; sioff.accessibility, sioff.index
and sioff.search wrap the other core modules.
WorkerFailureError ¶
Bases: RuntimeError
Raised by compute_off_targets when worker tasks failed.
Successful siRNAs are still yielded first; the error is raised once every
task has been attempted. failures holds
(task_name, error_message) pairs in completion order: in
compute_off_targets a task is an input file that could not be split
(named by its file name) or a siRNA that could not be scored (named by its
sirna_id).
Source code in src/sioff/core/off_targets.py
compute_off_targets ¶
compute_off_targets(
*,
predictions: Optional[DataFrame] = None,
risearch_file: Optional[Path] = None,
sirna_fasta: Optional[Path] = None,
target_fasta: Optional[Path] = None,
target_index: Optional[Path] = None,
gtf_file: Optional[Path] = None,
feature_type: Optional[str] = None,
expression_metric: str = "RPKM",
transcriptome_format: str = "auto",
accessibility: Optional[Mapping[str, DataFrame]] = None,
accessibility_dir: Optional[Path] = None,
accessibility_cache_dir: Optional[Path] = None,
genome_file: Optional[Path] = None,
window_size: int = 80,
max_span: int = 40,
unpaired_prob: int = 30,
temperature: float = 37.0,
matrix: Union[str, Path] = "t04",
sirna_table: Optional[Path] = None,
alpha: str = "1.0",
gamma: str = "1.0",
theta: str = "",
sense_only: bool = False,
predictions_type: str = "gw",
n_workers: int = 1,
summary_only: bool = False,
detailed_report: bool = False,
worker_log_level: str = "WARNING",
on_split: Optional[Callable[[int], None]] = None,
accessibility_progress_callback=None,
) -> Generator[tuple[pl.DataFrame, dict], None, None]
Compute off-target probabilities, one siRNA at a time.
A generator yielding (df, meta) per siRNA, in completion order. Every
input takes the same path: a file is treated as a folder holding one file,
and every input file is split into one Parquet part per sirna_id. A
single sioff search TSV holding every siRNA and a folder of per-siRNA
files therefore run the same way, and so do the predictions frame and
the hits of the in-process search, which are split in this process. A
sirna_id found in two input files is an error. Each siRNA is then
scored as its own task: its part is
loaded, filtered to the sense strand with sense_only, intersected with
the transcriptome and scored with the per-siRNA partition function.
siRNAs with no predictions left after filtering and intersection are
skipped.
E_min (the reference of the alpha/gamma clamp) follows the legacy
rule: the lower of the siRNA's perfect-match energy, computed from its
sirna_table sequence with matrix, and the strongest hit left
after sense_only and the intersection. The perfect-match energies are
computed when an alpha/gamma pair other than (1, 1) is, and every siRNA
with predictions then needs a table row, or with detailed_report.
The clamp alone uses E_min, and never at the baseline.
Tasks run in a pool of spawned worker processes (spawn rather
than fork avoids Rayon/Polars thread-pool deadlocks), started only
when more than one task can run at once. Otherwise they run in this
process. Splitting the input files and scoring the siRNAs share the pool.
A failed task is logged and skipped; once every successful siRNA has been
yielded, a WorkerFailureError summarising the failures is raised, so a
run where tasks failed never looks like an empty success.
Checks and warnings are made in this process, before any siRNA is
scored: a siRNA missing from the table (an error when E_min is needed, a
warning otherwise), table rows without predictions (an info line), and
on-target IDs without gtf_file (a warning). After the last siRNA, the
siRNAs whose on-target matched no row are named in one warning.
Default opening energies: a hit on a sequence without a profile, or
outside its sequence's profile, keeps the default 10.0 kcal/mol, which
all but removes it from the partition function. After the last siRNA
one warning per kind gives the number of such hits and up to ten
sequence names; if no hit of the run has a profile, an
AccessibilityError is raised instead.
Accessibility reaches the workers as a memory-mapped packed cache,
whatever its source: the cache of accessibility_dir, the
accessibility profiles written to a temporary directory and packed
there, or genome_file folded into one. Without any of them, opening
energies are treated as zero.
Temporary files: the transcriptome is written once to an Arrow IPC
file that every task memory-maps, the split parts go to another temporary
directory, and so do the packed accessibility profiles or the
genome_file fold. All of them are removed in a finally, on error
too. Consume the generator fully, call .close() on it, or wrap it in
contextlib.closing for deterministic teardown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
DataFrame
|
In-memory predictions, typically the value returned by
|
None
|
risearch_file
|
Path
|
A predictions file, or a directory of them (CLI
|
None
|
sirna_fasta
|
Path
|
Query FASTA for an in-process RIsearch run against |
None
|
target_fasta
|
Path
|
Target FASTA (genome or transcriptome) for the in-process search
(CLI |
None
|
target_index
|
Path
|
Pre-built RIsearch index for |
None
|
gtf_file
|
Path
|
Transcriptome annotation, GTF or GFF3 (CLI |
None
|
feature_type
|
str
|
Feature type (column 3) of the annotation rows to use (CLI
|
None
|
expression_metric
|
str
|
Annotation attribute used as the expression score (CLI
|
"RPKM"
|
transcriptome_format
|
str
|
Annotation format: |
"auto"
|
accessibility
|
Mapping[str, DataFrame]
|
In-memory accessibility profiles, |
None
|
accessibility_dir
|
Path
|
The npy cache from |
None
|
accessibility_cache_dir
|
Path
|
Where the cache of |
None
|
genome_file
|
Path
|
Genome FASTA to fold during the run (CLI |
None
|
window_size
|
int
|
RNAplfold window size for folding |
80
|
max_span
|
int
|
Maximum base-pair span for folding |
40
|
unpaired_prob
|
int
|
Maximum unpaired-stretch length for folding |
30
|
temperature
|
float
|
Temperature in degrees Celsius of everything this run computes (CLI
|
37.0
|
matrix
|
str or Path
|
Energy parameter set for the perfect-match energies: a bundled id or
the path of a DSM TSV table (CLI |
"t04"
|
sirna_table
|
Path
|
Tab-separated siRNA table with a header (CLI |
None
|
alpha
|
str
|
Alpha clamping parameter(s) as a |
"1.0"
|
gamma
|
str
|
Gamma clamping parameter(s), same format as |
"1.0"
|
theta
|
str
|
Theta scaling parameter(s) as a |
""
|
sense_only
|
bool
|
Keep only sense-strand ( |
False
|
predictions_type
|
str
|
|
"gw"
|
n_workers
|
int
|
Worker processes for splitting and scoring (CLI |
1
|
summary_only
|
bool
|
Only the per-siRNA sums are needed (CLI |
False
|
detailed_report
|
bool
|
Keep the raw |
False
|
worker_log_level
|
str
|
The loguru level of the spawned workers' stderr sink. They do not
inherit this process's handlers, and loguru's own default is DEBUG.
The CLI passes |
"WARNING"
|
on_split
|
callable
|
Called once with the number of siRNAs to score, after the inputs are split and checked and before any siRNA is scored. |
None
|
accessibility_progress_callback
|
callable
|
Called as |
None
|
Yields:
| Type | Description |
|---|---|
tuple[DataFrame, dict]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
FileNotFoundError
|
When |
RIsearchError
|
|
AccessibilityError
|
When |
WorkerFailureError
|
After the last successful siRNA, when an input file could not be split or a siRNA could not be scored. |
See Also
sioff.off_targets : Public wrapper.
Source code in src/sioff/core/off_targets.py
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 | |
sioff.core.accessibility ¶
Pure core for accessibility computation, returning in-memory DataFrames.
Folds each sequence in the FASTA with ViennaRNA and returns one Polars DataFrame
per chromosome (schema [position, strand, u1..u{unpaired_prob}] -- the same
schema the CLI streams to {chrom}.accessibility.parquet), holding nothing on
disk. For genome-scale inputs prefer the CLI's streaming path; the in-memory dict
keeps every profile resident at once.
The public wrapper is sioff.accessibility; its result feeds the
accessibility argument of sioff.off_targets.
compute_accessibility ¶
compute_accessibility(
genome: Path,
window_size: int = 80,
max_span: int = 40,
unpaired_prob: int = 30,
temperature: float = 37.0,
strand: str = "both",
) -> dict[str, pl.DataFrame]
Compute per-chromosome accessibility profiles in memory.
Every sequence in genome is folded twice with ViennaRNA's RNAplfold
model, once as given (+ strand) and once as its reverse complement
(- strand); strand="+" skips the reverse complement. The resulting
opening energies are returned as one Polars DataFrame per chromosome with
columns [position, strand, u1..u{unpaired_prob}], the strands stacked
(+ then -), matching the on-disk Parquet schema written by
sioff accessibility. position
is 1-based along the folded sequence and u{k} is the opening energy
(kcal/mol) of the k-nt stretch ending at that position. Writes no
files and keeps every profile resident at once, so prefer the CLI's
streaming path for genome-scale inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
genome
|
Path
|
FASTA file whose records are folded; each record ID becomes a key of
the result (CLI positional |
required |
window_size
|
int
|
RNAplfold window size |
80
|
max_span
|
int
|
Maximum base-pair span |
40
|
unpaired_prob
|
int
|
Maximum unpaired-stretch length |
30
|
temperature
|
float
|
Folding temperature in degrees Celsius (CLI |
37.0
|
strand
|
(both, '+')
|
|
"both"
|
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Mapping from chromosome (FASTA record ID) to its profile frame with
columns |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When |
AccessibilityError
|
|
See Also
sioff.accessibility : Public wrapper accepting str paths.
sioff.off_targets : Consumes the returned mapping via its accessibility
argument.
Source code in src/sioff/core/accessibility.py
sioff.core.risearch ¶
Pure core for RIsearch index/search.
Wraps sioff.services.risearch_service.RIsearchService without any CLI
side-effects (no stdout, no file writes beyond the index binary itself) and
returns in-memory objects. parse_seed_spec turns the RIsearch2 -s
seed string into the seed_start/seed_end/seed_length arguments of
run_search.
The public wrappers are sioff.index and sioff.search.
build_index ¶
Build (or reuse) a RIsearch index for a target FASTA.
The index is a binary on-disk artifact consumed by run_search, so
this returns its Path rather than in-memory data. An
existing index at the output path is reused when it is newer than the
target and rebuilt otherwise. The target is registered against the index
so that a later run_search in the same process can resolve target
names without target.
Exceptions from the underlying
index_target
propagate unchanged: FileNotFoundError when target does not
exist, and RIsearchError when
the risearch bindings fail to build the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Path
|
Target FASTA to index (CLI positional |
required |
output
|
Path
|
Index path (CLI |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path of the (new or reused) index file. |
See Also
sioff.index : Public wrapper accepting str paths.
run_search : Searches against the index built here.
Source code in src/sioff/core/risearch.py
parse_seed_spec ¶
Parse a RIsearch2 -s seed specification into (start, end, length).
Accepts the forms the RIsearch2 CLI accepts, so a command line can be
copied between the two without translation (CLI -s/--seed):
"7": length only, no positional constraint ->(None, None, 7)"2:8/7": seed must lie in query positions 2..8 and be 7 nt ->(2, 8, 7)"2:8": positions given, length defaults to the window width ->(2, 8, 7)
Positions are 1-based and inclusive, matching RIsearch2. Surrounding whitespace is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
str
|
Seed specification: |
required |
Returns:
| Type | Description |
|---|---|
tuple[int or None, int or None, int]
|
|
Raises:
| Type | Description |
|---|---|
RIsearchError
|
When |
See Also
run_search : Consumes the returned triple.
sioff.search : Public wrapper around run_search.
Source code in src/sioff/core/risearch.py
run_search ¶
run_search(
query: Path,
index: Path,
target: Optional[Path] = None,
seed_length: int = 6,
max_extension: int = 20,
energy_threshold: float = -10.0,
seed_start: Optional[int] = None,
seed_end: Optional[int] = None,
seed_wobble: bool = True,
matrix: Union[str, Path] = "t04",
mismatches: int = 0,
mismatch_prefix: int = 1,
mismatch_suffix: int = 0,
temperature: int = 37,
penalty: float = 0.0,
seed_energy: float = 0.0,
no_max_prune: bool = False,
no_dedup: bool = False,
alignment: bool = False,
threads: Optional[int] = None,
sense_only: bool = False,
) -> pl.DataFrame
Run a RIsearch search and return hits as a Polars DataFrame.
target is required when the index was built outside this process (it
is needed to resolve RIsearch's integer target indices to sequence names);
after build_index in the same process it may be omitted.
Every risearch.search option is passed through, each with siOFF's own
default, so an upstream default change cannot move the results; the
defaults reproduce the searches siOFF ran before these options existed.
Seed geometry and energy-model parameters mirror the RIsearch2 CLI.
seed_start/seed_end/seed_length are the -s n:m/l seed spec:
the seed must fall within query positions n..m and be l nt long;
leaving seed_start/seed_end as None constrains length only,
which is RIsearch's default behaviour. seed_wobble=False is
--noGUseed and forbids G:U wobble pairs inside the seed; this affects
seed location only, not the energy model, so it is a candidate-generation
knob rather than a rescoring one. Measured on 3,826 fly S2 3'UTRs x 10
miRNAs it removes 84.7% of hits (783,836 -> 119,928). matrix is -z,
the nearest-neighbour energy parameter set: a bundled id or the path of a
custom DSM TSV table.
Exceptions from the underlying
run_search
propagate unchanged: FileNotFoundError when query or index
does not exist, and RIsearchError
when target is needed but missing, the seed geometry is invalid,
matrix is neither a bundled id nor an existing file, a mismatch count
is negative, temperature is outside 0-50 °C, threads is below 1,
or the risearch bindings fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Path
|
Query siRNA FASTA (CLI positional |
required |
index
|
Path
|
Pre-built RIsearch index, typically from |
required |
target
|
Path
|
Target FASTA the index was built from (CLI |
None
|
seed_length
|
int
|
Seed length |
6
|
max_extension
|
int
|
Maximum extension length on each side of the seed (CLI
|
20
|
energy_threshold
|
float
|
Energy threshold in kcal/mol; only hits below this value are kept (CLI
|
-10.0
|
seed_start
|
int
|
First allowed 1-based query position of the seed (the |
None
|
seed_end
|
int
|
Last allowed 1-based query position of the seed, inclusive (the |
None
|
seed_wobble
|
bool
|
Allow G:U wobble pairs inside the seed. |
True
|
matrix
|
str or Path
|
Nearest-neighbour energy parameter set (CLI |
"t04"
|
mismatches
|
int
|
Mismatches allowed inside a seed (CLI |
0
|
mismatch_prefix
|
int
|
Matches required at the seed's 5' end before any mismatch (CLI
|
1
|
mismatch_suffix
|
int
|
Matches required at the seed's 3' end after any mismatch (CLI
|
0
|
temperature
|
int
|
Energy-model temperature in °C, 0 to 50 (CLI |
37
|
penalty
|
float
|
kcal/mol added per extended nucleotide, included in the reported
energy (CLI |
0.0
|
seed_energy
|
float
|
Accepted by risearch for compatibility; it has no effect in risearch
3.0.0a4/a5 (CLI |
0.0
|
no_max_prune
|
bool
|
Also extend non-maximal seeds, which gives redundant hits (CLI
|
False
|
no_dedup
|
bool
|
Report every seed's hit instead of one best hit per duplex (CLI
|
False
|
alignment
|
bool
|
Add the columns |
False
|
threads
|
int
|
Worker threads; |
None
|
sense_only
|
bool
|
Keep only |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per hit with columns |
See Also
sioff.search : Public wrapper accepting str paths.
parse_seed_spec : Builds seed_start/seed_end/seed_length from
a -s string.
build_index : Builds the index argument.
Source code in src/sioff/core/risearch.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |