API Referenceο
siRNAforge - Comprehensive siRNA design toolkit for gene silencing. Comprehensive gene silencing design and analysis.
This module exposes package metadata (author/email/version) in a single place. The version is resolved from installed package metadata (importlib.metadata). When running from a source checkout (not installed), it falls back to reading pyproject.toml if available, otherwise uses a conservative placeholder.
Configurationο
Reference Policyο
Reference resolution for the screening path: one resolver, one typed reference.
Screening vocabulary is transcriptome throughout (#99). genome survives only as the ZFN
ReferenceKind, where it means genomic DNA: siRNA and miRNA act on mRNA, so the
transcriptome is the correct reference for both on- and off-target, and kind is keyed to
modality and nothing else.
Two rules this module exists to enforce:
A referenceβs species comes from the resolved reference, never from the parameter it arrived on.
SpeciesAuthorityrecords which authority supplied it, in the order declared > bundled-source registry > the referenceβs own headers > unresolved.One door. An explicit index override and a resolved default are both
ReferenceRequestvalues that differ instate/reason/formβ their provenance β and resolve to the sameScreeningReferenceshape, so neither can skip the metadata the classifier needs.
Imports of sirnaforge.models and sirnaforge.data are deliberately lazy: both packagesβ
__init__ reach back into this module, so a module-level import would be circular.
- sirnaforge.config.reference_policy.UNRESOLVED_SPECIES = 'unknown'ο
Label for a reference whose species nothing could establish. Deliberately not βtranscriptomeβ: that is the kind, and using it as a species is the defect this module exists to close.
- class sirnaforge.config.reference_policy.ReferenceChoice(value: str | None, state: ReferenceState, reason: str)[source]ο
Bases:
objectNormalized representation of a resolved reference input.
- state: ReferenceStateο
- static explicit(value: str, reason: str = 'user-provided') ReferenceChoice[source]ο
Create an explicit user-selected reference choice.
- static default(value: str, reason: str = 'auto-selected') ReferenceChoice[source]ο
Create a default-sourced reference choice.
- static disabled(reason: str) ReferenceChoice[source]ο
Create a disabled reference choice with context.
- class sirnaforge.config.reference_policy.ReferenceForm(*values)[source]ο
-
How a requested reference arrives, which decides how it is materialised.
Not a second door: both forms resolve to one
ScreeningReferenceand both build the species label and the transcript index. The form only says what work materialising it takes.- Variables:
REFERENCE β A bundled source name, local path or URL to fetch, cache and index.
PREBUILT_INDEX β A
species:index_prefixthe caller has already built.
- REFERENCE = 'reference'ο
- PREBUILT_INDEX = 'prebuilt_index'ο
- class sirnaforge.config.reference_policy.ReferenceKind(*values)[source]ο
-
What a screening reference contains, keyed to modality and nothing else.
- Variables:
TRANSCRIPTOME β mRNA/cDNA sequence. The reference for siRNA and miRNA screening, on- and off-target alike.
GENOME β Genomic DNA. ZFN only β ZFNs bind DNA. No genomic screening mode exists for siRNA.
- TRANSCRIPTOME = 'transcriptome'ο
- GENOME = 'genome'ο
- exception sirnaforge.config.reference_policy.ReferenceKindError[source]ο
Bases:
ValueErrorA referenceβs kind does not match the modalityβs, raised before any expensive work.
- class sirnaforge.config.reference_policy.ReferenceRejection(species: str, identity: str, reason: str)[source]ο
Bases:
objectA requested reference that could not be used, and why.
Kept beside the resolved references rather than dropped: a species with no usable reference is a completeness fact about the run, and erasing it is how βunscreenedβ came to read as βcleanβ.
- Variables:
species (str) β Species the request was for, or
UNRESOLVED_SPECIESwhen even that is unknown.identity (str) β The reference that failed.
reason (str) β What went wrong, in terms a user can act on.
- class sirnaforge.config.reference_policy.ReferenceRequest(value: str, form: ReferenceForm, state: ReferenceState, reason: str, declared_species: str | None = None)[source]ο
Bases:
objectOne screening reference a run asked for, before anything is fetched.
- Variables:
value (str) β Bundled source name, path, URL or index prefix.
form (sirnaforge.config.reference_policy.ReferenceForm) β How it is materialised.
state (sirnaforge.config.reference_policy.ReferenceState) β Provenance β explicit caller override or resolved default.
reason (str) β Why this request exists, carried into the resolved reference.
declared_species (str | None) β Species the caller named for it, if any.
- form: ReferenceFormο
- state: ReferenceStateο
- __init__(value: str, form: ReferenceForm, state: ReferenceState, reason: str, declared_species: str | None = None) Noneο
- class sirnaforge.config.reference_policy.ReferenceSelection(choices: tuple[~sirnaforge.config.reference_policy.ReferenceChoice, ...]=<factory>, disabled_reason: str | None = None)[source]ο
Bases:
objectContainer describing zero or more resolved references.
- choices: tuple[ReferenceChoice, ...]ο
- static disabled(reason: str) ReferenceSelection[source]ο
Create a disabled selection with a descriptive reason.
- class sirnaforge.config.reference_policy.ReferencePolicyResolver(spec: WorkflowInputSpec)[source]ο
Bases:
objectResolve workflow defaults while preserving intent metadata.
- __init__(spec: WorkflowInputSpec)[source]ο
Create a resolver for a specific workflow input specification.
- resolve_transcriptomes() ReferenceSelection[source]ο
Return one or more transcriptome references.
- class sirnaforge.config.reference_policy.ReferenceState(*values)[source]ο
-
Describe how a reference input was selected.
- EXPLICIT = 'explicit'ο
- DEFAULT = 'default'ο
- DISABLED = 'disabled'ο
- class sirnaforge.config.reference_policy.ScreeningReference(species: str, kind: ReferenceKind, identity: str, index: str, species_authority: SpeciesAuthority, form: ReferenceForm, state: ReferenceState, reason: str, fasta: str | None = None, needs_index_build: bool = False, identity_evidence: Mapping[str, Any] | None = None)[source]ο
Bases:
objectOne resolved screening reference:
{species, kind, identity, index}plus its provenance.- Variables:
species (str) β Canonical species, taken from the reference itself (see
SpeciesAuthority).kind (sirnaforge.config.reference_policy.ReferenceKind) β Transcriptome or genome, keyed to the runβs modality.
identity (str) β What was resolved β the source name, path, URL or index prefix as requested.
index (str) β What the aligner is handed: an index prefix, or the FASTA to index when
needs_index_buildis set.species_authority (sirnaforge.config.reference_policy.SpeciesAuthority) β Which authority supplied
species.form (sirnaforge.config.reference_policy.ReferenceForm) β How the reference was materialised.
state (sirnaforge.config.reference_policy.ReferenceState) β Provenance β explicit override or resolved default.
reason (str) β Why this reference is in the run.
fasta (str | None) β The sequence file the classifierβs transcript index was built from, when there is one.
needs_index_build (bool) β True when no index exists yet, so the pipeline must build one. It decides which pipeline parameter carries this reference: a FASTA named as an index prefix aligns nothing, which the pipeline then reports as a completed screen.
identity_evidence (collections.abc.Mapping[str, Any] | None) β Frozen view of the cache metadata for these bytes β url, checksum and its algorithm, size and its scope, download date, filters.
identitynames a source; only this names the bytes, and it is the sole route by which they survive_prepare_transcriptome_database, where the manager that knew them is discarded. Optional because a prebuilt index adopted from the caller has no cache entry at all.
- kind: ReferenceKindο
- species_authority: SpeciesAuthorityο
- form: ReferenceFormο
- state: ReferenceStateο
- to_metadata() dict[str, object][source]ο
Serializable snapshot for the published reference summary.
- plan_entry(*, guide_set_digest: str, search_settings: SearchSettings | None = None) ScreeningPlanEntry[source]ο
The
ScreeningPlanEntrythis reference plans to screen.The channel is always
TRANSCRIPTOME: only a transcriptome reference ever resolves, since a genome-kind run refuses every screening reference before it is materialised.
- __init__(species: str, kind: ReferenceKind, identity: str, index: str, species_authority: SpeciesAuthority, form: ReferenceForm, state: ReferenceState, reason: str, fasta: str | None = None, needs_index_build: bool = False, identity_evidence: Mapping[str, Any] | None = None) Noneο
- class sirnaforge.config.reference_policy.ScreeningReferenceSet(kind: ReferenceKind, references: tuple[ScreeningReference, ...] = (), rejections: tuple[ReferenceRejection, ...] = (), requested_species: tuple[str, ...] = ())[source]ο
Bases:
objectEvery reference one run resolved, the requests it could not use, and the scope that covers.
- Variables:
kind (sirnaforge.config.reference_policy.ReferenceKind) β The modalityβs reference kind. Every member shares it, by construction.
references (tuple[sirnaforge.config.reference_policy.ScreeningReference, ...]) β Resolved references, in resolution order.
rejections (tuple[sirnaforge.config.reference_policy.ReferenceRejection, ...]) β Requests that produced no usable reference.
requested_species (tuple[str, ...]) β Species the run asked to screen, before resolution.
- kind: ReferenceKindο
- references: tuple[ScreeningReference, ...] = ()ο
- rejections: tuple[ReferenceRejection, ...] = ()ο
- property species: tuple[str, ...]ο
Species with a usable reference, deduplicated, in resolution order.
- property index_parameter: strο
The
species:index_prefix,...value for references whose index already exists.
- property fasta_parameter: strο
The
species:path,...value for references the pipeline still has to index.
- scope() FilterScope[source]ο
The species this screen resolved references for, as an explicit set rather than a counterβs name.
Planned, not covered: it is fixed when the references resolve, and a species whose alignment later published nothing is reported as a shortfall rather than removed from here.
- plan(*, guide_set_digest: str, search_settings: SearchSettings | None = None) ScreeningPlan[source]ο
The screening plan these references intend to execute, one entry per reference.
- requested_plan(*, guide_set_digest: str, search_settings: SearchSettings | None = None) ScreeningPlan[source]ο
The plan this run asked for: one entry per resolved reference and one per rejection.
plan()walksreferencesonly, so a request that resolved to nothing leaves no plan entry and its species reconciles as never having been asked for rather than as a failure (#100). This is the same plan seen from after resolution: a rejected request keeps its entry, carrying the identity that failed, so the species it was for still has something to reconcile against. A run that records its plan before resolution does not need this; a caller holding only a resolved set does.
- to_metadata() dict[str, object][source]ο
Serializable snapshot: what resolved, what did not, and over which species.
- __init__(kind: ReferenceKind, references: tuple[ScreeningReference, ...] = (), rejections: tuple[ReferenceRejection, ...] = (), requested_species: tuple[str, ...] = ()) Noneο
- class sirnaforge.config.reference_policy.SpeciesAuthority(*values)[source]ο
-
Which authority supplied a referenceβs species label.
Ordered strongest first. Header inference is a fallback, not the authority: a caller who names the species means it, and only silence hands the decision to the file.
- Variables:
DECLARED β The caller stated it (
species:prefix on a reference or index entry).SOURCE_REGISTRY β A bundled sourceβs own registry entry stated it.
REFERENCE_HEADERS β Inferred from the referenceβs own Ensembl headers.
UNRESOLVED β Nothing said. The label is
UNRESOLVED_SPECIES, which matches no species, so hits against it cannot be qualified.
- DECLARED = 'declared'ο
- SOURCE_REGISTRY = 'source_registry'ο
- REFERENCE_HEADERS = 'reference_headers'ο
- UNRESOLVED = 'unresolved'ο
- class sirnaforge.config.reference_policy.WorkflowInputSpec(input_fasta: str | None = None, transcriptome_argument: str | None = None, default_transcriptomes: Sequence[str] = <factory>, design_only: bool = False, allow_transcriptome_for_input_fasta: bool = False, index_overrides: bool = False)[source]ο
Bases:
objectRaw workflow inputs prior to policy resolution.
- sirnaforge.config.reference_policy.build_screening_requests(*, kind: ReferenceKind, selection: ReferenceSelection, index_requests: Sequence[ReferenceRequest] = ()) tuple[tuple[ReferenceRequest, ...], tuple[ReferenceRejection, ...]][source]ο
Turn a selection and any explicit index requests into one ordered request list.
The single place a screening reference can enter a run. Explicit index requests come first: they are an override, and the species they declare decide the screen.
- Raises:
ReferenceKindError β An explicitly requested referenceβs kind does not match
kind. A default that does not match is disabled instead and returned as a rejection, because a default nobody asked for must not fail a run.
- sirnaforge.config.reference_policy.kind_of_bundled_source(identity: str) ReferenceKind | None[source]ο
The kind of a bundled Ensembl source name, or None when the name is not a bundled source.
This is what makes a modality mismatch catchable before any download: a genomic assembly name handed to a transcriptome screen is recognisable from the source table alone.
- sirnaforge.config.reference_policy.parse_index_entries(raw: str | None, *, option: str, reason: str) tuple[ReferenceRequest, ...][source]ο
Parse
species:index_prefixentries into explicit prebuilt-index requests.- Parameters:
raw β Comma-separated entries, or None.
option β Option name quoted in the error, so a malformed entry is findable.
reason β Why these requests exist, carried into the resolved reference.
- Raises:
ValueError β An entry does not name a species, or names one the registry does not recognise. An index prefix carries no headers to fall back on, so a declared species here is the only authority for that referenceβs label β an unrecognised one would be accepted as the species (
transcriptome:and typos alike), and orthology would silently resolve against nothing.--speciesrefuses an unknown name for the same reason.
- sirnaforge.config.reference_policy.render_reference_selection_label(selection: ReferenceSelection) str[source]ο
Render a stable, human-readable label for CLI/config summaries.
- sirnaforge.config.reference_policy.resolve_reference_species(*, declared: str | None, source_species: str | None, header_species: str | None) tuple[str, SpeciesAuthority, str | None][source]ο
Resolve a referenceβs species and say which authority supplied it.
Returns
(species, authority, conflict).conflictis a message when a weaker authority disagrees with the winner β reported rather than silently discarded, because a declared species that contradicts the file is usually a mistake in one of the two.
- sirnaforge.config.reference_policy.screening_kind_for_design_mode(design_mode: DesignMode | str) ReferenceKind[source]ο
The reference kind a design mode screens against.
DesignModeis read by value rather than imported:sirnaforge.modelsimports this module, so importing it back at module scope would be circular.
- sirnaforge.config.reference_policy.split_declared_species(value: str) tuple[str | None, str][source]ο
Split an optional
species:prefix off a reference, returning(species, remainder).The prefix is only read as a species when it is a name the species registry recognises, so a URL scheme (
https:) or a Windows drive letter is never mistaken for one.
Command Line Interfaceο
Modern CLI for siRNAforge using Typer and Rich.
- sirnaforge.cli.patched_init(self: Console, *args: Any, **kwargs: Any) None[source]ο
Force simplified terminal capabilities for deterministic CI output.
- class sirnaforge.cli.TranscriptLike(*args, **kwargs)[source]ο
Bases:
ProtocolMinimal transcript-like interface used by CLI filters.
- __init__(*args, **kwargs)ο
- sirnaforge.cli.filter_transcripts(transcripts: list[TTranscript], include_types: list[str] | None = None, exclude_types: list[str] | None = None, canonical_only: bool = False) list[TTranscript][source]ο
Filter transcript records by type and canonical status.
- Parameters:
transcripts β Iterable of transcript-like objects that expose
transcript_typeandis_canonicalattributes.include_types β Optional iterable of transcript types to keep.
exclude_types β Optional iterable of transcript types to drop.
canonical_only β When True, keep only canonical isoforms.
- Returns:
A list of transcripts that match the requested filters.
- sirnaforge.cli.extract_canonical_transcripts(transcripts: list[TranscriptInfo], gene_name: str, output_dir: Path | str | None = None) tuple[Path | None, int][source]ο
Write canonical isoforms to a separate FASTA file.
- Parameters:
transcripts β Iterable of transcript-like objects (must expose
is_canonicaland sequence attributes used by the underlying save routine).gene_name β Name used to derive the output FASTA filename.
output_dir β Directory to write the FASTA file into (defaults to CWD).
- Returns:
A tuple of
(canonical_fasta_path, count)where the path is None when no canonical isoforms are available.
- sirnaforge.cli.search(query: str = <typer.models.ArgumentInfo object>, output: Path = <typer.models.OptionInfo object>, database: str = <typer.models.OptionInfo object>, all_databases: bool = <typer.models.OptionInfo object>, fallback: bool = <typer.models.OptionInfo object>, no_sequence: bool = <typer.models.OptionInfo object>, canonical_only: bool = <typer.models.OptionInfo object>, extract_canonical: bool = <typer.models.OptionInfo object>, transcript_types: str = <typer.models.OptionInfo object>, exclude_types: str = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>) None[source]ο
Search transcript references and optionally fetch sequences.
This command queries Ensembl/RefSeq/Gencode (depending on flags) for a gene or transcript identifier. When sequences are fetched, it writes them to a FASTA file and can optionally also emit a canonical-only FASTA.
- sirnaforge.cli.workflow(ctx: Context, gene_query: str = <typer.models.ArgumentInfo object>, run_mode: str | None = <typer.models.OptionInfo object>, policy_config: Path | None = <typer.models.OptionInfo object>, target_intent_config: Path | None = <typer.models.OptionInfo object>, transcript_seed_species: str | None = <typer.models.OptionInfo object>, transcript_seed_required_species: str | None = <typer.models.OptionInfo object>, transcript_seed_scope: TranscriptSequenceScope = <typer.models.OptionInfo object>, report_mode: str = <typer.models.OptionInfo object>, aligner: str = <typer.models.OptionInfo object>, max_transcript_seed_sites: int | None = <typer.models.OptionInfo object>, species_liability_limits: str | None = <typer.models.OptionInfo object>, filter_action: list[str] = <typer.models.OptionInfo object>, input_fasta: str | None = <typer.models.OptionInfo object>, output_dir: Path = <typer.models.OptionInfo object>, database: str = <typer.models.OptionInfo object>, design_mode: str = <typer.models.OptionInfo object>, zfn_subfinger_mutation: list[str] = <typer.models.OptionInfo object>, zfn_max_mismatches_per_subfinger: int | None = <typer.models.OptionInfo object>, zfn_max_substitutions_overall: int | None = <typer.models.OptionInfo object>, zfn_left_half_site: str | None = <typer.models.OptionInfo object>, zfn_right_half_site: str | None = <typer.models.OptionInfo object>, zfn_search_space: str | None = <typer.models.OptionInfo object>, zfn_search_space_index: str | None = <typer.models.OptionInfo object>, zfn_search_backend: ZFNSearchBackend = <typer.models.OptionInfo object>, zfn_algorithm: ZFNAlgorithm = <typer.models.OptionInfo object>, zfn_dimer_mode: DimerMode = <typer.models.OptionInfo object>, zfn_spacer_lengths: str = <typer.models.OptionInfo object>, zfn_max_mismatches: int = <typer.models.OptionInfo object>, zfn_window_stride: int | None = <typer.models.OptionInfo object>, zfn_top_n_sites: int | None = <typer.models.OptionInfo object>, zfn_report_n_sites: int | None = <typer.models.OptionInfo object>, cores: int | None = <typer.models.OptionInfo object>, zfn_annotation: str | None = <typer.models.OptionInfo object>, top_n_candidates: int | None = <typer.models.OptionInfo object>, species: str = <typer.models.OptionInfo object>, query_species: str | None = <typer.models.OptionInfo object>, mirna_db: str = <typer.models.OptionInfo object>, mirna_reference_manifest: Path | None = <typer.models.OptionInfo object>, mirna_species: str | None = <typer.models.OptionInfo object>, transcriptome_fasta: str | None = <typer.models.OptionInfo object>, transcriptome_filter: str | None = <typer.models.OptionInfo object>, transcriptome_indices: str | None = <typer.models.OptionInfo object>, ortholog_mapping: Path | None = <typer.models.OptionInfo object>, gc_min: float | None = <typer.models.OptionInfo object>, gc_max: float | None = <typer.models.OptionInfo object>, sirna_length: int | None = <typer.models.OptionInfo object>, modification_pattern: str | None = <typer.models.OptionInfo object>, overhang: str | None = <typer.models.OptionInfo object>, skip_off_targets: bool = <typer.models.OptionInfo object>, snp: list[str] = <typer.models.OptionInfo object>, snp_file: Path | None = <typer.models.OptionInfo object>, variant_mode: VariantMode = <typer.models.OptionInfo object>, min_af: float = <typer.models.OptionInfo object>, clinvar_filter_levels: str = <typer.models.OptionInfo object>, variant_assembly: str = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>, log_file: Path | None = <typer.models.OptionInfo object>, nextflow_docker_image: str | None = <typer.models.OptionInfo object>, max_hits: int | None = <typer.models.OptionInfo object>, max_off_targets: int | None = <typer.models.OptionInfo object>, min_asymmetry: float | None = <typer.models.OptionInfo object>, max_paired_fraction: float | None = <typer.models.OptionInfo object>, min_empirical: float | None = <typer.models.OptionInfo object>, min_isoform_coverage: float | None = <typer.models.OptionInfo object>, plfold_window: int | None = <typer.models.OptionInfo object>, plfold_max_bp_span: int | None = <typer.models.OptionInfo object>, accessibility_log_floor: float | None = <typer.models.OptionInfo object>, json_summary: bool = <typer.models.OptionInfo object>, fail_on_no_eligible: bool = <typer.models.OptionInfo object>) None[source]ο
Run the end-to-end workflow: transcripts β siRNA design β off-target.
This is the main orchestration command. It resolves transcriptome and miRNA reference policies, designs candidates, and then runs off-target analysis on the selected top candidates.
- sirnaforge.cli.offtarget(run_mode: str | None = <typer.models.OptionInfo object>, policy_config: Path | None = <typer.models.OptionInfo object>, filter_action: list[str] = <typer.models.OptionInfo object>, input_candidates_fasta: Path = <typer.models.OptionInfo object>, output_dir: Path = <typer.models.OptionInfo object>, species: str = <typer.models.OptionInfo object>, query_species: str | None = <typer.models.OptionInfo object>, mirna_db: str = <typer.models.OptionInfo object>, mirna_reference_manifest: Path | None = <typer.models.OptionInfo object>, mirna_species: str | None = <typer.models.OptionInfo object>, transcriptome_fasta: str | None = <typer.models.OptionInfo object>, transcriptome_filter: str | None = <typer.models.OptionInfo object>, transcriptome_indices: str | None = <typer.models.OptionInfo object>, aligner: str = <typer.models.OptionInfo object>, ortholog_mapping: Path | None = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>, log_file: Path | None = <typer.models.OptionInfo object>, nextflow_docker_image: str | None = <typer.models.OptionInfo object>) None[source]ο
Run off-target analysis on pre-designed siRNA candidates.
This command accepts a FASTA file containing pre-designed siRNA guide sequences of any length and runs comprehensive off-target analysis including: - Transcriptome alignment (BWA-MEM2) - miRNA seed match analysis - Off-target hit classification and scoring
The embedded Nextflow pipeline is used for parallel processing across species.
Notes
--speciesdrives transcriptome fetching and miRNA lookup.--offtarget-indicescan override the indices used for alignment usingspecies:/abs/path/index_prefixentries.
- sirnaforge.cli.zfn(output_dir: Path = <typer.models.OptionInfo object>, zfn_subfinger_mutation: list[str] = <typer.models.OptionInfo object>, zfn_max_mismatches_per_subfinger: int | None = <typer.models.OptionInfo object>, zfn_max_substitutions_overall: int | None = <typer.models.OptionInfo object>, zfn_left_half_site: str = <typer.models.OptionInfo object>, zfn_right_half_site: str = <typer.models.OptionInfo object>, zfn_search_space: str | None = <typer.models.OptionInfo object>, zfn_search_space_index: str | None = <typer.models.OptionInfo object>, zfn_search_backend: ZFNSearchBackend = <typer.models.OptionInfo object>, zfn_algorithm: ZFNAlgorithm = <typer.models.OptionInfo object>, zfn_dimer_mode: DimerMode = <typer.models.OptionInfo object>, zfn_spacer_lengths: str = <typer.models.OptionInfo object>, zfn_max_mismatches: int = <typer.models.OptionInfo object>, zfn_window_stride: int | None = <typer.models.OptionInfo object>, zfn_top_n_sites: int | None = <typer.models.OptionInfo object>, zfn_report_n_sites: int | None = <typer.models.OptionInfo object>, cores: int | None = <typer.models.OptionInfo object>, zfn_annotation: str | None = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>, log_file: Path | None = <typer.models.OptionInfo object>, nextflow_docker_image: str | None = <typer.models.OptionInfo object>, json_summary: bool = <typer.models.OptionInfo object>) None[source]ο
Evaluate a ZFN pair and run exhaustive genome-wide off-target search (EXPERIMENTAL).
- sirnaforge.cli.design(ctx: Context, input_file: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.OptionInfo object>, design_mode: str = <typer.models.OptionInfo object>, policy_config: Path | None = <typer.models.OptionInfo object>, filter_action: list[str] = <typer.models.OptionInfo object>, length: int | None = <typer.models.OptionInfo object>, top_n: int | None = <typer.models.OptionInfo object>, gc_min: float | None = <typer.models.OptionInfo object>, gc_max: float | None = <typer.models.OptionInfo object>, max_poly_runs: int | None = <typer.models.OptionInfo object>, min_asymmetry: float | None = <typer.models.OptionInfo object>, max_paired_fraction: float | None = <typer.models.OptionInfo object>, min_empirical: float | None = <typer.models.OptionInfo object>, plfold_window: int | None = <typer.models.OptionInfo object>, plfold_max_bp_span: int | None = <typer.models.OptionInfo object>, accessibility_log_floor: float | None = <typer.models.OptionInfo object>, snp_file: Path | None = <typer.models.OptionInfo object>, skip_structure: bool = <typer.models.OptionInfo object>, skip_off_targets: bool = <typer.models.OptionInfo object>, modification_pattern: str | None = <typer.models.OptionInfo object>, overhang: str | None = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>) None[source]ο
Design siRNA candidates from a transcript FASTA file.
Outputs a TSV/CSV-like table of candidates, optionally including secondary structure scoring, off-target checks, and chemical modification annotations.
- sirnaforge.cli.validate(input_file: Path = <typer.models.ArgumentInfo object>) None[source]ο
Validate a FASTA file and report basic statistics.
This performs lightweight validation (parseable FASTA, presence of sequences, and common issues like short/ambiguous sequences).
- sirnaforge.cli.annotate(query: list[str] = <typer.models.ArgumentInfo object>, provider: str = <typer.models.OptionInfo object>, annotation_file: Path = <typer.models.OptionInfo object>, assembly: str = <typer.models.OptionInfo object>, species: str = <typer.models.OptionInfo object>, regions: bool = <typer.models.OptionInfo object>, output: Path | None = <typer.models.OptionInfo object>) None[source]ο
Resolve transcript structure from local GENCODE or RefSeq GTF/GFF3 files.
- sirnaforge.cli.cache(clear: bool = <typer.models.OptionInfo object>, clear_mirna: bool = <typer.models.OptionInfo object>, clear_transcriptome: bool = <typer.models.OptionInfo object>, dry_run: bool = <typer.models.OptionInfo object>, info: bool = <typer.models.OptionInfo object>) None[source]ο
Inspect and clear the unified reference cache.
This command can display cache statistics and/or delete cached assets for miRNA databases and transcriptomes.
- sirnaforge.cli.benchmark_prepare(panel: str = <typer.models.OptionInfo object>, panel_csv: Path | None = <typer.models.OptionInfo object>, panel_transcripts: Path | None = <typer.models.OptionInfo object>, native_observations_csv: Path | None = <typer.models.OptionInfo object>, native_mappings_csv: Path | None = <typer.models.OptionInfo object>, native_reference_manifest: Path | None = <typer.models.OptionInfo object>, native_reference_fasta: Path | None = <typer.models.OptionInfo object>, paired_length: int | None = <typer.models.OptionInfo object>, out_dir: Path = <typer.models.OptionInfo object>, overwrite: bool = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>) None[source]ο
Prepare one fixed-length benchmark artifact for a compatible panel and paired length (#109).
Writes
<out-dir>/<panel_id>__len<paired_length>/withobservations.csv,design_inputs.fastaandmanifest.json. Every measured observation is preserved, including one incompatible with this paired length: dropping it silently would make a later count unreproducible from the panel bytes alone.design_inputs.fastais a plain FASTA, sosirnaforge designandsirnaforge workflowconsume it with no new execution path.
- sirnaforge.cli.benchmark_design(ctx: Context, artifact: Path = <typer.models.OptionInfo object>, design_mode: str = <typer.models.OptionInfo object>, gc_min: float | None = <typer.models.OptionInfo object>, gc_max: float | None = <typer.models.OptionInfo object>, policy_config: Path | None = <typer.models.OptionInfo object>, filter_action: list[str] = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>) None[source]ο
Run the fixed-length design path over a prepared benchmark artifact, twice-policied (#109).
The run executes once, under the (possibly widened) benchmark policy; the default-policy verdict for every candidate is then re-derived from what that one run already observed, never from a second run.
--gc-min/--gc-maxmay only widen the shipped floor/ceiling β a narrower value is refused before any design work, because the re-derived default verdicts assume the benchmark run enumerated a superset of what a default run would. Every other threshold, and the polynucleotide-run requirement (<= 3) in particular, resolves exactly assirnaforge designwould; nothing here can relax it.
- exception sirnaforge.cli.SequencesShowError[source]ο
Bases:
RuntimeErrorRaised when sequence display/formatting input is invalid.
- sirnaforge.cli.sequences_show(input_file: Path = <typer.models.ArgumentInfo object>, sequence_id: str | None = <typer.models.OptionInfo object>, format: str = <typer.models.OptionInfo object>) None[source]ο
Show sequences from a FASTA file in table, JSON, or FASTA format.
Use
--idto select a single record.--formatcontrols output:table(default),json(header metadata only), orfasta.
- sirnaforge.cli.sequences_annotate(input_fasta: Path = <typer.models.ArgumentInfo object>, metadata_json: Path = <typer.models.ArgumentInfo object>, output: Path | None = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>) None[source]ο
Merge metadata from a JSON file into FASTA headers.
The JSON is expected to conform to the project metadata schema used by the modification/annotation utilities.
- sirnaforge.cli.internal_zfn_make_shards(genome_fasta: Path = <typer.models.OptionInfo object>, left_half_site: str = <typer.models.OptionInfo object>, right_half_site: str = <typer.models.OptionInfo object>, spacer_lengths: str = <typer.models.OptionInfo object>, max_mismatches: int = <typer.models.OptionInfo object>, sharding_enabled: str = <typer.models.OptionInfo object>, shard_chunk_mb: float = <typer.models.OptionInfo object>, shard_overlap_bp: int = <typer.models.OptionInfo object>, shard_chromosomes: str = <typer.models.OptionInfo object>, output: Path = <typer.models.OptionInfo object>) None[source]ο
Build ZFN shard manifest for Nextflow execution.
- sirnaforge.cli.internal_zfn_build_search_index(genome_fasta: Path = <typer.models.OptionInfo object>, search_backend: ZFNSearchBackend = <typer.models.OptionInfo object>, output_dir: Path | None = <typer.models.OptionInfo object>) None[source]ο
Build a persisted ZFN search-space index bundle for indexed backends.
- sirnaforge.cli.internal_zfn_search_shard(shard_id: str = <typer.models.OptionInfo object>, shard_chrom: str = <typer.models.OptionInfo object>, scan_start_1: int = <typer.models.OptionInfo object>, scan_end_1: int = <typer.models.OptionInfo object>, core_start_1: int | None = <typer.models.OptionInfo object>, core_end_1: int | None = <typer.models.OptionInfo object>, shard_max_mismatches: int = <typer.models.OptionInfo object>, left_half_site: str = <typer.models.OptionInfo object>, right_half_site: str = <typer.models.OptionInfo object>, genome_fasta: Path = <typer.models.OptionInfo object>, search_backend: ZFNSearchBackend = <typer.models.OptionInfo object>, search_space_index: Path | None = <typer.models.OptionInfo object>, algorithm: ZFNAlgorithm = <typer.models.OptionInfo object>, dimer_mode: DimerMode = <typer.models.OptionInfo object>, spacer_lengths: str = <typer.models.OptionInfo object>, annotation_file: Path | None = <typer.models.OptionInfo object>, output_sites_csv: Path = <typer.models.OptionInfo object>, output_summary_json: Path = <typer.models.OptionInfo object>) None[source]ο
Run one shard-scoped ZFN search and emit shard artifacts.
- sirnaforge.cli.internal_zfn_search_full(genome_fasta: Path = <typer.models.OptionInfo object>, design_params_json: Path = <typer.models.OptionInfo object>, annotation_config_json: Path | None = <typer.models.OptionInfo object>, search_space_index: Path | None = <typer.models.OptionInfo object>, annotation_file: Path | None = <typer.models.OptionInfo object>, output_sites_csv: Path = <typer.models.OptionInfo object>, output_summary_json: Path = <typer.models.OptionInfo object>) None[source]ο
Run one full-reference ZFN search for the public Nextflow workflow route.
- sirnaforge.cli.internal_zfn_aggregate_shards(shard_csv_glob: str = <typer.models.OptionInfo object>, output_sites_csv: Path = <typer.models.OptionInfo object>, output_summary_json: Path = <typer.models.OptionInfo object>) None[source]ο
Aggregate shard-level ZFN outputs into final ranked outputs.
- sirnaforge.cli.report(run_dir: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.OptionInfo object>, diagnostics_json: Path | None = <typer.models.OptionInfo object>, quilt_summarize: bool = <typer.models.OptionInfo object>, mode: str = <typer.models.OptionInfo object>, artifact_dir: Path | None = <typer.models.OptionInfo object>, compact_max_input_bytes: int = <typer.models.OptionInfo object>, compact_max_candidate_rows: int = <typer.models.OptionInfo object>, compact_max_guides: int = <typer.models.OptionInfo object>, paged_max_input_bytes: int = <typer.models.OptionInfo object>, paged_max_candidate_rows: int = <typer.models.OptionInfo object>, paged_max_guides: int = <typer.models.OptionInfo object>) None[source]ο
Build a compact, paged, or data-backed HTML report over a finished run.
Works on any finished or archived run: it reads candidates_all.csv, the aggregated hit tables and manifest.json, and needs no live pipeline state. The report classifies nothing and applies no threshold of its own β gate descriptors come from the resolved policy and hit_class from the published table β so it cannot disagree with the run it describes.
Core Modulesο
Design Engineο
Core siRNA design algorithms and functionality.
- sirnaforge.core.design.record_gate_outcome(candidate: SiRNACandidate, outcome: FilterOutcome, *, status: FilterStatus | None = None) None[source]ο
Write one
FilterOutcomeonto a candidate (#100).The bridge between the pure evaluator and the single writer:
core/filtering.pymay not importmodels/sirna.py(that is what keeps it pure and testable without a candidate), andrecord_filter_verdictspeaks only PASS/FAIL/UNKNOWN.NOT_EVALUATEDis therefore written directly β a gate that made no claim must still occupy its verdict column with the value it would have compared, because an empty cell there reads as a verdict.Lives here rather than in
workflow.pybecause the design stage and the post-screen stage must write a verdict identically, andworkflow.pyalready imports this module (never the reverse).
- class sirnaforge.core.design.SiRNADesigner(parameters: DesignParameters, *, filter_actions: Mapping[str, FilterAction] | None = None)[source]ο
Bases:
objectMain siRNA design engine following the algorithm specification.
- __init__(parameters: DesignParameters, *, filter_actions: Mapping[str, FilterAction] | None = None) None[source]ο
Initialize designer with given parameters.
- Parameters:
parameters β Thresholds and scoring settings.
filter_actions β Per-filter actions from the resolved run policy. Keyword-only with a default because the declared defaults are the right answer when a caller has no policy in hand β
DesignParameterscarries thresholds and says nothing about whether exceeding one rejects a candidate, so without this the designer could only ever reject andFilterAction.WARNwould be inert.
- design_from_file(input_file: str) DesignResult[source]ο
Design siRNAs from input FASTA file.
- design_from_sequence(sequence: str, transcript_id: str = 'seq1') DesignResult[source]ο
Design siRNAs from a single sequence.
- static stamp_repeat_verdict(candidate: SiRNACandidate, observations: dict[str, RepeatObservation], action: FilterAction = FilterAction.FAIL) None[source]ο
Stamp repeat metadata and verdict on a single candidate if its guide is flagged.
The REPEAT_ELEMENT verdict is applied only if this gateβs action is FAIL and the candidate is currently passing (passes_filters is True or PASS). A candidate that already failed for another reason (GC, asymmetry, etc.) retains its earlier verdict β precedence is: existing failure > REPEAT_ELEMENT > PASS.
- Parameters:
candidate β Candidate to potentially flag.
observations β Mapping from normalized guide sequence to RepeatObservation.
action β The resolved action for
max_repeat_transcript_fraction. Only FAIL rejects; WARN records the verdict and the fraction and leaves the candidate passing.
- sirnaforge.core.design.classify_pos1_pairing(guide_base: str, passenger_base: str) str[source]ο
Classify the pairing state at guide position 1: perfect, wobble or mismatch.
Bases are stored as DNA, so they are read as RNA before lookup: otherwise A:T is not found in the Watson-Crick set and every A:U pair is called a mismatch.
- sirnaforge.core.design.supplementary_score(guide: str) float[source]ο
3β supplementary pairing sub-score from guide positions 13-16, in [0, 1].
High A/U content there means low pairing stability, which is the desirable direction (less 3β supplementary pairing, better specificity), so the sub-score rises with A/U as every other term rises with the thing it wants.
- sirnaforge.core.design.au_content_5p_score(guide: str) float | None[source]ο
A/U content over guide positions 1-5, as a fraction in [0, 1]. Issue #97, window per D5.
Reported on every candidate and scored by no default vector in 0.7.1: promoting it needs the post-screen feature assembly to forward it, which is not this moduleβs file. Returns None for a guide shorter than the window rather than a substituted midpoint β a missing input must not score as a good one.
Pure sequence, so it is computable wherever a guide exists, including on paths that have no transcript context and no ViennaRNA.
- sirnaforge.core.design.biogenesis_features(guide: str, passenger: str) dict[str, float][source]ο
The three miRNA biogenesis sub-scores, from sequence alone.
Computed here rather than read back off the candidate so post-screen scoring cannot be handed a partially-populated row: every term in the active post-screen vector must be present, and re-deriving them from the sequences means they always are. Each is in [0, 1] like every other term β they are features now, not bonuses added to a finished score.
- class sirnaforge.core.design.MiRNADesigner(parameters: DesignParameters, *, filter_actions: Mapping[str, FilterAction] | None = None)[source]ο
Bases:
SiRNADesignermiRNA-biogenesis-aware siRNA designer with specialized scoring.
Extends SiRNADesigner with scoring rules optimized for miRNA-like processing: - Argonaute selection preferences (pos1 A/U scored; pos1 pairing state reported only) - 3β supplementary pairing analysis (positions 13-16) - Conservative thermodynamic thresholds - Seed region quality assessment
Thermodynamics Analysisο
Thermodynamic calculations for siRNA design using ViennaRNA.
- class sirnaforge.core.thermodynamics.TargetSiteAccessibility(seed_end_8mer: float | None, seed_anchored_17mer: float | None, whole_site: float | None)[source]ο
Bases:
objectLocal opening probabilities for one siRNA target site on its mRNA.
Every window is anchored on the siteβs 3β end, which is the end the guide seed pairs (see SEED_END_WINDOW_NT). A value is None when the site is too close to the transcript 5β end for the window to fit; it is never substituted with a default, because a missing input must not score as a good one.
- Variables:
- class sirnaforge.core.thermodynamics.TargetAccessibilityProfile(unpaired: list[list[float]], length: int, u_max: int)[source]ο
Bases:
objectRNAplfold unpaired-probability profile for one transcript, folded once.
Wraps the matrix returned by
RNA.pfl_fold_up, which is 1-based in both axes:unpaired[i][u]is the equilibrium probability that the length-ustretch ending at 1-based positioniis entirely unpaired. (Confirmed against the library rather than its docstring:unpaired[1][u]is 0 for every u > 1 whileunpaired[N][u]is populated for every u, which only holds for the βending atβ convention.)RNAplfold is used rather than a global partition function because the latter is O(n^3) and a transcript is multiple kb; the windowed form is also the quantity local-opening models are defined on.
- __init__(unpaired: list[list[float]], length: int, u_max: int) None[source]ο
Wrap an already-computed pfl_fold_up matrix; prefer
fold()to build one.
- classmethod fold(sequence: str, window_size: int = 150, max_bp_span: int = 100, u_max: int = 17) TargetAccessibilityProfile[source]ο
Fold one transcript and cache its opening probabilities.
- Parameters:
sequence β Full transcript sequence; read as RNA, so T and U are equivalent.
window_size β RNAplfold averaging window (W).
max_bp_span β RNAplfold maximum base-pair span (L).
u_max β Longest unpaired stretch to tabulate. Must cover every window queried.
- site_accessibility(start_pos: int, site_length: int) TargetSiteAccessibility[source]ο
Look up the three 3β-anchored windows for a site.
- Parameters:
start_pos β Start of the target site (0-based) in the folded transcript.
site_length β Length of the target site in nucleotides.
- class sirnaforge.core.thermodynamics.ThermodynamicCalculator(temperature: float = 37.0)[source]ο
Bases:
objectCalculate thermodynamic properties for siRNA candidates using ViennaRNA.
- __init__(temperature: float = 37.0)[source]ο
Initialize thermodynamic calculator.
- Parameters:
temperature β Temperature in Celsius for calculations
- calculate_duplex_stability(guide: str, passenger: str) float[source]ο
Calculate duplex stability (deltaG) using ViennaRNA.
Both strands are supplied 5β->3β and are already complementary, so neither is reverse-complemented here: ViennaRNAβs
&cofold notation pairs the two strands antiparallel on its own.
- calculate_asymmetry_score(candidate: SiRNACandidate) tuple[float, float, float][source]ο
Calculate thermodynamic asymmetry score using ViennaRNA.
Duplex ends are antiparallel, so the guide 5β end pairs with the passenger 3β end and vice versa. Both windows are
END_WINDOW_NTlong so the two ΞG values are directly comparable.- Returns:
Tuple of (5β end stability, 3β end stability, asymmetry score)
- calculate_target_accessibility(target_sequence: str, start_pos: int, sirna_length: int, window_size: int = 150, max_bp_span: int = 100) TargetSiteAccessibility[source]ο
Compute local opening probabilities for one target site on the mRNA.
Convenience single-site entry point. Callers scoring many sites on the same transcript should build a
TargetAccessibilityProfileonce instead: this folds the whole transcript per call.- Parameters:
target_sequence β Full target mRNA sequence.
start_pos β Start of the siRNA target site (0-based).
sirna_length β Length of the target site in nucleotides.
window_size β RNAplfold averaging window (W).
max_bp_span β RNAplfold maximum base-pair span (L).
- Returns:
TargetSiteAccessibility for the site.
- calculate_melting_temperature(guide: str, passenger: str) float[source]ο
Calculate duplex melting temperature in Β°C.
Uses the RNA nearest-neighbour parameters of Xia et al. (1998) via Biopython. Tm needs ΞH and ΞS separately, which ViennaRNAβs MFE does not provide, so scaling ΞG cannot produce a physical Tm: at the corrected duplex ΞG of a 21mer (about -39 kcal/mol) the previous
37 + 2 * -ΞGapproximation returned 101-124 Β°C.- Parameters:
guide β Guide strand, 5β->3β
passenger β Passenger strand, 5β->3β (expected reverse complement of guide)
- static meets_asymmetry_threshold(asymmetry_score: float, threshold: float) bool[source]ο
Check an already-computed asymmetry score against a threshold.
Callers that have just computed the score use this instead of
is_thermodynamically_favorable()to avoid re-folding both duplex ends.
- is_thermodynamically_favorable(candidate: SiRNACandidate, threshold: float = 0.65) bool[source]ο
Check if candidate meets thermodynamic asymmetry threshold.
Off-Target Predictionο
Off-target analysis for siRNA design.
This module provides comprehensive off-target analysis functionality for siRNA design, including both miRNA seed match analysis and transcriptome off-target detection. Uses BWA-MEM2 for transcriptome alignments and supports in-process miRNA seed scanning. Optimized for both standalone use and parallelized Nextflow workflows.
- class sirnaforge.core.off_target.BwaAnalyzer(index_prefix: str | Path, mode: str = 'transcriptome', seed_length: int = 12, min_score: int = 15, max_hits: int | None = None, seed_start: int = 2, seed_end: int = 8, aligner: str = 'bwa-mem2')[source]ο
Bases:
objectBWA-compatible analyzer for transcriptome and miRNA seed off-target search.
- __init__(index_prefix: str | Path, mode: str = 'transcriptome', seed_length: int = 12, min_score: int = 15, max_hits: int | None = None, seed_start: int = 2, seed_end: int = 8, aligner: str = 'bwa-mem2')[source]ο
Initialize BWA-MEM2 analyzer.
- Parameters:
index_prefix β Path to BWA index
mode β Analysis mode - βtranscriptomeβ for long targets, βmirna_seedβ for short targets
seed_length β BWA seed length parameter
min_score β Minimum alignment score
max_hits β Maximum hits to return (
None= no limit / exhaustive)seed_start β Seed region start (1-based)
seed_end β Seed region end (1-based)
aligner β Selected BWA executable (MEM2 by default).
- analyze_sequences(sequences: dict[str, str]) list[dict[str, Any]][source]ο
Run BWA-MEM2 analysis on sequences.
- Parameters:
sequences β Dictionary of sequence name -> sequence
- Returns:
List of alignment dictionaries
- analyze_sequences_with_outcome(sequences: dict[str, str]) tuple[list[dict[str, Any]], ExecutionOutcome][source]ο
Run BWA-MEM2 analysis, also reporting the #100
ExecutionOutcomecontract.Sibling to
analyze_sequences(), which keeps returning[]on an aligner failure so every existing callerβs return shape stays untouched. That made a hard subprocess failure byte-identical to a clean zero-hit run;ExecutionOutcome.completedis what tells a caller (workflow.py, the Nextflow evidence emitters) apart, along with the submitted/processed guide membership and cap/truncation metadata evidence.json needs. Truncation is attributed to this methodβs own cap below, never to_filter_and_rank, which sorts the results but discards none of them.
- class sirnaforge.core.off_target.OffTargetAnalysisManager(species: str, transcriptome_path: str | Path | None = None, mirna_path: str | Path | None = None, transcriptome_index: str | Path | None = None, mirna_index: str | Path | None = None)[source]ο
Bases:
objectManager class for comprehensive off-target analysis using BWA-MEM2.
- __init__(species: str, transcriptome_path: str | Path | None = None, mirna_path: str | Path | None = None, transcriptome_index: str | Path | None = None, mirna_index: str | Path | None = None)[source]ο
Initialize the off-target analysis manager.
- analyze_mirna_off_targets(sequences: dict[str, str] | str | Path, output_prefix: str | Path) tuple[Path, Path][source]ο
Analyze miRNA off-targets using BWA-MEM2 in miRNA seed mode.
- class sirnaforge.core.off_target.MiRNASeedBackend(*values)[source]ο
-
Internal backend options for miRNA seed scanning.
- BWA = 'bwa'ο
- EXHAUSTIVE_PYTHON = 'exhaustive_python'ο
- PYAHOCORASICK = 'pyahocorasick'ο
- sirnaforge.core.off_target.create_temp_fasta(sequences: dict[str, str]) str[source]ο
Create temporary FASTA file from sequences.
- sirnaforge.core.off_target.build_bwa_index(fasta_file: str | Path, index_prefix: str | Path, *, aligner: str = 'bwa-mem2') Path[source]ο
Build an index with the selected BWA backend.
- sirnaforge.core.off_target.parse_fasta_file(fasta_file: str | Path) dict[str, str][source]ο
Parse FASTA file using existing FastaUtils.
- sirnaforge.core.off_target.validate_index_files(index_prefix: str | Path, tool: str = 'bwa') bool[source]ο
Validate that index files exist for given tool.
- sirnaforge.core.off_target.mirna_seed_hit_identity(hit: dict[str, Any], *, coord_is_one_based: bool = False) tuple[str, str, int, int, int, float][source]ο
Return the semantic identity tuple used for backend comparison.
This normalizes the current in-process seed-scan rows and the existing BWA-derived rows onto the same comparison contract.
- sirnaforge.core.off_target.normalize_mirna_seed_hit(hit: dict[str, Any], *, coord_is_one_based: bool = False) _NormalizedMiRNASeedHit[source]ο
Normalize backend-specific miRNA seed hit metadata onto one adapter/parity contract.
- sirnaforge.core.off_target.run_bwa_alignment_analysis(candidates_file: str | Path, index_prefix: str | Path, species: str, output_dir: str | Path, max_hits: int | None = None, bwa_k: int = 12, bwa_T: int = 15, seed_start: int = 2, seed_end: int = 8, *, evidence_dir: str | Path | None = None, aligner: str = 'bwa-mem2') Path[source]ο
Run BWA-MEM2 alignment analysis for candidate sequences using Pydantic models.
This is the main function called by OFFTARGET_ANALYSIS Nextflow module.
- Parameters:
candidates_file β Path to FASTA file with candidate sequences
index_prefix β Path to BWA-MEM2 index prefix
species β Species identifier
output_dir β Directory to write results
max_hits β Maximum hits to report per candidate (
None= no limit / exhaustive)bwa_k β BWA seed length parameter
bwa_T β BWA minimum score threshold
seed_start β Seed region start position (1-based)
seed_end β Seed region end position (1-based)
evidence_dir β When given, write a #100 transcriptome evidence envelope reporting whether this execution actually completed, additive and keyword-only so the
.nfscript block that calls this function by name is unaffected.aligner β
bwa-mem2(default) or the optional plain-modebwa-mem3backend.
- Returns:
Path to output directory containing results
- sirnaforge.core.off_target.aggregate_offtarget_results(results_dir: str | Path, output_dir: str | Path, transcriptome_species: str) Path[source]ο
Aggregate transcriptome off-target analysis results using Pandera.
Uses pandas + Pandera for efficient bulk reading and validation instead of manual line-by-line parsing with Pydantic models.
NOTE: This function ONLY aggregates transcriptome hits. miRNA results are aggregated separately by aggregate_mirna_results() to keep output files distinct and properly typed.
Rejecting a file is a fact about a species, not a log line. A per-species
*_analysis.tsvthat cannot be read (the 0-byte fileofftarget_analysis.nfβs stub emits, or one the schema rejects) must not leave the species reading as screened and clean:species_screenedandrejected_species_filescarry that verdict.- Parameters:
results_dir β Directory containing individual analysis results
output_dir β Directory to write aggregated results
transcriptome_species β Comma-separated list of species screened
- Returns:
Path to output directory containing aggregated results
- sirnaforge.core.off_target.scan_mirna_seed_matches(sequences: dict[str, str], mirna_sequences: dict[str, str], *, backend: MiRNASeedBackend | str = MiRNASeedBackend.PYAHOCORASICK, seed_start: int = 2, seed_end: int = 8, max_mismatches: int = 2, max_hits: int | None = None) list[dict[str, Any]][source]ο
Scan miRNA FASTA records using an in-process seed-scanning backend.
The returned rows preserve the existing internal hit shape used by miRNA analysis, so callers can continue adapting them to DataFrame-based outputs.
- sirnaforge.core.off_target.run_mirna_seed_analysis(candidates_file: str | Path, candidate_id: str, mirna_db: str, mirna_species: list[str], output_dir: str | Path, backend: MiRNASeedBackend | str = MiRNASeedBackend.PYAHOCORASICK, seed_start: int = 2, seed_end: int = 8, *, evidence_dir: str | Path | None = None, reference_manifest: str | Path | None = None) Path[source]ο
Run miRNA seed match analysis for candidate sequences.
This function uses the MiRNADatabaseManager to download and cache miRNA databases, builds BWA indices if needed, and performs seed match analysis.
The scan produces raw alignments: the guide seed window placed at every position along each miRNA. Only alignments where the guide seed lands on the miRNAβs own seed region (0-based
coord == seed_start - 1) are counted as hits in the filtered outputs and summarytotal_hits; perfect matches in non-seed regions are retained in the*_rawfiles but are not real miRNA seed off-targets.One species failing must not discard every other speciesβ already-computed results: the per-species loop below records a failure and moves on rather than aborting, and only re-raises if every requested species hit the same unavailable-backend error (#100).
Every exit from that loop writes an envelope when
evidence_diris given, including the species whose database could not be resolved.- Parameters:
candidates_file β Path to FASTA file with candidate sequences
candidate_id β Candidate identifier
mirna_db β miRNA database name (mirgenedb, mirbase, etc.)
mirna_species β List of species to analyze against
output_dir β Directory to write results
backend β miRNA seed backend to use for analysis (pyahocorasick by default)
seed_start β Seed region start position (1-based, default 2)
seed_end β Seed region end position (1-based, default 8)
reference_manifest β Optional versioned manifest of pinned local mature FASTA references.
evidence_dir β When given, write a per-species #100 mirna_seed evidence envelope for every species this run actually attempted, additive and keyword-only so the
.nfscript block that calls this function by name is unaffected.
- Returns:
Path to output directory containing results
- sirnaforge.core.off_target.aggregate_mirna_results(results_dir: str | Path, output_dir: str | Path, mirna_db: str, mirna_species: str, *, evidence_root: str | Path | None = None) Path[source]ο
Aggregate miRNA seed analysis results from multiple candidates using pandas.
Uses pandas + Pandera for efficient bulk reading and validation instead of manual line-by-line parsing with Pydantic models.
- Parameters:
results_dir β Directory containing individual miRNA analysis results
output_dir β Directory to write aggregated results
mirna_db β miRNA database used for analysis
mirna_species β Comma-separated list of species analyzed
evidence_root β Where to search for
*_evidence.jsonenvelopes, defaulting toresults_dir. Separate fromresults_dirbecause a caller may stage only the*_mirna_analysis.tsv/*_mirna_summary.jsonfiles into a directory of its own while the envelopes stay in the aggregation taskβs cwd (#100): searching the staging directory then found nothing and every requested species read as screened whatever happened.
- Returns:
Path to output directory containing aggregated results
ZFN Designο
Warning
EXPERIMENTAL. Every sirnaforge.zfn.* and sirnaforge.models.zfn API below is
experimental in 0.6.0 with known unfixed defects, tracked in
#82. Do not use ZFN output for any
decision without independent validation. Calling
sirnaforge.zfn.design.ZFNDesigner.evaluate_pair() logs the full notice at WARNING
on first use in a process. Two defects that change nothing visible in the returned objects:
ZFNCandidate.worst_site_score / best_offtarget_score are inverted (minimum and
maximum site score respectively, whereas the highest-scoring off-target is the most
dangerous one), and right_half_site must be supplied as the reverse complement of its
published plus-strand text or it matches nothing. See ZFN Module Guide.
Experimental-status notice for the ZFN arm.
This lives in its own module rather than in sirnaforge.zfn.__init__ because the
package __init__ imports design, and design has to emit the notice too β
reaching back into the package from one of its own submodules would be circular.
The notice is emitted at most once per process. Every ZFN entry point calls
emit_zfn_experimental_warning(), so whichever one a caller happens to reach first
carries the text, and the ones layered beneath it (CLI -> workflow -> designer) do not
repeat it. It is a statement about the moduleβs status, not about a result, so repeating
it per candidate or per run would only train users to skip it.
βOnceβ means once as the user sees it, not once per log record. When a rich console is
supplied, the log record and the panel would otherwise both land on the same terminal
stream and print the whole notice twice β sirnaforge.utils.logging_utils attaches a
StreamHandler(sys.stdout) to the root logger on first get_logger call, and rich
writes to sys.stdout too. emit_zfn_experimental_warning() therefore keeps the
log record (so log files, caplog and library callers still get it) but mutes, for that
one record only, the handlers writing to the consoleβs own stream.
Where the notice lands with no console: wherever the host applicationβs logging sends
WARNING. Under sirnaforgeβs own get_logger()
that is stdout, not stderr β because a handler is always installed, loggingβs
last-resort stderr handler never fires.
- sirnaforge.zfn.experimental.emit_zfn_experimental_warning(console: Console | None = None) bool[source]ο
Announce the ZFN armβs experimental status, at most once per process.
The notice is logged at
WARNINGon every path, so it reaches log files and any handler the host application configured. It is rendered to the terminal exactly once: with aconsolethe user sees the rich panel, without one they see whatever the log handlers show (stdout, under sirnaforgeβs own logging setup).- Parameters:
console β Rich console to render a highlighted notice on. Omit it for library callers β the warning still reaches the log.
- Returns:
True if this call emitted the notice, False if an earlier call already did.
- sirnaforge.zfn.experimental.reset_zfn_experimental_warning() None[source]ο
Re-arm the once-per-process latch. For tests that exercise several ZFN entry points.
High-level ZFN pair evaluation workflow.
- class sirnaforge.zfn.design.ZFNDesigner(searcher: ZFNOffTargetSearcher | None = None)[source]ο
Bases:
objectEvaluate one provided ZFN pair with exhaustive off-target search.
- __init__(searcher: ZFNOffTargetSearcher | None = None) None[source]ο
Initialize with a searcher implementation.
- evaluate_pair(params: ZFNDesignParameters, annotation: GenomicAnnotationConfig | None = None) ZFNDesignResult[source]ο
Run end-to-end pair evaluation and return typed results.
- build_candidate(params: ZFNDesignParameters, sites: list[ZFNOffTargetSite]) ZFNCandidate[source]ο
Public wrapper for candidate-summary construction.
- score_manufacturability(params: ZFNDesignParameters) float[source]ο
Public wrapper for manufacturability scoring logic.
ZFN Searchο
Exhaustive ZFN off-target search implementation for provided half-sites.
- sirnaforge.zfn.search.build_zfn_search_index(*, backend: ZFNSearchBackend, genome_fasta: Path, output_dir: Path | None = None) dict[str, Any][source]ο
Build a persisted search-space index bundle for indexed ZFN backends.
- sirnaforge.zfn.search.resolve_target_contigs(contig_names: list[str], requested: list[str]) list[str][source]ο
Resolve requested chromosome filters against loaded contig names.
- sirnaforge.zfn.search.build_zfn_shard_specs(contig_lengths: dict[str, int], params: ZFNDesignParameters) list[_ShardSpec][source]ο
Build chromosome/chunk shard specs from contig lengths.
This is the authoritative shard planning logic shared by the direct Python searcher and external orchestration layers such as Nextflow.
- class sirnaforge.zfn.search.ExhaustiveZFNOffTargetSearcher(annotation_provider: ZFNAnnotationProvider | None = None)[source]ο
Bases:
objectExhaustive sliding-window off-target search for a provided ZFN pair.
- __init__(annotation_provider: ZFNAnnotationProvider | None = None) None[source]ο
Initialize searcher with optional annotation provider.
- search(params: ZFNDesignParameters, annotation: GenomicAnnotationConfig | None = None) list[ZFNOffTargetSite][source]ο
Search all predicted cut sites with explicit mismatch + spacer constraints.
- search_region(params: ZFNDesignParameters, chrom: str, scan_start0: int, scan_end0: int, core_start0: int | None = None, core_end0: int | None = None, annotation: GenomicAnnotationConfig | None = None, top_n_sites: int | None = None) list[ZFNOffTargetSite][source]ο
Search one bounded genomic region using the same core engine as full search.
The region is scanned across
scan_start0..scan_end0and then filtered to the optional core window so overlapping shards can share context without double-reporting the same site.
ZFN Rankingο
Ranking utilities for ZFN off-target sites.
This module centralizes deterministic site ordering for reporting/regression use. The tie-break behavior follows the PROGNOS-inspired policy used in tests:
Higher score first.
Region priority for equal scores: Exon > Promoter > Intron > Intergenic > Unknown.
Chromosomal location ordering.
- sirnaforge.zfn.rank.rank_sites(sites: Sequence[ZFNOffTargetSite], params: ZFNDesignParameters | None = None) list[ZFNOffTargetSite][source]ο
Rank off-target sites with score-first ordering and deterministic tie-breaks.
- Parameters:
sites β Candidate sites to rank.
params β Optional design parameters. Currently only used to keep a typed, future-proof API for algorithm-specific ranking extensions.
- Returns:
A new sorted list of sites.
ZFN Annotationο
GTF/GFF-backed annotation provider for ZFN off-target sites.
- class sirnaforge.zfn.annotation.GTFZFNAnnotationProvider[source]ο
Bases:
objectAnnotate predicted ZFN sites using local GTF/GFF intervals.
- annotate(sites: list[ZFNOffTargetSite], config: GenomicAnnotationConfig) list[ZFNOffTargetSite][source]ο
Attach region and nearest gene labels to each site.
ZFN Interfacesο
Interfaces for ZFN off-target search and annotation engines.
- class sirnaforge.zfn.interfaces.ZFNOffTargetSearcher(*args, **kwargs)[source]ο
Bases:
ProtocolProtocol for ZFN off-target site searchers.
- search(params: ZFNDesignParameters, annotation: GenomicAnnotationConfig | None = None) list[ZFNOffTargetSite][source]ο
Return predicted off-target cut sites for a provided ZFN pair.
- __init__(*args, **kwargs)ο
- class sirnaforge.zfn.interfaces.ZFNAnnotationProvider(*args, **kwargs)[source]ο
Bases:
ProtocolOptional protocol for site-level region annotation.
- annotate(sites: list[ZFNOffTargetSite], config: GenomicAnnotationConfig) list[ZFNOffTargetSite][source]ο
Attach region and nearest-gene annotation to predicted sites.
- __init__(*args, **kwargs)ο
ZFN Nextflow Bridgeο
Typed Python bridge for ZFN Nextflow modules.
These helpers keep domain logic in Python while Nextflow handles process orchestration.
- class sirnaforge.zfn.nextflow_bridge.ZFNShardRow(shard_id: str, chrom: str, core_start_1: int, core_end_1: int, scan_start_1: int, scan_end_1: int, max_mismatches: int)[source]ο
Bases:
objectOne row in the ZFN shard manifest.
- sirnaforge.zfn.nextflow_bridge.make_zfn_shard_manifest(*, genome_fasta: Path, left_half_site: str, right_half_site: str, spacer_lengths: str, max_mismatches: int, sharding_enabled: str | bool, shard_chunk_mb: float, shard_overlap_bp: int, shard_chromosomes: str, output_tsv: Path) dict[str, int | bool][source]ο
Build shard TSV for ZFN search.
Sharding is applied whenever enabled, including for single-contig references. The direct Python searcher remains authoritative for overlap and chunk planning.
- sirnaforge.zfn.nextflow_bridge.run_zfn_shard_search(*, shard_id: str, shard_chrom: str, scan_start_1: int, scan_end_1: int, core_start_1: int | None = None, core_end_1: int | None = None, shard_max_mismatches: int, left_half_site: str, right_half_site: str, genome_fasta: Path, search_backend: ZFNSearchBackend, search_space_index: Path | None, algorithm: ZFNAlgorithm, dimer_mode: DimerMode, spacer_lengths: str, annotation_file: Path | None, output_sites_csv: Path, output_summary_json: Path, params: ZFNDesignParameters | None = None) dict[str, int | str][source]ο
Execute one shard search and persist shard-scoped outputs.
The search scans
scan_start_1..scan_end_1(1-based, inclusive) for sequence context, but only sites whose start lies within the core window (core_start_1..core_end_1) are written to output. This prevents duplicate sites across overlapping shards. Whencore_start_1orcore_end_1are not provided they default to the scan boundaries.
ZFN Benchmark Dataο
Typed ingestion helpers for CCR5 ZFN benchmark tables (PROGNOS supplementary extracts).
- class sirnaforge.zfn.benchmark_data.CCR5S10VisibleRow(closest_gene: str, match_type: MatchType, chrom: str, pos_hg19: int, plus_half_site: str, minus_half_site: str, empty_indels: int | None, empty_total: int | None, active_indels: int | None, active_total: int | None, active_mutation_freq_percent: float | None, p_value: float | None, notes: str, sequencing_failure: bool)[source]ο
Bases:
objectOne visible row from the extracted S10 CCR5 off-target validation table.
- __init__(closest_gene: str, match_type: MatchType, chrom: str, pos_hg19: int, plus_half_site: str, minus_half_site: str, empty_indels: int | None, empty_total: int | None, active_indels: int | None, active_total: int | None, active_mutation_freq_percent: float | None, p_value: float | None, notes: str, sequencing_failure: bool) Noneο
- class sirnaforge.zfn.benchmark_data.CCR5S11HomologyRow(homology_rank: int, t_mismatches: int, plus_mismatches: int, minus_mismatches: int, interrogated_by: str, closest_gene: str, match_type: MatchType, chrom: str, pos_hg19: int, plus_half_site: str, minus_half_site: str)[source]ο
Bases:
objectOne visible row from the S11 homology ranking extract.
- class sirnaforge.zfn.benchmark_data.MatchType(left: Literal['L', 'R'], spacer_len: int, right: Literal['L', 'R'])[source]ο
Bases:
objectStructured representation of PROGNOS match type, e.g.
L-5-R.
- sirnaforge.zfn.benchmark_data.load_ccr5_s10_visible_rows(path: str | Path) list[CCR5S10VisibleRow][source]ο
Load visible S10 rows from CSV into typed records.
- sirnaforge.zfn.benchmark_data.load_ccr5_s11_homology_rows(path: str | Path) list[CCR5S11HomologyRow][source]ο
Load visible S11 homology rows from CSV into typed records.
Data Modelsο
SiRNA Modelsο
Pydantic models for siRNA design data structures.
- class sirnaforge.models.sirna.SelectionState(*values)[source]ο
-
What the resolved selection was willing to claim about a candidate (#100).
Distinct from
passes_filters, which only answers whether a gate rejected the candidate: a candidate can pass every gate it was subject to and still not be exportable as a result, because the evidence behind those gates was never completed rather than adverse.- Variables:
ELIGIBLE β Every gate the run required was decided, and none rejected the candidate.
PROVISIONAL β An exploratory run scored the candidate ahead of incomplete evidence; the label keeps that scope explicit instead of reporting it identically to ELIGIBLE.
WITHHELD β A qualified run required evidence that never became available, so the candidate cannot be claimed even though nothing rejected it.
NOT_ELIGIBLE β A gate actively rejected the candidate.
NOT_SELECTED β Selection never ran over this candidate. The model default.
- ELIGIBLE = 'eligible'ο
- PROVISIONAL = 'provisional_incomplete_evidence'ο
- WITHHELD = 'withheld_incomplete_evidence'ο
- NOT_ELIGIBLE = 'not_eligible'ο
- NOT_SELECTED = 'not_selected'ο
- class sirnaforge.models.sirna.FilterCriteria(*, gc_min: Annotated[float, Ge(ge=0), Le(le=100)] = 35.0, gc_max: Annotated[float, Ge(ge=0), Le(le=100)] = 60.0, max_poly_runs: Annotated[int, Ge(ge=1)] = 3, max_repeat_transcript_fraction: Annotated[float, Gt(gt=0), Le(le=1)] = 0.001, max_paired_fraction: Annotated[float, Ge(ge=0), Le(le=1)] = 0.6, min_asymmetry_score: Annotated[float, Ge(ge=0), Le(le=1)] = 0.65, min_empirical_score: Annotated[float, Ge(ge=0.4), Le(le=0.6)] = 0.4, min_isoform_coverage: Annotated[float | None, Ge(ge=0), Le(le=1)] = None)[source]ο
Bases:
BaseModelQuality filters for siRNA candidate selection based on thermodynamic and empirical criteria.
- min_asymmetry_score: floatο
a second uncalibrated number above 0 would forbid what the field description above already permits.
--filter-action min_asymmetry_score=offis not equivalent:offdisables the gate (manifest records nothing evaluated), while floor=0 keeps it declared, applied and reportingasymmetry_scoreon every row.- Type:
Floor is 0, not e.g. 0.3 (#101)
- classmethod gc_max_greater_than_min(v: float, info: ValidationInfo) float[source]ο
Validate that gc_max is greater than or equal to gc_min.
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.OffTargetFilterCriteria(*, species_liability_limits: dict[str, ~sirnaforge.models.sirna.OffTargetFilterCriteria.SpeciesLiabilityLimits]=<factory>, max_off_target_count: Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, max_transcriptome_hits_0mm: Annotated[int | None, ~annotated_types.Ge(ge=0)] = 1, max_transcriptome_hits_1mm: Annotated[int | None, ~annotated_types.Ge(ge=0)] = 10, max_transcriptome_hits_2mm: Annotated[int | None, ~annotated_types.Ge(ge=0)] = 50, max_transcriptome_seed_perfect: Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, max_transcript_seed_sites: Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, max_mirna_perfect_seed: Annotated[int | None, ~annotated_types.Ge(ge=0)] = 0, max_mirna_1mm_seed: Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, fail_on_high_risk_mirna: bool = True, max_total_offtarget_hits: Annotated[int | None, ~annotated_types.Ge(ge=0)] = None)[source]ο
Bases:
BaseModelFiltering criteria for off-target analysis results.
Controls which siRNA candidates fail due to excessive off-target potential.
- class SpeciesLiabilityLimits(*, transcriptome_hits_0mm: Annotated[int | None, Ge(ge=0)] = None, transcriptome_hits_1mm: Annotated[int | None, Ge(ge=0)] = None, transcriptome_hits_2mm: Annotated[int | None, Ge(ge=0)] = None, transcript_seed_sites: Annotated[int | None, Ge(ge=0)] = None, transcript_seed_transcripts: Annotated[int | None, Ge(ge=0)] = None, transcript_seed_genes: Annotated[int | None, Ge(ge=0)] = None, action: FilterAction = FilterAction.FAIL)[source]ο
Bases:
BaseModelUncalibrated, user-supplied ceilings for one speciesβ independent liability channels.
- model_config = {'extra': 'forbid', 'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- action: FilterActionο
- require_at_least_one_limit() SpeciesLiabilityLimits[source]ο
Reject empty per-species entries instead of implying a configured gate.
- species_liability_limits: dict[str, SpeciesLiabilityLimits]ο
- classmethod canonicalize_species_liability_keys(value: Any) Any[source]ο
Normalize species aliases and reject aliases that collide after normalization.
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.WeightVector[source]ο
Bases:
BaseModelA named, hand-authored weight vector over one explicit term set.
Nothing in siRNAforge scales, renormalises or divides these numbers at runtime. A vector that does not already sum to 1.0, or that carries no name, is a construction-time error β which is what makes the weight recorded in the manifest the weight that actually applied.
Subclasses declare
VECTOR_NAMEandTERM_NAMES; the validator below reads both, so a subclass cannot forget either and still be usable.- model_config = {'extra': 'forbid', 'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- named_and_normalised() WeightVector[source]ο
Reject an unnamed, empty or mis-summed vector at construction.
- class sirnaforge.models.sirna.DesignWeights(*, target_accessibility: Annotated[float, Ge(ge=0), Le(le=1)] = 0.35, asymmetry: Annotated[float, Ge(ge=0), Le(le=1)] = 0.4, gc_content: Annotated[float, Ge(ge=0), Le(le=1)] = 0.25)[source]ο
Bases:
WeightVectorThe experimental design-stage vector over the three terms computable before screening.
Not comparable with the post-screen vectors below β different term set, different weights on shared terms β see the comparability note on
SiRNACandidate.design_score/composite_score.- model_config = {'extra': 'forbid', 'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.PostScreenSiRNAWeights(*, off_target: Annotated[float, Ge(ge=0), Le(le=1)] = 0.25, target_accessibility: Annotated[float, Ge(ge=0), Le(le=1)] = 0.1, asymmetry: Annotated[float, Ge(ge=0), Le(le=1)] = 0.3, gc_content: Annotated[float, Ge(ge=0), Le(le=1)] = 0.35)[source]ο
Bases:
WeightVectorThe active experimental siRNA post-screen vector: design terms plus
off_target.Experimental: the OligoGym panel fit is small, Martinelli is not target-identity-qualified, and no held-out replication has promoted it.
off_targetis fixed at 0.25 as a specificity policy term; the remaining budget favours asymmetry and GC content over accessibility.Named for its exact terms/numbers, not
legacy/currentβ the enclosing scoring profile, not the vector name, says which vectors are active for a given build.- TERM_NAMES: ClassVar[tuple[str, ...]] = ('off_target', 'target_accessibility', 'asymmetry', 'gc_content')ο
- model_config = {'extra': 'forbid', 'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.PostScreenMiRNAWeights(*, off_target: Annotated[float, Ge(ge=0), Le(le=1)] = 0.2, target_accessibility: Annotated[float, Ge(ge=0), Le(le=1)] = 0.08, asymmetry: Annotated[float, Ge(ge=0), Le(le=1)] = 0.24, gc_content: Annotated[float, Ge(ge=0), Le(le=1)] = 0.28, ago_start: Annotated[float, Ge(ge=0), Le(le=1)] = 0.1, supp_13_16: Annotated[float, Ge(ge=0), Le(le=1)] = 0.1)[source]ο
Bases:
WeightVectorThe experimental miRNA-biogenesis-aware post-screen vector, with 6 declared terms.
Hand-authored, not derived from the siRNA post-screen vector by scaling. The shared terms are exactly
0.80 x postscreen_sirna_experimental_v1(0.20 / 0.08 / 0.24 / 0.28);ago_startandsupp_13_16hold 0.10 each, so the biogenesis budget is 0.20 and the shared budget 0.80.pos1_mismatch(removed, issue #102) held 0.05 while scoring exactly 0.0 for every one of 13,415 candidates in the public baseline (0.000% of variance): the passenger is the exact reverse complement of the guide, so guide position 1 always Watson-Crick pairs, and a term that ranks nothing must not consume weight.biogenesis_featuresstill computes it and the row still carries the pairing state (guide_pos1_base/pos1_pairing_state), so the term can return if the designer ever builds deliberately mismatched passengers; its now-null contribution column isscore_pos1_mismatch.Declared expert priors, reviewed and accepted, not fitted to any dataset; bump SCORING_WEIGHT_SET_VERSION if these numbers change.
- TERM_NAMES: ClassVar[tuple[str, ...]] = ('off_target', 'target_accessibility', 'asymmetry', 'gc_content', 'ago_start', 'supp_13_16')ο
- model_config = {'extra': 'forbid', 'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.ScoringWeights(*, design: DesignWeights = <factory>, postscreen_sirna: PostScreenSiRNAWeights = <factory>, postscreen_mirna: PostScreenMiRNAWeights = <factory>)[source]ο
Bases:
BaseModelThe named experimental weight vectors this run may score with, one per stage and mode.
A vector is chosen, never combined:
vector_forreturns exactly one, its name is stamped on the candidate and written to the manifest, and the scorer requires every term it declares. There is deliberately no flat weight attribute here β a single flat vector is what let the scorer renormalise over βwhichever terms happened to be populatedβ.- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- design: DesignWeightsο
- postscreen_sirna: PostScreenSiRNAWeightsο
- postscreen_mirna: PostScreenMiRNAWeightsο
- vector_for(*, post_screen: bool, design_mode: DesignMode | None = None) WeightVector[source]ο
Return the one vector that applies, by stage and design mode.
The design stage uses a single vector in every mode: the miRNA biogenesis terms need screening-independent inputs but are only meaningful against the post-screen term set, and giving miRNA mode its own design vector would make two design_scores incomparable.
- all_vectors() tuple[WeightVector, ...][source]ο
Every declared vector, for manifest recording and whole-config validation.
- class sirnaforge.models.sirna.TargetAccessibilityConfig(*, window_size: Annotated[int, Ge(ge=20), Le(le=1000)] = 150, max_bp_span: Annotated[int, Ge(ge=10), Le(le=1000)] = 100, log_floor: Annotated[float, Lt(lt=0)] = -5.0)[source]ο
Bases:
BaseModelRNAplfold settings for the target-site accessibility scoring term.
All three fields change the numeric scale of target_accessibility, so a run that alters them is not comparable with a default run. They are recorded in the run manifest via DesignParameters.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- span_within_window() TargetAccessibilityConfig[source]ο
RNAplfold silently clamps L to W, so reject the combination instead of misreporting it.
- class sirnaforge.models.sirna.DesignMode(*values)[source]ο
-
Design mode for siRNA/miRNA-biogenesis-aware workflows.
- SIRNA = 'sirna'ο
- MIRNA = 'mirna'ο
- ZFN = 'zfn'ο
- class sirnaforge.models.sirna.MiRNADesignConfig(*, gc_min: Annotated[float, Ge(ge=0), Le(le=100)] = 30.0, gc_max: Annotated[float, Ge(ge=0), Le(le=100)] = 52.0, asymmetry_min: Annotated[float, Ge(ge=0), Le(le=1)] = 0.65, max_homopolymer: Annotated[int, Ge(ge=1)] = 3, overhang: str = 'UU', modifications: str = 'standard_2ome', off_target_preset: str = 'MIRNA_SEED_7_8', enable_pri_hairpin_validation: bool = False)[source]ο
Bases:
BaseModelConfiguration preset for miRNA-biogenesis-aware siRNA design.
This config encapsulates thresholds, defaults, and scoring weights optimized for miRNA-like processing (Drosha/Dicer recognition, Argonaute loading preferences, seed-based off-target analysis).
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.sirna.DesignParameters(*, design_mode: DesignMode = DesignMode.SIRNA, sirna_length: Annotated[int, ~annotated_types.Ge(ge=19), ~annotated_types.Le(le=23)] = 21, top_n: Annotated[int | None, ~annotated_types.Ge(ge=1)] = None, filters: FilterCriteria = <factory>, offtarget_filters: OffTargetFilterCriteria = <factory>, scoring: ScoringWeights = <factory>, target_accessibility: TargetAccessibilityConfig = <factory>, avoid_snps: bool = False, check_off_targets: bool = True, predict_structure: bool = True, apply_modifications: bool = True, modification_pattern: str = 'standard_2ome', default_overhang: str = 'dTdT', snp_file: str | None = None)[source]ο
Bases:
BaseModelComplete configuration parameters for siRNA design workflow.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- design_mode: DesignModeο
- filters: FilterCriteriaο
- offtarget_filters: OffTargetFilterCriteriaο
- scoring: ScoringWeightsο
- target_accessibility: TargetAccessibilityConfigο
- class sirnaforge.models.sirna.SequenceType(*values)[source]ο
-
Categories of input sequence types for siRNA design.
- TRANSCRIPT = 'transcript'ο
- GENOMIC = 'genomic'ο
- CDS = 'cds'ο
- UTR = 'utr'ο
- class sirnaforge.models.sirna.SiRNACandidate(*, id: str, transcript_id: str, position: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], guide_sequence: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=19), ~annotated_types.MaxLen(max_length=40)], passenger_sequence: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=19), ~annotated_types.MaxLen(max_length=40)], gc_content: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)], length: ~typing.Annotated[int, ~annotated_types.Ge(ge=19), ~annotated_types.Le(le=40)], asymmetry_score: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)], duplex_stability: float | None = None, structure: str | None = None, mfe: float | None = None, paired_fraction: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = 0.0, target_accessibility_p: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, target_accessibility_p_17mer: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, target_accessibility_p_site: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, off_target_screened: bool = False, off_target_count: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, off_target_penalty: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)] = 0.0, transcriptome_hits_total: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, max_poly_run_length: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_0mm: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_1mm: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_2mm: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_0mm_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_1mm_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_2mm_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_query_le2: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, transcriptome_hits_seed_0mm: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, on_target_confirmed: bool = False, on_target_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, ortholog_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, repeat_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, undetermined_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, ortholog_species: str = '', screen_query_id: str | None = None, repeat_flagged: bool = False, repeat_transcript_fraction: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = 0.0, mirna_hits_total: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, mirna_hits_0mm_seed: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, mirna_hits_1mm_seed: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, mirna_hits_high_risk: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, mirna_hits_0mm_seed_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, mirna_hits_high_risk_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, total_offtarget_hits_query: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, guide_pos1_base: str | None = None, pos1_pairing_state: str | None = None, seed_class: str | None = None, supp_13_16_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, seed_7mer_hits: ~typing.Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, seed_8mer_hits: ~typing.Annotated[int | None, ~annotated_types.Ge(ge=0)] = None, seed_hits_weighted: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0)] = None, off_target_seed_risk_class: str | None = None, transcript_hit_count: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 1, transcript_hit_fraction: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = 1.0, isoform_coverage: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, conservation_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, component_scores: dict[str, float] = <factory>, design_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, composite_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_off_target: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_target_accessibility: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_asymmetry: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_gc_content: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_ago_start: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_pos1_mismatch: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, score_supp_13_16: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, scored_after_screening: bool = False, selection_state: str = 'not_selected', weight_set_version: str = '', weight_vector: str = '', filter_verdicts: dict[str, str] = <factory>, filter_observed: dict[str, float | None] = <factory>, passes_filters: bool | ~sirnaforge.models.sirna.SiRNACandidate.FilterStatus = True, quality_issues: list[str] = <factory>, overlapped_variants: list[dict[str, ~typing.Any]] = <factory>, allele_specific: bool = False, targeted_alleles: list[str] = <factory>, variant_mode: str | None = None, guide_metadata: ~sirnaforge.models.modifications.StrandMetadata | None = None, passenger_metadata: ~sirnaforge.models.modifications.StrandMetadata | None = None)[source]ο
Bases:
BaseModelIndividual siRNA candidate with computed thermodynamic and efficacy properties.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class FilterStatus(*values)[source]ο
-
Filter status codes for quality control.
- PASS = 'PASS'ο
- GC_OUT_OF_RANGE = 'GC_OUT_OF_RANGE'ο
- POLY_RUNS = 'POLY_RUNS'ο
- EXCESS_PAIRING = 'EXCESS_PAIRING'ο
- LOW_ASYMMETRY = 'LOW_ASYMMETRY'ο
- LOW_EMPIRICAL_SCORE = 'LOW_EMPIRICAL_SCORE'ο
- LOW_ISOFORM_COVERAGE = 'LOW_ISOFORM_COVERAGE'ο
- DIRTY_CONTROL = 'DIRTY_CONTROL'ο
- REPEAT_ELEMENT = 'REPEAT_ELEMENT'ο
- EXCESS_OFF_TARGETS = 'EXCESS_OFF_TARGETS'ο
- TRANSCRIPTOME_PERFECT_MATCH = 'TRANSCRIPTOME_PERFECT_MATCH'ο
- TRANSCRIPTOME_1MM = 'TRANSCRIPTOME_1MM'ο
- TRANSCRIPTOME_2MM = 'TRANSCRIPTOME_2MM'ο
- TRANSCRIPTOME_SEED_PERFECT = 'TRANSCRIPTOME_SEED_PERFECT'ο
- MIRNA_PERFECT_SEED = 'MIRNA_PERFECT_SEED'ο
- HIGH_RISK_MIRNA = 'HIGH_RISK_MIRNA'ο
- TOTAL_OFFTARGETS = 'TOTAL_OFFTARGETS'ο
- passes_filters: bool | FilterStatusο
- guide_metadata: StrandMetadata | Noneο
- passenger_metadata: StrandMetadata | Noneο
- classmethod validate_nucleotide_sequence(v: str) str[source]ο
Validate that sequence contains only valid nucleotides.
- classmethod warn_beyond_recommended_length(v: str) str[source]ο
Warn (do not fail) when a sequence exceeds the recommended biological max.
19-23 nt is the recommended siRNA range; longer sequences (e.g. Dicer 3β read-through isoforms) are still analyzed up to ENGINE_MAX_GUIDE_LEN.
- classmethod sequences_same_length(v: str, info: ValidationInfo) str[source]ο
Validate that passenger sequence is same length as guide sequence.
- record_filter_verdict(filter_id: str, *, observed: float | None, passed: bool, action: FilterAction, status: FilterStatus | None = None) None[source]ο
Record one gateβs own outcome, and reject only if that gateβs action says to.
passes_filterskeeps first-failure-wins: it is a single label and the first FAIL-action gate to reject a candidate owns it. That is only a display choice, because every gateβs verdict survives infilter_verdictsregardless of which label won.- Parameters:
filter_id β The declared filter this verdict belongs to.
observed β The value compared against the threshold.
Nonerecordsunknown: the gate was in force but its evidence was unavailable, which is not the same as passing.passed β Whether the comparison succeeded.
action β The resolved action for this filter. Only
FAILmay reject.status β The label to put on
passes_filterswhen this gate rejects. Required for a FAIL-action gate; a warn-action gate never needs one.
- sirnaforge.models.sirna.ranking_score(candidate: SiRNACandidate) float[source]ο
The number a candidate is currently ranked by.
composite_scorewhen screening produced it, elsedesign_score(the two are not comparable β seeSiRNACandidate.composite_score; callers holding a mixture must keep them apart, seeSiRNAWorkflow._apply_post_screen_ranking). An unscored candidate sorts last at 0.0 rather than raising: rejected candidates and pre-designed guides legitimately have neither.
- sirnaforge.models.sirna.ranking_tiebreak_key(candidate: SiRNACandidate) tuple[str, str, int, str][source]ο
Return stable biological and identity fields for equal-score candidate ordering.
Guide normalization follows repeat matching (uppercase DNA, with U converted to T). Transcript, position, and candidate ID then make rows deterministic when the guide occurs in several contexts.
- sirnaforge.models.sirna.ranking_order_key(candidate: SiRNACandidate) tuple[float, str, str, int, str][source]ο
Sort by descending ranking score, then by a stable guide/context/identity key.
- sirnaforge.models.sirna.unique_guide_representatives(candidates: list[SiRNACandidate]) list[SiRNACandidate][source]ο
Return one conservative, deterministically ranked context row per normalized guide.
The guideβs minimum score across contexts is used for ranking, so one unusually favorable transcript context cannot give the same guide multiple shortlist slots.
- sirnaforge.models.sirna.build_candidate_row(candidate: SiRNACandidate) dict[str, Any][source]ο
Map one SiRNACandidate to its canonical output-row dict.
The single source of truth for candidate CSV columns, shared by DesignResult.save_csv (the sirnaforge design path) and SiRNAWorkflow.step6_generate_reports (the sirnaforge workflow path) so the two writers cannot drift on which columns they emit. Optional attributes use a tolerant getattr since the workflow path feeds candidates from several producers.
- class sirnaforge.models.sirna.DesignResult(*, input_file: str, parameters: ~sirnaforge.models.sirna.DesignParameters, candidates: list[~sirnaforge.models.sirna.SiRNACandidate], top_candidates: list[~sirnaforge.models.sirna.SiRNACandidate], total_sequences: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], total_candidates: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], filtered_candidates: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], processing_time: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)], tool_versions: dict[str, str] = <factory>, rejected_candidates: list[~sirnaforge.models.sirna.SiRNACandidate] = <factory>)[source]ο
Bases:
BaseModelComplete results from siRNA design workflow with metadata and statistics.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- parameters: DesignParametersο
- candidates: list[SiRNACandidate]ο
- top_candidates: list[SiRNACandidate]ο
- rejected_candidates: list[SiRNACandidate]ο
- save_csv(filepath: str) DataFrame[SiRNACandidateSchema][source]ο
Save siRNA candidates to CSV file with comprehensive validation.
Exports all candidates to CSV format with full thermodynamic metrics. The DataFrame is validated against SiRNACandidateSchema before saving to ensure data integrity and proper column types.
- Parameters:
filepath β Output CSV file path
- Returns:
Validated DataFrame conforming to SiRNACandidateSchema
- Raises:
pandera.errors.SchemaError β If data validation fails
Chemical Modificationsο
Data models for siRNA chemical modifications and metadata.
This module provides structured representations for chemical modifications, overhangs, and provenance metadata associated with siRNA strands.
- class sirnaforge.models.modifications.ConfirmationStatus(*values)[source]ο
-
Confirmation status for siRNA sequence data.
- PENDING = 'pending'ο
- CONFIRMED = 'confirmed'ο
- class sirnaforge.models.modifications.SourceType(*values)[source]ο
-
Source type for siRNA provenance.
- PATENT = 'patent'ο
- PUBLICATION = 'publication'ο
- CLINICAL_TRIAL = 'clinical_trial'ο
- DATABASE = 'database'ο
- DESIGNED = 'designed'ο
- OTHER = 'other'ο
- class sirnaforge.models.modifications.Provenance(*, source_type: SourceType, identifier: str, url: str | None = None)[source]ο
Bases:
BaseModelProvenance information for siRNA sequences.
Tracks the origin and validation status of siRNA sequences.
- source_type: SourceTypeο
- to_header_string() str[source]ο
Convert provenance to FASTA header format.
- Returns:
US10060921B2β
- Return type:
Formatted string like βPatent
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.modifications.ChemicalModification(*, type: str, positions: list[int] = <factory>)[source]ο
Bases:
BaseModelChemical modification annotation for siRNA strands.
Represents a specific type of chemical modification and the positions where it occurs in the sequence.
- classmethod validate_positions(v: list[int]) list[int][source]ο
Validate positions are positive integers.
- to_header_string() str[source]ο
Convert modification to FASTA header format.
- Returns:
Formatted string like β2OMe(1,4,6,11,13,16,19)β or β2F()β for no positions
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.modifications.StrandRole(*values)[source]ο
-
Role of the siRNA strand in the duplex.
- GUIDE = 'guide'ο
- SENSE = 'sense'ο
- ANTISENSE = 'antisense'ο
- PASSENGER = 'passenger'ο
- class sirnaforge.models.modifications.StrandMetadata(*, id: str, sequence: str, overhang: str | None = None, chem_mods: list[ChemicalModification] = <factory>, notes: str | None = None, provenance: Provenance | None = None, confirmation_status: ConfirmationStatus = ConfirmationStatus.PENDING)[source]ο
Bases:
BaseModelComplete metadata for a single siRNA strand.
This model captures all relevant information about a siRNA strand including sequence, modifications, overhangs, and provenance.
- chem_mods: list[ChemicalModification]ο
- provenance: Provenance | Noneο
- confirmation_status: ConfirmationStatusο
- classmethod validate_sequence(v: str) str[source]ο
Validate sequence contains only valid nucleotides.
- validate_modification_positions() StrandMetadata[source]ο
Validate that modification positions donβt exceed sequence length.
- to_fasta_header(target_gene: str | None = None, strand_role: StrandRole | None = None) str[source]ο
Generate FASTA header with embedded metadata.
- Parameters:
target_gene β Target gene name
strand_role β Role of this strand in the duplex
- Returns:
FASTA header string with key-value pairs
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.modifications.SequenceRecord(*, target_gene: str, strand_role: StrandRole, metadata: StrandMetadata)[source]ο
Bases:
BaseModelComplete sequence record with strand metadata.
Associates a strand with its target and role information.
- strand_role: StrandRoleο
- metadata: StrandMetadataο
- to_fasta() str[source]ο
Generate complete FASTA record.
- Returns:
Multi-line FASTA string with header and sequence
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Off-Target Modelsο
Pydantic models for off-target analysis data structures.
This module provides validated data models for: - BWA alignment results (both genome and miRNA) - Aggregated off-target summaries - Analysis metadata and statistics
Using Pydantic ensures type safety, automatic validation, and clean serialization to JSON/TSV formats.
- class sirnaforge.models.off_target.AlignmentStrand(*values)[source]ο
-
Genomic strand orientation.
- FORWARD = '+'ο
- REVERSE = '-'ο
- class sirnaforge.models.off_target.AnalysisMode(*values)[source]ο
-
BWA alignment analysis mode.
- MIRNA_SEED = 'mirna_seed'ο
- TRANSCRIPTOME = 'transcriptome'ο
- class sirnaforge.models.off_target.MiRNADatabase(*values)[source]ο
-
Supported miRNA database sources.
Values correspond to database identifiers used by MiRNADatabaseManager. Using str enum allows seamless string comparison while providing validation.
- MIRGENEDB = 'mirgenedb'ο
- MIRBASE = 'mirbase'ο
- MIRBASE_HIGH_CONF = 'mirbase_high_conf'ο
- MIRBASE_HAIRPIN = 'mirbase_hairpin'ο
- TARGETSCAN = 'targetscan'ο
- class sirnaforge.models.off_target.BaseAlignmentHit(*, qname: str, qseq: str, coord: Annotated[int, Ge(ge=0)], strand: AlignmentStrand, cigar: str, mapq: Annotated[int, Ge(ge=0), Le(le=255)], as_score: int | None = None, nm: Annotated[int, Ge(ge=0)], seed_mismatches: Annotated[int, Ge(ge=0)], offtarget_score: Annotated[float, Ge(ge=0)])[source]ο
Bases:
BaseModel,ABCBase class for alignment hits with common fields and validators.
This abstract base class contains all shared fields and validation logic for both off-target and miRNA alignment hits.
- model_config = {'frozen': False, 'validate_assignment': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- strand: AlignmentStrandο
- classmethod validate_sequence(v: str) str[source]ο
Ensure sequence contains only valid nucleotide characters.
- TSV_COLUMNS: ClassVar[tuple[str, ...]]ο
The TSV column order, declared once per subclass.
to_dictis keyed on it andtsv_header()is joined from it, so a header cannot drift from the row beneath it β both are written to the same file bycore/off_target.py.
- class sirnaforge.models.off_target.OffTargetHit(*, qname: str, qseq: str, coord: Annotated[int, Ge(ge=0)], strand: AlignmentStrand, cigar: str, mapq: Annotated[int, Ge(ge=0), Le(le=255)], as_score: int | None = None, nm: Annotated[int, Ge(ge=0)], seed_mismatches: Annotated[int, Ge(ge=0)], offtarget_score: Annotated[float, Ge(ge=0)], species: str, rname: str)[source]ο
Bases:
BaseAlignmentHitSingle off-target alignment hit from BWA analysis.
Represents one potential off-target binding site identified by sequence alignment against a reference genome or transcriptome.
- TSV_COLUMNS: ClassVar[tuple[str, ...]] = ('qname', 'qseq', 'species', 'rname', 'coord', 'strand', 'cigar', 'mapq', 'as_score', 'nm', 'seed_mismatches', 'offtarget_score')ο
The TSV column order, declared once per subclass.
to_dictis keyed on it andtsv_header()is joined from it, so a header cannot drift from the row beneath it β both are written to the same file bycore/off_target.py.
- model_config = {'frozen': False, 'validate_assignment': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.MiRNAHit(*, qname: str, qseq: str, coord: Annotated[int, Ge(ge=0)], strand: AlignmentStrand, cigar: str, mapq: Annotated[int, Ge(ge=0), Le(le=255)], as_score: int | None = None, nm: Annotated[int, Ge(ge=0)], seed_mismatches: Annotated[int, Ge(ge=0)], offtarget_score: Annotated[float, Ge(ge=0)], species: str, database: MiRNADatabase | str, mirna_id: str)[source]ο
Bases:
BaseAlignmentHitSingle miRNA seed match hit from BWA analysis.
Represents a potential miRNA-like seed match identified by alignment against miRNA databases.
- database: MiRNADatabase | strο
- TSV_COLUMNS: ClassVar[tuple[str, ...]] = ('qname', 'qseq', 'species', 'database', 'mirna_id', 'coord', 'strand', 'cigar', 'mapq', 'as_score', 'nm', 'seed_mismatches', 'offtarget_score')ο
The TSV column order, declared once per subclass.
to_dictis keyed on it andtsv_header()is joined from it, so a header cannot drift from the row beneath it β both are written to the same file bycore/off_target.py.
- model_config = {'frozen': False, 'validate_assignment': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.BaseSummary(*, candidate_id: str, total_sequences: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], total_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], timestamp: str = <factory>, status: str = 'completed', evidence_status: str | None = None)[source]ο
Bases:
BaseModelBase class for analysis summary statistics with common metadata fields.
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.AnalysisSummary(*, candidate_id: str, total_sequences: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], total_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], timestamp: str = <factory>, status: str = 'completed', evidence_status: str | None = None, species: str, mode: ~sirnaforge.models.off_target.AnalysisMode, mean_mapq: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0.0), ~annotated_types.Le(le=255.0)] = None, mean_mismatches: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0)] = None, mean_seed_mismatches: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0)] = None)[source]ο
Bases:
BaseSummarySummary statistics for a single candidateβs off-target analysis.
- mode: AnalysisModeο
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.MiRNASummary(*, candidate_id: str, total_sequences: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], total_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], timestamp: str = <factory>, status: str = 'completed', evidence_status: str | None = None, mirna_database: ~sirnaforge.models.off_target.MiRNADatabase | str, species_analyzed: list[str], hits_per_species: dict[str, int] = <factory>, filtered_hits_per_species: dict[str, int] = <factory>, total_raw_alignments: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, parameters: dict[str, ~typing.Any] = <factory>)[source]ο
Bases:
BaseSummarySummary statistics for miRNA seed match analysis.
The counts come in matched pairs, and the two levels must not be mixed:
total_hitsandfiltered_hits_per_speciesare seed-region hits, whiletotal_raw_alignmentsandhits_per_speciesare every alignment the scan produced. Each total is the sum of its own per-species mapping. Every species inspecies_analyzedappears in both mappings, reading 0 when it contributed nothing β an absent key would be indistinguishable from a species that was screened and came back clean.Beware that
AggregatedMiRNASummary.hits_per_speciescarries the same name at the filtered level, because aggregation reads the filtered analysis files: it reconciles withfiltered_hits_per_specieshere, not withhits_per_species.- mirna_database: MiRNADatabase | strο
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.BaseAggregatedSummary(*, species_analyzed: list[str], analysis_files_processed: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], combined_tsv: ~pathlib.Path | None = None, combined_json: ~pathlib.Path | None = None, summary_file: ~pathlib.Path | None = None, timestamp: str = <factory>)[source]ο
Bases:
BaseModelBase class for aggregated analysis summaries with common fields.
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.AggregatedOffTargetSummary(*, species_analyzed: list[str], analysis_files_processed: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], combined_tsv: ~pathlib.Path | None = None, combined_json: ~pathlib.Path | None = None, summary_file: ~pathlib.Path | None = None, timestamp: str = <factory>, total_results: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], hits_per_species: dict[str, int] = <factory>, human_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, other_species_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, species_file_counts: dict[str, int] = <factory>, usable_species_file_counts: dict[str, int] = <factory>, rejected_species_files: dict[str, list[str]] = <factory>, species_screened: list[str] = <factory>, unscreened_species: list[str] = <factory>, missing_species: list[str] = <factory>, status: str = 'completed')[source]ο
Bases:
BaseAggregatedSummarySummary of aggregated off-target results across multiple candidates and genomes.
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.off_target.AggregatedMiRNASummary(*, species_analyzed: list[str], analysis_files_processed: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], combined_tsv: ~pathlib.Path | None = None, combined_json: ~pathlib.Path | None = None, summary_file: ~pathlib.Path | None = None, timestamp: str = <factory>, total_mirna_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], mirna_database: ~sirnaforge.models.off_target.MiRNADatabase | str, hits_per_species: dict[str, int] = <factory>, hits_per_candidate: dict[str, int] = <factory>, human_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, other_species_hits: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, total_candidates: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], species_screened: list[str] = <factory>, unscreened_species: list[str] = <factory>)[source]ο
Bases:
BaseAggregatedSummarySummary of aggregated miRNA results across multiple candidates.
- mirna_database: MiRNADatabase | strο
- model_config = {'frozen': False}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
ZFN Modelsο
Pydantic models for Zinc Finger Nuclease (ZFN) design and off-target search.
- class sirnaforge.models.zfn.Strand(*values)[source]ο
-
Genome strand labels for reported sites.
- PLUS = '+'ο
- MINUS = '-'ο
- class sirnaforge.models.zfn.DimerMode(*values)[source]ο
-
What dimerization outcomes to consider when enumerating cut sites.
- HETERODIMER_ONLY = 'heterodimer_only'ο
- INCLUDE_HOMODIMERS = 'include_homodimers'ο
- class sirnaforge.models.zfn.ZFNAlgorithm(*values)[source]ο
-
Off-target ranking model family for ZFN sites.
- HOMOLOGY = 'homology'ο
- CONSERVED_G = 'conserved_g'ο
- ZFN_V2 = 'zfn_v2'ο
- class sirnaforge.models.zfn.MatchOrientation(*values)[source]ο
-
Orientation/ordering of half-sites at a genomic locus.
- LR = 'L...R'ο
- RL = 'R...L'ο
- LL = 'L...L'ο
- RR = 'R...R'ο
- class sirnaforge.models.zfn.IUPACMode(*values)[source]ο
-
How degenerate bases are handled in the query.
- NONE = 'none'ο
- ALLOW_IUPAC = 'allow_iupac'ο
- EXPAND_IUPAC = 'expand_iupac'ο
- class sirnaforge.models.zfn.ZFNSearchBackend(*values)[source]ο
-
Available scan backends for ZFN half-site search.
- EXHAUSTIVE_PYTHON = 'exhaustive_python'ο
- PYAHOCORASICK = 'pyahocorasick'ο
- FM_INDEX = 'fm_index'ο
- class sirnaforge.models.zfn.ZFNHalfSiteConstraints(*, min_len: Annotated[int, Ge(ge=6)] = 9, max_len: Annotated[int, Ge(ge=6)] = 18, max_mismatches: Annotated[int, Ge(ge=0), Le(le=6)] = 2, seed_len_from_fokI: Annotated[int | None, Ge(ge=1)] = 6, seed_max_mismatches: Annotated[int | None, Ge(ge=0)] = 1, iupac_mode: IUPACMode = IUPACMode.ALLOW_IUPAC, window_stride: Annotated[int, Ge(ge=1), Le(le=50)] = 1)[source]ο
Bases:
BaseModelConstraints on one ZFN half-site.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNSpacerConstraints(*, allowed_spacer_lengths: ~typing.Annotated[list[int], ~annotated_types.MinLen(min_length=1)] = <factory>, require_opposite_strands: bool = True)[source]ο
Bases:
BaseModelSpacer constraints between Left and Right half-sites at a cleavage site.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNOffTargetFilterCriteria(*, max_total_sites: Annotated[int | None, Ge(ge=0)] = None, max_exonic_sites: Annotated[int | None, Ge(ge=0)] = None, max_promoter_sites: Annotated[int | None, Ge(ge=0)] = None, min_site_score_to_count: Annotated[float, Ge(ge=0), Le(le=100)] = 70.0)[source]ο
Bases:
BaseModelCriteria to fail a candidate ZFN due to predicted off-target burden.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNScoringWeights(*, on_target_quality: Annotated[float, Ge(ge=0), Le(le=1)] = 0.35, off_target_specificity: Annotated[float, Ge(ge=0), Le(le=1)] = 0.45, manufacturability: Annotated[float, Ge(ge=0), Le(le=1)] = 0.2)[source]ο
Bases:
BaseModelWeights for composite ZFN candidate scoring.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNMutationType(*values)[source]ο
-
Allowed mutation categories for ZFN sub-finger constraints.
- SUBSTITUTION = 'substitution'ο
- TRANSITION = 'transition'ο
- TRANSVERSION = 'transversion'ο
- INSERTION = 'insertion'ο
- DELETION = 'deletion'ο
- class sirnaforge.models.zfn.ZFNSubfingerMutationConstraint(*, subfinger_index: Annotated[int, Ge(ge=1)], max_mutations: Annotated[int, Ge(ge=0)], mutation_types: Annotated[list[ZFNMutationType], MinLen(min_length=1)])[source]ο
Bases:
BaseModelMutation allowance definition for one ZFN sub-finger.
- mutation_types: list[ZFNMutationType]ο
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNDefaultSubfingerMutationConstraint(*, max_mutations: Annotated[int, Ge(ge=0)], mutation_types: Annotated[list[ZFNMutationType], MinLen(min_length=1)])[source]ο
Bases:
BaseModelDefault mutation allowance applied to each sub-finger.
- mutation_types: list[ZFNMutationType]ο
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNOverallMutationConstraint(*, max_mutations: Annotated[int, Ge(ge=0)], mutation_types: Annotated[list[ZFNMutationType], MinLen(min_length=1)])[source]ο
Bases:
BaseModelGlobal mutation allowance applied across all sub-fingers.
- mutation_types: list[ZFNMutationType]ο
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNMutationConstraints(*, subfinger_mutations: list[ZFNSubfingerMutationConstraint] = <factory>, default_subfinger_mutation: ZFNDefaultSubfingerMutationConstraint | None = None, overall_mutations: list[ZFNOverallMutationConstraint] = <factory>)[source]ο
Bases:
BaseModelComposite container for all ZFN sub-finger and global mutation budgets.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- subfinger_mutations: list[ZFNSubfingerMutationConstraint]ο
- default_subfinger_mutation: ZFNDefaultSubfingerMutationConstraint | Noneο
- overall_mutations: list[ZFNOverallMutationConstraint]ο
- class sirnaforge.models.zfn.ZFNShardingConfig(*, enabled: bool = True, chunk_size_bp: Annotated[int, ~annotated_types.Ge(ge=1)] = 12000000, overlap_bp: Annotated[int, ~annotated_types.Ge(ge=0)] = 50, chromosomes: list[str] = <factory>, max_workers: Annotated[int, ~annotated_types.Ge(ge=1), ~annotated_types.Le(le=128)] = 2, memory_budget_gb: Annotated[float | None, ~annotated_types.Gt(gt=0)] = None, memory_reserve_gb: Annotated[float, ~annotated_types.Ge(ge=0)] = 2.0, target_cpu_utilization: Annotated[float | None, ~annotated_types.Gt(gt=0), ~annotated_types.Le(le=1)] = None, max_cpu_workers: Annotated[int | None, ~annotated_types.Ge(ge=1), ~annotated_types.Le(le=128)] = None)[source]ο
Bases:
BaseModelOptional chromosome/chunk sharding controls for scalable ZFN search.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNDesignParameters(*, search_space_reference: str | None = 'ensembl_human_hg38_primary', search_space_fasta: str | None = None, search_space_index: str | None = None, search_backend: ZFNSearchBackend = ZFNSearchBackend.PYAHOCORASICK, left_half_site: str, right_half_site: str, half_site_constraints: ZFNHalfSiteConstraints = <factory>, spacer_constraints: ZFNSpacerConstraints = <factory>, dimer_mode: DimerMode = DimerMode.HETERODIMER_ONLY, algorithm: ZFNAlgorithm = ZFNAlgorithm.ZFN_V2, top_n_sites: Annotated[int, ~annotated_types.Ge(ge=1)] = 5000, report_n_sites: Annotated[int, ~annotated_types.Ge(ge=1)] = 200, off_target_filters: ZFNOffTargetFilterCriteria = <factory>, scoring: ZFNScoringWeights = <factory>, mutation_constraints: ZFNMutationConstraints | None = None, sharding: ZFNShardingConfig = <factory>)[source]ο
Bases:
BaseModelTop-level configuration for ZFN pair evaluation and off-target search.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- search_backend: ZFNSearchBackendο
- half_site_constraints: ZFNHalfSiteConstraintsο
- spacer_constraints: ZFNSpacerConstraintsο
- algorithm: ZFNAlgorithmο
- off_target_filters: ZFNOffTargetFilterCriteriaο
- scoring: ZFNScoringWeightsο
- mutation_constraints: ZFNMutationConstraints | Noneο
- sharding: ZFNShardingConfigο
- classmethod validate_dna_bases_and_iupac(v: str) str[source]ο
Validate half-sites as DNA/IUPAC strings.
- classmethod validate_half_site_lengths(v: str, info: ValidationInfo) str[source]ο
Validate half-site lengths against configured range.
- classmethod validate_search_space_source(v: str | None) str | None[source]ο
Normalize search-space reference keys.
- classmethod validate_search_space_fasta(v: str | None) str | None[source]ο
Normalize explicit FASTA path/URL strings.
- classmethod validate_search_space_index(v: str | None) str | None[source]ο
Normalize explicit search index path strings.
- canonical_search_contract() ZFNSearchContract[source]ο
Return canonical, JSON-serializable ZFN search contract for reports/workflows.
- class sirnaforge.models.zfn.ZFNSearchContract(*, left_half_site: str, right_half_site: str, allowed_spacer_lengths: list[int], max_mismatches_per_half_site: Annotated[int, Ge(ge=0)], seed_len_from_foki: Annotated[int | None, Ge(ge=1)] = None, seed_max_mismatches: Annotated[int | None, Ge(ge=0)] = None, dimer_mode: DimerMode, algorithm: ZFNAlgorithm, search_backend: ZFNSearchBackend, require_opposite_strands: bool, orientation_convention: str)[source]ο
Bases:
BaseModelCanonical internal contract for ZFN search/ranking behavior.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- algorithm: ZFNAlgorithmο
- search_backend: ZFNSearchBackendο
- class sirnaforge.models.zfn.GenomicAnnotationConfig(*, annotation_path: str | None = None, annotation_reference: str | None = None, cache_dir: str | None = None, promoter_upstream_bp: Annotated[int, Ge(ge=0)] = 2000, promoter_downstream_bp: Annotated[int, Ge(ge=0)] = 200)[source]ο
Bases:
BaseModelOptional annotation configuration for off-target site classification.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.zfn.ZFNOffTargetSite(*, site_id: str, chrom: str, start_1based: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], end_1based: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], strand: ~sirnaforge.models.zfn.Strand, orientation: ~sirnaforge.models.zfn.MatchOrientation, spacer_len: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], sequence: str, left_mismatches: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], right_mismatches: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], left_seed_mismatches: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, right_seed_mismatches: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, left_mismatch_positions: list[int] = <factory>, right_mismatch_positions: list[int] = <factory>, total_mismatches: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)], score: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)], score_components: dict[str, float] = <factory>, dimer_compatible: bool = True, region: ~typing.Literal['exon', 'promoter', 'intron', 'intergenic', 'unknown'] = 'unknown', nearest_gene: str | None = None, left_aligned: str, right_aligned: str)[source]ο
Bases:
BaseModelOne predicted cleavage site for a ZFN pair at a genomic locus.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- orientation: MatchOrientationο
- region: Literal['exon', 'promoter', 'intron', 'intergenic', 'unknown']ο
- class sirnaforge.models.zfn.ZFNCandidate(*, id: str, left_half_site: str, right_half_site: str, allowed_spacers: list[int], predicted_sites_total: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, predicted_sites_exonic: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, predicted_sites_promoter: ~typing.Annotated[int, ~annotated_types.Ge(ge=0)] = 0, worst_site_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, best_offtarget_score: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)] = None, passes_offtarget_filters: bool | str = True, component_scores: dict[str, float] = <factory>, composite_score: ~typing.Annotated[float, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=100)], top_offtargets: list[~sirnaforge.models.zfn.ZFNOffTargetSite] = <factory>)[source]ο
Bases:
BaseModelA ZFN pair candidate with summary metrics and composite score.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- top_offtargets: list[ZFNOffTargetSite]ο
- class sirnaforge.models.zfn.ZFNDesignResult(*, parameters: ~sirnaforge.models.zfn.ZFNDesignParameters, annotation: ~sirnaforge.models.zfn.GenomicAnnotationConfig | None = None, candidates: list[~sirnaforge.models.zfn.ZFNCandidate] = <factory>, off_target_sites: list[~sirnaforge.models.zfn.ZFNOffTargetSite] = <factory>, processing_time_s: ~typing.Annotated[float, ~annotated_types.Ge(ge=0)], tool_versions: dict[str, str] = <factory>)[source]ο
Bases:
BaseModelComplete results for ZFN pair evaluation and off-target search.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- parameters: ZFNDesignParametersο
- annotation: GenomicAnnotationConfig | Noneο
- candidates: list[ZFNCandidate]ο
- off_target_sites: list[ZFNOffTargetSite]ο
Transcript Annotation Modelsο
Pydantic models for transcript annotation data structures.
- class sirnaforge.models.transcript_annotation.Interval(*, seq_region_name: str, start: Annotated[int, Ge(ge=0)], end: Annotated[int, Ge(ge=0)], strand: int | None = None)[source]ο
Bases:
BaseModelGenomic interval with start, end, and optional strand information.
- model_config = {'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.transcript_annotation.TranscriptAnnotation(*, transcript_id: str, gene_id: str, symbol: str | None = None, biotype: str | None = None, transcript_name: str | None = None, is_canonical: bool = False, seq_region_name: str, start: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], end: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], strand: int, gene_interval: ~sirnaforge.models.transcript_annotation.Interval | None = None, exons: list[~sirnaforge.models.transcript_annotation.Interval] = <factory>, cds: list[~sirnaforge.models.transcript_annotation.Interval] = <factory>, provider: str, endpoint: str | None = None, reference_choice: str | None = None)[source]ο
Bases:
BaseModelComprehensive transcript annotation from genomic databases.
Contains transcript metadata, genomic coordinates, exon/CDS structure, and source provenance for reproducibility.
- model_config = {'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.transcript_annotation.TranscriptAnnotationBundle(*, transcripts: dict[str, ~sirnaforge.models.transcript_annotation.TranscriptAnnotation]=<factory>, unresolved: list[str] = <factory>, reference_choice: ReferenceChoice)[source]ο
Bases:
BaseModelCollection of transcript annotations with resolution tracking.
Bundles multiple transcript annotations from a single query, tracks which IDs were successfully resolved, and maintains reference provenance.
- transcripts: dict[str, TranscriptAnnotation]ο
- reference_choice: ReferenceChoiceο
- model_config = {'arbitrary_types_allowed': True, 'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Variant Modelsο
Pydantic models for genomic variant data structures.
- class sirnaforge.models.variant.VariantMode(*values)[source]ο
-
Mode for how variants should be handled in siRNA design.
- TARGET = 'target'ο
- AVOID = 'avoid'ο
- BOTH = 'both'ο
- class sirnaforge.models.variant.VariantSource(*values)[source]ο
-
Trusted sources for variant data, ordered by priority.
- CLINVAR = 'clinvar'ο
- ENSEMBL = 'ensembl'ο
- DBSNP = 'dbsnp'ο
- LOCAL_VCF = 'local-vcf'ο
- class sirnaforge.models.variant.ClinVarSignificance(*values)[source]ο
-
ClinVar clinical significance classifications.
- PATHOGENIC = 'Pathogenic'ο
- LIKELY_PATHOGENIC = 'Likely pathogenic'ο
- PATHOGENIC_LIKELY_PATHOGENIC = 'Pathogenic/Likely pathogenic'ο
- UNCERTAIN_SIGNIFICANCE = 'Uncertain significance'ο
- LIKELY_BENIGN = 'Likely benign'ο
- BENIGN = 'Benign'ο
- CONFLICTING = 'Conflicting interpretations of pathogenicity'ο
- OTHER = 'Other'ο
- class sirnaforge.models.variant.EnsemblMapping(*, location: str, allele_string: str, assembly_name: str, seq_region_name: str, strand: int, start: int, end: int, coord_system: str, **extra_data: Any)[source]ο
Bases:
BaseModelEnsembl variation mapping information.
Represents genomic mapping data for a variant from the Ensembl Variation API. Contains coordinate and allele information for a specific genomic location.
- model_config = {'extra': 'allow'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.variant.EnsemblPopulationFrequency(*, population: str, frequency: Annotated[float | None, Ge(ge=0), Le(le=1)], allele_count: Annotated[int | None, Ge(ge=0)] = None, allele_number: Annotated[int | None, Ge(ge=0)] = None, allele: str | None = None, **extra_data: Any)[source]ο
Bases:
BaseModelPopulation frequency data from Ensembl.
Contains allele frequency information for a specific population from sources like 1000 Genomes, gnomAD, ExAC, etc.
- model_config = {'extra': 'allow'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.variant.EnsemblVariationResponse(*, name: str, var_class: str, source: str, most_severe_consequence: str | None, MAF: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)], minor_allele: str | None, ambiguity: str, mappings: list[~sirnaforge.models.variant.EnsemblMapping], clinical_significance: list[str] | None, synonyms: list[str] | None, evidence: list[str] | None, populations: list[~sirnaforge.models.variant.EnsemblPopulationFrequency | None] = <factory>, **extra_data: ~typing.Any)[source]ο
Bases:
BaseModelResponse model for Ensembl Variation API.
Represents the complete response from the Ensembl REST API variation endpoint. Contains variant metadata, mappings, frequencies, and clinical information.
- model_config = {'extra': 'allow'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- mappings: list[EnsemblMapping]ο
- populations: list[EnsemblPopulationFrequency | None]ο
- class sirnaforge.models.variant.ClinVarVariationResponse(*, uid: str, obj_type: str | None, accession: str | None, title: str | None, germline_classification: dict | None, clinical_impact_classification: dict | None, variation_set: list[dict] | None, genes: list[dict] | None, molecular_consequence_list: list[str] | None, **extra_data: Any)[source]ο
Bases:
BaseModelResponse model for ClinVar variation summary.
Represents the response from NCBI ClinVar E-utilities esummary endpoint. Contains clinical significance, variation details, and associated conditions.
- model_config = {'extra': 'allow'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.models.variant.VariantRecord(*, id: str | None = None, chr: str, pos: ~typing.Annotated[int, ~annotated_types.Ge(ge=1)], ref: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1)], alt: ~typing.Annotated[str, ~annotated_types.MinLen(min_length=1)], assembly: str = 'GRCh38', sources: list[~sirnaforge.models.variant.VariantSource] = <factory>, clinvar_significance: ~sirnaforge.models.variant.ClinVarSignificance | None = None, af: ~typing.Annotated[float | None, ~annotated_types.Ge(ge=0), ~annotated_types.Le(le=1)] = None, population_afs: dict[str, float] = <factory>, annotations: dict[str, ~typing.Any] = <factory>, provenance: dict[str, ~typing.Any] = <factory>)[source]ο
Bases:
BaseModelComplete variant record with annotations from multiple sources.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- sources: list[VariantSource]ο
- clinvar_significance: ClinVarSignificance | Noneο
- get_max_population_af() float | None[source]ο
Get the maximum allele frequency across all populations.
- Returns:
Maximum population-specific AF, or None if no population data available
- get_effective_af_for_mode(mode: VariantMode) float | None[source]ο
Get the effective allele frequency based on variant mode.
For βavoidβ mode: Use max population AF if available (to avoid SNPs prevalent in any geographic group), otherwise use global AF.
For βtargetβ or βbothβ modes: Use global AF (targets most common alleles).
- Parameters:
mode β Variant mode (target/avoid/both)
- Returns:
Effective allele frequency for filtering, or None if no AF data
- get_primary_source() VariantSource | None[source]ο
Get the highest priority source for this variant.
- class sirnaforge.models.variant.VariantQueryType(*values)[source]ο
-
Types of variant query identifiers.
- RSID = 'rsid'ο
- COORDINATE = 'coordinate'ο
- HGVS = 'hgvs'ο
- class sirnaforge.models.variant.VariantQuery(*, raw_input: str, query_type: VariantQueryType, rsid: str | None = None, chr: str | None = None, pos: Annotated[int | None, Ge(ge=1)] = None, ref: str | None = None, alt: str | None = None, hgvs: str | None = None, assembly: str = 'GRCh38')[source]ο
Bases:
BaseModelParsed variant query with normalized components.
- model_config = {'extra': 'forbid'}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- query_type: VariantQueryTypeο
Validation Schemasο
Pandera schemas for siRNAforge data validation.
This module defines pandera schemas for validating the structure and content of various table-like outputs from the siRNAforge pipeline.
Modern schemas using class-based approach with type annotations for improved type safety, error reporting, and maintainability.
Use schemas: MySchema.validate(df) - validation errors provide detailed feedback.
- class sirnaforge.models.schemas.SchemaConfig[source]ο
Bases:
objectCommon configuration settings for all pandera schemas.
Provides consistent validation behavior across all siRNAforge data schemas with type coercion, strict column checking, and flexible column ordering.
- coerce = Trueο
- strict = Trueο
- ordered = Falseο
- class sirnaforge.models.schemas.SiRNACandidateSchema(*args, **kwargs)[source]ο
Bases:
DataFrameModelValidation schema for siRNA candidate results (CSV output).
Ensures data integrity and biological validity of siRNA design results with comprehensive checks for sequence composition, thermodynamic parameters, and scoring metrics. Includes optimal value ranges for key metrics based on research-backed thermodynamic principles.
Expected columns include sequences, thermodynamic scores (asymmetry, MFE, duplex stability), off-target counts, and composite quality scores.
- class Config[source]ο
Bases:
SchemaConfigSchema configuration with improved error reporting.
- description = 'siRNA candidate validation schema'ο
- title = 'SiRNA Design Results'ο
- add_missing_columns = Trueο
- strict = Falseο
- name = 'SiRNACandidateSchema'ο
- on_target_hits: Series[Int64Dtype] = 'on_target_hits'ο
- ortholog_hits: Series[Int64Dtype] = 'ortholog_hits'ο
- repeat_hits: Series[Int64Dtype] = 'repeat_hits'ο
- repeat_flagged: Series[BooleanDtype] = 'repeat_flagged'ο
- seed_7mer_hits: Series[Int64Dtype] = 'seed_7mer_hits'ο
- seed_8mer_hits: Series[Int64Dtype] = 'seed_8mer_hits'ο
- scored_after_screening: Series[BooleanDtype] = 'scored_after_screening'ο
- max_poly_run_length: Series[Int64Dtype] | None = 'max_poly_run_length'ο
- undetermined_hits: Series[Int64Dtype] | None = 'undetermined_hits'ο
- transcriptome_hits_total: Series[Int64Dtype] | None = 'transcriptome_hits_total'ο
- transcriptome_hits_0mm: Series[Int64Dtype] | None = 'transcriptome_hits_0mm'ο
- transcriptome_hits_1mm: Series[Int64Dtype] | None = 'transcriptome_hits_1mm'ο
- transcriptome_hits_2mm: Series[Int64Dtype] | None = 'transcriptome_hits_2mm'ο
- transcriptome_hits_seed_0mm: Series[Int64Dtype] | None = 'transcriptome_hits_seed_0mm'ο
- transcriptome_hits_0mm_query: Series[Int64Dtype] | None = 'transcriptome_hits_0mm_query'ο
- transcriptome_hits_1mm_query: Series[Int64Dtype] | None = 'transcriptome_hits_1mm_query'ο
- transcriptome_hits_2mm_query: Series[Int64Dtype] | None = 'transcriptome_hits_2mm_query'ο
- mirna_hits_total: Series[Int64Dtype] | None = 'mirna_hits_total'ο
- mirna_hits_0mm_seed: Series[Int64Dtype] | None = 'mirna_hits_0mm_seed'ο
- mirna_hits_1mm_seed: Series[Int64Dtype] | None = 'mirna_hits_1mm_seed'ο
- mirna_hits_high_risk: Series[Int64Dtype] | None = 'mirna_hits_high_risk'ο
- mirna_hits_0mm_seed_query: Series[Int64Dtype] | None = 'mirna_hits_0mm_seed_query'ο
- mirna_hits_high_risk_query: Series[Int64Dtype] | None = 'mirna_hits_high_risk_query'ο
- total_offtarget_hits_query: Series[Int64Dtype] | None = 'total_offtarget_hits_query'ο
- max_repeat_transcript_fraction_observed: Series[float] | None = 'max_repeat_transcript_fraction_observed'ο
- max_transcriptome_hits_0mm_observed: Series[float] | None = 'max_transcriptome_hits_0mm_observed'ο
- max_transcriptome_hits_1mm_observed: Series[float] | None = 'max_transcriptome_hits_1mm_observed'ο
- max_transcriptome_hits_2mm_observed: Series[float] | None = 'max_transcriptome_hits_2mm_observed'ο
- max_transcriptome_seed_perfect_observed: Series[float] | None = 'max_transcriptome_seed_perfect_observed'ο
- classmethod check_passes_filters_values(df: DataFrame) bool[source]ο
Ensure passes_filters contains allowed filter status values.
Derives the allow-list from SiRNACandidate.FilterStatus enum to prevent drift.
- classmethod check_selection_state_values(df: DataFrame) bool[source]ο
Ensure a present selection_state column only holds SelectionState values.
Derives the allow-list from SelectionState to prevent drift. The column is declared
Optional(see above), so an older CSV that predates it is not checked at all β only a selection_state column that is actually present must spell one of the five known states.
- classmethod check_filter_verdict_values(df: DataFrame) bool[source]ο
Ensure every present
{filter_id}_verdictcolumn holds a FilterEvaluation value.Derives the allow-list from FilterEvaluation to prevent drift, mirroring check_passes_filters_values. The verdict columns are not declared as schema fields at all (#100): declaring them would let
add_missing_columnsmaterialise a column an older runβs CSV never had, so only columns actually present in the frame are checked here.
- class sirnaforge.models.schemas.ORFValidationSchema(*args, **kwargs)[source]ο
Bases:
DataFrameModelValidation schema for open reading frame analysis results (tab-delimited output).
Validates ORF detection and characterization results with proper handling of nullable fields for cases where no valid ORF is found. Includes metrics for transcript composition, ORF boundaries, codon usage, and GC content within coding regions.
Used to validate outputs from ORF analysis tools and ensure data consistency for downstream siRNA target validation.
- class sirnaforge.models.schemas.OffTargetHitsSchema(*args, **kwargs)[source]ο
Bases:
DataFrameModelDEPRECATED: Use MiRNAAlignmentSchema or GenomeAlignmentSchema instead.
Legacy validation schema for off-target analysis results (TSV output). This schema is too generic and doesnβt match actual BWA output format.
Migration Guide: - For miRNA seed analysis β Use MiRNAAlignmentSchema - For transcriptome alignments β Use GenomeAlignmentSchema
Will be removed in v0.3.0.
- class sirnaforge.models.schemas.MiRNAAlignmentSchema(*args, **kwargs)[source]ο
Bases:
DataFrameModelPandera schema for miRNA seed match alignment results (TSV/DataFrame).
Validates tabular data from BWA-MEM2 miRNA seed analysis. Each row represents one alignment between an siRNA candidate and a miRNA seed region.
Use this for: - Reading *_mirna_analysis.tsv files - Validating pandas DataFrames from miRNA analysis - Bulk operations on miRNA alignment results
Corresponding Pydantic model: models.off_target.MiRNAHit (for single rows)
- class Config[source]ο
Bases:
SchemaConfigSchema configuration.
- description = 'miRNA seed match alignment results'ο
- title = 'miRNA Alignment DataFrame'ο
- strict = Trueο
- coerce = Trueο
- name = 'MiRNAAlignmentSchema'ο
- as_score: Series[Int64Dtype] = 'as_score'ο
- class sirnaforge.models.schemas.GenomeAlignmentSchema(*args, **kwargs)[source]ο
Bases:
DataFrameModelPandera schema for genome/transcriptome off-target alignment results (TSV/DataFrame).
Validates tabular data from BWA-MEM2 genome/transcriptome analysis. Each row represents one potential off-target alignment in the genome.
Use this for: - Reading *_analysis.tsv files from genome alignment - Validating pandas DataFrames from transcriptome off-target analysis - Bulk operations on genome alignment results
strict=Trueover 12 columns, andtranscriptome/*_analysis.tsvno longer has only one shape: the workflow writes the seven classification columns back onto those files on any run whose aggregate came back header-only, so that artifact appears with 12 and with 19 columns and this schema rejects the wider one. UseAggregatedOffTargetSchema, which accepts either, unless you specifically mean to require the producerβs shape.Corresponding Pydantic model: models.off_target.OffTargetHit (for single rows)
- class Config[source]ο
Bases:
SchemaConfigSchema configuration.
- description = 'Genome/transcriptome off-target alignment results'ο
- title = 'Genome Alignment DataFrame'ο
- strict = Trueο
- coerce = Trueο
- name = 'GenomeAlignmentSchema'ο
- as_score: Series[Int64Dtype] = 'as_score'ο
- sirnaforge.models.schemas.ORTHOLOG_EVIDENCE_VALUES: tuple[str, ...] = ('gene_id', 'symbol_heuristic', 'not_applicable')ο
a symbol-heuristic ortholog is not a validated one, so the tiers are published, not assumed (#101).
- Type:
How an ORTHOLOG verdict was evidenced.
not_applicableis every non-ortholog row
- sirnaforge.models.schemas.UNCLASSIFIED_CELL_VALUE = 'not_classified'ο
What every classification column holds on a row the producer wrote and no classifier has decided. Mirrors
core.hit_annotation.UNCLASSIFIED_CELL; kept here rather than imported to avoid a models -> core dependency.
- class sirnaforge.models.schemas.AggregatedOffTargetSchema(*args, **kwargs)[source]ο
Bases:
GenomeAlignmentSchemaPandera schema for the published aggregated off-target table (combined_offtargets.tsv).
aggregate_offtarget_results β the producer, whichever entry point invokes it β writes all seven classification columns, so the published column set no longer depends on how the run was started. On a row nothing has classified yet every one of them holds
UNCLASSIFIED_CELL_VALUE, which is why each columnβs vocabulary admits it: the verdicts are filled in place by the Python workflow, not appended as new columns.The columns stay optional so a table written by an earlier version, and the per-species transcriptome/*_analysis.tsv files as the aligner writes them, still validate against this schema.
The flag columns are typed as strings over (βTrueβ, βFalseβ) deliberately: these tables are read as text, and coercing the string βFalseβ to bool yields True.
- class Config[source]ο
Bases:
SchemaConfigAccept either published shape; reject columns from neither.
- description = 'Published aggregated off-target table, with or without the classification columns'ο
- title = 'Aggregated Off-Target DataFrame'ο
- strict = Trueο
- coerce = Trueο
- name = 'AggregatedOffTargetSchema'ο
Data Accessο
Base Data Classesο
Shared base classes and utilities for genomic data analysis.
- exception sirnaforge.data.base.DatabaseError(message: str, database: str | None = None)[source]ο
Bases:
ExceptionBase exception for database-related errors.
- exception sirnaforge.data.base.DatabaseAccessError(message: str, database: str | None = None)[source]ο
Bases:
DatabaseErrorException for network/access issues (firewall, timeout, server down).
- exception sirnaforge.data.base.GeneNotFoundError(query: str, database: str | None = None)[source]ο
Bases:
DatabaseErrorException for when a gene is not found in the database.
- sirnaforge.data.base.ENSEMBL_POST_CHUNK_SIZE = 50ο
Ensembl REST accepts at most 50 identifiers per POST body on its id endpoints.
- sirnaforge.data.base.ENSEMBL_RETRY_STATUSES = frozenset({429, 500, 502, 503, 504})ο
429 is Ensemblβs per-IP rate limit and the 5xx family is a saturated or wedged backend. All of them are transient β a plain sequence fetch draws 503s under load β so retry them.
- sirnaforge.data.base.ENSEMBL_UNAVAILABLE_STATUSES = (403, 502, 503, 504)ο
Statuses that mean the host answered but will not serve this request β access denied, or a gateway with nothing behind it. A 404 is not one of them: that is an answer.
The error every caller raises for
ENSEMBL_UNAVAILABLE_STATUSES, worded once.
- sirnaforge.data.base.ensembl_session(session: ClientSession | None, timeout: int) AsyncIterator[ClientSession][source]ο
Yield
sessionwhen the caller owns one, else open one for this operation.Retrieving a gene means several requests to one host, so they share a connection instead of paying a TLS handshake each.
- async sirnaforge.data.base.ensembl_request_json(session: ClientSession, method: str, url: str, *, headers: dict[str, str], json_body: dict[str, Any] | None = None, retry_cap: int = 30) Any[source]ο
Issue a JSON request to Ensembl, retrying its transient statuses.
- Parameters:
session β Session to issue the request on
method β HTTP method (βGETβ or βPOSTβ)
url β Fully-formed request URL
headers β Request headers
json_body β JSON body for POST requests
retry_cap β Upper bound in seconds on a Retry-After the server asks for
- Returns:
Parsed JSON payload, or None when Ensembl answers 404.
- Raises:
DatabaseAccessError β For network errors, and for 429/5xx that outlive the retries
- class sirnaforge.data.base.DatabaseType(*values)[source]ο
-
Supported genomic databases.
- ENSEMBL = 'ensembl'ο
- REFSEQ = 'refseq'ο
- GENCODE = 'gencode'ο
- class sirnaforge.data.base.SequenceType(*values)[source]ο
-
Types of sequence data that can be retrieved.
- CDNA = 'cdna'ο
- CDS = 'cds'ο
- PROTEIN = 'protein'ο
- GENOMIC = 'genomic'ο
- class sirnaforge.data.base.GeneInfo(*, gene_id: str, gene_name: str | None = None, gene_type: str | None = None, chromosome: str | None = None, start: int | None = None, end: int | None = None, strand: int | None = None, description: str | None = None, database: DatabaseType)[source]ο
Bases:
BaseModelGene information model.
- database: DatabaseTypeο
- model_config = {'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.data.base.TranscriptInfo(*, transcript_id: str, transcript_name: str | None = None, transcript_type: str | None = None, gene_id: str, gene_name: str | None = None, sequence: str | None = None, length: int | None = None, database: DatabaseType, is_canonical: bool = False, canonical_source: str | None = None, canonical_release: str | None = None)[source]ο
Bases:
BaseModelTranscript information model.
- database: DatabaseTypeο
- model_config = {'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.data.base.AbstractDatabaseClient(timeout: int = 30)[source]ο
Bases:
ABCAbstract base class for database clients.
- abstractmethod async search_gene(query: str, include_sequence: bool = True) tuple[GeneInfo | None, list[TranscriptInfo]][source]ο
Search for a gene and return gene info and transcripts.
- Parameters:
query β Gene ID, gene name, or transcript ID
include_sequence β Whether to fetch transcript sequences
- Returns:
Tuple of (gene_info, transcripts)
- Raises:
DatabaseAccessError β For network/server access issues
GeneNotFoundError β When gene is not found in database
- abstractmethod async get_sequence(identifier: str, sequence_type: SequenceType = SequenceType.CDNA) str[source]ο
Get sequence for a specific identifier.
- Parameters:
identifier β Gene ID, transcript ID, etc.
sequence_type β Type of sequence to retrieve
- Returns:
Sequence string
- Raises:
DatabaseAccessError β For network/server access issues
GeneNotFoundError β When identifier is not found in database
- abstract property database_type: DatabaseTypeο
Return the database type this client handles.
- property query_species: strο
Canonical organism whose transcripts a gene query against this database returns.
Every concrete client here is wired to exactly one organism β
EnsemblClientpinsspecies=homo_sapienson every lookup,RefSeqClientappendsAND Homo sapiens[Organism]to every esearch term, andGencodeClienttargets the human GENCODE release β so the organism of a retrieved transcript set is a property of where the transcripts came from. Callers that need the βquery speciesβ must read it from here rather than infer it from the off-target species list, which is an unordered set of genomes to screen against and says nothing about the target.
- class sirnaforge.data.base.AbstractTranscriptAnnotationClient(timeout: int = 30)[source]ο
Bases:
ABCAbstract base class for transcript annotation clients.
Purpose and Scope: Provides genomic annotation metadata (exon/CDS structure, coordinates, biotype) WITHOUT fetching full transcript sequences. This is complementary to, not overlapping with, AbstractDatabaseClient which focuses on sequence retrieval.
Key Differences from GeneSearcher/AbstractDatabaseClient:
Focus: Structural annotations (exons, CDS intervals, genomic coordinates) vs. sequence data (cDNA, CDS, protein sequences)
Use Case: Enriching existing transcript metadata with genomic context vs. discovering and retrieving transcripts with sequences
Query Patterns: - By stable IDs: fetch_by_ids([βENST00000269305β]) - By genomic regions: fetch_by_regions([β17:7661779-7687550β]) vs. GeneSearcher which queries by gene name/symbol
Caching Strategy: In-memory LRU cache with TTL for transient annotation data vs. ReferenceManagerβs persistent file cache for large sequence datasets
When to Use: - Need exon/CDS boundaries for visualization or analysis - Need genomic coordinates for variant mapping - Need biotype information without full sequence download - Need to query multiple transcripts in a genomic region
When to Use GeneSearcher Instead: - Need transcript sequences for siRNA design - Need to discover transcripts by gene name/symbol - Need protein sequences or translations
- __init__(timeout: int = 30)[source]ο
Initialize transcript annotation client.
- Parameters:
timeout β Request timeout in seconds
- abstractmethod async fetch_by_ids(ids: list[str], *, species: str, reference: ReferenceChoice) TranscriptAnnotationBundle[source]ο
Fetch transcript annotations by stable IDs.
- Parameters:
ids β List of transcript or gene IDs (e.g., ENST00000269305, TP53)
species β Species name (e.g., βhomo_sapiensβ, βhumanβ)
reference β Reference assembly/release choice
- Returns:
TranscriptAnnotationBundle containing resolved annotations
- Raises:
DatabaseAccessError β For network/server access issues
- abstractmethod async fetch_by_regions(regions: list[str], *, species: str, reference: ReferenceChoice) TranscriptAnnotationBundle[source]ο
Fetch transcript annotations by genomic regions.
- Parameters:
regions β List of genomic regions in format βchr:start-endβ (e.g., β17:7661779-7687550β)
species β Species name (e.g., βhomo_sapiensβ, βhumanβ)
reference β Reference assembly/release choice
- Returns:
TranscriptAnnotationBundle containing all transcripts overlapping regions
- Raises:
DatabaseAccessError β For network/server access issues
- class sirnaforge.data.base.EnsemblClient(timeout: int = 30, base_url: str = 'https://rest.ensembl.org')[source]ο
Bases:
AbstractDatabaseClientClient for Ensembl REST API interactions.
- __init__(timeout: int = 30, base_url: str = 'https://rest.ensembl.org')[source]ο
Initialize Ensembl client.
- property database_type: DatabaseTypeο
Return the database type this client handles.
- async search_gene(query: str, include_sequence: bool = True) tuple[GeneInfo | None, list[TranscriptInfo]][source]ο
Search for a gene and return gene info and transcripts.
- async get_sequences(identifiers: list[str], sequence_type: SequenceType = SequenceType.CDNA, session: ClientSession | None = None) dict[str, str][source]ο
Get sequences for many identifiers, one POST per chunk of identifiers.
POST /sequence/idserves exactly what the per-id GET serves, but in one round trip: all 40 TP53 transcripts come back in ~13s, where fetching them one at a time takes ~350s and loses several to transient 503s.- Parameters:
identifiers β Identifiers to fetch
sequence_type β Type of sequence to retrieve
session β Session to reuse; one is opened for this call when omitted
- Returns:
Mapping of identifier to sequence. Identifiers Ensembl does not know are absent from the mapping rather than raising β the POST endpoint simply omits them.
- Raises:
DatabaseAccessError β For network/server access issues
- async get_sequence(identifier: str, sequence_type: SequenceType = SequenceType.CDNA, headers: dict | None = None, session: ClientSession | None = None) str[source]ο
Get sequence from Ensembl REST API.
- Parameters:
identifier β Gene ID, transcript ID, etc.
sequence_type β Type of sequence to retrieve
headers β Optional HTTP headers
session β Session to reuse; one is opened for this call when omitted
- Returns:
Sequence string
- Raises:
DatabaseAccessError β For network/server access issues
GeneNotFoundError β When identifier is not found in database
- class sirnaforge.data.base.RefSeqClient(timeout: int = 30, base_url: str = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils')[source]ο
Bases:
AbstractDatabaseClientClient for RefSeq database via NCBI E-utilities API.
- __init__(timeout: int = 30, base_url: str = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils')[source]ο
Initialize RefSeq client.
- property database_type: DatabaseTypeο
Return the database type this client handles.
- async search_gene(query: str, include_sequence: bool = True) tuple[GeneInfo | None, list[TranscriptInfo]][source]ο
Search for a gene and return gene info and transcripts.
- async get_sequence(identifier: str, _sequence_type: SequenceType = SequenceType.CDNA) str[source]ο
Get sequence for a specific identifier from NCBI.
- class sirnaforge.data.base.GencodeClient(timeout: int = 30, *, gtf_path: str | Path | None = None, fasta_path: str | Path | None = None, assembly: str | None = None)[source]ο
Bases:
AbstractDatabaseClientClient for GENCODE database.
- __init__(timeout: int = 30, *, gtf_path: str | Path | None = None, fasta_path: str | Path | None = None, assembly: str | None = None)[source]ο
Configure human GENCODE files explicitly or through SIRNAFORGE_GENCODE_*.
- property database_type: DatabaseTypeο
Return the database represented by the local release.
- annotation_client() LocalTranscriptModelClient[source]ο
Resolve a local structural annotation client without downloading a release.
- async search_gene(query: str, include_sequence: bool = True) tuple[GeneInfo | None, list[TranscriptInfo]][source]ο
Find a human gene, symbol, or transcript in a local GENCODE release.
- async get_sequence(identifier: str, sequence_type: SequenceType = SequenceType.CDNA) str[source]ο
Retrieve exact-version cDNA from the configured transcript FASTA.
- class sirnaforge.data.base.SequenceUtils[source]ο
Bases:
objectUtility functions for sequence analysis.
- class sirnaforge.data.base.FastaUtils[source]ο
Bases:
objectUtility functions for FASTA file operations.
- static save_sequences_fasta(sequences: list[tuple[str, str]], output_path: str | Path, line_length: int = 80) None[source]ο
Save sequences to FASTA format.
- Parameters:
sequences β List of (header, sequence) tuples
output_path β Output file path
line_length β Maximum line length for sequence
- static read_fasta(file_path: str | Path) list[tuple[str, str]][source]ο
Read sequences from FASTA file.
- Parameters:
file_path β Path to FASTA file
- Returns:
List of (header, sequence) tuples
- static parse_fasta_to_dict(file_path: str | Path) dict[str, str][source]ο
Parse FASTA file into a dictionary.
- Parameters:
file_path β Path to FASTA file
- Returns:
Dictionary mapping sequence names to sequences
- static write_dict_to_fasta(sequences: dict[str, str], output_path: str | Path) None[source]ο
Write sequences dictionary to FASTA format.
- Parameters:
sequences β Dictionary of sequence name -> sequence
output_path β Output file path
- static validate_sirna_sequences(sequences: dict[str, str], expected_length: int = 21) dict[str, str][source]ο
Validate siRNA sequences for correct length and nucleotide content.
- Parameters:
sequences β Dictionary of sequence name -> sequence
expected_length β Expected siRNA length
- Returns:
Dictionary of valid sequences
- sirnaforge.data.base.get_database_display_name(database: DatabaseType) str[source]ο
Get display name for database, handling both enum and string values.
Annotation Managerο
Genomic annotation manager built on the transcriptome/reference cache pipeline.
- class sirnaforge.data.annotation_manager.AnnotationSource(name: str, url: str, species: str, format: str = 'fasta', compressed: bool = False, description: str = '')[source]ο
Bases:
TranscriptomeSourceAnnotation-specific source model.
- class sirnaforge.data.annotation_manager.AnnotationManager(cache_dir: str | Path | None = None, cache_ttl_days: int = 30)[source]ο
Bases:
TranscriptomeManagerAnnotation manager with caching and no index-building side effects.
- SOURCE_LABEL = 'annotation'ο
Gene Searchο
Gene search and sequence retrieval from multiple databases.
- class sirnaforge.data.gene_search.GeneSearchResult(*, query: str, database: DatabaseType, gene_info: GeneInfo | None = None, transcripts: list[TranscriptInfo] = <factory>, error: str | None = None, is_access_error: bool = False)[source]ο
Bases:
BaseModelComplete gene search result.
- database: DatabaseTypeο
- transcripts: list[TranscriptInfo]ο
- model_config = {'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.data.gene_search.GeneSearcher(timeout: int = 30, max_retries: int = 3)[source]ο
Bases:
objectSearch genes and retrieve sequences from genomic databases using multiple clients.
- __init__(timeout: int = 30, max_retries: int = 3)[source]ο
Initialize gene searcher with database clients.
- Parameters:
timeout β Request timeout in seconds
max_retries β Maximum retry attempts
- clients: dict[DatabaseType, AbstractDatabaseClient]ο
- get_client(database: DatabaseType) AbstractDatabaseClient[source]ο
Get the client for a specific database.
- query_species(database: DatabaseType | None = None) str[source]ο
Canonical organism whose transcripts a gene query returns.
This is the authoritative βquery speciesβ: the organism the retrieved target transcripts belong to, read off the database that retrieved them rather than guessed from the off-target species list.
database=Noneasks the questionsearch_gene_with_fallbackasks β any of the clients may serve the query. Every client is single-organism and they all agree today, so the fallback cannot change the answer; if that ever stops being true the disagreement surfaces here (the requested databaseβs answer wins and a warning is logged) instead of silently mislabelling the target.- Parameters:
database β Database the caller intends to query, or None for the fallback chain.
- Returns:
Canonical species name (e.g.
"human").
- async search_gene_with_fallback(query: str, include_sequence: bool = True, preferred_database: DatabaseType = DatabaseType.ENSEMBL) GeneSearchResult[source]ο
Search for a gene with automatic fallback to other databases.
Tries the selected database first, then the remaining registered providers. Unavailable providers and unresolved queries continue through the remaining providers.
- Parameters:
query β Gene ID, gene name, or transcript ID
include_sequence β Whether to fetch transcript sequences
preferred_database β Provider to try before falling back
- Returns:
GeneSearchResult from the first accessible database
- async search_gene(query: str, database: DatabaseType | None = None, include_sequence: bool = True) GeneSearchResult[source]ο
Search for a gene and retrieve its isoforms.
- Parameters:
query β Gene ID, gene name, or transcript ID
database β Database to search (defaults to Ensembl)
include_sequence β Whether to fetch transcript sequences
- Returns:
GeneSearchResult with gene info and transcripts
- async search_multiple_databases(query: str, databases: list[DatabaseType] | None = None, include_sequence: bool = True) list[GeneSearchResult][source]ο
Search across multiple databases.
- Parameters:
query β Gene ID, gene name, or transcript ID
databases β List of databases to search
include_sequence β Whether to fetch sequences
- Returns:
List of search results from each database
- save_transcripts_fasta(transcripts: list[TranscriptInfo], output_path: str | Path, include_metadata: bool = True) None[source]ο
Save transcripts to FASTA format using shared utility.
- Parameters:
transcripts β List of transcript information
output_path β Output file path
include_metadata β Include metadata in FASTA headers
- sirnaforge.data.gene_search.search_gene_sync(query: str, database: DatabaseType = DatabaseType.ENSEMBL, include_sequence: bool = True) GeneSearchResult[source]ο
Synchronous wrapper for gene search.
- sirnaforge.data.gene_search.search_gene_with_fallback_sync(query: str, include_sequence: bool = True, database: DatabaseType = DatabaseType.ENSEMBL) GeneSearchResult[source]ο
Synchronous wrapper for gene search with fallback.
- sirnaforge.data.gene_search.search_multiple_databases_sync(query: str, databases: list[DatabaseType] | None = None, include_sequence: bool = True) list[GeneSearchResult][source]ο
Synchronous wrapper for multi-database search.
ORF Analysisο
ORF analysis and sequence validation for transcript sequences.
- class sirnaforge.data.orf_analysis.ORFInfo(*, start_pos: int, end_pos: int, length: int, reading_frame: int, start_codon: str, stop_codon: str, has_valid_start: bool, has_valid_stop: bool, is_complete: bool, gc_content: float)[source]ο
Bases:
BaseModelInformation about an Open Reading Frame.
- model_config = {'frozen': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.data.orf_analysis.SequenceAnalysis(*, transcript_id: str, sequence_type: SequenceType, sequence_length: int, gc_content: float, orfs: list[ORFInfo], longest_orf: ORFInfo | None = None, has_valid_orf: bool = False, cds_sequence: str | None = None, protein_sequence: str | None = None, cds_start: int | None = None, cds_end: int | None = None, utr5_length: int | None = None, utr3_length: int | None = None, sequence_region: str | None = None)[source]ο
Bases:
BaseModelComplete sequence analysis including ORF information.
- sequence_type: SequenceTypeο
- model_config = {'use_enum_values': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.data.orf_analysis.ORFAnalyzer(database_client: AbstractDatabaseClient | None = None)[source]ο
Bases:
objectAnalyze ORFs in transcript sequences and validate sequence types.
- __init__(database_client: AbstractDatabaseClient | None = None)[source]ο
Initialize ORF analyzer.
- Parameters:
database_client β Optional database client for retrieving additional sequence types
- find_orfs(sequence: str, min_length: int = 150) list[ORFInfo][source]ο
Find all ORFs in a sequence (all 3 reading frames).
- async get_additional_sequence(transcript_id: str, sequence_type: SequenceType) str | None[source]ο
Retrieve specific sequence type using the database client if available.
- Parameters:
transcript_id β Transcript identifier
sequence_type β Type of sequence to retrieve
- Returns:
Sequence string or None if not available or client not provided
- async analyze_transcript(transcript: TranscriptInfo) SequenceAnalysis[source]ο
Perform complete ORF analysis of a transcript.
- async analyze_transcripts(transcripts: list[TranscriptInfo]) dict[str, SequenceAnalysis][source]ο
Analyze multiple transcripts.
- sirnaforge.data.orf_analysis.create_orf_analyzer(database_client: AbstractDatabaseClient | None = None) ORFAnalyzer[source]ο
Create an ORF analyzer with optional database client.
- Parameters:
database_client β Optional database client for retrieving additional sequence types
- Returns:
ORFAnalyzer instance
- async sirnaforge.data.orf_analysis.analyze_multiple_transcript_orfs(transcripts: list[TranscriptInfo], database_client: AbstractDatabaseClient | None = None) dict[str, SequenceAnalysis][source]ο
Analyze ORFs in multiple transcripts.
- Parameters:
transcripts β List of transcripts to analyze
database_client β Optional database client for additional sequence retrieval
- Returns:
Dictionary mapping transcript IDs to SequenceAnalysis results
Genome Managerο
Genome reference manager built on the composable transcriptome manager core.
- class sirnaforge.data.genome_manager.GenomeManager(cache_dir: str | Path | None = None, cache_ttl_days: int = 30, auto_build_indices: bool = True)[source]ο
Bases:
TranscriptomeManagerGenome FASTA manager with caching and optional BWA-MEM2 index building.
- SOURCE_LABEL = 'genome'ο
- SOURCES = {'ensembl_human_hg38_primary': TranscriptomeSource(name='ensembl_human_hg38_primary', url='https://ftp.ensembl.org/pub/current_fasta/homo_sapiens/dna/Homo_sapiens.GRCh38.dna.primary_assembly.fa.gz', species='human', format='fasta', compressed=True, description='Ensembl human GRCh38 primary assembly genomic reference'), 'ensembl_macaque_mmul10_toplevel': TranscriptomeSource(name='ensembl_macaque_mmul10_toplevel', url='https://ftp.ensembl.org/pub/current_fasta/macaca_mulatta/dna/Macaca_mulatta.Mmul_10.dna.toplevel.fa.gz', species='macaque', format='fasta', compressed=True, description='Ensembl rhesus macaque Mmul_10 toplevel assembly genomic reference'), 'ensembl_mouse_grcm39_primary': TranscriptomeSource(name='ensembl_mouse_grcm39_primary', url='https://ftp.ensembl.org/pub/current_fasta/mus_musculus/dna/Mus_musculus.GRCm39.dna.primary_assembly.fa.gz', species='mouse', format='fasta', compressed=True, description='Ensembl mouse GRCm39 primary assembly genomic reference'), 'ensembl_rat_grcr8_toplevel': TranscriptomeSource(name='ensembl_rat_grcr8_toplevel', url='https://ftp.ensembl.org/pub/current_fasta/rattus_norvegicus/dna/Rattus_norvegicus.GRCr8.dna.toplevel.fa.gz', species='rat', format='fasta', compressed=True, description='Ensembl rat GRCr8 toplevel assembly genomic reference')}ο
- __init__(cache_dir: str | Path | None = None, cache_ttl_days: int = 30, auto_build_indices: bool = True)[source]ο
Initialize genome manager.
- Parameters:
cache_dir β Directory for genome cache
cache_ttl_days β Cache time-to-live in days
auto_build_indices β Automatically build BWA-MEM2 indices when missing
Reference Managerο
Base Reference Database Manager for shared caching functionality.
This module provides the foundation for managing reference databases (miRNA, transcriptome, genome) with automatic caching, download management, and integrity validation.
- class sirnaforge.data.reference_manager.ReferenceSource(name: str, url: str, species: str, format: str = 'fasta', compressed: bool = False, description: str = '')[source]ο
Bases:
objectBase configuration for a reference database source.
- class sirnaforge.data.reference_manager.CacheMetadata(source: ReferenceSource, downloaded_at: str, file_size: int, checksum: str, file_path: str, version: str = '1.0', extra: dict[str, Any] | None = None)[source]ο
Bases:
objectMetadata for cached reference files.
- source: ReferenceSourceο
- classmethod from_dict(data: dict[str, ~typing.Any], source_class: type[~sirnaforge.data.reference_manager.ReferenceSource] = <class 'sirnaforge.data.reference_manager.ReferenceSource'>) CacheMetadata[source]ο
Create CacheMetadata from dictionary.
- Parameters:
data β Dictionary containing metadata
source_class β Class to use for source (allows subclasses)
- class sirnaforge.data.reference_manager.ReferenceManager(cache_subdir: str, cache_dir: str | Path | None = None, cache_ttl_days: int = 30, artifact_class: str | None = None)[source]ο
-
Base class for reference database managers with caching support.
This provides common functionality for: - Cache directory management with multiple fallback locations - File downloading with retry and progress - Checksum validation - TTL-based cache invalidation - Metadata persistence
Subclasses should implement source-specific operations like filtering, indexing, or multi-source aggregation.
- __init__(cache_subdir: str, cache_dir: str | Path | None = None, cache_ttl_days: int = 30, artifact_class: str | None = None)[source]ο
Initialize the reference manager.
- Parameters:
cache_subdir β Subdirectory name under cache root (e.g., βmirnaβ, βtranscriptomesβ)
cache_dir β Directory for caching databases (default: ~/.cache/sirnaforge/{cache_subdir})
cache_ttl_days β Cache time-to-live in days
artifact_class β Producer-version scope for this cache (default: cache_subdir). One subdirectory holds one kind of artifact, so the subdirectory name is also the natural invalidation scope; override only when two managers share a directory but not a producer.
- clear_cache(confirm: bool = False) dict[str, Any][source]ο
Clear all cached files for this manager.
By default this only reports what would be removed. Set confirm=True to actually delete files.
- is_producer_version_current(meta: CacheMetadata) bool[source]ο
Whether meta was written by the producer version this build ships.
Public because it is the one question every cache consumer needs to be able to ask (and test) directly, independently of TTL and checksums.
- stale_producer_entries() list[str][source]ο
Cache keys whose recorded producer version is no longer current.
Transcriptome Managerο
Transcriptome Database Manager with local caching and automatic index building.
This module provides a clean interface for downloading, caching, and managing transcriptome FASTA files with automatic BWA-MEM2 index building and cache management.
- sirnaforge.data.transcriptome_manager.INDEX_BUILD_ERROR_KEY = 'index_build_error'ο
Result key carrying the reason an index build failed. A reference with this key has no index, so it cannot be screened against β the FASTA is not a substitute for the index it failed to become.
- class sirnaforge.data.transcriptome_manager.TranscriptomeSource(name: str, url: str, species: str, format: str = 'fasta', compressed: bool = False, description: str = '')[source]ο
Bases:
ReferenceSourceTranscriptome-specific database source configuration.
Inherits from ReferenceSource with transcriptome-specific extensions.
- class sirnaforge.data.transcriptome_manager.TranscriptomeManager(cache_dir: str | Path | None = None, cache_ttl_days: int = 90, auto_build_indices: bool = True, local_content_dedupe: bool = True, cache_subdir: str = 'transcriptomes', sources: dict[str, TranscriptomeSource] | None = None, source_label: str | None = None, aligner: str = 'bwa-mem2')[source]ο
Bases:
ReferenceManager[TranscriptomeSource]Transcriptome database manager with caching and automatic BWA-MEM2 index building.
- SOURCE_LABEL = 'transcriptome'ο
- INDEX_SUFFIXES = ('.0123', '.amb', '.ann', '.bwt.2bit.64', '.pac', '.bwt', '.sa')ο
- FILTER_URI_FRAGMENT = '#filters='ο
- UNREMOVABLE_INDEX_KEY = 'unremovable_stale_index'ο
- SOURCES = {'ensembl_human_cdna': TranscriptomeSource(name='ensembl_cdna', url='https://ftp.ensembl.org/pub/current_fasta/homo_sapiens/cdna/Homo_sapiens.GRCh38.cdna.all.fa.gz', species='human', format='fasta', compressed=True, description='Ensembl human cDNA sequences (GRCh38)'), 'ensembl_macaque_cdna': TranscriptomeSource(name='ensembl_cdna', url='https://ftp.ensembl.org/pub/current_fasta/macaca_mulatta/cdna/Macaca_mulatta.Mmul_10.cdna.all.fa.gz', species='macaque', format='fasta', compressed=True, description='Ensembl rhesus macaque cDNA sequences (Mmul_10)'), 'ensembl_mouse_cdna': TranscriptomeSource(name='ensembl_cdna', url='https://ftp.ensembl.org/pub/current_fasta/mus_musculus/cdna/Mus_musculus.GRCm39.cdna.all.fa.gz', species='mouse', format='fasta', compressed=True, description='Ensembl mouse cDNA sequences (GRCm39)'), 'ensembl_rat_cdna': TranscriptomeSource(name='ensembl_cdna', url='https://ftp.ensembl.org/pub/current_fasta/rattus_norvegicus/cdna/Rattus_norvegicus.GRCr8.cdna.all.fa.gz', species='rat', format='fasta', compressed=True, description='Ensembl rat cDNA sequences (GRCr8)')}ο
- __init__(cache_dir: str | Path | None = None, cache_ttl_days: int = 90, auto_build_indices: bool = True, local_content_dedupe: bool = True, cache_subdir: str = 'transcriptomes', sources: dict[str, TranscriptomeSource] | None = None, source_label: str | None = None, aligner: str = 'bwa-mem2')[source]ο
Initialize the transcriptome database manager.
- Parameters:
cache_dir β Directory for caching transcriptomes (default: ~/.cache/sirnaforge/transcriptomes)
cache_ttl_days β Cache time-to-live in days (default: 90 days for large files)
auto_build_indices β Automatically build BWA-MEM2 indices when missing
aligner β Index backend; BWA-MEM2 remains the default.
local_content_dedupe β Reuse cached local files by content hash across different input paths
cache_subdir β Cache subdirectory override for composable manager reuse
sources β Optional source dictionary override
source_label β Optional source label used in status/error reporting
- sources: dict[str, TranscriptomeSource]ο
- describe_source_status(source_name: str) dict[str, Any][source]ο
Return cache metadata for a configured source.
- describe_sources_status(source_names: list[str] | tuple[str, ...] | None = None) list[dict[str, Any]][source]ο
Return cache statuses for multiple transcriptome sources.
- get_transcriptome(source_name: str, force_refresh: bool = False, build_index: bool = True) dict[str, Any] | None[source]ο
Get transcriptome database, downloading and building index if needed.
- Parameters:
source_name β Pre-configured source name (e.g., βensembl_human_cdnaβ)
force_refresh β Force re-download even if cached
build_index β Build BWA-MEM2 index if missing
- Returns:
Dictionary with βfastaβ and optionally βindexβ paths, or None if failed
- get_custom_transcriptome(fasta_path: str | Path, build_index: bool = True, cache_name: str | None = None) dict[str, Any] | None[source]ο
Process a custom transcriptome FASTA with caching and index building.
- Parameters:
fasta_path β Path or URL to transcriptome FASTA file
build_index β Build BWA-MEM2 index if missing
cache_name β Custom cache name (default: derived from filename)
- Returns:
Dictionary with βfastaβ and optionally βindexβ paths, or None if failed
- get_filtered_transcriptome(source_name: str, filters: list[str], force_refresh: bool = False, build_index: bool = True) dict[str, Any] | None[source]ο
Get a filtered transcriptome with caching.
- Parameters:
source_name β Pre-configured source name (e.g., βensembl_human_cdnaβ)
filters β List of filter names (e.g., [βprotein_codingβ, βcanonical_onlyβ])
force_refresh β Force re-download and re-filter
build_index β Build BWA-MEM2 index if missing
- Returns:
Dictionary with βfastaβ and optionally βindexβ paths, or None if failed
- list_available_sources() dict[str, TranscriptomeSource][source]ο
List all pre-configured transcriptome sources.
Transcriptome Filterο
Transcriptome filtering utilities for reducing reference size.
Provides functions to filter transcriptome FASTA files based on: - Biotype (protein_coding, etc.) - Canonical transcript status - Specific regions (e.g., 3β UTR)
This helps reduce memory requirements for BWA-MEM2 indexing on low-RAM machines.
- class sirnaforge.data.transcriptome_filter.TranscriptFilter[source]ο
Bases:
objectFilter transcripts based on header metadata and biotype.
- static parse_ensembl_header(description: str) dict[str, str][source]ο
Parse Ensembl FASTA header to extract metadata.
- Parameters:
description β Full FASTA description line (without β>β)
- Returns:
Dictionary of parsed fields (gene_biotype, transcript_biotype, gene_symbol, etc.)
- static is_protein_coding(record: SeqRecord) bool[source]ο
Check if transcript is protein coding.
- Parameters:
record β SeqRecord from FASTA
- Returns:
True if protein_coding, False otherwise
- static is_canonical(record: SeqRecord) bool[source]ο
Check if transcript is canonical (MANE Select or Ensembl canonical).
- Parameters:
record β SeqRecord from FASTA
- Returns:
True if canonical, False otherwise
- static filter_fasta(input_fasta: Path, output_fasta: Path, filter_func: Callable[[SeqRecord], bool], filter_name: str = 'custom') int[source]ο
Filter FASTA file using a custom filter function.
- Parameters:
input_fasta β Path to input FASTA file
output_fasta β Path to output FASTA file
filter_func β Function that returns True for records to keep
filter_name β Name of filter for logging
- Returns:
Number of sequences kept
- static apply_protein_coding_filter(input_fasta: Path, output_fasta: Path) int[source]ο
Filter to protein-coding transcripts only.
- Parameters:
input_fasta β Path to input FASTA file
output_fasta β Path to output FASTA file
- Returns:
Number of sequences kept
- static apply_canonical_filter(input_fasta: Path, output_fasta: Path) int[source]ο
Filter to canonical transcripts only.
- Parameters:
input_fasta β Path to input FASTA file
output_fasta β Path to output FASTA file
- Returns:
Number of sequences kept
- static apply_combined_filter(input_fasta: Path, output_fasta: Path, filters: list[str]) int[source]ο
Apply multiple filters in sequence.
- Parameters:
input_fasta β Path to input FASTA file
output_fasta β Path to output FASTA file
filters β List of filter names (e.g., [βprotein_codingβ, βcanonical_onlyβ])
- Returns:
Number of sequences kept
- sirnaforge.data.transcriptome_filter.get_filter_spec(filter_string: str | None) list[str][source]ο
Parse filter specification string into list of filter names.
- Parameters:
filter_string β Comma-separated filter names (e.g., βprotein_coding,canonical_onlyβ)
- Returns:
List of filter names, or empty list if None
Transcript Annotationsο
Transcript annotation providers using Ensembl REST and optional VEP enrichment.
This module provides clients for fetching genomic transcript annotations (exon/CDS structure, coordinates, biotype) separate from sequence retrieval.
Architecture Overview:
EnsemblTranscriptModelClient: Primary implementation using Ensembl REST API
VepConsequenceClient: Optional enrichment client (placeholder for future development)
Caching Strategy:
In-memory LRU cache with TTL rather than ReferenceManagerβs persistent file cache: annotation JSON is KB and versioned by release, unlike GB sequence files. The cache evicts oldest entries when reaching max_cache_entries, and entries expire after cache_ttl seconds.
Relationship to GeneSearcher:
GeneSearcher discovers transcripts and fetches sequences; this module enriches known transcript IDs with genomic structure β different Ensembl endpoints, no overlap.
- class sirnaforge.data.transcript_annotation.EnsemblTranscriptModelClient(timeout: int = 30, base_url: str = 'https://rest.ensembl.org', cache_ttl: int = 3600, max_cache_entries: int = 1000)[source]ο
Bases:
AbstractTranscriptAnnotationClientEnsembl REST-based transcript annotation client.
Retrieves transcript metadata including genomic coordinates, exon/CDS structure, and biotype information using Ensemblβs public REST API.
API Endpoints Used:
Lookup by ID (/lookup/id/:id?expand=1): - Fetches detailed annotation for single transcript/gene ID - Returns exon coordinates, CDS intervals, biotype - Example: /lookup/id/ENST00000269305?expand=1
Overlap by Region (/overlap/region/:species/:region): - Fetches all transcripts overlapping genomic region - Useful for region-based queries - Example: /overlap/region/human/17:7661779-7687550?feature=transcript
Caching Implementation:
Cache key format: βid:{species}:{identifier}:{reference}β or βregion:{species}:{region}:{reference}β
Single-process use only (workflow orchestration context); not thread-safe
Error Handling:
404 is not an error: the ID joins the unresolved list, no exception raised
Everything else becomes a DatabaseAccessError carrying its context
Example Usage:
>>> client = EnsemblTranscriptModelClient() >>> reference = ReferenceChoice.explicit("GRCh38", reason="user-specified") >>> bundle = await client.fetch_by_ids( ... ids=["ENST00000269305"], ... species="human", ... reference=reference ... ) >>> print(f"Resolved: {bundle.resolved_count}, Unresolved: {bundle.unresolved_count}")
- __init__(timeout: int = 30, base_url: str = 'https://rest.ensembl.org', cache_ttl: int = 3600, max_cache_entries: int = 1000)[source]ο
Initialize Ensembl transcript annotation client.
- Parameters:
timeout β Request timeout in seconds
base_url β Ensembl REST API base URL
cache_ttl β Cache time-to-live in seconds (default: 1 hour)
max_cache_entries β Maximum number of cached entries (default: 1000)
- async fetch_by_ids(ids: list[str], *, species: str, reference: ReferenceChoice) TranscriptAnnotationBundle[source]ο
Fetch transcript annotations by stable IDs using Ensembl lookup endpoint.
Ids that miss the cache are looked up with one
POST /lookup/idper chunk rather than one GET each: enriching 10 transcripts took ~100s serially and ~7s batched.- Parameters:
ids β List of transcript or gene IDs
species β Species name (e.g., βhomo_sapiensβ, βhumanβ)
reference β Reference assembly/release choice
- Returns:
TranscriptAnnotationBundle with resolved annotations
- async fetch_by_regions(regions: list[str], *, species: str, reference: ReferenceChoice) TranscriptAnnotationBundle[source]ο
Fetch transcript annotations by genomic regions using Ensembl overlap endpoint.
- Parameters:
regions β List of regions in format βchr:start-endβ (e.g., β17:7661779-7687550β)
species β Species name (e.g., βhomo_sapiensβ, βhumanβ)
reference β Reference assembly/release choice
- Returns:
TranscriptAnnotationBundle with all transcripts overlapping regions
- class sirnaforge.data.transcript_annotation.VepConsequenceClient(timeout: int = 30, base_url: str = 'https://rest.ensembl.org')[source]ο
Bases:
objectOptional VEP (Variant Effect Predictor) consequence enrichment client.
Current Status: PLACEHOLDER β enrich_annotations returns the input bundle unchanged. When activated it would query the Ensembl VEP REST API for consequence predictions and enrich each TranscriptAnnotation with them.
Separate from EnsemblTranscriptModelClient because VEP queries are rate-limited and slower, not every workflow needs them, and the two can then cache and be switched on independently.
- __init__(timeout: int = 30, base_url: str = 'https://rest.ensembl.org')[source]ο
Initialize VEP client.
- Parameters:
timeout β Request timeout in seconds
base_url β Ensembl REST API base URL
- async enrich_annotations(bundle: TranscriptAnnotationBundle, _species: str = 'homo_sapiens') TranscriptAnnotationBundle[source]ο
Enrich transcript annotations with VEP consequence data.
- Parameters:
bundle β Existing transcript annotation bundle
species β Species name for VEP queries
- Returns:
Enriched bundle (currently returns input unchanged - placeholder for future VEP integration)
miRNA Managementο
miRNA Database Manager with multi-species support.
This module provides a clean interface for downloading, caching, and managing miRNA databases from multiple sources (MirGeneDB, miRBase, TargetScan) with automatic cache management and species-specific organization.
- class sirnaforge.data.mirna_manager.MiRNASource(name: str, url: str, species: str, format: str = 'fasta', compressed: bool = False, description: str = '')[source]ο
Bases:
ReferenceSourcemiRNA-specific database source configuration.
Inherits from ReferenceSource and can add miRNA-specific fields if needed.
- class sirnaforge.data.mirna_manager.PinnedMiRNAReference(path: str | Path, release: str, sha256: str, original_url: str | None = None)[source]ο
Bases:
objectExplicit local mature FASTA with independently supplied release and SHA-256.
The checksum covers the original file, before species filtering. A pin never refreshes from an upstream endpoint and is not advertised as the latest release.
- class sirnaforge.data.mirna_manager.MiRNADatabaseManager(cache_dir: str | Path | None = None, cache_ttl_days: int = 30, *, pinned_references: dict[str, dict[str, PinnedMiRNAReference]] | None = None, download_timeout: int = 30, download_attempts: int = 2, retry_backoff_seconds: float = 0.25)[source]ο
Bases:
ReferenceManager[MiRNASource]Elegant miRNA database manager with caching and multi-species support.
- SOURCES = {'mirbase': {'chicken': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='chicken', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for chicken'), 'human': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='human', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for human'), 'mouse': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='mouse', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for mouse'), 'pig': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='pig', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for pig'), 'rat': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='rat', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for rat'), 'rhesus': MiRNASource(name='mirbase_mature', url='https://www.mirbase.org/download/mature.fa', species='rhesus', format='fasta', compressed=False, description='All mature miRBase sequences, filtered for macaque')}, 'mirbase_hairpin': {'human': MiRNASource(name='mirbase_hairpin', url='https://www.mirbase.org/download/hairpin.fa', species='human', format='fasta', compressed=False, description='miRBase hairpin precursor miRNA sequences (Homo sapiens - hsa)'), 'mouse': MiRNASource(name='mirbase_hairpin', url='https://www.mirbase.org/download/hairpin.fa', species='mouse', format='fasta', compressed=False, description='miRBase hairpin precursor miRNA sequences (Mus musculus - mmu)'), 'rat': MiRNASource(name='mirbase_hairpin', url='https://www.mirbase.org/download/hairpin.fa', species='rat', format='fasta', compressed=False, description='miRBase hairpin precursor miRNA sequences (Rattus norvegicus - rno)')}, 'mirbase_high_conf': {'human': MiRNASource(name='mirbase_mature_hc', url='https://www.mirbase.org/download/CURRENT/mature_high_conf.fa', species='human', format='fasta', compressed=False, description='miRBase high-confidence mature miRNA sequences (Homo sapiens - hsa)'), 'mouse': MiRNASource(name='mirbase_mature_hc', url='https://www.mirbase.org/download/CURRENT/mature_high_conf.fa', species='mouse', format='fasta', compressed=False, description='miRBase high-confidence mature miRNA sequences (Mus musculus - mmu)'), 'rat': MiRNASource(name='mirbase_mature_hc', url='https://www.mirbase.org/download/CURRENT/mature_high_conf.fa', species='rat', format='fasta', compressed=False, description='miRBase high-confidence mature miRNA sequences (Rattus norvegicus - rno)')}, 'mirgenedb': {'aga': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/aga?mat=1', species='aga', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Anopheles gambiae, NCBI:7165) [Mosquito]'), 'bta': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/bta?mat=1', species='bta', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Bos taurus, NCBI:9913) [Cow]'), 'cel': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/cel?mat=1', species='cel', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Caenorhabditis elegans, NCBI:6239) [C. elegans]'), 'cfa': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/cfa?mat=1', species='cfa', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Canis lupus familiaris, NCBI:9615) [Dog]'), 'dme': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/dme?mat=1', species='dme', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Drosophila melanogaster, NCBI:7227) [Fruit fly]'), 'dre': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/dre?mat=1', species='dre', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Danio rerio, NCBI:7955) [Zebrafish]'), 'eca': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/eca?mat=1', species='eca', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Equus caballus, NCBI:9796) [Horse]'), 'fca': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/fca?mat=1', species='fca', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Felis catus, NCBI:9685)'), 'gac': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/gac?mat=1', species='gac', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Gasterosteus aculeatus, NCBI:69293) [Stickleback]'), 'gga': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/gga?mat=1', species='gga', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Gallus gallus, NCBI:9031) [Chicken]'), 'ggo': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/ggo?mat=1', species='ggo', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Gorilla gorilla, NCBI:9593)'), 'hsa': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/hsa?mat=1', species='hsa', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Homo sapiens, NCBI:9606) [Human]'), 'mml': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/mml?mat=1', species='mml', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Macaca mulatta, NCBI:9544) [Rhesus macaque]'), 'mmu': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/mmu?mat=1', species='mmu', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Mus musculus, NCBI:10090) [Mouse]'), 'oar': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/oar?mat=1', species='oar', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Ovis aries, NCBI:9940) [Sheep]'), 'ola': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/ola?mat=1', species='ola', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Oryzias latipes, NCBI:8090) [Medaka]'), 'pma': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/pma?mat=1', species='pma', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Petromyzon marinus, NCBI:7757) [Sea lamprey]'), 'ptr': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/ptr?mat=1', species='ptr', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Pan troglodytes, NCBI:9598) [Chimpanzee]'), 'rno': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/rno?mat=1', species='rno', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Rattus norvegicus, NCBI:10116)'), 'spur': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/spur?mat=1', species='spur', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Strongylocentrotus purpuratus, NCBI:7668) [Purple sea urchin]'), 'ssc': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/ssc?mat=1', species='ssc', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Sus scrofa, NCBI:9823) [Pig]'), 'tgu': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/tgu?mat=1', species='tgu', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Meleagris gallopavo, NCBI:9103) [Turkey]'), 'xla': MiRNASource(name='mirgenedb', url='https://www.mirgenedb.org/fasta/xla?mat=1', species='xla', format='fasta', compressed=False, description='MirGeneDB high-confidence miRNAs (Xenopus laevis, NCBI:8355) [African clawed frog]')}, 'mirgenedb+mirbase': {'chicken': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='chicken', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)'), 'human': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='human', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)'), 'mouse': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='mouse', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)'), 'pig': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='pig', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)'), 'rat': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='rat', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)'), 'rhesus': MiRNASource(name='mirgenedb+mirbase', url='combined:mirgenedb+mirbase', species='rhesus', format='fasta', compressed=False, description='MirGeneDB mature plus full miRBase mature sequences (no star-only export)')}, 'targetscan': {'human': MiRNASource(name='targetscan', url='https://www.targetscan.org/vert_80/vert_80_data_download/miR_Family_Info.txt.zip', species='human', format='tsv', compressed=True, description='TargetScan miRNA family data')}}ο
- classmethod get_available_sources() list[str][source]ο
Return sorted list of supported database sources.
- classmethod get_all_species() list[str][source]ο
Return sorted list of all species across sources.
- classmethod get_species_for_source(source_name: str) list[str][source]ο
Return sorted list of species supported by a given source.
- classmethod get_species_aliases(source_name: str) dict[str, list[str]][source]ο
Return mapping of canonical species identifiers to their known aliases.
- classmethod get_canonical_species() list[str][source]ο
Return sorted list of canonical species keys.
- classmethod canonicalize_species_name(species: str) str | None[source]ο
Normalize a raw species identifier to a canonical key.
- classmethod canonicalize_species_list(species_list: Sequence[str]) list[str][source]ο
Normalize a list of species identifiers to canonical keys, preserving order.
- classmethod get_genome_species_for_canonical(canonical_species: Sequence[str]) list[str][source]ο
Return genome species identifiers for canonical species keys.
Note: These are used for miRNA database lookups, not genomic DNA alignment. The term βgenomeβ here refers to the organismβs miRNA annotation set.
- classmethod get_mirna_slugs_for_canonical(canonical_species: Sequence[str], source_name: str) list[str][source]ο
Return normalized miRNA identifiers for canonical species.
- classmethod get_supported_canonical_species_for_source(source_name: str) list[str][source]ο
Return canonical species supported by a given source.
- classmethod resolve_species_selection(requested_species: Sequence[str], source_name: str, mirna_overrides: Sequence[str] | None = None) dict[str, list[str]][source]ο
Resolve canonical, genome, and miRNA identifiers for the requested species.
- classmethod normalize_species(source_name: str, species: str) str | None[source]ο
Normalize user-provided species identifiers to canonical keys.
- classmethod get_source_configuration(source_name: str, species: str) MiRNASource | None[source]ο
Retrieve the MiRNASource configuration for a given source/species.
- classmethod is_supported_species(source_name: str, species: str) bool[source]ο
Check if a species is supported for the given source.
- classmethod get_mirgenedb_species_metadata() dict[str, dict[str, Any]][source]ο
Expose the MirGeneDB species metadata table.
- __init__(cache_dir: str | Path | None = None, cache_ttl_days: int = 30, *, pinned_references: dict[str, dict[str, PinnedMiRNAReference]] | None = None, download_timeout: int = 30, download_attempts: int = 2, retry_backoff_seconds: float = 0.25)[source]ο
Initialize the miRNA database manager.
- Parameters:
cache_dir β Directory for caching databases (default: ~/.cache/sirnaforge/mirna)
cache_ttl_days β Cache time-to-live in days
pinned_references β Explicit mature FASTA pins keyed by source and species.
download_timeout β Total deadline per live attempt, including transfer/decode, from 1 to 300 seconds.
download_attempts β Maximum acquisition attempts, from 1 to 3.
retry_backoff_seconds β Base exponential backoff, from 0 to 5 seconds.
- get_reference_metadata(source_name: str, species: str) dict[str, Any] | None[source]ο
Return provenance of a reference resolved by this manager in this run.
Call after
get_database. None means acquisition failed or was never attempted. This never inspects a different processβs or hostβs cache.
- get_database(source_name: str, species: str, force_refresh: bool = False) Path | None[source]ο
Resolve a single source or the explicit mature-only union.
- Parameters:
source_name β Registered source name or mirgenedb+mirbase.
species β Target organism identifier.
force_refresh β Refresh both component references when combining.
- Returns:
Validated reference path, or None if any required source failed.
- get_combined_database(sources: list[str], species: str, output_name: str | None = None) Path | None[source]ο
Combine multiple databases into a single file.
- Parameters:
sources β List of source names to combine
species β Target species
output_name β Custom output filename (default: auto-generated)
- Returns:
Path to combined FASTA file
- sirnaforge.data.mirna_manager.load_pinned_references(manifest_path: str | Path) dict[str, dict[str, PinnedMiRNAReference]][source]ο
Read a version 1 local reference manifest, resolving paths relative to it.
referencesis a nonempty list of source, species, release, sha256, path entries, optionally carrying original_url. This validates configuration only; acquisition verifies the actual FASTA bytes and never silently substitutes a source.
Species Registryο
Canonical species registry and metadata for miRNA and genome mappings.
- sirnaforge.data.species_registry.normalize_species_name(species: str) str[source]ο
Normalize species name to canonical form.
- Parameters:
species β Species name in any recognized form (e.g., βhsaβ, βhumanβ, βHomo sapiensβ)
- Returns:
Canonical species name (e.g., βhumanβ), or original string if not recognized
Examples
>>> normalize_species_name('hsa') 'human' >>> normalize_species_name('Mus musculus') 'mouse' >>> normalize_species_name('macaque') 'macaque' >>> normalize_species_name('unknown') 'unknown'
- sirnaforge.data.species_registry.ensembl_species_slug(species: str) str | None[source]ο
Ensembl REST species slug for a species name, or None if not in the registry.
Ensembl addresses species by underscored lowercase scientific name, so this is derived from the registryβs scientific name rather than stored twice.
- Parameters:
species β Species name in any recognized form
- Returns:
Slug such as
mus_musculus, or None when the species is not registered
Examples
>>> ensembl_species_slug('mouse') 'mus_musculus' >>> ensembl_species_slug('hsa') 'homo_sapiens' >>> ensembl_species_slug('nonesuch') is None True
Orthologyο
Orthologue resolution on stable gene IDs, for cross-species hit classification.
Why this module exists: orthology cannot be decided on gene symbols. HGNC and MGI are separate
nomenclature authorities, so the mouse orthologue of human TP53 is Trp53 β uppercased
symbol equality misses it, and would equally happily match two unrelated genes that share a symbol
across species. Issue #101 requires explicit orthology evidence for any conservation claim, with
symbol equality retained only as a labelled heuristic.
The resolver lives here, in the data layer, because core.hit_classification.classify_hit is a
pure function and must not perform network I/O. The workflow resolves a mapping once and passes the
resulting gene-ID set into ClassificationContext.
Cost is up to two Compara requests per (query gene x target species) β the gene-ID route, then
the symbol route when the first resolves nothing β charged once per resolution, never per hit.
There is no cache, so a caller that resolves twice pays twice. Two guards keep an unreachable
Compara off the critical path: a transport-level failure is never retried, and
OrthologueMapping.from_file() resolves from a user-supplied mapping with no network at all
(issue #101: an offline path is required, not optional).
ORTHOLOGY_BUDGET_SECONDS is a suggested ceiling for a host that drops packets rather than
refusing them, and it is opt-in β the default is no ceiling. Abandoning a slow-but-working
Compara reports a resolvable species as unresolved, and unresolved conservation still publishes
0.0 rather than null, so a ceiling trades a stall for a fabricated measurement. Bounding that
case belongs with #101βs null-conservation fix.
- sirnaforge.data.orthology.ORTHOLOGUE_TYPES = frozenset({'ortholog_many2many', 'ortholog_one2many', 'ortholog_one2one'})ο
a within-species duplicate is an off-target liability, not conservation evidence.
- Type:
Compara relationship types that are orthologues. Paralogues are deliberately excluded
- sirnaforge.data.orthology.ORTHOLOGY_BUDGET_SECONDS = 60.0ο
Wall-clock ceiling on one whole resolution, across every species and route. A host that DROPs rather than refuses (the common firewall default) fails only at the per-request timeout, so without a ceiling a multi-species screen stalls for minutes before degrading to the labelled heuristic. Species not reached by then are reported unresolved, which is the honest answer.
- sirnaforge.data.orthology.SOURCE_COMPARA = 'ensembl_compara'ο
Provenance labels for
OrthologueMapping.summary().
- sirnaforge.data.orthology.OrthologTableο
A user-supplied mapping, keyed on the uppercased version-stripped query gene ID or symbol.
- class sirnaforge.data.orthology.OrthologueMapping(gene_ids_by_species: dict[str, frozenset[str]], resolved_species: frozenset[str], unresolved_species: frozenset[str], queried_gene_ids: frozenset[str] = frozenset({}), queried_symbols: frozenset[str] = frozenset({}), source: str | None = 'ensembl_compara', reasons_by_species: dict[str, str] = <factory>)[source]ο
Bases:
objectResolved orthologues of one or more query genes, grouped by target species.
- Variables:
gene_ids_by_species (dict[str, frozenset[str]]) β Canonical species name -> version-stripped orthologue gene IDs.
resolved_species (frozenset[str]) β Species for which the lookup completed, even if it found nothing.
unresolved_species (frozenset[str]) β Species the lookup could not complete for (unregistered species or a failed request). Distinguished from βresolved, no orthologueβ because only the latter is evidence of absence.
queried_gene_ids (frozenset[str]) β The gene IDs actually sent to Compara. Recorded because a resolved-but-empty result is otherwise indistinguishable from a lookup on the wrong identifier β the first mouse run resolved 0 orthologues purely because the βgene IDsβ were transcript IDs.
queried_symbols (frozenset[str]) β The gene symbols used for the fallback route, if any.
source (str | None) β Where the orthologues came from β Compara, or a user-supplied mapping file, or
Nonewhen no lookup was attempted at all. An offline run must not publish provenance that claims a REST call it never made.
- property all_gene_ids: frozenset[str]ο
Every resolved orthologue gene ID, flattened for
ClassificationContext.
- summary() dict[str, Any][source]ο
Provenance record for the run summary, so a conservation claim is auditable.
orthologue_typesis published for a Compara lookup and nobody else: it is the filter this module applies to a Compara response, so it is provenance for a call that happened and for nothing else. Omitting it when no lookup ran was half the fix β a user-supplied mapping file was still described with all three relationship types, as if a REST call had filtered them.
- classmethod empty() OrthologueMapping[source]ο
A mapping that resolved nothing, so every ortholog verdict falls back to the heuristic.
source=Nonebecause nothing was asked: inheriting the Compara default published{"source": "ensembl_compara", "orthologue_types": [all three]}into every single-species screen, every design-only run and every run whose gene yielded neither ID nor symbol β a REST call that never happened.
- classmethod from_file(path: Path | str, query_gene_ids: frozenset[str] | set[str] | list[str], query_species: str, target_species: frozenset[str] | set[str] | list[str], *, query_gene_symbols: frozenset[str] | set[str] | list[str] = frozenset({})) OrthologueMapping[source]ο
Resolve from a user-supplied mapping file instead of Compara. Never touches the network.
The offline half of issue #101: an air-gapped run, and every deterministic fixture, states its orthologues in a file rather than depending on REST being reachable. Same arguments as
resolve_orthologues()so the two are interchangeable at the call site.
- __init__(gene_ids_by_species: dict[str, frozenset[str]], resolved_species: frozenset[str], unresolved_species: frozenset[str], queried_gene_ids: frozenset[str] = frozenset({}), queried_symbols: frozenset[str] = frozenset({}), source: str | None = 'ensembl_compara', reasons_by_species: dict[str, str] = <factory>) Noneο
- sirnaforge.data.orthology.load_ortholog_table(path: Path | str) dict[str, dict[str, frozenset[str]]][source]ο
Parse a mapping file of query gene -> species -> orthologue gene IDs.
JSON, e.g.
{"ENSG00000141510": {"mouse": ["ENSMUSG00000059552"], "rat": []}}. A query key may be a gene ID (version optional) or a gene symbol, because an input-FASTA run often has no stable gene ID to key on. An explicitly empty list is a claim β βchecked, no orthologueβ β and is kept distinct from a species the file says nothing about.- Raises:
FileNotFoundError β The path does not exist.
ValueError β The file is not JSON, or not of that shape. Unlike a failed network lookup, which degrades to the labelled heuristic, a malformed explicit input fails loudly: silently ignoring it would screen with weaker evidence than the user asked for.
- sirnaforge.data.orthology.mapping_from_table(table: dict[str, dict[str, frozenset[str]]], query_gene_ids: frozenset[str] | set[str] | list[str], query_species: str, target_species: frozenset[str] | set[str] | list[str], *, query_gene_symbols: frozenset[str] | set[str] | list[str] = frozenset({})) OrthologueMapping[source]ο
Select one query geneβs orthologues out of a parsed mapping table.
A requested species the table says nothing about is
unresolved, not resolved-empty: the file made no claim about it, so its hits fall back to the labelled symbol heuristic rather than being reported as βchecked, not an orthologueβ.
- async sirnaforge.data.orthology.resolve_orthologues(query_gene_ids: frozenset[str] | set[str] | list[str], query_species: str, target_species: frozenset[str] | set[str] | list[str], *, query_gene_symbols: frozenset[str] | set[str] | list[str] = frozenset({}), base_url: str = 'https://rest.ensembl.org', timeout: int = 30, budget: float | None = None, session: ClientSession | None = None) OrthologueMapping[source]ο
Resolve orthologues of the query gene(s) in each target species.
Two routes, because a run driven by
input_fastaoften has no stable gene ID at all. The pinned TP53 FASTA in the full-scale kit has headers like>ENST00000413465 TP53 ..., so the βgene IDβ reaching this function is a transcript ID, and/homology/id/homo_sapiens/ENST00000413465answers HTTP 200 with {βdataβ: []} β a successful empty result, indistinguishable from βno orthologue existsβ. So when the ID route finds nothing, the symbol route/homology/symbol/{species}/{symbol}is tried; it resolvesTP53toENSMUSG00000059552(both verified live on release 116).The symbol is only an input to the lookup here. What comes back is a stable gene ID from Compara, so a verdict reached this way is still
OrthologEvidence.GENE_IDβ unlike the symbol-equality heuristic inclassify_hit, nothing is being asserted from symbol equality.Never raises for a lookup failure: a species that could not be resolved is reported in
unresolved_speciesand its hits fall back to the symbol heuristic. Failing the whole screen because Compara was briefly unavailable would be worse than screening with weaker evidence, as long as the weaker evidence is labelled β whichOrthologEvidencedoes.Reaches the network. Use
OrthologueMapping.from_file()for an air-gapped run or any deterministic fixture; a unit test must never end up here.- Parameters:
query_gene_ids β Stable gene IDs of the query gene (version suffix optional).
query_species β Species the query gene belongs to.
target_species β Species to resolve orthologues in; the query species is skipped.
query_gene_symbols β Gene symbols to fall back to when the ID route resolves nothing.
base_url β Ensembl REST base URL.
timeout β Per-request timeout in seconds.
budget β Optional wall-clock ceiling on the whole resolution; species not reached in time are reported unresolved. Defaults to no ceiling, because an abandoned species is indistinguishable from an absent orthologue β see the module docstring.
session β Session to reuse; one is opened for this call when omitted.
- Returns:
An
OrthologueMapping. Empty when there is nothing to resolve.
Variant Resolverο
Variant resolution from multiple databases (ClinVar, Ensembl, dbSNP) with caching.
- class sirnaforge.data.variant_resolver.VariantResolver(min_af: float = 0.01, clinvar_filters: list[ClinVarSignificance] | None = None, assembly: str = 'GRCh38', source_priority: list[VariantSource] | None = None, cache_dir: Path | None = None, timeout: int = 30, variant_mode: str | None = None)[source]ο
Bases:
objectResolve variant identifiers to VariantRecord using multiple databases with priority ordering.
Priority order: ClinVar > Ensembl > dbSNP Supports caching and local VCF files. Only supports GRCh38 assembly.
- __init__(min_af: float = 0.01, clinvar_filters: list[ClinVarSignificance] | None = None, assembly: str = 'GRCh38', source_priority: list[VariantSource] | None = None, cache_dir: Path | None = None, timeout: int = 30, variant_mode: str | None = None)[source]ο
Initialize variant resolver.
- Parameters:
min_af β Minimum allele frequency threshold (default: 0.01)
clinvar_filters β Allowed ClinVar significance levels (default: Pathogenic, Likely pathogenic)
assembly β Reference genome assembly (only GRCh38 supported)
source_priority β Source priority list (default: ClinVar > Ensembl > dbSNP)
cache_dir β Cache directory for variant data
timeout β HTTP request timeout in seconds
variant_mode β Variant mode for AF filtering (βavoidβ, βtargetβ, βbothβ). In βavoidβ mode, uses max population AF if available to avoid SNPs prevalent in any geographic group (e.g., >10% in one population).
- parse_identifier(input_str: str) VariantQuery[source]ο
Parse variant identifier string into VariantQuery.
Accepts: - rsID: rs12345 - VCF-style coordinate: chr17:7577121:G:A or 17:7577121:G:A - HGVS: NM_000546.6:c.215C>G (basic support)
- Parameters:
input_str β User-provided variant identifier
- Returns:
VariantQuery with parsed components
- Raises:
ValueError β If input format is not recognized
- async resolve_variant(query: VariantQuery) VariantRecord | None[source]ο
Resolve a variant query to a VariantRecord.
Tries sources in priority order: ClinVar -> Ensembl -> dbSNP Applies AF and ClinVar filters. Uses cache when available.
- Parameters:
query β Parsed variant query
- Returns:
VariantRecord if found and passes filters, None otherwise
- read_vcf(vcf_path: Path) list[VariantRecord][source]ο
Read variants from VCF file (supports bgzip+tabix).
- Parameters:
vcf_path β Path to VCF file
- Returns:
List of VariantRecord objects passing filters
- Raises:
FileNotFoundError β If VCF file doesnβt exist
- sirnaforge.data.variant_resolver.resolve_variant_sync(variant_id: str, min_af: float = 0.01, clinvar_filters: list[ClinVarSignificance] | None = None, cache_dir: Path | None = None, variant_mode: str | None = None) VariantRecord | None[source]ο
Synchronous wrapper for variant resolution.
- Parameters:
variant_id β Variant identifier (rsID, coordinate, or HGVS)
min_af β Minimum allele frequency
clinvar_filters β Allowed ClinVar significance levels
cache_dir β Cache directory
variant_mode β Variant mode for AF filtering (βavoidβ, βtargetβ, βbothβ)
- Returns:
VariantRecord if found and passes filters, None otherwise
Variant Cacheο
Improved variant caching using Parquet for efficient storage and retrieval.
- class sirnaforge.data.variant_cache.VariantParquetCache(cache_dir: Path, ttl_days: int = 90)[source]ο
Bases:
objectEfficient variant cache using Parquet files for better performance than JSON.
Benefits over JSON: - Columnar storage format is much more efficient for variant data - Built-in compression reduces disk usage - Fast filtering and querying with pandas - Batch operations instead of individual file I/O
- __init__(cache_dir: Path, ttl_days: int = 90)[source]ο
Initialize the Parquet-based variant cache.
- Parameters:
cache_dir β Directory for cache storage
ttl_days β Time-to-live for cached entries in days (default: 90)
- get(cache_key: str) VariantRecord | None[source]ο
Retrieve a variant from cache by key.
- Parameters:
cache_key β Cache key for the variant
- Returns:
VariantRecord if found and not stale, None otherwise
- put(cache_key: str, variant: VariantRecord) None[source]ο
Store a variant in the cache.
- Parameters:
cache_key β Cache key for storage
variant β VariantRecord to cache
- cleanup_stale_entries() int[source]ο
Remove entries older than TTL.
- Returns:
Number of entries removed
Variant Helpersο
Helpers for applying genomic variants to transcript-oriented siRNA design.
- sirnaforge.data.variant_helpers.map_variant_to_transcript(variant: VariantRecord, annotation: TranscriptAnnotation) int | None[source]ο
Map a genomic SNV to a zero-based cDNA index using transcript exons.
Returns
Nonewhen chromosome or exon membership does not match. A genomic coordinate is never used directly as an index into transcript sequence.
- sirnaforge.data.variant_helpers.apply_variant_to_transcript_sequence(sequence: str, variant: VariantRecord, annotation: TranscriptAnnotation) tuple[str, int | None][source]ο
Apply a strictly mapped GRCh38 variant to cDNA, returning its cDNA position.
A non-overlapping transcript is returned unchanged with
None. Mapped variants must match the transcript-oriented reference base; this function never treats a genomic coordinate as a sequence offset.
- sirnaforge.data.variant_helpers.apply_variant_workflow(design_result: DesignResult, variants: Sequence[VariantRecord], transcripts: Sequence[TranscriptInfo], annotations: Mapping[str, TranscriptAnnotation], mode: str | VariantMode, design_sequence: Callable[[str, str], DesignResult]) DesignResult[source]ο
Filter reference guides and add allele-specific SNV guides to a design result.
avoidremoves candidates overlapping mapped SNVs.targetreplaces overlapping reference candidates with alternate-allele designs.bothkeeps overlapping reference designs and adds alternate-allele designs. A variant that cannot be mapped to any annotated exon fails with an explicit unknown-mapping error instead of silently interpreting its genomic position as cDNA.
- sirnaforge.data.variant_helpers.generate_contexts_for_variant(variant: VariantRecord, reference_sequence: str, transcript_start: int, transcript_id: str, flank_size: int = 50) dict[str, tuple[str, int, int]][source]ο
Generate reference and alternate sequence contexts for a variant.
- Parameters:
variant β Variant record with position and alleles
reference_sequence β Full reference transcript sequence
transcript_start β Genomic start position of the transcript (1-based)
transcript_id β Transcript identifier
flank_size β Number of nucleotides to include on each side of variant (default: 50)
- Returns:
sequence context (str)
relative position of variant in context (int, 0-based)
length of the allele (int)
- Return type:
Dictionary with βrefβ and βaltβ keys, each containing
- Raises:
ValueError β If variant position is outside transcript boundaries
- sirnaforge.data.variant_helpers.check_candidate_overlaps_variant(candidate_pos: int, candidate_length: int, variant: VariantRecord, transcript_start: int) bool[source]ο
Check if a siRNA candidate overlaps with a variant position.
- Parameters:
candidate_pos β 1-based start position of candidate in transcript
candidate_length β Length of the siRNA candidate
variant β Variant record to check
transcript_start β 1-based genomic start position of transcript
- Returns:
True if candidate overlaps the variant, False otherwise
- sirnaforge.data.variant_helpers.annotate_candidate_with_variant(candidate: SiRNACandidate, variant: VariantRecord, allele: str, variant_mode: str) None[source]ο
Annotate a siRNA candidate with variant information.
Modifies the candidate in place to add variant-specific metadata.
- Parameters:
candidate β SiRNACandidate to annotate
variant β Variant record that overlaps the candidate
allele β Which allele the candidate targets (βrefβ or βaltβ)
variant_mode β Variant handling mode (βtargetβ, βavoidβ, βbothβ)
- sirnaforge.data.variant_helpers.apply_variant_to_sequence(sequence: str, variant: VariantRecord, transcript_start: int, allele: str = 'alt') str[source]ο
Apply a variant to a reference sequence to generate an alternate sequence.
- Parameters:
sequence β Reference sequence
variant β Variant record with position and alleles
transcript_start β 1-based genomic start position of transcript
allele β Which allele to apply (βrefβ returns unchanged sequence, βaltβ applies variant)
- Returns:
Modified sequence with variant applied
- Raises:
ValueError β If variant position is outside sequence boundaries or allele is invalid
- sirnaforge.data.variant_helpers.get_variant_position_in_transcript(variant: VariantRecord, transcript_start: int) int[source]ο
Calculate the 0-based position of a variant within a transcript.
- Parameters:
variant β Variant record
transcript_start β 1-based genomic start position of transcript
- Returns:
0-based position of variant within transcript
Pipeline Integrationο
Nextflow CLIο
Command-line entry points used by embedded Nextflow modules.
- sirnaforge.pipeline.nextflow_cli.build_bwa_index_cli(fasta_file: str, species: str, output_dir: str = '.', aligner: str = 'bwa-mem2') dict[str, Any][source]ο
Build a BWA-family index for one screening reference.
- Parameters:
fasta_file β Path to input FASTA file
species β Species identifier
output_dir β Directory to write index files
aligner β Selected BWA-compatible backend (default:
bwa-mem2)
- Returns:
Dictionary with index prefix path
- sirnaforge.pipeline.nextflow_cli.offtarget_analysis_cli(species: str, index_prefix: str, candidates_file: str, output_dir: str = '.', max_hits: int | None = None, bwa_k: int = 12, bwa_T: int = 15, seed_start: int = 2, seed_end: int = 8, aligner: str = 'bwa-mem2') dict[str, Any][source]ο
Align one speciesβ reference for OFFTARGET_ANALYSIS, or record that it could not be aligned.
A named index prefix that does not resolve to a usable BWA-MEM2 index used to reach the aligner, which logged a failure, returned no hits, and published a header-only table β a completed screen with zero hits, indistinguishable from a clean one. The species is now published as an EMPTY analysis file plus a failed summary, which
aggregate_offtarget_resultsreports as a per-species rejection rather than as a clean result. Either way, this function owns the failed-vs-completed decision, so it also writes the #100transcriptome_<species>_evidence.jsonenvelope on both branches β directly here on the missing-index branch, and viarun_bwa_alignment_analysisβsevidence_diron the aligned branch.- Parameters:
species β Species identifier this reference belongs to
index_prefix β BWA-MEM2 index prefix as resolved for this species
candidates_file β FASTA of candidate guides to screen
output_dir β Directory to write
<species>_analysis.tsvand<species>_summary.jsonmax_hits β Maximum hits per candidate (
None= exhaustive)bwa_k β BWA seed length
bwa_T β BWA minimum score threshold
seed_start β Seed region start (1-based)
seed_end β Seed region end (1-based)
aligner β Selected BWA-compatible backend (default:
bwa-mem2)
- Returns:
Dictionary with the per-species status and the published file paths
- sirnaforge.pipeline.nextflow_cli.aggregate_results_cli(transcriptome_species: str, output_dir: str = '.', mirna_db: str | None = None, mirna_species: str | None = None, analysis_files: list[str] | None = None, summary_files: list[str] | None = None, *, evidence_plan: str | None = None) dict[str, Any][source]ο
Aggregate off-target analysis results from multiple candidates and references.
- Parameters:
transcriptome_species β Comma-separated list of species screened
output_dir β Directory to write aggregated results
mirna_db β The database that provided the reference
mirna_species β The species code for the matching miRNA
analysis_files β Optional explicit list of staged analysis files to aggregate
summary_files β Optional explicit list of staged summary files to aggregate
evidence_plan β Path to the serialized #100
ScreeningPlan(workflow.pyβsscreening_plan.json), additive and keyword-only. Reconciliation against it is written unconditionally on every return path, including the zero-files branch, so a pipeline that aborted before producing a single analysis file still leaves a machine-readableevidence.jsonbehind instead of only afinal_summary.txt.
- Returns:
Dictionary with aggregation statistics
- sirnaforge.pipeline.nextflow_cli.aggregate_mirna_results_cli(mirna_db: str, mirna_species: str, results_dir: str = '.', output_dir: str = '.', *, evidence_plan: str | None = None) dict[str, Any][source]ο
Aggregate miRNA seed analysis results from multiple candidates.
- Parameters:
mirna_db β miRNA database name used for analysis
mirna_species β Comma-separated list of species analyzed
results_dir β Directory containing individual miRNA results
output_dir β Directory to write aggregated results
evidence_plan β Path to the serialized #100
ScreeningPlan, additive and keyword-only.aggregate_results.nfdoes not call this entry point, but it gets the same unconditional reconciliation treatment asaggregate_results_cliso a caller of it is not left with a weaker evidence contract than the transcriptome channel.
- Returns:
Dictionary with aggregation statistics
Nextflow Configurationο
Nextflow Configuration Management.
This module handles configuration for Nextflow workflows, including Docker settings, resource management, and parameter validation.
Simple Usage Examples:
# Auto-configure based on environment (easiest) config = NextflowConfig.auto_configure()
# Production settings config = NextflowConfig.for_production()
# Testing settings config = NextflowConfig.for_testing()
# Local Docker testing (uses local image built by βmake dockerβ) config = NextflowConfig.for_local_docker_testing()
- class sirnaforge.pipeline.nextflow.config.EnvironmentInfo(*, running_in_docker: bool, docker_available: bool, requested_profile: str, recommended_profile: str, docker_image: str | None = None, profile_override_reason: str | None = None)[source]ο
Bases:
BaseModelInformation about the current execution environment.
- is_profile_overridden() bool[source]ο
Check if the recommended profile differs from the requested profile.
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.pipeline.nextflow.config.NextflowConfig(docker_image: str = 'ghcr.io/austin-s-h/sirnaforge:latest', profile: str = 'docker', work_dir: Path | None = None, nxf_home: Path | None = None, max_cpus: int | None = None, max_memory: str = '128.GB', max_time: str = '240.h', **kwargs: Any)[source]ο
Bases:
objectConfiguration manager for Nextflow workflows.
- DEFAULT_SIRNAFORGE_DOCKER_IMAGE = 'ghcr.io/austin-s-h/sirnaforge:latest'ο
- MEMORY_BUFFER_GB = 0.5ο
- MIN_MEMORY_GB = 1ο
- __init__(docker_image: str = 'ghcr.io/austin-s-h/sirnaforge:latest', profile: str = 'docker', work_dir: Path | None = None, nxf_home: Path | None = None, max_cpus: int | None = None, max_memory: str = '128.GB', max_time: str = '240.h', **kwargs: Any) None[source]ο
Initialize Nextflow configuration.
- Parameters:
docker_image β Docker container image to use
profile β Nextflow profile (docker, singularity, conda, local)
work_dir β Working directory for Nextflow execution
nxf_home β Nextflow home cache
max_cpus β Maximum CPU cores (defaults to available CPUs, capped at 16)
max_memory β Maximum memory allocation
max_time β Maximum execution time
**kwargs β Additional configuration parameters
- get_nextflow_args(input_file: Path, output_dir: Path, screen_species: list[str], additional_params: dict[str, Any] | None = None, include_test_profile: bool = False) list[str][source]ο
Generate Nextflow command arguments.
- Parameters:
input_file β Input FASTA file path
output_dir β Output directory
screen_species β Species the screen covers, as resolved from its references
additional_params β Additional parameters to pass
include_test_profile β Whether to include βtestβ profile for integration testing
- Returns:
List of command arguments for Nextflow
- create_config_file(config_path: Path) Path[source]ο
Create a custom Nextflow configuration file.
- Parameters:
config_path β Path where to create the config file
- Returns:
Path to the created configuration file
- validate_docker_available() bool[source]ο
Check if Docker is available for Nextflow execution.
This checks if Docker can be used by Nextflow to run containers. Note: This is different from running tests inside Docker containers.
- Returns:
True if Docker is available and accessible for Nextflow
- is_running_in_docker() bool[source]ο
Check if weβre currently running inside a Docker container.
This is useful for determining the appropriate execution profile when running tests or workflows.
- Returns:
True if running inside a Docker container
- get_execution_profile() str[source]ο
Get the appropriate execution profile based on available tools and environment.
This method considers: 1. Environment variables (SIRNAFORGE_USE_LOCAL_EXECUTION) 2. Whether weβre running inside a Docker container (for testing) 3. Whether Docker is available for Nextflow execution 4. Availability of Singularity or Conda as fallbacks 5. The requested profile
- Returns:
Recommended execution profile
- get_environment_info() EnvironmentInfo[source]ο
Get information about the current execution environment.
This provides structured information about Docker availability, profile selection, and environment detection.
- Returns:
EnvironmentInfo model with environment details
- classmethod for_testing() NextflowConfig[source]ο
Create a configuration optimized for testing.
This automatically detects if weβre running in Docker and adjusts accordingly. Uses uv/conda for environment management when available.
- Returns:
NextflowConfig instance with test-friendly settings
- classmethod for_production(**kwargs: Any) NextflowConfig[source]ο
Create a configuration optimized for production use.
This uses Docker by default for reproducible execution with full resources.
- Parameters:
**kwargs β Additional configuration parameters to override defaults
- Returns:
NextflowConfig instance with production settings
- classmethod auto_configure(**kwargs: Any) NextflowConfig[source]ο
Auto-configure Nextflow settings based on environment detection.
This method automatically detects available tools and selects the best profile.
- Parameters:
**kwargs β Additional configuration parameters to override defaults
- Returns:
NextflowConfig instance with auto-detected settings
Nextflow Runnerο
Nextflow Pipeline Runner.
This module provides a Python interface to execute Nextflow workflows for siRNA off-target analysis with proper Docker integration.
- class sirnaforge.pipeline.nextflow.runner.NextflowRunner(config: NextflowConfig | None = None)[source]ο
Bases:
objectExecute Nextflow workflows from Python with proper error handling.
- __init__(config: NextflowConfig | None = None)[source]ο
Initialize Nextflow runner.
- Parameters:
config β NextflowConfig instance, creates auto-configured if None
- async run(input_file: Path, output_dir: Path, screen_species: list[str] | None = None, **kwargs: Any) dict[str, Any][source]ο
Simple method to run Nextflow workflow with auto-validation and defaults.
- Parameters:
input_file β Path to input FASTA file
output_dir β Output directory for results
screen_species β Species to screen against (defaults to [βhumanβ, βratβ, βrhesusβ])
**kwargs β Additional parameters passed to run_offtarget_analysis
- Returns:
Dictionary containing execution results and metadata
- Raises:
NextflowExecutionError β If workflow execution fails
- run_sync(input_file: Path, output_dir: Path, screen_species: list[str] | None = None, **kwargs: Any) dict[str, Any][source]ο
Synchronous version of run() for simpler usage without async/await.
- Parameters:
input_file β Path to input FASTA file
output_dir β Output directory for results
screen_species β Species to screen against (defaults to [βhumanβ, βratβ, βrhesusβ])
**kwargs β Additional parameters passed to run_offtarget_analysis
- Returns:
Dictionary containing execution results and metadata
- async run_offtarget_analysis(input_file: Path, output_dir: Path, screen_species: list[str], additional_params: dict[str, Any] | None = None, show_progress: bool = True) dict[str, Any][source]ο
Run the off-target analysis Nextflow workflow.
- Parameters:
input_file β Path to siRNA candidates FASTA file
output_dir β Output directory for results
screen_species β Species to screen against for off-target liabilities
additional_params β Additional parameters for the workflow
show_progress β Whether to show progress indicators
- Returns:
Dictionary containing execution results and metadata
- Raises:
NextflowExecutionError β If workflow execution fails
- validate_installation() dict[str, bool | str][source]ο
Validate that Nextflow and required tools are available.
- Returns:
Dictionary of tool availability status
- classmethod for_testing() NextflowRunner[source]ο
Create a runner configured for testing.
This uses the test configuration which automatically detects if weβre running in Docker and adjusts accordingly.
- Returns:
NextflowRunner configured for testing
- classmethod create(**config_kwargs: Any) NextflowRunner[source]ο
Create a NextflowRunner with auto-configured settings.
- Parameters:
**config_kwargs β Configuration parameters for NextflowConfig
- Returns:
NextflowRunner with auto-configured NextflowConfig
- exception sirnaforge.pipeline.nextflow.runner.NextflowExecutionError(message: str, stdout: str = '', stderr: str = '')[source]ο
Bases:
ExceptionException raised when Nextflow execution fails.
- __init__(message: str, stdout: str = '', stderr: str = '')[source]ο
Initialize the exception with message and optional stdout/stderr.
- Parameters:
message β Error message describing what went wrong
stdout β Standard output from the failed command
stderr β Standard error from the failed command
Pipeline Resourcesο
Resource Management for siRNAforge Pipeline.
This module provides utilities for managing test data and pipeline resources.
- sirnaforge.pipeline.resources.resources.get_resource_path(resource_name: str) Path[source]ο
Get path to a pipeline resource file.
- Parameters:
resource_name β Name of the resource file
- Returns:
Path to the resource file
- Raises:
FileNotFoundError β If resource is not found
- sirnaforge.pipeline.resources.resources.get_test_data_path(filename: str) Path[source]ο
Get path to test data file.
- Parameters:
filename β Name of the test data file
- Returns:
Path to the test data file
- Raises:
FileNotFoundError β If test data file is not found
- sirnaforge.pipeline.resources.resources.validate_test_data() dict[str, bool][source]ο
Validate that required test data files are present.
- Returns:
Dictionary mapping filenames to availability status
Workflow Orchestrationο
siRNAforge Workflow Orchestrator.
Coordinates the complete siRNA design pipeline: 1. Transcript retrieval and validation 2. ORF validation and reporting 3. siRNA candidate generation and scoring 4. Top-N candidate selection and reporting 5. Off-target analysis with Nextflow pipeline
- sirnaforge.workflow.describe_shortfall_reasons(reasons: Mapping[str, int]) str[source]ο
One human sentence naming what was actually missing, most costly first.
no_evidence:<channel>:<species>andunknown:<filter_id>are different problems with different fixes β a screen to re-run against, versus an annotation the gate could not read β so the console says which rather than attributing both to screening.
- sirnaforge.workflow.screening_run_status(*, status: str, reason: str = '', required_evidence_missing: bool = False) RunStatus[source]ο
Translate one screening exitβs
{status, reason}pair into the one run-status vocabulary.Pure and total, because it is the single definition of what those seven string pairs mean (#100) and every exit is stamped through it. The result is published beside
status/reason, never instead of them.required_evidence_missingis what lets a step whose own word iscompletedreportINCOMPLETE:statusis decided from the aggregateβs self-report, which says nothing was missing whenever aggregation itself is what failed, while the reconciled evidence knows the unit was planned and published nothing. An unrecognised status word claims no completeness rather than inheriting one, so a new exit cannot arrive silently readingCOMPLETED.
- class sirnaforge.workflow.CandidateTablePaths(all_csv: Path, pass_csv: Path, pass_fasta: Path, qualified_csv: Path, qualified_fasta: Path, provisional_csv: Path, manifest_json: Path)[source]ο
Bases:
NamedTupleWhere a runβs candidate tables and manifest live, named once for both entry points.
step6_generate_reportsandSiRNAWorkflow.write_offtarget_only_exports()publish the same six files into the samesirnaforge/sub-directory, which is what letssirnaforge report <output_dir>read either kind of run with no special case.- classmethod under(base: Path) CandidateTablePaths[source]ο
The table paths under one runβs
sirnaforge/directory.
- class sirnaforge.workflow.OffTargetGateCounts(transcriptome_0mm: int = 0, transcriptome_1mm: int = 0, transcriptome_2mm: int = 0, transcriptome_seed_0mm: int = 0, mirna_0mm_seed: int = 0, mirna_high_risk: int = 0, total_hits: int = 0, genuine_off_target_count: int = 0, transcriptome_by_species: Mapping[str, Mapping[str, int]] | None = None)[source]ο
Bases:
NamedTupleThe counts the off-target gates compare, one field per gate input.
Named so the no-hit and with-hit paths can hand the same eight numbers to the same gate call, which reads them by field name β so field order here carries no meaning and reordering one cannot feed a gate the wrong number. Every field defaults to zero and
_ZERO_OFFTARGET_COUNTSis that all-zero instance: a completed screen that found nothing is a measurement of zero, and giving it a name is what stopped the clean-screen path from skipping the gates entirely (issue #106).
- sirnaforge.workflow.POST_SCREEN_FILTER_CHANNELS: Mapping[str, frozenset[ScreeningChannel]] = {'fail_on_high_risk_mirna': frozenset({ScreeningChannel.MIRNA_SEED}), 'max_mirna_1mm_seed': frozenset({ScreeningChannel.MIRNA_SEED}), 'max_mirna_perfect_seed': frozenset({ScreeningChannel.MIRNA_SEED}), 'max_off_target_count': frozenset({ScreeningChannel.TRANSCRIPTOME}), 'max_total_offtarget_hits': frozenset({ScreeningChannel.MIRNA_SEED, ScreeningChannel.TRANSCRIPTOME}), 'max_transcript_seed_sites': frozenset({ScreeningChannel.TRANSCRIPT_SEED}), 'max_transcriptome_hits_0mm': frozenset({ScreeningChannel.TRANSCRIPTOME}), 'max_transcriptome_hits_1mm': frozenset({ScreeningChannel.TRANSCRIPTOME}), 'max_transcriptome_hits_2mm': frozenset({ScreeningChannel.TRANSCRIPTOME}), 'max_transcriptome_seed_perfect': frozenset({ScreeningChannel.TRANSCRIPTOME})}ο
Which screening channel supplies each post-screen gateβs count. One mapping, because
_check_offtarget_filtersand_apply_post_screen_rankingboth need this answer and must not diverge. A declared filter absent from it reads design-time or annotation evidence instead (min_isoform_coverage, every design-stage gate), so an incomplete channel never excuses it.
- sirnaforge.workflow.RENAMED_ARGUMENTS: Mapping[str, str] = {'genome_indices_override': 'transcriptome_indices', 'genome_species': 'screen_species'}ο
nothing silently maps an old name onto the new one, because the two were never quite the same thing β
genome_indices_overridebypassed reference resolution, andtranscriptome_indicesdoes not. They are still named here so the failure quotes the replacement instead of βunexpected keywordβ.- Type:
0.7.0 keyword arguments the #99 rename removed, and what to pass instead. A hard break
- sirnaforge.workflow.RENAMED_NEXTFLOW_PARAMS: Mapping[str, str] = {'genome_fastas': 'transcriptome_fastas', 'genome_indices': 'transcriptome_indices', 'genome_species': 'transcriptome_species'}ο
Nextflow accepts an unknown
--paramsilently, so a stalegenome_indicesin a rawnextflow_configwould configure nothing and the run would screen against nothing and report success.- Type:
Pipeline parameters the rename removed. Refused rather than ignored
- sirnaforge.workflow.refuse_renamed_arguments(supplied: Mapping[str, Any]) None[source]ο
Refuse a removed
genome_*keyword, naming its replacement.- Raises:
TypeError β Any keyword was supplied. Unknown keywords are reported the same way Python would, so a typo does not read as a rename.
- class sirnaforge.workflow.WorkflowConfig(output_dir: Path, gene_query: str, input_fasta: Path | None = None, database: DatabaseType = DatabaseType.ENSEMBL, design_params: DesignParameters | None = None, nextflow_config: Mapping[str, Any] | None = None, transcriptome_indices: str | None = None, screen_species: list[str] | None = None, query_species: str | None = None, mirna_database: str = 'mirgenedb', mirna_species: Sequence[str] | None = None, transcriptome_fasta: str | None = None, transcriptome_filter: str | None = None, transcriptome_selection: ReferenceSelection | None = None, ortholog_mapping_file: Path | str | None = None, validation_config: ValidationConfig | None = None, log_file: str | None = None, write_json_summary: bool = True, quilt_summarize: bool = False, num_threads: int | None = None, input_source: InputSource | None = None, keep_nextflow_work: bool = False, variant_config: VariantWorkflowConfig | None = None, zfn_config: ZFNWorkflowConfig | None = None, resolved_policy: ResolvedRunPolicy | None = None, mirna_reference_manifest: str | Path | None = None, target_intent_request: TargetIntentRequest | None = None, transcript_seed_species: Sequence[str] | None = None, transcript_seed_required_species: Sequence[str] = (), transcript_seed_scope: TranscriptSequenceScope | str = TranscriptSequenceScope.FULL_CDNA, max_transcript_seed_sites: int | None = None, aligner: str = 'bwa-mem2', report_mode: Literal['auto', 'compact_single_file', 'paged_single_file', 'data_backed'] = 'auto', report_artifact_dir: Path | None = None, report_thresholds: ReportModeThresholds | None = None, **renamed: Any)[source]ο
Bases:
objectConfiguration for the complete siRNA design workflow.
- __init__(output_dir: Path, gene_query: str, input_fasta: Path | None = None, database: DatabaseType = DatabaseType.ENSEMBL, design_params: DesignParameters | None = None, nextflow_config: Mapping[str, Any] | None = None, transcriptome_indices: str | None = None, screen_species: list[str] | None = None, query_species: str | None = None, mirna_database: str = 'mirgenedb', mirna_species: Sequence[str] | None = None, transcriptome_fasta: str | None = None, transcriptome_filter: str | None = None, transcriptome_selection: ReferenceSelection | None = None, ortholog_mapping_file: Path | str | None = None, validation_config: ValidationConfig | None = None, log_file: str | None = None, write_json_summary: bool = True, quilt_summarize: bool = False, num_threads: int | None = None, input_source: InputSource | None = None, keep_nextflow_work: bool = False, variant_config: VariantWorkflowConfig | None = None, zfn_config: ZFNWorkflowConfig | None = None, resolved_policy: ResolvedRunPolicy | None = None, mirna_reference_manifest: str | Path | None = None, target_intent_request: TargetIntentRequest | None = None, transcript_seed_species: Sequence[str] | None = None, transcript_seed_required_species: Sequence[str] = (), transcript_seed_scope: TranscriptSequenceScope | str = TranscriptSequenceScope.FULL_CDNA, max_transcript_seed_sites: int | None = None, aligner: str = 'bwa-mem2', report_mode: Literal['auto', 'compact_single_file', 'paged_single_file', 'data_backed'] = 'auto', report_artifact_dir: Path | None = None, report_thresholds: ReportModeThresholds | None = None, **renamed: Any)[source]ο
Initialize workflow configuration.
resolved_policyis the run policy resolved once byconfig/run_policy.py. A caller that supplies its owndesign_paramsinstead gets the same object built by the adapter, so every path β CLI, Python API, off-target-only, direct WorkflowConfig β carries a policy and none of them re-derives a threshold. Resolution happens before the output directories below are created, so an invalid configuration costs nothing.screen_speciesare the species this run asks to screen;transcriptome_indicesarespecies:index_prefixreferences the caller has already built. Both feed one resolver (#99), so an override and a default differ only in provenance.**renamedexists solely to refuse the 0.7.0genome_*spellings with the new name rather than a bare TypeError.
- class sirnaforge.workflow.ZFNWorkflowConfig(zfn_params: ZFNDesignParameters, annotation: GenomicAnnotationConfig | None = None)[source]ο
Bases:
objectConfiguration for ZFN pair evaluation and off-target search workflow.
This carries the scientifically distinct ZFN parameters: - Left/right half-site sequences (IUPAC-validated, 9-18 bp) - Genomic search space (whole-genome FASTA) - Algorithm choice (homology / conserved_g / zfn_v2) - Spacer/dimer/mismatch constraints - Optional genomic annotation for region classification
- __init__(zfn_params: ZFNDesignParameters, annotation: GenomicAnnotationConfig | None = None)[source]ο
Initialize ZFN workflow configuration.
- class sirnaforge.workflow.SiRNAWorkflow(config: WorkflowConfig)[source]ο
Bases:
objectMain workflow orchestrator for siRNA/miRNA/ZFN design pipeline.
- __init__(config: WorkflowConfig)[source]ο
Initialize the workflow orchestrator.
- zfn_designer: ZFNDesigner | Noneο
- sirnaforgeer: SiRNADesigner | MiRNADesigner | Noneο
- async run_complete_workflow() dict[str, Any][source]ο
Run the complete design workflow (siRNA/miRNA or ZFN).
- async step1_retrieve_transcripts(progress: Progress) list[TranscriptInfo][source]ο
Step 1: Retrieve and validate transcript sequences.
- async resolve_variants_step(progress: Progress) list[VariantRecord][source]ο
Resolve variants for targeting or avoidance (optional workflow step).
Runs after transcript retrieval and before ORF validation and siRNA design, using ClinVar, Ensembl Variation, and/or VCF files.
- Parameters:
progress β Rich progress tracker
- Returns:
List of resolved VariantRecords that passed filters
- async step2_validate_orfs(transcripts: list[TranscriptInfo], progress: Progress) dict[str, Any][source]ο
Step 2: Validate ORFs and generate validation report.
- async step3_design_sirnas(transcripts: list[TranscriptInfo], progress: Progress) DesignResult[source]ο
Step 3: Design siRNA candidates for valid transcripts.
Parallelizes per-transcript design when not running from a user-provided input FASTA, to preserve backward-compatibility with tests and monkeypatching of design_from_file. Set env SIRNAFORGE_PARALLEL_DESIGN=1 to force parallel mode.
The two branches have inverse failure modes, and only the parallel one needs a record (#100). The single-call branch has no try/except at all: a design failure propagates and the run stops, so no result can claim a target set the designer never covered. The parallel branch catches a failed batch (and, inside the batch, a failed transcript) and carries on, which is the right call for a 40-transcript gene β but the loss has to be written down, so every dropped transcript id goes to
_design_input_shortfallsand from there intodesign_summaryandSelectionInputs.design_input_shortfalls.
- async step6_generate_reports(design_results: DesignResult) None[source]ο
Step 6: Generate comprehensive reports.
Four candidate tables, and the difference between them is the point (#100).
candidates_allis every row;candidates_passis the gate verdict and nothing else, kept exactly as it was because it is the compat deliverable (narrowing it once deleted the whole output of an unscreened run);candidates_qualifiedandcandidates_provisionalare the selection, named as files so βwhich of these can I order?β does not depend on the reader knowing to filter a column.
- write_offtarget_only_exports(candidates: Sequence[SiRNACandidate]) dict[str, str][source]ο
Publish the candidate tables and the manifest for a run of pre-designed guides (#100).
run_offtarget_only_workflowbypasses step5 and step6 entirely. This writes the same four tables step6 writes, from the same_build_candidate_frame()into the samesirnaforge/sub-directory, so one column set and one directory shape serve both entry points andsirnaforge report <output_dir>needs no special case.What is not published is as deliberate. A pre-designed guide arrives with no design score and no transcript context, so
design_score,composite_scoreand every accessibility column stay null andscored_after_screeningstays False: score-unavailable is the honest cell. Deriving accessibility from the guide alone would be a fabricated target measurement, and falling back to a design score would invent a potency claim for a guide this tool did not design. Nothing here writes an ORF report either, because no ORF was validated.- Returns:
the qualified FASTA is absent when nothing qualified.
- Return type:
Written file name -> path, for the callerβs own result dictionary. Only files that exist
- async step5_offtarget_analysis(design_results: DesignResult) dict[str, Any][source]ο
Step 5: Detect repeat elements, then run off-target analysis via the Nextflow pipeline.
Repeat detection runs here rather than as its own workflow step so it can reuse the transcriptome reference this step already materializes for screening, instead of fetching it a second time just to locate the query speciesβ FASTA. The corollary is that
check_off_targets=False(--skip-off-targets) skips repeat detection as well: both are reference-based scans, and the reference is what the flag exists to avoid paying for.
- sirnaforge.workflow.apply_zfn_runtime_overrides(zfn_design_params: ZFNDesignParameters, nextflow_config_overrides: dict[str, Any]) ZFNDesignParameters[source]ο
Apply non-CLI ZFN sharding/runtime overrides and project Nextflow params.
Starts from
zfn_design_params.sharding(typed defaults are authoritative), merges optional JSON overrides fromSIRNAFORGE_ZFN_SHARDING_JSON, and mirrors the resolved sharding values intonextflow_config_overridesso the Nextflow route and direct Python route share the same effective config.The runtime search implementation remains generic and contig-aware, including chunk sharding on single-contig inputs when sharding is enabled.
- async sirnaforge.workflow.run_sirna_workflow(gene_query: str, output_dir: str, input_fasta: str | None = None, database: str = 'ensembl', design_mode: str = 'sirna', top_n_candidates: int | None = None, screen_species: list[str] | None = None, query_species: str | None = None, transcriptome_indices: str | None = None, mirna_database: str = 'mirgenedb', mirna_species: Sequence[str] | None = None, transcriptome_fasta: str | None = None, transcriptome_filter: str | None = None, transcriptome_selection: ReferenceSelection | None = None, ortholog_mapping_file: Path | str | None = None, resolved_policy: ResolvedRunPolicy | None = None, run_mode: str | None = None, policy_config: Path | str | None = None, filter_actions: Mapping[str, Any] | None = None, gc_min: float | None = None, gc_max: float | None = None, sirna_length: int | None = None, modification_pattern: str | None = None, overhang: str | None = None, zfn_design_params: ZFNDesignParameters | None = None, zfn_annotation: GenomicAnnotationConfig | None = None, check_off_targets: bool | None = None, variant_ids: list[str] | None = None, variant_vcf_file: Path | None = None, variant_mode: str = 'avoid', variant_min_af: float = 0.01, variant_clinvar_filters: str = 'Pathogenic,Likely pathogenic', variant_assembly: str = 'GRCh38', log_file: str | None = None, write_json_summary: bool = True, num_threads: int | None = None, allow_transcriptome_with_input_fasta: bool = False, default_transcriptome_sources: Sequence[str] = ('ensembl_human_cdna', 'ensembl_mouse_cdna', 'ensembl_rat_cdna', 'ensembl_macaque_cdna'), keep_nextflow_work: bool = False, nextflow_docker_image: str | None = None, max_hits: int | None = None, max_off_targets: int | None = None, min_asymmetry_score: float | None = None, max_paired_fraction: float | None = None, min_empirical_score: float | None = None, min_isoform_coverage: float | None = None, plfold_window: int | None = None, plfold_max_bp_span: int | None = None, accessibility_log_floor: float | None = None, mirna_reference_manifest: str | Path | None = None, target_intent_request: TargetIntentRequest | None = None, transcript_seed_species: Sequence[str] | None = None, transcript_seed_required_species: Sequence[str] = (), transcript_seed_scope: TranscriptSequenceScope | str = TranscriptSequenceScope.FULL_CDNA, max_transcript_seed_sites: int | None = None, aligner: str = 'bwa-mem2', report_mode: Literal['auto', 'compact_single_file', 'paged_single_file', 'data_backed'] = 'auto', report_artifact_dir: Path | None = None, report_thresholds: ReportModeThresholds | None = None, **renamed: Any) dict[str, Any][source]ο
Run complete siRNA design workflow.
- Parameters:
gene_query β Gene name or ID to search for
output_dir β Directory for output files
input_fasta β Local path or remote URI to an input FASTA file
database β Database to search (ensembl, refseq, gencode)
design_mode β Design mode (sirna, mirna, or zfn)
top_n_candidates β Cap on distinct normalized guide sequences in the shortlist (None = no cap). Enumeration and screening cover all transcript-context rows.
screen_species β Species to screen against for off-target liabilities
query_species β Organism the TARGET transcripts belong to. Defaults to the organism the gene-query database serves (human), which is also the species of the default transcriptome; set it when designing against an input FASTA from another organism.
transcriptome_indices β Comma-separated species:/index_prefix transcriptome references the caller has already built. Replaces automatic transcriptome references; explicitly supplied transcriptome FASTAs are screened alongside these indices.
mirna_reference_manifest β Optional JSON manifest of pinned local mature miRNA references.
target_intent_request β Optional validated target-intent declaration, resolved against the full annotation set.
transcript_seed_species β Species with a usable materialized cDNA reference to scan for seed sites.
transcript_seed_required_species β Subset of transcript_seed_species required for qualification; others are exploratory.
transcript_seed_scope β Full cDNA or explicit 3β²UTR; plain cDNA FASTA has no UTR annotation.
max_transcript_seed_sites β Optional per-guide ceiling over requested transcript-seed species.
report_mode β HTML report layout selection; auto chooses from artifact size and row counts.
report_artifact_dir β Optional destination for normalized report artifacts.
report_thresholds β Optional deterministic auto-mode size and row-count limits.
aligner β Transcriptome alignment backend: bwa-mem2 or bwa-mem3 (plain mode).
mirna_database β miRNA reference database identifier
mirna_species β miRNA reference species identifiers
transcriptome_fasta β Path or URL to transcriptome FASTA for off-target analysis
transcriptome_filter β Comma-separated filter names (protein_coding, canonical_only)
transcriptome_selection β Pre-resolved transcriptome selection metadata
ortholog_mapping_file β JSON mapping of query gene -> species -> orthologue gene IDs. Supply it to resolve cross-species orthology offline instead of calling Ensembl Compara.
resolved_policy β A policy already resolved by
config.run_policy.resolve_run_policyβ how the CLI passes its resolution, so the command line and this function cannot diverge. Supplying it together with any of the threshold arguments below is an error, because two resolutions of the same run could disagree.run_mode β design_only, exploratory or qualified. Defaults to qualified;
check_off_targetsset False maps to design_only, as the legacy skip flag does.policy_config β JSON/TOML policy file; beats the built-in profile, loses to explicit values.
filter_actions β
filter_id -> off|warn|fail. A filter set to off is not evaluated.gc_min β Minimum GC content percentage. None means unstated, so the profile applies.
gc_max β Maximum GC content percentage. None means unstated, so the profile applies β which for siRNA mode is 60.0.
sirna_length β siRNA length in nucleotides (None = profile default)
modification_pattern β Chemical modification pattern (None = profile default)
overhang β Overhang sequence, dTdT for DNA or UU for RNA (None = profile default, and UU in miRNA design mode)
zfn_design_params β Optional ZFN design parameters for ZFN mode workflow
zfn_annotation β Optional genomic annotation config for ZFN off-target classification
check_off_targets β Perform off-target analysis stage. None means unstated (screening on); False maps the run mode to design_only.
variant_ids β List of variant identifiers (rsID, chr:pos:ref:alt, or HGVS) to target or avoid
variant_vcf_file β Path to VCF file containing variants to target or avoid
variant_mode β How to handle variants (avoid/target/both) - default is avoid
variant_min_af β Minimum allele frequency threshold for variant filtering (default: 0.01)
variant_clinvar_filters β Comma-separated ClinVar significance levels to include (default: Pathogenic,Likely pathogenic)
variant_assembly β Reference genome assembly for variants (only GRCh38 supported)
log_file β Path to centralized log file
write_json_summary β Write logs/workflow_summary.json
num_threads β Optional override for design parallelism
allow_transcriptome_with_input_fasta β Opt in to resolving
default_transcriptome_sourceswheninput_fastais supplied (default: False). Left False, an input-FASTA run is design-only unlesstranscriptome_fastanames a reference explicitly: supplying your own sequences should never trigger a multi-gigabyte reference download you did not ask for. Set True to screen an input-FASTA run against the bundled defaults.default_transcriptome_sources β Ordered list of transcriptome identifiers evaluated by default
keep_nextflow_work β Keep Nextflow work directory symlink in output
nextflow_docker_image β Override Docker image used by the embedded Nextflow pipeline
max_hits β Override the pipelineβs per-candidate off-target hit cap (None keeps the pipelineβs exhaustive default; set a lower value, e.g. 10000, to speed up large gene-family searches)
max_off_targets β Override the genuine off-target ceiling that gates PASS vs EXCESS_OFF_TARGETS (None keeps OffTargetFilterCriteriaβs default of 15). Unlike max_hits this changes the verdict, not how many hits are recorded.
min_asymmetry_score β Override the thermodynamic asymmetry floor gating LOW_ASYMMETRY (None keeps FilterCriteriaβs default of 0.65).
max_paired_fraction β Override the guide self-structure ceiling gating EXCESS_PAIRING (None keeps FilterCriteriaβs default of 0.6).
min_empirical_score β Override the empirical design-rule floor gating LOW_EMPIRICAL_SCORE (None keeps FilterCriteriaβs default).
min_isoform_coverage β Opt into the protein-coding isoform coverage gate (LOW_ISOFORM_COVERAGE). None, the default, means no gate: coverage is reported on every candidate either way, and no floor has been calibrated against truth data.
plfold_window β Override the RNAplfold averaging window W used by the target_accessibility term (None keeps the default of 150).
plfold_max_bp_span β Override the RNAplfold maximum base-pair span L (None keeps 100).
accessibility_log_floor β Override the log10-probability floor the accessibility term is normalised against (None keeps -5.0). Changing any of these three changes the numeric scale of composite_score, so results are not comparable with a default run.
**renamed β Accepted only to refuse the
genome_*names the #99 rename removed, quoting the replacement instead of βunexpected keyword argumentβ.
- Returns:
Dictionary with complete workflow results
- async sirnaforge.workflow.run_offtarget_only_workflow(input_candidates_fasta: str, output_dir: str, screen_species: list[str] | None = None, query_species: str | None = None, transcriptome_indices: str | None = None, mirna_database: str = 'mirgenedb', mirna_species: Sequence[str] | None = None, transcriptome_fasta: str | None = None, transcriptome_filter: str | None = None, transcriptome_selection: ReferenceSelection | None = None, ortholog_mapping_file: Path | str | None = None, log_file: str | None = None, nextflow_docker_image: str | None = None, resolved_policy: ResolvedRunPolicy | None = None, run_mode: str | None = None, policy_config: Path | str | None = None, filter_actions: Mapping[str, Any] | None = None, mirna_reference_manifest: str | Path | None = None, aligner: str = 'bwa-mem2', **renamed: Any) dict[str, Any][source]ο
Run off-target-only workflow for pre-designed siRNA candidates.
This is a simplified workflow that only runs the off-target analysis stage without transcript retrieval, ORF validation, or siRNA design. It accepts pre-designed 21-nt siRNA guide sequences and runs comprehensive off-target analysis using the embedded Nextflow pipeline.
- Parameters:
input_candidates_fasta β Path to FASTA file with 21-nt siRNA guide sequences
output_dir β Directory for output files
screen_species β Species to screen against for off-target liabilities
query_species β Organism the input guides were designed against (defaults to human)
transcriptome_indices β Comma-separated species:/index_prefix transcriptome references the caller has already built. Replaces automatic references while retaining explicit FASTAs.
mirna_reference_manifest β Optional JSON manifest of pinned local mature miRNA references.
aligner β Transcriptome alignment backend: bwa-mem2 or bwa-mem3 (plain mode).
mirna_database β miRNA reference database identifier
mirna_species β miRNA reference species identifiers
transcriptome_fasta β Path or URL to transcriptome FASTA for off-target analysis
transcriptome_filter β Comma-separated filter names (protein_coding, canonical_only)
transcriptome_selection β Pre-resolved transcriptome selection metadata
ortholog_mapping_file β JSON mapping of query gene -> species -> orthologue gene IDs, used instead of Ensembl Compara for cross-species orthology
log_file β Path to centralized log file
nextflow_docker_image β Override Docker image used by the embedded Nextflow pipeline
resolved_policy β A policy already resolved by
config.run_policy.resolve_run_policy, which is where this pathβs off-target thresholds come from.run_mode β design_only, exploratory or qualified (default: qualified).
policy_config β JSON/TOML policy file; beats the built-in profile, loses to explicit values.
filter_actions β
filter_id -> off|warn|fail.**renamed β Accepted only to refuse the
genome_*names the #99 rename removed, quoting the replacement instead of βunexpected keyword argumentβ.
- Returns:
the seven long-standing keys, plus (#100)
selection_summaryβ the resolved selection, counted by exclusion reason β andwritten_files. A run that could qualify nobody is a result, not a failure: it reports an empty shortlist and still returns normally.- Return type:
Dictionary with off-target analysis results
Variant Workflow Integrationο
Workflow integration for variant targeting.
- class sirnaforge.workflow_variant.VariantWorkflowConfig(variant_ids: list[str] | None = None, vcf_file: Path | None = None, variant_mode: VariantMode = VariantMode.AVOID, min_af: float = 0.01, clinvar_filter_levels: list[ClinVarSignificance] | None = None, assembly: str = 'GRCh38', cache_dir: Path | None = None)[source]ο
Bases:
objectConfiguration for variant targeting in the workflow.
- __init__(variant_ids: list[str] | None = None, vcf_file: Path | None = None, variant_mode: VariantMode = VariantMode.AVOID, min_af: float = 0.01, clinvar_filter_levels: list[ClinVarSignificance] | None = None, assembly: str = 'GRCh38', cache_dir: Path | None = None)[source]ο
Initialize variant workflow configuration.
- Parameters:
variant_ids β List of variant identifiers (rsID, coordinate, HGVS)
vcf_file β Path to VCF file with variants
variant_mode β How to handle variants (avoid/target/both)
min_af β Minimum allele frequency threshold
clinvar_filter_levels β Allowed ClinVar significance levels
assembly β Reference genome assembly (only GRCh38 supported)
cache_dir β Cache directory for variant data
- async sirnaforge.workflow_variant.resolve_workflow_variants(config: VariantWorkflowConfig, gene_name: str, output_dir: Path) list[VariantRecord][source]ο
Resolve all variants for the workflow.
This is an optional workflow step that runs after gene/transcript selection and before siRNA candidate design.
- Parameters:
config β Variant workflow configuration
gene_name β Gene name for logging/reporting
output_dir β Output directory for reports
- Returns:
List of resolved VariantRecords passing filters
- sirnaforge.workflow_variant.normalize_variant_mode(mode: str | VariantMode) VariantMode[source]ο
Normalize variant mode to enum, handling string input.
- Parameters:
mode β Variant mode as string or enum
- Returns:
VariantMode enum
- Raises:
ValueError β If mode string is invalid
- sirnaforge.workflow_variant.parse_clinvar_filter_string(filter_string: str) list[ClinVarSignificance][source]ο
Parse comma-separated ClinVar filter string to enum list.
- Parameters:
filter_string β Comma-separated string of significance levels
- Returns:
List of ClinVarSignificance enums
- Raises:
ValueError β If any significance level is invalid
Validationο
Validation Configurationο
Validation configuration and settings.
- class sirnaforge.validation.config.ValidationLevel(*values)[source]ο
-
Validation strictness levels.
- STRICT = 'strict'ο
- WARNING = 'warning'ο
- DISABLED = 'disabled'ο
- class sirnaforge.validation.config.ValidationStage(*values)[source]ο
-
Pipeline stages where validation can be applied.
- INPUT = 'input'ο
- TRANSCRIPT_RETRIEVAL = 'transcript_retrieval'ο
- ORF_ANALYSIS = 'orf_analysis'ο
- DESIGN = 'design'ο
- FILTERING = 'filtering'ο
- SCORING = 'scoring'ο
- OFF_TARGET = 'off_target'ο
- OUTPUT = 'output'ο
- class sirnaforge.validation.config.ValidationConfig(*, default_level: ValidationLevel = ValidationLevel.STRICT, stage_levels: dict[~sirnaforge.validation.config.ValidationStage, ~sirnaforge.validation.config.ValidationLevel]=<factory>, validate_sequences: bool = True, validate_ranges: bool = True, validate_consistency: bool = True, validate_biology: bool = True, max_validation_errors: Annotated[int, ~annotated_types.Ge(ge=1)] = 100, collect_all_errors: bool = False, batch_size: Annotated[int, ~annotated_types.Ge(ge=1)] = 1000, enable_caching: bool = True)[source]ο
Bases:
BaseModelConfiguration for validation system.
- default_level: ValidationLevelο
- stage_levels: dict[ValidationStage, ValidationLevel]ο
- get_level_for_stage(stage: ValidationStage) ValidationLevel[source]ο
Get validation level for a specific stage.
- is_enabled_for_stage(stage: ValidationStage) bool[source]ο
Check if validation is enabled for a stage.
- should_fail_on_error(stage: ValidationStage) bool[source]ο
Check if validation errors should cause failures.
- model_config = {}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class sirnaforge.validation.config.ValidationPresets[source]ο
Bases:
objectPredefined validation configurations.
- static development() ValidationConfig[source]ο
Configuration for development environment.
- static production() ValidationConfig[source]ο
Configuration for production environment.
- static testing() ValidationConfig[source]ο
Configuration for testing environment.
- static performance() ValidationConfig[source]ο
Configuration optimized for performance.
Validation Middlewareο
Validation middleware for integrating validation into the siRNA design workflow.
- class sirnaforge.validation.middleware.ValidationReport(stage: ValidationStage)[source]ο
Bases:
objectComprehensive validation report for a workflow stage.
- __init__(stage: ValidationStage)[source]ο
Initialize validation report.
- add_item_result(result: ValidationResult) None[source]ο
Add validation result for an individual item.
- class sirnaforge.validation.middleware.ValidationMiddleware(config: ValidationConfig)[source]ο
Bases:
objectMiddleware for integrating validation throughout the workflow.
- __init__(config: ValidationConfig)[source]ο
Initialize validation middleware.
- validate_input_parameters(params: DesignParameters) ValidationReport[source]ο
Validate input design parameters.
- validate_transcripts(transcripts: list[TranscriptInfo]) ValidationReport[source]ο
Validate transcript data after retrieval.
- validate_design_results(design_result: DesignResult) ValidationReport[source]ο
Validate siRNA design results.
- validate_dataframe_output(df: DataFrame, schema_type: str) ValidationReport[source]ο
Validate DataFrame output against pandera schemas.
- validate_transcript_id_consistency(transcripts: list[TranscriptInfo], candidates: list[SiRNACandidate], orf_data: DataFrame | None = None) ValidationReport[source]ο
Validate consistency of transcript IDs across datasets.
Validation Utilitiesο
Validation utilities for data consistency and cross-validation.
- class sirnaforge.validation.utils.ValidationResult(is_valid: bool = True)[source]ο
Bases:
objectContainer for validation results.
- merge(other: ValidationResult) None[source]ο
Merge another validation result into this one.
- class sirnaforge.validation.utils.ValidationUtils[source]ο
Bases:
objectUtility functions for data validation.
- static validate_nucleotide_sequence(sequence: str, allow_ambiguous: bool = True) ValidationResult[source]ο
Validate nucleotide sequence composition.
- static validate_sirna_length(sequence: str) ValidationResult[source]ο
Validate siRNA sequence length.
- static validate_parameter_consistency(params: DesignParameters) ValidationResult[source]ο
Validate design parameter consistency.
- static validate_candidate_consistency(candidate: SiRNACandidate) ValidationResult[source]ο
Validate siRNA candidate internal consistency.
- static validate_dataframe_schema(df: DataFrame, schema_type: str) ValidationResult[source]ο
Validate DataFrame against appropriate pandera schema.
- static validate_transcript_ids_consistency(candidate_ids: set[str], orf_ids: set[str], transcript_ids: set[str]) ValidationResult[source]ο
Validate consistency of transcript IDs across datasets.
- static validate_biological_constraints(candidate: SiRNACandidate) ValidationResult[source]ο
Validate bioinformatics-specific constraints.
- static cross_validate_pydantic_pandera() ValidationResult[source]ο
Cross-validate Pydantic model constraints with Pandera schema constraints.
Utilitiesο
Logging Utilitiesο
Logging utilities for siRNAforge toolkit.
This module provides a single point to configure logging for both console and an optional centralized log file. Call configure_logging once at application startup (CLI entrypoint) to enable file logging. Individual modules should use get_logger(__name__) to obtain a configured logger.
- sirnaforge.utils.logging_utils.configure_logging(level: str | None = None, log_file: str | None = None) None[source]ο
Configure root logger: console + optional rotating file handler.
- Parameters:
level β Logging level name (DEBUG/INFO/WARNING/ERROR). If None, uses INFO.
log_file β Path to central log file. If None, will read env var SIRNAFORGE_LOG_FILE. If still None, no file handler is added.
- sirnaforge.utils.logging_utils.get_logger(name: str, level: str | None = None) Logger[source]ο
Get a logger with standard configuration.
This will return a child logger of the root logger configured by configure_logging. For scripts that donβt call configure_logging, get_logger will still set a console handler on first use.
Cache Utilitiesο
Shared cache helpers for siRNAforge.
Centralizes cache path resolution so every subsystem honors the same SIRNAFORGE_CACHE_DIR / XDG cache layout, and the producer-version stamping that lets us discard artifacts a known-bad writer left on disk.
- sirnaforge.utils.cache_utils.resolve_cache_subdir(subdir: str, *, override: str | PathLike[str] | None = None) Path[source]ο
Resolve a writable cache directory for the requested subdir.
The lookup order matches ReferenceManager: explicit override, env vars, XDG, $HOME/.cache, workspace-local fallback, then temp dir.
- sirnaforge.utils.cache_utils.stable_cache_key(payload: Mapping[str, Any]) str[source]ο
Create a deterministic sha256 digest for arbitrary JSON-serializable data.
- sirnaforge.utils.cache_utils.LEGACY_PRODUCER_VERSION = '1.0'ο
Version attributed to artifacts predating producer stamping.
CacheMetadata.version defaults to this string, so old metadata reads as βpre-versioningβ with no migration step needed.
- sirnaforge.utils.cache_utils.PRODUCER_VERSION_FIELD = 'producer_version'ο
Key under which a sidecar artifact stamp records its producer version.
Manager-backed caches keep the same value in CacheMetadata.version. Only artifact classes actually validated somewhere are registered below - a constant nobody checks would read as a guarantee we do not give.
- sirnaforge.utils.cache_utils.current_producer_version(artifact_class: str) str[source]ο
Return the producer version to record for artifact_class.
Unregistered classes report the legacy version: registering a class is what opts it in, so a new cache namespace can never invalidate itself by accident.
- sirnaforge.utils.cache_utils.normalize_producer_version(recorded: object) str[source]ο
Coerce a recorded producer version into a comparable string.
Missing values (None, NaN from a parquet column that did not exist yet, an empty string) all mean the same thing: the artifact predates stamping.
- sirnaforge.utils.cache_utils.is_producer_version_current(artifact_class: str, recorded: object) bool[source]ο
Whether an artifactβs recorded producer version is the current one.
- sirnaforge.utils.cache_utils.log_discarded_artifact(artifact_class: str, artifact: Path | str, reason: str) None[source]ο
Warn that a stale cache artifact is being dropped.
Deliberately WARNING, not DEBUG: this is the one line that explains why a run suddenly spends time regenerating or re-downloading a reference.
- sirnaforge.utils.cache_utils.STAMP_FULL_DIGEST_MAX_BYTES = 67108864ο
Largest output we are willing to read end-to-end on every cache hit.
A combined miRNA FASTA is a few MB, so it is digested whole for a few milliseconds. A BWA-MEM2 index or a transcriptome is gigabytes: reading it in full on every hit would cost more than the cache saves, so those fall back to DIGEST_MODE_SAMPLED.
- sirnaforge.utils.cache_utils.STAMP_SAMPLE_BYTES = 4194304ο
Head/tail window digested for outputs above the full-digest budget.
- sirnaforge.utils.cache_utils.artifact_stamp_path(artifact: Path) Path[source]ο
Return the sidecar stamp path for a derived artifact or index prefix.
- sirnaforge.utils.cache_utils.fingerprint_outputs(outputs: Sequence[Path], *, full_digest_max_bytes: int | None = None) dict[str, dict[str, Any]][source]ο
Fingerprint the bytes an artifact is actually made of.
Keyed by basename so the fingerprint survives a re-homed cache directory, and so a multi-file artifact (a BWA index prefix has four members) records one entry per member and therefore proves its own completeness on read.
Every member records its exact size; the digest is full below STAMP_FULL_DIGEST_MAX_BYTES and sampled above it. Size alone already catches every truncation, which is the failure mode that actually happens.
- sirnaforge.utils.cache_utils.fingerprint_inputs(inputs: Sequence[Path]) dict[str, str][source]ο
MD5 each input file, keyed by position and basename.
Position keeps duplicate basenames distinct; basenames rather than full paths keep the fingerprint stable when a cache directory is re-homed (containers mount it elsewhere). Callers that already hold a digest for a large file should pass it directly rather than paying for a second full read.
- sirnaforge.utils.cache_utils.write_artifact_stamp(artifact_class: str, artifact: Path, *, inputs: Mapping[str, str] | None = None, outputs: Sequence[Path] | None = None, extra: Mapping[str, Any] | None = None) Path[source]ο
Record the producer version, input fingerprint and output bytes of an artifact.
outputs lists the files the artifact consists of, and defaults to the artifact itself. Multi-file artifacts must pass their members explicitly: a BWA index prefix is not a file, and the four files behind it are what has to be verified.
- sirnaforge.utils.cache_utils.read_artifact_stamp(artifact: Path) dict[str, Any] | None[source]ο
Read a derived artifactβs stamp, or None when it is absent/unreadable.
- sirnaforge.utils.cache_utils.discard_artifact_stamp(artifact: Path) None[source]ο
Remove a derived artifactβs stamp so it cannot vouch for a rebuilt file.
- sirnaforge.utils.cache_utils.is_artifact_stamp_current(artifact_class: str, artifact: Path, *, inputs: Mapping[str, str] | None = None, max_age_days: int | None = None) bool[source]ο
Whether a derived artifact may be reused.
Answers βwas it produced by the current code, from exactly these inputs, recently enough - and are its own bytes still the bytes we stampedβ. The last clause is what makes a stamp unable to vouch for an artifact that was truncated or corrupted after it was written, so callers may reuse on a True answer alone.
CLI Input Helpersο
Shared CLI input parsing and validation helpers.
These helpers are intentionally small and side-effect free so that Typer/Rich commands can stay focused on orchestration and UX.
Control Candidatesο
Helpers for injecting control candidates into design results.
- sirnaforge.utils.control_candidates.inject_dirty_controls(design_result: DesignResult, count: int = 2) list[SiRNACandidate][source]ο
Append clearly labelled βdirtyβ control candidates to a design result.
βDirtyβ controls are not synthetic sequences. We intentionally reuse the lowest-scoring rejected candidates from the same run so every control is a plausible design that simply failed QC (GC range, off-target score, etc.). Carrying these borderline guides forward guarantees that the downstream off-target pipeline receives at least a couple of sequences that should light up in the reports, making it easier for users to confirm the workflow is wired correctly.
The clones retain their original guide/passenger sequences and metadata but are marked with
DIRTY_CONTROL. They are appended to bothcandidatesandtop_candidatesso that subsequent stages (CSV export, Nextflow off-target analysis, etc.) see the controls exactly where they expect normal guides. IDs are suffixed with__DIRTY_CONTROL_<n>for clarity.- Parameters:
design_result β Aggregated design result to augment in-place.
count β Number of controls to add (default: 2).
- Returns:
List of control candidates that were appended. Returns an empty list if the design result already contains controls or there are no candidates to copy.
FASTA Utilitiesο
Shared FASTA parsing helpers used across siRNAforge modules.
Modification Patternsο
Utility functions for applying chemical modification patterns to siRNA candidates.
This module provides functions to apply standard modification patterns to siRNA candidates during the design workflow, enabling automated annotation of chemical modifications for downstream synthesis and analysis.
- sirnaforge.utils.modification_patterns.apply_standard_2ome_pattern(sequence: str) list[ChemicalModification][source]ο
Apply standard alternating 2β-O-methyl pattern.
This is the industry-standard pattern providing balanced nuclease resistance and RISC loading efficiency.
- Parameters:
sequence β RNA sequence to modify
- Returns:
List containing one ChemicalModification with alternating positions
- sirnaforge.utils.modification_patterns.apply_minimal_terminal_pattern(sequence: str) list[ChemicalModification][source]ο
Apply minimal terminal modifications for cost-effective protection.
Modifies only the 3β terminal positions to provide basic nuclease resistance while minimizing synthesis cost.
- Parameters:
sequence β RNA sequence to modify
- Returns:
List containing one ChemicalModification with terminal positions
- sirnaforge.utils.modification_patterns.apply_maximal_stability_pattern(sequence: str) list[ChemicalModification][source]ο
Apply maximal stability pattern for in vivo applications.
Fully modified pattern similar to FDA-approved therapeutics, providing maximum nuclease resistance and extended serum half-life.
- Parameters:
sequence β RNA sequence to modify
- Returns:
List containing ChemicalModifications (2OMe on all positions, PS at terminals)
- sirnaforge.utils.modification_patterns.get_modification_pattern(pattern_name: str, sequence: str) list[ChemicalModification][source]ο
Get modification pattern by name.
- Parameters:
pattern_name β Name of the pattern (standard_2ome, minimal_terminal, maximal_stability, none)
sequence β RNA sequence to apply pattern to
- Returns:
List of ChemicalModification objects
- Raises:
ValueError β If pattern_name is not recognized
- sirnaforge.utils.modification_patterns.apply_modifications_to_candidate(candidate: SiRNACandidate, pattern_name: str = 'standard_2ome', overhang: str = 'dTdT', target_gene: str | None = None) SiRNACandidate[source]ο
Apply chemical modifications to a siRNA candidate.
This function annotates both guide and passenger strands with the specified modification pattern and overhang, updating the candidateβs metadata fields.
- Parameters:
candidate β SiRNACandidate to annotate
pattern_name β Modification pattern to apply (default: standard_2ome)
overhang β Overhang sequence (default: dTdT)
target_gene β Optional target gene name for metadata
- Returns:
Updated SiRNACandidate with modification metadata
Resource Resolverο
Utilities for resolving user-provided input resources.
Supports downloading transcript FASTA files from remote locations and normalises them into local paths that the workflow can consume.
- class sirnaforge.utils.resource_resolver.InputSource(original: str, local_path: Path, source_type: str, downloaded: bool, size_bytes: int, sha256: str | None = None)[source]ο
Bases:
objectNormalized representation of a workflow input resource.
- sirnaforge.utils.resource_resolver.resolve_input_source(input_location: str, destination_root: Path, *, timeout: float = 30.0) InputSource[source]ο
Resolve a workflow input location into a local path.
- Parameters:
input_location β Raw string provided by the user (path or URI).
destination_root β Directory where downloaded inputs should be stored.
timeout β Timeout for remote downloads in seconds.
- Returns:
InputSource describing the normalized local resource.
- Raises:
FileNotFoundError β If a local file doesnβt exist.
ValueError β If the URI scheme is unsupported.
httpx.HTTPStatusError β If the remote download fails with non-2xx status.
Species Utilitiesο
Shared helpers for reasoning about species labels.
These utilities centralize the normalization and categorization rules we use when aggregating off-target hits across genome/transcriptome and miRNA pipelines. The helpers intentionally accept very loose inputs (common names, scientific labels, assembly identifiers) so downstream callers can rely on a single implementation when deciding whether a hit should be treated as human-specific.
- sirnaforge.utils.species.bucket_species(label: str | None) str[source]ο
Map an arbitrary label to
"human"or"other".
- sirnaforge.utils.species.human_vs_other_totals(counts: Mapping[str, int]) tuple[int, int][source]ο
Collapse per-species hit counts into
(human, other)totals.
- sirnaforge.utils.species.is_human_species(label: str | None) bool[source]ο
Return
Truewhen the provided label should be bucketed as human.
- sirnaforge.utils.species.normalize_species_label(label: str | None) str[source]ο
Normalize a species label to a lowercase slug.
The transformation removes punctuation, collapses whitespace, and replaces runs of non-alphanumeric characters with a single underscore so strings like
"Homo sapiens (GRCh38)"become"homo_sapiens_grch38".
Typed Decoratorsο
Typed wrappers for third-party decorators used across models.
These wrappers preserve runtime behavior while helping static analyzers (mypy/Pylance) keep function signatures precise when decorator stubs are insufficiently typed.
- sirnaforge.utils.typed_decorators.field_validator_typed(*field_names: str, **kwargs: Any) Callable[[F], F][source]ο
Typed wrapper around pydantic
field_validator.
- sirnaforge.utils.typed_decorators.field_serializer_typed(*field_names: str, **kwargs: Any) Callable[[F], F][source]ο
Typed wrapper around pydantic
field_serializer.
- sirnaforge.utils.typed_decorators.check_types_typed(func: F) F[source]ο
Typed wrapper around pandera
check_types.
Unified Cacheο
Unified cache manager for all sirnaforge reference databases.
Provides a single interface to manage miRNA databases, transcriptomes, and indices using composition and protocol-based design.
- class sirnaforge.utils.unified_cache.CacheStats[source]ο
Bases:
TypedDictStatistics for a cache component.
- class sirnaforge.utils.unified_cache.ClearResult[source]ο
Bases:
TypedDictResult of a cache clear operation.
- class sirnaforge.utils.unified_cache.CacheComponent(*args, **kwargs)[source]ο
Bases:
ProtocolProtocol for cache components.
- cache_info() CacheStats[source]ο
Get cache statistics.
- clear_cache(confirm: bool = False) ClearResult[source]ο
Clear the cache.
- __init__(*args, **kwargs)ο
- class sirnaforge.utils.unified_cache.UnifiedCacheManager[source]ο
Bases:
objectUnified manager for all sirnaforge caches.
Uses composition to combine miRNA and transcriptome caches into a single, easy-to-use interface.
- get_info(include_mirna: bool = True, include_transcriptome: bool = True) dict[str, CacheStats][source]ο
Get cache info for selected components.
- Parameters:
include_mirna β Include miRNA cache stats
include_transcriptome β Include transcriptome cache stats
- Returns:
Dictionary mapping component name to cache stats
- clear(clear_mirna: bool = False, clear_transcriptome: bool = False, dry_run: bool = False) dict[str, ClearResult][source]ο
Clear selected cache components.
- Parameters:
clear_mirna β Clear miRNA databases
clear_transcriptome β Clear transcriptomes and indices
dry_run β Show what would be deleted without deleting
- Returns:
Dictionary mapping component name to clear results
Chemical Modificationsο
Helper functions for working with siRNA chemical modifications metadata.
This module provides utilities for: - Parsing FASTA headers to extract modification metadata - Loading metadata from JSON sidecar files - Encoding/decoding modification annotations
- sirnaforge.modifications.parse_chem_mods(chem_mods_str: str) list[ChemicalModification][source]ο
Parse ChemMods field from FASTA header.
- Parameters:
chem_mods_str β String like β2OMe(1,4,6,11)+2F()β
- Returns:
List of ChemicalModification objects
- sirnaforge.modifications.parse_provenance(prov_str: str, url: str | None = None) Provenance | None[source]ο
Parse Provenance field from FASTA header.
- Parameters:
prov_str β String like βPatent:US10060921B2β
url β Optional URL string
- Returns:
Provenance object or None
- sirnaforge.modifications.parse_header(record: SeqRecord) dict[str, Any][source]ο
Parse FASTA header to extract metadata.
- Parameters:
record β BioPython SeqRecord from FASTA file
- Returns:
Dictionary with parsed metadata fields
- sirnaforge.modifications.load_metadata(json_path: str | Path) dict[str, StrandMetadata][source]ο
Load and validate metadata from JSON sidecar file using Pydantic.
- Parameters:
json_path β Path to JSON file containing metadata
- Returns:
Dictionary mapping strand IDs to StrandMetadata objects
- Raises:
ValidationError β If JSON data doesnβt match StrandMetadata schema
- sirnaforge.modifications.merge_metadata_into_fasta(fasta_path: str | Path, metadata_path: str | Path, output_path: str | Path) int[source]ο
Merge metadata from JSON into FASTA headers.
Uses Pydantic for automatic validation of metadata.
- Parameters:
fasta_path β Input FASTA file
metadata_path β JSON file with metadata
output_path β Output FASTA file with updated headers
- Returns:
Number of sequences with metadata applied
- Raises:
ValidationError β If metadata doesnβt match StrandMetadata schema
- sirnaforge.modifications.save_metadata_json(metadata_dict: dict[str, StrandMetadata], output_path: str | Path) None[source]ο
Save strand metadata to JSON file using Pydantic serialization.
- Parameters:
metadata_dict β Dictionary mapping strand IDs to StrandMetadata objects
output_path β Path to output JSON file