def parse_cov(cov_table, scaffold2genome):
    size   = {}
    mapped = {}
    for line in open(cov_table):
        line = line.strip().split('\t')
        if line[0].startswith('
            samples = line[1:]
            samples = [i.rsplit('/', 1)[-1].split('.', 1)[0] for i in samples]
            continue
        scaffold, length = line[0].split(': ')
        length = float(length)
        covs  = [float(i) for i in line[1:]]
        bases = [c * length for c in covs]
        if scaffold not in scaffold2genome:
            continue
        genome = scaffold2genome[scaffold]
        if genome not in size:
            size[genome] = 0
            mapped[genome] = {sample:0 for sample in samples}
        size[genome] += length
        for sample, count in zip(samples, bases):
            mapped[genome][sample] += count
    coverage = {'genome':[], 'genome size (bp)':[], 'sample':[], 'coverage':[]}
    for genome, length in size.items():
        for sample in samples:
            cov = mapped[genome][sample] / length
            coverage['genome'].append(genome)
            coverage['genome size (bp)'].append(length)
            coverage['sample'].append(sample)
            coverage['coverage'].append(cov)
    return pd.DataFrame(coverage)