r 找到Rowname重叠

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 找到Rowname重叠相关的知识,希望对你有一定的参考价值。

#' Title
#'
#' @param named.exprmat.list 
#' Rows = genes
#' @return
#' @export
#'
#' @examples
#' 
#' a <- gene.overlap(list("steidl"=expr.steidl, "steidl2"=expr.steidl, "steidl3"=expr.steidl[8:15, ], "steidl4"=expr.steidl[1:10, ]))
rn.overlap <- function(named.exprmat.list){
	if(is.null(names(named.exprmat.list)))
		warning("You should give names!")
	named.genelist <- lapply(named.exprmat.list, rownames)
	inmat <- matrix(0, nrow=length(named.genelist), ncol=length(named.genelist))
	colnames(inmat) <- names(named.genelist)
	rownames(inmat) <- names(named.genelist)
	
	genesetmat <- inmat
	
	name.listlist  <- rep(list(rep(list(NULL), length(named.genelist))), length(named.genelist))
	names(name.listlist) <- names(named.genelist)
	name.listlist <- lapply(name.listlist, function(x) {
		names(x) <- names(named.genelist)
		return(x)
		})
	
	
	genesets <- list()
	genesetcounter <- 1
	for(rowX in names(named.genelist)){
		for(colX in names(named.genelist)){
			name.listlist[[rowX]][[colX]] <- named.genelist[[rowX]][named.genelist[[rowX]] %in% named.genelist[[colX]]]
			# check if the name.listlist[[]][[]] is already in our genesets
			# if not, add it
			genelist.present <- unlist(lapply(genesets, function(x){
				all(name.listlist[[rowX]][[colX]] %in% x) && 
				all(x %in% name.listlist[[rowX]][[colX]] && 
				length(x)==length(name.listlist[[rowX]][[colX]]))
			} ))
			if(!any(genelist.present)){
				genesets[[genesetcounter]] <- name.listlist[[rowX]][[colX]]
				found.genelist <- genesetcounter
				genesetcounter <- genesetcounter + 1
			}else{
				found.genelist <- which(genelist.present)
			}
			genesetmat[rowX, colX] <- found.genelist
			inmat[rowX, colX] <- sum(named.genelist[[rowX]] %in% named.genelist[[colX]])
		}
	}
	
	total.overlap <- Reduce(intersect, genesets)
	return(list("N_rowINcol"=inmat, "overlapNameList_Row_Col"=name.listlist
				, "genesets"=genesets, "genesetmat"=genesetmat
				,"totalOverlap"=total.overlap))
}

以上是关于r 找到Rowname重叠的主要内容,如果未能解决你的问题,请参考以下文章

按其rowname和columnname访问值,而不是数字

在MATLAB中找到具有共同重叠区域的多个圆

R等同于SAS的“In”数据集选项,用于包含和排除重叠数据

R - 找到所有可能的数字组合,限制组合长度

r R重叠#R

使用 R (data.table) 提取重叠和非重叠时间段