def filter_stats(tup):
    """
    Filter reads based upon metrics
    :param tup: contains a line from the stats file and the score ranges to filter by
    :return: line if passing, none otherwise
    """
    line, score_ranges = tup
    read_id, aln_scores, num_alns, mapq_scores, sramm_scores = line.strip().split('\t')
    map_score, uniq_rep_score, unmap_score = [float(v) for v in sramm_scores.split(',')]
    map_range, uniq_rep_range, unmap_range, num_alns_range = score_ranges
    # Tempted to use all() here, but might be more complex looking since ranges are dynamic
    if map_range[0] <= map_score <= map_range[1] and \
            uniq_rep_range[0] <= uniq_rep_score <= uniq_rep_range[1] and \
            unmap_range[0] <= unmap_score <= unmap_range[1] and \
            num_alns_range[0] <= int(num_alns) <= num_alns_range[1]:
        return line
    else:
        return None