Parser
The parser module provides low-level parsing functionality for VCF files.
vcfpy.parser.Parser
- class vcfpy.parser.Parser(stream: TextIOWrapper, path: Path | str | None = None, record_checks: Iterable[Literal['FORMAT', 'INFO']] | None = None)[source]
Class for line-wise parsing of VCF files
In most cases, you want to use
vcfpy.reader.Readerinstead.- Parameters:
stream –
file-like object to read frompath (str) – path the VCF is parsed from, for display purposes only, optional
- header
header, once it has been read
- parse_header(parsed_samples: list[str] | None = None)[source]
Read and parse
vcfpy.header.Headerfrom file, set intoself.headerand return it- Parameters:
parsed_samples (list) –
listofstrfor subsetting the samples to parse- Returns:
vcfpy.header.Header- Raises:
vcfpy.exceptions.InvalidHeaderExceptionin the case of problems reading the header
- parse_next_record()[source]
Read, parse and return next
vcfpy.record.Record- Returns:
next VCF record or
Noneif at end- Raises:
vcfpy.exceptions.InvalidRecordExceptionin the case of problems reading the record
- record_checks
checks to perform, can contain ‘INFO’ and ‘FORMAT’
- samples
vcfpy.header.SamplesInfoswith sample information; set on parsing the header
vcfpy.RecordParser
- class vcfpy.parser.RecordParser(header: Header, samples: SamplesInfos, record_checks: Iterable[Literal['FORMAT', 'INFO']] | None = None)[source]
Helper class for parsing VCF records
- header
Header with the meta information
- parse_line(line_str: str) Record | None[source]
Parse line from file (including trailing line break) and return resulting Record
- record_checks
The checks to perform, can contain ‘INFO’ and ‘FORMAT’
- samples
SamplesInfos with sample information
vcfpy.HeaderParser
- class vcfpy.parser.HeaderParser[source]
Helper class for parsing a VCF header
- parse_line(line: str) HeaderLine[source]
Parse VCF header
line(trailing ‘ ‘ or ‘ ‘ is ignored)- param str line:
strwith line to parse- param dict sub_parsers:
dictmapping header line types to appropriate parser objects- returns:
appropriate
HeaderLineparsed fromline- raises:
vcfpy.exceptions.InvalidHeaderExceptionif there was a problem parsing the file
- sub_parsers
Sub parsers to use for parsing the header lines