from typing import OrderedDict
import gzip


def parse_genomecov(genomecov_gzfile):
    """Parse gzipped bedtools genomecov output"""
    genomecov = OrderedDict()
    with gzip.open(genomecov_gzfile) as fh:
        for line in fh:
            sq, pos, cov = line.decode().rstrip().split("\t")
            pos = int(pos)-1
            cov = int(float(cov))# float for support of scientific notation
            if sq not in genomecov:
                genomecov[sq] = OrderedDict()
            genomecov[sq][pos] = cov
    return genomecov