R/checkFCSbyCIPHE.R

Defines functions delColFromFCSbyCIPHE foundSpillCIPHE catch.createFCSfromCSV read.FCS.CIPHE

read.FCS.CIPHE <- function(fcs){
  out <- tryCatch({
    read.FCS(fcs,emptyValue=FALSE)
  },
  error = function(cond){
    return(NULL)
  })
}

catch.createFCSfromCSV <- function(csv){
  if(dim(csv)[2]<2){return(NULL)}
  out <- tryCatch({
    createFCSfromCSV(csv)
  },
  error = function(cond){
    return(NULL)
  })
}

foundSpillCIPHE <- function(fcs){
  comp <- "NULL"
  dim <- "NULL"
  desc <- fcs@description
  id1 <- unlist(lapply(desc, function(i){return(dim(i)[1])}))
  if(!is.null(id1)){
    comp <- names(id1)
    s <- fcs@description[[names(id1)]]
    if(dim(s)[1]==dim(s)[2]){
      dim <- dim(s)[1]
    }
  }
  return(c(comp,dim))
}

delColFromFCSbyCIPHE <- function(fcs, marker, spill=NULL){

  id <- which(colnames(fcs)==marker)
  data <- exprs(fcs)
  data <- data[,-id]
  exprs(fcs) <- data

  desc <- fcs@description
  new.desc <- list()
  new.name <- list()
  for(i in c(1:length(desc))){
    if(length(grep(paste0("P",id),names(desc[i])))>0){
      print(names(desc)[i])
    } else {
      new.name <- c(new.name,names(desc)[i])
      new.desc <- c(new.desc,desc[i])
    }
  }
  names(new.desc) <- new.name
  fcs@description <- new.desc

  if(!is.null(spill)){
    new.spill <- fcs@description[[spill]]
    id.spill <- which(colnames(new.spill)==marker)
    new.spill <- new.spill[-id.spill,-id.spill]
    fcs@description[[spill]] <- new.spill
  }

  return(fcs)

}
Selkie-13/Jarvis documentation built on May 1, 2020, 4:12 a.m.