type error in add_anno
schmucr1 opened this issue · 1 comments
schmucr1 commented
Hi
I believe there should be a conversion to str
in the if
-statement for the error message: instead of len(notmatched)
, it should be str(len(notmatched))
. Otherwise, concatenation for the print
statement does not work.
Original code:
def add_anno(adata, cnames, mycol, clusters='leiden'):
""" Adds annotation generated with make_anno to a AnnData object
Takes as input the AnnData object to which annotation will be appended and the annotation pd
Generates a pd.Series that can be added as a adata.obs column with annotation at a level
Parameters
----------
adata: AnnData
AnnData object that is to be annotated
cnames: panda.DataFrame
a list of cluster names generated with make_anno
mycol: string
column to be added
clusters: string
initial cluster used for annotation (column in adata.obs)
returns
-------
pd.Series
the annotated cells
"""
newlab = adata.obs[clusters]
# mycol='celltype0'
notmatched = list(set(list(cnames.index))-set(newlab))
if len(notmatched) > 0:
errm = 'Please check that you have indexed the correct clustering. ' + \
len(notmatched) + 'clusterIDs not found in ' + clusters
return(errm)
else:
for i in list(set(newlab)):
newlab = newlab.replace(i, cnames.loc[i, mycol]).copy()
return(newlab)
alberto-valdeolivas commented