def run(self, simu_path, pool_folder, eval_results_path): """ """ nparams = len(pool_folder) plog = self.get_param_from_log(simu_path) nsimu = int(plog['nsimu']) param_name = plog["parameter to explore name"] param = self.get_param(pool_folder) kt_plate = [] logger.info("Running processes on each pool") for i, simudir in enumerate(sorted(pool_folder)): logger.info(color("Running processes on pool called: %s" % os.path.split(simudir)[-1], 'BOLD')) p = Process(results_path=simudir) resu = p.evaluate(name="Mitotic Plate", draw=False, verbose=False) kt_plate.append(resu) # Configure and plot the graph logger.info("Plotting results") timelapse = np.arange(0, plog['duration'], plog['dt']) plot_data = {} plot_data['title'] = "Mitotic plate formation with %s variable" % param_name plot_data['xaxis'] = {'data': timelapse, 'label': 'Time (second)'} plot_data['yaxis'] = {'label': 'Dispersion measure (relative to the spindle length)', 'axis': []} plot_data['error'] = False plot_data['legend'] = True # plot_data['limit_y_min'] = 0 # Draw parameters box plot_data["params_box"] = [{'name': "Name", 'data': plog["name"]}, {'name': "Simulations number", 'data': nsimu}, ] # User matplotlib to get color gradient cm = plt.get_cmap('gist_rainbow') for i, resu in enumerate(kt_plate): plot_color = cm(1. * i / nparams) plot_data['yaxis']['axis'].append({'data': resu['dispersion'], 'color': plot_color, 'legend': "%s" % resu['params'][param_name] }) dic_plot(plot_data, os.path.join(eval_results_path, "Mitotic_Plate_Formation.svg")) # Now we gonna plote plate formation according to parameter explored plot_data['yaxis'] = {'label': 'Dispersion measure (relative to the spindle length)', 'axis': []} plot_data['xaxis'] = {'data': [], 'label': param_name} plot_data['legend'] = False plot_data["params_box"].append({'name': 'Infos', 'data': 'Dispersion measure is the mean to the last 30 sec before anaphase trigger'}) yaxisparam = [] xaxisparam = [] for i, resu in enumerate(kt_plate): plot_color = cm(1. * i / nparams) # Compute mean plate rate see on last 30 second before anaphase start = (param['t_A'] - 30) / param['dt'] stop = (param['t_A']) / param['dt'] # Remove nan value disp = resu['dispersion'][start:stop] disp = disp[~np.isnan(disp)] yaxisparam.append(disp.mean()) xaxisparam.append(resu['params'][param_name]) plot_data['xaxis']['data'] = np.array(xaxisparam) plot_data['yaxis']['axis'].append({'data': np.array(yaxisparam), 'color': 'blue', }) dic_plot(plot_data, os.path.join(eval_results_path, "Mitotic_Plate_Formation2.svg")) return kt_plate
def run(self, simu_path, raw_path, eval_results_path, draw=True, verbose=True): """ """ # Create eval_results_path if it does not exist if not os.path.isdir(eval_results_path): os.makedirs(eval_results_path) params = self.get_params(simu_path) meta_infos = self.get_simus_params(simu_path) num_steps = meta_infos.num_steps nsimu = int(self.get_nsimu(simu_path)) name = self.get_name(simu_path) ana_onset = int(params["t_A"]) chromo_attach = {'monotelic': np.zeros((nsimu, num_steps)), 'syntelic': np.zeros((nsimu, num_steps)), 'unattached': np.zeros((nsimu, num_steps)), 'amphitelic': np.zeros((nsimu, num_steps)), 'merotelic-cut': np.zeros((nsimu, num_steps)), 'merotelic-amphi': np.zeros((nsimu, num_steps)), 'merotelic-synte': np.zeros((nsimu, num_steps)), } if verbose: logger.info("Loading data from simulations files") for i, (simu_id, meta) in enumerate(self.iter_simulations(raw_path, nsimu=nsimu, print_progress=verbose)): results = meta.evaluate(name="Chromosome Attachment", verbose=False) for attach_name, value in results.items(): chromo_attach[attach_name][i] = value logger.disabled = False if not draw: return chromo_attach # Configure and plot the graph if verbose: logger.info("Plotting results") timelapse = meta_infos.timelapse plot_data = {} plot_data['title'] = "Chromosome attachment rate" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Chromosome rate', 'axis': []} plot_data['error'] = False # Draw parameters box plot_data["params_box"] = [{'name': "Name", 'data': name}, {'name': "Simulations number", 'data': nsimu}, ] # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, 0), 'xytext': (0,50), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': chromo_attach['monotelic'].mean(axis=0), 'color': 'cyan', 'legend': 'Monotelic', 'error': chromo_attach['monotelic'].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': chromo_attach['unattached'].mean(axis=0), 'color': 'blue', 'legend': 'Unattached', 'error': chromo_attach['unattached'].std(axis=0) }) # plot_data['yaxis']['axis'].append({'data': chromo_attach['amphitelic'].mean(axis=0), # 'color': 'green', # 'legend': 'Amphitelic', # 'error': chromo_attach['amphitelic'].std(axis=0) # }) plot_data['yaxis']['axis'].append({'data': chromo_attach['syntelic'].mean(axis=0), 'color': 'yellow', 'legend': 'Syntelic', 'error': chromo_attach['syntelic'].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-cut'].mean(axis=0), 'color': 'orange', 'legend': 'Balanced Merotelic', 'error': chromo_attach['merotelic-cut'].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-amphi'].mean(axis=0), 'color': 'red', 'legend': 'Mero-Amphitelic', 'error': chromo_attach['merotelic-amphi'].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-synte'].mean(axis=0), 'color': 'purple', 'legend': 'Mero-Syntelic', 'error': chromo_attach['merotelic-synte'].std(axis=0) }) dic_plot(plot_data, os.path.join(eval_results_path, "Chromosome_Attachment.svg")) # Now plot with logarithmic xaxis plot_data['xaxis']['label'] = 'Time (Logarithmic scale)' plot_data['logx'] = True dic_plot(plot_data, os.path.join(eval_results_path, "Chromosome_Attachment_logarithmic.svg")) # Draw same plot but without all merotelic type : we merge them plot_data['logx'] = False plot_data['yaxis']['axis'] = plot_data['yaxis']['axis'][0:4] mero = chromo_attach['merotelic-cut'] + chromo_attach['merotelic-synte'] + chromo_attach['merotelic-amphi'] plot_data['yaxis']['axis'].append({'data': mero.mean(axis=0), 'color': 'red', 'legend': 'Merotelic', 'error': mero.std(axis=0) }) dic_plot(plot_data, os.path.join(eval_results_path, "Chromosome_Attachment_Merge_Mero.svg")) # Now plot with logarithmic xaxis plot_data['xaxis']['label'] = 'Time (Logarithmic scale)' plot_data['logx'] = True dic_plot(plot_data, os.path.join(eval_results_path, "Chromosome_Attachment_Merge_Mero_logarithmic.svg")) return chromo_attach
def run(self, KD, draw=False): """ """ N = int(KD.params["N"]) ana_onset = int(KD.params["t_A"]) timelapse = np.arange(0, KD.duration, KD.dt) trajectories = {'spbR': KD.spbR.traj, 'spbL': KD.spbL.traj, 'chromosomes': [], } # Retrieve kinetochores trajectories for ch in KD.chromosomes: traj = [ch.cen_A.traj, ch.cen_B.traj] trajectories['chromosomes'].append(traj) if not draw: return trajectories # Draw attachment state with matplotlib timelapse = np.arange(0, KD.duration, KD.dt) plot_data = {} plot_data['title'] = "Chromosome kinetochores trajectories" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Relative position to SPB axes center', 'axis': []} plot_data['logx'] = False plot_data['legend'] = False # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, -2), 'xytext': (0, 20), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': trajectories['spbR'], 'color': 'black', 'plot_args': {'ls': '-', 'lw': 3} }) plot_data['yaxis']['axis'].append({'data': trajectories['spbL'], 'color': 'black', 'plot_args': {'ls': '-', 'lw': 3} }) # User matplotlib to get color gradient cm = plt.get_cmap('gist_rainbow') for i, ch in enumerate(trajectories['chromosomes']): color = cm(1. * i / N) plot_data['yaxis']['axis'].append({'data': ch[0], 'color': color, }) plot_data['yaxis']['axis'].append({'data': ch[1], 'color': color, }) dic_plot(plot_data) return trajectories
def run(self, KD, draw=False): """ """ N = int(KD.params["N"]) ana_onset = int(KD.params["t_A"]) timelapse = np.arange(0, KD.duration, KD.dt) num_steps = KD.duration / KD.dt kt_traj_step = num_steps / 20 spindle_length = abs(KD.spbR.traj - KD.spbL.traj) # Dispersion is size of the segment made by extrem Kt scaled # by spindle size kt_plate = {'dispersion': None, 'kt_trajs': [], 'plate_shape_right': np.zeros((N , num_steps), dtype="float"), 'plate_shape_left': np.zeros((N , num_steps), dtype="float") } max_kt = np.zeros((N * 2, num_steps), dtype="float") min_kt = np.zeros((N * 2, num_steps), dtype="float") kt_trajs = [] for i, ch in enumerate(KD.chromosomes): id1 = (i * 2) - 1 id2 = (i * 2) max_kt[id1] = ch.cen_A.traj max_kt[id2] = ch.cen_B.traj min_kt[id1] = ch.cen_A.traj min_kt[id2] = ch.cen_B.traj kt_trajs.append(ch.cen_A.traj / spindle_length) kt_trajs.append(ch.cen_B.traj / spindle_length) if ch.cen_A.traj.mean() < ch.cen_B.traj.mean(): kt_plate['plate_shape_left'][i] = ch.cen_A.traj kt_plate['plate_shape_right'][i] = ch.cen_B.traj else: kt_plate['plate_shape_right'][i] = ch.cen_A.traj kt_plate['plate_shape_left'][i] = ch.cen_B.traj kt_plate['plate_shape_left'] = kt_plate['plate_shape_left'].std(axis=0) kt_plate['plate_shape_right'] = kt_plate['plate_shape_right'].std(axis=0) max_kt_distance = max_kt.max(axis=0) min_kt_distance = min_kt.min(axis=0) kt_plate['dispersion'] = (abs(max_kt_distance - min_kt_distance) / spindle_length) # Scale kt trajectories for kt in kt_trajs: kt = kt + kt_plate['dispersion'] # Lighten array light_traj = np.zeros(num_steps, dtype='float') light_traj[::kt_traj_step] = 1 light_traj *= kt light_traj[light_traj == 0] = np.nan kt_plate['kt_trajs'].append(light_traj) if not draw: return kt_plate # Draw attachment state with matplotlib timelapse = np.arange(0, KD.duration, KD.dt) plot_data = {} plot_data['title'] = "Centromeres dispersion variation" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time (second)'} plot_data['yaxis'] = {'label': "Dispersion measure (relative to the spindle length)", 'axis': []} plot_data['logx'] = False plot_data['legend'] = False plot_data['limit_y_min'] = 0 # Draw parameters box plot_data["params_box"] = [{'name': "Lenght Dependance factor", 'data': KD.params["ldep"]}, ] # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, 0), 'xytext': (0, 20), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': kt_plate['dispersion'], 'color': 'blue', 'plot_args' : {'lw': 2} }) dic_plot(plot_data) # User matplotlib to get color gradient cm = plt.get_cmap('gist_rainbow') for j, kt in enumerate(kt_plate['kt_trajs']): if j%2 == 0: color = cm(1. * j / (N)) plot_data['yaxis']['axis'].append({'data': kt, 'color': color, 'plot_args' : {'marker': 'o'} }) dic_plot(plot_data) # Plot the plate shape plot_data['title'] = "Mitotic plate formation" plot_data['yaxis'] = {'label': "Centromeres position variance", 'axis': []} del plot_data['limit_y_min'] plot_data['yaxis']['axis'].append({'data': kt_plate['plate_shape_right'], 'color': 'blue', 'legend': 'Right kinetochores' }) plot_data['yaxis']['axis'].append({'data': kt_plate['plate_shape_left'], 'color': 'red', 'legend': 'Left kinetochores' }) dic_plot(plot_data) return kt_plate
def run(self, simu_path, raw_path, eval_results_path, draw=True, verbose=True): """ """ # Create eval_results_path if it does not exist if not os.path.isdir(eval_results_path): os.makedirs(eval_results_path) params = self.get_params(simu_path) meta_infos = self.get_simus_params(simu_path) num_steps = meta_infos.num_steps nsimu = int(self.get_nsimu(simu_path)) name = self.get_name(simu_path) ana_onset = int(params["t_A"]) N = int(params["N"]) Mk = int(params["Mk"]) attach_state = {'correct_attached': np.zeros((nsimu, num_steps)), 'incorrect_attached': np.zeros((nsimu, num_steps)), 'unattached': np.zeros((nsimu, num_steps)) } if verbose: logger.info("Loading data from simulations files") for i, (simu_id, meta) in enumerate(self.iter_simulations(raw_path, nsimu=nsimu, print_progress=verbose)): results = meta.evaluate(name="Kineto Attachment", verbose=False) attach_state['correct_attached'][i] = results['correct_attached'] attach_state['incorrect_attached'][i] = results['incorrect_attached'] attach_state['unattached'][i] = results['unattached'] logger.disabled = False # Mean data logger.info("Processing data") correct_attached = attach_state['correct_attached'].mean(axis=0) correct_attached_std = attach_state['correct_attached'].std(axis=0) incorrect_attached = attach_state['incorrect_attached'].mean(axis=0) incorrect_attached_std = attach_state['incorrect_attached'].std(axis=0) unattached = attach_state['unattached'].mean(axis=0) unattached_std = attach_state['unattached'].std(axis=0) if not draw: return attach_state # Configure and plot the graph if verbose: logger.info("Plotting results") timelapse = meta_infos.timelapse plot_data = {} plot_data['title'] = """Kinetochores attachment rate""" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Attachment rate', 'axis': []} # Draw parameters box plot_data["params_box"] = [{'name': "Name", 'data': name}, {'name': "Simulations number", 'data': nsimu}, {'name': "Chromosome number", 'data': '%i' % N}, {'name': "Plug site per kinetochore", 'data': '%i' % Mk} ] # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, 0), 'xytext': (0,50), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) correct_attached_axis = {'data': correct_attached, 'color': 'green', 'legend': 'Correct attached kinetochore', 'error': correct_attached_std, } incorrect_attached_axis = {'data': incorrect_attached, 'color': 'red', 'legend': 'Incorrect attached kinetochore', 'error': incorrect_attached_std, } unattached_axis = {'data': unattached, 'color': 'blue', 'legend': 'Unattached kinetochore', 'error': unattached_std, } plot_data['yaxis']['axis'].append(correct_attached_axis) plot_data['yaxis']['axis'].append(incorrect_attached_axis) plot_data['yaxis']['axis'].append(unattached_axis) dic_plot(plot_data, os.path.join(eval_results_path, "Kineto_Attachment.svg")) # Now plot with log xaxis plot_data['xaxis']['label'] = 'Time (Logarithmic scale)' plot_data['logx'] = True dic_plot(plot_data, os.path.join(eval_results_path, "Kineto_Attachment_logarithmic.svg")) return attach_state
def run(self, simu_path, raw_path, eval_results_path, draw=True, verbose=True): """ """ # Create eval_results_path if it does not exist if not os.path.isdir(eval_results_path): os.makedirs(eval_results_path) params = self.get_params(simu_path) meta_infos = self.get_simus_params(simu_path) num_steps = meta_infos.num_steps nsimu = int(self.get_nsimu(simu_path)) name = self.get_name(simu_path) ana_onset = int(params["t_A"]) kt_plate = {'dispersion': np.zeros((nsimu, num_steps)), 'plate_shape_right': np.zeros((nsimu, num_steps)), 'plate_shape_left': np.zeros((nsimu, num_steps)), 'params': params } if verbose: logger.info("Loading data from simulations files") for i, (simu_id, meta) in enumerate(self.iter_simulations(raw_path, nsimu=nsimu, print_progress=verbose)): results = meta.evaluate(name="Mitotic Plate", verbose=False) kt_plate['dispersion'][i] = results['dispersion'] kt_plate['plate_shape_left'][i] = results['plate_shape_left'] kt_plate['plate_shape_right'][i] = results['plate_shape_right'] logger.disabled = False kt_plate['dispersion_std'] = kt_plate['dispersion'].std(axis=0) kt_plate['dispersion'] = kt_plate['dispersion'].mean(axis=0) kt_plate['plate_shape_right'] = kt_plate['plate_shape_right'].mean(axis=0) kt_plate['plate_shape_right_std'] = kt_plate['plate_shape_right'].std(axis=0) kt_plate['plate_shape_left'] = kt_plate['plate_shape_left'].mean(axis=0) kt_plate['plate_shape_left_std'] = kt_plate['plate_shape_left'].std(axis=0) if not draw: return kt_plate # Configure and plot the graph if verbose: logger.info("Plotting results") timelapse = meta_infos.timelapse plot_data = {} plot_data['title'] = "Centromeres dispersion variation" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time (second)'} plot_data['yaxis'] = {'label': 'Dispersion measure (relative to the spindle length)', 'axis': []} plot_data['error'] = True plot_data['legend'] = False plot_data['limit_y_min'] = 0 # Draw parameters box plot_data["params_box"] = [{'name': "Name", 'data': name}, {'name': "Simulations number", 'data': nsimu}, {'name': "Lenght Dependance factor", 'data': params["ldep"]} ] # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, 0), 'xytext': (0,50), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': kt_plate['dispersion'], 'color': 'blue', 'error': kt_plate['dispersion_std'] }) dic_plot(plot_data, os.path.join(eval_results_path, "Mitotic_Plate_Formation.svg")) # Plot the plate shape plot_data['title'] = "Mitotic plate formation" plot_data['yaxis'] = {'label': "Centromeres position variance", 'axis': []} del plot_data['limit_y_min'] plot_data['legend'] = True plot_data['yaxis']['axis'].append({'data': kt_plate['plate_shape_right'], 'color': 'blue', 'legend': 'Right kinetochores', 'error': kt_plate['plate_shape_right_std'] }) plot_data['yaxis']['axis'].append({'data': kt_plate['plate_shape_left'], 'color': 'red', 'legend': 'Left kinetochores', 'error': kt_plate['plate_shape_left_std'] }) dic_plot(plot_data, os.path.join(eval_results_path, "Mitotic_Plate_Formation2.svg")) return kt_plate
def run(self, simu_path, raw_path, eval_results_path, draw=True, verbose=True): """ """ # Create eval_results_path if it does not exist if not os.path.isdir(eval_results_path): os.makedirs(eval_results_path) params = self.get_params(simu_path) meta_infos = self.get_simus_params(simu_path) num_steps = meta_infos.num_steps nsimu = int(self.get_nsimu(simu_path)) name = self.get_name(simu_path) ana_onset = int(params["t_A"]) N = int(params["N"]) trajectories = {'spbR': np.zeros((nsimu, num_steps), dtype=float), 'spbL': np.zeros((nsimu, num_steps), dtype=float), 'chromosomes': [], } for i in range(N): cen_traj = [np.zeros((nsimu, num_steps), dtype=float), np.zeros((nsimu, num_steps), dtype=float)] trajectories['chromosomes'].append(cen_traj) if verbose: logger.info("Loading data from simulations files") for i, (simu_id, meta) in enumerate(self.iter_simulations(raw_path, nsimu=nsimu, print_progress=verbose)): results = meta.evaluate(name="Kinetochores Trajectories", verbose=False) trajectories['spbR'][i] = results['spbR'] trajectories['spbL'][i] = results['spbL'] for j, ch in enumerate(results['chromosomes']): trajectories["chromosomes"][j][0][i] = ch[0] trajectories["chromosomes"][j][1][i] = ch[1] logger.disabled = False if not draw: return trajectories # Configure and plot the graph if verbose: logger.info("Plotting results") timelapse = meta_infos.timelapse plot_data = {} plot_data['title'] = "Chromosome kinetochores trajectories" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Relative position to SPB axes center', 'axis': []} plot_data['error'] = False plot_data['legend'] = False # Draw parameters box plot_data["params_box"] = [{'name': "Name", 'data': name}, {'name': "Simulations number", 'data': nsimu}, ] # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, -2.5), 'xytext': (0, 20), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': trajectories['spbR'].mean(axis=0), 'color': 'black', 'error': trajectories['spbR'].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': trajectories['spbL'].mean(axis=0), 'color': 'black', 'error': trajectories['spbL'].std(axis=0) }) # User matplotlib to get color gradient cm = plt.get_cmap('gist_rainbow') for i, ch in enumerate(trajectories['chromosomes']): color = cm(1.*i/N) plot_data['yaxis']['axis'].append({'data': ch[0].mean(axis=0), 'color': color, 'error': ch[0].std(axis=0) }) plot_data['yaxis']['axis'].append({'data': ch[1].mean(axis=0), 'color': color, 'error': ch[1].std(axis=0) }) dic_plot(plot_data, os.path.join(eval_results_path, "Kt_Trajectories.svg")) return trajectories
def run(self, KD, draw=False): """ """ num_steps = KD.spbR.traj.size N = int(KD.params['N']) Mk = int(KD.params['Mk']) ana_onset = int(KD.params["t_A"]) value_max = N * Mk * 2 chromo_attach = {'monotelic': np.zeros(num_steps), 'syntelic': np.zeros(num_steps), 'unattached': np.zeros(num_steps), 'amphitelic': np.zeros(num_steps), 'merotelic-cut': np.zeros(num_steps), 'merotelic-amphi': np.zeros(num_steps), 'merotelic-synte': np.zeros(num_steps), } for ch in KD.chromosomes: iterator = enumerate(zip(ch.correct_history, ch.erroneous_history)) for i, (correct, incorrect) in iterator: # Kt A n° correct attachments ac = correct[0] # Kt B n° correct attachments bc = correct[1] # Kt A n° incorrect attachments ai = incorrect[0] # Kt B n° incorrect attachments bi = incorrect[1] if ac + bc + ai + bi == 0: # The actual chromosome is unattached (so easy...) chromo_attach['unattached'][i] += 1 elif (ac + ai + bi == 0 and bc > 0) or \ (bc + bi + ai == 0 and ac > 0): # The actual chromosome is monotelic chromo_attach['monotelic'][i] += 1 elif ai + bi == 0 and ac > 0 and bc > 0: # The actual chromosome is amphitelic chromo_attach['amphitelic'][i] += 1 elif (ac == 0 and ai > 0) or (bc == 0 and bi > 0): # The actual chromosome is syntelic chromo_attach['syntelic'][i] += 1 # It should remain here, only merotelic chromosomes. # Let's check it elif ai > 0 or bi > 0: # Welcome to the merotelic world ! if ac == ai or bc == bi: chromo_attach['merotelic-cut'][i] += 1 elif ac < ai or bc < bi: chromo_attach['merotelic-synte'][i] += 1 elif ac > ai or bc > bi: chromo_attach['merotelic-amphi'][i] += 1 else: # The code should never run here unless we got errors ! logger.error("Problem in attachment rate algorithm (second level condition") return False else: # The code should never run here unless we got errors ! logger.error("Problem in attachment rate algorithm (first level condition") return False # Normalize values on 1 for state in chromo_attach: chromo_attach[state] = chromo_attach[state] / N if draw: # Draw attachment state with matplotlib timelapse = np.arange(0, KD.duration, KD.dt) plot_data = {} plot_data['title'] = "Chromosome attachment rate" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Attachment rate', 'axis': []} plot_data['logx'] = True # Add annotation about anaphase onset plot_data["annotations"] = [] plot_data["annotations"].append({'s': 'Anaphase onset: %i' % ana_onset, 'xy': (ana_onset, 0), 'xytext': (0,50), 'textcoords': 'offset points', 'ha': 'center', 'va': 'bottom', 'bbox': dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3), 'arrowprops': dict(arrowstyle='->', # connectionstyle='arc3,rad=0.5', color='black') }) plot_data['yaxis']['axis'].append({'data': chromo_attach['monotelic'], 'color': 'cyan', 'legend': 'Monotelic' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['unattached'], 'color': 'blue', 'legend': 'Unattached' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['amphitelic'], 'color': 'green', 'legend': 'Amphitelic' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['syntelic'], 'color': 'yellow', 'legend': 'Syntelic' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-cut'], 'color': 'orange', 'legend': 'Balanced Merotelic' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-amphi'], 'color': 'red', 'legend': 'Mero-Amphitelic' }) plot_data['yaxis']['axis'].append({'data': chromo_attach['merotelic-synte'], 'color': 'purple', 'legend': 'Mero-Syntelic' }) dic_plot(plot_data) return chromo_attach
def run(self, KD, draw=False): """ """ num_steps = KD.spbR.traj.size N = int(KD.params['N']) Mk = int(KD.params['Mk']) value_max = N * Mk * 2 kt_attach = {'correct_attached': np.zeros(num_steps, dtype='float'), 'incorrect_attached': np.zeros(num_steps, dtype='float'), 'unattached': np.zeros(num_steps, dtype='float') } for ch in KD.chromosomes: ch_incorrect = np.array(ch.erroneous_history).sum(1) ch_correct = np.array(ch.correct_history).sum(1) kt_attach['correct_attached'] += ch_correct kt_attach['incorrect_attached'] += ch_incorrect kt_attach['unattached'] = np.ones(num_steps, dtype='float') * value_max kt_attach['unattached'] -= kt_attach['correct_attached'] kt_attach['unattached'] -= kt_attach['incorrect_attached'] # Scale values on 1 kt_attach['correct_attached'] /= value_max kt_attach['incorrect_attached'] /= value_max kt_attach['unattached'] /= value_max if draw: # Draw attachment state with matplotlib timelapse = np.arange(0, KD.duration, KD.dt) plot_data = {} plot_data['title'] = "Kinetochores attachment rate" plot_data['xaxis'] = {'data': timelapse, 'label': 'Time'} plot_data['yaxis'] = {'label': 'Attachment rate', 'axis': []} # Draw parameters box correct_attached_axis = {'data': kt_attach['correct_attached'], 'color': 'green', 'legend': 'Correct attached kinetochore'} incorrect_attached_axis = {'data': kt_attach['incorrect_attached'], 'color': 'red', 'legend': 'Incorrect attached kinetochore'} unattached_axis = {'data': kt_attach['unattached'], 'color': 'blue', 'legend': 'Unattached kinetochore'} plot_data['yaxis']['axis'].append(correct_attached_axis) plot_data['yaxis']['axis'].append(incorrect_attached_axis) plot_data['yaxis']['axis'].append(unattached_axis) dic_plot(plot_data) return kt_attach