immunogenomics / symphony

Efficient and precise single-cell reference atlas mapping with Symphony
GNU General Public License v3.0
100 stars 22 forks source link

Suggestion to update the new source code #8

Closed Yale73 closed 3 years ago

Yale73 commented 3 years ago

Hi symphony team,

Thanks for such a great package. I like the plots it made and the mapping is also accurate. But I am wondering whether we can update the source code so that we can use the Seurat object as a reference.

The only know the following details to modify:

  1. plotReference() --- Error: Cannot find 'meta_data' in this Seurat object There is no meta_data, but meta.data in Seurat metadata. I know we can revise the source code by ourselves, but it will be convenient for beginners.

  2. mapQuery() --- Error: Cannot find 'vargenes' in this Seurat object We cannot get vargenes directly using ref_obj$vargenes$symbol. For Seurat object, we have to use ref_obj@assays[["RNA"]]@var.features. Also, ref_obj$vargenes$mean is ref_obj@assays[["RNA"]]@meta.features$vst.mean; ref_obj$vargenes$stddev is ref_obj@assays[["RNA"]]@meta.features$vst.variance.standardized

  3. scaleDataWithStats() ---Error in as(A, "dgCMatrix") : no method or default for coercing “Seurat” to “dgCMatrix” I tried many methods and don't know how to fix it.

Maybe you can write a function to build reference from Seurat object directly like buildReferenceFromHarmonyObj()

Thanks, Yale

joycekang commented 3 years ago

Hi Yale73, sorry for the delay in getting back to you about this. We have now made Symphony compatible with Seurat reference objects (as long as they are integrated using Harmony). Check out the Seurat tutorial under the vignettes folder for example code. Hope that helps!

joycekang commented 3 years ago

Closing this for now - let us know if you still have any issues!

massonix commented 3 years ago

Hi @joycekang,

Thanks so much for developing this package! I use harmony virtually for all my analysis and symphony will be the perfect complement.

I went through the Seurat tutorial under "vignettes", and I could run it successfully with my own data :)! The only bug that I found is in the function class::knn call of the knnPredict.Seurat` function:

knn_pred <- class::knn(t(ref_obj$Z_corr), Embeddings(query, 'harmony'), 
        ref$meta_data[[label_transfer]], k = k)

I switched:

Otherwise the function takes the objects "query" and "ref" defined outside the function.

In any case, it works wonders! I hope Symphony becomes the gold-standard method for HCA reference mapping.

Ramon

joycekang commented 3 years ago

Hi @massonix,

Thanks for catching the error! Will update the code.

Glad to hear Symphony is helpful for you!

joycekang commented 3 years ago

Hi Yale,

The function is located in utils_seurat.R (in the vignettes directory). We are working on moving those functions to the package itself, but those should work for now!

Joyce

From: Yale Liu @.> Reply-To: immunogenomics/symphony @.> Date: Friday, August 20, 2021 at 7:19 PM To: immunogenomics/symphony @.> Cc: "Kang, Joyce" @.>, Mention @.***> Subject: Re: [immunogenomics/symphony] Suggestion to update the new source code (#8)

Hi, @joycekanghttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_joycekang&d=DwMCaQ&c=WO-RGvefibhHBZq3fL85hQ&r=gkEq751KlSRJlVuy8SraU3Wb28v5yiP_3zek87VnAks&m=arTOBcYcFEMQwRQgcRfoR5u4uMYa1RwFU_Ti5yxcnDQ&s=EYgsNuQ4pkObKL1ZTDvQn-5AeNSwjJ_Il27Jd7tB4xE&e=

Sorry for the late reply. Thanks for the detailed vignette and I tested it today, Our vignette has buildReferenceFromSeurat, but I can not find the function. Can you let me know where the source code is and I can load it by myself?

Thanks, Yale

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_immunogenomics_symphony_issues_8-23issuecomment-2D903004291&d=DwMCaQ&c=WO-RGvefibhHBZq3fL85hQ&r=gkEq751KlSRJlVuy8SraU3Wb28v5yiP_3zek87VnAks&m=arTOBcYcFEMQwRQgcRfoR5u4uMYa1RwFU_Ti5yxcnDQ&s=mcyY7xHKxmJcygNHT1lBY3FzrVCNWVlf0M9_eHfXCmk&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ADCTGIZEFDNM7WJJ4VW2VJDT53PIPANCNFSM44DAXGBQ&d=DwMCaQ&c=WO-RGvefibhHBZq3fL85hQ&r=gkEq751KlSRJlVuy8SraU3Wb28v5yiP_3zek87VnAks&m=arTOBcYcFEMQwRQgcRfoR5u4uMYa1RwFU_Ti5yxcnDQ&s=CV4LzGMNwOCQIRFvui8UaSK2o6RtH8TRbhjngFIvw3o&e=. Triage notifications on the go with GitHub Mobile for iOShttps://urldefense.proofpoint.com/v2/url?u=https-3A__apps.apple.com_app_apple-2Dstore_id1477376905-3Fct-3Dnotification-2Demail-26mt-3D8-26pt-3D524675&d=DwMCaQ&c=WO-RGvefibhHBZq3fL85hQ&r=gkEq751KlSRJlVuy8SraU3Wb28v5yiP_3zek87VnAks&m=arTOBcYcFEMQwRQgcRfoR5u4uMYa1RwFU_Ti5yxcnDQ&s=6HmY389kQFFFEBlahDc8NrlaAFYpTc02HDD9LEdkYys&e= or Androidhttps://urldefense.proofpoint.com/v2/url?u=https-3A__play.google.com_store_apps_details-3Fid-3Dcom.github.android-26utm-5Fcampaign-3Dnotification-2Demail&d=DwMCaQ&c=WO-RGvefibhHBZq3fL85hQ&r=gkEq751KlSRJlVuy8SraU3Wb28v5yiP_3zek87VnAks&m=arTOBcYcFEMQwRQgcRfoR5u4uMYa1RwFU_Ti5yxcnDQ&s=HALDTuKxZX-0DP60_K1XQypTpt7Y1Xi9r9YBl75OUR4&e=.

Yale73 commented 3 years ago

@joycekang Thanks for your quick reply. I want to use my own object to check another dataset. There is cluster information (not seurat_clusters) I want to keep. Therefore, I didn't make the reference from the scratch. I started from the following code

Myobj <- RunHarmony.Seurat(Myobj, 'orig.ident')
ref <- buildReferenceFromSeurat(Myobj, verbose = TRUE, save_umap = TRUE, save_uwot_path = 'cache_symphony.uwot')

But the buildReferenceFromSeurat ran the following error. image

I found it is because of save_umap. When I set it FALSE, it works. But I have no idea whether it affects the results.

Thanks, Yale

joycekang commented 3 years ago

Hi Yale,

Thanks for the question. Based on the error message, I suspect that the main issue is that the Seurat object you are using as the reference had UMAP run using something other than the RunUMAP2 function in utils_seurat.R. In order to do the query-to-reference UMAP projection, Symphony requires that the reference UMAP model is stored according to the uwot package (which RunUMAP2 automates). If you ran UMAP separately beforehand, the model may not have been saved in a compatible format, which is leading to your error. Can you try RunUMAP2 prior to reference building (as shown in the vignette) and see if the error goes away? Note that this might change your UMAP embedding slightly from the version you may already have saved.