def normal(): wanted = json.loads(open("wanted.json").read()) original_path = os.path.abspath(os.getcwd()) for d, v in wanted.items(): for subdir, lins in v.items(): path = os.path.abspath(os.path.join(d, subdir)) print("Processing path:", path) os.chdir(path) for lin in lins: lineage_num = int(lin) target_file = os.path.join( "data", "cell_lines", "lineage{0:02d}.npy".format(lineage_num) ) cell_line = np.load(target_file) spot_plot.plot_images(cell_line, lineage_num) try: spot_plot.plot_graphs(cell_line, lineage_num) except AttributeError: print("ParA data missing") get_parA.main() cell_line = np.load(target_file) spot_plot.plot_graphs(cell_line, lineage_num) print("Generated plots for lineage {0}".format(lineage_num)) os.chdir(original_path)
def end(self, discard=False): if discard: plt.close() return # backup previous lineage file previous_file = "data/cell_lines/lineage{0:02d}.npy".format(self.lineage_num) if os.path.exists(previous_file): if not os.path.exists("data/cell_lines/backups"): os.mkdir("data/cell_lines/backups") backup_file = "data/cell_lines/backups/{0}-lineage{1:02d}.npy".format( datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d-%H%M"), self.lineage_num ) attempt = 2 while os.path.exists(backup_file): first = backup_file.split(".npy")[0] backup_file = "{0}.npy-{1}".format(first, attempt) attempt += 1 print("Backing up previous lineage file to {0}".format(backup_file)) os.rename(previous_file, backup_file) print("Saving new lineage file") np.save( "data/cell_lines/lineage{0:02d}".format(self.lineage_num), self.cell_line ) if self.GEN_PLOTS: print("Saving new PDFs") spot_plot.plot_images(self.cell_line, int(self.lineage_num)) spot_plot.plot_graphs(self.cell_line, int(self.lineage_num), um=True) spot_spread.gen_xl(self.cell_line, int(self.lineage_num)) plt.close(self.fig)