R/read.input.files.R

Defines functions read.input.files

# Function read.input.files reads in REVA output files

read.input.files <- function(file.list, condition, normalized){
  upload = list()
  for(nr in 1:length(file.list[, 1])){
    data.df <- read.table(
      file = file.list[[nr, 'datapath']],
      sep = c("\t"),
      header = T,
      fill = T,
      quote = c(""),
      blank.lines.skip = T,
      strip.white = T,
      flush = T,
      allowEscapes = T,
      stringsAsFactors = F,
      encoding = "latin1",
      skip = max(grep(pattern = "<!", readLines(file.list[[nr, 'datapath']]), value = FALSE)) - 1
    )
    data.df[, c((ncol(data.df) - 1), ncol(data.df))] <- NULL
    names(data.df) <- gsub(pattern = "\\__.*", "", names(data.df))
    names(data.df)[1] <- ifelse(names(data.df)[1] == "Chromosome", "Chr", names(data.df)[1])
    if(normalized){
      for(i in 4:ncol(data.df)){
        data.df[2:nrow(data.df), i] <- (data.df[2:nrow(data.df), i]*1e6)/data.df[1, i]
      }
    }
    upload[[nr]] <- data.df
    names(upload)[[nr]] <- paste(condition, nr, sep = "_")
  }
  return(bind_rows(upload, .id = "Condition")) # append condition
}
mjmccoy/REVAvis documentation built on April 8, 2021, 8:11 p.m.