1
|
|
|
""" |
2
|
|
|
Command-line interface for mandos. |
3
|
|
|
""" |
4
|
|
|
|
5
|
|
|
from __future__ import annotations |
6
|
|
|
|
7
|
|
|
from pathlib import Path |
8
|
|
|
from typing import Any, Mapping, Optional, Tuple, TypeVar |
9
|
|
|
|
10
|
|
|
import pandas as pd |
|
|
|
|
11
|
|
|
from pocketutils.core.chars import Chars |
|
|
|
|
12
|
|
|
from pocketutils.core.exceptions import XValueError |
|
|
|
|
13
|
|
|
from typeddfs import TypedDf |
|
|
|
|
14
|
|
|
from typeddfs.cli_help import DfCliHelp |
|
|
|
|
15
|
|
|
|
16
|
|
|
# noinspection PyProtectedMember |
17
|
|
|
from mandos.analysis._plot_utils import ( |
18
|
|
|
VIZ_RESOURCES, |
19
|
|
|
CompoundStyleDf, |
20
|
|
|
MandosPlotStyling, |
21
|
|
|
MandosPlotUtils, |
22
|
|
|
PhiPsiStyleDf, |
23
|
|
|
PredicateObjectStyleDf, |
24
|
|
|
) |
25
|
|
|
from mandos.analysis.io_defns import ( |
26
|
|
|
EnrichmentDf, |
27
|
|
|
PhiPsiSimilarityDfLongForm, |
28
|
|
|
PsiProjectedDf, |
29
|
|
|
SimilarityDfLongForm, |
30
|
|
|
) |
31
|
|
|
from mandos.analysis.plots import ( |
32
|
|
|
CatPlotType, |
33
|
|
|
CorrPlotter, |
34
|
|
|
PlotOptions, |
35
|
|
|
ProjectionPlotter, |
36
|
|
|
RelPlotType, |
37
|
|
|
ScorePlotter, |
38
|
|
|
TauPlotter, |
39
|
|
|
) |
40
|
|
|
|
41
|
|
|
# noinspection PyProtectedMember |
42
|
|
|
from mandos.entry._arg_utils import Arg, EntryUtils, Opt |
43
|
|
|
from mandos.entry._common_args import CommonArgs |
44
|
|
|
from mandos.entry.calc_commands import Aa |
45
|
|
|
from mandos.model.settings import SETTINGS |
46
|
|
|
from mandos.model.utils.setup import MANDOS_SETUP |
47
|
|
|
|
48
|
|
|
DEF_SUFFIX = SETTINGS.table_suffix |
49
|
|
|
nl = "\n\n" |
|
|
|
|
50
|
|
|
IMG_SUFFIXES = {".pdf", ".png", ".svg", ".jpg", ".jpeg"} |
51
|
|
|
|
52
|
|
|
T = TypeVar("T", bound=TypedDf) |
|
|
|
|
53
|
|
|
V = TypeVar("V", bound=TypedDf) |
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
class Pa: |
|
|
|
|
57
|
|
|
|
58
|
|
|
in_style: str = Opt.val( |
59
|
|
|
rf""" |
60
|
|
|
The name of a matplotlib style or a path to a .mplstyle file. |
61
|
|
|
|
62
|
|
|
See https://matplotlib.org/stable/tutorials/introductory/customizing.html. |
63
|
|
|
[default: matplotlib default] |
64
|
|
|
""", |
|
|
|
|
65
|
|
|
show_default=False, |
66
|
|
|
) |
67
|
|
|
|
68
|
|
|
size: str = Opt.val( |
69
|
|
|
rf""" |
70
|
|
|
The width and height of a single figure. |
71
|
|
|
|
72
|
|
|
In the format "<width> x <height>' (e.g. "8.5 in x 11 in") or "<width>" (without height). |
73
|
|
|
If present, use simple expression with units or built-in, "registered" names. |
74
|
|
|
|
75
|
|
|
Example formats: "8.5 in", "8.5 in x 11 in", "2 cm + 5 in", "pnas.1-col x pnas.full-page". |
76
|
|
|
|
77
|
|
|
Registered widths: {", ".join(VIZ_RESOURCES.dims["heights"])} |
78
|
|
|
|
79
|
|
|
Registered heights: {", ".join(VIZ_RESOURCES.dims["widths"])} |
80
|
|
|
|
81
|
|
|
[default: matplotlib style default] |
82
|
|
|
""", |
83
|
|
|
show_default=False, |
84
|
|
|
) |
85
|
|
|
|
86
|
|
|
ci = Opt.val( |
87
|
|
|
f""" |
88
|
|
|
The upper side of the confidence interval, as a percentage. |
89
|
|
|
""", |
|
|
|
|
90
|
|
|
default=95.0, |
91
|
|
|
) |
92
|
|
|
|
93
|
|
|
out_fig_file: Optional[Path] = Opt.out_file( |
94
|
|
|
r""" |
95
|
|
|
Path to an output PDF or other figure file. |
96
|
|
|
|
97
|
|
|
PDF (.pdf) is recommended, but .svg, .png, and others are supported. |
98
|
|
|
|
99
|
|
|
[default: <input-dir>/<auto-generated-filename>.pdf] |
100
|
|
|
""" |
101
|
|
|
) |
102
|
|
|
|
103
|
|
|
out_fig_dir: Optional[Path] = Opt.out_dir( |
104
|
|
|
r""" |
105
|
|
|
Path to an output directory for figures. |
106
|
|
|
|
107
|
|
|
[default: <input-dir>] |
108
|
|
|
""" |
109
|
|
|
) |
110
|
|
|
|
111
|
|
|
in_projection: Optional[Path] = Opt.in_file( |
112
|
|
|
rf""" |
113
|
|
|
Path to data from ``:calc:project`` or a similar command. |
114
|
|
|
""" |
|
|
|
|
115
|
|
|
) |
116
|
|
|
|
117
|
|
|
cat_plot_kind: str = ( |
118
|
|
|
Opt.val( |
119
|
|
|
r""" |
120
|
|
|
The type of categorical-to-numerical plot. |
121
|
|
|
|
122
|
|
|
Can be: 'bar', 'fold', 'box', 'violin', 'strip', or 'swarm'. |
123
|
|
|
The type of plot: bar, box, violin, or swarm. |
124
|
|
|
'fold' plots an opaque bar plot for the score over a transparent one for the total. |
125
|
|
|
It is intended for integer scores representing simple counts. |
126
|
|
|
Bar (and box) plots include confidence/error bars. |
127
|
|
|
""", |
128
|
|
|
default="violin", |
129
|
|
|
), |
130
|
|
|
) |
131
|
|
|
|
132
|
|
|
rel_plot_kind = Opt.val( |
133
|
|
|
rf""" |
134
|
|
|
The type of x{Chars.en}y relationship plot. |
135
|
|
|
|
136
|
|
|
Either 'scatter', 'line', 'regression:logistic', or 'regression:<order>. |
137
|
|
|
'regression:1' plots a linear regression line, 'regression:2' plots a quadratic, |
138
|
|
|
and so on. ('regression:linear', 'regression:quartic', etc., are also accepted.) |
139
|
|
|
Line and regression plots include confidence/error bands (see --ci and --boot). |
140
|
|
|
""", |
141
|
|
|
default="scatter", |
142
|
|
|
) |
143
|
|
|
|
144
|
|
|
group = Opt.flag( |
145
|
|
|
""" |
146
|
|
|
Combine the colors (with --color) into plots. |
147
|
|
|
|
148
|
|
|
Applies only if --color is set and there is more than 1 category / color value. |
149
|
|
|
|
150
|
|
|
For strip and swarm plots, ignores the category, plotting all points together in |
151
|
|
|
single scatter plots. (Otherwise, slightly separates the colors along the x-axis.) |
152
|
|
|
For bar, box, and violin plots, places the bars immediately adjacent. |
153
|
|
|
For violin plots with exactly 2 colors, splits each violin into a half-violin per color. |
154
|
|
|
""" |
155
|
|
|
) |
156
|
|
|
|
157
|
|
|
bandwidth = Opt.val( |
158
|
|
|
r""" |
159
|
|
|
Bandwidth as a float. |
160
|
|
|
|
161
|
|
|
Defaults to using Scott's algorithm. |
162
|
|
|
Only applies to violin plots. |
163
|
|
|
""" |
164
|
|
|
) |
165
|
|
|
|
166
|
|
|
cut = Opt.val( |
167
|
|
|
r""" |
168
|
|
|
Distance, in units of bandwidth size, to extend the density past extreme points. |
169
|
|
|
|
170
|
|
|
Only applies to violin plots. |
171
|
|
|
""", |
172
|
|
|
default=2, |
173
|
|
|
) |
174
|
|
|
|
175
|
|
|
in_compound_viz: Optional[Path] = Opt.in_file( |
176
|
|
|
rf""" |
177
|
|
|
{DfCliHelp.help(CompoundStyleDf).get_short_text(nl=nl)} |
178
|
|
|
|
179
|
|
|
If set, ``--colors`` and ``--markers`` will refer to columns in this file. |
180
|
|
|
Otherwise, they will refer to columns in the input. |
181
|
|
|
""" |
182
|
|
|
) |
183
|
|
|
|
184
|
|
|
in_pair_viz: Optional[Path] = Opt.in_file( |
185
|
|
|
rf""" |
186
|
|
|
{DfCliHelp.help(PredicateObjectStyleDf).get_short_text(nl=nl)} |
187
|
|
|
|
188
|
|
|
NOTE: This is currently not supported with pair intersection. |
189
|
|
|
|
190
|
|
|
If set, ``--colors`` and ``--markers`` will refer to columns in this file. |
191
|
|
|
Otherwise, they will refer to columns in the input. |
192
|
|
|
|
193
|
|
|
Any null (empty-string) value is taken to mean any/all. |
194
|
|
|
(The main use is to easily collapse over all predicates.) |
195
|
|
|
""" |
196
|
|
|
) |
197
|
|
|
|
198
|
|
|
in_psi_viz: Optional[Path] = Opt.in_file( |
199
|
|
|
rf""" |
200
|
|
|
{DfCliHelp.help(CompoundStyleDf).get_short_text(nl=nl)} |
201
|
|
|
|
202
|
|
|
If set, ``--colors`` and ``--markers`` will refer to columns in this file. |
203
|
|
|
Otherwise, they will refer to columns in the input. |
204
|
|
|
""" |
205
|
|
|
) |
206
|
|
|
|
207
|
|
|
colors: Optional[str] = Opt.val( |
208
|
|
|
rf""" |
209
|
|
|
A column that defines the 'group' and color. |
210
|
|
|
|
211
|
|
|
Each group is assigned a different color. |
212
|
|
|
If not specified, will use one color unless the plot requires more. |
213
|
|
|
|
214
|
|
|
See also: ``--palette``. |
215
|
|
|
""", |
|
|
|
|
216
|
|
|
) |
217
|
|
|
|
218
|
|
|
palette: Optional[str] = Opt.val( |
219
|
|
|
rf""" |
220
|
|
|
The name of a color palette. |
221
|
|
|
|
222
|
|
|
If not set, chooses a palette depending on the data type: |
223
|
|
|
|
224
|
|
|
- a vibrant palette for strings with a max of 26 unique items |
225
|
|
|
|
226
|
|
|
- a palette from white to black for numbers of the same sign (excluding NaN and 0) |
227
|
|
|
|
228
|
|
|
- a palette from blue to white to red for negative and positive numbers |
229
|
|
|
|
230
|
|
|
Choices: {", ".join(MandosPlotStyling.list_named_palettes())}. |
231
|
|
|
Some are only available for some data types. |
232
|
|
|
""" |
233
|
|
|
) |
234
|
|
|
|
235
|
|
|
@classmethod |
236
|
|
|
def add_styling(cls, data: T, viz: Optional[TypedDf]) -> T: |
|
|
|
|
237
|
|
|
if viz is None: |
238
|
|
|
return data |
239
|
|
|
viz = pd.merge(data, viz, on=viz.get_typing().required_names) |
240
|
|
|
return CompoundStyleDf.convert(viz) |
241
|
|
|
|
242
|
|
|
@classmethod |
243
|
|
|
def read_rel_kind(cls, kind: str) -> Tuple[RelPlotType, Mapping[str, Any]]: |
|
|
|
|
244
|
|
|
type_ = RelPlotType.or_none(kind) |
245
|
|
|
if type_ is not None: |
246
|
|
|
return type_, {} |
247
|
|
|
type_, order = kind.split(":") |
248
|
|
|
if order == "logistic": |
249
|
|
|
return type_, dict(logistic=True) |
250
|
|
|
order = cls.get_degree(order) |
251
|
|
|
if order is None: |
252
|
|
|
raise XValueError(f"Unknown plot kind {kind}") |
253
|
|
|
return type_, dict(order=order) |
254
|
|
|
|
255
|
|
|
@classmethod |
256
|
|
|
def get_degree(cls, order: str) -> int: |
|
|
|
|
257
|
|
|
try: |
258
|
|
|
order = int(order) |
259
|
|
|
except ValueError: |
260
|
|
|
pass |
261
|
|
|
arities = dict( |
262
|
|
|
linear=1, |
263
|
|
|
quadratic=2, |
264
|
|
|
cubic=3, |
265
|
|
|
quartic=4, |
266
|
|
|
quintic=5, |
267
|
|
|
sextic=6, |
268
|
|
|
hexic=6, |
269
|
|
|
septic=7, |
270
|
|
|
heptic=7, |
271
|
|
|
) |
272
|
|
|
return arities[order] |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
class PlotCommands: |
|
|
|
|
276
|
|
|
@staticmethod |
277
|
|
|
def plot_enrichment( |
|
|
|
|
278
|
|
|
path: Path = Aa.in_scores_table, |
|
|
|
|
279
|
|
|
kind: str = Pa.cat_plot_kind, |
|
|
|
|
280
|
|
|
group: bool = Pa.group, |
|
|
|
|
281
|
|
|
ci: float = Pa.ci, |
|
|
|
|
282
|
|
|
boot: int = Aa.boot, |
|
|
|
|
283
|
|
|
seed: int = Aa.seed, |
|
|
|
|
284
|
|
|
bandwidth: float = Pa.bandwidth, |
|
|
|
|
285
|
|
|
cut: int = Pa.cut, |
|
|
|
|
286
|
|
|
viz: Optional[Path] = Pa.in_pair_viz, |
|
|
|
|
287
|
|
|
colors: Optional[str] = Pa.colors, |
|
|
|
|
288
|
|
|
palette: Optional[str] = Pa.palette, |
|
|
|
|
289
|
|
|
size: Optional[str] = Pa.size, |
|
|
|
|
290
|
|
|
style: Optional[str] = Pa.in_style, |
|
|
|
|
291
|
|
|
to: Optional[Path] = Pa.out_fig_dir, |
|
|
|
|
292
|
|
|
log: Optional[Path] = CommonArgs.log, |
|
|
|
|
293
|
|
|
stderr: bool = CommonArgs.stderr, |
|
|
|
|
294
|
|
|
) -> None: |
295
|
|
|
r""" |
296
|
|
|
Plot correlation to scores. |
297
|
|
|
|
298
|
|
|
Visualizes the correlation between predicate/object pairs and user-supplied scores. |
299
|
|
|
Will output one figure (file) per scoring function. |
300
|
|
|
Will plot over a grid, one row per key/source pair and column per predicate/object pair. |
301
|
|
|
""" |
302
|
|
|
MANDOS_SETUP(log, stderr) |
303
|
|
|
kind = CatPlotType.of(kind) |
304
|
|
|
to, suffix = EntryUtils.adjust_dir_name(to, path.parent, suffixes=IMG_SUFFIXES) |
305
|
|
|
df = EnrichmentDf.read_file(path) |
|
|
|
|
306
|
|
|
viz = None if viz is None else PredicateObjectStyleDf.read_file(viz) |
307
|
|
|
df = Pa.add_styling(df, viz) |
|
|
|
|
308
|
|
|
palette = MandosPlotStyling.choose_palette(df, colors, palette) |
309
|
|
|
extra = dict(bandwith=bandwidth, cut=cut) if kind is CatPlotType.violin else {} |
310
|
|
|
rc = PlotOptions( |
|
|
|
|
311
|
|
|
size=size, |
312
|
|
|
style=style, |
313
|
|
|
rc={}, |
314
|
|
|
hue=colors, |
315
|
|
|
palette=palette, |
316
|
|
|
extra=extra, |
317
|
|
|
) |
318
|
|
|
plotter = ScorePlotter( |
319
|
|
|
rc=rc, |
320
|
|
|
kind=kind, |
321
|
|
|
group=group, |
322
|
|
|
ci=ci, |
323
|
|
|
seed=seed, |
324
|
|
|
boot=boot, |
325
|
|
|
) |
326
|
|
|
for score_name in df["score_name"].unique(): |
327
|
|
|
fig = plotter.plot(df) |
328
|
|
|
MandosPlotUtils.save(fig, to / f"{score_name}-{kind}-plot{suffix}") |
329
|
|
|
|
330
|
|
|
@staticmethod |
331
|
|
|
def plot_phi_psi( |
|
|
|
|
332
|
|
|
path: Path = Aa.in_matrix_long_form, |
|
|
|
|
333
|
|
|
kind: str = Pa.rel_plot_kind, |
|
|
|
|
334
|
|
|
ci: float = Pa.ci, |
|
|
|
|
335
|
|
|
boot: int = Aa.boot, |
|
|
|
|
336
|
|
|
seed: int = Aa.seed, |
|
|
|
|
337
|
|
|
viz: Optional[Path] = Pa.in_psi_viz, |
|
|
|
|
338
|
|
|
colors: Optional[str] = Pa.colors, |
|
|
|
|
339
|
|
|
palette: Optional[str] = Pa.palette, |
|
|
|
|
340
|
|
|
size: Optional[str] = Pa.size, |
|
|
|
|
341
|
|
|
style: Optional[str] = Pa.in_style, |
|
|
|
|
342
|
|
|
to: Optional[Path] = Pa.out_fig_file, |
|
|
|
|
343
|
|
|
log: Optional[Path] = CommonArgs.log, |
|
|
|
|
344
|
|
|
stderr: bool = CommonArgs.stderr, |
|
|
|
|
345
|
|
|
) -> None: |
346
|
|
|
r""" |
347
|
|
|
Plot line plots of phi against psi. |
348
|
|
|
|
349
|
|
|
Plots scatter plots of (phi, psi) values, sorted by phi values. |
350
|
|
|
All plots are log/log (all similarity values should be scaled from 0 to 1). |
351
|
|
|
|
352
|
|
|
For each unique phi matrix and psi matrix, flattens the matrices and plots |
353
|
|
|
the flattened (n choose 2 - n) pairs of each jointly, phi mapped to the y-axis |
354
|
|
|
and psi mapped to the x-axis. |
355
|
|
|
|
356
|
|
|
Will show values for all psi variables together. |
357
|
|
|
If --colors is not set, will choose a palette. |
358
|
|
|
""" |
359
|
|
|
MANDOS_SETUP(log, stderr) |
360
|
|
|
default = path.parent / f"{path.name}-{kind}-plot.pdf" |
361
|
|
|
to = EntryUtils.adjust_filename(to, default, True, suffixes=IMG_SUFFIXES) |
362
|
|
|
df = PhiPsiSimilarityDfLongForm.read_file(path) |
|
|
|
|
363
|
|
|
viz = None if viz is None else PhiPsiStyleDf.read_file(viz) |
364
|
|
|
df = Pa.add_styling(df, viz) |
|
|
|
|
365
|
|
|
palette = MandosPlotStyling.choose_palette(df, colors, palette) |
366
|
|
|
kind, extra = Pa.read_rel_kind(kind) |
367
|
|
|
rc = PlotOptions( |
|
|
|
|
368
|
|
|
size=size, |
369
|
|
|
style=style, |
370
|
|
|
rc={}, |
371
|
|
|
hue=colors, |
372
|
|
|
palette=palette, |
373
|
|
|
extra=extra, |
374
|
|
|
) |
375
|
|
|
plotter = CorrPlotter( |
376
|
|
|
rc=rc, |
377
|
|
|
kind=kind, |
378
|
|
|
ci=ci, |
379
|
|
|
boot=boot, |
380
|
|
|
seed=seed, |
381
|
|
|
) |
382
|
|
|
fig = plotter.plot(df) |
383
|
|
|
MandosPlotUtils.save(fig, to) |
384
|
|
|
|
385
|
|
|
@staticmethod |
386
|
|
|
def plot_tau( |
|
|
|
|
387
|
|
|
path: Path = Arg.in_file( |
|
|
|
|
388
|
|
|
rf""" |
389
|
|
|
Output file from ``:calc:tau``. |
390
|
|
|
""" |
|
|
|
|
391
|
|
|
), |
392
|
|
|
kind: str = Pa.cat_plot_kind, |
|
|
|
|
393
|
|
|
group: bool = Pa.group, |
|
|
|
|
394
|
|
|
ci: float = Pa.ci, |
|
|
|
|
395
|
|
|
boot: int = Aa.boot, |
|
|
|
|
396
|
|
|
seed: int = Aa.seed, |
|
|
|
|
397
|
|
|
bandwidth: float = Pa.bandwidth, |
|
|
|
|
398
|
|
|
cut: int = Pa.cut, |
|
|
|
|
399
|
|
|
viz: Optional[Path] = Pa.in_psi_viz, |
|
|
|
|
400
|
|
|
colors: Optional[str] = Pa.colors, |
|
|
|
|
401
|
|
|
palette: Optional[str] = Pa.palette, |
|
|
|
|
402
|
|
|
size: Optional[str] = Pa.size, |
|
|
|
|
403
|
|
|
style: Optional[str] = Pa.in_style, |
|
|
|
|
404
|
|
|
to: Optional[Path] = Pa.out_fig_file, |
|
|
|
|
405
|
|
|
log: Optional[Path] = CommonArgs.log, |
|
|
|
|
406
|
|
|
stderr: bool = CommonArgs.stderr, |
|
|
|
|
407
|
|
|
) -> None: |
408
|
|
|
r""" |
409
|
|
|
Plot violin plots or similar from tau values. |
410
|
|
|
|
411
|
|
|
The input data should be generated by ``:calc:phi-vs-psi.tau``. |
412
|
|
|
|
413
|
|
|
Will plot each (phi, psi) pair over a grid, one row per phi and one column per psi. |
414
|
|
|
""" |
415
|
|
|
MANDOS_SETUP(log, stderr) |
416
|
|
|
kind = CatPlotType.of(kind) |
417
|
|
|
default = path.parent / (f"{path.name}-{kind}-plot.pdf") |
418
|
|
|
to = EntryUtils.adjust_filename(to, default, suffixes=IMG_SUFFIXES) |
|
|
|
|
419
|
|
|
df: SimilarityDfLongForm = SimilarityDfLongForm.read_file(path) |
|
|
|
|
420
|
|
|
viz = None if viz is None else PhiPsiStyleDf.read_file(viz) |
421
|
|
|
df = Pa.add_styling(df, viz) |
|
|
|
|
422
|
|
|
palette = MandosPlotStyling.choose_palette(df, colors, palette) |
423
|
|
|
extra = dict(bandwith=bandwidth, cut=cut) if kind is CatPlotType.violin else {} |
424
|
|
|
rc = PlotOptions( |
|
|
|
|
425
|
|
|
size=size, |
426
|
|
|
style=style, |
427
|
|
|
rc={}, |
428
|
|
|
hue=colors, |
429
|
|
|
palette=palette, |
430
|
|
|
extra=extra, |
431
|
|
|
) |
432
|
|
|
plotter = TauPlotter( |
433
|
|
|
rc=rc, |
434
|
|
|
kind=kind, |
435
|
|
|
group=group, |
436
|
|
|
ci=ci, |
437
|
|
|
boot=boot, |
438
|
|
|
seed=seed, |
439
|
|
|
) |
440
|
|
|
fig = plotter.plot(df) |
441
|
|
|
MandosPlotUtils.save(fig, to) |
442
|
|
|
|
443
|
|
|
@staticmethod |
444
|
|
|
def plot_heatmap( |
|
|
|
|
445
|
|
|
path: Path = Aa.in_matrix_long_form, |
|
|
|
|
446
|
|
|
size: Optional[str] = Pa.size, |
|
|
|
|
447
|
|
|
style: Optional[str] = Pa.in_style, |
|
|
|
|
448
|
|
|
to: Optional[Path] = Pa.out_fig_file, |
|
|
|
|
449
|
|
|
log: Optional[Path] = CommonArgs.log, |
|
|
|
|
450
|
|
|
stderr: bool = CommonArgs.stderr, |
|
|
|
|
451
|
|
|
) -> None: |
452
|
|
|
r""" |
453
|
|
|
Plot a heatmap of correlation between compounds. |
454
|
|
|
|
455
|
|
|
Will output one figure / file per correlation definition ('key' column). |
456
|
|
|
""" |
457
|
|
|
MANDOS_SETUP(log, stderr) |
458
|
|
|
default = path.parent / (path.name + "-heatmap-plot.pdf") |
459
|
|
|
to = EntryUtils.adjust_filename(to, default, True, suffixes=IMG_SUFFIXES) |
460
|
|
|
df = PsiProjectedDf.read_file(path) |
|
|
|
|
461
|
|
|
rc = PlotOptions( |
|
|
|
|
462
|
|
|
size=size, |
463
|
|
|
style=style, |
464
|
|
|
rc={}, |
465
|
|
|
hue=None, |
466
|
|
|
palette=None, |
467
|
|
|
extra={}, |
468
|
|
|
) |
469
|
|
|
fig = ProjectionPlotter(rc).plot(df) |
470
|
|
|
MandosPlotUtils.save(fig, to) |
471
|
|
|
|
472
|
|
|
@staticmethod |
473
|
|
|
def plot_projection( |
|
|
|
|
474
|
|
|
path: Path = Pa.in_projection, |
|
|
|
|
475
|
|
|
viz: Optional[Path] = Pa.in_compound_viz, |
|
|
|
|
476
|
|
|
colors: Optional[str] = Pa.colors, |
|
|
|
|
477
|
|
|
palette: Optional[str] = Pa.palette, |
|
|
|
|
478
|
|
|
size: Optional[str] = Pa.size, |
|
|
|
|
479
|
|
|
style: Optional[str] = Pa.in_style, |
|
|
|
|
480
|
|
|
to: Optional[Path] = Pa.out_fig_file, |
|
|
|
|
481
|
|
|
log: Optional[Path] = CommonArgs.log, |
|
|
|
|
482
|
|
|
stderr: bool = CommonArgs.stderr, |
|
|
|
|
483
|
|
|
) -> None: |
484
|
|
|
r""" |
485
|
|
|
Plot UMAP, etc. of compounds from psi matrices. |
486
|
|
|
|
487
|
|
|
Will plot the psi variables over a grid. |
488
|
|
|
""" |
489
|
|
|
MANDOS_SETUP(log, stderr) |
490
|
|
|
default = path.parent / (path.name + "-plot.pdf") |
491
|
|
|
to = EntryUtils.adjust_filename(to, default, True, suffixes=IMG_SUFFIXES) |
492
|
|
|
df = PsiProjectedDf.read_file(path) |
|
|
|
|
493
|
|
|
viz = None if viz is None else CompoundStyleDf.read_file(viz) |
494
|
|
|
df = Pa.add_styling(df, viz) |
|
|
|
|
495
|
|
|
palette = MandosPlotStyling.choose_palette(df, colors, palette) |
496
|
|
|
rc = PlotOptions( |
|
|
|
|
497
|
|
|
size=size, |
498
|
|
|
style=style, |
499
|
|
|
rc={}, |
500
|
|
|
hue=colors, |
501
|
|
|
palette=palette, |
502
|
|
|
extra={}, |
503
|
|
|
) |
504
|
|
|
fig = ProjectionPlotter(rc).plot(df) |
505
|
|
|
MandosPlotUtils.save(fig, to) |
506
|
|
|
|
507
|
|
|
|
508
|
|
|
__all__ = ["PlotCommands"] |
509
|
|
|
|