def trackDefinedDSBtrajectory(polymerParams, simulationParams, x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackDSB_fixedDSBs' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nc in enumerate(x_Nc): print("\n Simulation for Nc = %s CLs " % Nc) polymerParams['Nc'] = Nc # ### ADAPTIVE ENCOUNTER DISTANCE # xi = 2*(Nc)/((N-1)*(N-2)) ## scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) # simulationParams['encounterDistance'] = adaptiveEpsilon(xi, N, polymerParams['b']) # # simulationParams['distanceThreshold'] = simulationParams['encounterDistance'] p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results})
def proba_v_sigma(polymerParams, simulationParams, x_sigma): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_msrg-v_sigma' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, keepCL in enumerate([True]): polymerParams['keepCL'] = keepCL for j, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} if sigma == 0: expName = "measureMSRG" else: expName = "measureMSRG" mc = Experiment(p0, results, simulationParams, expName) if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def FET_Simulation(polymerParams, simulationParams): date = strftime("%Y_%m_%d_%H_%M") p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "Encounter_withExcludedVolume") plotFET(mc) halfCI = 1.96 * np.std(mc.results['FETs']) / np.sqrt( simulationParams['numRealisations']) print('Mean FTE : ' + str(np.mean(mc.results['FETs'])) + ' ± ' + str(halfCI)) events = mc.results['eventsCounter'] plot_bar_from_counter(events) plt.show() filepath = 'results/FET_Distribution_Experiment_' + date + '.pkl' with open(filepath, 'wb') as output: pickle.dump(mc, output, pickle.HIGHEST_PROTOCOL) return mc
def FET_Simulation(polymerParams, simulationParams): # date = strftime("%Y_%m_%d_%H_%M") date = strftime("%Y_%m_%d_%H_%M") filename = date + '__FETSimulationResults' + '.csv' p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") ### SAVE RESULTS with open('results/' + filename, 'w') as csvfile: fieldnames = list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({**mc.results}) ### PLOT RESULTS plotFET(mc) halfCI = 1.96 * np.nanstd(mc.results['FETs']) / np.sqrt( simulationParams['numRealisations']) print('Mean FTE : ' + str(np.nanmean(mc.results['FETs'])) + ' ± ' + str(halfCI)) events = mc.results['eventsCounter'] plot_bar_from_counter(events) plt.show() # filepath = 'results/FET_Distribution_Experiment_'+date+'.pkl' # with open(filepath, 'wb') as output: # pickle.dump(mc, output, pickle.HIGHEST_PROTOCOL) return mc
def proba_v_gNc(polymerParams, simulationParams, x_g, x_Nc, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_gNc_withVE' + '.csv' first_time = True N = polymerParams['numMonomers'] with open('results/' + filename, 'w') as csvfile: for i, g in enumerate(x_g): print("Simulation for g = %s " % g) simulationParams['genomicDistance'] = g for j, nc in enumerate(x_Nc): print("Simulation for Nc = %s " % nc) polymerParams['Nc'] = nc ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (nc + simulationParams['Nc_inDamageFoci']) / ( (N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) # simulationParams['excludedVolumeCutOff'] = 3*simulationParams['encounterDistance'] ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 simulationParams['numMaxSteps'] = int(60 // simulationParams['dt']) print("ε = %s" % (simulationParams['encounterDistance'])) p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def proba_vs_conectorsNumber(test_genomic_distances, x_Nc, keepCL, errorbars=False): probas = [] demiCI = [] output = np.zeros((len(test_genomic_distances), 3, len(x_Nc))) date = strftime("%Y_%m_%d_%H_%M") plt.figure() for i, genomicDistance in enumerate(test_genomic_distances): probas = [] demiCI = [] for Nc in x_Nc: results = {} p0 = RCLPolymer(100, 3, 0.2, Nc, keepCL) params['genomicDistance'] = genomicDistance mc = Experiment(p0, results, params, "EncounterSimulation") probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) probas = np.array(probas) demiCI = np.array(demiCI) output[i][0] = x_Nc output[i][1] = probas output[i][2] = demiCI np.save( 'results/proba_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(100) + 'monomers_' + str(numRealisations) + 'iterations' + date + '.npy', output) if errorbars: plt.errorbar(x=x_Nc, y=probas, yerr=demiCI, fmt='-o', label=r'$g = $ ' + str(genomicDistance), capsize=4) else: plt.plot(x_Nc, probas, '-o', label=r'$g = $ ' + str(genomicDistance)) np.save( 'results/proba_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(100) + 'monomers_' + str(numRealisations) + 'iterations' + date + '.npy', output) plt.legend() plt.show()
def DSBclustering(polymerParams, simulationParams): """ Tracks the breaks positions assuming they are persistent """ date = strftime("%Y_%m_%d_%H_%M") filename = date + '_interbreakdistances' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'large'}) plt.xlabel('Time (sec)') plt.ylabel('Distance between A1 and A2') #(r'$\mathbb{P}$(Repair)') first_time = True for i, VolumeExclusion in enumerate([False]): if VolumeExclusion: labelkeep = 'Excluding volume with a cutoff of ' + str( simulationParams['excludedVolumeCutOff']) + ' μm' else: labelkeep = 'Without excluded volume' simulationParams['excludedVolumeCutOff'] = 0 p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'persistentDSB') if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) plt.title(labelkeep) time = np.arange(simulationParams['numSteps'] + 1) * simulationParams['dt'] from itertools import combinations z = combinations([ chr(97 + i // 2) + str(1 + i % 2) for i in range(2 * len(p0.subDomainnumMonomers)) ], r=2) names = [i for i in z] for i in range(15): distanceA2B1 = mc.results['MeanInterBreakDistance'][:, i] plt.plot(time, distanceA2B1, '-', label='d(%s, %s)' % names[i]) plt.legend() plt.show()
def proba_v_NlrandSizes(polymerParams, simulationParams, x_Nlr, x_TADsizes): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_Nlr_TADsize' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, nlr in enumerate(x_Nlr): print("Simulation for Nlr = %s " % nlr) polymerParams['Nc'][0, 1] = polymerParams['Nc'][1, 0] = nlr for j, tadsize in enumerate(x_TADsizes): print("Simulation for a parasyte of size %s " % tadsize) polymerParams['numMonomers'][1] = tadsize N = polymerParams['numMonomers'].sum() ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (polymerParams['Nc'].sum()) / ((N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 print("ε = %s" % (simulationParams['encounterDistance'])) p0 = RCLPolymer(**polymerParams) results = { **polymerParams, **simulationParams, **{ 'Nlr': polymerParams['Nc'][0, 1], 'TADsize': polymerParams['numMonomers'][1] } } mc = Experiment(p0, results, simulationParams, "oneTAD_Repair") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def proba_v_sigma(polymerParams, simulationParams, x_sigma, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_sigma' + '.csv' # plt.figure() # rcParams.update({'axes.labelsize' : 'xx-large'}) # rcParams.update({'legend.fontsize': 'xx-large'}) # rcParams.update({'xtick.labelsize': 'xx-large'}) # rcParams.update({'ytick.labelsize': 'xx-large'}) # plt.xlabel('Number of connectors in DF') # plt.ylabel('Mean FET (sec)') #('Mean first encounter time (sec)') # first_time = True with open('results/' + filename, 'w') as csvfile: for i, keepCL in enumerate([True]): # if keepCL: # labelkeep = "Keeping CLs in DF" # # else: # labelkeep = 'Removing CLs in DF' polymerParams['keepCL'] = keepCL # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) # p = np.zeros(len(x_sigma)) # dp = np.zeros(len(x_sigma)) for j, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} if sigma == 0: expName = "EncounterSimulation" else: expName = "Encounter_withRepairSphere" mc = Experiment(p0, results, simulationParams, expName) # p[j] = mc.results['repair_probability'] # dp[j] = mc.results['repair_CIhalflength'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def proba_vs_genomicDistance_andVE(polymerParams, simulationParams, x_sigma, gmax, gStep, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_VE_proba_vs_genomicDistance_' + '.csv' with open('results/' + filename, 'w') as csvfile: gmin = 2 # plt.figure() # rcParams.update({'axes.labelsize': 'xx-large'}) # plt.xlabel('genomic distance (in number of monomers)') # plt.ylabel(r'$\mathbb{P}$(Repair)') xg = np.arange(gmin, gmax, gStep, dtype=int) for i, sigma in enumerate(x_sigma): if sigma == 0: labelkeep = 'Without excluded volume' experimentName = "EncounterSimulation" simulationParams['excludedVolumeCutOff'] = 0 else: labelkeep = r"Excluding volume ($\sigma = %s $)" % sigma experimentName = "Encounter_withRepairSphere" simulationParams['excludedVolumeCutOff'] = sigma probas = np.zeros(len(xg)) demiCI = np.zeros(len(xg)) for j, g in enumerate(xg): print("Simulation for g =", g, "and ", labelkeep) p0 = RCLPolymer(**polymerParams) simulationParams['genomicDistance'] = g results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, experimentName) # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] if i == 0 and g == gmin: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def trackAlpha_vsNc(x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackAlphaAfterDSB_vsNc' with open('results/' + filename + '.csv', 'w') as csvfile: first_time = True for i, Nc in enumerate(x_Nc): polymerParams['Nc'] = Nc p0 = RCLPolymer(**polymerParams) # Waiting time will be relaxation time (Nc dependant) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) simulationParams['VE_waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, trackAlpha) if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False os.makedirs('results/' + filename + '_figures') writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) # Save MSD raw data with open( 'results/' + filename + '_figures/nc' + str(Nc) + 'msd_data.csv', 'w') as rawdata: rowwriter = csv.writer(rawdata) for msd_data in mc.results['monomersMSD'].transpose(): rowwriter.writerow(msd_data) # Save MSD curve plt.figure() plt.plot(mc.results['monomersMSD'].transpose()) legend = ['_o'] * polymerParams['numMonomers'] legend[simulationParams['A1']] = 'a1' legend[simulationParams['A1'] + 1] = 'a2' legend[simulationParams['B1']] = 'b1' legend[simulationParams['B1'] + 1] = 'b2' legend = tuple(legend) plt.legend(legend) plt.savefig('results/' + filename + '_figures/nc' + str(Nc) + '.png') plt.close()
def proba_v_interDomainDistance(polymerParams, simulationParams, TAD_size, test_distances, errorbars): """ Probability vs interDomainDistance """ plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) plt.xlabel('genomic distance between TADs') plt.ylabel(r'$\mathbb{P}$(Repair)') xg = test_distances date = strftime("%Y_%m_%d_%H_%M") output = np.empty((3, len(xg))) probas = [] demiCI = [] for g in xg: print("Simulation for 2 TADs of size %s, at a distance % s" % (TAD_size, g)) tad1_right = 50 - np.ceil(g / 2).astype(int) tad2_left = 50 + np.floor(g / 2).astype(int) polymerParams['TADs'] = [(tad1_right - TAD_size, tad1_right), (tad2_left, tad2_left + TAD_size)] p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "TAD_Repair") probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) probas = np.array(probas) demiCI = np.array(demiCI) output[0] = xg output[1] = probas output[2] = demiCI if errorbars: plt.errorbar(x=xg, y=probas, yerr=demiCI, fmt='-o', capsize=4) else: plt.plot(xg, probas, '-o') np.save('results/proba_vs_interTADdistance__' + date + '.npy', output) plt.legend() plt.show() return mc
def measureProba(g): probas = np.zeros(len(x_Nc)) halfCI = np.zeros(len(x_Nc)) params['genomicDistance'] = g for i, Nc in enumerate(x_Nc): results = {} np.random.seed() p0 = RCLPolymer(100, 3, 0.2, Nc, False) mc = Experiment(p0, results, params, "EncounterSimulation") probas[i] = mc.results['repair_probability'] halfCI[i] = mc.results['repair_CIhalflength'] return (probas, halfCI)
def makeExperiment(numrealisations): p0 = RCLPolymer(100, 3, 0.2, 3) params = dict( dt_relax=0.5, diffusionConstant=0.008, # numSteps = 100, dt=0.1, genomicDistance=2, Nb=2, waitingSteps=200, numMaxSteps=600, encounterDistance=0.1) results = {} params['numRealisations'] = numrealisations np.random.seed() return Experiment(p0, results, params, "EncounterSimulation")
def proba_vs_ExclusioncutoffRadius(polymerParams, simulationParams, test_cutoffs, errorbars=False): Allresults = [] probas = [] demiCI = [] date = strftime("%Y_%m_%d_%H_%M") plt.figure() plt.xlabel('Cutoff radius (micron)') plt.ylabel(r'$\mathbb{P}$(Correct repair)') for threshold in test_cutoffs: print('Simulation for a cutoff of', threshold) p0 = RCLPolymer(**polymerParams) simulationParams['excludedVolumeCutOff'] = threshold results = {} mc = Experiment(p0, results, simulationParams, "Encounter_withExcludedVolume") Allresults.append(mc.results) probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) if errorbars: plt.errorbar(x=test_cutoffs, y=probas, yerr=demiCI, fmt='-o', capsize=4) else: plt.plot(test_cutoffs, probas, '-o') filepath = 'results/Proba_vs_cutoffs__' + date + '.pkl' saveasPickle(filepath, Allresults) # plt.legend() plt.show()
def DSBclustering(polymerParams, simulationParams): """This experiment""" date = strftime("%Y_%m_%d_%H_%M") filename = date + '_interbreakdistances' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'large'}) plt.xlabel('Time (sec)') plt.ylabel('Distance between A1 and A2') #(r'$\mathbb{P}$(Repair)') first_time = True for i, VolumeExclusion in enumerate([True, False]): if VolumeExclusion: labelkeep = 'Excluding volume with a cutoff of ' + str( simulationParams['excludedVolumeCutOff']) + ' μm' else: labelkeep = 'Without excluded volume' simulationParams['excludedVolumeCutOff'] = 0 p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'persistentDSB') if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) distanceA2B1 = mc.results['MeanInterBreakDistance'][:, 0] time = np.arange(simulationParams['numSteps'] + 1) * simulationParams['dt'] plt.plot(time, distanceA2B1, '-', label=labelkeep) plt.legend() plt.show()
def stats_vs_Nb(polymerParams, simulationParams, x_Nb, x_g): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_StatsVsNb' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nb in enumerate(x_Nb): print("Simulation for Nb = %s breaks " % Nb) simulationParams['Nb'] = Nb for j, g in enumerate(x_g): simulationParams['genomicDistance'] = g print("and g = %s . " % g) p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + "_" + str(j) }, **mc.results })
def trackAlpha_v_gNc(polymerParams, simulationParams, x_g, x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackMSD' + '.csv' first_time = True N = polymerParams['numMonomers'] with open('results/' + filename, 'w') as csvfile: for i, g in enumerate(x_g): print("Simulation for g = %s " % g) simulationParams['genomicDistance'] = g for j, nc in enumerate(x_Nc): print("Simulation for Nc = %s " % nc) polymerParams['Nc'] = nc p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackMSD") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def trackDistanceDistribution(polymerParams, simulationParams, x_Nc, x_g): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackDSB' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nc in enumerate(x_Nc): print("Simulation for Nc = %s CLs " % Nc) polymerParams['Nc'] = Nc for j, g in enumerate(x_g): simulationParams['genomicDistance'] = g print("and g = %s . " % g) p0 = RCLPolymer(**polymerParams) # simulationParams['waitingSteps'] = np.ceil(p0.relaxTime(simulationParams['diffusionConstant'])/simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + "_" + str(j) }, **mc.results })
def proba_v_VEkappa(polymerParams, simulationParams, x_sigma, x_kappa, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_kappa' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma for j, kappa in enumerate(x_kappa): print("Simulation for κ = %s " % kappa) simulationParams['excludedVolumeSpringConstant'] = kappa p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "Encounter_withRepairSphere") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
) simulationParams = dict(# Physicial parameters diffusionConstant = 0.008, # Numerical parameters numRealisations = 5, dt = 0.01, dt_relax = 0.01, # numSteps = 500, # excludedVolumeCutOff = 0.2, waitingSteps = 200, numMaxSteps = 500, encounterDistance = 0.1, genomicDistance = 10, Nb = 2, selectedSubDomain = 0 ) with open('results/test_results.csv', 'w') as csvfile: for i in range(5): p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams,"EncounterSimulation") if i == 0: fieldnames = ['experimentSetID']+list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({**{'experimentSetID' : str(i)}, **mc.results})
# x_g = [5,40] # trackDistanceDistribution(polymerParams, simulationParams, x_Nc, x_g) # x_Nc = np.arange(20,60,5) simulationParams['A1'] = 30 simulationParams['B1'] = 59 # trackDefinedDSBtrajectory(polymerParams, simulationParams, x_Nc) # p0 = RCLPolymer(**polymerParams) # simulationParams['waitingSteps'] = np.ceil(p0.relaxTime(simulationParams['diffusionConstant'])/simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") above = mc.results['aboveTimes'] below = mc.results['belowTimes'] plt.figure() plt.hist(below['a1-a2']) aboveTimes = { 'a1-a2': np.array([ 1.0050e+00, 4.2000e-01, 9.5000e-02, 5.0000e-03, 1.0000e-02, 4.5000e-02, 1.6500e-01, 5.0000e-03, 5.5000e-02, 5.0000e-03, 1.0000e-02, 4.7500e-01, 8.5000e-02, 1.5000e-02, 8.0000e-02, 5.0000e-03, 5.0000e-03, 5.5000e-02, 4.8500e-01, 7.0000e-02, 9.5000e-02, 5.0000e-03, 1.0000e-02, 1.7000e-01, 1.1500e-01,
def proba_vs_genomicDistance(polymerParams, simulationParams, gmax, gStep, test_epsilons, errorbars=False): # gmax = nb_monomers - 3 gmin = 2 probas = [] demiCI = [] plt.figure() plt.xlabel('genomic distance (in number of monomers)') plt.ylabel(r'$\mathbb{P}$(Repair)') xg = np.arange(gmin, gmax, gStep, dtype=int) date = strftime("%Y_%m_%d_%H_%M") output = np.empty((len(test_epsilons), 3, len(xg))) for i, eps in enumerate(test_epsilons): simulationParams['encounterDistance'] = eps probas = [] demiCI = [] for g in xg: print("Simulation for g =", g, "and epsilon =", eps) p0 = RCLPolymer(**polymerParams) results = {} simulationParams['genomicDistance'] = g mc = Experiment(p0, results, simulationParams, "Encounter_withExcludedVolume") probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) probas = np.array(probas) demiCI = np.array(demiCI) output[i][0] = xg output[i][1] = probas output[i][2] = demiCI if errorbars: plt.errorbar(x=xg, y=probas, yerr=demiCI, fmt='-o', label=r'$\varepsilon = $ ' + str(eps), capsize=4) else: plt.plot(xg, probas, '-o', label=r'$\varepsilon = $ ' + str(eps)) np.save( 'results/proba_vs_genomicDistance_ExcludedVolume__' + date + '.npy', output) plt.legend() plt.show()
kappa = 3 * 0.008 / (p0.b**2) # Loci dependant kappa breakPoints = [5, 6, 10, 11, 70, 71] # amplitude = np.ones(p0.numMonomers)/10. # amplitude[breakPoints] = 1. # kappa = kappa * amplitude # repulsionForce = lambda polymer : (ExcludedVolume(polymer, excludedVolumeCutOff, method='spring-like').T * -kappa).T repulsionForce = lambda polymer: -kappa * LocalExcludedVolume( polymer, breakPoints, excludedVolumeCutOff) p0.addnewForce(repulsionForce) # Simulation print(len(p0.forces), 'added forces.') results = {} mc_ve = Experiment(p0, results, simulationParams) for monomer in breakPoints: mc_ve.addMonomer2follow(monomer) print('MRG with volume exclusion :', np.sqrt(mc_ve.results['MSRG'])) # # Without excluded volume # p0 = RCLPolymer(**polymerParams) # print(len(p0.forces), 'added forces.') # results = {} # mc_normal = Experiment(p0, results, simulationParams) # print('MRG without volume exclusion :', np.sqrt(mc_normal.results['MSRG'])) ############################################################################ ############################################################################
def proba_vs_keepDFCL(polymerParams, simulationParams, x_Nc, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + 'proba_VE_vs_Nc_NcinDF_adptEPSILONandSIGMA' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'xx-large'}) rcParams.update({'xtick.labelsize': 'large'}) plt.xlabel('Number of connectors in DF') plt.ylabel( r'$\mathbb{P}$(Repair)') #('Mean first encounter time (sec)') # first_time = True N = polymerParams['numMonomers'] for i, keepCL in enumerate([True, False]): if keepCL: labelkeep = "Keeping CLs in DF" else: labelkeep = 'Removing CLs in DF' polymerParams['keepCL'] = keepCL # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) probas = np.zeros(len(x_Nc)) demiCI = np.zeros(len(x_Nc)) for j, Nc in enumerate(x_Nc): print("Simulation for %s CL in DF" % Nc) simulationParams['Nc_inDamageFoci'] = Nc ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (polymerParams['Nc'] + Nc) / ((N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) # ### ADAPTIVE CUTOFF RADIUS # simulationParams['excludedVolume'] = 2 * adaptiveEpsilon(xi, N, polymerParams['b']) # ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 print("ε = %s and σ = %s" % (simulationParams['encounterDistance'], simulationParams['excludedVolumeCutOff'])) p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] # mfet[j] = mc.results['meanFET'] # efet[j] = mc.results['halfCI_FET'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results }) if errorbars: plt.errorbar(x=x_Nc, y=probas, yerr=demiCI, fmt='-o', label=labelkeep, capsize=4) else: plt.plot(x_Nc, probas, '-o', label=labelkeep) plt.legend() plt.show()
def proba_vs_Nc_andVE(polymerParams, simulationParams, x_Nc, x_v, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + 'proba_VE_vs_Nc_NcinDF_adptEPSILONandSIGMA' + '.csv' with open('results/' + filename, 'w') as csvfile: # plt.figure() # rcParams.update({'axes.labelsize' : 'xx-large'}) # rcParams.update({'legend.fontsize': 'xx-large'}) # rcParams.update({'xtick.labelsize': 'large'}) # plt.xlabel('Number of connectors') # plt.ylabel(r'$\mathbb{P}$(Repair)') #('Mean first encounter time (sec)') # first_time = True N = polymerParams['numMonomers'] # Nc0 = x_Nc[0] # xi0 = 2*Nc0/((N-1)*(N-2)) # eps0 = simulationParams['encounterDistance'] # sigma0 = simulationParams['excludedVolumeCutOff'] for i, v in enumerate(x_v): simulationParams['v'] = v experimentName = "Encounter_withRepairSphere" # if VolumeExclusion: ## labelkeep = r"Excluding volume ($\xi$-adaptive $\epsilon$ and $\sigma$)" # experimentName = "Encounter_withRepairSphere" # else: ## labelkeep = 'Without excluded volume' # experimentName = "EncounterSimulation" # simulationParams['excludedVolumeCutOff'] = 0 # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) probas = np.zeros(len(x_Nc)) demiCI = np.zeros(len(x_Nc)) for j, Nc in enumerate(x_Nc): print("Simulation for Nc =", Nc) polymerParams['Nc'] = Nc ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * Nc / ((N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) ### ADAPTIVE CUTOFF RADIUS simulationParams['excludedVolumeCutOff'] = v * adaptiveEpsilon( xi, N, polymerParams['b']) ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 print("ε = %s and σ = %s" % (simulationParams['encounterDistance'], simulationParams['excludedVolumeCutOff'])) p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, experimentName) # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] # mfet[j] = mc.results['meanFET'] # efet[j] = mc.results['halfCI_FET'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def watchOneSimulation(polymerParams, simulationParams): p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "watchEncounter") print(mc.results['FET']) return mc
def proba_vs_genomicDistance(polymerParams, simulationParams, gmax, gStep, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba_vs_genomicDistance_Ncs_' + '.csv' with open('results/' + filename, 'w') as csvfile: gmin = 2 plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) plt.xlabel('genomic distance (in number of monomers)') plt.ylabel(r'$\mathbb{P}$(Repair)') xg = np.arange(gmin, gmax, gStep, dtype=int) first_time = True for i, keepCL in enumerate([True, False]): if keepCL: labelkeep = "Keeping CLs in DF" else: labelkeep = 'Removing CLs in DF' polymerParams['keepCL'] = keepCL # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) probas = np.zeros(len(xg)) demiCI = np.zeros(len(xg)) for j, g in enumerate(xg): print("Simulation for g = %s " % g) simulationParams['genomicDistance'] = g p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'EncounterSimulation') # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results }) if errorbars: plt.errorbar(x=xg, y=probas, yerr=demiCI, fmt='-o', label=labelkeep, capsize=4) else: plt.plot(xg, probas, '-o', label=labelkeep) plt.legend() plt.show()
def makeExperiment(numrealisations): params['numRealisations'] = numrealisations np.random.seed() return Experiment(p0, results, params,"EncounterSimulation")
def proba_v_neighborSize(polymerParams, simulationParams, TADsizes, connectivityFraction, x_Nc, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + 'proba_vs_neighborSize' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'large'}) plt.xlabel('Number of long-range connectors') plt.ylabel( r'$\mathbb{P}$(Repair)') #('Mean first encounter time (sec)') # first_time = True for i, TADsize in enumerate(TADsizes): polymerParams['numMonomers'] = np.array([100, TADsize]) probas = np.zeros(len(x_Nc)) demiCI = np.zeros(len(x_Nc)) polymerParams['Nc'][1, 1] = np.ceil(connectivityFraction * (TADsize - 1) * (TADsize - 2) / 2).astype(int) for j, Nc in enumerate(x_Nc): print("Simulation for interNc =", Nc) polymerParams['Nc'][0, 1] = polymerParams['Nc'][1, 0] = Nc p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'oneTAD_Repair') # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] # mfet[j] = mc.results['meanFET'] # efet[j] = mc.results['halfCI_FET'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results }) if errorbars: plt.errorbar(x=x_Nc, y=probas, yerr=demiCI, fmt='-o', label='Neighbor TAD size: %s' % TADsize, capsize=4) else: plt.plot(x_Nc, probas, '-o', label='Neighbor TAD size: %s' % TADsize) plt.legend() plt.show()