Input/Output¶
Contents
vcfpy.Reader¶
-
class
vcfpy.
Reader
(stream, path=None, tabix_path=None, record_checks=None, parse_samples=None)[source]¶ Class for parsing of files from
file
-like objectsInstead of using the constructor, use the class methods
from_stream()
andfrom_path()
.On construction, the header will be read from the file which can cause problems. After construction,
Reader
can be used as an iterable ofRecord
.Raises: InvalidHeaderException
in the case of problems reading the headerNote
It is important to note that the
header
member is used during the parsing of the file. If you need a modified version then create a copy, e.g., using :py:method:`~vcfpy.header.Header.copy`.Note
If you use the
parse_samples
feature and you write out records then you must not change theFORMAT
of the record.-
fetch
(chrom_or_region, begin=None, end=None)[source]¶ Jump to the start position of the given chromosomal position and limit iteration to the end position
Parameters: - chrom_or_region (str) – name of the chromosome to jump to if begin and end are given and a samtools region string otherwise (e.g. “chr1:123,456-123,900”).
- begin (int) – 0-based begin position (inclusive)
- end (int) – 0-based end position (exclusive)
-
classmethod
from_path
(klass, path, tabix_path=None, record_checks=None, parse_samples=None)[source]¶ Create new
Reader
from pathNote
If you use the
parse_samples
feature and you write out records then you must not change theFORMAT
of the record.Parameters: - path – the path to load from (converted to
str
for compatibility withpath.py
) - tabix_path – optional string with path to TBI index,
automatic inferral from
path
will be tried on the fly if not given - record_checks (list) – record checks to perform, can contain ‘INFO’ and ‘FORMAT’
- path – the path to load from (converted to
-
classmethod
from_stream
(klass, stream, path=None, tabix_path=None, record_checks=None, parse_samples=None)[source]¶ Create new
Reader
from fileNote
If you use the
parse_samples
feature and you write out records then you must not change theFORMAT
of the record.Parameters: - stream –
file
-like object to read from - path – optional string with path to store (for display only)
- record_checks (list) – record checks to perform, can contain ‘INFO’ and ‘FORMAT’
- parse_samples (list) –
list
ofstr
values with names of samples to parse call information for (for speedup); leave toNone
for ignoring
- stream –
-
header
= None¶ the Header
-
parse_samples
= None¶ if set, list of samples to parse for
-
parser
= None¶ the parser to use
-
path
= None¶ optional
str
with the path to the stream
-
record_checks
= None¶ checks to perform on records, can contain ‘FORMAT’ and ‘INFO’
-
stream
= None¶ stream (
file
-like object) to read from
-
tabix_file
= None¶ the
pysam.TabixFile
used for reading from index bgzip-ed VCF; constructed on the fly
-
tabix_path
= None¶ optional
str
with path to tabix file
-
vcfpy.Writer¶
-
class
vcfpy.
Writer
(stream, header, path=None)[source]¶ Class for writing VCF files to
file
-like objectsInstead of using the constructor, use the class methods
from_stream()
andfrom_path()
.The writer has to be constructed with a
Header
object and the full VCF header will be written immediately on construction. This, of course, implies that modifying the header after construction is illegal.-
classmethod
from_path
(klass, path, header)[source]¶ Create new
Writer
from pathParameters: - path – the path to load from (converted to
str
for compatibility withpath.py
) - header – VCF header to use, lines and samples are deep-copied
- path – the path to load from (converted to
-
classmethod
from_stream
(klass, stream, header, path=None, use_bgzf=None)[source]¶ Create new
Writer
from fileNote that for getting bgzf support, you have to pass in a stream opened in binary mode. Further, you either have to provide a
path
ending in".gz"
or setuse_bgzf=True
. Otherwise, you will get the notorious “TypeError: ‘str’ does not support the buffer interface”.Parameters: - stream –
file
-like object to write to - header – VCF header to use, lines and samples are deep-copied
- path – optional string with path to store (for display only)
- use_bgzf – indicator whether to write bgzf to
stream
ifTrue
, prevent ifFalse
, interpretpath
ifNone
- stream –
-
header
= None¶ the :py:class:~vcfpy.header.Header` to write out, will be deep-copied into the
Writer
on initialization
-
path
= None¶ optional
str
with the path to the stream
-
stream
= None¶ stream (
file
-like object) to read from
-
write_record
(record)[source]¶ Write out the given
vcfpy.record.Record
to this Writer
-
classmethod