def __init__(self, gfn, bedfile=None):
        self.chrlen = {} # length of each chromosome
        self.chrmap = [] # used for picking chromosomes
        self.ref    = pysam.Fastafile(gfn)

        bp = 0
        bins = 100000

        with open(gfn + '.fai', 'r') as g:
            for line in g:
                chrom, length = line.strip().split()[:2]
                self.chrlen[chrom] = int(length)
                bp += int(length)

        for chrom, length in self.chrlen.iteritems():
            self.chrmap += [chrom] * int(float(length) / float(bp) * bins)

        self.bed = []
        self.bedfile = None

        if bedfile is not None:
            self.bedfile = bedfile
            with open(self.bedfile, 'r') as bed:
                for line in bed:
                    chrom, start, end = line.strip().split()[:3]
                    start = int(start)
                    end   = int(end)
                    assert start < end, "start >= end in BED line: " + line.strip()
                    self.bed.append((chrom, start, end))
gfn = genome file name
dataset/ETHPy150Open adamewing/bamsurgeon/scripts/randomsites.py/Genome.__init__