def doFirstStepMode(seq, concentrations, T=20.0, numOfRuns=500): # track time for each kind of simulation, using time.time(), which has units of second # do one "first step mode" run, get k1, k2, etc, from which z_crit and k_eff(z) can be computed myMultistrand = first_step_simulation(seq, numOfRuns, T=T) myRates = myMultistrand.results # print myRates.dataset time2 = time.time() print str(myRates) FSResult = list() for z in concentrations: kEff = myRates.kEff(z) myBootstrap = Bootstrap(myRates, N=BOOTSTRAP_RESAMPLE, concentration=z, computek1=False) low, high = myBootstrap.ninetyFivePercentiles() logStd = myBootstrap.logStd() print "keff = %g /M/s at %s" % (kEff, concentration_string(z)) myResult = (np.log10(kEff), np.log10(low), np.log10(high), logStd) FSResult.append(myResult) print # call NUPACK for pfunc dG of the reaction, calculate krev based on keff print "Calculating dissociate rate constant based on NUPACK partition function energies and first step mode k_eff..." dG_top = nupack.pfunc([seq], T=T) dG_bot = nupack.pfunc([Strand(sequence=seq).C.sequence], T=T) dG_duplex = nupack.pfunc([seq, Strand(sequence=seq).C.sequence], T=T) RT = 1.987e-3 * (273.15 + T) time3 = time.time() time_nupack = time3 - time2 krev_nupack = kEff * np.exp((dG_duplex - dG_top - dG_bot) / RT) print "krev = %g /s (%g seconds)" % (krev_nupack, time_nupack) times = list() for i in concentrations: myTime = (np.log10(myMultistrand.runTime), 0.0, 0.0) times.append(myTime) return FSResult, times
def comparison(): # for seq, seqC in zip( ["ACTGAAGATGACGA"], ["TCGTCATCTTCAGT"] ): seq = "ATCCCAATCAACACCTTTCCTA" seqC = "TAGGAAAGGTGTTGATTGGGAT" temp = 25.0 + 273.15 + 40 file.write(str(seq) + " ") file.write(str("%0.3g" % (temp)) + " ") # FD: just leaving this linking for now, meaning the simulation # settings will default to whatever is default for these functions predictedA = computeAnneal(seq, temp, 1.0) predictedD = computeDissociation(seq, temp) dotparen = "(" * len(seq) + "+" + ")" * len(seq) dG = pfunc([seq, seqC], [1, 2], T=(temp - 273.15), material="dna") print(str(dG)) kMinus = predictedA.k1() * math.exp(dG / (GAS_CONSTANT_R * temp)) file.write(str("%0.3g" % np.log10(kMinus)) + " ") file.write(str("%0.3g" % np.log10(predictedD.k1())) + " ") diff = np.abs(np.log10(kMinus) - np.log10(predictedD.k1())) file.write(str("%0.3g" % diff) + " ") file.write("\n") file.flush()
def _get_pf_fold(self, sequence, temperature, ligand=None, constraint=None): # Nupack doesn't return ensemble structure return re.sub('[^\+]', '?', self._change_cuts(sequence)), nupack.pfunc( [sequence], material='rna', pseudo=True, T=temperature)
def computeDissociationAndWriteToCL(strand_seq, doBootstrap): result = first_step_simulation(strand_seq, 1200, material="DNA") seq = strand_seq seqC = seqComplement(seq) temp = 273.15 + 25.0 # this is just for NUPACK calls, setting temperature is not yet implemented properly. ## We only import nupack bindings here because it will print an welcom message from nupack import pfunc dG = pfunc([seq, seqC], [1, 2], T=(temp - 273.15), material="dna") print("Using dG = " + "{:.2e}".format(dG) + " kcal/mol, and k+ = " + "{:.2e}".format(result.k1()) + " /M /s to compute the dissociation rate.") kMinus = result.k1() * math.exp(dG / (GAS_CONSTANT_R * temp)) print("The dissociation rate of ", strand_seq, " and the reverse complement is ", "{:.2e}".format(kMinus), " /M /s \n", sep="") # check for two-stateness # result.testForTwoStateness(100e-9) if (doBootstrap): low, high = result.doBootstrap(NIn=1200) kMinusLow = low * math.exp(dG / (GAS_CONSTANT_R * temp)) kMinusHigh = high * math.exp(dG / (GAS_CONSTANT_R * temp)) print("Estimated 95% confidence interval: [", "{:.2e}".format(kMinusLow), ",", "{:.2e}".format(kMinusHigh), "] ", sep="")
def compare_hybridization(seq, concentrations, T=25, material="DNA"): # track time for each kind of simulation, using time.time(), which has units of seconds time1 = time.time() # do one "first step mode" run, get k1, k2, etc, from which z_crit and k_eff(z) can be computed k1, k2, k1prime, k2prime = first_step_simulation(seq, 10000, T=T, material=material) time2 = time.time() time1step_for = time2 - time1 print "k1 = %g /M/s, k2 = %g /s, k1prime = %g /M/s, k2prime = %g /s (%g seconds)" % ( k1, k2, k1prime, k2prime, time1step_for) zcrit = k2 * k2prime / ( k1 * k2prime + k1prime * k2 ) # this is the critical concentration at which k_eff = k1/2 print "zcrit = %s" % (concentration_string(zcrit)) for z in concentrations: keff_1s = 1 / (1 / k1 + z / k2 + (k1prime / k1) * (z / k2prime)) # first-step mode predictions print "keff = %g /M/s at %s" % (keff_1s, concentration_string(z)) print # call NUPACK for pfunc dG of the reaction, calculate krev based on keff print "Calculating dissociate rate constant based on NUPACK partition function energies and first step mode k_eff..." import nupack dG_top = nupack.pfunc([seq], T=T) dG_bot = nupack.pfunc([Strand(sequence=seq).C.sequence], T=T) dG_duplex = nupack.pfunc([seq, Strand(sequence=seq).C.sequence], T=T) RT = 1.987e-3 * (273.15 + T) time3 = time.time() time_nupack = time3 - time2 krev_nupack = keff_1s * np.exp((dG_duplex - dG_top - dG_bot) / RT) print "krev = %g /s (%g seconds)" % (krev_nupack, time_nupack) print # do one "first passage time" run for dissociation, and get k_rev # krev_1p = first_passage_dissociation(seq, 500, T=T, material=material) # this is good, for short enough strands krev_1p = first_passage_dissociation( seq, 10, T=T, material=material) # too few, but faster time4 = time.time() time1passage_rev = time4 - time3 print "krev = %g /s (%g seconds)" % (krev_1p, time1passage_rev) print # for each concentration z, do one "first passage time" run for association, and get k_eff(z) keffs_1p = [] for concentration in concentrations: keff = first_passage_association(seq, 10000, concentration=concentration, T=T, material=material) keffs_1p.append((keff, concentration)) time5 = time.time() time1passage_for = time5 - time4 for (keff, z) in keffs_1p: print "keff = %g /M/s at %s" % (keff, concentration_string(z)) print "(took %g seconds total)" % (time1passage_for) print # for each concentration z, do one long "transition mode" run, and compute k_eff(z) and k_rev for each run. keffs_tm = [] krevs_tm = [] for concentration in concentrations: keff, krev = transition_mode_simulation(seq, 0.5, concentration, T=T, material=material) keffs_tm.append((keff, concentration)) if not keff is None: print "keff = %g /M/s at %s" % ( keff, concentration_string(concentration)) krevs_tm.append((krev, concentration)) if not krev is None: print "krev = %g /s at %s" % (krev, concentration_string(concentration)) time6 = time.time() time_transitions = time6 - time5 print "(took %g seconds total)" % (time_transitions) print
def strand_dG(seq, T=GLOBAL_TEMPERATURE, material='dna'): return nupack.pfunc([ seq ], T=T, material=material)
def duplex_dG(seq, T=GLOBAL_TEMPERATURE, material='dna'): return nupack.pfunc([ seq, WC(seq) ], T=T, material=material)
def binding_dG(seq, T=GLOBAL_TEMPERATURE, material='dna'): dG_top = nupack.pfunc([seq], T=T, material=material) dG_bot = nupack.pfunc([ WC(seq) ], T=T, material=material) dG_duplex = nupack.pfunc([ seq, WC(seq) ], T=T, material=material) return (dG_duplex - dG_top - dG_bot)
def strand_dG(seq, T=25, material='dna'): return nupack.pfunc([ seq ], T=T, material=material)
def duplex_dG(seq, T=25, material='dna'): return nupack.pfunc([ seq, WC(seq) ], T=T, material=material)