|
32 | 32 | 'Outcome']) |
33 | 33 | p180_network = plt.imread(savepath + |
34 | 34 | 'CytoscapeInput-edges-brown-blue-yellow.png') |
35 | | -#nmr_network = plt.imread(savepath + |
36 | | -# 'CytoscapeInput-edges-green-turquoise.txt.png') |
| 35 | +nmr_network = plt.imread(savepath + |
| 36 | + 'CytoscapeInput-edges-brown-turquoise.png') |
37 | 37 |
|
38 | 38 |
|
39 | 39 | #### Figure 1 : PLS-DA #### |
|
161 | 161 |
|
162 | 162 |
|
163 | 163 | #### FIGURE 4: NMR platform #### |
| 164 | +## Set Figure |
164 | 165 | fig = plt.figure(figsize = (12,12)) |
165 | | -fig.suptitle('Sex differences in NMR platform', fontsize=18) |
166 | | -ax1 = fig.add_subplot(221) |
167 | | -ax2 = fig.add_subplot(222) |
168 | | -ax3 = fig.add_subplot(223) |
169 | | -ax4 = fig.add_subplot(224) |
| 166 | +fig.suptitle('Sex differences in metabolite modules\n(NMR platform)', |
| 167 | + fontsize=18) |
| 168 | +gs = gridspec.GridSpec(2, 2, wspace=space) |
| 169 | +axs = [] |
| 170 | +axs.append(fig.add_subplot(gs[0:,0])) |
| 171 | +for row in range(2): |
| 172 | + axs.append(fig.add_subplot(gs[row,1])) |
170 | 173 |
|
171 | | -# AX1: forest plot |
| 174 | +## Forest Plot ## |
172 | 175 | plots.female_male_forest(results_nmr_modules, |
173 | 176 | color_pastel, |
174 | | - ax1) |
175 | | - |
176 | | -# AX2: network |
177 | | -ax2.imshow(nmr_network, |
178 | | - aspect='auto') |
179 | | -ax2.axis('off') |
180 | | -ax2.set_title('Green and turquoise metabolite modules') |
| 177 | + axs[0]) |
181 | 178 |
|
182 | | -# AX3: scatter plot Component 1 |
183 | | -plots.female_male_scatter(results_nmr, |
184 | | - ['green', 'turquoise'], |
185 | | - 'Component 1', |
186 | | - ax3) |
| 179 | +## Network image ## |
| 180 | +axs[1].imshow(nmr_network) |
| 181 | +axs[1].axis('off') |
| 182 | +axs[1].set_title('Brown and turquoise\nmetabolite modules') |
187 | 183 |
|
188 | | -# AX4: scatter plot Component 2 |
| 184 | +## Scatter Plot Single Metabolites ## |
189 | 185 | plots.female_male_scatter(results_nmr, |
190 | | - ['green', 'turquoise'], |
191 | | - 'Component 2', |
192 | | - ax4) |
193 | | -# Annotate labels |
194 | | -axes = [ax1, |
195 | | - ax2, |
196 | | - ax3, |
197 | | - ax4] |
198 | | -for i, label in enumerate(('A', 'B', 'C', 'D')): |
199 | | - axes[i].text(-0.05, 1.1, |
200 | | - label, |
201 | | - transform=axes[i].transAxes, |
202 | | - fontsize=16, |
203 | | - fontweight='bold', |
204 | | - va='top', |
205 | | - ha='right') |
206 | | - |
207 | | -for ext in file_extensions: |
208 | | - filename = savepath +\ |
209 | | - 'Figure4' +\ |
210 | | - ext |
211 | | - plt.savefig(filename, |
212 | | - dpi=300) |
213 | | - |
214 | | -#### SUPP FIG 2 #### |
215 | | -# PLS-DA scatter plots # |
216 | | - |
217 | | -def score_plot(ax, |
218 | | - percents:list, |
219 | | - components:list=['Component 1', 'Component 2']): |
220 | | - ''' |
221 | | - Generate a scatter plot from PLS-DA scores |
222 | | -
|
223 | | - Parameters |
224 | | - ---------- |
225 | | - components: list of str |
226 | | - Name of Components to plot. Must match score column names |
227 | | - percents: list of str |
228 | | - Percentages to use for axis names |
229 | | - ax: ax |
230 | | - Matplotlib ax to use |
231 | | - ''' |
232 | | - font_ax_title = 16 |
233 | | - font_axis = 12 |
234 | | - ax.set_xlabel(components[0] + ' ' + percents[0], |
235 | | - fontsize = font_axis) |
236 | | - ax.set_ylabel(components[1] + ' ' + percents[1], |
237 | | - fontsize = font_axis) |
238 | | - ax.set_title('Scores', |
239 | | - fontsize = font_ax_title) |
240 | | - targets = ['CN', |
241 | | - 'MCI', |
242 | | - 'AD'] |
243 | | - c = 0 |
244 | | - for target in targets: |
245 | | - indicesToKeep = qtpad.data['DX.bl'] == target |
246 | | - ax.scatter(qtpad.scores.loc[indicesToKeep, |
247 | | - components[0]], |
248 | | - qtpad.scores.loc[indicesToKeep, |
249 | | - components[1]], |
250 | | - color = color_pastel(c), |
251 | | - s = 50, |
252 | | - alpha = 0.6) |
253 | | - c = c + 1 |
254 | | - ax.legend(targets) |
255 | | - |
256 | | -def weight_plot(ax, |
257 | | - percents:list, |
258 | | - weights:list=['Weight 1', 'Weight 2'], |
259 | | - offset:dict=None): |
260 | | - ''' |
261 | | - Plot the weights of phenotypes and diagnosis |
262 | | -
|
263 | | - Parameters |
264 | | - ---------- |
265 | | - components: list of str |
266 | | - Name of Components to plot. Must match score column names |
267 | | - percents: list of str |
268 | | - Percentages to use for axis names |
269 | | - ax: ax |
270 | | - Matplotlib ax to use |
271 | | - offset: dict |
272 | | - Phenotype offset dict to change annotation possition. |
273 | | - E.g. {'Ventricles': (-10, 10)} |
274 | | - ''' |
275 | | - font_ax_title = 16 |
276 | | - font_axis = 12 |
277 | | - components = [str(l) for i in weights for l in i.split() if l.isdigit()] |
278 | | - ax.set_xlabel('Component' + components[0] + ' ' + percents[0], |
279 | | - fontsize = font_axis) |
280 | | - ax.set_ylabel('Component' + components[1] + ' ' + percents[1], |
281 | | - fontsize = font_axis) |
282 | | - ax.set_title('Weights', |
283 | | - fontsize = font_ax_title) |
284 | | - ax.scatter(qtpad.x_weights[weights[0]], |
285 | | - qtpad.x_weights[weights[1]]) |
286 | | - for segment in qtpad.x_weights.index: |
287 | | - if offset is not None: |
288 | | - if segment in offset.keys(): |
289 | | - xy_offset = offset[segment] |
290 | | - else: |
291 | | - xy_offset = (-55, 4) |
292 | | - ax.annotate(segment, |
293 | | - xy=(qtpad.x_weights.loc[segment, |
294 | | - weights[0]], |
295 | | - qtpad.x_weights.loc[segment, |
296 | | - weights[1]]), |
297 | | - xytext=xy_offset, |
298 | | - textcoords='offset points') |
299 | | - ax.scatter(qtpad.y_weights[weights[0]], |
300 | | - qtpad.y_weights[weights[1]]) |
301 | | - for group in qtpad.y_weights.index: |
302 | | - xy_offset = (-10, 5) |
303 | | - ax.annotate(group, |
304 | | - xy=(qtpad.y_weights.loc[group, |
305 | | - weights[0]], |
306 | | - qtpad.y_weights.loc[group, |
307 | | - weights[1]]), |
308 | | - xytext=xy_offset, |
309 | | - textcoords='offset points') |
310 | | - |
311 | | - |
312 | | -fig = plt.figure(figsize = (12,12)) |
313 | | -fig.tight_layout(h_pad=10) |
314 | | -fig.suptitle('PLS-DA Scores', fontsize=18) |
315 | | - |
316 | | -ax1 = fig.add_subplot(2,2,1) |
317 | | -ax2 = fig.add_subplot(2,2,2) |
318 | | -ax3 = fig.add_subplot(2,2,3) |
319 | | -ax4 = fig.add_subplot(2,2,4) |
320 | | -percents = [] |
321 | | -for i in range(2, len(qtpad.x_variance_explained)): |
322 | | - per = '(' + \ |
323 | | - str(round(qtpad.x_variance_explained[i] * 100)) + \ |
324 | | - '%)' |
325 | | - percents.append(per) |
326 | | - |
327 | | -#### AX 1 #### |
328 | | -score_plot(ax1, |
329 | | - percents[:2], |
330 | | - ['Component 3', 'Component 4']) |
331 | | - |
332 | | -#### AX 2 #### |
333 | | -weight_plot(ax2, |
334 | | - percents[:2], |
335 | | - ['Weight 3', 'Weight 4'], |
336 | | - {'Ventricles': (-10, 10), |
337 | | - 'Entorhinal': (-40, 10)}) |
338 | | - |
339 | | -#### AX 3 #### |
340 | | -score_plot(ax3, |
341 | | - percents[1:], |
342 | | - ['Component 4', 'Component 5']) |
| 186 | + axs[2], |
| 187 | + 'All') |
343 | 188 |
|
344 | | -#### AX 4 #### |
345 | | -weight_plot(ax4, |
346 | | - percents[1:], |
347 | | - ['Weight 4', 'Weight 5']) |
| 189 | +for i, label in enumerate(('A', 'B', 'C')): |
| 190 | + axs[i].text(-0.05, 1.1, |
| 191 | + label, |
| 192 | + transform=axs[i].transAxes, |
| 193 | + fontsize=16, |
| 194 | + fontweight='bold', |
| 195 | + va='top', |
| 196 | + ha='right') |
348 | 197 |
|
349 | 198 | for ext in file_extensions: |
350 | 199 | filename = savepath +\ |
351 | | - 'FigureS2' +\ |
| 200 | + 'Figure4' +\ |
352 | 201 | ext |
353 | 202 | plt.savefig(filename, |
354 | 203 | dpi=300) |
0 commit comments