def loadFromFiles(self, reactions_file, metabs_file, matrix_file): reaction_ids, reactions = read_file_rm(reactions_file) metab_ids, _ = read_file_rm(metabs_file) matrix = read_file_mat(matrix_file) gmr = MyGraph() for metab in metab_ids: gmr.add_node(metab) for reaction in reaction_ids: gmr.add_node(reaction) for index_metabolite, index_reaction, coeficient_value in matrix: metab_id = metab_ids[index_metabolite] reaction_id = reaction_ids[index_reaction] reaction_rev = reactions[reaction_id][0] if coeficient_value > 0 or reaction_rev < 0: gmr.add_edge(reaction_id, metab_id) if coeficient_value < 0 or reaction_rev < 0: gmr.add_edge(metab_id, reaction_id) if self.net_type == 'metabolite-reaction': self.g = gmr.g else: self.g = {}
def perg1(metab,reac,bounds,mat): print("\nPergunta 1\n") gmr = MyGraph({}) for m in metab: gmr.add_node(m) for r in reac: gmr.add_node(r) for e in mat: met_index = int(e[0]) met_id = metab[met_index] reac_index = int(e[1]) reac_id = reac[reac_index] reac_rev = float(bounds[reac_id][0]) sign = float(e[2]) if sign > 0 or reac_rev < 0: gmr.add_edge(reac_id,met_id) if sign < 0 or reac_rev < 0: gmr.add_edge(met_id, reac_id) print("\nGrafo concluído\n--------------------------") return gmr