I'm trying to create a Dotplot in R using scanpy with reticulate.
It works as expected unless I try to add the var_group_positions argument to the function.
I don't understand which R object I have to pass to this function in order to be recognized well by scanpy/reticulate for var_group_positions.
library(anndata)
library(sceasy)
library(reticulate)
sc <- reticulate::import(module="scanpy",convert = FALSE)
# This works well , no worries
adata_sce <- sc$AnnData(
X = t(x),
obs = as.data.frame(colData(spe.sub)),
var = var
)
# I create the content for var_group_positions
subset <- c("B.cell","T.cell","Fibroblast","Ovarian.cancer.cell")
list <- list()
for (celltype in subset){
inds <- which(celltype == ano)
list[[length(list)+1]]<- c(min(inds), max(inds))
names(list)[length(list)] <- celltype
}
print(list)
$B.cell
[1] 1 7
$T.cell
[1] 54 70
$Fibroblast
[1] 8 40
$Ovarian.cancer.cell
[1] 41 53
sc$pl$DotPlot(adata_sce,
var_names=names(markers_ENSEMBL),
var_group_positions = r_to_py(unname(list)),
var_group_labels = r_to_py(subset),
groupby="spatial.cluster.name")$savefig("plot.pdf")
I got this error :
**Erreur dans py_call_impl(callable, call_args$unnamed, call_args$named)
: TypeError: can only concatenate str (not "float") to str Run
`reticulate::py_last_error()` for details. Appels : <Anonymous> ->
py_call_impl Exécution arrêtée**
From the doc :
var_group_positions
Sequence[tuple[int, int]] | None (default: None)
Use this parameter to highlight groups of var_names. This will draw a ‘bracket’ or a color block between the given start and end positions. If the parameter var_group_labels is set, the corresponding labels are added on top/left. E.g. var_group_positions=[(4,10)] will add a bracket between the fourth var_name and the tenth var_name. By giving more positions, more brackets/color blocks are drawn.
After a bunch of coffee on monday morning, it worked fine. Hope this could help other folks that are lazy enough to open a pure python script.