Tools
scyan.tools.umap(adata, markers=None, obsm=None, n_cells=200000, min_dist=0.5, obsm_key='X_umap', filter=None, **umap_kwargs)
Run a UMAP on a specific set of markers (or all markers by default). It can be useful to show differences that are due to some markers of interest, instead of using the whole panel.
Info
This function returns a UMAP reducer. You can reuse it with reducer.transform(...)
or save it with scyan.data.add.
Note
To actually plot the UMAP, use scyan.plot.umap.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
An |
required |
markers |
Optional[List[str]]
|
List marker names. By default, use all the panel markers, i.e., |
None
|
obsm |
Optional[str]
|
Name of the obsm to consider to train the UMAP. By default, uses |
None
|
n_cells |
Optional[int]
|
Number of cells to be considered for the UMAP (to accelerate it when \(N\) is very high). If |
200000
|
min_dist |
float
|
Min dist UMAP parameter. |
0.5
|
obsm_key |
str
|
Key for |
'X_umap'
|
filter |
Optional[Tuple]
|
Optional tuple |
None
|
**umap_kwargs |
int
|
Optional kwargs to provide to the |
{}
|
Returns:
Type | Description |
---|---|
UMAP
|
UMAP reducer. |
Source code in scyan/tools/representation.py
scyan.tools.leiden(adata, resolution=1, key_added='leiden', n_neighbors=15)
Leiden clustering
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
AnnData object. |
required |
resolution |
float
|
Resolution of the clustering. |
1
|
key_added |
str
|
Name of the key of adata.obs where clusters will be saved. |
'leiden'
|
n_neighbors |
int
|
Number of neighbors. |
15
|
Source code in scyan/tools/representation.py
scyan.tools.subcluster(adata, population, markers=None, key='scyan_pop', resolution=0.2, size_ratio_th=0.02, min_cells_th=200, n_cells=100000)
Create sub-clusters among a given populations, and filters small clusters according to (i) a minimum number of cells and (ii) a minimum ratio of cells.
Info
After having run this method, you can analyze the results with scyan.plot.umap and scyan.plot.pops_expressions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
An |
required |
population |
str
|
Name of the population to target (one of |
required |
markers |
Optional[List[str]]
|
Optional list of markers used to create subclusters. By default, uses the complete panel. |
None
|
key |
str
|
Key to look for population in |
'scyan_pop'
|
resolution |
float
|
Resolution used for leiden clustering. Higher resolution leads to more clusters. |
0.2
|
size_ratio_th |
float
|
(Only used if |
0.02
|
min_cells_th |
int
|
(Only used if |
200
|
n_cells |
int
|
Number of cells to be considered for the subclustering (to accelerate it when \(N\) is very high). If |
100000
|
Source code in scyan/tools/representation.py
scyan.tools.palette_level(table, population_index=0, level_index=1, hue_shift=0.4, alpha_l=0.25, step_l=0.15, alpha_s=0.3, step_s=0.4)
Computes a color palette that in grouped by the hierarchical main populations. It improves the UMAP readability when many populations are defined.
Info
Once such a color palette is defined, you can use it for plotting. For instance, try scyan.plot.umap(adata, color="scyan_pop", palette=palette)
, where palette
is the one you created with this function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
table |
DataFrame
|
Knowledge table provided to Scyan. It must be a multi-index DataFrame. |
required |
population_index |
Union[int, str]
|
Index or name of the level in |
0
|
level_index |
Union[int, str]
|
Index or name of the level in |
1
|
hue_shift |
float
|
Shift the hue values. The value must be a float in |
0.4
|
alpha_l |
float
|
Lower it to have a larger lightness range of colors. |
0.25
|
step_l |
float
|
Increase it to have more distinct colors (in term of lightness). |
0.15
|
alpha_s |
float
|
Lower it to have a larger saturation range of colors. |
0.3
|
step_s |
float
|
Increase it to have more distinct colors (in term of saturation). |
0.4
|
Returns:
Type | Description |
---|---|
Dict[str, Tuple[float]]
|
A dictionnary whose keys are population names and values are RGB colors. |
Source code in scyan/tools/colors.py
scyan.tools.cell_type_ratios(adata, groupby=None, normalize=True, key='scyan_pop', among=None)
Computes the ratio of cells per population. This ratio can be provided for each patient (or for any kind of 'group').
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
An |
required |
groupby |
Union[str, List[str], None]
|
Key(s) of |
None
|
normalize |
bool
|
If |
True
|
key |
str
|
Key of |
'scyan_pop'
|
among |
str
|
Key of |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
A DataFrame of ratios or counts (one row per group, one column per population). If |
Source code in scyan/tools/biomarkers.py
scyan.tools.mean_intensities(adata, groupby=None, layer=None, key='scyan_pop', unstack_join=' mean intensity on ', obsm=None, obsm_names=None)
Compute the Mean Metal Intensity (MMI) or Mean Fluorescence Intensity (MFI) per population. If needed, mean intensities can be computed per group (e.g., per patient) by providing the groupby
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
An |
required |
groupby |
Union[str, List[str], None]
|
Key(s) of |
None
|
layer |
Optional[str]
|
In which |
None
|
key |
str
|
Key of |
'scyan_pop'
|
unstack_join |
Optional[str]
|
If |
' mean intensity on '
|
obsm |
Optional[str]
|
In which |
None
|
obsm_names |
Optional[List[str]]
|
Ordered list of names in |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
A DataFrame of MFI. If |
Source code in scyan/tools/biomarkers.py
scyan.tools.PolygonGatingUMAP
Class used to select cells on a UMAP using polygons.
Note
If used on a Jupyter Notebook, you should first run %matplotlib tk
. After the selection, you can run %matplotlib inline
to retrieve the default behavior.
# Usage example (`%matplotlib tk` is required for the cell selection on jupyter notebooks)
>>> %matplotlib tk
>>> selector = scyan.tools.PolygonGatingUMAP(adata)
>>> selector.select() # select the cells
>>> sub_adata = selector.extract_adata() # on a notebook, this has to be on a new jupyter cell
Source code in scyan/tools/gating.py
__init__(adata)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata |
AnnData
|
An |
required |
select(s=0.05)
Open a UMAP plot on which you can draw a polygon to select cells.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s |
float
|
Size of the cells on the plot. |
0.05
|
Source code in scyan/tools/gating.py
save_selection(key_added='scyan_selected')
Save the selected cells in adata.obs[key_added]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_added |
str
|
Column name used to save the selected cells in |
'scyan_selected'
|
Source code in scyan/tools/gating.py
extract_adata()
Returns an anndata objects whose cells where inside the polygon
Source code in scyan/tools/gating.py
scyan.tools.PolygonGatingScatter
Class used to select cells on a scatterplot using polygons.
Note
If used on a Jupyter Notebook, you should first run %matplotlib tk
. After the selection, you can run %matplotlib inline
to retrieve the default behavior.
# Usage example (`%matplotlib tk` is required for the cell selection on jupyter notebooks)
>>> %matplotlib tk
>>> selector = scyan.tools.PolygonGatingScatter(adata)
>>> selector.select() # select the cells
>>> sub_adata = selector.extract_adata() # on a notebook, this has to be on a new jupyter cell
Source code in scyan/tools/gating.py
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
__init__(adata)
select(x, y, s=0.05, max_cells_display=100000)
Open a scatter plot on which you can draw a polygon to select cells.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
str
|
Column name of adata.obs used for the x-axis |
required |
y |
str
|
Column name of adata.obs used for the y-axis |
required |
s |
float
|
Size of the cells on the plot. |
0.05
|
Source code in scyan/tools/gating.py
save_selection(key_added='scyan_selected')
Save the selected cells in adata.obs[key_added]
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_added |
str
|
Column name used to save the selected cells in |
'scyan_selected'
|
Source code in scyan/tools/gating.py
extract_adata()
Returns an anndata objects whose cells where inside the polygon