diff CorrTable/Corr_Script_samples_row.R @ 30:4bc95a71fe6a draft

Uploaded
author melpetera
date Wed, 31 Jul 2019 09:51:06 -0400
parents e1b75c764ffe
children 80324d9a0089
line wrap: on
line diff
--- a/CorrTable/Corr_Script_samples_row.R	Wed Jul 31 05:47:19 2019 -0400
+++ b/CorrTable/Corr_Script_samples_row.R	Wed Jul 31 09:51:06 2019 -0400
@@ -2,7 +2,7 @@
   # CORRELATION TABLE                                                                             #
   #                                                                                               #
   #                                                                                               #
-  # Input : 2 tables with common samples                                                          #
+  # Input : 2 tables with shared samples                                                          #
   # Output : Correlation table ; Heatmap (pdf)                                                    #
   #                                                                                               #
   # Dependencies : Libraries "ggplot2" and "reshape2"                                             #
@@ -327,11 +327,13 @@
     dist.tab2 <- as.dist(1 - cormat.tab2)
     hc.tab2 <- hclust(dist.tab2, method = "ward.D2")
     tab.corr <- tab.corr[hc.tab2$order,]
+	rm(cormat.tab2)
     
     cormat.tab1 <- cor(tab1, method = corr.method, use = "pairwise.complete.obs")
     dist.tab1 <- as.dist(1 - cormat.tab1)
     hc.tab1 <- hclust(dist.tab1, method = "ward.D2")
     tab.corr <- tab.corr[,hc.tab1$order]
+	rm(cormat.tab1)
     
   }
   
@@ -345,9 +347,8 @@
   
   
   # Create the heatmap ---------------------------------------------------------------------------------
- 
-#### conditions de creation de heatmap
 
+  if(plot.choice != "none"){
  
   # A message if no variable kept
   if(length(tab.corr)==0){
@@ -357,6 +358,17 @@
 	dev.off()
   } else {
   
+  # A message if more than 1000 variable in auto mode
+  if((plot.choice=="auto")&&(max(dim(tab.corr))>1000)){
+	pdf(output2)
+	war.msg <- paste0("In 'default' mode, the colored table is not provided when\none of the tables contains more than ",
+	                  "a thousand\nvariables after the filter step.\n\nOne of your table still contains ",max(dim(tab.corr))," variables.\n",
+					  "Please consider more filtering, or use the 'Always plot a\ncolored table' mode to obtain your colored table.")
+	plot.new()
+	legend("center",war.msg,adj=c(0.05,0.075))
+	dev.off()
+  } else {
+  
   
   library(ggplot2)
   library(reshape2)
@@ -471,7 +483,10 @@
   ggsave(output2, device = "pdf", width = 10+0.075*dim(tab.corr)[2], height = 5+0.075*dim(tab.corr)[1], limitsize = FALSE)
   
   
-  } # End if(length(tab.corr)==0)else
+  } # End of if((plot.choice=="auto")&&(max(dim(tab.corr))>1000)) else
+  } # End of if(length(tab.corr)==0)else
+  } # End of if(plot.choice != "auto")
+  
   
   } # End of correlation.tab