A package for maf files io
Project description
MAFIO
A minimalist Python package for reading and writing MAF files.
Installation
Package can be installed using pip.
> pip install mafio
Usage
Read
from mafio import MAFReader
reader = MAFReader("test.maf")
# for reading compressed file
reader = MAFReader("test.maf", compression='gzip')
data = reader.read()
print(reader.headers) # ['col1', 'col2', 'col3']
print(next(data)) # [[1,2,3], [4,5,6], [7,8,9]]
# return only certain columns
data = reader.read(use_cols=['col1','col3'])
print(reader.headers) # ['col1', 'col3']
print(next(data)) # [[1,3], [4,6], [7,9]]
# for big files use chunks
data = reader.read(chunk_size=2)
print(next(data)) #[[1,2,3], [4,5,6]]
print(next(data)) #[[7,8,9]]
Write
from mafio import write
cols = ['col1', 'col2', 'col3']
row1 = [1,2,3]
row2 = [4,5,6]
row3 = [7,8,9]
data = [cols, row1, row2, row3]
# Creates file if not exists
write("test.maf", data)
# Appending the file instead of overwriting
write("test.maf", data, append=True)
# gzip the file
write("test.maf.gz", data)
Tests
Clone the library.
> git clone https://github.com/zeyad-kay/mafio.git
Install test dependencies.
pip install -r test-requirements.txt
Run tests.
> pytest mafio/tests
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mafio-1.0.2.tar.gz
(3.8 kB
view hashes)
Built Distribution
mafio-1.0.2-py3-none-any.whl
(4.4 kB
view hashes)