API Reference¶
This section contains the complete API reference for SSIAMB.
CLI Module¶
ssiamb - SSI Ambiguous Site Detection Tool
Command-line interface for detecting ambiguous sites in bacterial genomes through mapping and variant calling approaches.
main(version=None, config=None, verbose=False, quiet=False, dry_run=False)
¶
SSI Ambiguous Site Detection Tool.
Detect ambiguous sites in bacterial genomes through mapping and variant calling.
Source code in src/ssiamb/cli.py
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 | |
ref(ctx, r1, r2, reference=None, species=None, bracken=None, sample=None, output_dir=None, threads=4, mapper='minimap2', caller='bbtools', bbtools_mem=None, dp_min=10, maf_min=0.1, mapq=30, dp_cap=100, depth_tool=DepthTool.MOSDEPTH, require_pass=False, min_bracken_frac=0.7, min_bracken_reads=100000, ref_dir=None, on_fail='error', emit_vcf=False, emit_bed=False, emit_matrix=False, emit_per_contig=False, emit_multiqc=False, emit_provenance=False, tsv_mode=TSVMode.OVERWRITE, stdout=False)
¶
Reference-mapping mode: map reads to a reference genome.
Maps paired-end reads to a reference genome to identify ambiguous sites. Reference can be provided directly, looked up by species, or selected from Bracken.
Source code in src/ssiamb/cli.py
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 | |
self(ctx, r1, r2, assembly, sample=None, output_dir=None, threads=4, mapper='minimap2', caller='bbtools', bbtools_mem=None, dp_min=10, maf_min=0.1, mapq=30, dp_cap=100, depth_tool=DepthTool.MOSDEPTH, require_pass=False, emit_vcf=False, emit_bed=False, emit_matrix=False, emit_per_contig=False, emit_multiqc=False, emit_provenance=False, tsv_mode=TSVMode.OVERWRITE, stdout=False)
¶
Self-mapping mode: map reads to their own assembly.
Maps paired-end reads to the provided assembly to identify ambiguous sites where the assembly may not represent the true sequence.
Source code in src/ssiamb/cli.py
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 | |
summarize(ctx, vcf, bam, output=None, dp_min=10, maf_min=0.1, dp_cap=100, require_pass=False, emit_vcf=False, emit_bed=False, emit_matrix=False, emit_per_contig=False, emit_multiqc=False, emit_provenance=False, mode='combined', stdout=False)
¶
Summarize VCF and BAM files to generate ambiguous site summary.
Analyzes a VCF file with BAM for denominator calculation to produce ambiguous site statistics.
Source code in src/ssiamb/cli.py
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 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
version_callback(value)
¶
Print version and exit.
Source code in src/ssiamb/cli.py
30 31 32 33 34 | |
Configuration¶
Configuration management for ssiamb.
This module handles loading and merging configuration from: 1. Built-in defaults (config/defaults.yaml) 2. User-specified config files (--config) 3. Environment variables 4. Command-line overrides
SsiambConfig(thresholds, species_aliases, tools, output)
dataclass
¶
Complete ssiamb configuration.
This holds all configurable values that were previously hardcoded, allowing users to customize behavior via config files.
get_output_setting(key, default=None)
¶
Get an output formatting setting.
Source code in src/ssiamb/config.py
170 171 172 | |
get_species_alias(species)
¶
Get species alias, returning original name if no alias exists.
Source code in src/ssiamb/config.py
162 163 164 | |
get_threshold(key, default=None)
¶
Get a threshold value with fallback.
Source code in src/ssiamb/config.py
158 159 160 | |
get_tool_setting(tool, key, default=None)
¶
Get a tool-specific setting.
Source code in src/ssiamb/config.py
166 167 168 | |
load(config_path=None)
classmethod
¶
Load configuration from files and environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Optional[Path]
|
Optional path to user config file |
None
|
Returns:
| Type | Description |
|---|---|
SsiambConfig
|
Merged configuration object |
Source code in src/ssiamb/config.py
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 | |
get_config()
¶
Get the global configuration instance.
Source code in src/ssiamb/config.py
179 180 181 182 183 184 | |
load_config(config_path=None)
¶
Load and set configuration from file.
Source code in src/ssiamb/config.py
193 194 195 196 197 | |
set_config(config)
¶
Set the global configuration instance.
Source code in src/ssiamb/config.py
187 188 189 190 | |
Mapping¶
Mapping and index handling for minimap2 and bwa-mem2.
This module provides functionality for: - Building and managing indexes for reference sequences - Mapping paired-end FASTQ files to references - Generating sorted BAM files with proper read groups
ExternalToolError
¶
Bases: Exception
Raised when external tools are missing or fail.
MappingError
¶
Bases: Exception
Raised when mapping operations fail.
calculate_mapping_rate(bam_path)
¶
Calculate mapping rate from BAM file using samtools stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Path to sorted BAM file |
required |
Returns:
| Type | Description |
|---|---|
float
|
Mapping rate as fraction (0.0-1.0) |
Raises:
| Type | Description |
|---|---|
MappingError
|
If BAM file doesn't exist or samtools fails |
ExternalToolError
|
If samtools is not available |
Source code in src/ssiamb/mapping.py
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 | |
check_external_tools()
¶
Check availability and versions of external mapping tools.
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, str]]
|
Dictionary mapping tool names to availability and version info. |
Dict[str, Dict[str, str]]
|
Each tool entry contains: |
Dict[str, Dict[str, str]]
|
|
Dict[str, Dict[str, str]]
|
|
Examples:
>>> tools = check_external_tools()
>>> if not tools['minimap2']['available']:
... raise ExternalToolError("minimap2 not found")
>>> print(f"minimap2 version: {tools['minimap2']['version']}")
Source code in src/ssiamb/mapping.py
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 | |
ensure_indexes_self(fasta_path, mapper)
¶
Ensure index files exist for self-mode mapping, building them if missing.
This function builds index files next to the FASTA file if they don't exist. For minimap2, creates .mmi file. For bwa-mem2, creates .0123, .amb, .ann, .pac, .bwt.2bit.64 files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_path
|
Path
|
Path to reference FASTA file |
required |
mapper
|
Mapper
|
Mapper type (minimap2 or bwa-mem2) |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If FASTA file doesn't exist |
ExternalToolError
|
If required mapper tool is not available |
MappingError
|
If index building fails |
Examples:
>>> ensure_indexes_self(Path("ref.fasta"), Mapper.MINIMAP2)
# Creates ref.mmi if it doesn't exist
Source code in src/ssiamb/mapping.py
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 | |
get_index_files(fasta_path, mapper)
¶
Get expected index file paths for a given FASTA and mapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_path
|
Path
|
Path to reference FASTA file |
required |
mapper
|
Mapper
|
Mapper type (minimap2 or bwa-mem2) |
required |
Returns:
| Type | Description |
|---|---|
List[Path]
|
List of expected index file paths |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mapper is not supported |
Source code in src/ssiamb/mapping.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
index_bam(bam_path)
¶
Index a BAM file using samtools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Path to BAM file to index |
required |
Raises:
| Type | Description |
|---|---|
MappingError
|
If indexing fails |
Source code in src/ssiamb/mapping.py
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 | |
indexes_exist(fasta_path, mapper)
¶
Check if all required index files exist for a given FASTA and mapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fasta_path
|
Path
|
Path to reference FASTA file |
required |
mapper
|
Mapper
|
Mapper type |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all index files exist, False otherwise |
Source code in src/ssiamb/mapping.py
119 120 121 122 123 124 125 126 127 128 129 130 131 | |
map_fastqs(mapper, fasta_path, r1_path, r2_path, sample_name, threads=4, output_path=None)
¶
Map paired-end FASTQ files to reference and return sorted BAM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapper
|
Mapper
|
Mapper type (minimap2 or bwa-mem2) |
required |
fasta_path
|
Path
|
Path to reference FASTA file |
required |
r1_path
|
Path
|
Path to R1 FASTQ file |
required |
r2_path
|
Path
|
Path to R2 FASTQ file |
required |
sample_name
|
str
|
Sample name for read group |
required |
threads
|
int
|
Number of threads to use |
4
|
output_path
|
Optional[Path]
|
Output BAM path (auto-generated if None) |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to sorted BAM file |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If input files don't exist |
ExternalToolError
|
If required tools are not available |
MappingError
|
If mapping fails |
Examples:
>>> bam_path = map_fastqs(
... Mapper.MINIMAP2,
... Path("ref.fasta"),
... Path("sample_R1.fastq.gz"),
... Path("sample_R2.fastq.gz"),
... "sample123"
... )
Source code in src/ssiamb/mapping.py
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 | |
Variant Calling¶
Variant calling module for ssiamb.
This module implements variant calling using BBTools and bcftools pipelines. Supports both bacterial genome analysis with appropriate ploidy and quality settings.
VariantCallResult(vcf_path, caller, success, error_message=None, runtime_seconds=None)
dataclass
¶
Result of variant calling operation.
VariantCallingError
¶
Bases: Exception
Raised when variant calling fails.
call_variants(bam_path, reference_path, output_vcf, caller, sample_name, threads=1, mapq_min=20, baseq_min=20, minallelefraction=0.0, bbtools_mem=None)
¶
Run variant calling with the specified caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Input BAM file |
required |
reference_path
|
Path
|
Reference genome FASTA |
required |
output_vcf
|
Path
|
Output VCF file path |
required |
caller
|
Caller
|
Variant caller to use |
required |
sample_name
|
str
|
Sample name for VCF header |
required |
threads
|
int
|
Number of threads to use |
1
|
mapq_min
|
int
|
Minimum mapping quality |
20
|
baseq_min
|
int
|
Minimum base quality |
20
|
minallelefraction
|
float
|
Minimum allele fraction (BBTools only) |
0.0
|
bbtools_mem
|
Optional[str]
|
BBTools heap memory (e.g., '4g', '8g') |
None
|
Returns:
| Type | Description |
|---|---|
VariantCallResult
|
VariantCallResult with execution details |
Raises:
| Type | Description |
|---|---|
VariantCallingError
|
If caller tools are not available or calling fails |
Source code in src/ssiamb/calling.py
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 | |
caller_tools_available(caller)
¶
Check if all required tools for the specified caller are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caller
|
Caller
|
Variant caller to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all required tools are available, False otherwise |
Source code in src/ssiamb/calling.py
123 124 125 126 127 128 129 130 131 132 133 134 | |
check_caller_tools(caller)
¶
Check if required tools for the specified caller are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caller
|
Caller
|
Variant caller to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all required tools are available, False otherwise |
Source code in src/ssiamb/calling.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
check_caller_tools_detailed(caller)
¶
Check availability and versions of required tools for the specified caller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caller
|
Caller
|
Variant caller to check |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, str]]
|
Dictionary mapping tool names to availability and version info. |
Dict[str, Dict[str, str]]
|
Each tool entry contains: |
Dict[str, Dict[str, str]]
|
|
Dict[str, Dict[str, str]]
|
|
Source code in src/ssiamb/calling.py
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 | |
get_available_callers()
¶
Get list of available variant callers based on tool availability.
Returns:
| Type | Description |
|---|---|
List[Caller]
|
List of available Caller enum values |
Source code in src/ssiamb/calling.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
run_bbtools_calling(bam_path, reference_path, output_vcf, sample_name, threads=1, mapq_min=20, baseq_min=20, minallelefraction=0.0, bbtools_mem=None)
¶
Run BBTools variant calling pipeline.
Executes: 1. callvariants.sh directly with BAM input (no pileup step needed)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Input BAM file |
required |
reference_path
|
Path
|
Reference genome FASTA |
required |
output_vcf
|
Path
|
Output VCF file path |
required |
sample_name
|
str
|
Sample name for VCF header |
required |
threads
|
int
|
Number of threads to use |
1
|
mapq_min
|
int
|
Minimum mapping quality |
20
|
baseq_min
|
int
|
Minimum base quality |
20
|
minallelefraction
|
float
|
Minimum allele fraction for variant calling |
0.0
|
bbtools_mem
|
Optional[str]
|
BBTools heap memory (e.g., '4g', '8g') |
None
|
Returns:
| Type | Description |
|---|---|
VariantCallResult
|
VariantCallResult with execution details |
Source code in src/ssiamb/calling.py
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 | |
run_bcftools_calling(bam_path, reference_path, output_vcf, sample_name, threads=1, mapq_min=20, baseq_min=20)
¶
Run bcftools variant calling pipeline.
Executes: 1. bcftools mpileup -q20 -Q20 -B -a AD,ADF,ADR,DP 2. bcftools call -m --ploidy 1
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Input BAM file |
required |
reference_path
|
Path
|
Reference genome FASTA |
required |
output_vcf
|
Path
|
Output VCF file path |
required |
sample_name
|
str
|
Sample name for VCF header |
required |
threads
|
int
|
Number of threads to use |
1
|
mapq_min
|
int
|
Minimum mapping quality |
20
|
baseq_min
|
int
|
Minimum base quality |
20
|
Returns:
| Type | Description |
|---|---|
VariantCallResult
|
VariantCallResult with execution details |
Source code in src/ssiamb/calling.py
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 | |
Depth Analysis¶
Depth analysis using mosdepth for computing denominator metrics.
This module provides functionality for: - Running mosdepth on BAM files to compute depth statistics - Parsing mosdepth summary output files - Computing callable bases, genome length, breadth, and mean depth - Filtering contigs by size (≥500 bp) for consistent numerator/denominator
ContigDepthStats(name, length, bases_covered, mean_depth, breadth_10x)
dataclass
¶
Depth statistics for a single contig.
is_long_enough
property
¶
Check if contig meets minimum length threshold (≥500 bp).
DepthAnalysisError
¶
Bases: Exception
Raised when depth analysis operations fail.
DepthSummary(callable_bases, genome_length, breadth_10x, mean_depth, total_contigs, included_contigs, contig_stats)
dataclass
¶
Summary of depth analysis results.
included_contig_names
property
¶
Set of contig names that meet length threshold.
analyze_depth(bam_path, output_dir, sample_name, mapq_threshold=30, depth_threshold=10, threads=4)
¶
Complete depth analysis workflow: run mosdepth and parse results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Path to input BAM file |
required |
output_dir
|
Path
|
Directory for output files |
required |
sample_name
|
str
|
Sample name for output prefix |
required |
mapq_threshold
|
int
|
Minimum mapping quality (default: 30) |
30
|
depth_threshold
|
int
|
Depth threshold for breadth calculation (default: 10) |
10
|
threads
|
int
|
Number of threads to use |
4
|
Returns:
| Type | Description |
|---|---|
DepthSummary
|
DepthSummary object with computed statistics |
Raises:
| Type | Description |
|---|---|
DepthAnalysisError
|
If analysis fails at any step |
Source code in src/ssiamb/depth.py
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 | |
check_mosdepth_available()
¶
Check if mosdepth is available in PATH.
Returns:
| Type | Description |
|---|---|
bool
|
True if mosdepth is available, False otherwise |
Source code in src/ssiamb/depth.py
58 59 60 61 62 63 64 65 66 67 68 69 70 | |
get_depth_from_existing_summary(summary_file)
¶
Parse existing mosdepth summary file without running mosdepth.
Useful for reusing existing depth analysis results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_file
|
Path
|
Path to existing .mosdepth.summary.txt file |
required |
Returns:
| Type | Description |
|---|---|
DepthSummary
|
DepthSummary object with computed statistics |
Source code in src/ssiamb/depth.py
298 299 300 301 302 303 304 305 306 307 308 309 310 | |
list_included_contigs(summary_file, min_len=500)
¶
Get set of contig names that meet minimum length threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_file
|
Path
|
Path to .mosdepth.summary.txt file |
required |
min_len
|
int
|
Minimum contig length threshold |
500
|
Returns:
| Type | Description |
|---|---|
Set[str]
|
Set of contig names that meet the length threshold |
Source code in src/ssiamb/depth.py
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 | |
parse_mosdepth_summary(summary_file)
¶
Parse mosdepth summary file to extract depth statistics.
The mosdepth summary file has format: chrom length bases mean min max contig1 5000 4850 25.3 0 100 ... total 50000 48500 24.8 0 100
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_file
|
Path
|
Path to .mosdepth.summary.txt file |
required |
Returns:
| Type | Description |
|---|---|
DepthSummary
|
DepthSummary object with computed statistics |
Raises:
| Type | Description |
|---|---|
DepthAnalysisError
|
If file parsing fails |
FileNotFoundError
|
If summary file doesn't exist |
Source code in src/ssiamb/depth.py
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 | |
run_mosdepth(bam_path, output_prefix, mapq_threshold=30, threads=4)
¶
Run mosdepth on a BAM file to compute depth statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bam_path
|
Path
|
Path to input BAM file |
required |
output_prefix
|
Path
|
Output prefix for mosdepth files |
required |
mapq_threshold
|
int
|
Minimum mapping quality (default: 30) |
30
|
threads
|
int
|
Number of threads to use |
4
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the generated summary file (.mosdepth.summary.txt) |
Raises:
| Type | Description |
|---|---|
DepthAnalysisError
|
If mosdepth is not available or execution fails |
FileNotFoundError
|
If BAM file doesn't exist |
Source code in src/ssiamb/depth.py
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 | |
Quality Control¶
Quality control policies and warning thresholds for ssiamb.
This module implements QC policies that warn but do not fail runs, as specified in spec.md §8.
QCThresholds(min_breadth_10x=0.8, min_callable_bases=1000000, min_mapping_rate_ref=0.7)
dataclass
¶
QC warning thresholds as specified in spec.md §8.
QCWarning(metric, value, threshold, message)
dataclass
¶
A QC warning with message and metric values.
check_qc_metrics(breadth_10x, callable_bases, mapping_rate=None, mode=None, thresholds=None)
¶
Check QC metrics against warning thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
breadth_10x
|
float
|
Breadth of coverage at 10x depth (0.0-1.0) |
required |
callable_bases
|
int
|
Number of callable bases |
required |
mapping_rate
|
Optional[float]
|
Mapping rate (0.0-1.0), required for ref mode |
None
|
mode
|
Optional[Mode]
|
Analysis mode (used to determine if mapping rate applies) |
None
|
thresholds
|
Optional[QCThresholds]
|
QC thresholds (uses defaults if None) |
None
|
Returns:
| Type | Description |
|---|---|
List[QCWarning]
|
List of QC warnings |
Source code in src/ssiamb/qc.py
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 | |
format_qc_warnings_for_summary(warnings)
¶
Format QC warnings for inclusion in summary TSV qc_warnings field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warnings
|
List[QCWarning]
|
List of QC warnings |
required |
Returns:
| Type | Description |
|---|---|
str
|
Semicolon-separated string of warning codes, or empty string if no warnings |
Source code in src/ssiamb/qc.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
log_qc_warnings(warnings)
¶
Log QC warnings to the logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warnings
|
List[QCWarning]
|
List of QC warnings to log |
required |
Source code in src/ssiamb/qc.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
VCF Operations¶
VCF operations module for ssiamb.
This module implements VCF normalization, atomization, MAF extraction, variant classification, and grid-based counting for ambiguous sites.
AmbigGrid(dp_cap=100)
¶
100×51 cumulative grid for ambiguous site counting.
Tracks sites by depth (0-100, with capping) and MAF bins (0-50, representing 0.00-0.50). MAF binning: bin = floor(100 * MAF), capped at 50.
Initialize grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dp_cap
|
int
|
Maximum depth value (higher values are capped) |
100
|
Source code in src/ssiamb/vcf_ops.py
346 347 348 349 350 351 352 353 354 355 356 357 | |
add_site(depth, maf)
¶
Add a site to the grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depth
|
int
|
Site depth (will be capped at dp_cap) |
required |
maf
|
float
|
Minor allele frequency (0.0 to 1.0) |
required |
Source code in src/ssiamb/vcf_ops.py
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 | |
build_cumulative()
¶
Build cumulative counts matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
Cumulative grid where each cell contains count of sites |
ndarray
|
with depth >= row_index and MAF >= col_index/100 |
Source code in src/ssiamb/vcf_ops.py
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 | |
count_at(dp_min, maf_min)
¶
Count sites meeting minimum thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dp_min
|
int
|
Minimum depth threshold |
required |
maf_min
|
float
|
Minimum MAF threshold |
required |
Returns:
| Type | Description |
|---|---|
int
|
Count of sites with depth >= dp_min and MAF >= maf_min |
Source code in src/ssiamb/vcf_ops.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
to_wide_tsv(output_path)
¶
Write cumulative grid to wide TSV format.
Per spec.md §4.4: "Wide table: rows depth=1..100; columns maf_0..maf_50"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Output file path |
required |
Source code in src/ssiamb/vcf_ops.py
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 | |
SiteRecord(chrom, pos, ref, alt, variant_class, depth, maf, original_filter)
dataclass
¶
Record for a genomic site with variant information.
VCFNormalizationResult(normalized_vcf_path, success, error_message=None, records_processed=0)
dataclass
¶
Result of VCF normalization operation.
VCFOperationError
¶
Bases: Exception
Raised when VCF operations fail.
VariantClass
¶
Bases: Enum
Variant classification types.
check_vcf_tools()
¶
Check if required VCF processing tools are available.
Returns:
| Type | Description |
|---|---|
bool
|
True if all required tools are available, False otherwise |
Source code in src/ssiamb/vcf_ops.py
59 60 61 62 63 64 65 66 67 | |
classify_variant(ref, alt)
¶
Classify variant type based on REF and ALT alleles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
str
|
Reference allele |
required |
alt
|
str
|
Alternative allele |
required |
Returns:
| Type | Description |
|---|---|
VariantClass
|
VariantClass enum value |
Source code in src/ssiamb/vcf_ops.py
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 | |
count_ambiguous_sites(vcf_path, dp_min, maf_min, dp_cap=100, included_contigs=None, variant_classes=None)
¶
Count ambiguous sites from normalized VCF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vcf_path
|
Path
|
Path to normalized VCF file |
required |
dp_min
|
int
|
Minimum depth threshold |
required |
maf_min
|
float
|
Minimum MAF threshold |
required |
dp_cap
|
int
|
Maximum depth (higher values capped) |
100
|
included_contigs
|
Optional[Set[str]]
|
Set of contigs to include |
None
|
variant_classes
|
Optional[List[VariantClass]]
|
List of variant classes to count (default: [SNV]) |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[int, AmbigGrid]
|
Tuple of (ambiguous_count, grid_object) |
Source code in src/ssiamb/vcf_ops.py
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 | |
emit_bed(normalized_vcf_path, output_path, dp_min, maf_min, sample_name, included_contigs=None)
¶
Emit BED output with ambiguous sites in 0-based half-open coordinates.
BED format columns: chrom, start, end, name, score, strand, sample, variant_class, ref, alt, maf, dp, maf_bin, dp_cap
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_vcf_path
|
Path
|
Path to normalized input VCF |
required |
output_path
|
Path
|
Output BED path (will be bgzipped) |
required |
dp_min
|
int
|
Minimum depth threshold |
required |
maf_min
|
float
|
Minimum MAF threshold |
required |
sample_name
|
str
|
Sample name |
required |
included_contigs
|
Optional[Set[str]]
|
Set of contigs to include |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to compressed, indexed BED file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If emission fails |
Source code in src/ssiamb/vcf_ops.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
emit_matrix(grid, output_path, sample_name)
¶
Emit variant matrix as compressed TSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
AmbigGrid
|
Populated AmbigGrid with variant counts |
required |
output_path
|
Path
|
Output path (will be ensured to end with .tsv.gz) |
required |
sample_name
|
str
|
Sample name for logging |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to compressed matrix file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If matrix emission fails |
Source code in src/ssiamb/vcf_ops.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
emit_multiqc(sample_name, ambiguous_snv_count, breadth_10x, callable_bases, genome_length, dp_min, maf_min, mapper, caller, mode, output_path)
¶
Emit MultiQC-compatible metrics TSV.
As per spec.md §4.6: sample, ambiguous_snv_count, ambiguous_snv_per_mb, breadth_10x, callable_bases, genome_length, dp_min, maf_min, mapper, caller, mode
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_name
|
str
|
Sample identifier |
required |
ambiguous_snv_count
|
int
|
Count of ambiguous SNVs |
required |
breadth_10x
|
float
|
Fraction of genome with ≥10x coverage |
required |
callable_bases
|
int
|
Number of callable bases |
required |
genome_length
|
int
|
Total genome length |
required |
dp_min
|
int
|
Minimum depth threshold used |
required |
maf_min
|
float
|
Minimum MAF threshold used |
required |
mapper
|
str
|
Mapper tool name |
required |
caller
|
str
|
Caller tool name |
required |
mode
|
str
|
Analysis mode (self or ref) |
required |
output_path
|
Path
|
Output path (will be ensured to end with .tsv) |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to emitted MultiQC TSV file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If MultiQC emission fails |
Source code in src/ssiamb/vcf_ops.py
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
emit_per_contig(normalized_vcf_path, depth_summary_path, output_path, dp_min, maf_min, sample_name, included_contigs=None)
¶
Emit per-contig summary statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_vcf_path
|
Path
|
Path to normalized VCF file |
required |
depth_summary_path
|
Path
|
Path to mosdepth summary file |
required |
output_path
|
Path
|
Output TSV path |
required |
dp_min
|
int
|
Minimum depth threshold |
required |
maf_min
|
float
|
Minimum MAF threshold |
required |
sample_name
|
str
|
Sample name |
required |
included_contigs
|
Optional[Set[str]]
|
Set of contigs to include |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to per-contig summary file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If emission fails |
Source code in src/ssiamb/vcf_ops.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | |
emit_vcf(normalized_vcf_path, output_path, dp_min, maf_min, sample_name, require_pass=False, included_contigs=None)
¶
Emit VCF output with only records passing ambiguous site thresholds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized_vcf_path
|
Path
|
Path to normalized input VCF |
required |
output_path
|
Path
|
Output VCF path (will be bgzipped) |
required |
dp_min
|
int
|
Minimum depth threshold |
required |
maf_min
|
float
|
Minimum MAF threshold |
required |
sample_name
|
str
|
Sample name for output |
required |
require_pass
|
bool
|
If True, include ORIG_FILTER info field |
False
|
included_contigs
|
Optional[Set[str]]
|
Set of contigs to include |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to compressed, indexed VCF file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If emission fails |
Source code in src/ssiamb/vcf_ops.py
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 | |
extract_maf_from_record(record)
¶
Extract minor allele frequency from VCF record using precedence: AD → DP4 → AF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
pysam VariantRecord |
required |
Returns:
| Type | Description |
|---|---|
Optional[float]
|
MAF as float between 0 and 1, or None if cannot be determined |
Source code in src/ssiamb/vcf_ops.py
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 | |
normalize_and_split(vcf_in, reference, output_dir=None)
¶
Normalize VCF to reference and decompose into primitive records.
Uses bcftools norm to:
1. Normalize variants to reference (-f REF)
2. Split multiallelic sites (-m -both)
3. Atomize variants (--atomize)
4. Compress and index output
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vcf_in
|
Path
|
Input VCF file path |
required |
reference
|
Path
|
Reference FASTA file path |
required |
output_dir
|
Optional[Path]
|
Output directory (defaults to input directory) |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to normalized, compressed VCF file |
Raises:
| Type | Description |
|---|---|
VCFOperationError
|
If normalization fails |
Source code in src/ssiamb/vcf_ops.py
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 | |
parse_vcf_sites(vcf_path, included_contigs=None)
¶
Parse normalized VCF and yield site records with MAF and variant classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vcf_path
|
Path
|
Path to VCF file (can be compressed) |
required |
included_contigs
|
Optional[Set[str]]
|
Set of contig names to include (None = include all) |
None
|
Yields:
| Type | Description |
|---|---|
SiteRecord
|
SiteRecord objects for each variant site |
Source code in src/ssiamb/vcf_ops.py
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 | |
I/O Utilities¶
I/O utilities for ssiamb.
This module provides file handling utilities including sample name validation, TSV writing with atomic operations, and file hashing.
SampleNameError
¶
Bases: ValueError
Raised when sample name is invalid.
TSVWriteError
¶
Bases: Exception
Raised when TSV writing fails.
compute_md5(file_path)
¶
Compute MD5 hash of a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to file |
required |
Returns:
| Type | Description |
|---|---|
str
|
MD5 hash as hex string |
Source code in src/ssiamb/io_utils.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
file_lock(file_path)
¶
Context manager for file locking (best-effort cross-platform).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to lock |
required |
Source code in src/ssiamb/io_utils.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 | |
infer_sample_name(r1, r2=None, vcf=None, bam=None)
¶
Infer sample name from input filenames.
Tries to extract a common prefix from R1/R2 filenames, removing common suffixes like _R1, _R2, .fastq, .gz, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
Path
|
Forward reads file |
required |
r2
|
Optional[Path]
|
Reverse reads file (optional) |
None
|
vcf
|
Optional[Path]
|
VCF file (optional) |
None
|
bam
|
Optional[Path]
|
BAM file (optional) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Inferred sample name |
Raises:
| Type | Description |
|---|---|
SampleNameError
|
If sample name cannot be inferred |
Source code in src/ssiamb/io_utils.py
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 | |
validate_sample_name(sample)
¶
Validate sample name according to ssiamb rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
str
|
Sample name to validate |
required |
Returns:
| Type | Description |
|---|---|
str
|
Validated sample name |
Raises:
| Type | Description |
|---|---|
SampleNameError
|
If sample name is invalid |
Source code in src/ssiamb/io_utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
write_tsv_summary(output_path, rows, mode=TSVMode.OVERWRITE)
¶
Write summary rows to TSV file with atomic operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Output TSV file path |
required |
rows
|
List[SummaryRow]
|
List of SummaryRow objects to write |
required |
mode
|
TSVMode
|
Write mode (overwrite, append, or fail if exists) |
OVERWRITE
|
Raises:
| Type | Description |
|---|---|
TSVWriteError
|
If writing fails |
FileExistsError
|
If file exists and mode is FAIL |
Source code in src/ssiamb/io_utils.py
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 | |
write_tsv_to_stdout(rows)
¶
Write summary rows to stdout in TSV format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
List[SummaryRow]
|
List of SummaryRow objects to write |
required |
Source code in src/ssiamb/io_utils.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
Models¶
Core data models for ssiamb.
This module defines the primary data structures used throughout the application, including configuration objects, output records, and enums for various options.
Caller
¶
Bases: Enum
Variant calling tool.
DepthTool
¶
Bases: Enum
Depth analysis tool.
Mapper
¶
Bases: Enum
Read mapping tool.
Mode
¶
Bases: Enum
Analysis mode.
OnFail
¶
Bases: Enum
Action when reference resolution fails.
Paths(r1, r2, assembly=None, reference=None, output_dir=Path('.'), sample=None, bam=None, vcf=None, depth_summary=None)
dataclass
¶
File paths for input and output.
__post_init__()
¶
Validate paths and resolve output directory.
Source code in src/ssiamb/models.py
230 231 232 233 234 235 236 237 238 | |
Provenance(ssiamb_version, command_line, timestamp, input_files=dict(), tool_versions=dict(), hostname='', working_dir='')
dataclass
¶
Provenance information for reproducibility.
Tracks tool versions, command lines, input file hashes, etc.
to_dict()
¶
Convert to dictionary for JSON output.
Source code in src/ssiamb/models.py
307 308 309 310 311 312 313 314 315 316 317 | |
RunPlan(mode, sample, paths, thresholds, mapper=Mapper.MINIMAP2, caller=Caller.BBTOOLS, depth_tool=DepthTool.MOSDEPTH, bbtools_mem=None, require_pass=False, ref_source='unknown', ref_label='unknown', emit_vcf=False, emit_bed=False, emit_matrix=False, emit_per_contig=False, emit_provenance=False, emit_multiqc=False, to_stdout=False, tsv_mode=TSVMode.OVERWRITE, threads=1, dry_run=False)
dataclass
¶
Complete execution plan for a ssiamb run.
This captures all resolved inputs, tools, and output specifications before execution begins.
get_sample_prefix()
¶
Get prefix for output files.
Source code in src/ssiamb/models.py
283 284 285 | |
SummaryRow(sample, mode, mapper, caller, dp_min, maf_min, dp_cap, denom_policy, callable_bases, genome_length, breadth_10x, ambiguous_snv_count, ambiguous_snv_per_mb, ambiguous_indel_count, ambiguous_del_count, ref_label, ref_accession, bracken_species, bracken_frac, bracken_reads, alias_used, reused_bam, reused_vcf, runtime_sec, tool_version)
dataclass
¶
Single row of the ambiguous_summary.tsv output.
Based on spec.md §4.1 - Primary Output Format. Schema: sample, mode, mapper, caller, dp_min, maf_min, dp_cap, denom_policy, callable_bases, genome_length, breadth_10x, ambiguous_snv_count, ambiguous_snv_per_mb, ambiguous_indel_count, ambiguous_del_count, ref_label, ref_accession, bracken_species, bracken_frac, bracken_reads, alias_used, reused_bam, reused_vcf, runtime_sec, tool_version
to_dict()
¶
Convert to dictionary for TSV output.
Source code in src/ssiamb/models.py
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 | |
TSVMode
¶
Bases: Enum
TSV output mode.
Thresholds(dp_min=None, maf_min=None, dp_cap=None, mapq_min=None, baseq_min=None)
dataclass
¶
Thresholds for ambiguous site detection.
__post_init__()
¶
Load defaults from configuration and validate threshold values.
Source code in src/ssiamb/models.py
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 | |
from_config(config=None, **overrides)
classmethod
¶
Create Thresholds from configuration with optional overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional['SsiambConfig']
|
Configuration object (uses global if None) |
None
|
**overrides
|
Explicit threshold values to override |
{}
|
Returns:
| Type | Description |
|---|---|
'Thresholds'
|
Thresholds instance with config defaults and overrides applied |
Source code in src/ssiamb/models.py
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 | |
Provenance¶
Provenance tracking for ssiamb runs.
This module handles collection and output of detailed per-sample provenance information when --emit-provenance is used.
ProvenanceCallerParams(exact_cmdlines)
dataclass
¶
Variant caller parameters.
ProvenanceContigFilters(min_contig_len=500)
dataclass
¶
Contig filtering settings.
ProvenanceCounts(ambiguous_snv_count=None, ambiguous_indel_count=None, ambiguous_del_count=None, callable_bases=None, genome_length=None)
dataclass
¶
Analysis counts.
ProvenanceDuplicatePolicy(denominator_excludes_dups=True, bam_had_dups_flag=None)
dataclass
¶
Duplicate handling policy.
ProvenanceExtrasEmitted(vcf=False, bed=False, matrix=False, per_contig=False)
dataclass
¶
Optional outputs emitted.
ProvenanceGridCell(depth, maf_bin)
dataclass
¶
Grid cell used for analysis.
ProvenanceInput(path, md5=None)
dataclass
¶
Input file information with MD5 hash.
ProvenanceMappingStats(total_reads=None, mapped_reads=None, map_rate=None, mean_depth=None, breadth_1x=None, breadth_10x=None)
dataclass
¶
Mapping statistics.
ProvenanceRecord(tool_version, python_version, conda_env, started_at, finished_at, runtime_sec, threads, sample, mode, mapper, caller, thresholds, denom_policy, depth_tool, inputs, reference_info, species_selection=None, mapping_stats=None, duplicate_policy=None, contig_filters=None, caller_params=None, counts=None, grid_cell_used=None, extras_emitted=None, warnings=None)
dataclass
¶
Complete provenance record for a sample.
ProvenanceReferenceInfo(species_requested=None, alias_applied=None, species_final=None, fasta_path=None, fasta_md5=None, source=None)
dataclass
¶
Reference genome information.
ProvenanceSpeciesSelection(bracken_species=None, bracken_frac=None, bracken_reads=None, thresholds=None, on_fail=None)
dataclass
¶
Species selection from Bracken.
calculate_md5(file_path)
¶
Calculate MD5 hash of a file.
Source code in src/ssiamb/provenance.py
151 152 153 154 155 156 157 158 159 160 | |
create_provenance_record(sample, mode, started_at, finished_at, threads, mapper, caller, dp_min, maf_min, dp_cap, denom_policy, depth_tool, emit_vcf, emit_bed, emit_matrix, emit_per_contig, r1=None, r2=None, assembly=None, reference=None, bam=None, vcf=None, species=None, mapping_stats=None, species_selection=None, counts=None, warnings=None, reference_path=None, reference_species=None)
¶
Create a complete provenance record for a sample.
Source code in src/ssiamb/provenance.py
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 | |
get_conda_env()
¶
Get the name of the current conda environment.
Source code in src/ssiamb/provenance.py
163 164 165 166 167 168 | |
get_tool_version()
¶
Get the current tool version.
Source code in src/ssiamb/provenance.py
171 172 173 174 175 176 177 | |
write_provenance_json(records, output_path)
¶
Write provenance records to JSON file.
Source code in src/ssiamb/provenance.py
292 293 294 295 | |