def test_pfba_batch_iml1515_baseline(self): fba_model = FBAModel(model_code='ecoli:iML1515') solution = fba_model.solve( alg='pfba', conditions=pd.read_csv( '../mscproject/simulation/data/perturbations.csv')) solution.to_csv('baseline/pfba_batch_iml1515.csv')
def test_fba_batch(self): fba_model = FBAModel() solution = fba_model.solve(conditions=pd.read_csv( '../mscproject/simulation/data/perturbations.csv')) baseline = pd.read_csv('baseline/fba_batch.csv', index_col=0) solution.columns = baseline.columns self.assertTrue(solution.equals(baseline))
def test_pfba_batch_baseline(self): fba_model = FBAModel() solution = fba_model.solve( alg='pfba', conditions=pd.read_csv( '../mscproject/simulation/data/perturbations.csv')) solution.to_csv('baseline/pfba_batch.csv')
def test_two_rounds_solve(self): fba_model = FBAModel() fba_model.model.reactions.get_by_id( 'BIOMASS_Ec_iJO1366_core_53p95M').bounds = 1, 1 fba_model.solve( alg='pfba', conditions=pd.read_csv( 'perturbations_small.csv')).to_csv('output/two_round.csv')
def test_pfba_batch_iml1515(self): fba_model = FBAModel(model_code='ecoli:iML1515') solution = fba_model.solve( alg='pfba', conditions=pd.read_csv( '../mscproject/simulation/data/perturbations.csv')) baseline = pd.read_csv('baseline/pfba_batch_iml1515.csv', index_col=0) solution.columns = baseline.columns self.assertTrue(solution.equals(baseline))
def run(model_code='ecoli:iJO1366'): model = FBAModel(model_code).model conditions = pd.read_csv('perturbations.csv') df = pd.DataFrame(columns=('met_id', 'e_met_id', 'p_met_id', 'c_met_id')) for _, condition in conditions.iterrows(): condition = condition.dropna() for met_id in condition: row = [met_id] e_met_id = met_id + '_e' if model.metabolites.has_id(e_met_id): row.append(e_met_id) else: row.append('-') p_met_id = met_id + '_p' if model.metabolites.has_id(p_met_id): row.append(p_met_id) else: row.append('-') c_met_id = met_id + '_c' if model.metabolites.has_id(c_met_id): row.append(c_met_id) else: row.append('-') df.loc[len(df), :] = row df = df.drop_duplicates() model_code = model_code.replace(':', '_') df.to_csv(f'output/{model_code}_check_metabolites.csv', index=False)
def run(model_code='ecoli:iJO1366', database='kegg'): fba_model = FBAModel(model_code) if fba_model.species == 'ecoli': gene_ids = pd.Series( [f'eco:{gene.id}:{gene.name}' for gene in fba_model.model.genes]) gene_ids = pd.concat([ gene_ids, ecoli_rnap_genes + ':', ecoli_rrna_genes + ':', ecoli_rpeptide_genes + ':' ]) gene_ids = gene_ids.sort_values() gene_ids = gene_ids.drop_duplicates() if database == 'kegg': nt_sequences = gene_ids.apply(get_from_kegg) nt_sequences.index = gene_ids.str.split(':').apply(lambda x: x[1]) nt_sequences = nt_sequences.dropna() nt_sequences.to_csv( f'{fba_model.species}/{fba_model.model_name}_nt_seq_kegg.csv', header=False)
def test_align_to_yangs(self): yangs_data = pd.read_csv('baseline/yangs_data.csv', index_col=0).round(decimals=2) pfba_data = FBAModel().solve( alg='pfba', conditions=pd.read_csv('perturbations_small.csv')) for _, condition in pd.read_csv('perturbations_small.csv').iterrows(): condition = condition.dropna() c_name = '-'.join(condition) x = yangs_data[c_name].to_frame() x = x[(x.T != 0).any()] y = pfba_data[c_name].to_frame() y = y[(y.T != 0).any()] align_df = pd.merge(x, y, left_on=x.index, right_on=y.index, how='outer', suffixes=('_yangs', '_ours')).fillna(0) align_df = align_df.set_index('key_0').sort_index() align_df.to_csv(f'output/align_{c_name}.csv')
def test_fba_small_baseline(self): fba_model = FBAModel() solution = fba_model.solve( conditions=pd.read_csv('perturbations_small.csv')) solution.to_csv('baseline/fba_small.csv')
def test_pfba_small(self): fba_model = FBAModel() solution = fba_model.solve( alg='pfba', conditions=pd.read_csv('perturbations_small.csv')) baseline = pd.read_csv('baseline/pfba_small.csv', index_col=0) self.assertTrue(solution.equals(baseline))
def test_small_sampling(self): sampling_model = FBAModel() solution = sampling_model.solve( conditions=pd.read_csv('perturbations_small.csv'), sampling_n=10000) solution.to_csv('baseline/sampling_small.csv')