paper/renameCoefs.R

renameCoefs <- function(coefs) {
  coefs <- gsub('mentalStatus0','mental status of 0', coefs)
  coefs <- gsub('mentalStatus1','mental status of 1', coefs)
  coefs <- gsub('kpsDECR','KPS decreased', coefs)
  coefs <- gsub('kpsSigDECR','KPS significantly decreased', coefs)
  coefs <- gsub('kpsUNCH','KPS unchanged', coefs)
  coefs <- gsub('kpsINCR','KPS increased', coefs)
  coefs <- gsub('kpsSigINCR','KPS significantly increased', coefs)
  coefs <- gsub('kpsInitial','initial KPS', coefs)
  coefs <- gsub('overallNeuro0','overall neurologic status of 0', coefs)
  coefs <- gsub('overallNeuro1','overall neurologic status of 1', coefs)
  coefs <- gsub('overallNeuro2','overall neurologic status of 2', coefs)
  coefs <- gsub('overallNeuroNeg1','overall neurologic status of -1', coefs)
  coefs <- gsub('overallNeuroNeg2','overall neurologic status of -2', coefs)
  coefs <- gsub('neuroFunc0','neurologic function of 0', coefs)
  coefs <- gsub('neuroFunc1','neurologic function of 1', coefs)
  coefs <- gsub('neuroFunc2','neurologic function of 2', coefs)
  coefs <- gsub('neuroFunc3','neurologic function of 3', coefs)
  coefs <- gsub('neuroFunc4','neurologic function of 4', coefs)
  coefs <- gsub('tumorVolRateChange','tumor vol. rate change', coefs)
  coefs <- gsub('1.22e+02','121.525',coefs, fixed=T)
  coefs <- gsub('1.33e+01','13.338',coefs, fixed=T)
  coefs <- gsub('2.67e+04','26,700',coefs, fixed=T)
  coefs <- gsub('4.61e+01','46.105',coefs, fixed=T)
  coefs <- gsub('1.67e+02','167.088',coefs, fixed=T)
  coefs <- gsub('3.71e+02','371.024',coefs, fixed=T)
  coefs <- gsub('4.01e+01','40.116',coefs, fixed=T)
  coefs <- gsub('7.71e+00','7.713',coefs, fixed=T)
  coefs <- gsub('1.74e-01','0.174',coefs, fixed=T)
  coefs <- gsub('4.03e+00','4.030',coefs, fixed=T)
  coefs <- gsub(',',', ', coefs)
  coefs <- gsub('MSPU','MGMT promoter unmethylated',coefs)
  coefs <- gsub('ageDecade','age decade in ',coefs)
  coefs <- gsub('genderMALE', 'male gender',coefs)
  coefs <- gsub('location:', 'tumor located in',coefs)
  coefs <- gsub('laterality:  left', 'left-sided tumor', coefs)
  coefs <- gsub('TRUE', '', coefs)
  coefs <- gsub('  ', ' ', coefs)
  return(coefs)
}

renameCoefs_truncated <- function(coefs) {
  coefs <- gsub('mentalStatus0','mental status of 0', coefs)
  coefs <- gsub('mentalStatus1','mental status of 1', coefs)
  coefs <- gsub('kpsDECR','KPS decreased', coefs)
  coefs <- gsub('kpsSigDECR','KPS significantly decreased', coefs)
  coefs <- gsub('kpsUNCH','KPS unchanged', coefs)
  coefs <- gsub('kpsINCR','KPS increased', coefs)
  coefs <- gsub('kpsSigINCR','KPS significantly increased', coefs)
  coefs <- gsub('kpsInitial','initial KPS', coefs)
  coefs <- gsub('overallNeuro0','overall neurologic status of 0', coefs)
  coefs <- gsub('overallNeuro1','overall neurologic status of 1', coefs)
  coefs <- gsub('overallNeuro2','overall neurologic status of 2', coefs)
  coefs <- gsub('overallNeuroNeg1','overall neurologic status of -1', coefs)
  coefs <- gsub('overallNeuroNeg2','overall neurologic status of -2', coefs)
  coefs <- gsub('neuroFunc0','neurologic function of 0', coefs)
  coefs <- gsub('neuroFunc1','neurologic function of 1', coefs)
  coefs <- gsub('neuroFunc2','neurologic function of 2', coefs)
  coefs <- gsub('neuroFunc3','neurologic function of 3', coefs)
  coefs <- gsub('neuroFunc4','neurologic function of 4', coefs)
  coefs <- gsub('tumorVolRateChange','tumor vol. rate change', coefs)
  coefs <- gsub('1.22e+02','122',coefs, fixed=T)
  coefs <- gsub('1.33e+01','13',coefs, fixed=T)
  coefs <- gsub('2.67e+04','26,700',coefs, fixed=T)
  coefs <- gsub('4.61e+01','46',coefs, fixed=T)
  coefs <- gsub('1.67e+02','167',coefs, fixed=T)
  coefs <- gsub('3.71e+02','371',coefs, fixed=T)
  coefs <- gsub('4.01e+01','40',coefs, fixed=T)
  coefs <- gsub('7.71e+00','7.7',coefs, fixed=T)
  coefs <- gsub('1.74e-01','0.17',coefs, fixed=T)
  coefs <- gsub('4.03e+00','4',coefs, fixed=T)
  coefs <- gsub('5878.997','5878',coefs, fixed=T)
  coefs <- gsub('371.306','371',coefs, fixed=T)
  coefs <- gsub('46.105','46',coefs, fixed=T)
  coefs <- gsub('167.088','167',coefs, fixed=T)
  coefs <- gsub('13.338','13',coefs, fixed=T)
  coefs <- gsub('4.030','4',coefs, fixed=T)
  coefs <- gsub('7.713','7.7',coefs, fixed=T)
  coefs <- gsub('40.116','40',coefs, fixed=T)
  coefs <- gsub('0.174','0.17',coefs, fixed=T)
  coefs <- gsub('121.525','121',coefs, fixed=T)
  coefs <- gsub(',',', ', coefs)
  coefs <- gsub('MSPU','MGMT promoter unmethylated',coefs)
  coefs <- gsub('ageDecade','age decade in ',coefs)
  coefs <- gsub('genderMALE', 'male gender',coefs)
  coefs <- gsub('location:', 'tumor located in',coefs)
  coefs <- gsub('laterality:  left', 'left-sided tumor', coefs)
  coefs <- gsub('TRUE', '', coefs)
  coefs <- gsub('  ', ' ', coefs)
  coefs <- gsub('\\[ ', '\\[', coefs)
  coefs <- gsub('\\, ', '\\,', coefs)
  return(coefs)
}

dataDir <- '~/Data/Agile/final_model'
filenames <- c("coefs_2m.txt", 'coefs_6m.txt', 'coefs_9m.txt', 'coefs_12m.txt')
coefs <- lapply(filenames, function(f) {
  coef <- read.table(file=file.path(dataDir,f), stringsAsFactors = F, header = T)
  
  coef$variable <- renameCoefs_truncated(coef$variable)
  colnames(coef) <- c('temporal pattern','odds ratio')
  coef <- coef[, c(2,1)] # reorder columnes
  coef <- coef[order(-coef$`odds ratio`),] # reorder rows by decreasing odds ratio
  coef <- coef[-(which(coef$`temporal pattern`=='(Intercept)')),] # remove intercept term

  write.table(coef, file=file.path(dataDir, paste0('renamed_',f)), sep='\t',row.names=F)
  coef
})
novasmedley/gbmSpm documentation built on May 17, 2019, 10:39 a.m.