Skip to content

Commit 5817177

Browse files
authored
Merge pull request #1 from behzadk/master
Merging BK updates
2 parents 77ca0e9 + 8d1bdee commit 5817177

File tree

8 files changed

+29
-75
lines changed

8 files changed

+29
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
venv/
22
*.pyc
33
*.pyo
4+
.idea/

README.MD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Automated equation generation of candidate models for synthetic microbial commun
44
AutoCD builds a equations for candidate model systems that can simulate the growth of bacteria capturing important interactions such as competition for nutrients, communication through quorum sensing and amensalism via bacteriocins. AutoCD performs model selection for a desired population level behaviour. AutoCD is intended to aide in the design of synthetic microbial systems, identfying promising candidate network topologies and essential parameters for controlling a microbial community.
55

66

7-
AutoCD is written in C++ and Python 3.4+, data analysis scripts require R. This has been tested on Linux only.
7+
AutoCD is written in C++ and Python 3.4+, data analysis scripts require R.
8+
9+
This software has been tested on Linux and designed for HPC, using OpenMP for parallel simulations.
810

911
## Requirements
1012

@@ -17,7 +19,7 @@ g++ (tested with g++-8)
1719
Boost >= v1.67
1820
OpenMP
1921

20-
Boost must be installed for the version of python being used to run AutoCD. Ensure boost has been correvtly added to paths. Run `build_test.sh` to test on a simple build example and identify issues with library flags and ensuring the correct Python includes. Changes should be made to `build_pop_modules.sh` which is used to the build necessarry Boost Python libarary for a newly generated model space.
22+
Boost must be installed for the version of python being used to run AutoCD. Ensure boost has been correctly added to paths. Run `build_test.sh` to test on a simple build example and identify issues with library flags and ensuring the correct Python includes. Changes should be made to `build_pop_modules.sh` which is used to the build necessary Boost Python libarary for a newly generated model space.
2123

2224
#### R packages: ####
2325
ggplot2, ggisoband, gridExtra, sm

data_analysis/NMF_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def nmf_decomposition(output_dir, adj_mat_dir, n_components=4):
354354
write_W_to_csv(W, model_idxs, W_csv_path)
355355

356356
H = model.components_
357-
H = H.reshape(n_components, 9, 11)
358-
# H = H.reshape(i, 7, 9)
357+
# H = H.reshape(n_components, 9, 11)
358+
H = H.reshape(n_components, 7, 9)
359359

360360
H_csv_path = figure_output_dir + "H_" + str(n_components) + ".csv"
361361
write_H_to_csv(H, H_csv_path, row_names, column_names, normalise=True)

data_analysis/data_analysis_ABCSMC.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ def generate_marginal_probability_boxplot(pop_dir_list, output_dir, hide_x_ticks
120120
ax.margins(y=0)
121121
fig.tight_layout()
122122
plt.show()
123-
# model_space_report_df.drop(model_space_report_df.filter(regex="Unname"),axis=1, inplace=True)
124-
# model_space_report_df = model_space_report_df.sort_values(by='model_idx', ascending=False).reset_index(drop=True)
125-
# print(model_space_report_df.columns)
126-
# model_space_report_list.append(model_space_report_df)
127123

128124

129125
def generate_marginal_probability_distribution(pop_dir_list, output_dir, hide_x_ticks=True, show_median=True, show_BF=False, drop_eqless=-1):
@@ -236,7 +232,6 @@ def plot_all_model_param_distributions(pop_dir, inputs_dir, figure_output_dir):
236232
model_space_report_path = pop_dir + "combined_model_space_report.csv"
237233
model_space_report_df = pd.read_csv(model_space_report_path, index_col=0)
238234
# generate_model_space_statistics(model_space_report_df, "model_marginal")
239-
print(list(model_space_report_df))
240235

241236
model_space_report_df.drop(model_space_report_df[model_space_report_df['model_marginal_mean'] == 0].index, inplace=True)
242237

@@ -660,10 +655,6 @@ def self_regulation_bar_plot(pop_dir_list, adj_mat_dir, output_dir, hide_x_ticks
660655
model_space_report_df = merge_model_space_report_df_list(model_space_report_list)
661656
generate_model_space_statistics(model_space_report_df, "model_marginal")
662657

663-
# total_accepted = sum(model_space_report_df['accepted_count'].values)
664-
# new_model_marginals = [x/total_accepted for x in model_space_report_df['accepted_count'].values]
665-
# model_space_report_df['model_marginal_mean'] = new_model_marginals
666-
667658
if drop_unnacepted:
668659
model_space_report_df.drop(model_space_report_df[model_space_report_df['model_marginal_mean'] == 0.0].index, inplace=True)
669660

@@ -716,21 +707,10 @@ def self_regulation_bar_plot(pop_dir_list, adj_mat_dir, output_dir, hide_x_ticks
716707
adjusted_vals.append(row['model_marginal_mean'])
717708
model_space_report_df['model_marginal_mean'] = adjusted_vals
718709
print(model_space_report_df)
719-
# if drop_unnacepted:
720-
# model_space_report_df.drop(model_space_report_df[model_space_report_df['symmetrical'] == False].index, inplace=True)
721-
# model_idxs = model_space_report_df['model_idx'].values
722-
# model_space_report_df = model_space_report_df.sort_values(by='model_marginal_mean', ascending=False).reset_index(drop=True)
723710
model_space_report_df.to_csv(output_dir + "dists_test.csv")
724711

725712
fig, ax = plt.subplots()
726713

727-
print(model_space_report_df)
728-
if num_pops > 1:
729-
pass
730-
# ax.errorbar(model_space_report_df.index,
731-
# model_space_report_df['model_marginal_mean'],
732-
# yerr=model_space_report_df['model_marginal_std'], fmt=',', color='black', alpha=1,
733-
# label=None, elinewidth=0.5)
734714

735715
sns.barplot(model_space_report_df.index, model_space_report_df.model_marginal_mean,
736716
data=model_space_report_df, alpha=0.9, ax=ax)

data_analysis/dens_plot_2D.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,6 @@ output_dir <- args[5]
722722
make_1d_plot <- args[6]
723723
make_2d_plot <- args[7]
724724

725-
# wd <- "/home/behzad/Documents/barnes_lab/cplusplus_software/speed_test/repressilator/cpp/"
726-
# data_dir <- paste(wd, "output/spock_manu_stable_1_SMC/spock_manu_stable_1_SMC_a1/Population_2/model_sim_params/", sep="")
727-
# inputs_data_dir <- paste(wd, "input_files/input_files_two_species_spock_manu_1/input_files/", sep="")
728725

729726
data_df <- read.csv(params_posterior_path)
730727

data_analysis/network_vis.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ def get_flat_adjacency_matricies_df(model_indexes, adj_matrix_path_template):
212212
adj_mat_path = adj_matrix_path_template.replace("#REF#", str(m_idx))
213213
adj_mat_df = pd.read_csv(adj_mat_path, index_col=0)
214214

215-
print(adj_mat_df)
216215
adj_mat_df = convert_QS_column(adj_mat_df)
217-
print(adj_mat_df)
218-
print(np.shape(adj_mat_df))
219-
exit()
220216
flat_adj_mats.append(abs(adj_mat_df.values).flatten())
221217

222218
interaction_indexes = ["a_" + str(i) for i in range(np.shape(flat_adj_mats)[1])]
@@ -237,9 +233,6 @@ def get_flat_adjacency_matricies_df(model_indexes, adj_matrix_path_template):
237233
adj_mat_df = adj_mat_df.loc[:, adj_mat_df.columns != col]
238234

239235

240-
print(np.shape(adj_mat_df))
241-
exit()
242-
243236
return adj_mat_df
244237

245238

@@ -744,34 +737,6 @@ def make_hierarchical_clustering(combined_analysis_output_dir, adj_mat_dir, drop
744737
plt.savefig(output_path, dpi=500, bbox_inches='tight', transparent=False)
745738
plt.close()
746739

747-
# print("Making posterior probability heatmap")
748-
# # Plot with posterior probability as heatmap
749-
# adj_mat_df['p_prob'] = model_space_report_df['model_marginal_mean'].values
750-
# linkage_data = adj_mat_df.loc[:, adj_mat_df.columns != 'p_prob'].values
751-
# linkage = hc.linkage(sp.distance.pdist(linkage_data), method='average', metric='euclidean')
752-
# cm = sns.clustermap(data=adj_mat_df['p_prob'], row_linkage=linkage, col_cluster=False, yticklabels=1)
753-
# pprob_row_colours = cm.row_colors
754-
# hm = cm.ax_heatmap.get_position()
755-
# cm.ax_heatmap.set_position([int_link_x, int_link_y0, int_link_width*0.1, int_link_height])
756-
757-
# # cm.ax_heatmap.set(yticklabels=[])
758-
# # cm.ax_heatmap.set(xticklabels=[])
759-
760-
# # cm.ax_heatmap.set(xlabel='')
761-
# # cm.ax_heatmap.set(ylabel='')
762-
# cm.ax_heatmap.tick_params(left=False, bottom=False, right=False)
763-
764-
# col = cm.ax_col_dendrogram.get_position()
765-
# cm.ax_heatmap.tick_params(left=False, bottom=False, right=False)
766-
767-
# cm.ax_row_dendrogram.set_visible(False)
768-
# cm.cax.set_visible(False)
769-
770-
# plt.setp(cm.ax_heatmap.yaxis.get_majorticklabels(), rotation=0)
771-
772-
# output_path = combined_analysis_output_dir + "pprob_dendrogram_" + str(max_level) + ".pdf"
773-
# plt.savefig(output_path, dpi=500, bbox_inches='tight', transparent=True)
774-
# plt.close()
775740

776741

777742
print("Making posterior probability barchart")
@@ -994,15 +959,6 @@ def main():
994959
for levels in [5]:
995960
make_hierarchical_clustering(combined_analysis_output_dir, adj_mat_dir, drop_eqless=-1, hide_x_ticks=True, max_level=levels, use_bar=True, plot_error=False, average_clusters=True, log_scale=True)
996961

997-
exit()
998-
make_model_network(combined_analysis_output_dir, adj_mat_dir, use_adjacent_neighbour=True)
999-
exit()
1000-
exit()
1001-
exit()
1002-
make_model_network(combined_analysis_output_dir, adj_mat_dir, use_nearest_neighbour=True)
1003-
1004-
make_model_network(combined_analysis_output_dir, adj_mat_dir, use_adjacent_neighbour=True, colour_by_motif=True)
1005-
make_model_network(combined_analysis_output_dir, adj_mat_dir, use_nearest_neighbour=True, colour_by_motif=True)
1006962

1007963
if __name__ == "__main__":
1008964
main()

data_analysis/run_data_analysis.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from . import data_analysis_ABCSMC as ABC_DA
99
from . import NMF_analysis
1010
from . import nearest_neighbours
11-
11+
from . import network_vis
1212

1313
def main(data_analysis_config):
1414
experiment_name = data_analysis_config['experiment_name']
@@ -31,11 +31,12 @@ def main(data_analysis_config):
3131
# Get final population directories of each repeat experiment
3232
final_pop_dirs = ABC_DA.find_latest_pop_dirs(exp_dir)
3333

34+
3435
model_space_report_df = ABC_DA.write_combined_model_space_report(finished_exp_final_population_dirs, combined_analysis_output_dir)
3536
model_space_report_df = ABC_DA.write_combined_model_space_with_motif_counts(finished_exp_final_population_dirs, combined_analysis_output_dir, adj_mat_dir, window=0, normalise=False, plot=False)
3637

37-
ABC_DA.generate_marginal_probability_distribution(finished_exp_final_population_dirs,
38-
combined_analysis_output_dir, hide_x_ticks=True, show_median=False, show_BF=False, drop_eqless=-1)
38+
network_vis.make_hierarchical_clustering(combined_analysis_output_dir, adj_mat_dir, drop_eqless=-1, hide_x_ticks=True, max_level=1000,
39+
use_bar=True, plot_error=True, average_clusters=False, log_scale=False)
3940

4041
ABC_DA.generate_marginal_probability_distribution(finished_exp_final_population_dirs,
4142
combined_analysis_output_dir, hide_x_ticks=True, show_median=False, show_BF=False, drop_eqless=-1)
@@ -44,7 +45,11 @@ def main(data_analysis_config):
4445
combined_analysis_output_dir, drop_eqless=-1,
4546
show_median=False, hide_x_ticks=False)
4647

48+
nearest_neighbours.get_motif_neighbours(combined_analysis_output_dir, load_pickle=False, remove_zero_change=True)
49+
NMF_analysis.nmf_decomposition(combined_analysis_output_dir, adj_mat_dir)
4750
ABC_DA.combine_model_params(finished_exp_final_population_dirs, combined_analysis_output_dir)
4851
ABC_DA.plot_all_model_param_distributions(combined_analysis_output_dir, inputs_dir, combined_analysis_output_dir + "dist_plots/")
4952

50-
nearest_neighbours.get_motif_neighbours(combined_analysis_output_dir, load_pickle=False, remove_zero_change=True)
53+
54+
55+

run_AutoCD.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def main():
4646
experiment_config = yaml.load(yaml_file, Loader=yaml.FullLoader)
4747

4848
module_path = experiment_config['population_modules_path']
49+
if os.path.isfile(module_path) and os.access(module_path, os.R_OK):
50+
print("population.modules.so exists...")
51+
52+
else:
53+
print("population.modules.so missing, attempting to build... ")
54+
build_file_path = "./build_pop_modules.sh"
55+
build_arguments = MSG_config['output_dir'] + MSG_config['model_space_name'] + '/'
56+
57+
# Call build for C++ modules, first argument
58+
# pointing to where model.cpp and model.h are
59+
subprocess.check_call([build_file_path, build_arguments])
60+
61+
4962
# Copy population_modules.so to ABC folder
5063
copy(module_path, './ABC/')
5164

0 commit comments

Comments
 (0)