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 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| f_getdfcol <- function(df, cN){ res <- df[[cN]] names(res) <- rownames(df) res } 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, is_sce){ if(is_sce){ lc_filter <- unlist(unique(sObject[[lc_groupN]])) }else{ 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, is_sce=T){ if(is_sce){ lc_g <- f_metaG2G(sObject[[lc_groupN]]) lc_l <- sObject[[lc_labelN]] }else{ 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, is_sce)) 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 }
|