def read_table(table, filename): with open(filename) as table_file: for record in parse_padded_table(table_file): key = (record["Name"], record["Sample"], record["Library"], record["Contig"]) if "*" in key: continue subtable = get_in(table, key, {"Size": int(record["Size"])}) assert int(subtable["Size"]) == int(record["Size"]) for field in ("Hits", "SE", "PE_1", "PE_2", "Collapsed", "M", "I", "D"): subtable[field] = subtable.get(field, 0) + int( record.get(field, 0)) set_in(table, key, subtable)
def _read_max_depths(filename, prefix, sample): if filename in _DEPTHS_CACHE: return _DEPTHS_CACHE[filename] max_depth = None try: with open(filename) as handle: for row in parse_padded_table(handle): if row["Name"] == sample and row["Sample"] == "*" and row["Library"] == "*" and row["Contig"] == "*": max_depth = row["MaxDepth"] break else: raise MakefileError("Could not find MaxDepth in " "depth-histogram: %r" % (filename,)) except (OSError, IOError), error: raise MakefileError("Error reading depth-histogram (%s): %s" % (filename, error))
def read_table(table, filename): with open(filename) as table_file: for record in parse_padded_table(table_file): key = (record["Name"], record["Sample"], record["Library"], record["Contig"]) if "*" in key: continue subtable = get_in(table, key) if subtable is None: subtable = dict(READGROUP_TEMPLATE) subtable["Size"] = int(record["Size"]) set_in(table, key, subtable) assert int(subtable["Size"]) == int(record["Size"]) for key in READGROUP_TEMPLATE: if key != "Size": subtable[key] += int(record.get(key, 0))
def _read_max_depths(filename, prefix, sample): if filename in _DEPTHS_CACHE: return _DEPTHS_CACHE[filename] max_depth = None try: with open(filename) as handle: for row in parse_padded_table(handle): if row["Name"] == sample and \ row["Sample"] == "*" and \ row["Library"] == "*" and \ row["Contig"] == "*": max_depth = row["MaxDepth"] break else: raise MakefileError("Could not find MaxDepth in " "depth-histogram: %r" % (filename, )) except (OSError, IOError), error: raise MakefileError("Error reading depth-histogram (%s): %s" % (filename, error))
def _parse_padded_table(*args, **kwargs): return list(parse_padded_table(*args, **kwargs))