def meltingTemperature(seq, concentration=1.0e-9): GAS_CONSTANT = 0.001987 strand = Strand(sequence=seq) energy20 = float(mfe([strand.sequence, strand.C.sequence ], material='dna', T=20.0)[0][1]) + GAS_CONSTANT * (273.15 + 20) * np.log(55.5) energy30 = float(mfe([strand.sequence, strand.C.sequence ], material='dna', T=30.0)[0][1]) + GAS_CONSTANT * (273.15 + 30) * np.log(55.5) dS = (energy20 - energy30) / 10.0 # kcal/ K mol dH = energy30 + (273.15 + 30.0) * dS # kcal/mol return (dH / (dS + GAS_CONSTANT * np.log(concentration / 4.0)))
def Gibbs(probes, targets, send_end): G_list = np.zeros((np.shape(probes)[0], np.shape(targets)[0])) for p in range(np.shape(probes)[0]): for t in range(np.shape(targets)[0]): #print(p,t) s1 = probes[p, :] s2 = targets[t, :] Seq1, Seq2 = translate(s1, s2) rna_seqs = [Seq1[0], Seq2[0]] G = float( nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False)[0][1]) #print(nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False)) G_list[p, t] = G #print(G_list) send_end.send(G_list) return G_list
def toeholds(seq, T=GLOBAL_TEMPERATURE, material="dna"): result = nupack.mfe([seq], T=T, material=material) struct = result[0][0] n = len(struct) try: toe5len = struct.index('(') toe3len = struct[::-1].index(')') except ValueError: toe5len = n toe3len = n # print " %s = %s , toes %d and %d" % (seq, struct, toe5len, toe3len) return (toe5len, toe3len)
def stemsize(seq, T=GLOBAL_TEMPERATURE, material='dna'): result = nupack.mfe([seq], T=T, material=material) struct = result[0][0] n = len(struct) try: stemstart5 = struct.index('(') stemlen5 = struct[stemstart5:].index('.') revstruct = struct[::-1] stemstart3 = revstruct.index(')') stemlen3 = revstruct[stemstart3:].index('.') stemlen = min(stemlen5, stemlen3) except ValueError: stemlen = 0 return stemlen
def Gibbs(probes, send_end): G_list = np.zeros((np.shape(probes)[0],1)) for p in range(np.shape(probes)[0]): s1 = probes[p,:] Seq = translate(s1) rna_seqs = [Seq[0]] G = float(nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False)[0][1]) #print(nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False)) G_list[p,0] = G #print(G_list) send_end.send(G_list) #print(G_list) return G_list
def _get_fold(self, sequence, temperature, ligand=None, constraint=None): nupack_mfe = nupack.mfe([self._change_cuts(sequence)], material='rna', pseudo=True, T=temperature) # if str, 0, no error pattern = re.compile('(\[\(\')|(\',)|(\'\)\])') temp_mfe = pattern.sub('', "%s" % nupack_mfe) temp_mfe = temp_mfe.replace("'", "") mfe_list = temp_mfe.split() mfe_struct = mfe_list[0] mfe_energy = float(mfe_list[1]) return mfe_struct, mfe_energy
def probes(Targets, nEpochs, procNum, TargetsConc, ProbeConc, interval, Temp, popSize, nElite, pointmutProb, shiftmutProb, TargetCell): start_time = time.time() Probes = np.random.choice(4, (popSize, np.shape(Targets)[1])) + 1 theprobes = np.zeros((0, np.shape(Targets)[1])) #Target들의 self secondary structure 에너지 계산. Ghp_target = np.zeros((1, np.shape(Targets)[0])) for i in range(np.shape(Targets)[0]): Seq1 = translate(Targets[i, :]) rna_seqs = [Seq1[0]] G = float( nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False)[0][1]) Ghp_target[0, i] = G Khpt = Keq.Keq(Ghp_target, Temp) Khp_target = Khpt.keq() #Genetic algorithm 시작. iter = 0 while iter < nEpochs: #Probe들의 self secondary structure 에너지 계산. procs = [] pipe_list = [] Ghp_probe = np.zeros((0, 1)) for i in range(procNum): recv_end, send_end = multiprocessing.Pipe(False) Probe_part = Probes[int(i * (popSize / procNum)):int((i + 1) * (popSize / procNum)), :] proc = multiprocessing.Process(target=gibbs_single.Gibbs, args=(Probe_part, send_end)) procs.append(proc) pipe_list.append(recv_end) proc.start() for proc in procs: proc.join() for x in pipe_list: result = np.array(x.recv()) Ghp_probe = np.concatenate((Ghp_probe, result), axis=0) Khp = Keq.Keq(Ghp_probe, Temp) Khp_probe = Khp.keq() #Target과 Probe 사이의 결합 에너지 계산. procs = [] pipe_list = [] G_TargetProbe = np.zeros((0, np.shape(Targets)[0])) for i in range(procNum): recv_end, send_end = multiprocessing.Pipe(False) Probe_part = Probes[int(i * (popSize / procNum)):int((i + 1) * (popSize / procNum)), :] proc = multiprocessing.Process(target=gibbs_multi.Gibbs, args=(Probe_part, Targets, send_end)) procs.append(proc) pipe_list.append(recv_end) proc.start() for proc in procs: proc.join() for x in pipe_list: result = np.array(x.recv()) G_TargetProbe = np.concatenate((G_TargetProbe, result), axis=0) K = Keq.Keq(G_TargetProbe, Temp) Keqs = K.keq() #print(Gibbs_list) #각 세포들의 hybridization yield 계산. Cp_list, Ct_list, Ct_hp, Cp_hp = cpt.Conc(Keqs, Khp_target, Khp_probe, TargetsConc, ProbeConc) Cpts = np.zeros((np.shape(Probes)[0], np.shape(TargetsConc)[0])) for cell in range(np.shape(TargetsConc)[0]): for p in range(np.shape(Probes)[0]): Cpts[p, cell] = ProbeConc - Cp_list[p, cell] - Cp_hp[p, cell] #TargetCell의 Cpt 값의 상대 우위 계산. fitness = np.zeros((np.shape(Probes)[0], 1)) for p in range(np.shape(Probes)[0]): TargetCpt = Cpts[p, int(TargetCell)] RestCpt = np.delete(Cpts[p, :], TargetCell).max() #print Cpts[p, :], np.delete(Cpts[p, :], TargetCell), TargetCpt, RestCpt fitness[p, 0] = TargetCpt - RestCpt #print(fitness[p,0], Cpts[p,int(TargetCell)].max(), TargetCpt, RestCpt) #print('f', fitness) theprobe = Probes[np.where(fitness == fitness.max())[0], :] # print(theprobe[0,:]) elites = elite.elitism(nElite, Probes, fitness) #print(elites) #print np.shape(elites), np.shape(Probes) leftovers = roulette.roulette(elites, Probes, fitness) #print np.shape(Probes), np.shape(leftovers) newPopulation = crossover.cross(leftovers, popSize - np.shape(elites)[0]) newPopulation = pointmut.pointmut(newPopulation, pointmutProb) newPopulation = shiftmut.shiftmut(newPopulation, shiftmutProb) Probes = np.concatenate((elites, newPopulation), axis=0) #print(Ghp_probe) if iter % interval == 0: print 'Target =', str(TargetCell), '/ Iter =', iter print "End Time =", time.time() - start_time, 'Fitness =', round( fitness.max() / ProbeConc * 100, 3), "%" for t in range(np.shape(Targets)[0]): Seq1, Seq2 = translate2(theprobe[0], Targets[t, :]) rna_seqs = [Seq1[0], Seq2[0]] print( "MFE =", str(t), nupack.mfe(rna_seqs, ordering=None, material='rna', dangles='some', T=37, multi=0, pseudo=False, sodium=1.0, magnesium=0.0, degenerate=False), Cpts[np.where(fitness == fitness.max())[0], t][0]) theprobes = np.concatenate((theprobes, [theprobe[0]]), axis=0) #print(theprobes) #print(Cpts[np.where(fitness == fitness.max())[0], :]) iter += 1 return theprobes, fitness.max() / ProbeConc * 100