harmony icon indicating copy to clipboard operation
harmony copied to clipboard

Best Practices for Sequential vs. Parallel Regression of Multiple Covariates in Harmony

Open vertesy opened this issue 1 year ago • 3 comments

Hello,

I'm using Seurat with Harmony for batch correction in my scRNA-seq analysis, and I have a question regarding the regression of multiple covariates.

Background:

I want to regress out three covariates from my data:

  • Library
  • SampleType
  • CellCyclePhase

Initially, I attempted to regress out all three covariates in parallel by concatenating the corresponding metadata columns, split the merged object, and providing that to Harmony. It fails at splitting, because of too small / empty categories.

Splitting ‘counts’, ‘data’ layers. Not splitting ‘scale.data’. If you would like to split other layers, set in `layers` argument.
Error in validObject(object = object) : 
  invalid class “Assay5” object: Layers must be two-dimensional objects

I understand that small categories will also be a problem for correction, even if I fix the failing data split.

Not sure how I can solve this:

  1. Ignore some covariates
  2. Subset to SampleType 1, and keep covariates (Library, CellCyclePhase). Repeat for s.t.2. Suboptimal.
  3. Regress out cell cycle scores in ScaleData(), and provide covariates SampleType and Library to Harmony. (or variations thereof)
    1. One issue is that regression in ScaleData() works much less well then Harmony to remove differences.
    2. (related to #262)
  4. Iterative / Sequential / Serial Harmony corrections.

I recall that the Harmony authors discussed a "serial Harmony" approach, where covariates are corrected sequentially rather than in parallel, but I haven't been able to re-find that discussion again.

My Questions:

  1. Is there a recommended practice for handling situations where (concatenating covariates leads to / there are) too many, and sparse categories?

    (other than don't do it)

  2. Can I legitimately overcome the small categories problem by sequential Harmony, and should result in equivalent results to parallel regression in Harmony (assuming both are possible)?

    • Could sequential regression help mitigate issues arising from sparse category combinations?
  3. How can I implement sequential regression of covariates in Harmony within Seurat?

    • Feed "harmony" reduction into RunHarmony() instead of "pca" at the 2nd and 3rd variable?
    • Are there recommended workflows or code examples for applying Harmony multiple times, each time correcting for a single covariate?
    • Do I need to adjust Harmony parameters, e.g Library has 25 categories, Phase has 3.

Additional Context:

Thank you for your time taken.

vertesy avatar Nov 05 '24 12:11 vertesy

Hi @vertesy!

I have always had struggles with data integration and batch effect removals. Also, I find that there are several ways of removing an effect (within the ScaleData() function, with RunHarmony() or IntegrateData()). Did you get any answer or could you solved it through any other way?

Thank you!

jcasadogp avatar May 19 '25 16:05 jcasadogp

I think ignored some of the covariates at the end, but did not find a proper answer.

vertesy avatar Aug 18 '25 07:08 vertesy

Hello @vertesy I was in similar issue as this. Did you figure out a way to do this? Im using seurat V5 by the way I tried:

  1. Split on covariate X, integrate based on this covariate X. The input reduction was the pca. The output is reduction1
  2. Join the layers.
  3. Split on covariate Y, integrate based on covariate Y. Save this in reduction2

The input reduction for second pass of harmony has to be pca since as far as i can understand the input indicates the original embedding of the cells based on which harmony calculates cluster assignments etc etc. So if I were to cluster assign again based on a "corrected assignment" the clustering is collapsing. Since my UMAP/tsne looks bad if I feed harmony embedding from step 1 to step 3. I ended up with variable by var1_Var2 and corrected on that and it looks better.

Did you ignore the other covars?

Shubhra-B avatar Sep 15 '25 09:09 Shubhra-B