Skip to content

A minimalist Python package for reading and writing MAF files.

License

Notifications You must be signed in to change notification settings

zeyad-kay/mafio

Repository files navigation

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

About

A minimalist Python package for reading and writing MAF files.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages