def test_open_ro__uncompressed(): handle = open_ro('tests/data/fasta_file.fasta') try: assert_equal(handle.read(), b'>This_is_FASTA!\nACGTN\n>This_is_ALSO_FASTA!\nCGTNA\n') finally: handle.close()
def read_msa(filename, read_meta = False): """Reads a MSA from the specified filename. The file may be uncompressed, gzipped or bzipped. See also 'parse_msa'.""" fasta_file = open_ro(filename) try: return parse_msa(iter(fasta_file), read_meta = read_meta) finally: fasta_file.close()
def from_file(cls, filename): """Reads a MSA from the specified filename. The file may be uncompressed, gzipped or bzipped. See also 'MSA.from_lines'.""" fasta_file = open_ro(filename) try: return MSA.from_lines(fasta_file) except MSAError, error: raise MSAError("%s in file %r" % (error, filename))
def test_open_ro__bz2(): handle = open_ro('tests/data/fasta_file.fasta.bz2') try: assert_equal(handle.read(), b'>This_is_BZ_FASTA!\nCGTNA\n' b'>This_is_ALSO_BZ_FASTA!\nACGTN\n') finally: handle.close()
def read_msa(filename, read_meta=False): """Reads a MSA from the specified filename. The file may be uncompressed, gzipped or bzipped. See also 'parse_msa'.""" fasta_file = open_ro(filename) try: return parse_msa(iter(fasta_file), read_meta=read_meta) finally: fasta_file.close()
def test_open_ro__gz(): handle = open_ro('tests/data/fasta_file.fasta.gz') try: assert_equal( handle.read(), b'>This_is_GZipped_FASTA!\nACGTN\n>This_is_ALSO_GZipped_FASTA!\nCGTNA\n' ) finally: handle.close()
def read_fasta(filename): """Reads an unindexed FASTA file, returning a sequence of tuples containing the name and sequence of each entry in the file. The FASTA file may be GZIP/BZ2 compressed.""" fasta_file = open_ro(filename) try: for record in parse_fasta(iter(fasta_file)): yield record finally: fasta_file.close()
def from_file(cls, filename): """Reads an unindexed FASTA file, returning a sequence of tuples containing the name and sequence of each entry in the file. The FASTA file may be GZIP/BZ2 compressed.""" fasta_file = open_ro(filename) try: for record in FASTA.from_lines(fasta_file): yield record finally: fasta_file.close()
def read_bed_file(filename): """Parses a (gzip/bzip2 compressed) BED file, and yields a sequence of records. Comments and empty lines are skipped.""" handle = None try: handle = fileutils.open_ro(filename) for record in text.parse_lines(handle, BEDRecord): yield record finally: if handle: handle.close()
def read_bed_file(filename): """Parses a (gzip/bzip2 compressed) BED file, and yields a sequence of records. Comments and empty lines are skipped.""" handle = None try: handle = fileutils.open_ro(filename) parser = pysam.asBed() for record in text.parse_lines(handle, parser): # Force evaluation of (lazily parsed) properties _ = record.start _ = record.end yield record finally: if handle: handle.close()
def test_open_ro__gz(): handle = open_ro('tests/data/fasta_file.fasta.gz') try: assert_equal(handle.read(), b'>This_is_GZipped_FASTA!\nACGTN\n>This_is_ALSO_GZipped_FASTA!\nCGTNA\n') finally: handle.close()