-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathend_to_end_pipeline.py
More file actions
174 lines (158 loc) · 6.99 KB
/
Copy pathend_to_end_pipeline.py
File metadata and controls
174 lines (158 loc) · 6.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import logging
from pathlib import Path
import mlflow
from experiment_scripts import save_files_for_wgcna_cutting, \
do_coherence_with_stat_tests, analyse_go_enrichments_find_enrichment, \
from_expr_mat_time_to_ode, save_supp_table_go_enrichments, \
pypesto_from_sbml
from figure_pipelines import see_gene_module_sizes
from expr_mat_factories import expr_mat_time_factory
from helpers import one_gene_list_file_per_cluster, config_preprocess
def full_pipeline_prototype(experiment_path: Path):
"""Main script: do all processing from input data to output model in one go"""
skip_slow_steps = True
for treatment_name in ['heat']:
# for treatment_name in ['drought']:
# for treatment_name in ['drought', 'heat']:
logging.info(f'Doing {treatment_name}')
treatment_path = experiment_path / treatment_name
data_params, hyper_params, experiment_params = config_preprocess(
treatment_path)
# # Uncomment to only save files
# with mlflow.start_run(
# description=experiment_params['description']):
# mlflow.log_params(data_params)
# mlflow.log_params(hyper_params)
# mlflow.set_tags(experiment_params)
# mlflow.log_artifact(
# str(treatment_path / 'figs'))
# mlflow.log_artifact(
# str(treatment_path / 'petab_files'))
# mlflow.log_artifact(
# str(treatment_path / 'pypesto_results.hdf5'))
# mlflow.log_artifact(
# str(treatment_path / 'log.log'))
# # mlflow.log_artifact(
# # str(treatment_path / 'go_terms_supp_table.csv'))
# continue
if not skip_slow_steps:
expr_mat_all_genes = expr_mat_time_factory(
treatment_path,
data_params['soft_path'],
hyper_params['agg_method'],
hyper_params['do_log2'],
gpl_path=data_params.get('gpl_path', None)
)
expr_mat_all_genes.save_for_limma(treatment_path / '01_input_for_limma.csv')
# ## Here: run limma script (limma_de_selection/de_selection.R) ##
# continue
# Select only the DE genes
de_file_path = list(treatment_path.glob('02[a_]*.csv'))
assert len(de_file_path) == 1
de_file_path = str(de_file_path[0])
expr_mat_time = expr_mat_time_factory(
treatment_path,
de_file_path,
hyper_params['agg_method'],
hyper_params['do_log2'],
gpl_path=None)
#
expr_mat_time.merge_biological_samples()
# # Read DE genes from limma output and get the ATTED/Merged/Local scores
# g = sns.clustermap(a.iloc[:2000, :2000], cmap='coolwarm', cbar_pos=None,
# dendrogram_ratio=0);
# g.ax_heatmap.set_xticks([]);
# g.ax_heatmap.set_yticks([]);
# plt.tight_layout();
# # plt.show()
skip_slow_steps = True
if not skip_slow_steps:
save_files_for_wgcna_cutting(treatment_path, data_params, expr_mat_time)
# continue
## Here: run wgcna cutting script (r_wgcna_dyntreecut/dyntreecut.R) ##
# continue
see_gene_module_sizes(expr_mat_time,
cut_modules_path=treatment_path / 'dyntreecut_output',
figure_path=treatment_path / 'figs')
skip_slow_steps = True
if not skip_slow_steps:
one_gene_list_file_per_cluster(
in_dir=treatment_path / 'dyntreecut_output',
out_dir=treatment_path / 'split_by_module',
use_for_analysis_func=lambda x: True
)
# Also generate random clusters that have the same size as a representative of these clusters
skip_slow_steps = True
if not skip_slow_steps:
expr_mat_time.save_random_modules_for_goa_find_enrichment(
wgcna_label_file=treatment_path
/ 'dyntreecut_output'
/ 'combined_sum_dists_wgcna_clustered_ds1.csv',
out_dir=treatment_path / 'split_by_module'
)
skip_slow_steps = True
# Coherence
if not skip_slow_steps:
do_coherence_with_stat_tests(
in_dir=treatment_path / 'split_by_module',
expr_mat_time=expr_mat_time,
out_dir=treatment_path / 'figs',
do_stat_test=False
)
# continue
# Do GO enrichment
### RUN SNAKEMAKE ###
# snakemake -s ../../../../snakemake_workflows/Snakefile_wgcna_deepsplit_go_terms -r -c5 -k
go_enrich_output_path = (
treatment_path
/ 'go_outputs_exp_evidence_only_background_de_genes'
)
skip_slow_steps = True
if not skip_slow_steps:
analyse_go_enrichments_find_enrichment(
go_enrich_output_path,
treatment_path / 'figs',
do_annotations=False
)
# continue
# with mlflow.start_run(
# description=experiment_params['description']):
# mlflow.log_params(data_params)
# mlflow.log_params(hyper_params)
# mlflow.set_tags(experiment_params)
# mlflow.log_artifact(
# str(treatment_path / 'figs'))
# continue
sbml_path = treatment_path / 'module_network.xml'
skip_slow_steps = False
if not skip_slow_steps:
# ODE modelling steps
my_ode = from_expr_mat_time_to_ode(data_params, treatment_path,
expr_mat_time, hyper_params)
# These are parameters that are different between the two datasets
u_t_function = 'temp' if treatment_name == 'heat' \
else 'drought * time / 13'
my_ode.save_to_sbml(sbml_path,
u_t_function)
skip_slow_steps = True
if not skip_slow_steps:
# Save GO enrich files into one file
expr_mat_pickl_path = treatment_path / 'expr_mat_time.pkl'
save_supp_table_go_enrichments(expr_mat_pickl_path,
go_enrich_output_path,
treatment_path)
#
# # This is done on server now
# pypesto_from_sbml(treatment_path,
# treatment_name,
# treatment_path / 'expr_mat_time.pkl',
# sbml_path,
# )
# use_best_params_as_init= treatment_path / 'pypesto_results.hdf5')
with mlflow.start_run(
description=experiment_params['description']):
mlflow.log_params(data_params)
mlflow.log_params(hyper_params)
mlflow.set_tags(experiment_params)
mlflow.log_artifact(
str(treatment_path / 'figs'))