Skip to content
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

Seurat object as reference #17

Closed
NK-HD opened this issue Oct 23, 2021 · 8 comments
Closed

Seurat object as reference #17

NK-HD opened this issue Oct 23, 2021 · 8 comments

Comments

@NK-HD
Copy link

NK-HD commented Oct 23, 2021

Dear Symphony Team,

thank you for developing this very interesting package!

could you maybe assist me on how to use an existing (harmony based integrated) Seurat object as a reference to map new datasets (ideally Seurat datasets) on?

Thank you very much in advance fr your help!
Best,
Niklas

@wfma
Copy link

wfma commented Oct 31, 2021

i have a similar question also-

  ref = readRDS('references/Symphony_ref_data/fibroblast_atlas.rds')

  query = symphony::mapQuery(seuratobj@assays$RNA, [email protected], ref, 
                   vars = [email protected], 
                   do_normalize = TRUE)

this does not work... I get the following output. Do yall have an example with working with Seurat Obj?

Normalizing
Error in as(A, "dgCMatrix") : 
  no method or default for coercing “Assay” to “dgCMatrix”

Many thanks!!!

@alexvpickering
Copy link

alexvpickering commented Nov 16, 2021

You need to get the counts dgCMatrix from the object. Also, vars is the column names of meta_data that you want to harmonize over (a batch variable). Something like this:

query = symphony::mapQuery(
  seuratobj[['RNA']]@counts,
  seuratobj@meta.data,
  ref, 
  vars = 'samples',  # use column names from your meta_data
  do_normalize = TRUE)

@wfma
Copy link

wfma commented Nov 22, 2021

Thank you! I attempted the above code and it worked! Will update if anything else needs attention. Wei

@NK-HD
Copy link
Author

NK-HD commented Nov 22, 2021

Hey, thank you very much for your solution!
As far as I see, this works with a symphony reference, but is there a way (and ideally a code snip) to use a preexisting Seurat object (Harmony integrated) (and it´s UMAP and its clusters) as a reference?
Thank you very much!!!
Best, Niklas

@alexvpickering
Copy link

@NK-HD I've had success following this vignette when creating references for docs.dseqr.com. Happy to add another reference there if it's something public and of general use

@NK-HD
Copy link
Author

NK-HD commented Jan 15, 2022

@alexvpickering and everybody else :)
Thank you very much for the vignette and help!

I have a specific problem now since I would like to use an existing seurat object and the according clusters (RunHarmony() already done) as a reference to analyse new data by using the same clustering.

So I can´t re-run RunHarmony.Seurat without redoing the whole clustering and downstream analysis (right?).

As I understand it the issue is here in the buildReferenceFromSeurat() function:

res$R <- t(obj@reductions$harmony@misc$R)
message('Saved soft cluster assignments')

Error:
Error in t.default(obj@reductions$harmony@misc$R) :
argument is not a matrix

This data is apparently not in the object when this is processed with the default RunHarmony() function, as I understand it, correct?

Would it be possible to extract that info by any other way from a seurat object processed by the default RunHarmony() function?

Thank you very much for your help!!!!
Best, Niklas

@joycekang
Copy link
Collaborator

Hi @NK-HD ,

Thanks so much for your message! Unfortunately, it is not currently possible to make an existing Harmony object into a mappable Symphony object without rerunning the integration step with the RunHarmony.Seurat function. This is because the RunHarmony.Seurat function calculates and saves additional components of the reference needed for mapping. Hopefully, if you run RunHarmony.Seurat it should give you the same or nearly the same embedding as the first time you ran RunHarmony() (it'd be good to check this anyway for the sake of reproducibility). Apologies for the inconvenience - we will try to think of a way to "Symphonize" a legacy Harmony object in the future.

@cedmo001
Copy link

cedmo001 commented Nov 2, 2023

Hi @joycekang,

Is there any update on the comment above re: making an existing Harmony object into a Symphony object without rerunning RunHarmony.Seurat?

This would be very useful for my pipeline!

Many thanks for such a great tool :)

Best,
C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants