API Reference
vcf_reader
VCF File Readers.
VCFReader
class VCFReader(Reader)
A VCF File Reader.
This class is used to read a VCF file and convert it to a polars DataFrame.
__init__
def __init__(path: os.PathLike)
Initialize the VCFReader.
Arguments:
path
Path - Path to the VCF file.
inner
@property
def inner()
Return the inner reader.
VCFIndexedReader
class VCFIndexedReader(Reader)
An Indexed VCF File Reader.
This class is used to read or query an indexed VCF file and convert it to a polars DataFrame.
__init__
def __init__(path: os.PathLike)
Initialize the VCFIndexedReader.
inner
@property
def inner()
Return the inner reader.
query
def query(region: str) -> pa.RecordBatchReader
Query the VCF file and return a pyarrow RecordBatchReader.
Arguments:
region
str - The region to query.
genbank_reader
Genbank file reader.
GenbankReader
class GenbankReader(Reader)
Genbank file reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Read a genbank file.
Arguments:
path
Path - Path to the fasta file.compression
Compression - Compression type of the file.
inner
@property
def inner()
Return the inner reader.
mzml_reader
MzML File Reader.
MzMLReader
class MzMLReader(Reader)
A MzML File Reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Initialize the MzMLReader.
Arguments:
path
- The path to the MzML file.
inner
@property
def inner()
Return the inner reader.
gtf_reader
GTF File Reader.
GTFReader
class GTFReader(Reader)
A GTF File Reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Initialize the GTFReader.
Arguments:
path
- The path to the GTF file.
to_polars
def to_polars()
Read the GTF file and return a polars DataFrame.
to_arrow
def to_arrow() -> pa.RecordBatchReader
Convert the GTF reader to an arrow batch reader.
to_arrow_scanner
def to_arrow_scanner() -> ds.Scanner
Convert the GTF reader to an arrow scanner.
inner
@property
def inner()
Return the inner reader.
fasta_reader
FASTA file reader.
FastaReader
class FastaReader(Reader)
FASTA file reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Read a fasta file.
Arguments:
path
Path - Path to the fasta file.Kwargs:
compression
Compression - Compression type of the file. Defaults to Compression.INFERRED.
inner
@property
def inner()
Return the inner reader.
compression
Compression configuration.
Compression
class Compression(Enum)
Compression types for files.
from_file
@classmethod
def from_file(cls, path: os.PathLike) -> "Compression"
Infer the compression type from the file extension.
infer_or_use
def infer_or_use(path: os.PathLike) -> "Compression"
Infer the compression type from the file extension if needed.
session
__init__
Main biobear package.
reader
Abstract Reader class for reading data from a file or stream.
Reader
class Reader(ABC)
An abstract base class (ABC) representing a reader.
The class defines basic functionalities for conversion, but the specifics must be implemented in a subclass.
inner
@property
@abstractmethod
def inner()
Abstract property for the inner reader.
Returns:
The inner reader. The type of the reader is defined by the specific subclass.
to_pandas
def to_pandas()
Convert the inner data to a Pandas DataFrame.
Returns:
pd.DataFrame
- The converted data in a Pandas DataFrame.
Raises:
ImportError
- If the 'pandas' package is not installed.
to_polars
def to_polars()
Convert the inner data to a Polars DataFrame.
This method first converts the inner reader's data to an Arrow table, then to a Python dictionary, and finally to a Polars DataFrame.
Returns:
pl.DataFrame
- The converted data in a Polars DataFrame.
Raises:
ImportError
- If the 'polars' package is not installed.
to_arrow_scanner
def to_arrow_scanner() -> ds.Scanner
Convert the inner data to an Arrow scanner.
This method first converts the inner reader's data to Arrow batches, and then forms a scanner from these batches.
Returns:
ds.Scanner
- The converted data in an Arrow scanner.
to_arrow
def to_arrow() -> pa.RecordBatchReader
Convert the inner data to an Arrow record batch reader.
If the inner reader is exhausted, this method raises an exception. Otherwise, it converts the inner reader's data to an Arrow record batch.
Returns:
pa.RecordBatchReader
- The converted data in an Arrow record batch reader.
Raises:
StopIteration
- If the inner reader is exhausted.
bam_reader
BAM File Readers.
BamReader
class BamReader(Reader)
A BAM File Reader.
__init__
def __init__(path: os.PathLike)
Initialize the BamReader.
Arguments:
path
Path - Path to the BAM file.
inner
@property
def inner()
Return the inner reader.
BamIndexedReader
class BamIndexedReader(Reader)
An Indexed BAM File Reader.
__init__
def __init__(path: os.PathLike)
Initialize the BamIndexedReader.
Arguments:
path
Path - Path to the BAM file.index
Path - Path to the BAM index file.
inner
@property
def inner()
Return the inner reader.
query
def query(region: str) -> pa.RecordBatchReader
Query the BAM file and return an Arrow RecordBatchReader.
Arguments:
region
- A region in the format "chr:start-end".
fastq_reader
FASTQ reader.
FastqReader
class FastqReader(Reader)
FASTQ file reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Read a fastq file.
Arguments:
path
Path - Path to the fastq file.Kwargs:
compression
Compression - Compression type of the file. Defaults to Compression.INFERRED.
inner
@property
def inner()
Return the inner reader.
bcf_reader
BCF File Readers.
BCFReader
class BCFReader(Reader)
A BCF File Reader.
This class is used to read a BCF file and convert it to a polars DataFrame.
__init__
def __init__(path: os.PathLike)
Initialize the BCFReader.
Arguments:
path
Path - Path to the BCF file.
inner
@property
def inner()
Return the inner reader.
BCFIndexedReader
class BCFIndexedReader(Reader)
An Indexed BCF File Reader.
This class is used to read or query an indexed BCF file and convert it to a polars DataFrame.
__init__
def __init__(path: os.PathLike)
Initialize the BCFIndexedReader.
inner
@property
def inner()
Return the inner reader.
query
def query(region: str) -> pa.RecordBatchReader
Query the BCF file and return an arrow batch reader.
Arguments:
region
str - The region to query.
gff_reader
GFF File Reader.
GFFReader
class GFFReader(Reader)
A GFF File Reader.
__init__
def __init__(path: os.PathLike,
compression: Compression = Compression.INFERRED)
Initialize the GFFReader.
Arguments:
path
- The path to the GFF file.
to_polars
def to_polars()
Read the GFF file and return a polars DataFrame.
to_arrow
def to_arrow() -> pa.RecordBatchReader
Convert the GFF reader to an arrow batch reader.
to_arrow_scanner
def to_arrow_scanner() -> ds.Scanner
Convert the GFF reader to an arrow scanner.
inner
@property
def inner()
Return the inner reader.