def read_fasta(fasta, upper=True):
    """
    Taken from David Bernick but modified slightly to fit my purposes.

    using filename given in init, returns each included FastA record
    as 2 strings - header and sequence.
    whitespace is removed, no adjustment is made to sequence contents.
    The initial '>' is removed from the header.


    :param fasta: path to fasta file
    :param upper: boolean option to convert strings to uppercase
    :return: generator yielding header, sequence
    """
    assert fasta.endswith(".fa") or fasta.endswith(".fasta"), "Did not receive fasta file: {}".format(fasta)

    # initialize return containers

    def upperstring(line):
        return ''.join(line.rstrip().split()).upper()

    def lowerstring(line):
        return ''.join(line.rstrip().split())

    if upper:
        funct = upperstring
    else:
        funct = lowerstring

    sequence = ''
    with open(fasta, 'r+') as fasta_f:
        # skip to first fasta header
        line = fasta_f.readline()
        while not line.startswith('>'):
            line = fasta_f.readline()
        header = line[1:].rstrip()

        # header is saved, get the rest of the sequence
        # up until the next header is found
        # then yield the results and wait for the next call.
        # next call will resume at the yield point
        # which is where we have the next header
        for line in fasta_f:
            if line.startswith('>'):
                yield header, sequence
                # headerList.append(header)
                # sequenceList.append(sequence)
                header = line[1:].rstrip()
                sequence = ''
            else:
                sequence += funct(line)
        # final header and sequence will be seen with an end of file
        # with clause will terminate, so we do the final yield of the data

    yield header, sequence