Plotting API
The Plotting API provides built-in plotting functions. For basic usage, you can generate plots dierctly via Nanocompore's command line interface (Plotting guide). However, if you want to use the plotting functions programatically or want to customize them beyond the basic parameters provided by the command line interface, you can use the API. Nanocompore uses Seaborn, so all functions produce Matplotlib figures that you can modify.
For example:
>>> from nanocompore.api import load_config
>>> from nanocompore.plotting import plot_coverage
# Load the YAML configuration file to a Config object.
>>> config = load_config('analysis.yaml')
# Get a coverage figure for a given transcript.
>>> ref_id = 'ENST00000464651.1|ENSG00000166136.16|OTTHUMG00000019346.4|OTTHUMT00000051221.1|NDUFB8-204|NDUFB8|390|retained_intron|'
>>> fig = plot_coverage(config, ref_id)
# We can now manipulate the figure to customize it
# beyond the parametrization of provided by the API.
# E.g. we can add a title:
>>> fig.axes[0].set_title('Coverage of NDUF8B-204')
# Then we update the layout and save the figure:
>>> fig.tight_layout()
>>> fig.savefig('NDUF8B_coverage.png')
Reference
plot_coverage(config, reference, start=None, end=None, figsize=(30, 10), split_samples=False, palette='Dark2')
Plot the read coverage over a reference for all samples analysed. Note that this would plot the input coverage before applying any filtering that Nanocompore does before the comparison.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
The configuration object for the run. |
required |
reference
|
str
|
Transcript reference. |
required |
start
|
Union[int, None]
|
Start of the region that will be plotted. |
None
|
end
|
Union[int, None]
|
End of the region that will be plotted. |
None
|
figsize
|
tuple[int, int]
|
Size of the figure. |
(30, 10)
|
split_samples
|
bool
|
If True, all samples would be plotted separately. By default it's False and the samples are grouped by condition. |
False
|
palette
|
str
|
Color palette to use. |
'Dark2'
|
Returns:
Type | Description |
---|---|
Union[Figure, SubFigure, None]
|
Figure with the coverage plot. |
Source code in nanocompore/plotting.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
plot_gmm(config, reference, position, figsize=(10, 10), point_size=20, xlim=(None, None), ylim=(None, None), gmm_levels=4, palette='Dark2', point_palette=None, gmm_palette=None)
Plot the GMM fitted by Nanocompore for a given position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
The configuration object for the run. |
required |
reference
|
str
|
Transcript reference. |
required |
position
|
int
|
0-based index on the reference indicating the position. |
required |
figsize
|
tuple[int, int]
|
Size of the figure. |
(10, 10)
|
point_size
|
int
|
Size of the points. |
20
|
xlim
|
Union[tuple[Union[int, None], Union[int, None]], None]
|
Limits of the x-axis. |
(None, None)
|
ylim
|
Union[tuple[Union[int, None], Union[int, None]], None]
|
Limits of the y-axis. |
(None, None)
|
gmm_levels
|
int
|
How many levels of the GMM to show. |
4
|
palette
|
Union[str, None]
|
Palette that will be used to determine the colors of both points and the GMMs. If set, it will override point_palette and gmm_palette. |
'Dark2'
|
point_palette
|
Union[str, None]
|
Palette to use for the points. |
None
|
gmm_palette
|
Union[str, None]
|
Palette to use for the GMMs. |
None
|
Returns:
Type | Description |
---|---|
Union[Figure, SubFigure, None]
|
The resulting figure that will contain a 2D plot with the observations as points and the gaussians obtained from the GMM. |
Source code in nanocompore/plotting.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
plot_position(config, reference, position, figsize=(10, 10), point_size=20, xlim=(None, None), ylim=(None, None), show_kde=True, kde_levels=10, palette='Dark2')
Plot the signal data for a given position.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
The configuration object for the run. |
required |
reference
|
str
|
Transcript reference. |
required |
position
|
int
|
0-based index on the reference indicating the position. |
required |
figsize
|
tuple[int, int]
|
Size of the figure. |
(10, 10)
|
point_size
|
int
|
Size of the points. |
20
|
xlim
|
Union[tuple[Union[int, None], Union[int, None]], None]
|
Limits of the x-axis. |
(None, None)
|
ylim
|
Union[tuple[Union[int, None], Union[int, None]], None]
|
Limits of the y-axis. |
(None, None)
|
kde
|
bool
|
Whether to show the KDEs. |
required |
kde_levels
|
int
|
How many levels of the KDEs to show. |
10
|
palette
|
Union[str, None]
|
Palette that will be used to determine the colors of both points and the GMMs. If set, it will override point_palette and gmm_palette. |
'Dark2'
|
Returns:
Type | Description |
---|---|
Union[Figure, SubFigure, None]
|
The resulting figure that will contain a 2D plot with the observations as points and the gaussians obtained from the GMM. |
Source code in nanocompore/plotting.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
plot_pvalues(config, reference, start=None, end=None, kind='lineplot', threshold=0.01, figsize=(30, 10), tests=None, palette='Dark2')
Plot the p-values from the statistical tests performed in a Nanocompore run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
The configuration object for the run. |
required |
reference
|
str
|
Transcript reference. |
required |
start
|
Union[int, None]
|
Start of the region that will be plotted. |
None
|
end
|
Union[int, None]
|
End of the region that will be plotted. |
None
|
kind
|
str
|
Kind of plot to make. The available options are: lineplot, barplot |
'lineplot'
|
threshold
|
Union[float, None]
|
If set, it will indicate the p-value threshold as a dashed horizontal line. |
0.01
|
figsize
|
tuple[int, int]
|
Size of the figure. |
(30, 10)
|
tests
|
Union[list[str], None]
|
List of tests to plot. The available options are: GMM, KS, TT, MW. If set to None (default) it would plot all tests that were listed in the configuration. |
None
|
palette
|
str
|
Color palette to use. |
'Dark2'
|
Returns:
Type | Description |
---|---|
Union[Figure, SubFigure, None]
|
The resulting figure that will contain the p-values for the specified tests in the provided region. |
Source code in nanocompore/plotting.py
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 |
|
plot_signal(config, reference, start=None, end=None, kind='violinplot', figsize=(30, 10), split_samples=False, markersize=2, palette='Dark2')
Plot the raw signal values (intensity and dwell time) for the given reference and region. Note that this will plot all reads from the input files without applying all the filtering and downsampling that Nanocompore does.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
The configuration object for the run. |
required |
reference
|
str
|
Transcript reference. |
required |
start
|
Union[int, None]
|
Start of the region that will be plotted. |
None
|
end
|
Union[int, None]
|
End of the region that will be plotted. |
None
|
kind
|
str
|
Kind of plot to make. The available options are: lineplot, barplot |
'violinplot'
|
figsize
|
tuple[int, int]
|
Size of the figure. |
(30, 10)
|
split_samples
|
bool
|
If True, all samples would be plotted separately. By default it's False and the samples are grouped by condition. |
False
|
markersize
|
int
|
Size of the points (only used for the swarmplot). |
2
|
palette
|
str
|
Color palette to use. |
'Dark2'
|
Returns:
Type | Description |
---|---|
Union[Figure, SubFigure, None]
|
The resulting figure that will contain the intensity and log-dwell-time plots for the specified reference and region. |
Source code in nanocompore/plotting.py
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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|