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

Changeset 0:b22c453e4cf4 (2018-10-11)
Next changeset 1:29ec7e3afdd4 (2019-08-01)
Commit message:
Uploaded
added:
CorrTable/Corr.xml
CorrTable/Corr_Script_samples_row.R
CorrTable/Corr_wrap.r
b
diff -r 000000000000 -r b22c453e4cf4 CorrTable/Corr.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CorrTable/Corr.xml Thu Oct 11 05:35:55 2018 -0400
[
b'@@ -0,0 +1,300 @@\n+<tool id="corrtable" name="Between-table Correlation" version="0.0.0">\r\n+\t<description>Correlation table between two tables and graphic representation </description>\r\n+\t  <requirements>\r\n+\t\t\t<requirement type="package" version="1.1_4">r-batch</requirement>\r\n+\t\t\t<requirement type="package" version="3.0.0">r-ggplot2</requirement>\r\n+\t\t\t<requirement type="package" version="1.4.3">r-reshape2</requirement>\r\n+\t</requirements>\r\n+\t<command interpreter="Rscript">\r\n+\t\r\n+\t\tCorr_wrap.r\r\n+\t\t\r\n+\t\ttab1_in "$tab1_in"\r\n+\t\ttab2_in "$tab2_in"\r\n+\t\t\r\n+\t\ttab1_samples "$tab1_samples"\r\n+\t\ttab2_samples "$tab2_samples"\r\n+\t\t\r\n+\t\tcorr_method "$corr_method"\r\n+\t\t\r\n+\t\ttest_corr "${filter_section.testcorr_cond.test_corr}"\r\n+\t\t#if str($filter_section.testcorr_cond.test_corr) == \'yes\' :\r\n+\t\t\tcorrect_multi "${filter_section.testcorr_cond.correct_multi}"\r\n+\t\t\trisk_alpha "${filter_section.testcorr_cond.risk_alpha}"\r\n+\t\t#end if\r\n+\t\t\r\n+\t\tfilter "${filter_section.filter_cond.filter}"\r\n+\t\t#if str($filter_section.filter_cond.filter) == \'yes\' :\r\n+\t\t\tfilters_choice "${filter_section.filter_cond.filtchoice_cond.filters_choice}"\r\n+\t\t\t#if str($filter_section.filter_cond.filtchoice_cond.filters_choice) == \'filters_0_thr\' :\r\n+\t\t\t\tthreshold "${filter_section.filter_cond.filtchoice_cond.threshold}"\r\n+\t\t\t#end if\r\n+\t\t#end if\r\n+\t\t\r\n+\t\treorder_var "$out_section.reorder_var"\r\n+\t\t\r\n+\t\tcolor_heatmap "${out_section.heatmap_cond.color_heatmap}"\r\n+\t\t#if str($out_section.heatmap_cond.color_heatmap) == \'yes\' :\r\n+\t\t\ttype_classes "${out_section.heatmap_cond.typeclass_cond.type_classes}"\r\n+\t\t\t#if str($out_section.heatmap_cond.typeclass_cond.type_classes) == \'regular\' :\r\n+\t\t\t\treg_class_value "${out_section.heatmap_cond.typeclass_cond.reg_class_value}"\r\n+\t\t\t#elif str($out_section.heatmap_cond.typeclass_cond.type_classes) == \'irregular\' :\r\n+\t\t\t\tirreg_class_vect "${out_section.heatmap_cond.typeclass_cond.irreg_class_vect}"\r\n+\t\t\t#end if\r\n+\t\t#end if\t\r\n+\t\t\r\n+\t\ttabcorr_out "$tabcorr_out"\r\n+\t\theatmap_out "$heatmap_out"\r\n+\t\t\r\n+\t</command>\r\n+\t\r\n+\t<inputs>\r\n+\t\r\n+\t\t<param name="tab1_in" type="data" label="Table 1 file" help="The two input tables must have the same sample IDs" format="tabular" />\r\n+\t\t<param name="tab1_samples" label="Where are the samples in table 1?" type="select" display="radio" help="">\r\n+\t\t\t<option value="row">Row</option>\r\n+\t\t\t<option value="column">Column</option>\r\n+\t\t</param>\r\n+\t\t\r\n+\t\t<param name="tab2_in" type="data" label="Table 2 file" help="The two input tables must have the same sample IDs" format="tabular" />\r\n+\t\t<param name="tab2_samples" label="Where are the samples in table 2?" type="select" display="radio" help="">\r\n+\t\t\t<option value="row">Row</option>\r\n+\t\t\t<option value="column">Column</option>\t\t\r\n+\t\t</param>\r\n+\t\t\r\n+\t\t<param name="corr_method" label="Method to calculate the correlation coefficients" type="select" help="">\r\n+\t\t\t<option value="pearson">Pearson</option>\r\n+\t\t\t<option value="spearman">Spearman</option>\r\n+\t\t\t<option value="kendall">Kendall</option>\r\n+\t\t</param>\t\r\n+\t\t\r\n+\t\t<section name="filter_section" title="Filtering options" expanded="False">\r\n+\t\t\t<conditional name="testcorr_cond">\r\n+\t\t\t\t<param name="test_corr" label="Significance test for the correlation coefficients" type="select" display="radio" help="">\r\n+\t\t\t\t\t<option value="no">No</option>\r\n+\t\t\t\t\t<option value="yes">Yes</option>\r\n+\t\t\t\t</param>\r\n+\t\t\t\t<when value="yes">\r\n+\t\t\t\t\t<param name="correct_multi" label="Method for multiple testing correction" type="select" help="">\r\n+\t\t\t\t\t\t<option value="none">none</option>\t\t\t\t\r\n+\t\t\t\t\t\t<option value="fdr">fdr</option>\r\n+\t\t\t\t\t\t<option value="BH">BH</option>\r\n+\t\t\t\t\t\t<option value="bonferroni">bonferroni</option>\r\n+\t\t\t\t\t\t<option value="BY">BY</option>\r\n+\t\t\t\t\t\t<option value="hochberg">hochberg</option>\r\n+\t\t\t\t\t\t<option value="holm">holm</option>\r\n+\t\t\t\t\t\t<option value="hommel">hommel</option>\r\n+\t\t\t\t\t</param>\r\n+\t\t\t\t\t<param name="risk_alpha" label="(Corrected) p-value significance threshold" type="float" value="0.05" help="Must be between 0 and 1" />\r\n+'..b' more powerfil than the others."\r\n+|\r\n+\r\n+| **(Corrected) p-value significance threshold (only if significance test is \'Yes\'):**\r\n+| A value between 0 and 1, usually 0.05.\r\n+|\r\n+\t\r\n+Filter the correlation table\r\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^\t\r\n+        | Allows to reduce the correlation table size by keeping only variables considered relevant.\r\n+        |\r\n+\r\n+| **Choose the filters to apply (only if filter is \'Yes\'):**\r\n+| \t- \'Only zero filter\': Remove variables with all their correlation coefficients equal to zero.\r\n+| \t- \'Threshold filter\': Remove variables with all their correlation coefficients (in absolute value) strictly below a threshold.\r\n+\t\r\n+| *Choose a threshold (only threshold filter is used):* A value between 0 and 1.\r\n+|\r\n+\r\n+Reorder variables using Hierarchical Cluster Analysis (HCA)\r\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n+        | Allows the most linked variables to be close in the correlation table.\r\n+        | A HCA is performed on each input tables, with:\r\n+        |    - 1 - correlation coefficient, as distance\r\n+        |    - Ward as aggregation method.\r\n+        |\r\n+\r\n+        \r\n+Colored correlation table strategy\r\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n+\t\t| Allows to create a colored correlation table. Variables of table 1 and variables of table 2 are related using colored rectangles. \r\n+\t\t| About the colors, the negative correlations are in red, more or less intense according to their position between -1 and 0, and the positive correlations in green, more or less intense according to their position between 0 and 1. The coefficients equal to 0 are in white.\r\n+\t\t| \t- \'Standard\': the graphical representation has a scale with a smooth gradient between three colors: red, white and green.\r\n+\t\t| \t- \'Customized\': the colored correlation table has coefficient classes. It is possible to create regular or irregular classes. The scale is discreet.\r\n+\t\t|\r\n+\t\t\r\n+| **Choose the type of classes (only if colored correlation table strategy is \'Customized\'):**\r\n+\r\n+| \t- \'Regular\': classes are all (or almost) the same size. \t\r\n+| To realize these intervals, we start from 1 to go to 0 by taking a step of the size chosen by the user, and we make the symmetry for -1 towards 0. If the last step does not fall on the 0 value, we create a class between this last value and 0, smaller in size than the others. It is important to specify that 0 represents a class on its own, which is assigned the color white for the heatmap.\t\r\n+\r\n+| *Size of classes (if regular classes):* A value between 0 and 1.\r\n+\r\n+| Example: if the size is 0.4, classes are [-1;-0.6], ]-0.6;-0.2], ]-0.2;0[, 0, ]0;0.2], ]0.2;0.6] and ]0.6;1].\r\n+|\r\n+\r\n+| \t- \'Irregular\': classes have variable lengths.\r\n+| It is possible to do as many classes as you want, and of any size. There is not necessarily symmetry between -1 and 0, and 0 and 1. You can choose to have a white class with only 0, or an interval which contains the value 0.\r\n+\r\n+| *Vector with values for classes (if irregular classes):* The values in the vector must be between -1 and 1 excluded, and in ascending order. It must have this form (value1,value2,...). If the vector contains 0, then this value becomes a class on its own, otherwise the white class is the one which contains 0.\r\n+\r\n+| Example: if the vector is (-0.8,-0.5,-0.4,0,0.4,0.5,0.8), the classes are [-1;-0.8], ]-0.8;-0.5], ]-0.5;-0.4], ]-0.4;0[, 0, ]0;0.4], ]0.4;0.5], ]0.5;0.8] and ]0.8;1].\r\n+|\r\n+\r\n+\t\r\n+------------\r\n+Output files\r\n+------------\r\n+\r\n+Correlation Table\r\n+^^^^^^^^^^^^^^^^^\r\n+\t| Tabular output\r\n+\t| Correlation table between the variables of the two input tables\r\n+\t|\r\n+\t\r\n+Heatmap (colored correlation table)\r\n+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n+\t| Pdf output\r\n+\t| Colored representation of the correlation table. The coefficients are replaced by colors. A coefficient close to -1 is red, close to 0 white, and close to 1 in green.\r\n+\t|\r\n+\t\r\n+\t\r\n+\t</help>\r\n+\t\r\n+</tool>\t\n\\ No newline at end of file\n'
b
diff -r 000000000000 -r b22c453e4cf4 CorrTable/Corr_Script_samples_row.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CorrTable/Corr_Script_samples_row.R Thu Oct 11 05:35:55 2018 -0400
[
b'@@ -0,0 +1,410 @@\n+  #################################################################################################\r\n+  # CORRELATION TABLE                                                                             #\r\n+  #                                                                                               #\r\n+  #                                                                                               #\r\n+  # Input : 2 tables with common samples                                                          #\r\n+  # Output : Correlation table ; Heatmap (pdf)                                                    #\r\n+  #                                                                                               #\r\n+  # Dependencies : Libraries "ggplot2" and "reshape2"                                             #\r\n+  #                                                                                               #\r\n+  #################################################################################################\r\n+  \r\n+  \r\n+  # Parameters (for dev)\r\n+  if(FALSE){\r\n+    \r\n+    rm(list = ls())\r\n+    setwd(dir = "Y:/Developpement")\r\n+\r\n+    tab1.name <- "Test/Ressources/Inputs/CT2_DM.tabular"\r\n+    tab2.name <- "Test/Ressources/Inputs/CT2_base_Diapason_14ClinCES_PRIN.txt"\r\n+    param1.samples <- "column"\r\n+    param2.samples <- "row"\r\n+    corr.method <- "pearson"\r\n+    test.corr <- "yes"\r\n+    alpha <- 0.05\r\n+    multi.name <- "none"\r\n+    filter <- "yes"\r\n+    filters.choice <- "filters_0_thr"\r\n+    threshold <- 0.2\r\n+    reorder.var <- "yes"\r\n+    color.heatmap <- "yes"\r\n+    type.classes <-"irregular"\r\n+    reg.value <- 1/3\r\n+    irreg.vect <- c(-0.3, -0.2, -0.1, 0, 0.3, 0.4)\r\n+    output1 <- "Correlation_table.txt"\r\n+    output2 <- "Heatmap.pdf"\r\n+    \r\n+  }\r\n+  \r\n+  \r\n+  \r\n+  correlation.tab <- function(tab1.name, tab2.name, param1.samples, param2.samples, corr.method, test.corr, alpha, \r\n+                              multi.name, filter, filters.choice, threshold, reorder.var, color.heatmap, type.classes, \r\n+                              reg.value, irreg.vect, output1, output2){\r\n+\r\n+    # This function allows to visualize the correlation between two tables\r\n+    # \r\n+    # Parameters:\r\n+    # - tab1.name: table 1 file\'s access\r\n+    # - tab2.name: table 2 file\'s access\r\n+    # - param1.samples ("row" or "column"): where the samples are in tab1\r\n+    # - param2.samples ("row" or "column"): where the samples are in tab2\r\n+    # - corr.method ("pearson", "spearman", "kendall"): \r\n+    # - test.corr ("yes" or "no"): test the significance of a correlation coefficient\r\n+    # - alpha (value between 0 and 1): risk for the correlation significance test\r\n+    # - multi.name ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"): correction of multiple tests\r\n+    # - filter ("yes", "no"): use filter.0 or/and filter.threshold\r\n+    # - filters.choice ("filter_0" or "filters_0_thr"): zero filter removes variables with all their correlation coefficients = 0\r\n+    #   and threshold filter remove variables with all their correlation coefficients in abs < threshold\r\n+    # - threshold (value between 0 and 1): threshold for filter threshold\r\n+    # - reorder.var ("yes" or "no"): reorder variables in the correlation table thanks to the HCA\r\n+    # - color.heatmap ("yes" or "no"): color the heatmap with classes defined by the user\r\n+    # - type.classes ("regular" or "irregular"): choose to color the heatmap with regular or irregular classes\r\n+    # - reg.value (value between 0 and 1): value for regular classes\r\n+    # - irreg.vect (vector with values between -1 and 1): vector which indicates values for intervals (irregular classes)\r\n+    # - output1: correlation table file\'s access\r\n+    # - output2: heatmap (colored correlation table) file\'s access\r\n+  \r\n+  \r\n+  # Input ----------------------------------------------------------------------------------------------\r\n+  \r\n+  tab1 <- read.table(tab1.name, sep = "\\t'..b'"irregular") {\r\n+      \r\n+      irreg.vect <- c(-1, irreg.vect, 1) \r\n+      vect <- irreg.vect\r\n+      \r\n+    }\r\n+    \r\n+    # Color palette :  \r\n+    myPal <- colorRampPalette(c("#00CC00", "white", "red"), space = "Lab", interpolate = "spline")\r\n+    \r\n+    # Create vector intervals\r\n+    cl <- vector()\r\n+    cl <- paste("[", vect[1], ";", round(vect[2],3), "]", sep = "")\r\n+    \r\n+    for (x in 2:(length(vect)-1)) {\r\n+      if (vect[x+1] == 0) {\r\n+        cl <- c(cl, paste("]", round(vect[x],3), ";", round(vect[x+1],3), "[", sep = ""))\r\n+      } else {\r\n+        cl <- c(cl, paste("]", round(vect[x],3), ";", \r\n+                          round(vect[x+1],3), "]", sep = ""))\r\n+      }\r\n+    }\r\n+    \r\n+    # Assign an interval to each correlation coefficient\r\n+    for (i in 1:dim(melted.tab.corr)[1]){\r\n+      for (j in 1:(length(cl))){\r\n+        if (vect[j] == -1){\r\n+          melted$classe[i][melted$value[i] >= vect[j] \r\n+                           && melted$value[i] <= vect[j+1]] <- cl[j]\r\n+        } else {\r\n+          melted$classe[i][melted$value[i] > vect[j] \r\n+                           && melted$value[i] <= vect[j+1]] <- cl[j]\r\n+        }\r\n+      }\r\n+    }\r\n+    \r\n+    # Find the 0 and assign it the white as name\r\n+    if (length(which(vect == 0)) == 1) {\r\n+      melted$classe[melted$value == 0] <- "0"\r\n+      indic <- which(vect == 0)\r\n+      cl <- c(cl[1:(indic-1)], 0, cl[indic:length(cl)])\r\n+      names(cl)[indic] <- "#FFFFFF"\r\n+    } else if (length(which(vect == 0)) == 0) {\r\n+      indic <- 0\r\n+      for (x in 1:(length(vect)-1)) {\r\n+        if (0 > vect[x] && 0 <= vect[x+1]) {\r\n+          names(cl)[x] <- "#FFFFFF"\r\n+          indic <- x\r\n+        }\r\n+      }\r\n+    }\r\n+    \r\n+    indic <- length(cl) - indic + 1\r\n+    cl <- rev(cl)\r\n+    \r\n+    # Assign the colors of each intervals as their name\r\n+    names(cl)[1:(indic-1)] <- myPal(length(cl[1:indic])*2-1)[1:indic-1]\r\n+    names(cl)[(indic+1):length(cl)] <- myPal(length(cl[indic:length(cl)])*2-1)[(ceiling(length(myPal(length(cl[indic:length(cl)])*2-1))/2)+1):length(myPal(length(cl[indic:length(cl)])*2-1))]\r\n+    \r\n+    \r\n+    melted$classe <- factor(melted$classe)\r\n+    melted$classe <- factor(melted$classe, levels = cl[cl%in%levels(melted$classe)])\r\n+    \r\n+    # Heatmap if color.heatmap = yes :\r\n+    ggplot(melted, aes(Var2, Var1, fill = classe)) +\r\n+      ggtitle("Colored correlation table" ) + xlab("Table 1") + ylab("Table 2") +\r\n+      geom_tile(color ="ghostwhite") +\r\n+      scale_fill_manual( breaks = levels(melted$classe),\r\n+                         values = names(cl)[cl%in%levels(melted$classe)],\r\n+                         name = paste(corr.method, "correlation", sep = "\\n")) +\r\n+      theme_classic() +\r\n+      theme(axis.text.x = element_text(angle = 90, vjust = 0.5), \r\n+            plot.title = element_text(hjust = 0.5)) \r\n+    \r\n+  } else {\r\n+    \r\n+    # Heatmap if color.heatmap = no :\r\n+    ggplot(melted.tab.corr, aes(Var2, Var1, fill = value)) +\r\n+      ggtitle("Colored correlation table" ) + xlab("Table 1") + ylab("Table 2") +\r\n+      geom_tile(color ="ghostwhite") +\r\n+      scale_fill_gradient2(low = "red", high = "#00CC00", mid = "white", midpoint = 0, limit = c(-1,1),\r\n+                           name = paste(corr.method, "correlation", sep = "\\n")) +\r\n+      theme_classic() +\r\n+      theme(axis.text.x = element_text(angle = 90, vjust = 0.5), \r\n+            plot.title = element_text(hjust = 0.5))\r\n+  }\r\n+  \r\n+  \r\n+  ggsave(output2, device = "pdf", width = 10+0.075*dim(tab.corr)[2], height = 5+0.075*dim(tab.corr)[1], limitsize = FALSE)\r\n+  \r\n+  \r\n+  } # End if(length(tab.corr)==0)else\r\n+  \r\n+  } # End of correlation.tab\r\n+  \r\n+  \r\n+  # Function call\r\n+  # correlation.tab(tab1.name, tab2.name, param1.samples, param2.samples, corr.method, test.corr, alpha, multi.name, filter,\r\n+  #                             filters.choice, threshold, reorder.var, color.heatmap, type.classes,\r\n+  #                             reg.value, irreg.vect, output1, output2)\r\n'
b
diff -r 000000000000 -r b22c453e4cf4 CorrTable/Corr_wrap.r
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CorrTable/Corr_wrap.r Thu Oct 11 05:35:55 2018 -0400
[
@@ -0,0 +1,80 @@
+#!/usr/bin/Rscript --vanilla --slave --no-site-file
+
+################################################################################################
+# WRAPPER FOR Corr_Script_samples_row.R (CORRELATION TABLE)                                    #
+#                                                                                              #
+# Author: Ophelie BARBET                                                                       #
+# User: Galaxy                                                                                 #
+# Original data: used with Corr_Script_samples_row.R                                           #
+# Starting date:                                                                               #
+# V-1: First version of wrapper                                                                #
+#                                                                                              #
+#                                                                                              #
+# Input files: 2 tables with common samples file                                               #
+# Output files: Correlation table ; Heatmap file                                               #
+#                                                                                              #
+################################################################################################
+
+
+library(batch) #necessary for parseCommandArgs function
+args = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects
+
+source_local <- function(...){
+ argv <- commandArgs(trailingOnly = FALSE)
+ base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
+ for(i in 1:length(list(...))){source(paste(base_dir, list(...)[[i]], sep="/"))}
+}
+#Import the different functions
+source_local("Corr_Script_samples_row.R")
+
+
+if(length(args) < 10){ stop("NOT enough argument !!!") }
+
+
+cat('\n--------------------------------------------------------------------', 
+'\nParameters used in "Between-table Correlation":\n\n')
+print(args)
+cat('--------------------------------------------------------------------\n\n')
+
+
+risk_alpha <- NULL
+correct_multi <- NULL
+if(args$test_corr == "yes"){
+ risk_alpha <- args$risk_alpha
+ correct_multi <- args$correct_multi
+}
+
+filters_choice <- NULL
+threshold <- NULL
+if(args$filter == "yes"){
+ filters_choice <- args$filters_choice
+ if(filters_choice == "filters_0_thr"){
+ threshold <- args$threshold
+ }
+}
+
+type_classes <- NULL
+reg_class_value <- NULL
+irreg_class_vect <- NULL
+if(args$color_heatmap == "yes"){
+ type_classes <- args$type_classes
+ if(type_classes == "regular"){
+ reg_class_value <- args$reg_class_value
+ } else if(type_classes == "irregular"){
+ irreg_class_vect <- eval(parse(text=paste0("c",args$irreg_class_vect)))
+ }
+}
+
+
+correlation.tab(args$tab1_in, args$tab2_in, args$tab1_samples, args$tab2_samples, args$corr_method, args$test_corr, risk_alpha, correct_multi, args$filter, filters_choice, threshold,
+args$reorder_var, args$color_heatmap, type_classes, reg_class_value, irreg_class_vect, args$tabcorr_out, args$heatmap_out)
+
+
+cat('\n--------------------------------------------------------------------',
+'\nInformation about R (version, Operating System, attached or loaded packages):\n\n')
+sessionInfo()
+cat('--------------------------------------------------------------------\n\n')
+
+
+#delete the parameters to avoid the passage to the next tool in .RData image
+rm(args)
\ No newline at end of file