Example #1
0
 def __init__(self,probfile,nucleusRadius=5000.0,contactRange=1,level=None,record=-1):
     self.probmat = matrix.contactmatrix(probfile)
     self.nbead   = len(self.probmat)
     #setup log
     LEVELS={'debug':logging.DEBUG,'info':logging.INFO,'warning':logging.WARNING,'error':logging.ERROR,'critical':logging.CRITICAL}
     loglevel = LEVELS.get(level,logging.NOTSET)
     self.logger = logging.getLogger()
     self.logger.setLevel(loglevel)
     self._log_capture_string = StringIO()
     chhandler = logging.StreamHandler(self._log_capture_string)
     chhandler.setLevel(loglevel)
     self.logger.addHandler(chhandler)
     self.logger.setLevel(loglevel)
     #setup record
     self._record_step = record
     if record >= 100:
         self.record = []
     #CONST
     rscale               = 1.38                  # 20% occupancy
     self.nucleusRadius   = nucleusRadius         # nm
     cdensity             = 107.45                # bp/nm assuming 197 bp/nucleosomes and 6 nucleosome/11 nm
     kscale               = (0.75*15**2)**(1.0/3.0) # 3/4*r**2 where r=15nm
     self.contactRange    = contactRange          # surface to surface distance scale of (r1+r2)
                                                  # for which 2 beads are considered as contact 
     #get radius of each bead
     self.beadRadius = [rscale * kscale * ((index['end'] - index['start'])/cdensity) ** (1.0/3.0) for index in self.probmat.idx]
     #calculate the total volumn of DNA (diploid) and nucleus
     dnavol   = sum(4. * 3.1415/3. * np.array(self.beadRadius)**3) * 2 
     nucvol   = (4*3.1415/3)*self.nucleusRadius**3
     #And chromosome occupancy
     dnaocc   = dnavol / nucvol
     self.logger.debug('occupancy: %.2f with Rnuc %d'%(dnaocc,self.nucleusRadius))
     #diploid Rb; 2xtotal haploid beads 
     self.beadRadius = self.beadRadius + self.beadRadius
     # Chromosome territory apply
     self.genome = utils.genome(self.probmat.genome)
     cscale=1.0
     chrvol = nucvol * self.genome.info['length']/sum(self.genome.info['length'])/2
     self.chromRadius=cscale*((chrvol/4*3/3.1415)**(1./3.))
     
     #record starting time
     self.model      = IMP.Model()
     self.chain      = IMP.container.ListSingletonContainer(self.model)
     self.restraints = IMP.RestraintSet(self.model)
     #IMP.set_check_level(IMP.USAGE)
     IMP.set_check_level(IMP.NONE)
     IMP.set_log_level(IMP.SILENT)
     #setup nucleus envelope
     self.center = IMP.algebra.Vector3D(0,0,0)
Example #2
0
 def getContactMap(self,contactRange=1):
     """
     Return contact matrix format contact heatmap
     """
     from scipy.spatial import distance
     modelmap        = matrix.contactmatrix(self.nbead)
     modelmap.idx    = copy.deepcopy(self.idx)
     modelmap.genome = copy.deepcopy(self.genome)
     modelmap.resolution = None
     n    = self.nbead*2
     dcap = distance.cdist(self.radius,-self.radius)*(contactRange+1)
     cmap = np.zeros((n,n))
     for i in range(self.nstruct):
         if (i+1)*10.0 % self.nstruct == 0:
             print("%.3f %%"%((i+1)*100.0 / self.nstruct))
         #print(i)
         dist   = distance.cdist(self.coordinates[i],self.coordinates[i],'euclidean')
         submap = dist <= dcap
         cmap  += submap
         
     modelmap.matrix = cmap[:n/2,:n/2]+cmap[:n/2,n/2:]+cmap[n/2:,:n/2]+cmap[n/2:,n/2:]
     modelmap.matrix = modelmap.matrix/self.nstruct/2
     
     return modelmap
Example #3
0
 def getContactMap(self,contactRange=1):
     """
     Return contact matrix format contact heatmap
     """
     from scipy.spatial import distance
     modelmap        = matrix.contactmatrix(self.nbead)
     modelmap.idx    = copy.deepcopy(self.idx)
     modelmap.genome = copy.deepcopy(self.genome)
     modelmap.resolution = None
     n    = self.nbead*2
     dcap = distance.cdist(self.radius,-self.radius)*(contactRange+1)
     cmap = np.zeros((n,n))
     for i in range(self.nstruct):
         if (i+1)*10.0 % self.nstruct == 0:
             print("%.3f %%"%((i+1)*100.0 / self.nstruct))
         #print(i)
         dist   = distance.cdist(self.coordinates[i],self.coordinates[i],'euclidean')
         submap = dist <= dcap
         cmap  += submap
         
     modelmap.matrix = cmap[:n/2,:n/2]+cmap[:n/2,n/2:]+cmap[n/2:,:n/2]+cmap[n/2:,n/2:]
     modelmap.matrix = modelmap.matrix/self.nstruct/2
     
     return modelmap
Example #4
0
    def __init__(self,
                 probfile,
                 nucleusRadius=5000.0,
                 chromosomeOccupancy=0.2,
                 contactRange=1,
                 level=None):
        self.probmat = alabmatrix.contactmatrix(probfile)
        self.nbead = len(self.probmat)
        #setup log
        LEVELS = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL
        }
        loglevel = LEVELS.get(level, logging.NOTSET)
        self.logger = logging.getLogger()
        self.logger.setLevel(loglevel)
        self._log_capture_string = io.StringIO()
        chhandler = logging.StreamHandler(self._log_capture_string)
        chhandler.setLevel(loglevel)
        self.logger.addHandler(chhandler)
        self.logger.setLevel(loglevel)
        #CONST
        #rscale               = 1.38                  # 20% occupancy
        self.occupancy = chromosomeOccupancy  #chromosome occupancy in nucleus, defined as diploid_domain_total_volume/nuclear_volume

        self.nucleusRadius = nucleusRadius  # nm
        #cdensity             = 107.45                # bp/nm assuming 197 bp/nucleosomes and 6 nucleosome/11 nm
        #kscale               = (0.75*15**2)**(1.0/3.0) # 3/4*r**2 where r=15nm
        self.contactRange = contactRange  # surface to surface distance scale of (r1+r2)
        # for which 2 beads are considered as contact
        self.genome = alabutils.genome(self.probmat.genome)
        rho = self.occupancy * self.nucleusRadius**3 / (
            2 * sum(self.genome.info['length']))
        #get radius of each bead
        self.beadRadius = [(rho * (index['end'] - index['start']))**(1.0 / 3.0)
                           for index in self.probmat.idx]
        #self.beadRadius = [rscale * kscale * ((index['end'] - index['start'])/cdensity) ** (1.0/3.0) for index in self.probmat.idx]
        #calculate the total volumn of DNA (diploid) and nucleus
        dnavol = sum(4. * 3.1415 / 3. * np.array(self.beadRadius)**3) * 2
        nucvol = (4 * 3.1415 / 3) * self.nucleusRadius**3
        #And chromosome occupancy
        dnaocc = dnavol / nucvol
        self.logger.debug(u'Occupancy: %.2f with Rnuc %d' %
                          (dnaocc, self.nucleusRadius))
        #diploid Rb; 2xtotal haploid beads
        self.beadRadius = self.beadRadius + self.beadRadius
        # Chromosome territory apply
        #self.genome = alabutils.genome(self.probmat.genome)
        cscale = 1.0
        chrvol = nucvol * self.genome.info['length'] / sum(
            self.genome.info['length']) / 2
        self.chromRadius = cscale * ((chrvol / 4 * 3 / 3.1415)**(1. / 3.))

        #record starting time
        self.model = IMP.Model()
        self.chain = IMP.container.ListSingletonContainer(self.model)
        self.restraints = IMP.RestraintSet(self.model)
        #IMP.set_check_level(IMP.USAGE)
        IMP.set_check_level(IMP.NONE)
        IMP.set_log_level(IMP.SILENT)
        #setup nucleus envelope
        self.center = IMP.algebra.Vector3D(0, 0, 0)