Tutorial 4: Visualization¶
Plotting helpers work with tensors, network arrays, manifold outputs, and differential-regulation tables produced by the workflows.
In [1]:
Copied!
%matplotlib inline
from scTenifold import compare_networks, scTenifoldNet
from scTenifold.data import get_test_df
from scTenifold.plotting import plot_hist, plot_network_heatmap, plot_qqplot
x = get_test_df(n_cells=80, n_genes=40, random_state=0)
y = get_test_df(n_cells=80, n_genes=40, random_state=1)
%matplotlib inline
from scTenifold import compare_networks, scTenifoldNet
from scTenifold.data import get_test_df
from scTenifold.plotting import plot_hist, plot_network_heatmap, plot_qqplot
x = get_test_df(n_cells=80, n_genes=40, random_state=0)
y = get_test_df(n_cells=80, n_genes=40, random_state=1)
Build a small result¶
For plotting intermediate tensors, use the class API.
In [2]:
Copied!
model = scTenifoldNet(
x,
y,
"control",
"condition",
qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0},
nc_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0, "backend": "serial"},
td_kws={"K": 2, "max_iter": 20, "init": "random"},
ma_kws={"d": 2},
)
model.build()
model = scTenifoldNet(
x,
y,
"control",
"condition",
qc_kws={"min_lib_size": 1, "plot": False, "max_mito_ratio": 1.0, "min_percent": 0},
nc_kws={"n_nets": 2, "n_samp_cells": 25, "q": 0, "backend": "serial"},
td_kws={"K": 2, "max_iter": 20, "init": "random"},
ma_kws={"d": 2},
)
model.build()
Removed 0 cells with lib size < 1 Removed 0 outlier cells from original data Found mitochondrial genes: ['MT-1', 'MT-10', 'MT-2', 'MT-3', 'MT-4', 'MT-5', 'MT-6', 'MT-7', 'MT-8', 'MT-9'] Removed 0 samples from original data (mt genes ratio > 1.0) Removed 0 genes expressed in less than 0 of data Removed 0 genes with expression values: average < 0 or sum < 0 finish QC: control Removed 0 cells with lib size < 1 Removed 0 outlier cells from original data Found mitochondrial genes: ['MT-1', 'MT-10', 'MT-2', 'MT-3', 'MT-4', 'MT-5', 'MT-6', 'MT-7', 'MT-8', 'MT-9'] Removed 0 samples from original data (mt genes ratio > 1.0) Removed 0 genes expressed in less than 0 of data Removed 0 genes with expression values: average < 0 or sum < 0 finish QC: condition process qc finished in 0.010431443000015861 secs. make_networks processing time: 0.11921537599937437
make_networks processing time: 0.11902902600013476 process nc finished in 0.2391113330004373 secs. Using tensorly (40, 40, 2) tensor_decomp processing time: 0.00449678600034531 Using tensorly (40, 40, 2) tensor_decomp processing time: 0.004096064999430382 process td finished in 0.009546962000058556 secs. manifold_alignment processing time: 0.0024742929999774788 process ma finished in 0.002513353000722418 secs. d_regulation processing time: 0.011251283999627049 process dr finished in 0.011294083999928262 secs.
Out[2]:
| Gene | Distance | boxcox-transformed distance | Z | FC | p-value | adjusted p-value | |
|---|---|---|---|---|---|---|---|
| 34 | NG-4 | 0.029244 | -1.382743 | 2.033638 | 3.698975 | 0.054446 | 0.669520 |
| 31 | NG-29 | 0.027043 | -1.390411 | 1.787239 | 3.163037 | 0.075323 | 0.669520 |
| 10 | NG-1 | 0.024698 | -1.398821 | 1.516972 | 2.638354 | 0.104312 | 0.669520 |
| 37 | NG-7 | 0.023560 | -1.403003 | 1.382574 | 2.400828 | 0.121271 | 0.669520 |
| 21 | NG-2 | 0.021716 | -1.409936 | 1.159797 | 2.039616 | 0.153248 | 0.669520 |
| 13 | NG-12 | 0.021076 | -1.412387 | 1.081014 | 1.921230 | 0.165721 | 0.669520 |
| 7 | MT-7 | 0.019370 | -1.419056 | 0.866696 | 1.622804 | 0.202701 | 0.669520 |
| 11 | NG-10 | 0.018749 | -1.421535 | 0.787053 | 1.520416 | 0.217557 | 0.669520 |
| 5 | MT-5 | 0.018358 | -1.423109 | 0.736469 | 1.457703 | 0.227296 | 0.669520 |
| 36 | NG-6 | 0.018210 | -1.423707 | 0.717235 | 1.434323 | 0.231060 | 0.669520 |
| 3 | MT-3 | 0.017761 | -1.425537 | 0.658447 | 1.364433 | 0.242771 | 0.669520 |
| 28 | NG-26 | 0.017729 | -1.425669 | 0.654208 | 1.359484 | 0.243627 | 0.669520 |
| 29 | NG-27 | 0.017520 | -1.426525 | 0.626701 | 1.327665 | 0.249221 | 0.669520 |
| 8 | MT-8 | 0.017387 | -1.427074 | 0.609063 | 1.307530 | 0.252842 | 0.669520 |
| 38 | NG-8 | 0.016313 | -1.431550 | 0.465213 | 1.150939 | 0.283353 | 0.669520 |
| 23 | NG-21 | 0.016251 | -1.431809 | 0.456883 | 1.142281 | 0.285171 | 0.669520 |
| 16 | NG-15 | 0.015174 | -1.436408 | 0.309103 | 0.995890 | 0.318307 | 0.669520 |
| 4 | MT-4 | 0.015082 | -1.436804 | 0.296370 | 0.983904 | 0.321237 | 0.669520 |
| 22 | NG-20 | 0.015065 | -1.436878 | 0.293984 | 0.981669 | 0.321787 | 0.669520 |
| 30 | NG-28 | 0.014473 | -1.439462 | 0.210957 | 0.906010 | 0.341175 | 0.669520 |
| 35 | NG-5 | 0.014167 | -1.440814 | 0.167518 | 0.868042 | 0.351498 | 0.669520 |
| 17 | NG-16 | 0.012110 | -1.450164 | -0.132955 | 0.634331 | 0.425771 | 0.729819 |
| 9 | MT-9 | 0.011887 | -1.451212 | -0.166622 | 0.611152 | 0.434354 | 0.729819 |
| 32 | NG-3 | 0.011696 | -1.452113 | -0.195592 | 0.591670 | 0.441774 | 0.729819 |
| 15 | NG-14 | 0.011331 | -1.453849 | -0.251357 | 0.555357 | 0.456137 | 0.729819 |
| 24 | NG-22 | 0.010439 | -1.458181 | -0.390582 | 0.471319 | 0.492381 | 0.743579 |
| 0 | MT-1 | 0.010106 | -1.459827 | -0.443484 | 0.441784 | 0.506263 | 0.743579 |
| 26 | NG-24 | 0.009347 | -1.463660 | -0.566651 | 0.377909 | 0.538724 | 0.743579 |
| 14 | NG-13 | 0.009333 | -1.463732 | -0.568981 | 0.376765 | 0.539339 | 0.743579 |
| 33 | NG-30 | 0.008915 | -1.465893 | -0.638424 | 0.343729 | 0.557685 | 0.743579 |
| 12 | NG-11 | 0.008206 | -1.469633 | -0.758585 | 0.291282 | 0.589400 | 0.753433 |
| 1 | MT-10 | 0.007914 | -1.471211 | -0.809295 | 0.270874 | 0.602746 | 0.753433 |
| 39 | NG-9 | 0.006644 | -1.478307 | -1.037349 | 0.190936 | 0.662139 | 0.802592 |
| 6 | MT-6 | 0.006147 | -1.481211 | -1.130661 | 0.163454 | 0.685996 | 0.807055 |
| 18 | NG-17 | 0.004996 | -1.488279 | -1.357776 | 0.107964 | 0.742475 | 0.836668 |
| 20 | NG-19 | 0.004785 | -1.489635 | -1.401360 | 0.099026 | 0.753001 | 0.836668 |
| 25 | NG-23 | 0.003878 | -1.495714 | -1.596716 | 0.065047 | 0.798689 | 0.854055 |
| 2 | MT-2 | 0.003336 | -1.499585 | -1.721123 | 0.048137 | 0.826337 | 0.854055 |
| 27 | NG-25 | 0.003212 | -1.500503 | -1.750598 | 0.044620 | 0.832704 | 0.854055 |
| 19 | NG-18 | 0.002612 | -1.505121 | -1.899023 | 0.029513 | 0.863601 | 0.863601 |
QC histogram¶
In [3]:
Copied!
plot_hist(x, "control")
plot_hist(x, "control")
Tensor heatmap¶
In [4]:
Copied!
plot_network_heatmap(model.tensor_dict["control"].to_numpy())
plot_network_heatmap(model.tensor_dict["control"].to_numpy())
Differential regulation QQ plot¶
In [5]:
Copied!
plot_qqplot(model.d_regulation)
plot_qqplot(model.d_regulation)
The documentation build executes this notebook with the inline Matplotlib backend, so figures are rendered into the generated page.