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.
__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
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 | |
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
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.
__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
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.
__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: