Types¶
Core data structures and type definitions used throughout pyprego.
pyprego.types ¶
Core type definitions for pyprego.
This module defines the data structures used throughout the package. PSSM matrices and spatial models are represented as pandas DataFrames to keep things simple, inspectable, and consistent with the R prego package.
RegressionResult
dataclass
¶
Container for the output of :func:pyprego.regression.regress_pwm.
| ATTRIBUTE | DESCRIPTION |
|---|---|
pssm |
PSSM DataFrame (pos, A, C, G, T) for the inferred motif.
TYPE:
|
spat |
Spatial model DataFrame (bin, spat_factor).
TYPE:
|
pred |
Predicted PWM score for each input sequence.
TYPE:
|
consensus |
Consensus sequence derived from the PSSM.
TYPE:
|
r2 |
R-squared of prediction vs response (continuous response).
TYPE:
|
ks |
KS statistic (binary response).
TYPE:
|
seed_motif |
The seed motif / kmer that initialised the regression.
TYPE:
|
bidirect |
Whether the model is bidirectional (uses reverse complement).
TYPE:
|
spat_min |
Minimum spatial position used.
TYPE:
|
spat_max |
Maximum spatial position used.
TYPE:
|
seq_length |
Length of input sequences.
TYPE:
|
_predict_fn |
Internal prediction function (set after fitting).
TYPE:
|
predict ¶
Predict PWM scores for new sequences.
| PARAMETER | DESCRIPTION |
|---|---|
sequences
|
DNA sequences to score.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Predicted scores, one per sequence. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the model has not been fitted yet. |
to_dict ¶
Serialise the result to a plain dictionary (for YAML/JSON export).
pssm_dataframe ¶
Create a PSSM DataFrame from a (L, 4) NumPy array.
| PARAMETER | DESCRIPTION |
|---|---|
matrix
|
Array of shape (L, 4) with columns ordered A, C, G, T.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with columns |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If matrix does not have exactly 4 columns. |
pssm_to_array ¶
Extract the (L, 4) NumPy array from a PSSM DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
pssm
|
PSSM DataFrame with at least columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Array of shape (L, 4). |
spatial_dataframe ¶
Create a spatial model DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
bins
|
1-D array of bin start positions.
TYPE:
|
factors
|
1-D array of spatial factors (same length as bins).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with columns |