serogen.genes¶
Single-pass bacterial and prophage Open Reading Frame (ORF) prediction, functional gene role ontology, and multi-channel 1D CNN protein classification.
ORF Prediction (serogen.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,
Sequences, or GenomeAssembly
containers using a unified flat window table and Numba prange parallelism, returning
batched Genes. Supports bacterial and viral/phage translation
tables and single-pass co-prediction of bacterial and prophage/phage ORFs.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
HMM
|
Baked HMM model parameter container. |
genetic_code |
GeneticCode
|
Translation table defining start/stop codons and amino acid mappings. |
include_phage |
bool
|
If True, enables single-pass phage/prophage ORF co-prediction (sliding local GC adaptation, overlapping operon transitions, and small ORF recovery). |
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/serogen/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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
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/serogen/genes/orf/predictor.py
Gene Containers & HMM Parameters (serogen.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/serogen/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/serogen/genes/models.py
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 | |
empty
classmethod
¶
empty(length: int = 0) -> Indels
Create an empty Indels container.
Source code in src/serogen/genes/models.py
concat
classmethod
¶
Concatenate multiple Indels containers into a single batch.
Source code in src/serogen/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/serogen/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
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/serogen/genes/models.py
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 | |
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
¶
translations: Sequences
Translated protein sequences.
Returns pre-computed translations if provided, or computes them lazily using
self.genetic_code.
Returns:
| Name | Type | Description |
|---|---|---|
Sequences |
Sequences
|
Protein translation sequences. |
translate
¶
translate(code: GeneticCode | int | str | None = None, to_stop: bool = True) -> Sequences
Translate coding nucleotide sequences into protein sequences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
GeneticCode | int | 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/serogen/genes/models.py
concat
classmethod
¶
Concatenate multiple Genes batches into a single container.
Source code in src/serogen/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/serogen/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/serogen/genes/models.py
Functional Gene Role Ontology (serogen.genes.roles)¶
roles
¶
Canonical biosynthetic gene roles, metadata specifications, and 4-tier regex classification.
Classes:
| Name | Description |
|---|---|
RoleCategory |
Functional category of a biosynthetic gene role. |
RoleSpec |
Immutable metadata and classification specification for a canonical gene role. |
GeneRole |
Canonical biosynthetic gene roles (0..29) for surface polysaccharide loci. |
RoleCategory
¶
Bases: StrEnum
Functional category of a biosynthetic gene role.
Source code in src/serogen/genes/roles.py
RoleSpec
dataclass
¶
Immutable metadata and classification specification for a canonical gene role.
Source code in src/serogen/genes/roles.py
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 SciPy CSR matrices.
Methods:
| Name | Description |
|---|---|
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 string array of canonical role names. |
abbreviations_array |
Contiguous 1D NumPy string array of role abbreviations. |
categories_array |
Contiguous 1D NumPy string array of role categories. |
feature_matrix |
Return precomputed |
label |
Assign gene role indices for a single gene or batch of genes using the 4-tier strategy. |
Attributes:
| Name | Type | Description |
|---|---|---|
spec |
RoleSpec
|
Return the immutable |
abbreviation |
str
|
Short display abbreviation (e.g. |
abbr |
str
|
Alias for |
category |
RoleCategory
|
Functional |
description |
str
|
Human-readable biochemical description. |
aliases |
tuple[str, ...]
|
Known gene symbol aliases for this role. |
trusted_prefixes |
tuple[str, ...]
|
Trusted canonical gene symbol prefixes for Tier-1 classification. |
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. |
Source code in src/serogen/genes/roles.py
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 | |
trusted_prefixes
property
¶
Trusted canonical gene symbol prefixes for Tier-1 classification.
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.
from_name
classmethod
¶
Resolve a role from an integer index, canonical name, abbreviation, or alias.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | bytes | int | GeneRole
|
Role identifier ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GeneRole |
GeneRole
|
Resolved canonical role enum member. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a string/bytes key does not match any known role name, abbreviation, or alias. |
ValueError
|
If an integer index is out of range. |
Source code in src/serogen/genes/roles.py
resolve
classmethod
¶
Resolve a role identifier, falling back to default (or GeneRole.UNKNOWN) if not found.
Source code in src/serogen/genes/roles.py
names_array
classmethod
¶
abbreviations_array
classmethod
¶
categories_array
classmethod
¶
feature_matrix
classmethod
¶
Return precomputed (30, D) float32 one-hot category feature matrix for embeddings.
label
classmethod
¶
label(symbol: str | bytes | Sequence[str | bytes] | ndarray | None = None, description: str | bytes | Sequence[str | bytes] | ndarray | None = None) -> GeneRole | ndarray[tuple[int], dtype[int8]]
Assign gene role indices for a single gene or batch of genes using the 4-tier strategy.
- Tier 1: Canonical trusted core symbol prefixes.
- Tier 2: Informative product description regex.
- Tier 3: Symbol regex and aliases fallback (with locus suffix stripping).
- Tier 4: Gene identifier extraction from product description fallback.
Returns:
| Type | Description |
|---|---|
GeneRole | ndarray[tuple[int], dtype[int8]]
|
|
Source code in src/serogen/genes/roles.py
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 | |
1D CNN Role Classifier (serogen.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, 9, 13), ReLU activation, dual pooling (global max pooling + global average pooling) concatenated with normalized log-length and amino acid composition, and a dense classification layer. 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 |
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/serogen/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 | |
is_fitted
property
¶
Return True if all model parameters have been fitted or loaded.
feature_dim
property
¶
Dimensionality of the penultimate 1D-CNN + global composition feature vector.
fit
¶
fit(X: Genes | Sequences | Sequence[Any] | tuple[ndarray, ndarray], y: Sequence[int | GeneRole] | ndarray, sample_weight: Sequence[float] | ndarray | None = None, *, 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/serogen/genes/cnn.py
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 | |
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/serogen/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/serogen/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/serogen/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/serogen/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/serogen/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/serogen/genes/cnn.py
save
¶
Save model weights, classes, and hyperparameters to a compressed .npz archive.
Source code in src/serogen/genes/cnn.py
load
classmethod
¶
Load model weights, classes, and hyperparameters from a compressed .npz archive.
Source code in src/serogen/genes/cnn.py
pretrained
cached
classmethod
¶
Load the packaged pre-trained GeneRoleClassifier from serogen.data/model.npz.