Repository 'intensity_checks'
hg clone https://toolshed.g2.bx.psu.edu/repos/melpetera/intensity_checks

Changeset 3:bdee2c2c484b (2019-03-08)
Previous changeset 2:a7553caa2572 (2019-01-14) Next changeset 4:49c36c54e0cf (2020-01-03)
Commit message:
Uploaded
modified:
Intchecks/Script_intensity_check.R
Intchecks/wrapper_intensity_check.R
Intchecks/xml_intensity_check.xml
b
diff -r a7553caa2572 -r bdee2c2c484b Intchecks/Script_intensity_check.R
--- a/Intchecks/Script_intensity_check.R Mon Jan 14 08:17:26 2019 -0500
+++ b/Intchecks/Script_intensity_check.R Fri Mar 08 09:07:12 2019 -0500
[
b'@@ -2,7 +2,7 @@\n # SCRIPT INTENSITY CHECK                                                #\r\n #                                                                       #\r\n # Input: Data Matrix, VariableMetadata, SampleMetadata                  #\r\n-# Output: VariableMetadata, Graphics (barplots and boxplots)            #\r\n+# Output: VariableMetadata, Graphics                                    #\r\n #                                                                       #\r\n # Dependencies: RcheckLibrary.R                                         #\r\n #                                                                       #\r\n@@ -13,16 +13,18 @@\n if(FALSE){\r\n   \r\n   rm(list = ls())\r\n-  setwd("Y:\\\\Developpement\\\\Intensity check\\\\Pour tests")\r\n+  setwd("Y:\\\\Developpement\\\\Intensity check\\\\Pour tests\\\\Tests_global")\r\n   \r\n   DM.name <- "DM_NA.tabular"\r\n   SM.name <- "SM_NA.tabular"\r\n   VM.name <- "vM_NA.tabular"\r\n-  class.col <- "2"\r\n-  type <- "One_class"\r\n-  class1 <- "Blanks"\r\n+  method <- "one_class"\r\n+  chosen.stat <- "mean,sd,quartile,decile,NA" \r\n+  class.col <- "2" \r\n+  test.fold <- "Yes" \r\n+  class1 <- "Pools"\r\n   fold.frac <- "Top"\r\n-  logarithm <- "log2"\r\n+  logarithm <- "log10"\r\n   VM.output <- "new_VM.txt"\r\n   graphs.output <- "Barplots_and_Boxplots.pdf"\r\n }\r\n@@ -30,31 +32,31 @@\n \r\n \r\n \r\n-intens_check <- function(DM.name, SM.name, VM.name, class.col, type, class1, fold.frac, logarithm,\r\n-                         VM.output, graphs.output){\r\n-  \r\n+intens_check <- function(DM.name, SM.name, VM.name, method, chosen.stat, class.col, test.fold, class1, fold.frac, \r\n+                         logarithm, VM.output, graphs.output){\r\n   \r\n-  # This function allows to check the intensities considering classes with a mean fold change calculation,  \r\n-  # the number and the proportion of missing values (NA) in dataMatrix\r\n+  # This function allows to check the intensities with various statistics, number of missing values and mean fold change\r\n   #\r\n-  # Two options: \r\n-  # - one class (selected by the user) against all the remaining samples ("One_class")\r\n-  # - tests on each class ("Each_class")\r\n+  # Three methods proposed:\r\n+  # - global: tests for each variable without distinction between samples\r\n+  # - one class: one class versus all the remaining samples\r\n+  # - each class: if the class columns contains at least three classes and you want to test each of them\r\n   #\r\n   # Parameters:\r\n   # DM.name, SM.name, VM.name: dataMatrix, sampleMetadata, variableMetadata files access\r\n-  # class.col: number of the sampleMetadata\'s column with classes\r\n-  # type: "One_class" or "Each_class"\r\n-  # class1: name of the class, only if type="One_class"\r\n-  # fold.frac: if type="One class": class1/other ("Top") or other/class1 ("Bottom")\r\n-  # logarithm: "log2", "log10" or "none" for log mean fold change\r\n+  # method: "global", "one_class", "each_class"\r\n+  # chosen.stat: character listing the chosen analysis (comma-separated)\r\n+  # class.col: number of the sampleMetadata\'s column with classes (if method = one_class or each_class)\r\n+  # test.fold: "yes" or "no" (if method = one_class or each_class)\r\n+  # class1: name of the class (if method = one_class)\r\n+  # fold.frac: "Top" -> class1/other or "Bottom" -> other/class1 (if method = one_class) \r\n+  # logarithm: "log2", "log10" or "none" (if method = one_class or each_class)\r\n   # VM.output: output file\'s access (VM with new columns)\r\n   # graphs.output: pdf file\'s access with barplots for the proportion of NA and boxplots with the folds values\r\n \r\n   \r\n   \r\n   \r\n-  \r\n   # Input ---------------------------------------------------------------------------------------------------\r\n   \r\n   DM <- read.table(DM.name, header=TRUE, sep="\\t", check.names=FALSE)\r\n@@ -66,247 +68,344 @@\n   # Table match check with Rchecklibrary\r\n   table.check <- match3(DM, SM, VM)\r\n   check.err(table.check)\r\n-  \r\n-  \r\n+\r\n   \r\n   rownames(DM) <- DM[,1]\r\n   var_names <- DM[,1]\r\n   DM <- DM[,-1]\r\n   DM <- data.frame(t(DM))\r\n-  \r\n-  c'..b' no NA.\\n")\r\n-  }\r\n-  \r\n-  if(length(alerte) != 0){ \r\n-    cat(alerte,"\\n")\r\n-  }\r\n-  table_NA <- cbind(calcul_NA, pct_NA)\r\n-  \r\n-  \r\n-  \r\n-  # check columns names ---------------------------------------------------------------------------------------\r\n-  \r\n \r\n-  VM.names <- colnames(VM)\r\n-  \r\n-  # Fold\r\n-  \r\n-  if(nb_class >=2){\r\n-    fold.names <- colnames(fold)\r\n-  \r\n-    for (i in 1:length(VM.names)){\r\n-      for (j in 1:length(fold.names)){\r\n-        if (VM.names[i]==fold.names[j]){\r\n-          fold.names[j] <- paste(fold.names[j],"2", sep="_")\r\n-        }\r\n-      }\r\n-    }\r\n-    colnames(fold) <- fold.names\r\n-    \r\n-    VM <- cbind(VM,fold)\r\n-  }\r\n-  \r\n-  # NA\r\n-  NA.names <- colnames(table_NA)\r\n-  \r\n-  for (i in 1:length(VM.names)){\r\n-    for (j in 1:length(NA.names)){\r\n-      if (VM.names[i]==NA.names[j]){\r\n-        NA.names[j] <- paste(NA.names[j],"2", sep="_")\r\n-      }\r\n-    }\r\n-  }\r\n-  colnames(table_NA) <- NA.names\r\n-  VM <- cbind(VM,table_NA)\r\n-  \r\n-  \r\n-  #for NA barplots -------------------------------------------------------------------------------------------\r\n-  \r\n-  data_bp <- data.frame()\r\n-  \r\n-  for (j in 1:ncol(pct_NA)){\r\n-    Nb_NA_0_20 <- 0\r\n-    Nb_NA_20_40 <- 0\r\n-    Nb_NA_40_60 <- 0\r\n-    Nb_NA_60_80 <- 0\r\n-    Nb_NA_80_100 <- 0\r\n-    for (i in 1:nrow(pct_NA)){\r\n-      \r\n-      if ((0<=pct_NA[i,j])&(pct_NA[i,j]<20)){\r\n-        Nb_NA_0_20=Nb_NA_0_20+1\r\n-      }\r\n-      \r\n-      if ((20<=pct_NA[i,j])&(pct_NA[i,j]<40)){\r\n-        Nb_NA_20_40=Nb_NA_20_40+1}\r\n-      \r\n-      if ((40<=pct_NA[i,j])&(pct_NA[i,j]<60)){\r\n-        Nb_NA_40_60=Nb_NA_40_60+1}\r\n-      \r\n-      if ((60<=pct_NA[i,j])&(pct_NA[i,j]<80)){\r\n-        Nb_NA_60_80=Nb_NA_60_80+1}   \r\n-      \r\n-      if ((80<=pct_NA[i,j])&(pct_NA[i,j]<=100)){\r\n-        Nb_NA_80_100=Nb_NA_80_100+1}   \r\n-    }\r\n-    data_bp[1,j] <- Nb_NA_0_20\r\n-    data_bp[2,j] <- Nb_NA_20_40\r\n-    data_bp[3,j] <- Nb_NA_40_60\r\n-    data_bp[4,j] <- Nb_NA_60_80\r\n-    data_bp[5,j] <- Nb_NA_80_100\r\n-  }\r\n-  rownames(data_bp) <- c("0%-20%", "20%-40%", "40%-60%", "60%-80%", "80%-100%")\r\n-  colnames(data_bp) <- classnames\r\n-  data_bp <- as.matrix(data_bp)\r\n-  \r\n   \r\n   # Output ---------------------------------------------------------------------------------------------------\r\n   \r\n+  VM <-cbind(VM,stat.res)\r\n   \r\n   write.table(VM, VM.output,sep="\\t", quote=FALSE, row.names=FALSE)\r\n   \r\n-  #graphics pdf\r\n+  \r\n+  ### graphics pdf\r\n+  \r\n+  if(graphs == 1){\r\n   \r\n   pdf(graphs.output)\r\n+\r\n   \r\n   #Barplots for NA\r\n+  if("NA" %in% stat.list){\r\n+  graph.colors <- c("green3","palegreen3","lightblue","orangered","red")\r\n   par(mar=c(5.1, 4.1, 4.1, 8.1), xpd=TRUE)\r\n-  \r\n-  bp=barplot(data_bp, col=rainbow(nrow(data_bp)), main="Proportion of NA", xlab="Classes", ylab="Variables")\r\n-  legend("topright", fill=rainbow(nrow(data_bp)),rownames(data_bp), inset=c(-0.3,0))\r\n-  \r\n+\r\n+  bp=barplot(data_bp, col=graph.colors, main="Proportion of NA", xlab="Classes", ylab="Variables")\r\n+  legend("topright", fill=graph.colors,rownames(data_bp), inset=c(-0.3,0))\r\n+\r\n   stock=0\r\n   for (i in 1:nrow(data_bp)){\r\n     text(bp, stock+data_bp[i,]/2, data_bp[i,], col="white", cex=0.7)\r\n     stock <- stock+data_bp[i,]\r\n   }\r\n   \r\n-  \r\n-  #Boxplots for fold test\r\n+  }\r\n+\r\n+  # Boxplots for fold test\r\n   \r\n-  if(nb_class >= 2){\r\n-    \r\n-    clean_fold <- fold\r\n+  if((test.fold=="Yes")&&(nb_class >= 2)){\r\n+\r\n+    clean_fold <- fold.res\r\n     for(i in 1:nrow(clean_fold)){\r\n       for(j in 1:ncol(clean_fold)){\r\n         if(is.infinite(clean_fold[i,j])){\r\n@@ -316,12 +415,23 @@\n     }\r\n     for (j in 1:ncol(clean_fold)){\r\n       title <- paste(fold.names[j])\r\n-      boxplot(clean_fold[j], main=title)\r\n+      boxplot(clean_fold[,j], main=title)\r\n     }\r\n-    }\r\n+  }\r\n+\r\n+  dev.off()\r\n   \r\n-  dev.off()\r\n+  }else{\r\n+    pdf(graphs.output)\r\n+    plot.new()\r\n+    legend("center","You did not select any option with graphical output.")\r\n+    dev.off()\r\n+  }\r\n \r\n-}  \r\n+  }\r\n+  \r\n+\r\n+  \r\n+  \r\n \r\n   \n\\ No newline at end of file\n'
b
diff -r a7553caa2572 -r bdee2c2c484b Intchecks/wrapper_intensity_check.R
--- a/Intchecks/wrapper_intensity_check.R Mon Jan 14 08:17:26 2019 -0500
+++ b/Intchecks/wrapper_intensity_check.R Fri Mar 08 09:07:12 2019 -0500
b
@@ -9,7 +9,7 @@
 #                                                                           #
 #                                                                           #
 # Input: Data Matrix, VariableMetadata, SampleMetadata                      #
-# Output: VariableMetadata, Graphics (barplots and boxplots)                #
+# Output: VariableMetadata, Graphics                                        #
 #                                                                           #
 #                                                                           #
 #############################################################################
@@ -27,14 +27,36 @@
 source_local("Script_intensity_check.R", "RcheckLibrary.R")
 
 
-if(length(args) < 8){ stop("NOT enough argument !!!") }
+if(length(args) < 7){ stop("NOT enough argument !!!") }
 
-
+class_col <- NULL
+test_fold <- NULL
 class1 <- NULL
 fold_frac <- NULL
-if(args$type == "One_class"){
+logarithm <- NULL
+if(args$method == "each_class"){ 
+  class_col <- args$class_col
+  test_fold <- args$test_fold
+  if(args$test_fold == "Yes"){
+    logarithm <- args$logarithm
+  }
+}
+if(args$method == "one_class"){
+  class_col <- args$class_col
   class1 <- args$class1
-  fold_frac <- args$fold_frac
+  test_fold <- args$test_fold
+  if(args$test_fold == "Yes"){
+    fold_frac <- args$fold_frac
+    logarithm <- args$logarithm
+  }
+}
+
+err_no_option <- NULL
+
+if(((args$method == "no_class")&&(args$chosen_stat == "None"))||
+   ((args$method != "no_class") && (args$chosen_stat == "None") && (test_fold == "No"))){
+  err_no_option<- "You did not select any computational option. Program could not be executed."
+  stop("\n- - - - - - - - -\n",err_no_option,"\n- - - - - - - - -\n")
 }
 
 
@@ -43,10 +65,12 @@
 print(args)
 cat("--------------------------------\n")
 
+if(is.null(err_no_option)){
 
-intens_check(args$dataMatrix_in, args$sampleMetadata_in, args$variableMetadata_in, args$class_col, args$type,
-            class1, fold_frac, args$logarithm, args$variableMetadata_out, args$graphs_out)
-
+  intens_check(args$dataMatrix_in, args$sampleMetadata_in, args$variableMetadata_in, args$method, args$chosen_stat, 
+             class_col, test_fold, class1, fold_frac, logarithm, args$variableMetadata_out, args$graphs_out)
+}
+  
 sessionInfo()
 cat("--------------------------------\n")
 
b
diff -r a7553caa2572 -r bdee2c2c484b Intchecks/xml_intensity_check.xml
--- a/Intchecks/xml_intensity_check.xml Mon Jan 14 08:17:26 2019 -0500
+++ b/Intchecks/xml_intensity_check.xml Fri Mar 08 09:07:12 2019 -0500
b
b'@@ -1,7 +1,7 @@\n-<tool id="intens_check" name="Intensity Check" version="1.0.1">\r\n-\t<description>Adding information about intensities (mean fold change and missing values) in the variable metadata table</description>\r\n+<tool id="intens_check" name="Intensity Check" version="1.2.1">\r\n+\t<description>Statistical measures, number of missing values and mean fold change</description>\r\n \t<requirements>\r\n-\t<requirement type="package" version="1.1_4">r-batch</requirement>\r\n+\t<requirement type="package" version="1.1_5">r-batch</requirement>\r\n \t</requirements>\r\n \t<command interpreter="Rscript">\r\n   \r\n@@ -10,19 +10,34 @@\n \t\tdataMatrix_in "$dataMatrix_in"\r\n \t\tsampleMetadata_in "$sampleMetadata_in"\r\n \t\tvariableMetadata_in "$variableMetadata_in"\r\n-\t\r\n-\t\tclass_col "$class_col"\r\n-\t\r\n-\t\ttype "${type_cond.type}"\r\n-\t\t#if $type_cond.type == "One_class" :\r\n-\t\tclass1 "${type_cond.class1}"\r\n-\t\tfold_frac "${type_cond.fold_frac}"\r\n+\t\t\r\n+\t\tmethod "${method_cond.method}"\r\n+\t\t\r\n+\t\tchosen_stat "${method_cond.chosen_stat}"\r\n+\t\t\r\n+\t\t#if $method_cond.method == "each_class" :\r\n+\t\t\tclass_col "${method_cond.class_col}"\r\n+\t\t\ttest_fold "${method_cond.test_fold_cond.test_fold}"\r\n+\t\t\t#if $method_cond.test_fold_cond.test_fold == "Yes" :\r\n+\t\t\t\tlogarithm "${method_cond.test_fold_cond.logarithm}"\r\n+\t\t\t#end if\r\n \t\t#end if\r\n \t\t\r\n-\t\tlogarithm "$logarithm"\r\n-\t\r\n+\t\t#if $method_cond.method == "one_class" :\r\n+\t\t\tclass_col "${method_cond.class_col}"\r\n+\t\t\tclass1 "${method_cond.class1}"\r\n+\t\t\ttest_fold "${method_cond.test_fold_cond.test_fold}"\r\n+\t\t\t#if $method_cond.test_fold_cond.test_fold == "Yes" :\r\n+\t\t\t\tfold_frac "${method_cond.test_fold_cond.fold_frac}"\r\n+\t\t\t\tlogarithm "${method_cond.test_fold_cond.logarithm}"\r\n+\t\t\t#end if\r\n+\t\t#end if\r\n+\t\t\r\n \t\tvariableMetadata_out "$variableMetadata_out"\r\n \t\tgraphs_out "$graphs_out"\r\n+\t\t\r\n+\t\t\r\n+\t\t\r\n \t</command>\r\n \r\n \t<inputs>\r\n@@ -30,31 +45,83 @@\n \t\t<param name="sampleMetadata_in" type="data" label="Sample metadata file" help="" format="tabular" />\r\n \t\t<param name="variableMetadata_in" type="data" label="Variable metadata file" help="" format="tabular" />\r\n \t\t\r\n-\t\t<param name="class_col" type="data_column" data_ref="sampleMetadata_in" use_header_names="true" label="Class column" help="Class column in Sample metadata" />\r\n-\t\r\n-\t\t<conditional name="type_cond">\r\n-\t\t\t<param name="type" type="select" label="What kind of tests do you want to perform?" display="radio" help="If you only have two classes, \'One class\' could be selected to choose which class should be on the numerator/denominator.">\r\n-\t\t\t\t<option value="One_class">Tests between one class and the remaining samples </option>\r\n-\t\t\t\t<option value="Each_class" selected="true">Tests for each class </option>\r\n+\t\t<conditional name="method_cond">\r\n+\t\t\t<param name="method" type="select" label="Computation method" help="Select the first method if you don\'t want to take into account any class of samples">\r\n+\t\t\t\t<option value="no_class">Without distinction between samples </option>\r\n+\t\t\t\t<option value="each_class">For each class of samples  </option>\r\n+\t\t\t\t<option value="one_class">Between one class and all the remaining samples </option>\r\n+\t\t\t\t\r\n \t\t\t</param>\r\n-\t\t\t<when value="One_class">\r\n-\t\t\t\t<param name="class1" type="text" label="Selected class" help="Class name if you choose to test one class against the remaining samples." />\r\n-\t\t\t\t<param name="fold_frac" type="select" label="Where should the class be placed for the mean fold change calculation?" display="radio">\r\n-\t\t\t\t\t<option value="Top">Numerator (Top) </option>\r\n-\t\t\t\t\t<option value="Bottom">Denominator (Bottom) </option>\r\n+\t\t\t\r\n+\t\t\t<when value="no_class">\r\n+\t\t\t\t<param name="chosen_stat" type="select" display="checkboxes" multiple="True" label="Statistics">\r\n+\t\t\t\t\t<option value="mean">Mean</option>\r\n+                    <option value="sd">Standard deviation</option>\r\n+                    <option value="median">Median</option>\r\n+                    <option value="quartile">Quartile</option>\r\n+                    <option value="decile">Decile'..b'\t\r\n \t<outputs>\r\n \t\t<data name="variableMetadata_out" label="IC_${variableMetadata_in.name}" format="tabular" />\r\n@@ -75,23 +142,6 @@\n ========================\r\n \r\n -----------\r\n-Description\r\n------------\r\n-\r\n-This tool performs two tests: a mean fold change calculation and the number of missing values. \r\n-\r\n-**Fold:**\r\n-The test calculates the mean fold change between two classes. It could be converted into logarithm.\r\n-\r\n-**Missing values:**\r\n-This tool calculates the number and the proportion of missing values in the data matrix considering the class. \r\n-Missing values in numerical columns of data must be coded NA.\r\n-\r\n-**Two types of tests:**\r\n-\t|\t- Between **one class** and the remaining samples: if you have only two classes or if you want to test only one class versus all the remaining samples without class distinction. \r\n-\t|\t- **Each class**: if the class columns contains at least three classes and you want to test each of them. Can also be used with only two classes, but you will not choose which class to put as numerator/denominator. \r\n-\r\n------------\r\n Input files\r\n -----------\r\n \r\n@@ -109,29 +159,37 @@\n Parameters\r\n ----------\r\n \r\n+**Computation method**\r\n+\t| \t- **Without distinction between samples:** calculates chosen statistic(s) for each variable.\r\n+\t| \t- **For each class of samples:** separates samples between each class (class column to specified). Chosen statistic(s) and/or mean fold change are calculated for each of them. \r\n+\t| \t- **Between one class versus all the remaining samples:** If you want to focus only on one class versus all the remaining samples without class distinction. \r\n+\t\r\n+\t| In the case of two classes: "each class" and "one class" give the same results for statistical measures. We recommend to choose "one class" for mean fold change calculation in order to select the class you want to put as numerator or denominator (see below).\r\n+\t\r\n+**Statistics**\r\n+\t|  Select the statistical measures you want to add in the variable metadata table. If the method is "each class" or "one class", you could choose no statistical measure if you only want to calculate the mean fold change (see below).\r\n+\r\n **Class column**\r\n \t| Select the class column in sample metadata table.\r\n \r\n-**Type of test**\r\n-\t|  Two options:\r\n-\t|     - "One class" allows to perform tests on one class against the remaining samples.\r\n-\t|     - "Each class" allows to add several columns with the ratio between all the classes and the number of missing values for each class.\r\n-\r\n **Selected class**\r\n-\t| If the type is "one class", specify it to calculate the ratio and the number of missing values. \r\n+\t| If the method is "one class", specify it. Remaining samples will be named "Other".\r\n \t\r\n-**Numerator or denominator**\r\n-\t| If the type is "one class", choose "top" or "bottom" to put the selected class as numerator or denominator (respectively) for the mean fold change.\r\n+**Calculate the mean fold change**\r\n+\t| Choose if you want to calculate the mean fold change. If the method is "each class": mean fold change will be calculated for all combinations of classes. If the method is "one class": it will be calculated between the selected class (see above) and the remaining samples.\r\n+\t\r\n+**Where should the class be placed for the mean fold change calculation?**\t\r\n+\t| If the method is "one class", choose "top" or "bottom" to put the selected class as numerator or denominator (respectively) for the mean fold change calculation.\t\r\n \t\r\n **Logarithm**\r\n \t| Choose if you want to transform the mean fold change with a log2 or log10.\r\n-\r\n+\t\r\n ------------\r\n Output file\r\n ------------\r\n \r\n **Variable metadata file**\r\n-\t| Contains the previous columns in variable metadata file and the new ones with fold tests, number and proportion of missing values.\r\n+\t| Contains the previous columns in variable metadata file and the new ones.\r\n \t| In the column names for fold, the first class specified is the one used like numerator for the ratio.\r\n \t\r\n **Graphs file**\r\n'