def parse_bbmap_log_file(log_file):
    """
    parses a bbmap log file (paired, single end or both (bbrwap))
    returns number of used and mapped reads.
    This is the sum or se + R1 + R2 reads
    """
    N_results = 0

    mapped = 0
    used = 0

    with open(log_file) as f:
        for line in f:
            if line.startswith("mapped:"):
                # mapped:                  85.4123%        27804399        85.4133%         2774727540
                try:
                    mapped_reads = line.strip().split(":")[1].split()[1]
                except ValueError as e:
                    raise Exception(f"Error parsing line:\n{line}\n") from e
                mapped += int(mapped_reads)

            elif line.startswith("Reads Used:"):
                # Reads Used:             65106274        (6496839447 bases)

                try:
                    used_reads = line.strip().split(":")[1].split()[0]
                except ValueError as e:
                    raise Exception(f"Error parsing line:\n{line}\n") from e

                used += int(used_reads)

            elif "Results" in line:
                N_results += 1
                assert N_results <= 2, "you have more than one library in this log file"

        if used == 0:
            raise IOError(
                f"I couldn't parse the log file, probably the job didn't finish properly: {log_file}"
            )

        assert (
            used >= mapped
        ), "something is wrong, you have more than 100% mapped reads?"

        return used, mapped