kaptive.serotyping.io¶
I/O formatting and TSV report generation for in silico serotyping results.
This module provides abstract base class ReportRow and concrete implementation
dataclasses KaptiveRow and Pha4geRow
for exporting SerotypingResult objects into tab-separated value (TSV)
report files adhering to original Kaptive or standard PHA4GE reporting formats.
Classes:
-
KaptiveRow–Report row representation matching the classic Kaptive TSV output format.
-
Pha4geRow–Report row representation adhering to Public Health Alliance for Genomic Epidemiology (PHA4GE) standards.
-
ReportRow–Abstract base class for tabular in silico serotyping report rows.
KaptiveRow
dataclass
¶
KaptiveRow(Kaptive_version: bytes, Database_name: bytes, Database_version: bytes, Assembly: bytes, Best_match_locus: bytes, Best_match_type: bytes, Match_confidence: bytes, Problems: bytes, Identity: bytes, Coverage: bytes, Length_discrepancy: bytes, Expected_genes_in_locus: bytes, Expected_genes_in_locus_details: bytes, Missing_expected_genes: bytes, Other_genes_in_locus: bytes, Other_genes_in_locus_details: bytes, Expected_genes_outside_locus: bytes, Expected_genes_outside_locus_details: bytes, Other_genes_outside_locus: bytes, Other_genes_outside_locus_details: bytes, Truncated_genes_details: bytes, Extra_genes_details: bytes)
flowchart TD
kaptive.serotyping.io.KaptiveRow[KaptiveRow]
kaptive.serotyping.io.ReportRow[ReportRow]
kaptive.serotyping.io.ReportRow --> kaptive.serotyping.io.KaptiveRow
click kaptive.serotyping.io.KaptiveRow href "" "kaptive.serotyping.io.KaptiveRow"
click kaptive.serotyping.io.ReportRow href "" "kaptive.serotyping.io.ReportRow"
Report row representation matching the classic Kaptive TSV output format.
Encapsulates all summary statistics, locus match calls, problem flags, gene details, and coverage metrics for a single genome assembly in tab-separated binary format compatible with traditional Kaptive output parsers.
Attributes:
-
Kaptive_version(bytes) –The version of Kaptive used to perform serotyping.
-
Database_name(bytes) –Name of the reference database used for serotyping.
-
Database_version(bytes) –Version of the reference database used.
-
Assembly(bytes) –Identifier/filename of the analyzed genome assembly.
-
Best_match_locus(bytes) –Best matching reference locus type identifier.
-
Best_match_type(bytes) –Predicted serotype/phenotype call for the genome.
-
Match_confidence(bytes) –Confidence classification (
b"Typeable"orb"Untypeable"). -
Problems(bytes) –Symbolic character flags representing
SerotypingProblemlocus match issues (?,+,-,*,!). -
Identity(bytes) –Mean percentage amino acid identity across intact expected locus genes.
-
Coverage(bytes) –Percentage coverage of the best matching reference locus by assembly contigs.
-
Length_discrepancy(bytes) –Difference in base pairs between assembly locus length and reference locus length (or
"n/a"). -
Expected_genes_in_locus(bytes) –Count and fraction of expected locus genes found inside locus boundary.
-
Expected_genes_in_locus_details(bytes) –Detailed identity and coverage specs for expected genes inside locus.
-
Missing_expected_genes(bytes) –Semicolon-separated names of expected genes not found.
-
Other_genes_in_locus(bytes) –Count of unexpected genes from other loci found inside locus boundary.
-
Other_genes_in_locus_details(bytes) –Detailed specs for unexpected genes inside locus.
-
Expected_genes_outside_locus(bytes) –Count and fraction of expected locus genes found outside locus boundary.
-
Expected_genes_outside_locus_details(bytes) –Detailed specs for expected genes found outside locus.
-
Other_genes_outside_locus(bytes) –Count of unexpected genes found outside locus boundary.
-
Other_genes_outside_locus_details(bytes) –Detailed specs for unexpected genes found outside locus.
-
Truncated_genes_details(bytes) –Detailed specs for truncated or partial genes.
-
Extra_genes_details(bytes) –Detailed specs for allowed extra database genes.
Note
Numbers beside gene names indicate percentage identity and percentage coverage of the gene in the genome.
Warning
You may sometimes see two copies of the same gene in the Expected_genes_in_locus_details column.
These represent parts of the same gene split over contig boundaries.
Methods:
-
__bytes__–Serialize the report row fields into a tab-separated binary TSV row.
-
from_result–Construct a classic
KaptiveRowfrom a serotyping result. -
header–Generate backwards-compatible column header bytes for classic Kaptive reports.
-
read_tsv–Parse an iterable of TSV byte lines into report row instances.
__bytes__
¶
__bytes__() -> bytes
Serialize the report row fields into a tab-separated binary TSV row.
Returns:
-
bytes(bytes) –Tab-separated field values ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
from_result
classmethod
¶
from_result(result: SerotypingResult) -> KaptiveRow
Construct a classic KaptiveRow from a serotyping result.
Calculates gene counts, percentage coverages, identity metrics, and problem symbol codes, formatting all fields into UTF-8 encoded bytes for backwards-compatible TSV output.
Parameters:
-
(result¶SerotypingResult) –The serotyping call result. See
SerotypingResult.
Returns:
-
KaptiveRow(KaptiveRow) –Formatted report row object.
Source code in src/kaptive/serotyping/io.py
| Python | |
|---|---|
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 | |
header
classmethod
¶
header() -> bytes
Generate backwards-compatible column header bytes for classic Kaptive reports.
Replaces internal field name underscores with spaces and _details with , details to maintain exact
compatibility with legacy Kaptive TSV headers.
Returns:
-
bytes(bytes) –Tab-separated legacy header line ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
read_tsv
classmethod
¶
Parse an iterable of TSV byte lines into report row instances.
Parameters:
Yields:
Source code in src/kaptive/serotyping/io.py
Pha4geRow
dataclass
¶
Pha4geRow(*, sample: bytes, genotyping_method: bytes = b'In silico serotyping', genotyping_schema_taxon: bytes, genotyping_database_name: bytes, genotyping_database_version: bytes, genotyping_schema_name: bytes = b'Kaptive', genotyping_software_name: bytes = b'Kaptive', genotyping_software_version: bytes, genotype: bytes, genotype_predicted_phenotype: bytes, genotype_confidence_value: bytes, genotyping_details: bytes, genotyping_method_url: bytes = b'https://github.com/klebgenomics/Kaptive')
flowchart TD
kaptive.serotyping.io.Pha4geRow[Pha4geRow]
kaptive.serotyping.io.ReportRow[ReportRow]
kaptive.serotyping.io.ReportRow --> kaptive.serotyping.io.Pha4geRow
click kaptive.serotyping.io.Pha4geRow href "" "kaptive.serotyping.io.Pha4geRow"
click kaptive.serotyping.io.ReportRow href "" "kaptive.serotyping.io.ReportRow"
Report row representation adhering to Public Health Alliance for Genomic Epidemiology (PHA4GE) standards.
Encapsulates sample metadata, taxonomy, software versioning, genotype calls, and confidence values in tab-separated binary format standardized for public health surveillance data exchange.
For more information on the rationale and specifics of the PHA4GE genotyping specification, please see: https://github.com/pha4ge/genotyping-specification
Attributes:
-
sample(bytes) –Sample identifier taken from genome assembly filename.
-
genotyping_method(bytes) –Genotyping methodology string (default
b"In silico serotyping"). -
genotyping_schema_taxon(bytes) –NCBITaxon formatted organism species string and taxon ID.
-
genotyping_database_name(bytes) –Name of reference database used for serotyping.
-
genotyping_database_version(bytes) –Version of reference database used.
-
genotyping_schema_name(bytes) –Schema name (default
b"Kaptive"). -
genotyping_software_name(bytes) –Software name (default
b"Kaptive"). -
genotyping_software_version(bytes) –Kaptive software version used for analysis.
-
genotype(bytes) –Best matching locus type identifier call.
-
genotype_predicted_phenotype(bytes) –Predicted surface antigen phenotype/serotype string.
-
genotype_confidence_value(bytes) –Confidence assessment (
b"Typeable"orb"Untypeable"). -
genotyping_details(bytes) –Human-readable descriptions of any locus match problems detected.
-
genotyping_method_url(bytes) –Repository URL for methodology documentation.
Methods:
-
__bytes__–Serialize the report row fields into a tab-separated binary TSV row.
-
from_result–Construct a standardized
Pha4geRowfrom a serotyping result. -
header–Generate the TSV header row as UTF-8 encoded bytes.
-
read_tsv–Parse an iterable of TSV byte lines into report row instances.
__bytes__
¶
__bytes__() -> bytes
Serialize the report row fields into a tab-separated binary TSV row.
Returns:
-
bytes(bytes) –Tab-separated field values ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
from_result
classmethod
¶
from_result(result: SerotypingResult) -> Pha4geRow
Construct a standardized Pha4geRow from a serotyping result.
Transforms numeric taxon IDs and problem flags into human-readable PHA4GE-compliant strings and binary bytes.
Parameters:
-
(result¶SerotypingResult) –The serotyping call result. See
SerotypingResult.
Returns:
-
Pha4geRow(Pha4geRow) –Formatted PHA4GE report row object.
Source code in src/kaptive/serotyping/io.py
header
classmethod
¶
header() -> bytes
Generate the TSV header row as UTF-8 encoded bytes.
Returns:
-
bytes(bytes) –Tab-separated column header line ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
read_tsv
classmethod
¶
Parse an iterable of TSV byte lines into report row instances.
Parameters:
Yields:
Source code in src/kaptive/serotyping/io.py
ReportRow
dataclass
¶
flowchart TD
kaptive.serotyping.io.ReportRow[ReportRow]
click kaptive.serotyping.io.ReportRow href "" "kaptive.serotyping.io.ReportRow"
Abstract base class for tabular in silico serotyping report rows.
Provides a uniform interface and binary serialization methods (__bytes__ and header) for converting
SerotypingResult instances into tab-separated (TSV) outputs.
Attributes documented in subclass docstrings correspond directly to TSV report column headers.
Methods:
-
__bytes__–Serialize the report row fields into a tab-separated binary TSV row.
-
from_result–Construct a report row instance from a serotyping result.
-
header–Generate the TSV header row as UTF-8 encoded bytes.
-
read_tsv–Parse an iterable of TSV byte lines into report row instances.
__bytes__
¶
__bytes__() -> bytes
Serialize the report row fields into a tab-separated binary TSV row.
Returns:
-
bytes(bytes) –Tab-separated field values ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
from_result
abstractmethod
classmethod
¶
from_result(result: SerotypingResult) -> Self
Construct a report row instance from a serotyping result.
Parameters:
-
(result¶SerotypingResult) –The serotyping analysis result to format. See
SerotypingResult.
Returns:
Source code in src/kaptive/serotyping/io.py
header
classmethod
¶
header() -> bytes
Generate the TSV header row as UTF-8 encoded bytes.
Returns:
-
bytes(bytes) –Tab-separated column header line ending with a newline (
b"\n").
Source code in src/kaptive/serotyping/io.py
read_tsv
classmethod
¶
Parse an iterable of TSV byte lines into report row instances.
Parameters:
Yields: