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
| library('biomaRt') mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl")) genes <- rownames(gene_len) G_list <- getBM(filters= "ensembl_gene_id", attributes= c("ensembl_gene_id","hgnc_symbol"),values=genes,mart= mart) G_list <- subset(G_list, hgnc_symbol!="")‘ gene_len <- readRDS('exons_gene_lens.rds')
f_id2name_fuck <- function(lc_exp, lc_db){ if(!is.data.frame(lc_db)){ lc_ids <- toTable(lc_db) }else{ lc_ids <- lc_db } res_n <- rownames(lc_exp) res_n <- res_n[res_n %in% lc_ids[[1]]] res <- lc_exp[res_n,] if(!is.data.frame(res)){res=data.frame(row.names = res_n, res)} lc_ids=lc_ids[match(rownames(res),lc_ids[[1]]),] lc_tmp = by(res, lc_ids[[2]], function(x) rownames(x)[which.max(rowMeans(x))]) lc_probes = as.character(lc_tmp) res_n <- rownames(res) res_n <- res_n[res_n %in% lc_probes] res = res[res_n,] if(!is.data.frame(res)){res=data.frame(row.names = res_n, res)} rownames(res)=lc_ids[match(rownames(res),lc_ids[[1]]),2] res }
gene_len <- f_id2name_fuck(gene_len,G_list)
|