def build_binKeeper (self,chromLenDict={},binsize=200):
        """Use this function to return a dictionary of BinKeeper
        objects.

        chromLenDict is a dictionary for chromosome length like

        {'chr1':100000,'chr2':200000}

        bin is in bps. for detail, check BinKeeper.
        """
        data = {}
        chrom = "Unknown"
        pos_fixed = 0
        for i in self.fhd:
            if i.startswith("track"):
                continue
            elif i.startswith("browse"):
                continue
            elif i.startswith("#"):
                continue
            elif i.startswith("variableStep"): # define line
                pos_fixed = 0
                chromi = i.rfind("chrom=")  # where the 'chrom=' is
                spani = i.rfind("span=")   # where the 'span=' is
                if chromi != -1:
                    chrom = i[chromi+6:].strip().split()[0]
                else:
                    chrom = "Unknown"
                if spani != -1:
                    span = int(i[spani+5:].strip().split()[0])
                else:
                    span = 0

                chrlength = chromLenDict.setdefault(chrom,250000000) + 10000000
                data.setdefault(chrom,BinKeeperI(binsize=binsize,chromosomesize=chrlength))
                add = data[chrom].add

            elif i.startswith("fixedStep"):
                chromi = i.rfind("chrom=")  # where the 'chrom=' is
                starti = i.rfind("start=")  # where the 'chrom=' is
                stepi = i.rfind("step=")  # where the 'chrom=' is
                spani = i.rfind("span=")   # where the 'span=' is
                if chromi != -1:
                    chrom = i[chromi+6:].strip().split()[0]
                else:
                    raise Exception("fixedStep line must define chrom=XX")
                if spani != -1:
                    span = int(i[spani+5:].strip().split()[0])
                else:
                    span = 0
                if starti != -1:
                    pos_fixed = int(i[starti+6:].strip().split()[0])
                    if pos_fixed < 1:
                        raise Exception("fixedStep start must be bigger than 0!")
                else:
                    raise Exception("fixedStep line must define start=XX")
                if stepi != -1:
                    step = int(i[stepi+5:].strip().split()[0])
                else:
                    raise Exception("fixedStep line must define step=XX!")
                chrlength = chromLenDict.setdefault(chrom,250000000) + 10000000
                data.setdefault(chrom,BinKeeperI(binsize=binsize,chromosomesize=chrlength))
                
                add = data[chrom].add

            else:                       # read data value
                if pos_fixed:           # fixedStep
                    value = i.strip()
                    add(int(pos_fixed),float(value))
                    pos_fixed += step
                else:                   # variableStep
                    try:
                        (pos,value) = i.split()
                    except __HOLE__:
                        print i,pos_fixed
                    add(int(pos),float(value))

        self.fhd.seek(0)
        return data

#     def build_DBBinKeeper (self,dirname="NA",templatedb=None):
#         """Use this function to build DBBinKeepers for every
#         chromosome under a given directory.

#         Parameters:
#         dirname : where we store the DBBinKeeper files
#         templatedb : if not None, copy the templatedb file
#         instead of initialize a db file.

#         """
#         data= {}
#         chrom = "Unknown"
#         if not os.path.exists(dirname):
#             os.mkdir(dirname)
#         chromdbfile = None
#         dbbk = None
#         for i in self.fhd:
#             if i.startswith("track"):
#                 continue
#             elif i.startswith("browse"):
#                 continue
#             elif i.startswith("variableStep"):
#                 ci = i.rfind("chrom=")  # where the 'chrom=' is
#                 si = i.rfind("span=")   # where the 'span=' is
#                 if ci != -1:
#                     chrom = i[i.rfind("chrom=")+6:].strip().split()[0]
#                 else:
#                     chrom = "Unknown"
#                 if si != -1:
#                     span = int(i[i.rfind("span=")+5:].strip().split()[0])
#                 else:
#                     span = 0
#                 if dbbk:
#                     dbbk.conn.commit()
#                 chromdbfile = os.path.join(dirname,chrom+".db")
#                 data[chrom] = chromdbfile

#                 if templatedb:
#                     shutil.copy(templatedb,chromdbfile)
#                     dbbk = DBBinKeeperI(chromdbfile,chromosome=chrom,bin=8,chromosomesize=250000000)
#                 else:
#                     dbbk = DBBinKeeperI(chromdbfile,chromosome=chrom,bin=8,chromosomesize=250000000)                    
#                     dbbk.init_tables()
#                 add = dbbk.add
#             else:
#                 (pos,value) = i.split()
#                 add(int(pos),float(value))
#         self.fhd.seek(0)
#         if dbbk:
#             dbbk.conn.commit()
#         return data
dataset/ETHPy150Open taoliu/taolib/CoreLib/Parser/WiggleIO.py/WiggleIO.build_binKeeper