1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| f_metaG2G <- function(metaG, matrixN=F){ res <- list() alltype <- unique(metaG[[1]]) for(type in alltype){ res[[type]] <- rownames(metaG)[metaG[[1]] == type] if (matrixN){ res[[type]] <- gsub('-','.',res[[type]]) } } res }
f_br_cluster_f <- function(sObject, lc_groupN){ lc_filter <- unlist(unique(sObject[[lc_groupN]])) lc_filter <- lc_filter[!is.na(lc_filter)] lc_filter }
f_br_cluster <- function(sObject, lc_groupN, lc_labelN, lc_prop = F){ lc_g <- f_metaG2G(sObject[[lc_groupN]]) lc_l <- sObject[[lc_labelN]] lc_l[[1]] <- as.character(lc_l[[1]]) res <- data.frame(row.names = f_br_cluster_f(lc_l, lc_labelN)) if(lc_prop){ for(Nm in names(lc_g)){ tmp <- prop.table(table(lc_l[lc_g[[Nm]],])) res[[Nm]] <- tmp[rownames(res)] } }else{ for(Nm in names(lc_g)){ tmp <- table(lc_l[lc_g[[Nm]],]) res[[Nm]] <- tmp[rownames(res)] } } res[is.na(res)] = 0 res }
|