vcf ¶
Read and write vcf file.
add_info_column ¶
Construct an INFO column from multiple columns of lf.
Useful when you want serialise polars.LazyFrame in vcf file format.
Parameters:
-
lf
(LazyFrame
) – -
vcfinfo2parquet_name
(list[tuple[str, str]]
) –List of vcf column name and polars.LazyFrame column name.
Returns:
-
LazyFrame
–polars.LazyFrame with INFO column and remove lf column use.
Source code in src/variantplaner/io/vcf.py
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 |
|
build_rename_column ¶
build_rename_column(chromosome: str, pos: str, identifier: str, ref: str, alt: str, qual: str | None = '.', filter_col: str | None = '.', info: list[tuple[str, str]] | None = None, format_string: str | None = None, sample: dict[str, dict[str, str]] | None = None) -> RenameCol
A helper function to generate rename column dict for variantplaner.io.vcf.from_lazyframe function parameter.
Returns:
-
RenameCol
–A rename column dictionary.
Source code in src/variantplaner/io/vcf.py
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 |
|
extract_header ¶
Extract all header information of vcf file.
Line between start of file and first line start with '#CHROM' or not start with '#'
Parameters:
-
input_path
(Path
) –Path to vcf file.
Returns:
Raises:
-
NotAVCFError
–If a line not starts with '#'
-
NotAVCFError
–If all line not start by '#CHROM'
Source code in src/variantplaner/io/vcf.py
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 |
|
format2expr ¶
format2expr(header: list[str], input_path: Path, select_format: set[str] | None = None) -> dict[str, Callable[[Expr, str], Expr]]
Read vcf header to generate a list of polars.Expr to extract genotypes information.
Warning: Float values can't be converted for the moment they are stored as String to keep information
Parameters:
-
header
(list[str]
) –Line of vcf header.
-
input_path
(Path
) –Path to vcf file.
-
select_format
(set[str] | None
, default:None
) –List of target format field.
Returns:
-
dict[str, Callable[[Expr, str], Expr]]
–A dict to link format id to pipeable function with Polars.Expr
Raises:
-
NotAVCFError
–If all line not start by '#CHR'
Source code in src/variantplaner/io/vcf.py
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 |
|
from_lazyframe ¶
from_lazyframe(lf: LazyFrame, output_path: Path, renaming: RenameCol = DEFAULT_RENAME) -> None
Write polars.LazyFrame in vcf format.
Chromosome name mapping table
- 23: X
- 24: Y
- 25: MT
All other chromosome number isn't changed.
Warning: This function performs polars.LazyFrame.collect before write vcf, this can have a significant impact on memory usage.
Parameters:
-
lf
(LazyFrame
) –LazyFrame contains information.
-
output_path
(Path
) –Path to where vcf to write.
Returns:
-
None
–None
Source code in src/variantplaner/io/vcf.py
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 |
|
info2expr ¶
Read vcf header to generate a list of polars.Expr to extract variants information.
Parameters:
-
header
(list[str]
) –Line of vcf header
-
input_path
(Path
) –Path to vcf file.
-
select_info
(set[str] | None
, default:None
) –List of target info field
Returns:
-
list[Expr]
–List of polars.Expr to parse info columns.
Raises:
-
NotAVCFError
–If all line not start by '#CHR'
Source code in src/variantplaner/io/vcf.py
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 |
|
into_lazyframe ¶
into_lazyframe(input_path: Path, chr2len_path: Path, extension: IntoLazyFrameExtension = IntoLazyFrameExtension.NOTHING) -> LazyFrame
Read a vcf file and convert it in polars.LazyFrame.
Parameters:
-
input_path
(Path
) –Path to vcf file.
-
chr2len_path
(Path
) –Path to chr2length csv.
-
extension
(IntoLazyFrameExtension
, default:NOTHING
) –Control behavior of into_lazyframe.
Returns:
-
LazyFrame
–A polars.LazyFrame that contains vcf information ('chr', 'pos', 'vid', 'ref', 'alt', 'qual', 'filter', 'info', ['format'], ['genotypes',…], 'id').
Source code in src/variantplaner/io/vcf.py
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 |
|
sample_index ¶
Read vcf header to generate an association map between sample name and index.
Parameters:
Returns:
Raises:
-
NotAVCFError
–If all line not start by '#CHR'
Source code in src/variantplaner/io/vcf.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|