Mercurial > repos > melpetera > intensity_checks
comparison Intchecks/Script_intensity_check.R @ 2:cab3e0dfb566 draft default tip
Uploaded
| author | melpetera |
|---|---|
| date | Wed, 22 Jan 2020 14:32:21 +0000 |
| parents | d1133a7c26f9 |
| children |
comparison
equal
deleted
inserted
replaced
| 1:d1133a7c26f9 | 2:cab3e0dfb566 |
|---|---|
| 67 | 67 |
| 68 # Table match check with Rchecklibrary | 68 # Table match check with Rchecklibrary |
| 69 table.check <- match3(DM, SM, VM) | 69 table.check <- match3(DM, SM, VM) |
| 70 check.err(table.check) | 70 check.err(table.check) |
| 71 | 71 |
| 72 | 72 # Transposing the dataMatrix |
| 73 rownames(DM) <- DM[,1] | 73 rownames(DM) <- DM[,1] |
| 74 var_names <- DM[,1] | 74 var_names <- DM[,1] |
| 75 DM <- DM[,-1] | 75 DM <- DM[,-1] |
| 76 DM <- data.frame(t(DM)) | 76 DM <- data.frame(t(DM)) |
| 77 | 77 |
| 78 # Re-ordering the dataMatrix to match the sampleMetadata file order | |
| 79 DM <- merge(x=cbind(1:nrow(SM),SM), y=DM, by.x=2, by.y=0) | |
| 80 DM <- DM[order(DM[,2]),] | |
| 81 rownames(DM) <- DM[,1] | |
| 82 DM <- DM[,-c(1:(ncol(SM)+1))] | |
| 83 | |
| 84 | |
| 78 stat.list <- strsplit(chosen.stat,",")[[1]] | 85 stat.list <- strsplit(chosen.stat,",")[[1]] |
| 79 | 86 |
| 80 | 87 |
| 81 # check class.col, class1 and the number of classes --------------------------------------------------------- | 88 # check class.col, class1 and the number of classes --------------------------------------------------------- |
| 82 | 89 |
| 101 c_class <- as.factor(c_class) | 108 c_class <- as.factor(c_class) |
| 102 nb_class <- nlevels(c_class) | 109 nb_class <- nlevels(c_class) |
| 103 classnames <- levels(c_class) | 110 classnames <- levels(c_class) |
| 104 | 111 |
| 105 if((nb_class < 2)&&(test.fold=="Yes")){ | 112 if((nb_class < 2)&&(test.fold=="Yes")){ |
| 106 err.1class <- c("\n The column",class.col, "contains only one class, fold calculation could not be executed \n") | 113 err.1class <- c("\n The column",class.col, "contains only one class, fold calculation could not be executed. \n") |
| 107 cat(err.1class) | 114 cat(err.1class) |
| 108 } | 115 } |
| 109 | 116 |
| 110 if((nb_class > (nrow(SM))/3)&&(method == "each_class")){ | 117 if((nb_class > (nrow(SM))/3)&&(method == "each_class")){ |
| 111 class.err <- c("\n There are too many classes, think about reducing the number of classes and excluding those | 118 class.err <- c("\n There are too many classes, think about reducing the number of classes and excluding those |
| 112 with few samples \n") | 119 with few samples. \n") |
| 113 cat(class.err) | 120 cat(class.err) |
| 114 } | 121 } |
| 115 | 122 |
| 116 | 123 |
| 117 if(method == "one_class"){ | 124 if(method == "one_class"){ |
| 137 } | 144 } |
| 138 | 145 |
| 139 | 146 |
| 140 # Statistics ------------------------------------------------------------------------------------------------ | 147 # Statistics ------------------------------------------------------------------------------------------------ |
| 141 | 148 |
| 149 # Check whether the dataMatrix contains non-numeric values | |
| 150 if(!(is.numeric(as.matrix(DM)))){ | |
| 151 # findchar definition | |
| 152 findchar <- function(myval){ | |
| 153 if(is.na(myval)){ | |
| 154 return("ok") | |
| 155 }else{ | |
| 156 mytest <- as.character(myval) | |
| 157 if(is.na(as.numeric(mytest[1]))){ | |
| 158 return("char") | |
| 159 }else{ | |
| 160 return("ok") | |
| 161 } | |
| 162 } | |
| 163 } | |
| 164 # findchar application | |
| 165 chardiag <- suppressWarnings(apply(DM,2,vapply,findchar,"character")) | |
| 166 charlist <- which(chardiag == "char") | |
| 167 err.stock <- paste("\n- - - - - - - - -\nYour dataMatrix contains", | |
| 168 length(charlist), | |
| 169 "non-numeric value(s). To help you check your data, please find below a short overview:\n") | |
| 170 charover <- 1 | |
| 171 while((length(err.stock)<10)&(length(err.stock)<(length(charlist)+1))){ | |
| 172 charex <- paste("variable",colnames(DM)[ceiling(charlist[charover]/nrow(DM))], | |
| 173 "- sample",rownames(DM)[charlist[charover]-floor(charlist[charover]/nrow(DM))*nrow(DM)], | |
| 174 "~> value:",as.matrix(DM)[charlist[charover]],"\n") | |
| 175 err.stock <- c(err.stock,charex) | |
| 176 charover <- charover + 1 | |
| 177 } | |
| 178 stop(c(err.stock,"The dataMatrix file is supposed to contain only numeric values.\n- - - - - - - - -\n")) | |
| 179 } | |
| 142 | 180 |
| 143 ### Initialization | 181 ### Initialization |
| 144 | 182 |
| 145 DM <- cbind(c_class,DM) | 183 DM <- cbind(c_class,DM) |
| 146 | 184 |
