@staticmethod
def read_fasta(fasta, delim=None, as_id=0):
    """read from fasta fasta file 'fasta'
        and split sequence id at 'delim' (if set)

        example:

        >idpart1|idpart2

        ATGTGA

        and 'delim="|"' returns ("idpart1", "ATGTGA")
        """
    name = ''
    fasta = open(fasta, 'r')
    while True:
        line = name or fasta.readline()
        if not line:
            break
        seq = []
        while True:
            name = fasta.readline()
            name = name.rstrip()
            if not name or name.startswith('>'):
                break
            else:
                seq.append(name)
        joined_seq = ''.join(seq)
        line = line[1:]
        if delim:
            line = line.split(delim)[as_id]
        yield line.rstrip(), joined_seq.rstrip()
    fasta.close()
