-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map new data when using Seurat object #120
Comments
It looks like One quick fix for it is to convert sparse matrices into dense matrices, i.e. WT_adata.X = WT_adata.X.A
Mutant_adata.X = Mutant_adata.X.A |
I tried to convert sparse matrices into dense matrices. However, I got the following error :
|
Hmmm, they seem already numpy arrays, which kind of contradicts the previous error.. is there a dummy dataset you can share to reproduce the issue? I m happy to take a closer look. |
Sorry for the late reply. I tried to rerun the scripts and found out that converting sparse matrices into dense matrices works. Howerver, I still encounter another problem when mapping data.
It seems that my adata contain something unexpected var after converting from Seurat object. Here is my adata :
|
The two anndata objects both look fine to me. It's difficult to understand what's going on without knowing the output of |
Here are a subset of WT_adata and Mutant_adata which both downsampled to 1000 cells. You can download the data from this url : https://mab.to/5HqGKVtVt import anndata as ad
import stream as st
WT_adata = ad.read_loom("Seurat_1000cells_integrated_WT_germline_scRNA.loom")
## convert sparse matrices into dense matrices
WT_adata.X = WT_adata.X.A
## Feature selection
st.select_variable_genes(WT_adata,loess_frac=0.01, n_genes=2000)
## select top principal components using variable genes
st.select_top_principal_components(WT_adata,n_pc=30,feature='var_genes',first_pc=False)
WT_adata.obsm['top_pcs'] = WT_adata.obsm['pca_cell_embeddings']
## dimension_reduction
st.dimension_reduction(WT_adata,method='mlle',feature='top_pcs',n_jobs=4,n_neighbors=30)
st.plot_dimension_reduction(WT_adata,color=['rough_cell_type'],n_components=2,show_graph=False,show_text=False)
## Trajectory inference
# Seeding the initial elastic principal graph
st.seed_elastic_principal_graph(WT_adata,n_clusters=10)
st.elastic_principal_graph(WT_adata,epg_alpha=0.05,epg_mu=0.05,epg_lambda=0.05,epg_trimmingradius=0.1)
#Extend leaf branch to reach further cells
st.extend_elastic_principal_graph(WT_adata)
## mapping
Mutant_adata = ad.read_loom("Seurat_1000cells_integrated_Mutant_germline_scRNA.loom")
Mutant_adata.obsm['top_pcs'] = Mutant_adata.obsm['pca_cell_embeddings']
# convert sparse matrices into dense matrices
Mutant_adata.X = Mutant_adata.X.A
adata_combined = st.map_new_data(WT_adata,Mutant_adata) Thanks a lot for your help! |
Hi, Thanks for sharing the data. I was able to reproduce the error. Basically the error was caused by the auto-change of variable keys of the same name when concatenating two anndata objects (The same variable key A simple workaround would be to rename either one of them, e.g. Mutant_adata = ad.read_loom("./Seurat_1000cells_integrated_Mutant_germline_scRNA.loom")
st.set_workdir(WT_adata, './stream_result')
st.set_workdir(Mutant_adata, './stream_mapping_result')
Mutant_adata.var.rename(columns={"Selected": "Selected_mutant"},inplace=True)
Mutant_adata.obsm['top_pcs'] = Mutant_adata.obsm['pca_cell_embeddings']
# convert sparse matrices into dense matrices
Mutant_adata.X = Mutant_adata.X.A
adata_combined = st.map_new_data(WT_adata,Mutant_adata) The above code works for me. |
Thanks for your help and sorry to bother you again. I can sucessfully run
I tried to run |
No problem. I'm glad the above solution worked out for you. Re the plotting error, unfortunately I was not able to reproduce it. With the same dataset you shared previously, the same function works for me. But it seems to have something to do with the data type. Can you change the data type from
|
Hi,
I have precomputed two seurat objects. After infering trajectory for one seurat object, I'd like to map cells from the other seurat object to the precomputed trajectory. However, there is an error when I run map_new_data() function :
The following is my code :
I tried to run select_top_principal_components() function for WT_adata, but there is another error :
Could anyone please tell me how to solve this problem? Thanks a lot !
The text was updated successfully, but these errors were encountered: