def read_map_iterator(infile):
    for line in infile.readlines():
        data = line[:-1].split("\t")
        seq_id = data[0]
        data = data[1].split("|")

        # The data follow a hierarchy from more specific to
        # more general taxonomic classes so can iteratively sort them out
        data = [x.split("__")[1] for x in data]
        if len(data) == 7:
            kingdom, phylum, c_lass, order, family, genus, species = data[
                0], data[1], data[2], data[3], data[4], data[5], data[6]
        elif len(data) == 6:
            kingdom, phylum, c_lass, order, family, genus, species = data[
                0], data[1], data[2], data[3], data[4], data[5], "unclassified"
        elif len(data) == 5:
            kingdom, phylum, c_lass, order, family, genus, species = data[0], data[
                1], data[2], data[3], data[4], "unclassified", "unclassified"
        elif len(data) == 4:
            kingdom, phylum, c_lass, order, family, genus, species = data[0], data[
                1], data[2], data[3], "unclassified", "unclassified", "unclassified"
        elif len(data) == 3:
            kingdom, phylum, c_lass, order, family, genus, species = data[0], data[
                1], data[2], "unclassified", "unclassified", "unclassified", "unclassified"
        elif len(data) == 2:
            kingdom, phylum, c_lass, order, family, genus, species = data[0], data[
                1], "unclassified", "unclassified", "unclassified", "unclassified", "unclassified"
        elif len(data) < 2:
            raise ValueError("could not assign taxonomy at the phylum level")
        yield ReadMap().read(seq_id, kingdom, phylum, c_lass, order, family, genus, species)

##############################
# count by taxonomic group
##############################
iterate over read_map file
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Metaphlan.py/read_map_iterator