kaptive.compare¶
Multi-locus comparative genomic analysis and sequence alignment containers.
This module provides high-performance Structure-of-Arrays (SoA) data containers and an indexed comparison engine for performing all-vs-all forward protein alignments across multiple genomic loci.
Classes:
-
[`LocusComparisonEdges`][kaptive.compare.LocusComparisonEdges]βContainer storing pairwise cross-locus protein alignments.
-
[`LocusComparisons`][kaptive.compare.LocusComparisons]βComplete result set for multi-locus comparison.
-
[`LocusData`][kaptive.compare.LocusData]βGeneralised input data container representing a single locus.
-
[`LocusComparator`][kaptive.compare.LocusComparator]βVectorised engine for multi-locus pairwise comparisons.
LocusComparator
¶
Vectorised engine for multi-locus all-vs-all forward protein comparison.
Uses strobemer indexing (RandstrobeIndex) to quickly identify
candidate homology hits between loci, and aligns candidates using
PairwiseAligner.
Parameters:
-
(k¶int, default:10) βStrobemer seed length. Defaults to 10.
-
(s¶int, default:5) βStrobemer sampling stride. Defaults to 5.
-
(min_score¶int, default:1) βMinimum seed hit score threshold. Defaults to 1.
-
(aligner_kwargs¶dict | None, default:None) βOptional arguments passed to
PairwiseAligner.
Methods:
-
__call__βPerform multi-locus pairwise comparisons across all input loci.
Source code in src/kaptive/compare.py
__call__
¶
__call__(inputs: Sequence[LocusData]) -> LocusComparisons
Perform multi-locus pairwise comparisons across all input loci.
Parameters:
Returns:
-
LocusComparisons(LocusComparisons) βComplete comparison results including pairwise edges and normalized intervals.
Source code in src/kaptive/compare.py
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 | |
LocusComparisonEdges
dataclass
¶
LocusComparisonEdges(query_locus_indices: NDArray[int32], target_locus_indices: NDArray[int32], query_indices: NDArray[int32], target_indices: NDArray[int32], global_query_indices: NDArray[int32], global_target_indices: NDArray[int32], alignments: PairwiseAlignments)
flowchart TD
kaptive.compare.LocusComparisonEdges[LocusComparisonEdges]
kaptive.core.collections.BatchedContainer[BatchedContainer]
kaptive.core.collections.BatchedContainer --> kaptive.compare.LocusComparisonEdges
click kaptive.compare.LocusComparisonEdges href "" "kaptive.compare.LocusComparisonEdges"
click kaptive.core.collections.BatchedContainer href "" "kaptive.core.collections.BatchedContainer"
A high-performance SoA container for forward cross-locus protein alignments.
Stores index pointers and alignment statistics for protein-level pairwise hits
identified between different genomic loci. Inherits batch slicing and concatenation
capabilities from BatchedContainer.
Attributes:
-
query_locus_indices(NDArray[int32]) βLocus-level indices for query loci.
-
target_locus_indices(NDArray[int32]) βLocus-level indices for target loci.
-
query_indices(NDArray[int32]) βProtein indices within the query locus.
-
target_indices(NDArray[int32]) βProtein indices within the target locus.
-
global_query_indices(NDArray[int32]) βGlobal protein indices across concatenated loci.
-
global_target_indices(NDArray[int32]) βGlobal protein indices across concatenated loci.
-
alignments(PairwiseAlignments) βPairwise alignment metrics for each edge.
Methods:
-
__getitem__βSlice or filter alignment edges using a slice or array mask.
-
__len__βReturn the total number of cross-locus alignment edges.
-
concatβConcatenate multiple
LocusComparisonEdgesbatches into a single container. -
emptyβCreate an empty
LocusComparisonEdgesinstance.
__getitem__
¶
Slice or filter alignment edges using a slice or array mask.
Parameters:
Returns:
-
Any | LocusComparisonEdgesβAny | LocusComparisonEdges: A new container with sliced alignment edges.
Raises:
-
NotImplementedErrorβIf
itemis a single integer.
Source code in src/kaptive/compare.py
__len__
¶
__len__() -> int
Return the total number of cross-locus alignment edges.
Returns:
-
int(int) βThe number of alignment edges stored in the container.
concat
classmethod
¶
Concatenate multiple LocusComparisonEdges batches into a single container.
Parameters:
-
(batches¶list[LocusComparisonEdges]) βList of edge containers to merge.
Returns:
-
LocusComparisonEdges(Self) βConcatenated container holding all input batches.
Source code in src/kaptive/compare.py
empty
classmethod
¶
empty() -> LocusComparisonEdges
Create an empty LocusComparisonEdges instance.
Returns:
-
LocusComparisonEdges(LocusComparisonEdges) βAn empty edges container with zero-length arrays.
Source code in src/kaptive/compare.py
LocusComparisons
dataclass
¶
LocusComparisons(edges: LocusComparisonEdges, locus_names: tuple[str, ...], locus_lengths: NDArray[int32], locus_offsets: NDArray[int32], gene_names: NDArray[object_], gene_descriptions: NDArray[object_], gene_states: NDArray[int8], gene_intervals: Intervals)
Complete result container for multi-locus comparative analysis.
Holds pairwise alignment edges between loci, global gene metadata, locus offsets, and physical genomic intervals normalized for visualization.
Attributes:
-
edges(LocusComparisonEdges) βAlignment edges between compared loci.
-
locus_names(tuple[str, ...]) βNames of the compared loci.
-
locus_lengths(NDArray[int32]) βProtein counts for each locus.
-
locus_offsets(NDArray[int32]) βGlobal gene index offsets for each locus.
-
gene_names(NDArray[object_]) βFlattened array of gene identifiers.
-
gene_descriptions(NDArray[object_]) βFlattened array of gene descriptions.
-
gene_states(NDArray[int8]) βFlattened array of gene classification states.
-
gene_intervals(Intervals) βPre-normalised physical gene intervals for plotting.
LocusData
dataclass
¶
LocusData(proteins: Sequences, name: str, backbone: Intervals, pieces: LocusPieces | None = None, gene_ctg_indices: NDArray[uint32] | None = None, gene_states: NDArray[int8] | None = None, gene_descriptions: NDArray[object_] | Sequence[str] | None = None)
A generalised container representing a single locus for comparison.
Attributes:
-
proteins(Sequences) βProtein sequences within the locus.
-
name(str) βLocus identifier or name.
-
backbone(Intervals) βPhysical genomic coordinates of genes in the locus.
-
pieces(LocusPieces | None) βSegmented contig piece layout, if fragmented.
-
gene_ctg_indices(NDArray[uint32] | None) βContig assignment indices for genes.
-
gene_states(NDArray[int8] | None) βArray of GeneState integer values for genes in locus.
-
gene_descriptions(NDArray[object_] | Sequence[str] | None) βProduct description strings for genes.