Exemple #1
0
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()
Exemple #2
0
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()
Exemple #3
0
 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()
Exemple #5
0
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()
Exemple #6
0
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()
Exemple #7
0
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()
Exemple #8
0
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()
Exemple #9
0
 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()
Exemple #10
0
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()
Exemple #11
0
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()
Exemple #12
0
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()
Exemple #13
0
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()
Exemple #14
0
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()
Exemple #15
0
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()