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

Allow pluggable similarity measure to validate. #5

Open
1 of 3 tasks
seandavi opened this issue Feb 18, 2021 · 0 comments
Open
1 of 3 tasks

Allow pluggable similarity measure to validate. #5

seandavi opened this issue Feb 18, 2021 · 0 comments

Comments

@seandavi
Copy link
Contributor

seandavi commented Feb 18, 2021

  • Spearman
  • other methods from dist
  • straight function

.loadingCor <- function(dataset, avgLoading, method = "pearson", scale = FALSE) {
if (any(class(dataset) == "ExpressionSet")) {
dat <- Biobase::exprs(dataset)
} else if (any(class(dataset) %in% c("SummarizedExperiment", "RangedSummarizedExperiment"))) {
dat <- SummarizedExperiment::assay(dataset)
} else if (any(class(dataset) == "matrix")) {
dat <- dataset
} else {
stop("'dataset' should be one of the following objects: ExpressionSet,
SummarizedExperiment, RangedSummarizedExperiment, and matrix.")
}
if (isTRUE(scale)) {dat <- rowNorm(dat)} # row normalization
dat <- dat[apply(dat, 1, function (x) {!any(is.na(x) | (x==Inf) | (x==-Inf))}),]
gene_common <- intersect(rownames(avgLoading), rownames(dat))
prcomRes <- stats::prcomp(t(dat[gene_common,])) # centered, but not scaled by default
loadings <- prcomRes$rotation[, 1:8]
loading_cor <- abs(stats::cor(avgLoading[gene_common,], loadings[gene_common,],
use = "pairwise.complete.obs",
method = method))
return(loading_cor)
}

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

1 participant