def read(self,fn=''):
        """Read a bed file
        
        Parameters:
        1. fn: file name
        """
        
        #open the bed file
        f=open(fn,'r')
        self.__name__=fn
        
        standard_chroms={'I':'chrI','II':'chrII','III':'chrIII','IV':'chrIV','V':'chrV','M':'chrM','X':'chrX'}
        types=self.__types
        type_coversion={'int':'l','float':'d'}
        self.bed={}
        chrom=''
        for line in f.xreadlines():
            if re.search(r'track',line) or line=='' or line=='\n' or line[0]=='#':continue
            l=line.strip().split()
            
            # when new chromosome met, initialize the dictionary 
#            try:
#                newchrom=standard_chroms[l[0]]
#            except KeyError:
#                newchrom=l[0]
#            if chrom!=newchrom:

            try:
                chrom=standard_chroms[l[0]]
            except __HOLE__:
                chrom=l[0]
            if not self.bed.has_key(chrom):
                self.bed[chrom]={}
                for i in range(1,len(l)):
                    if types[i]=='int':        # when column is integer
                        self.bed[chrom][self.__columns[i]]=array('l',[])
                    elif types[i]=='float':    # when column is float
                        self.bed[chrom][self.__columns[i]]=array('d',[])
                    elif types[i]=='str'or types[i]=='list':       # when string or blob type (comma separated string)
                        self.bed[chrom][self.__columns[i]]=[]
                        
            for i in range(1,len(l)):
                if types[i]=='int':
                    element=int(l[i])
                elif types[i]=='float':
                    element=float(l[i])
                elif types[i]=='str':
                    element=l[i]
                elif types[i]=='list':
                    element=[int(e) for e in l[i].rstrip(',').split(',')]
                self.bed[chrom][self.__columns[i]].append(element)
        
        f.close()
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/Bed.read