R/HistMarkerMetaCl.R

Defines functions HistMarkerMetaCl

Documented in HistMarkerMetaCl

#' Histogram representation of a marker in a given meta-cluster, compared to the full data
#'
#' @param TreeMetaCl Object generated by the function BuildFSOMTree
#' @param Marker Marker name
#' @param MetaCl a meta-cluster name or number
#' @param breaks parameter to pass to R hist function
#' @param xlim parameter to pass to R hist function
#' @param freq parameter to pass to R hist function
#' @return a double histogram figure, with meta-cluster in red
#' @export

HistMarkerMetaCl = function(TreeMetaCl,Marker,MetaCl,breaks=100,xlim=NULL,freq=F) {
  clusterList=which(TreeMetaCl$metaCl == MetaCl)
  if (length(clusterList) < 1) {stop("Meta-cluster not found")}
  metaClustIndices=unlist(sapply(clusterList,
                                 function(cluster){which(TreeMetaCl$fSOMTree$map$mapping[,1] == cluster)}))
  MarkerIndex=which(TreeMetaCl$fSOMTree$prettyColnames == Marker)
  if (length(MarkerIndex) < 1) {stop("Marker not found")}

  if (nchar(MetaCl) < 27) {MetaClName = MetaCl} else {MetaClName = paste(substring(
    MetaCl,(0:((nchar(MetaCl)%/%24))*24),c(1:((nchar(MetaCl)%/%24))*24,nchar(MetaCl))),
    collapse = "\n")}
par(mar=c(4,4,4+nchar(MetaCl)%/%24,4))
    if (is.null(xlim)) {
      hist(TreeMetaCl$fSOMTree$data[,MarkerIndex],breaks=breaks,xlab=Marker,main=MetaClName,freq)
      hist(TreeMetaCl$fSOMTree$data[metaClustIndices,MarkerIndex],border="red",breaks=breaks,add=T,xlab=Marker,freq)
    }
    else {
      hist(TreeMetaCl$fSOMTree$data[,MarkerIndex],xlim=xlim,breaks=breaks,xlab=Marker,main=MetaClName,freq)
      hist(TreeMetaCl$fSOMTree$data[metaClustIndices,MarkerIndex],border="red",breaks = breaks,add=T,xlab=Marker,freq)
    }
  }
gautierstoll/CytoSOM documentation built on May 16, 2020, 10:36 a.m.