def generate_categorization_report(sa, reports_folder, category_dict, categories_to_print=[]): """ Method to generate categorization report :param sa: SimulationAnalyzer object :param reports_folder: path to the save the report to :param category_dict: dictionary with reaction category as the key and list of reactions as the value :param categories_to_print: list of reaction types to print, if "[]" all reaction types will be printed """ if categories_to_print == []: categories_to_print = list(category_dict.keys()) with open( reports_folder + "/categorization.tex", "w", ) as f: generate_latex_header(f) for rxn_type, reactions in category_dict.items(): f.write("\n\n\n") str_type = str("Reaction Type: " + rxn_type + " count: " + str(len(reactions))).replace("_", " ") f.write(str_type) if rxn_type in categories_to_print: f.write("\n\n\n") for reaction_index in reactions: sa.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def pathfinding_path_report(folder: str, rn: ReactionNetwork, paths): entries_dict = {} for entry in rn.entries_list: entries_dict[entry.parameters["ind"]] = entry if not os.path.isdir(folder): os.mkdir(folder) visualize_molecules(folder + "/molecule_diagrams", entries_dict) pathways = [] for reaction_path in paths: pathway = [] cost = reaction_path["cost"] for node in reaction_path["full_path"]: if type(node) == str: dG = rn.graph.nodes[node]["free_energy"] pathway.append(reaction_string_to_dict(node, dG)) pathways.append((cost, pathway)) with open(folder + "/pathway_report.tex", "w") as f: generate_latex_header(f) count = 1 for cost, pathway in pathways: f.write("pathway " + str(count) + "\n\n") f.write("pathway cost: " + str(cost) + "\n\n") for reaction in pathway: latex_emit_reaction(f, reaction) f.write("\\newpage\n") count += 1 generate_latex_footer(f)
def generate_list_of_all_species_report(self): with open( self.reports_folder + "/list_of_all_species.tex", "w", ) as f: generate_latex_header(f) for species_index in range(self.number_of_species): f.write("\n\n\n") latex_emit_molecule(f, species_index) generate_latex_footer(f)
def generate_list_of_all_reactions_report(self): with open( self.reports_folder + "/list_of_all_reactions.tex", "w", ) as f: generate_latex_header(f) for reaction_index in range(self.number_of_reactions): f.write("\n\n\n") self.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def generate_consumption_report(self, mol_entry: MoleculeEntry): target_species_index = mol_entry.parameters["ind"] ( producing_reactions, consuming_reactions, final_counts, ) = self.extract_species_consumption_info(target_species_index) histogram_file = (self.reports_folder + "/final_count_histogram_" + str(target_species_index) + ".pdf") visualize_molecule_count_histogram(final_counts, histogram_file) with open( self.reports_folder + "/consumption_report_" + str(target_species_index) + ".tex", "w", ) as f: generate_latex_header(f) f.write("consumption report for") latex_emit_molecule(f, target_species_index) f.write("\n\n") f.write("molecule frequency at end of simulations") f.write("\\raisebox{-.5\\height}{" + "\\includegraphics[scale=0.5]{" + "./final_count_histogram_" + str(target_species_index) + ".pdf" + "}}\n\n") f.write("producing reactions:\n\n\n") for reaction_index, frequency in sorted( producing_reactions.items(), key=lambda item: -item[1]): f.write(str(frequency) + " occurrences:\n") self.latex_emit_reaction(f, reaction_index) f.write("consuming reactions:\n\n\n") for reaction_index, frequency in sorted( consuming_reactions.items(), key=lambda item: -item[1]): f.write(str(frequency) + " occurrences:\n") self.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def generate_simulation_history_report(self, history_num): with open( self.reports_folder + "/simulation_history_report_" + str(history_num) + ".tex", "w", ) as f: generate_latex_header(f) f.write("simulation " + str(history_num)) f.write("\n\n\n") for reaction_index in self.reaction_histories[history_num]: f.write("\n\n\n") self.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def generate_reaction_tally_report(self, cutoff: int): self.compute_reaction_tally() with open(self.reports_folder + "/reaction_tally_report.tex", "w") as f: generate_latex_header(f) f.write("reaction tally report") f.write("\n\n\n") for (reaction_index, number) in sorted(self.observed_reactions.items(), key=lambda pair: -pair[1]): if number > cutoff: f.write(str(number) + " occourances of:") self.latex_emit_reaction(f, reaction_index) generate_latex_footer(f)
def generate_pathway_report(self, mol_entry: MoleculeEntry, min_frequency: int): target_species_index = mol_entry.parameters["ind"] if target_species_index not in self.reaction_pathways_dict: self.extract_reaction_pathways(target_species_index) with open( self.reports_folder + "/pathway_report_" + str(target_species_index) + ".tex", "w", ) as f: pathways = self.reaction_pathways_dict[target_species_index] generate_latex_header(f) f.write("pathway report for\n\n") latex_emit_molecule(f, target_species_index) self.latex_emit_initial_state(f) f.write("\\newpage\n\n\n") for _, unique_pathway in sorted( pathways.items(), key=lambda item: -item[1]["frequency"]): frequency = unique_pathway["frequency"] if frequency > min_frequency: f.write(str(frequency) + " occurrences:\n") for reaction_index in unique_pathway["pathway"]: self.latex_emit_reaction(f, reaction_index) f.write("\\newpage\n") else: break generate_latex_footer(f)
def generate_pathway_report(self, mol_entry: MoleculeEntry, number_of_pathways=100, sort_by_frequency=True): target_species_index = mol_entry.parameters["ind"] if target_species_index not in self.reaction_pathways_dict: self.extract_reaction_pathways(target_species_index) if sort_by_frequency: suffix = "frequency" else: suffix = "cost" with open( self.reports_folder + "/pathway_report_" + str(target_species_index) + "_" + suffix + ".tex", "w", ) as f: pathways = self.reaction_pathways_dict[target_species_index] generate_latex_header(f) f.write("pathway report for\n\n") latex_emit_molecule(f, target_species_index) if sort_by_frequency: f.write("\n\ntop " + str(number_of_pathways) + " pathways sorted by frequency") else: f.write("\n\ntop " + str(number_of_pathways) + " pathways sorted by cost") f.write("\\vspace{1cm}") self.latex_emit_initial_state(f) f.write("\\newpage\n\n\n") if sort_by_frequency: def sort_function(item): return -item[1]["frequency"] else: def sort_function(item): return item[1]["weight"] count = 1 for _, unique_pathway in sorted(pathways.items(), key=sort_function): frequency = unique_pathway["frequency"] weight = unique_pathway["weight"] f.write("pathway " + str(count) + "\n\n") f.write("path weight: " + str(weight) + "\n\n") f.write(str(frequency) + " occurrences:\n") for reaction_index in unique_pathway["pathway"]: self.latex_emit_reaction(f, reaction_index) f.write("\\newpage\n") count += 1 if count > number_of_pathways: break generate_latex_footer(f)