Could not find spliced / unspliced counts after merging data
Closed this issue · 4 comments
liyiwang0725 commented
Hi everyone,
I meet problem after merging snRNA-seq data and loom data, there is no spliced and unspliced in layers.
Above is the code and error output.
Thanks for your help!
# load loom data
F1=anndata.read_loom("/count1.loom")
M1=anndata.read_loom("/count2.loom")
F2=anndata.read_loom("/count3.loom")
M2=anndata.read_loom("/count4.loom")
F3=anndata.read_loom("/count5.loom")
M3=anndata.read_loom("/count6.loom")
F4=anndata.read_loom("/count7.loom")
M4=anndata.read_loom("/count8.loom")
barcodes = [bc.split(':')[1] for bc in F1.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['F1_'+ bc[0:len(bc)] for bc in barcodes]
F1.obs.index = barcodes
F1.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in F2.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['F2_'+ bc[0:len(bc)] for bc in barcodes]
F2.obs.index = barcodes
F2.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in F3.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['F3_'+ bc[0:len(bc)] for bc in barcodes]
F3.obs.index = barcodes
F3.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in F4.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['F4_'+ bc[0:len(bc)] for bc in barcodes]
F4.obs.index = barcodes
F4.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in M1.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['M1_'+ bc[0:len(bc)] for bc in barcodes]
M1.obs.index = barcodes
M1.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in M2.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['M2_'+ bc[0:len(bc)] for bc in barcodes]
M2.obs.index = barcodes
M2.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in M3.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['M3_'+ bc[0:len(bc)] for bc in barcodes]
M3.obs.index = barcodes
M3.var_names_make_unique()
barcodes = [bc.split(':')[1] for bc in M4.obs.index.tolist()]
barcodes=[bc[0:len(bc)-1]+'-1' for bc in barcodes]
barcodes=['M4_'+ bc[0:len(bc)] for bc in barcodes]
M4.obs.index = barcodes
M4.var_names_make_unique()
#merge loom data
ldata= F1.concatenate([F2,F3,F4,M1,M2,M3,M4])
#load snRNA-seq data
expr_matrix = scipy.io.mmread("/expr_matrix.mtx").T
cell_metadata = pd.read_csv("/cell_metadata.csv", index_col=0)
gene_metadata = pd.read_csv("/gene_metadata.csv", index_col=0)
adata = ad.AnnData(X=expr_matrix, obs=cell_metadata, var=gene_metadata)
#merge ldata and data
adata.X = adata.X.tocsr()
loom_data.X = loom_data.X.tocsr()
adata = scv.utils.merge(adata, ldata)
adata
#gene selection and normalization
scv.pp.filter_and_normalize(adata,min_shared_counts=20,n_top_genes=2000)
<!-- Error Output -->
WARNING: Could not find spliced / unspliced counts.
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
[<ipython-input-16-c2fd51ae0fb6>](https://c0tca9bzkbn-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241023-060115_RC00_688913526#) in <cell line: 1>()
----> 1 scv.pp.filter_and_normalize(adata,min_shared_counts=20,n_top_genes=2000)
2 scv.pp.moments(adata,n_pcs=30,n_neighbors=30)
3 scv.tl.recover_dynamics(adata)
4 scv.tl.velocity(adata,mode='dynamical')
5 scv.tl.velocity_graph(adata)
2 frames
[/usr/local/lib/python3.10/dist-packages/anndata/_core/aligned_mapping.py](https://c0tca9bzkbn-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241023-060115_RC00_688913526#) in __getitem__(self, key)
211
212 def __getitem__(self, key: str) -> Value:
--> 213 return self._data[key]
214
215 def __setitem__(self, key: str, value: Value):
KeyError: 'spliced'
fanjiacheng-max commented
When converting Seurat objects to h5ad files, some errors may occur, resulting in incomplete files. You can try other conversion methods, or save the matrix and regenerate the object in Scanpy.
liyiwang0725 commented
When converting Seurat objects to h5ad files, some errors may occur, resulting in incomplete files. You can try other conversion methods, or save the matrix and regenerate the object in Scanpy.
I used sceasy to convert Seurat to h5ad and now it worked.
Thank you so much for your help!
babySherlock commented
请问你的seurat是V4吗
liyiwang0725 commented
请问你的seurat是V4吗
我的是v5