Closed Yuan-9 closed 9 months ago
This may be useful:
https://github.com/immunogenomics/harmony/releases
I would expect that v0.1 would reproduce most results. Version 1 is different.
On Fri, Jan 5, 2024, 03:00 绛雪 @.***> wrote:
How do I download version 0.99.9 of harmony? Many of the papers I need to reproduce use this version of harmony, but I can't find a way to install it anywhere.
— Reply to this email directly, view it on GitHub https://github.com/immunogenomics/harmony/issues/235, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSFW2G4ZFNFM7ZQGIRKNATYM6XILAVCNFSM6AAAAABBOBXRNKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DMOBZG4ZDENY . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Thanks for your very quick reply! I tried using the v0.1 version of harmony provided in the repository, but when I installed it it said the version was 1.0.
packageVersion('harmony') [1] ‘1.0’ remove.packages("harmony") Removing package from ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified) packageVersion('harmony') Error in packageVersion("harmony") : there is no package called ‘harmony’ devtools::install_version("harmony", version = "0.1") Warning: unable to access index for repository https://inwt-vmeh2.inwt.de/r-repo/src/contrib: cannot open URL 'https://inwt-vmeh2.inwt.de/r-repo/src/contrib/PACKAGES' Trying https://packagemanager.posit.co/cran/2020-04-23 Trying file:////r-repo/ Trying https://inwt-vmeh2.inwt.de/r-repo/ Trying https://inwtlab.github.io/drat/ Error in download_version_url(package, version, repos, type): couldn't find package 'harmony' install.packages("/home/1/harmony-0.1.tar.gz", repos = NULL, type = "source") Installing package into ‘/usr/local/lib/R/site-library’ (as ‘lib’ is unspecified)
Warning in untar2(tarfile, files, list, exdir, restore_times): skipping pax global extended headers
packageVersion('harmony') [1] ‘1.0’
You need to install it through the release zip on the link I provided.
I believe that you can do that with the devtools::install_local($PATH_EXTRACTED_ZIP) or with the R CMD INSTALL
I found a 0.1 version of harmony on cran and after I ran: Error in UseMethod("RunHarmony") : no applicable method for 'RunHarmony' applied to an object of class "seurat"
traceback() 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#100 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R") packageVersion("harmony") [1] ‘0.1.0’
I don't have this problem when running version 1.0 of harmony. When using version 1.0, I will get an error: Error in eval(ei, envir) : element-wise pow(): incompatible matrix dimensions: 50x2 and 2x1 traceback() 13: stop(list(message = "element-wise pow(): incompatible matrix dimensions: 50x2 and 2x1", call = eval(ei, envir), cppstack = NULL)) 12: .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x5613a16a03b0>, dll = list(name = "Rcpp", path = "/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x5613a24d9230>, info = <pointer: 0x5613a029ae40>), numParameters = -1L), <pointer: 0x5613a5371390>, <pointer: 0x5613a27b3bc0>, .pointer) 11: harmonyObj$cluster_cpp() 10: cluster(harmonyObj) 9: harmonize(harmonyObj, max.iter.harmony, verbose) 8: HarmonyMatrix(pca_embedding, metavars_df, group.by.vars, FALSE, 0, theta, lambda, sigma, nclust, tau, block.size, max.iter.harmony, max.iter.cluster, epsilon.cluster, epsilon.harmony, plot_convergence, FALSE, verbose, reference_values) 7: RunHarmony.seurat(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#100 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R")
Is there any information that can help me fix the bug?
I found a 0.1 version of harmony on cran and after I ran: Error in UseMethod("RunHarmony") : no applicable method for 'RunHarmony' applied to an object of class "seurat"
traceback() 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#100 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R") packageVersion("harmony") [1] ‘0.1.0’
What values of theta are you using? Also what is the batch_label? Is this harmony v1?
I found a 0.1 version of harmony on cran and after I ran: Error in UseMethod("RunHarmony") : no applicable method for 'RunHarmony' applied to an object of class "seurat"
traceback() 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#100 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R") packageVersion("harmony") [1] ‘0.1.0’
I call it like this:
theta_harmony = 2 numclust = 50 max_iter_cluster = 100 b_seurat <- RunPCA(object = b_seurat, pcs.compute = npcs, pc.genes = b_seurat@var.genes, do.print = TRUE, pcs.print = 1:5, genes.print = 5)
b_seurat <- RunHarmony(object = b_seurat, group.by.vars =batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster)
harmony version is 0.1.0, Seurat version is 2.3.3
I don't have this problem when running version 1.0 of harmony. When using version 1.0, I will get an error: Error in eval(ei, envir) : element-wise pow(): incompatible matrix dimensions: 50x2 and 2x1 traceback() 13: stop(list(message = "element-wise pow(): incompatible matrix dimensions: 50x2 and 2x1", call = eval(ei, envir), cppstack = NULL)) 12: .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x5613a16a03b0>, dll = list(name = "Rcpp", path = "/usr/local/lib/R/site-library/Rcpp/libs/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x5613a24d9230>, info = <pointer: 0x5613a029ae40>), numParameters = -1L), <pointer: 0x5613a5371390>, <pointer: 0x5613a27b3bc0>, .pointer) 11: harmonyObj$cluster_cpp() 10: cluster(harmonyObj) 9: harmonize(harmonyObj, max.iter.harmony, verbose) 8: HarmonyMatrix(pca_embedding, metavars_df, group.by.vars, FALSE, 0, theta, lambda, sigma, nclust, tau, block.size, max.iter.harmony, max.iter.cluster, epsilon.cluster, epsilon.harmony, plot_convergence, FALSE, verbose, reference_values) 7: RunHarmony.seurat(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#100 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R")
Is there any information that can help me fix the bug?
The harmony version of this is 1.0
batch_label is "batch"
b_seurat@meta.data nGene nUMI batch T-cell_Thymus_1.GCGTCCGGTACACCGCTA 525 672 1 T-cell_Thymus_2.CGAGTATAGTCGGTCGGT 885 1859 1
Can you check whether the meta.data$batch is a factor? If not, cast it as such.
I changed it to this:
b_seurat <- RunPCA(object = b_seurat, pcs.compute = npcs, pc.genes = b_seurat@var.genes, do.print = TRUE, pcs.print = 1:5, genes.print = 5) if (!is.factor(b_seurat@meta.data$batch)) { print("meta.data$batch is not a factor") b_seurat@meta.data$batch <- as.factor(b_seurat@meta.data$batch) } b_seurat <- RunHarmony(object = b_seurat, group.by.vars =batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster)
It still has the original problem: [1] "meta.data$batch is not a factor" Error in UseMethod("RunHarmony") : no applicable method for 'RunHarmony' applied to an object of class "seurat"
traceback() 6: RunHarmony(object = b_seurat, group.by.vars = batch_label, theta = theta_harmony, plot_convergence = TRUE, nclust = numclust, max.iter.cluster = max_iter_cluster) at call_harmony.R#103 5: call_harmony(b_seurat, batch_label, celltype_label, npcs, plotout_dir = working_dir, saveout_dir = working_dir, outfilename_prefix = outfile_prefix, visualize = visualize, save_obj = save_obj) at run_harmony_02.R#73 4: eval(ei, envir) 3: eval(ei, envir) 2: withVisible(eval(ei, envir)) 1: source("run_harmony_02.R")
Please provide a minimal reproducible example
I packaged my working environment as a docker at https://hub.docker.com/r/jxbsx/bug. You can start it with the following command: docker run -it --name try_idea -p 9001:8787 jxbsx/bug:1.1 R The running file path is /home/2/run_harmony_02.R You need to execute setwd("/home/2") first
Additionally, I have a very simple test code running in my environment:
library(Seurat) library(harmony)
data("pbmc_small")
batch_data <- data.frame(batch = sample(c("batch1", "batch2"), size = nrow(pbmc_small@meta.data), replace = TRUE)) pbmc_small <- AddMetaData(pbmc_small, metadata = batch_data)
pbmc_small <- NormalizeData(pbmc_small)
pbmc_small <- FindVariableGenes(pbmc_small)
pbmc_small <- RunPCA(pbmc_small, pcs.print = 1:5, genes.print = 5)
pbmc_small <- RunHarmony(pbmc_small, group.by.vars = "batch")
The same problem occurred: Error in UseMethod("RunHarmony") : no applicable method for 'RunHarmony' applied to an object of class "seurat"
Can you please share a sessionInfo()
for your R environment?
With Seurat 4.9.9 I get this using your code.
data("pbmc_small")
#Add a batch variable
batch_data <- data.frame(batch = sample(c("batch1", "batch2"), size = nrow(pbmc_small@meta.data), replace = TRUE))
pbmc_small <- AddMetaData(pbmc_small, metadata = batch_data)
Error: No cell overlap between new meta data and Seurat object
sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux
Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblas.so.0.3; LAPACK version 3.11.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/New_York
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Seurat_4.9.9.9067 SeuratObject_4.9.9.9091 sp_1.6-0
sessionInfo() R version 3.6.3 (2020-02-29) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.6 LTS
Matrix products: default BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] harmony_0.1.0 Rcpp_1.0.11 Seurat_2.3.3 Matrix_1.2-18 cowplot_1.1.2 [6] ggplot2_3.4.4
Seurat v2 was released on 2016, 3 years before harmony was published. Upgrade this package to get proper support
Since the environment used in the original paper was Seurat v2, I could not upgrade it when reproducing it. Thank you for your help.
In that case, use the HarmonyMatrix (in v0) instead of the Seurat wrapper.
Okay, I'm going to try to use this function. Thank you for your help.
How do I download version 0.99.9 of harmony? Many of the papers I need to reproduce use this version of harmony, but I can't find a way to install it anywhere.