How to use the pyfaidx.fasta function in pyfaidx

To help you get started, we’ve selected a few pyfaidx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdshw5 / pyfaidx / pyfaidx.py View on Github external
start = start - 1 ## make coordinates [0,1)
        offset = entry.get('offset')
        rlen = entry.get('rlen')
        line_len = entry.get('lenc')
        line_blen = entry.get('lenb')
        seq_len = end - start
        newlines_total = int(rlen / line_len * (line_blen - line_len))
        newlines_before = int((start - 1) / line_len * (line_blen - line_len)) if start > 0 else 0
        newlines_to_end = int(end / line_len * (line_blen - line_len))
        newlines_inside = newlines_to_end - newlines_before
        seq_blen = newlines_inside + seq_len
        bstart = offset + newlines_before + start
        bend = offset + newlines_total + rlen
        self.m.seek(bstart)
        if seq_blen < 0:
            return fasta(rname, '')
        if bstart + seq_blen <= bend:
            s = self.m.read(seq_blen)
        else:
            s = self.m.read(bend - bstart)
        return fasta(rname, s.replace('\n',''))
github mdshw5 / pyfaidx / pyfaidx.py View on Github external
seq_len = end - start
        newlines_total = int(rlen / line_len * (line_blen - line_len))
        newlines_before = int((start - 1) / line_len * (line_blen - line_len)) if start > 0 else 0
        newlines_to_end = int(end / line_len * (line_blen - line_len))
        newlines_inside = newlines_to_end - newlines_before
        seq_blen = newlines_inside + seq_len
        bstart = offset + newlines_before + start
        bend = offset + newlines_total + rlen
        self.m.seek(bstart)
        if seq_blen < 0:
            return fasta(rname, '')
        if bstart + seq_blen <= bend:
            s = self.m.read(seq_blen)
        else:
            s = self.m.read(bend - bstart)
        return fasta(rname, s.replace('\n',''))
github mdshw5 / pyfaidx / pyfaidx.py View on Github external
def __iter__(self):
        """ 
        Return tuple (name, sequence).
        """
        seq = ''
        for line in self.file:
            if line[0] == '>':
                if seq != '':
                    yield fasta(name, seq.upper())
                    seq = ''
                name = line.rstrip()
            else:
                seq = seq + line.rstrip()
                
        yield fasta(name, seq.upper())