def __ddEvent(self): if self.pool.size() == 0 or self.pool.weight() == 1: return sampleNode1, offset1, sampleNode2, offset2 = self.__drawSamples() c1 = sampleNode1.data c2 = sampleNode2.data # only deal with dead / dead contigs in this event if (c1.isDead() == False or c2.isDead() == False): return # only support single dead contig assert c1 is c2 # don't know what to do here if (offset1 == offset2): return self.pool.remove(sampleNode1) if c1 is not c2: self.pool.remove(sampleNode2) #forward means do not cut forward = random.random() > self.pgain # do the dcj dcjResult = dcj(c1, offset1, c2, offset2, forward) deadIdx = 0; if len(dcjResult) == 2 and \ random.randint(0, dcjResult[0].size + dcjResult[1].size) \ >= dcjResult[0].size: deadIdx = 1 dcjResult[deadIdx].setDead(True) if forward: self.ddSwapCount += 1 assert len(dcjResult) == 1 else: self.ddGainCount += 1 assert len(dcjResult) == 2 assert not dcjResult[0].isDead() or not dcjResult[1].isDead() # add the resulting contigs back to the pool for res in dcjResult: self.pool.insert(res, res.numBases())
def __ldEvent(self): if self.pool.size() == 0 or self.pool.weight() == 1: return # draw (and remove) two random adajcenies and their #contigs from the pool (only if they are not dead) sampleNode1, offset1, sampleNode2, offset2 = self.__drawSamples() c1 = sampleNode1.data c2 = sampleNode2.data # only deal with live / dead contigs in this event if (c1.isDead() == c2.isDead()): return self.pool.remove(sampleNode1) if c1 is not c2: self.pool.remove(sampleNode2) # make sure c1 is alive and c2 is dead if c1.isDead(): c1, c2 = c2, c1 offset1, offset2 = offset2, offset1 # do the dcj dcjResult = dcj(c1, offset1, c2, offset2, random.randint(0, 1) == 1) deadIdx = 0; if len(dcjResult) == 2 and \ random.randint(0, dcjResult[0].size + dcjResult[1].size) >= \ dcjResult[0].size: deadIdx = 1 dcjResult[deadIdx].setDead(True) if len(dcjResult) == 1: self.ldLossCount += 1 else: self.ldSwapCount += 1 # add the resulting contigs back to the pool deadCount = 0 for res in dcjResult: if res.isDead(): deadCount += 1 self.pool.insert(res, res.numBases()) assert deadCount == 1
def __llGain(self, c1, c2, offset1, offset2): # correct "not composite check below" if c1.isCircular() or (offset1 != 0 and offset1 != c1.size - 1): forward = self.fg > random.random() if forward: self.fgCount += 1 dcjResult = dcj(c1, offset1, c2, offset2, forward) if c1.isCircular(): assert len(dcjResult) == 1 and dcjResult[0].isLinear() else: assert len(dcjResult) == 2 and dcjResult[0].isLinear() \ and dcjResult[1].isLinear() # add the resulting contigs back to the pool for res in dcjResult: self.pool.insert(res, res.numBases()) return self.pool.insert(c1, c1.numBases()) if c2 is not c1: self.pool.insert(c2, c2.numBases())
def __llEvent(self): if self.pool.size() == 0 or self.pool.weight() == 1: return # draw (and remove) two random adajcenies and their #contigs from the pool (only if they are not dead) sampleNode1, offset1, sampleNode2, offset2 = self.__drawSamples() c1 = sampleNode1.data c2 = sampleNode2.data # don't deal with dead contigs in this event if c1.isDead() == True or c2.isDead() == True: return self.pool.remove(sampleNode1) if c1 is not c2: self.pool.remove(sampleNode2) # case 1) gain of telomere if sampleNode1 is sampleNode2 and offset1 == offset2: return self.__llGain(c1, c2, offset1, offset2) # case 2) loss of telomere elif c1.isLinear() and c2.isLinear() and \ (offset1 == 0 or offset1 == c1.size - 1) and \ (offset2 == 0 or offset2 == c2.size - 1): return self.__llLoss(c1, c2, offset1, offset2) # case 3) no gain or loss self.llCount += 1 forward = random.randint(0, 1) == 1 # do the dcj dcjResult = dcj(c1, offset1, c2, offset2, forward) # add the resulting contigs back to the pool for res in dcjResult: self.pool.insert(res, res.numBases())
def __llLoss(self, c1, c2, offset1, offset2): if c1 is c2: forward = self.fl / 4.0 > random.random() else: forward = self.fl / 2.0 > random.random() if forward: c1 = c1.circularize() if c1 is not c2: c2 = c2.circularize() dcjResult = dcj(c1, offset1, c2, offset2, forward) self.flCount += 1 assert len(dcjResult) == 1 if c1 is not c2: assert dcjResult[0].isLinear() else: assert dcjResult[0].isCircular() # add the resulting contigs back to the pool for res in dcjResult: self.pool.insert(res, res.numBases()) else: self.pool.insert(c1, c1.numBases()) if c2 is not c1: self.pool.insert(c2, c2.numBases())