seroref.genes¶
Single-pass bacterial and prophage Open Reading Frame (ORF) prediction, functional gene role ontology, and multi-channel 1D-CNN protein classification.
ORF Prediction (seroref.genes.orf.predictor)¶
predictor
¶
OrfPredictor high-level execution engine for sequences and assemblies.
Classes:
| Name | Description |
|---|---|
OrfPredictor |
High-performance Open Reading Frame (ORF) predictor. |
OrfPredictor
¶
High-performance Open Reading Frame (ORF) predictor.
Executes Numba JIT-compiled FragGeneScan HMM decoding over single sequences,
seroverse.core.seq.seq.Sequences, or seroverse.core.genome.GenomeAssembly
containers using a unified flat window table and Numba prange parallelism, returning
batched Genes.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
HMM
|
Baked HMM model parameter container. |
genetic_code |
GeneticCode
|
Translation table defining start/stop codons and amino acid mappings. |
min_gene_len |
int
|
Minimum gene length in nucleotides. |
local_gc_window |
int
|
Sliding window size in bp for local GC bin adaptation. |
Methods:
| Name | Description |
|---|---|
predict |
Predict Open Reading Frames across target sequences. |
Source code in src/seroref/genes/orf/predictor.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
predict
¶
predict(
target: bytes
| str
| Sequence
| Sequences
| GenomeAssembly,
) -> Genes
Predict Open Reading Frames across target sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
bytes | str | Sequence | Sequences | GenomeAssembly
|
Input genomic sequence(s). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Genes |
Genes
|
Batched |
Raises:
| Type | Description |
|---|---|
TypeError
|
If target is not a supported sequence type. |
Source code in src/seroref/genes/orf/predictor.py
Gene Containers & HMM Parameters (seroref.genes.models)¶
models
¶
Structure-of-Arrays data containers for predicted genes, indels, and HMM parameters.
Classes:
| Name | Description |
|---|---|
IndelKind |
Indel mutation type for frameshift tracking. |
IndelRecord |
Scalar view of frameshift indel events for a single gene. |
Indels |
Ragged Structure-of-Arrays container for frameshift indels across a Genes batch. |
Gene |
Scalar view of a single predicted gene. |
Genes |
Structure-of-Arrays (SoA) container for predicted genes. |
HMM |
Container holding baked FragGeneScan HMM parameters. |
Functions:
| Name | Description |
|---|---|
get_hmm_model |
Return cached singleton instance of the default bundled HMM model. |
IndelKind
¶
IndelRecord
dataclass
¶
Scalar view of frameshift indel events for a single gene.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
ndarray
|
0-based contig coordinates where indels occurred. |
kinds |
ndarray
|
Indel mutation types (+1 for Insertion, -1 for Deletion). |
Source code in src/seroref/genes/models.py
Indels
dataclass
¶
Bases: RaggedArrayContainer[IndelRecord, 'Indels']
Ragged Structure-of-Arrays container for frameshift indels across a Genes batch.
Stores variable-length indel event coordinates and mutation kinds in flat contiguous arrays,
indexed via offsets and lengths per gene.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
ndarray
|
1D array of 0-based contig coordinates across all indels. |
kinds |
ndarray
|
1D array of indel kinds (+1=ins, -1=del). |
offsets |
ndarray
|
Starting index into |
lengths |
ndarray
|
Number of indels for each gene. |
Methods:
| Name | Description |
|---|---|
empty |
Create an empty Indels container. |
concat |
Concatenate multiple Indels containers into a single batch. |
Source code in src/seroref/genes/models.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
empty
classmethod
¶
empty(length: int = 0) -> Indels
Create an empty Indels container.
Source code in src/seroref/genes/models.py
concat
classmethod
¶
Concatenate multiple Indels containers into a single batch.
Source code in src/seroref/genes/models.py
Gene
dataclass
¶
Scalar view of a single predicted gene.
Attributes:
| Name | Type | Description |
|---|---|---|
interval |
Interval
|
Genomic interval coordinate ( |
seq |
Sequence | None
|
Coding nucleotide or protein sequence ( |
contig_index |
int
|
0-based contig index offset corresponding to parent contig name. |
indels |
IndelRecord
|
Scalar frameshift indel record ( |
is_partial |
bool
|
True if the ORF is truncated at a contig boundary without a start or stop codon. |
Source code in src/seroref/genes/models.py
Genes
dataclass
¶
Bases: BatchedContainer[Gene, 'Genes']
Structure-of-Arrays (SoA) container for predicted genes.
Stores interval coordinates, in-frame coding nucleotide sequences, and contig index
mappings for a collection of predicted Open Reading Frames (ORFs). Inherits
vectorised slicing and concatenation interface from
seroverse.core.collections.BatchedContainer.
Attributes:
| Name | Type | Description |
|---|---|---|
intervals |
Intervals
|
Genomic interval coordinates for predicted ORFs
( |
seqs |
Sequences
|
In-frame coding nucleotide sequences oriented 5' to 3'
( |
contig_indices |
ndarray[tuple[int], dtype[uint32]]
|
1D array of 0-based contig index offsets corresponding to parent contig names. |
indels |
Indels
|
Ragged frameshift indel records. |
is_partial |
ndarray[tuple[int], dtype[bool_]]
|
Boolean mask indicating contig-edge partial ORFs. |
Methods:
| Name | Description |
|---|---|
translate |
Translate coding nucleotide sequences into protein sequences. |
empty |
Create an empty |
concat |
Concatenate multiple |
Source code in src/seroref/genes/models.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
has_frameshift
property
¶
Boolean mask indicating which genes contain at least one frameshift indel.
frameshift_count
property
¶
Array of frameshift indel counts per gene.
translations
property
¶
Translated protein sequences.
Returns pre-computed translations if provided, or computes them lazily using
self.genetic_code (seroverse.core.seq.alphabet.GeneticCode).
Returns:
| Name | Type | Description |
|---|---|---|
Sequences |
Sequences
|
Protein translation sequences. |
translate
¶
translate(
code: GeneticCode | int | bytes | str | None = None,
to_stop: bool = True,
) -> Sequences
Translate coding nucleotide sequences into protein sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
GeneticCode | int | bytes | str | None
|
Genetic code translation table to use.
If None, uses |
None
|
to_stop
|
bool
|
If True, truncates translation at the first stop codon (*). Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Sequences |
Sequences
|
Translated protein sequences. |
Source code in src/seroref/genes/models.py
concat
classmethod
¶
Concatenate multiple Genes batches into a single container.
Source code in src/seroref/genes/models.py
HMM
dataclass
¶
Container holding baked FragGeneScan HMM parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
tr |
ndarray
|
Global transition penalties (14,). |
tr_mi |
ndarray
|
Match-to-insertion transitions (4, 4). |
tr_ii |
ndarray
|
Insertion-to-insertion transitions (4, 4). |
pi |
ndarray
|
Initial state log-probabilities (29,). |
e_m |
ndarray
|
Forward match state emission log-probabilities (44, 6, 16, 4). |
e_m1 |
ndarray
|
Reverse match state emission log-probabilities (44, 6, 16, 4). |
tr_rr |
ndarray
|
Non-coding state transitions (44, 4, 4). |
tr_s |
ndarray
|
PWM window transitions around forward start (44, 61, 64). |
tr_e |
ndarray
|
PWM window transitions around forward stop (44, 61, 64). |
tr_s1 |
ndarray
|
PWM window transitions around reverse start (44, 61, 64). |
tr_e1 |
ndarray
|
PWM window transitions around reverse stop (44, 61, 64). |
dist_s |
ndarray
|
Gaussian parameters for forward start (44, 6). |
dist_e |
ndarray
|
Gaussian parameters for forward stop (44, 6). |
dist_s1 |
ndarray
|
Gaussian parameters for reverse start (44, 6). |
dist_e1 |
ndarray
|
Gaussian parameters for reverse stop (44, 6). |
Methods:
| Name | Description |
|---|---|
load |
Load HMM parameters from compressed NumPy archive (.npz). |
Source code in src/seroref/genes/models.py
load
classmethod
¶
load(path: str | Path | None = None) -> HMM
Load HMM parameters from compressed NumPy archive (.npz).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path | None
|
Optional path to .npz archive. If None, loads the
bundled default model located at |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
HMM |
HMM
|
Instantiated HMM parameter container. |
Source code in src/seroref/genes/models.py
Functional Gene Role Ontology (seroref.genes.roles)¶
roles
¶
Canonical biosynthetic gene roles and Structure-of-Arrays (SoA) metadata specifications.
Classes:
| Name | Description |
|---|---|
RoleCategory |
Functional category of a biosynthetic gene role. |
RoleSpec |
Immutable scalar view of a canonical |
RoleSpecs |
Pure CSR-packed Ragged Structure-of-Arrays (SoA) batch container over |
GeneRole |
Canonical biosynthetic gene roles (0..29) for surface polysaccharide loci. |
RoleCategory
¶
Bases: IntEnum
Functional category of a biosynthetic gene role.
Methods:
| Name | Description |
|---|---|
from_name |
Resolve a |
resolve |
Resolve a |
Attributes:
| Name | Type | Description |
|---|---|---|
label |
bytes
|
Canonical ASCII byte-string label for this category. |
Source code in src/seroref/genes/roles.py
from_name
classmethod
¶
from_name(
key: str | bytes | int | RoleCategory,
) -> RoleCategory
Resolve a RoleCategory by integer ID, enum name, or label.
Source code in src/seroref/genes/roles.py
resolve
classmethod
¶
resolve(
key: str | bytes | int | RoleCategory,
default: RoleCategory | None = None,
) -> RoleCategory
Resolve a RoleCategory identifier, falling back to default (or RoleCategory.BACKGROUND).
Source code in src/seroref/genes/roles.py
RoleSpec
dataclass
¶
Bases: ScalarView
Immutable scalar view of a canonical GeneRole metadata specification.
Attributes:
| Name | Type | Description |
|---|---|---|
is_mobile_element |
bool
|
True if this role is a mobile genetic element ( |
is_biosynthetic |
bool
|
True if this role represents active locus biosynthesis, modification, or transport. |
Source code in src/seroref/genes/roles.py
RoleSpecs
dataclass
¶
Bases: RaggedArrayContainer[RoleSpec, 'RoleSpecs']
Pure CSR-packed Ragged Structure-of-Arrays (SoA) batch container over RoleSpec definitions.
Methods:
| Name | Description |
|---|---|
empty |
Create an empty 0-length |
from_list |
Compile a sequence of |
concat |
Concatenate multiple |
Attributes:
| Name | Type | Description |
|---|---|---|
biosynthetic_mask |
ndarray[tuple[int], dtype[bool_]]
|
1D boolean mask ( |
machinery_roles |
ndarray[tuple[int], dtype[int32]]
|
1D |
Source code in src/seroref/genes/roles.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
biosynthetic_mask
property
¶
1D boolean mask ((N,)) marking active biosynthetic/transport/modifier gene roles.
machinery_roles
property
¶
1D int32 array of role indices marked as core export/polymerization machinery.
empty
classmethod
¶
Create an empty 0-length RoleSpecs container.
Source code in src/seroref/genes/roles.py
from_list
classmethod
¶
from_list(specs: Sequence[RoleSpec]) -> Self
Compile a sequence of RoleSpec scalar views into a frozen RoleSpecs SoA container.
Source code in src/seroref/genes/roles.py
concat
classmethod
¶
Concatenate multiple RoleSpecs containers.
GeneRole
¶
Bases: IntEnum
Canonical biosynthetic gene roles (0..29) for surface polysaccharide loci.
Subclasses IntEnum for zero-overhead integer semantics in bitfields (IntNode),
32-bit presence masks (1 << role), Numba kernels, and CSR matrices.
Methods:
| Name | Description |
|---|---|
specs |
Return the cached singleton |
from_name |
Resolve a role from an integer index, canonical name, abbreviation, or alias. |
resolve |
Resolve a role identifier, falling back to |
names_array |
Contiguous 1D NumPy byte-string array of canonical role names. |
abbreviations_array |
Contiguous 1D NumPy byte-string array of role abbreviations. |
categories_array |
Contiguous 1D |
feature_matrix |
Return precomputed |
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
RoleSpec
|
Return the immutable |
abbreviation |
bytes
|
Short display abbreviation (e.g. |
category |
RoleCategory
|
Functional |
description |
bytes
|
Human-readable biochemical description. |
aliases |
tuple[bytes, ...]
|
Known gene symbol aliases for this role. |
bitmask |
int
|
32-bit integer bitmask ( |
is_mobile_element |
bool
|
True if this role is a mobile genetic element ( |
is_biosynthetic |
bool
|
True if this role represents active locus biosynthesis, modification, or transport. |
is_machinery |
bool
|
True if this role is core export, translocation, or polymerization machinery. |
Source code in src/seroref/genes/roles.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
bitmask
property
¶
32-bit integer bitmask (1 << int(self)) for archetype presence masks.
is_mobile_element
property
¶
True if this role is a mobile genetic element (TRANSPOSASE, INTEGRASE).
is_biosynthetic
property
¶
True if this role represents active locus biosynthesis, modification, or transport.
is_machinery
property
¶
True if this role is core export, translocation, or polymerization machinery.
from_name
classmethod
¶
Resolve a role from an integer index, canonical name, abbreviation, or alias.
Source code in src/seroref/genes/roles.py
resolve
classmethod
¶
Resolve a role identifier, falling back to default (or GeneRole.UNKNOWN) if not found.
Source code in src/seroref/genes/roles.py
names_array
classmethod
¶
abbreviations_array
classmethod
¶
Contiguous 1D NumPy byte-string array of role abbreviations.
categories_array
classmethod
¶
feature_matrix
classmethod
¶
Return precomputed (30, D) float32 one-hot category feature matrix for embeddings.
1D CNN Role Classifier (seroref.genes.cnn)¶
cnn
¶
Classifying gene roles from amino acid sequences using a Multi-Scale 1D-CNN trained via compiled Numba AdamW backpropagation with dual (max + average) pooling.
Classes:
| Name | Description |
|---|---|
GeneRoleClassifier |
Classifies |
GeneRoleClassifier
¶
Classifies GeneRoles from amino acid sequences using a Multi-Scale 1D-CNN with Dual Pooling.
Learns representations from variable-length sequence token arrays using an embedding layer,
multi-scale 1D convolutions (e.g. receptive fields 5, 11, 17), ReLU activation, emergent dual
pooling ([conv_max, conv_avg]), a dense role classification head, and a joint 1-bit genomic
source readout head (0 = bacterial, 1 = phage/prophage). Optimization is performed via a
parallel compiled Numba AdamW training kernel with exact gradient routing.
Attributes:
| Name | Type | Description |
|---|---|---|
vocab_size |
Number of discrete tokens in sequence vocabulary (default 23: 22 AMINO tokens + 1 unknown/pad). |
|
embed_dim |
Dimensionality of token embedding vectors. |
|
num_filters |
Number of 1D convolutional feature channels across all kernel sizes. |
|
kernel_size |
Width of 1D convolution receptive field window (int), or tuple of multi-scale
kernel sizes (e.g. |
|
learning_rate |
AdamW step size hyperparameter. |
|
epochs |
Number of complete training epochs over dataset. |
|
batch_size |
Mini-batch size for parallel AdamW gradient accumulation and updates. |
|
weight_decay |
Decoupled L2 weight decay coefficient applied to model parameters. |
|
random_state |
Optional seed for reproducible parameter initialization and sample shuffling. |
|
class_weight |
Optional |
Methods:
| Name | Description |
|---|---|
fit |
Fit the 1D-CNN using parallel mini-batch AdamW optimization over ragged token sequences. |
transform |
Extract sequence representations from the specified network layer. |
decision_function |
Compute raw pre-softmax class logits |
predict_proba |
Predict class probabilities |
predict_source_proba |
Predict probability |
predict_source |
Predict binary genomic source ( |
predict |
Predict most likely class label (e.g. |
score |
Return classification accuracy on |
top_k_accuracy |
Compute Top- |
save |
Save model weights, classes, and hyperparameters to a compressed |
load |
Load model weights, classes, and hyperparameters from a compressed |
pretrained |
Load the packaged pre-trained |
Source code in src/seroref/genes/cnn.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
is_fitted
property
¶
Return True if all model parameters have been fitted or loaded.
feature_dim
property
¶
Dimensionality of the penultimate 1D-CNN dual-pooling ([conv_max, conv_avg]) feature vector.
fit
¶
fit(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
y: Sequence[int | GeneRole] | ndarray,
sample_weight: Sequence[float] | ndarray | None = None,
*,
y_source: Sequence[int] | ndarray | None = None,
source_loss_weight: float = 0.25,
init_from: GeneRoleClassifier | None = None,
backbone_lr_scale: float = 1.0,
) -> Self
Fit the 1D-CNN using parallel mini-batch AdamW optimization over ragged token sequences.
Source code in src/seroref/genes/cnn.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
transform
¶
transform(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
*,
layer: str = "penultimate",
) -> ndarray[tuple[int, int], dtype[float32]]
Extract sequence representations from the specified network layer.
Source code in src/seroref/genes/cnn.py
decision_function
¶
decision_function(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
) -> ndarray[tuple[int, int], dtype[float32]]
Compute raw pre-softmax class logits (n_samples, n_classes) for each sequence in X.
Source code in src/seroref/genes/cnn.py
predict_proba
¶
predict_proba(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
) -> ndarray[tuple[int, int], dtype[float32]]
Predict class probabilities (n_samples, n_classes) for each sequence in X.
Source code in src/seroref/genes/cnn.py
predict_source_proba
¶
predict_source_proba(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
) -> ndarray[tuple[int], dtype[float32]]
Predict probability P(phage | x) in [0.0, 1.0] for each sequence in X.
Source code in src/seroref/genes/cnn.py
predict_source
¶
predict_source(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
threshold: float = 0.5,
) -> ndarray[tuple[int], dtype[uint8]]
Predict binary genomic source (0 = bacterial, 1 = phage/prophage) for each sequence in X.
Source code in src/seroref/genes/cnn.py
predict
¶
predict(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
min_confidence: float = 0.0,
unknown_label: int | None = None,
) -> ndarray[tuple[int], dtype[Any]]
Predict most likely class label (e.g. GeneRole integer index) for each sequence in X.
Source code in src/seroref/genes/cnn.py
score
¶
score(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
y: Sequence[int | GeneRole] | ndarray,
) -> float
Return classification accuracy on (X, y).
Source code in src/seroref/genes/cnn.py
top_k_accuracy
¶
top_k_accuracy(
X: Genes
| Sequences
| Sequence[Any]
| tuple[ndarray, ndarray],
y: Sequence[int | GeneRole] | ndarray,
k: int = 3,
) -> float
Compute Top-k classification accuracy on (X, y).
Source code in src/seroref/genes/cnn.py
save
¶
Save model weights, classes, and hyperparameters to a compressed .npz archive.
Source code in src/seroref/genes/cnn.py
load
classmethod
¶
Load model weights, classes, and hyperparameters from a compressed .npz archive.
Source code in src/seroref/genes/cnn.py
pretrained
cached
classmethod
¶
Load the packaged pre-trained GeneRoleClassifier from serogen.data/model.npz.