theislab / scvelo

RNA Velocity generalized through dynamical modeling
https://scvelo.org
BSD 3-Clause "New" or "Revised" License
408 stars 103 forks source link

scv.utils.merge does not combine the adata and ldata #1167

Closed smallfishcui closed 9 months ago

smallfishcui commented 9 months ago

Hi dear development team,

I am using scvelo to do RNA velocity analysis for two samples. Here is my code,

adata = sc.read_h5ad("processed_seurat_object.h5ad") #this is a combined h5ad object, including 2 samples ldata1 = scv.read("./NAin.loom") ldata2 = scv.read("./EU.loom")

rename barcodes in order to merge:

barcodes = [bc.split(':')[1] for bc in ldata1.obs.index.tolist()] barcodes = ['NAin_' + bc[0:len(bc)-1] for bc in barcodes] ldata1.obs.index = barcodes

barcodes = [bc.split(':')[1] for bc in ldata2.obs.index.tolist()] barcodes = ['EU_' + bc[0:len(bc)-1] for bc in barcodes] ldata2.obs.index = barcodes

barcodes = [bc.split('-')[0] for bc in adata.obs.index.tolist()] substring_toreplace1 = '1' replacementsubstring1 = 'EU' modified_list = [bc.replace(substring_to_replace1, replacement_substring1) for bc in barcodes] substring_toreplace2 = '2' replacementsubstring2 = 'NA' modified_list = [bc.replace(substring_to_replace2, replacement_substring2) for bc in modified_list] adata.obs.index=modified_list

subsetting

Sample= adata.obs['Sample'] adata1 = adata[adata.obs['Sample'] == "EU"] adata2= adata[adata.obs['Sample'] == "NAin"]

make variable names unique

ldata1.var_names_make_unique() ldata2.var_names_make_unique()

scv.utils.clean_obs_names(adata1) scv.utils.clean_obs_names(ldata1)

adata1=scv.utils.merge(adata1, ldata1)

The code did not result an error. However, the resulted object was still the original adata file, and the spliced/unspliced layers in the ldata1 was not merged at all. Can you help me to check what is wrong here?

thanks, Cui

smallfishcui commented 9 months ago

well I noticed the adata1 should be merged with ldata2 here. But even if I used the right objects, the layers are still missing in the merged objects.

smallfishcui commented 9 months ago

Hi,

I figured out the problem. The h5ad file was produced by Seurat in R, and Seurat replace all the underscores '' in the transcript names to '-'. Here, when we do the merging, apart from making the sampleID in .obs, we should also make sure the index in .var is the same between adata and ldata. When I replace the hyphen '-' to '' in adata1.var, the layers were merged successfully. I will close this issue now.

best, Cui