Plotting
Plotting helpers and dimensionality-reduction preparation functions.
Result Plots
plot_qqplot
plot_qqplot(
df: DataFrame,
exp_col: str = "FC",
stat_col: str = "adjusted p-value",
plot_qqline: bool = True,
sig_threshold: float = 0.1,
) -> None
Plot QQ-plot using a d_regulation dataframe
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A d_regulation dataframe |
required |
exp_col
|
str
|
Column name of data used to put the y-axis |
'FC'
|
stat_col
|
str
|
Column name of data used to check significance |
'adjusted p-value'
|
plot_qqline
|
bool
|
Plot Q-Q line on the plot |
True
|
sig_threshold
|
float
|
The significance |
0.1
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in scTenifold/plotting/_plotting.py
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 | |
plot_hist
plot_hist(
df_1: DataFrame,
df_1_name: str,
df_2: Optional[DataFrame] = None,
df_2_name: Optional[str] = None,
sum_axis: int = 0,
label: str = "Sample",
figsize: Tuple[int, int] = (10, 8),
) -> None
Plot library-size histograms for one or two QC matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_1
|
DataFrame
|
Genes-by-cells (or cells-by-genes) DataFrame. |
required |
df_1_name
|
str
|
Legend label for |
required |
df_2
|
Optional[DataFrame]
|
Optional second DataFrame plotted on the same axes. |
None
|
df_2_name
|
Optional[str]
|
Legend label for |
None
|
sum_axis
|
int
|
Axis to sum over before histogramming ( |
0
|
label
|
str
|
X-axis label for the histogram. |
'Sample'
|
figsize
|
Tuple[int, int]
|
Figure size in inches. |
(10, 8)
|
Source code in scTenifold/plotting/_plotting.py
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 | |
plot_embedding
plot_embedding(
df: DataFrame,
groups: Optional[Dict[str, List[str]]],
method: str = "UMAP",
plot_2D: bool = True,
figsize: Tuple[int, int] = (8, 8),
size: int = 10,
title: Optional[str] = None,
palette: str = "muted",
**kwargs: object,
) -> None
Do dimension reduction and plot the embeddings onto a 2D plot
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A dataframe to perform dimension reduction |
required |
groups
|
Optional[Dict[str, List[str]]]
|
A dict indicating the groups |
required |
method
|
str
|
The name of used method, could be: PCA, TSNE, UMAP, Isomap, MDS, SpectralEmbedding, LocallyLinearEmbedding |
'UMAP'
|
plot_2D
|
bool
|
Draw a 2D or 3D (if false) plot |
True
|
figsize
|
Tuple[int, int]
|
The figure size of the plot: (width, height) |
(8, 8)
|
title
|
Optional[str]
|
The subplot's title |
None
|
palette
|
str
|
The name of used seaborn color palette, reference: https://seaborn.pydata.org/generated/seaborn.color_palette.html |
'muted'
|
kwargs
|
object
|
|
{}
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in scTenifold/plotting/_plotting.py
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 147 148 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 | |
Network Plots
plot_network_graph
plot_network_graph(
network: ndarray,
weight_thres: float = 0.1,
con_thres: float = 0,
) -> None
Plot graph of a PCnet
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
ndarray
|
A pc net |
required |
weight_thres
|
float
|
Minimum threshold of the pcnet's weights |
0.1
|
con_thres
|
float
|
Minimum threshold of sum of weights |
0
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in scTenifold/plotting/_plotting.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
plot_network_heatmap
plot_network_heatmap(
network: ndarray, figsize: Tuple[int, int] = (12, 12)
) -> None
Plot a heatmap of a PC network
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
ndarray
|
A pcnet |
required |
figsize
|
Tuple[int, int]
|
output figure size |
(12, 12)
|
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in scTenifold/plotting/_plotting.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
Embedding Preparation
prepare_PCA_dfs
prepare_PCA_dfs(
feature_df: DataFrame,
transform_func: Optional[
Callable[[DataFrame], DataFrame]
] = None,
n_components: Optional[int] = None,
standardize: bool = True,
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]
Run PCA on a genes-by-cells DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_df
|
DataFrame
|
Input expression DataFrame (rows are features, columns are samples). |
required |
transform_func
|
Optional[Callable[[DataFrame], DataFrame]]
|
Optional pre-PCA transform applied to |
None
|
n_components
|
Optional[int]
|
Number of components; defaults to |
None
|
standardize
|
bool
|
If True, z-score columns before PCA. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple ``(scores, explained_variance, loadings)`` as DataFrames.
|
|
Source code in scTenifold/plotting/_dim_reduction.py
30 31 32 33 34 35 36 37 38 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 | |
prepare_embedding_dfs
prepare_embedding_dfs(
feature_df: DataFrame,
transform_func: Optional[
Callable[[ndarray], ndarray]
] = None,
n_components: int = 2,
reducer: Union[str, Reducer] = "TSNE",
standardize: bool = True,
**kwargs: object,
) -> pd.DataFrame
Run a non-PCA dimensionality reducer on a feature DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feature_df
|
DataFrame
|
Input expression DataFrame (features x samples). |
required |
transform_func
|
Optional[Callable[[ndarray], ndarray]]
|
Optional pre-embedding transform applied to |
None
|
n_components
|
int
|
Number of embedding dimensions. |
2
|
reducer
|
Union[str, Reducer]
|
Reducer name or :class: |
'TSNE'
|
standardize
|
bool
|
If True, z-score columns before reduction. |
True
|
**kwargs
|
object
|
Forwarded to the underlying reducer class. |
{}
|
Returns:
| Type | Description |
|---|---|
Sample-by-component DataFrame.
|
|
Source code in scTenifold/plotting/_dim_reduction.py
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 | |