PK!D yy&bin2fasta/.converter.cpp.cppimporthash]qXA/Users/kimja/programming/python/bin2fasta/bin2fasta/converter.cppqaX e3e7bd28e5f460ce8f24e6c59685f705qq.PK!6D!bin2fasta/.rendered.converter.cpp/*cppimport */ #include int add(int i, int j) { return i + j; } PYBIND11_MODULE(converter, m) { m.def("add", &add, "A function which adds two numbers"); } PK!j*,,bin2fasta/__init__.pyfrom .main import main __all__ = ['main'] PK!ibin2fasta/converter.cpp/*cppimport <% setup_pybind11(cfg) %> */ #include int add(int i, int j) { return i + j; } PYBIND11_MODULE(converter, m) { m.def("add", &add, "A function which adds two numbers"); } PK!bin2fasta/crypto.pyimport os from io import IOBase import M2Crypto class CryptoStreamer(IOBase): def __init__(self, key: str, fname: str): self.stream = stream block_size = M2Crypto.m2.AES_BLOCK_SIZE iv = os.urandom(block_size) self.aes = M2Crypto.EVP.Cipher( alg='aes_128_cfb', key=key.encode(), iv=iv, op=M2Crypto.m2.encrypt ) def read(self, *args, **kwargs): return self.aes.update(self.stream.read(*args, **kwargs)) def write(self, data): self.stream.write(self.aes.update(data.encode())) def close(self): self.stream.write(self.aes.final()) if __name__ == '__main__': import sys cs = CryptoStreamer('huibuh', sys.stdout) cs.write('foo') PK!AI/ / bin2fasta/main.pyimport sys import click from tqdm import tqdm class FileStreamer: """Generic file opener context""" def __init__(self, fname, mode): self.fname = fname self.mode = mode self.fd = None def __enter__(self): if self.fname == '-': self.fd = sys.stdin.buffer if 'b' in self.mode else sys.stdin else: self.fd = open(self.fname, self.mode) return self def __exit__(self, exc_type, exc_val, exc_tb): self.fd.close() class BitReader(FileStreamer): """Read individual bits of file""" def read(self): while True: byte = self.fd.read(1) if len(byte) == 0: return b = ord(byte) for i in range(7, -1, -1): yield (b >> i) & 1 class SequenceReader(FileStreamer): """Read only bases from FASTA file""" def read(self): ignore = True while True: char = self.fd.read(1) if len(char) == 0: return if char == '>': ignore = True continue elif char == '\n': ignore = False continue if not ignore: yield char TABLE_BIN2FASTA = {0: {0: 'A', 1: 'G'}, 1: {0: 'T', 1: 'C'}} TABLE_FASTA2BIN = {'A': '00', 'G': '01', 'T': '10', 'C': '11'} @click.command() @click.argument('filename', type=click.Path(exists=True, allow_dash=True)) @click.option( '-D', '--decode', is_flag=True, default=False, help='Enable conversion from FASTA to binary.') @click.option( '-o', '--output', type=click.File('w'), default='-', help='File to write to.') def main(filename, decode, output): """Store any file as a fasta file""" if decode: with SequenceReader(filename, mode='r') as fd: data = '' for base in tqdm(fd.read()): out = TABLE_FASTA2BIN[base] data += out if len(data) == 8: int_ = 0 for bit in data: int_ = (int_ << 1) | int(bit) data = '' byte = int_.to_bytes(1, byteorder=sys.byteorder) output.buffer.write(byte) else: section_length = 250 output.write('>Sequence_master\n') with BitReader(filename, mode='rb') as fd: last = None for i, bit in enumerate(tqdm(fd.read())): if (i+1) % section_length == 0: output.write(f'\n>Sequence_{hex(i)}\n') if last is None: last = bit else: out = TABLE_BIN2FASTA[last][bit] last = None output.write(out) if __name__ == '__main__': main() PK!bin2fasta/tests/__init__.pyPK!]bin2fasta/tests/test_all.pyfrom click.testing import CliRunner from ..main import main def test_integration(): runner = CliRunner() with runner.isolated_filesystem(): # setup environment content = 'Hello World!' fname = 'test.dat' with open(fname, 'w') as fd: fd.write(content) # run conversions result_b2f = runner.invoke( main, [fname, '-o', 'tmp.fasta']) result_f2b = runner.invoke( main, ['--decode', '-o', 'out.dat', 'tmp.fasta']) assert result_b2f.exit_code == 0 assert result_f2b.exit_code == 0 # check result with open('out.dat') as fd: conv_content = fd.read() assert content == conv_content PK!Ho_`&,*bin2fasta-0.0.2.dist-info/entry_points.txtN+I/N.,()J3JK,.Ir3PK!HnHTUbin2fasta-0.0.2.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H%g"bin2fasta-0.0.2.dist-info/METADATATmo8_1]ZBQ,mY"`KU]c'ݮN"<3~;RG߹BZт0QzQ"Ӳ(0upr ʢ&_TMȕ9ml.yT|ҏ͝kHRL]"v=-g$`A qmÈsjX[_p;BQ+ordlТr T.Kמ. a] , ?uèq --<zGG\urÄkefe2#}%.m4kbR, A,sʩESq?l9ES%u@+if%nyaȏCyN}܄<<<̩GB86j1W AsM*^x6Mjx}9Jn. =1Bw)-QUX0d:K)аBϬ<*.ktW>"߸zYpo>s|-\XZpxO B-d @ϓ` N`.\\ >' Xr+m2̩ nH88w|> OO#Ai D;kr>X I  ~6K3|x$]Yl3WG~9 ZR֐lWT,/r6R>uQ%0*O` E;-S o?\ƅ3GXq+V5QZy8w[%f{d.or5c1,[loC|wf<-r-釕9_Q6pϕ?x y1 LØIj9+o}!j#0x7u<68ތ?y FfPK!HrI bin2fasta-0.0.2.dist-info/RECORD}ѷrP29[` P p%@OBxqqN'\aMUԏGI`6=!Æ,X~/cD1"+|ᱽ9m°ʹ|4Iozq'ט42ң2Qȳlv=1e?` . 5DAjV^'Fa\Dd D+2txa֏ER PzrfIyWhˆF_~nQ̿D>ggƞ4na|=e79aBX/؅y}O|+p:(xFז~?9S8eH6Chl6QbEZ8Io[zq8X+jNF ѰBz%lcjK3=Er+8\XM6[ˣtE^3wGRWt:}̩q8Fe/^z~z˅I#s7f T$W`HЮv\PK!D yy&bin2fasta/.converter.cpp.cppimporthashPK!6D!bin2fasta/.rendered.converter.cppPK!j*,,bin2fasta/__init__.pyPK!ibin2fasta/converter.cppPK!#bin2fasta/crypto.pyPK!AI/ / Ybin2fasta/main.pyPK!bin2fasta/tests/__init__.pyPK!]bin2fasta/tests/test_all.pyPK!Ho_`&,*bin2fasta-0.0.2.dist-info/entry_points.txtPK!HnHTUubin2fasta-0.0.2.dist-info/WHEELPK!H%g"bin2fasta-0.0.2.dist-info/METADATAPK!HrI bin2fasta-0.0.2.dist-info/RECORDPK