Plotting

scSELpy can be employed to manual select and annotate cells on scanpy generated plots. The following plots are supported: UMAP, TSNE, PCA and scatter plots. All these plots take the normal scanpy parameters, with additonal scSELpy parameters. The scSELpy parameters are the same for all 4, unless specified otherwise.

If none of the above mentioned embeddings work, scSELpy also supports scanpy’s embedding plotting parameter.

UMAP

scselpy.pl.umap(adata,*kwargs)

TSNE

scselpy.pl.tsne(adata,*kwargs)

PCA

scselpy.pl.pca(adata,*kwargs)

Scatter plot

scselpy.pl.scatter(adata,x,y,*kwargs)
For example:
scselpy.pl.scatter(adata,'n_genes','n_counts',color="ATCB")

Embedding

scselpy.pl.embedding(adata,basis=arg,*kwargs)
For example, in order to run umap:
scselpy.pl.embedding(adata,basis="X_umap",color="ATCB")

Parameters

 line_palette: None, list (default: None)
    A list with colors for the lines of the drawn polygons.

 line_labels: None, str, list (default: None)
    Labels for the polygon on the plot. The labels given will not rename the polygon. This has to be done after running scSELpy. See Renaming scSELpy annotations

 linestyle: None, str, list (default: '-')
    Specify the style of the polygon lines. Options are -, .,-- and -.. If you want to select 3 polygons, you can pass [".","-","--"]

 line_loc: None, str (default: 'upper left')
    Handles the legend location of the second legend, namely the one of the line labels for the polygons. See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html for more information

 line_bbox_to_anchor: None, tuple (default: (1, 1))
    Same as the line_loc parameter.

 line_handlelength: None, int, float (default: None)
    Handles the line length of the lines in the second legend. Can be usefull when changing plt.rcParams['font.size']

 unselected_cells: str (default: 'Other')
    All cells that are not located within a polygon will be denominated as "Other" by default. Changing this parameter will denominate all unselected cells to the name given here. If an integer in string format will be given here, scSELpy might not work properly.

 load: None, str (default: None)
    Load an Anndata obvservation, on which annotations will be added. For example, load="REMAP_1" (default scSELpy output) or load="leiden_r0.5". For concrete examples please check the toturial.

 replot_lines: None, str (default: None)
    Using this parameter can replot polygons drawn from previous scSELpy invocations. Takes an Unstructured Anndata annotation stored by an earlier invocation of scSELpy. When this parameter is used, the user can not draw new lines, with the exception for when used together with the load parameter. In the latter case, all previously and newly drawn polygons will be annotated on the loaded Anndata obvservation.

 overwrite: bool (default: False)
    While overwrite = False, multiple polygons that overlap the same cell, will have the name annotated to that cell. For example "1,2,3" when Polygon 1, 2 and 3 overlap this cell. In the case that overwrite = True, only the last Polygon will be annotated. Therefore the output will be "3", even when Polygon 1, 2 and 3 overlap it.

 printcords: bool (default: False)
    Print out the coordinates of the selected lines. These can be used for the mock parameter.

 use_log_scale: bool (default: False)
    If you wish to use the log scale in plots. Could be used e.g. for selecting antibody data in scatter plots in combination with use_raw=True.

 skip_float_check: bool (default: False)
    When running scatter plots, scSELpy will automatically check if the input is float. If this is not the case, it will return an error. To disable this error, run skip_float_check = True

 mock: None, dict (default: None)
    Automatically runs scSELpy with preset coordinates, the user will not be able to make a selection. This can be handy when rerunning pipelines. For usage instructions please check the Mock section in the documentation.

 save: None, str (default: None)
    Saves figure in provided path+filename. If only a filename is provided, will save in "figures/"+filename. Does not work the same as in scanpy. scanpy.set_figure_params should still work.

 interactive_backend: str, None (default: None)
    Default: None if not running on Jupyter Notebook (In this case, backend will only switch if you specify this parameter). If running on Jupyter: Qt5Agg. If running scSELpy on Jupyter Notebook, the drawing of polygons requires the use of an interactive backend. If the default back-end does not work propperly on your computer, you can change it. More information at https://matplotlib.org/stable/users/explain/backends.html

 timeout: float, int (default: 60)
    Amount of seconds until the drawing of the polygons will automatically stop.

 helpbox: bool (default: False)
    Before drawing, shows some text that gives instructions for drawing polygons

Removed or changed parameters

In general, all scanpy plotting parameters can be passed to the scselpy.pl.* functions, with the exception of:

  • Layers or Layer

The following parameters have been changed:

  • components in scSELpy, you can only have 2 dimensions. e.g. the 3rd and 4th component.

  • save As shown in parameters, scSELpy has its own saving function implemented.

Running other commands (Not supported)

In case the user would like to use scSELpy with other commands, it is technically possible by calling scSELpy’s Remap() function directly and set its internal parameter override to True:

scselpy.pl._scselpy.Remap(adata,override=True,scat_plot=False,basis=<input from obsm>,plotattr=<function>,remove_show_override=True)

scat_plot defines if the entry is a scatter plot. If passing a scatterplot, use the arguments “x_scat” and “y_scat”. Options: “scat”,”embedding” and anything else, e.g. False

plotattr passes the function that we want to run. e.g. sc.pl.umap, sc.pl.draw_graph or maybe even a function that does not stem from scanpy.

remove_show_override disables the scSELpy internal override which always passes show=False to scanpy. The default of remove_show_override=True, this is probabaly the best if not running scanpy directly.

With the following command we run a scatter plot this way:

scselpy.pl._scselpy.Remap(adata,x_scat="n_counts",y_scat="n_genes",override=True,scat_plot="scat",plotattr=sc.pl.scatter,remove_show_override=False)

To run this on e.g. Scanpy’s draw_graph:

scselpy.pl._scselpy.Remap(adata,override=True,scat_plot=False,basis="X_draw_graph_fa",plotattr=sc.pl.draw_graph,remove_show_override=False)

To try this on an external Scanpy-based package, such as Scirpy:

import scirpy as ir
df, dst, lk = ir.tl.repertoire_overlap(adata, "CD4_and_CD8_cells", inplace=False)
dfT = df.T
First = "CD8"
Second = "CD4"
adata.obsm['X_Repertoire'] = np.array([[dfT[First][ID],dfT[Second][ID]] if np.isnan(float(ID)) == False else [0.0,0.0] for ID in list(adata.obs["clone_id"])])
scselpy.pl._scselpy.Remap(adata,override=True,remove_show_override=True,scat_plot=False,basis="X_Repertoire",plotattr=ir.pl.repertoire_overlap,...)



This function only works on scanpy-based packages and if the Anndata object is the only non-keyword argument.