modifiedRanks <- function(plateau, binaryLevel, inverse=FALSE, penalty=0){ if( ! missing(binaryLevel) ){ ##cat(" using: binary approach with parameter:", binaryLevel, " and inverse:", inverse, "\n") return( function(x){ if( plateau < 1 ){ stop(paste(" invalid plateau:", plateau)) } if( inverse ){ tmp <- rank(x, ties.method="min") }else{ tmp <- rank(-x, ties.method="min") } tmp[ tmp>plateau ] <- binaryLevel tmp[ tmp<=plateau ] <- 0 return(tmp) }) }else{ ##cat(" using: rank approach with plateau:", plateau, " and penalty:", penalty, " and inverse:", inverse, "\n") return( function(x){ if( plateau < 1 ){ stop(paste(" invalid plateau:", plateau)) } if( inverse ){ tmp <- rank(x) }else{ tmp <- rank(-x) } tmp[ tmp>plateau ] <- plateau+penalty return(tmp) }) } } calculateStatistics <- function(rawExpr,windowSize,maxCluster,...){ probenzahl=nrow(rawExpr) genzahl=ncol(rawExpr) ## differs for nullstat ! geneNames <- colnames(rawExpr) if( missing(maxCluster) ){ maxCluster=ceiling(probenzahl/2) }else{ stopifnot( maxCluster <= ceiling(probenzahl/2) ) } resultStatistiken <- array(data=NA, dim=c(maxCluster,(genzahl-(windowSize-1)),2), dimnames=list(NULL, geneNames[1:(genzahl-(windowSize-1))],NULL)) for(inverse in 1:2){ for(cp in 1:maxCluster){ myRank <- modifiedRanks(cp, inverse=(inverse==2), ...) expr <- apply(rawExpr,2,myRank) ## samples x genes diffInit = apply(expr[,1:windowSize],1,sum)## init diff = cbind(diffInit,expr[,(windowSize+1):genzahl] - expr[,1:(genzahl-windowSize)] ) statistiken = t( apply(diff,1,cumsum) ) ## still samples x genes statistiken = apply(statistiken,2,sort) resultStatistiken[cp,,inverse]<-apply(statistiken[(1:cp),,drop=FALSE],2,sum) } } return(resultStatistiken) }