|
a |
|
b/notebooks/papermill_test.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "code", |
|
|
5 |
"execution_count": 1, |
|
|
6 |
"metadata": { |
|
|
7 |
"tags": [] |
|
|
8 |
}, |
|
|
9 |
"outputs": [], |
|
|
10 |
"source": [ |
|
|
11 |
"%load_ext autoreload\n", |
|
|
12 |
"%autoreload 2\n", |
|
|
13 |
"\n", |
|
|
14 |
"%matplotlib inline" |
|
|
15 |
] |
|
|
16 |
}, |
|
|
17 |
{ |
|
|
18 |
"cell_type": "code", |
|
|
19 |
"execution_count": 2, |
|
|
20 |
"metadata": {}, |
|
|
21 |
"outputs": [], |
|
|
22 |
"source": [ |
|
|
23 |
"import os, sys\n", |
|
|
24 |
"import subprocess" |
|
|
25 |
] |
|
|
26 |
}, |
|
|
27 |
{ |
|
|
28 |
"cell_type": "code", |
|
|
29 |
"execution_count": 3, |
|
|
30 |
"metadata": {}, |
|
|
31 |
"outputs": [], |
|
|
32 |
"source": [ |
|
|
33 |
"import pylab as plt\n", |
|
|
34 |
"import matplotlib\n", |
|
|
35 |
"\n", |
|
|
36 |
"import numpy as np\n", |
|
|
37 |
"import pandas as pd" |
|
|
38 |
] |
|
|
39 |
}, |
|
|
40 |
{ |
|
|
41 |
"cell_type": "code", |
|
|
42 |
"execution_count": 4, |
|
|
43 |
"metadata": {}, |
|
|
44 |
"outputs": [], |
|
|
45 |
"source": [ |
|
|
46 |
"import papermill as pm" |
|
|
47 |
] |
|
|
48 |
}, |
|
|
49 |
{ |
|
|
50 |
"cell_type": "code", |
|
|
51 |
"execution_count": 5, |
|
|
52 |
"metadata": {}, |
|
|
53 |
"outputs": [], |
|
|
54 |
"source": [ |
|
|
55 |
"sys.path.append('..')" |
|
|
56 |
] |
|
|
57 |
}, |
|
|
58 |
{ |
|
|
59 |
"cell_type": "code", |
|
|
60 |
"execution_count": 6, |
|
|
61 |
"metadata": {}, |
|
|
62 |
"outputs": [], |
|
|
63 |
"source": [ |
|
|
64 |
"from pyMultiOmics.common import create_if_not_exist" |
|
|
65 |
] |
|
|
66 |
}, |
|
|
67 |
{ |
|
|
68 |
"cell_type": "markdown", |
|
|
69 |
"metadata": {}, |
|
|
70 |
"source": [ |
|
|
71 |
"# Execute notebook" |
|
|
72 |
] |
|
|
73 |
}, |
|
|
74 |
{ |
|
|
75 |
"cell_type": "code", |
|
|
76 |
"execution_count": 7, |
|
|
77 |
"metadata": {}, |
|
|
78 |
"outputs": [ |
|
|
79 |
{ |
|
|
80 |
"data": { |
|
|
81 |
"text/plain": [ |
|
|
82 |
"'/Users/joewandy/Work/git/pyMultiOmics/templates/cic_template.ipynb'" |
|
|
83 |
] |
|
|
84 |
}, |
|
|
85 |
"execution_count": 7, |
|
|
86 |
"metadata": {}, |
|
|
87 |
"output_type": "execute_result" |
|
|
88 |
} |
|
|
89 |
], |
|
|
90 |
"source": [ |
|
|
91 |
"input_notebook = os.path.abspath(os.path.join('..', 'templates', 'cic_template.ipynb'))\n", |
|
|
92 |
"input_notebook" |
|
|
93 |
] |
|
|
94 |
}, |
|
|
95 |
{ |
|
|
96 |
"cell_type": "code", |
|
|
97 |
"execution_count": 8, |
|
|
98 |
"metadata": {}, |
|
|
99 |
"outputs": [ |
|
|
100 |
{ |
|
|
101 |
"data": { |
|
|
102 |
"text/plain": [ |
|
|
103 |
"('/Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results/cic_analysis.ipynb',\n", |
|
|
104 |
" '/Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results/cic_analysis.pdf')" |
|
|
105 |
] |
|
|
106 |
}, |
|
|
107 |
"execution_count": 8, |
|
|
108 |
"metadata": {}, |
|
|
109 |
"output_type": "execute_result" |
|
|
110 |
} |
|
|
111 |
], |
|
|
112 |
"source": [ |
|
|
113 |
"output_dir = 'temp_results'\n", |
|
|
114 |
"create_if_not_exist(output_dir)\n", |
|
|
115 |
"\n", |
|
|
116 |
"output_notebook = os.path.abspath(os.path.join(output_dir, 'cic_analysis.ipynb'))\n", |
|
|
117 |
"output_pdf = os.path.abspath(os.path.join(output_dir, 'cic_analysis.pdf'))\n", |
|
|
118 |
"output_notebook, output_pdf" |
|
|
119 |
] |
|
|
120 |
}, |
|
|
121 |
{ |
|
|
122 |
"cell_type": "code", |
|
|
123 |
"execution_count": 9, |
|
|
124 |
"metadata": {}, |
|
|
125 |
"outputs": [], |
|
|
126 |
"source": [ |
|
|
127 |
"params = {\n", |
|
|
128 |
" \n", |
|
|
129 |
" # the input file name (excel)\n", |
|
|
130 |
" 'file_name': '/Users/joewandy/Library/CloudStorage/OneDrive-UniversityofGlasgow/CiC_Affinity_Biomarkers/data_group_clustering.xlsx',\n", |
|
|
131 |
" \n", |
|
|
132 |
" # parameters for feature normalisation\n", |
|
|
133 |
" 'normalise': 'minmax',\n", |
|
|
134 |
" 'log': True,\n", |
|
|
135 |
" \n", |
|
|
136 |
" # parameters for case-control analysis\n", |
|
|
137 |
" 'case_group': 'disease',\n", |
|
|
138 |
" 'control_group': 'control',\n", |
|
|
139 |
" \n", |
|
|
140 |
" # parameters for case-control results\n", |
|
|
141 |
" 'p_value_thresh': 0.05,\n", |
|
|
142 |
" 'fc_iqr_thresh': 1.5,\n", |
|
|
143 |
" 'top_n': 10\n", |
|
|
144 |
" \n", |
|
|
145 |
"}" |
|
|
146 |
] |
|
|
147 |
}, |
|
|
148 |
{ |
|
|
149 |
"cell_type": "code", |
|
|
150 |
"execution_count": 10, |
|
|
151 |
"metadata": {}, |
|
|
152 |
"outputs": [ |
|
|
153 |
{ |
|
|
154 |
"data": { |
|
|
155 |
"text/plain": [ |
|
|
156 |
"{'file_name': '/Users/joewandy/Library/CloudStorage/OneDrive-UniversityofGlasgow/CiC_Affinity_Biomarkers/data_group_clustering.xlsx',\n", |
|
|
157 |
" 'normalise': 'minmax',\n", |
|
|
158 |
" 'log': True,\n", |
|
|
159 |
" 'case_group': 'disease',\n", |
|
|
160 |
" 'control_group': 'control',\n", |
|
|
161 |
" 'p_value_thresh': 0.05,\n", |
|
|
162 |
" 'fc_iqr_thresh': 1.5,\n", |
|
|
163 |
" 'top_n': 10}" |
|
|
164 |
] |
|
|
165 |
}, |
|
|
166 |
"execution_count": 10, |
|
|
167 |
"metadata": {}, |
|
|
168 |
"output_type": "execute_result" |
|
|
169 |
} |
|
|
170 |
], |
|
|
171 |
"source": [ |
|
|
172 |
"params" |
|
|
173 |
] |
|
|
174 |
}, |
|
|
175 |
{ |
|
|
176 |
"cell_type": "code", |
|
|
177 |
"execution_count": 11, |
|
|
178 |
"metadata": {}, |
|
|
179 |
"outputs": [ |
|
|
180 |
{ |
|
|
181 |
"data": { |
|
|
182 |
"application/vnd.jupyter.widget-view+json": { |
|
|
183 |
"model_id": "7fc5f06355244b9b98dc3bf91ea5dafe", |
|
|
184 |
"version_major": 2, |
|
|
185 |
"version_minor": 0 |
|
|
186 |
}, |
|
|
187 |
"text/plain": [ |
|
|
188 |
"Executing: 0%| | 0/37 [00:00<?, ?cell/s]" |
|
|
189 |
] |
|
|
190 |
}, |
|
|
191 |
"metadata": {}, |
|
|
192 |
"output_type": "display_data" |
|
|
193 |
} |
|
|
194 |
], |
|
|
195 |
"source": [ |
|
|
196 |
"_ = pm.execute_notebook(input_notebook, output_notebook, report_mode=True, parameters=params)" |
|
|
197 |
] |
|
|
198 |
}, |
|
|
199 |
{ |
|
|
200 |
"cell_type": "code", |
|
|
201 |
"execution_count": 12, |
|
|
202 |
"metadata": {}, |
|
|
203 |
"outputs": [ |
|
|
204 |
{ |
|
|
205 |
"name": "stdout", |
|
|
206 |
"output_type": "stream", |
|
|
207 |
"text": [ |
|
|
208 |
"\n", |
|
|
209 |
"[NbConvertApp] Converting notebook /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results/cic_analysis.ipynb to pdf\n", |
|
|
210 |
"[NbConvertApp] Support files will be in /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results/cic_analysis_files/\n", |
|
|
211 |
"[NbConvertApp] Making directory /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results\n", |
|
|
212 |
"[NbConvertApp] Making directory /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results\n", |
|
|
213 |
"[NbConvertApp] Making directory /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results\n", |
|
|
214 |
"[NbConvertApp] Making directory /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results\n", |
|
|
215 |
"[NbConvertApp] Writing 26073 bytes to notebook.tex\n", |
|
|
216 |
"[NbConvertApp] Building PDF\n", |
|
|
217 |
"[NbConvertApp] Running xelatex 3 times: ['xelatex', 'notebook.tex', '-quiet']\n", |
|
|
218 |
"[NbConvertApp] Running bibtex 1 time: ['bibtex', 'notebook']\n", |
|
|
219 |
"[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations\n", |
|
|
220 |
"[NbConvertApp] PDF successfully created\n", |
|
|
221 |
"[NbConvertApp] Writing 887703 bytes to /Users/joewandy/Work/git/pyMultiOmics/notebooks/temp_results/cic_analysis.pdf\n", |
|
|
222 |
"\n" |
|
|
223 |
] |
|
|
224 |
} |
|
|
225 |
], |
|
|
226 |
"source": [ |
|
|
227 |
"command = ['jupyter', 'nbconvert', '--TemplateExporter.exclude_input=True', '--output', output_pdf, '--to', 'pdf', output_notebook]\n", |
|
|
228 |
"result = subprocess.run(command, capture_output=True, text=True)\n", |
|
|
229 |
"print(result.stdout)\n", |
|
|
230 |
"print(result.stderr)" |
|
|
231 |
] |
|
|
232 |
} |
|
|
233 |
], |
|
|
234 |
"metadata": { |
|
|
235 |
"kernelspec": { |
|
|
236 |
"display_name": "Python 3 (ipykernel)", |
|
|
237 |
"language": "python", |
|
|
238 |
"name": "python3" |
|
|
239 |
}, |
|
|
240 |
"language_info": { |
|
|
241 |
"codemirror_mode": { |
|
|
242 |
"name": "ipython", |
|
|
243 |
"version": 3 |
|
|
244 |
}, |
|
|
245 |
"file_extension": ".py", |
|
|
246 |
"mimetype": "text/x-python", |
|
|
247 |
"name": "python", |
|
|
248 |
"nbconvert_exporter": "python", |
|
|
249 |
"pygments_lexer": "ipython3", |
|
|
250 |
"version": "3.10.1" |
|
|
251 |
} |
|
|
252 |
}, |
|
|
253 |
"nbformat": 4, |
|
|
254 |
"nbformat_minor": 4 |
|
|
255 |
} |