changeset 8:ab4be65b0960 draft

Uploaded
author melpetera
date Fri, 05 Oct 2018 12:10:45 -0400
parents be9a707fbb60
children a8a679d16745
files ACF/Analytic_correlation_filtration.pl ACF/IonFiltration.pm ACF/analytic_correlation_filtration.xml CorrTable/Corr.xml CorrTable/Corr_Script_samples_row.R CorrTable/Corr_wrap.r
diffstat 6 files changed, 1439 insertions(+), 790 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACF/Analytic_correlation_filtration.pl	Fri Oct 05 12:10:45 2018 -0400
@@ -0,0 +1,144 @@
+#!usr/bin/perl
+
+### Perl modules
+use warnings;
+use strict;
+use Getopt::Long qw(GetOptions); #Creation of script options
+use Pod::Usage qw(pod2usage); #Creation of script options
+
+#Personnal packages
+use FindBin ; ## Allows you to locate the directory of original perl script
+use lib $FindBin::Bin;
+use lib "$FindBin::Bin/../lib";
+use IonFiltration;
+
+my ($file, $mass_file, $opt, $dataMatrix, $combined_DMVM, $repres_opt, $rt_threshold, $mass_threshold, $output_sif, $output_tabular, $correl_threshold); #Options to complete
+
+########################
+### Options and help ###
+########################
+
+GetOptions("f=s"=>\$file, "m=s"=>\$mass_file, "o=s"=>\$opt, "d=s"=>\$dataMatrix, "v=s"=>\$combined_DMVM, "r=s"=>\$repres_opt, "rt=f"=>\$rt_threshold, "mass=f"=>\$mass_threshold, "output_sif=s"=>\$output_sif, "output_tabular=s"=>\$output_tabular, "correl=s"=>\$correl_threshold) or pod2usage(2);
+
+### Check required parameters :
+pod2usage({-message=>q{Mandatory argument '-f' is missing}, -exitval=>1, -verbose=>0}) unless $file;
+#pod2usage({-message=>q{Mandatory argument '-m' is missing}, -exitval=>1, -verbose=>0}) unless $mass_file;
+pod2usage({-message=>q{Mandatory argument '-o' is missing. It correspond to the grouping method for analytical correlation groups formation.
+#It should be a number (1 ; 2 or 3) :
+#	1 : Don't take into acount mass information (only RT)
+#	2 : Check that all mass differences are include in a specific list and taking into acount RT information
+#	3 : Check that all mass differences are include in a specific list, ignoring RT information}, -exitval=>1, -verbose=>0}) unless $opt;
+pod2usage({-message=>q{Mandatory argument '-r' is missing. It correspond to the group representent choosing method for analytical correlation groups formation.
+It should be one of the 3 options below :
+	"mass" : choose the ion with the highest mass as the representant
+	"intensity" : choose the ion with the highest intensity as the representant
+	"mixt" : choose the ion with the highest (mass^2 * intensity) as the representant}, -exitval=>1, -verbose=>0}) unless $repres_opt;
+pod2usage({-message=>q{Mandatory argument '-d' is missing}, -exitval=>1, -verbose=>0}) unless $dataMatrix;
+pod2usage({-message=>q{Mandatory argument '-v' is missing}, -exitval=>1, -verbose=>0}) unless $combined_DMVM;
+#pod2usage({-message=>q{Mandatory argument '-rt' is missing}, -exitval=>1, -verbose=>0}) unless $rt_threshold;
+#pod2usage({-message=>q{Mandatory argument '-mass' is missing}, -exitval=>1, -verbose=>0}) unless $mass_threshold;
+pod2usage({-message=>q{Mandatory argument '-correl' is missing}, -exitval=>1, -verbose=>0}) unless $correl_threshold;
+pod2usage({-message=>q{Mandatory argument '-output_tabular' is missing}, -exitval=>1, -verbose=>0}) unless $output_tabular;
+pod2usage({-message=>q{Mandatory argument '-output_sif' is missing}, -exitval=>1, -verbose=>0}) unless $output_sif;
+
+
+#if(($opt != 1) && ($opt != 2) && ($opt != 3) && ($opt != 4)){
+#	print "you must indicate \"1\", \"2\", \"3\" or \"4\" for the --o otpion\n";
+#	exit;
+#}
+
+	
+
+if(($repres_opt ne "mass") && ($repres_opt ne "intensity") && ($repres_opt ne "mixt")){
+	print "you must indicate \"mass\", \"intensity\" or \"mix\" for the --r otpion\n";
+	exit;
+}
+
+
+#######################################
+### Creation of a correlation table ###
+#######################################
+
+#$file = IonFiltration::correlationTable($dataMatrix);
+#print "correlation table crée\n";
+
+#########################################################################
+#### Création of a hash containing all adduits and fragments possible ###
+#########################################################################
+
+my %hmass;
+if($opt != 1){
+	%hmass = IonFiltration::MassCollecting($mass_file);
+	print "Hash créé\n";
+}
+
+#################################################
+### Check the correlation table configuration ###
+#################################################
+
+#$file = IonFiltration::checkCorrelTable ($file, $combined_DMVM);
+#print "Format correl table ok !\n";
+	
+########################################################
+### Creation of a sif table + correlation filtration ###
+########################################################
+
+
+
+($output_sif, $output_tabular) = IonFiltration::sifTableCreation($file, $output_sif, $opt, $rt_threshold, $mass_threshold, $correl_threshold, $dataMatrix, $output_tabular, $combined_DMVM, $repres_opt, \%hmass);
+print "sif table créée\n";
+
+
+
+#################################################################
+### Creation of a subfile set containingfiltered correl pairs ###
+#################################################################
+
+my $subfile;
+#
+#if($file =~ m/(.+)\.sif/){
+#	$subfile = $1."_filtered.tabular";
+#} 
+
+
+
+##############################################################################
+#### Removing all duplicates in correlation matrice and filtered all pairs ###
+##############################################################################
+
+#$subfile = IonFiltration::CorrelationFiltering($file, $subfile, $opt, $rt_threshold, $mass_threshold, \%hmass);
+#print "Duplicats enlevés\n";
+#
+#
+#my $no_duplica;
+#if($file =~ m/(.+)\.sif/){
+#	$no_duplica = $1."_filtered_no_duplica.tabular";
+#} 
+#print "Subfile créé\n";
+#
+#$subfile = IonFiltration::DuplicatesRemoving($subfile, $no_duplica);
+
+
+
+
+#####################################
+#### Correlation groups formation ### 
+#####################################
+
+
+#my $result_file = IonFiltration::CorrelGroups($file, $subfile);
+#print "Groupes de corrélation calculés\n";
+
+
+
+#########################################################################
+### Representative ion selection for each analytics correlation group ###
+#########################################################################
+
+
+
+#my $final = IonFiltration::FiltrationResult($dataMatrix , $result_file, $combined_DMVM, $repres_opt, $output_tabular);
+
+
+print "All steps done\n";
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACF/IonFiltration.pm	Fri Oct 05 12:10:45 2018 -0400
@@ -0,0 +1,1164 @@
+#!usr/bin/perl
+package IonFiltration;
+
+### Perl modules
+use strict;
+use warnings;
+
+
+my $test;
+
+#######################################
+### Création of a correlation table ###
+#######################################
+
+#sub correlationTable{
+#	
+##	use lib 'J:\Programmation\GrandPa\GrandPa_Utils\Analytic_correlation_filtration_galaxy\lib';
+#	use Statistics::R;
+#
+#	my $file = $_[0];
+#	
+#	my $subfile;
+#	if($file =~ m/(.+)\.tabular/){
+#		$subfile = $1."_correl_table.txt";
+#	} 
+#	
+#	# Run simple R commands
+#	my $R = Statistics::R->new();
+#	$R->run(qq`donnees <- read.table($file,header=TRUE,sep="\t",dec=".",check.names=FALSE)`);
+#	$R->run(qq`x <- setNames(as.data.frame(t(donnees[-1])),donnees[,1])`);
+#	$R->run(qq`y <- cor(x, method="pearson")`);
+#	$R->run(qq`write.table(x = data.frame(name = rownames(y), y), file ="matrice_correl_test.txt", sep = "\t", quote = FALSE, row.names = FALSE) `);
+#
+#	print "$R\n";
+#	
+#	return $subfile;
+#}
+
+
+
+
+
+########################################################################
+### Création of a hash containing all adduits and fragments possible ###
+########################################################################
+
+
+sub MassCollecting{
+	
+	my $mass_file = $_[0];
+	my %hmass;
+
+	open (F1, $mass_file);
+	
+	while(my $line = <F1>){
+		chomp $line;
+		my @tline = split(";", $line);
+		if(defined($hmass{$tline[2]})){
+#			print "Il existe déjà une même différence de masse : $tline[2] !\n";
+		}
+		$hmass{$tline[2]}{$tline[1]}=$tline[0];
+	}
+	
+	close F1;
+	my $count=0;
+	foreach my $k (keys %hmass){
+		$count++;
+	}
+	
+	return %hmass;
+	
+	
+}
+
+
+
+#################################################
+### Check the correlation table configuration ###
+#################################################
+
+#sub checkCorrelTable {
+#	
+#	my $file = $_[0];
+#	my $combined_DMVM = $_[1];
+#	
+#	open (F1, $combined_DMVM);
+#	my $linenb=0;
+#	my %hheader_line;
+#	my %hnewName;
+#	
+#	while(my $line = <F1>){
+#		chomp $line;
+#		my @tline = split(/\t/, $line);
+#		
+#		if($linenb == 0){
+#			for(my $i=0; $i<scalar(@tline);$i++){
+#				my $a = $tline[$i];
+#				$hheader_line{$a}=$i;
+#			}
+#		}
+#		else{
+#			my $b = "M".$tline[$hheader_line{mzmed}]."T".$tline[$hheader_line{rtmed}];
+#			$hnewName{$tline[0]}=$b;
+#		}
+#		
+#		$linenb ++;
+#	}
+#	close F1;
+#	
+#	open (F2, $file) or die "Impossible to open $file\n";
+#	open (F3, ">./test_res.txt");
+#	
+#	my $linenb2=0;
+#	while(my $line = <F2>){
+#		chomp $line;
+#		my @tline = split(/\t/, $line);
+#		
+#			if($line =~m/M(.+)T(\d+\.\d+)_?/){
+#				print"Le format est bon\n";
+#				last;
+#			}
+#			else{
+#				for(my $i=0; $i<scalar(@tline);$i++){
+#					if (defined($hnewName{$tline[$i]})){
+#						my $c = $hnewName{$tline[$i]};
+#						$tline[$i]=$c;
+#					}
+#				}
+#				my $line2 = join("\t", @tline);
+#				print F3 "$line2\n";
+#			}
+#		$linenb2 ++;
+#	}
+#	
+#	close F2;
+#	close F3;
+#	
+#	
+#}
+
+
+
+########################################################
+### Creation of a sif table + correlation filtration ###
+########################################################
+
+
+sub sifTableCreation{
+	
+	my $file = $_[0];
+	my $output_sif = $_[1];
+	my $opt = $_[2];
+	my $rt_threshold = $_[3];
+	my $mass_threshold = $_[4];
+	my $correl_threshold = $_[5];
+	my $dataMatrix = $_[6];
+	my $output_tabular = $_[7];
+	my $combined_DMVM = $_[8];
+	my $repres_opt = $_[9];
+	my $refhmass = $_[10];
+	
+	
+	my $linenb=0;
+	my %hheader_file;
+	my %hduplicate;
+	
+	my %hcorrelgroup;
+	my $groupct=1;
+
+	open (F5, $combined_DMVM);
+	my $linenb3=0;
+	my %hheader_line;
+	my %hrtmz;
+	
+	while(my $line = <F5>){
+		chomp $line;
+		my @tline = split(/\t/, $line);
+		
+		if($linenb3 == 0){
+			for(my $i=0; $i<scalar(@tline);$i++){
+				my $a = $tline[$i];
+				$hheader_line{$a}=$i;
+			}
+		}
+		else{
+			if(defined($hheader_line{mzmed})){
+				my $b = $tline[$hheader_line{mzmed}];
+				$hrtmz{$tline[0]}{mz}=$b;
+			}
+			else{
+				my $b = $tline[$hheader_line{mz}];
+				$hrtmz{$tline[0]}{mz}=$b;
+			}
+			if(defined($hheader_line{rtmed})){
+				my $d = $tline[$hheader_line{rtmed}];
+				$hrtmz{$tline[0]}{rt}=$d;
+			}
+			else{
+				my $d = $tline[$hheader_line{rt}];
+				$hrtmz{$tline[0]}{rt}=$d;
+			}
+		}
+		
+		$linenb3 ++;
+	}
+	close F5;
+	
+	open (F1, $file) or die "Impossible to open $file\n";
+	open(F2, ">$output_sif") or die "Impossible to open $output_sif\n";
+	
+	while(my $line = <F1>){
+		chomp $line;
+		my @tline = split(/\t/, $line);
+		
+		
+		###############################
+		### Création of a sif table ###
+		###############################
+		
+		if($linenb == 0){
+			for(my $i=0; $i<scalar(@tline);$i++){
+				my $a = $tline[$i];
+				$hheader_file{$i}=$a;
+			}
+		}
+		else{
+			for(my $i=1; $i<scalar(@tline);$i++){
+				my $a=$tline[0];
+				my $b=$hheader_file{$i};
+				my $coef=$tline[$i];
+				
+				
+				if($a eq $b){
+	#				print "This is a correlation between A ($a) and A ($b) !\n"
+				}
+				else{
+					
+					#########################
+					### Remove duplicates ###
+					#########################
+					
+					my $y = $a."/".$b;
+					my $z = $b."/".$a;
+					
+					if((!(defined($hduplicate{$y}))) && (!(defined($hduplicate{$z})))){
+						
+						$hduplicate{$y}=1;
+						
+						if($coef > $correl_threshold){
+						
+							print F2 "$a\t$coef\t$b\n";
+							
+							my $count=0;
+							
+							######################################################
+							### Analytic correlation filtrering follow options ###
+							######################################################
+							
+							
+							
+								my $amass=$hrtmz{$a}{mz};
+								my $atemp=$hrtmz{$a}{rt};
+									my $bmass= $hrtmz{$b}{mz};
+									my $btemp=$hrtmz{$b}{rt};
+									my $diff = $amass-$bmass;
+									$diff = abs($diff);
+								
+									### Option 1: Don't take into acount mass information ###
+					
+									if($opt == 1){
+										my $btplus = $btemp + $rt_threshold;
+										my $btmoins = $btemp - $rt_threshold;
+										if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+											foreach my $k (keys %hcorrelgroup){
+												
+												if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
+													$hcorrelgroup{$k}{$a}=1;
+													$hcorrelgroup{$k}{$b}=1;
+													$count++;
+													last;
+												}
+											}
+											if($count == 0){
+												my $groupnb="group".$groupct;
+												$hcorrelgroup{$groupnb}{$a}=1;
+												$hcorrelgroup{$groupnb}{$b}=1;
+												$groupct ++;
+											}
+											
+										}
+									}
+									
+								
+									### Option 2: Check that all mass differences are include in a specific list taking into account RT information ###
+									
+									elsif($opt == 2){
+										
+										my $print = 0;
+										foreach my $r (keys %$refhmass){
+											my $rm = $r - $mass_threshold;
+											my $rp = $r + $mass_threshold;
+											if(($diff <= $rp) && ($diff >= $rm)){
+												if($print == 0){
+													my $btplus = $btemp + $rt_threshold;
+													my $btmoins = $btemp - $rt_threshold;
+													
+													if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+														foreach my $s (keys %{%$refhmass{$r}}){
+						#									print F2 "$line\t$hmass{$r}{$s} : $s ($r)\n";
+															foreach my $k (keys %hcorrelgroup){
+																if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
+																	$hcorrelgroup{$k}{$a}=1;
+																	$hcorrelgroup{$k}{$b}=1;
+																	$hcorrelgroup{$k}{frag}.="#".$s;
+																	$count++;
+																	last;
+																}
+															}
+															if($count == 0){
+																my $groupnb="group".$groupct;
+																$hcorrelgroup{$groupnb}{$a}=1;
+																$hcorrelgroup{$groupnb}{$b}=1;
+																$hcorrelgroup{$groupnb}{frag}.="#".$s;
+																$groupct ++;
+																
+															}
+															$print = 1;
+														}
+														
+													}
+												}
+											}
+										}
+									}
+									
+								
+									### Option 3: Check that all mass differences are include in a specific list, ignoring RT information ###
+					
+									elsif($opt == 3){
+										
+										my $print = 0;
+										foreach my $r (keys %$refhmass){
+											my $rm = $r - $mass_threshold;
+											my $rp = $r + $mass_threshold;
+											if(($diff <= $rp) && ($diff >= $rm)){
+												if($print == 0){
+													
+													foreach my $s (keys %{%$refhmass{$r}}){
+						#								print F2 "$line\t$hmass{$r}{$s} : $s ($r)\n";
+														foreach my $k (keys %hcorrelgroup){
+															if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
+																$hcorrelgroup{$k}{$a}=1;
+																$hcorrelgroup{$k}{$b}=1;
+																$hcorrelgroup{$k}{frag}.="#".$s;
+																$count++;
+																last;
+															}
+														}
+														if($count == 0){
+															my $groupnb="group".$groupct;
+															$hcorrelgroup{$groupnb}{$a}=1;
+															$hcorrelgroup{$groupnb}{$b}=1;
+															$hcorrelgroup{$groupnb}{frag}.="#".$s;
+															$groupct ++;
+														}
+														$print = 1;
+													}
+												}
+											}
+										}
+									}
+								}
+
+
+					}
+				}
+			}
+		}
+		$linenb ++;
+	}
+	close F1;
+	close F2;
+	
+	
+	#############################################
+	### Join groups that have been subdivided ###
+	#############################################
+	
+	my @tdelete;
+	
+	foreach my $k (keys %hcorrelgroup){
+		foreach my $i (keys %{$hcorrelgroup{$k}}){
+			foreach my $v (keys %hcorrelgroup){
+				my $count = 0;
+				if ($v ne $k){
+					foreach my $w (keys %{$hcorrelgroup{$v}}){
+						if($w ne "frag"){
+							if($w eq $i){
+								$count = 1;
+								push(@tdelete, $v);
+							}	
+						}
+					}
+				}
+				if($count == 1){
+					foreach my $w (keys %{$hcorrelgroup{$v}}){
+						$hcorrelgroup{$k}{$w}=$hcorrelgroup{$v}{$w};
+					}
+					delete($hcorrelgroup{$v});
+				}
+			}
+		}
+	}
+	
+	foreach my $t (@tdelete){
+		delete($hcorrelgroup{$t});
+	}
+	
+	
+	### Do it twice to see if it fix the problem of unmerge groups
+	
+	foreach my $k (keys %hcorrelgroup){
+		foreach my $i (keys %{$hcorrelgroup{$k}}){
+			foreach my $v (keys %hcorrelgroup){
+				my $count = 0;
+				if ($v ne $k){
+					foreach my $w (keys %{$hcorrelgroup{$v}}){
+						if($w ne "frag"){
+							if($w eq $i){
+								$count = 1;
+								push(@tdelete, $v);
+							}	
+						}
+					}
+				}
+				if($count == 1){
+					foreach my $w (keys %{$hcorrelgroup{$v}}){
+						$hcorrelgroup{$k}{$w}=$hcorrelgroup{$v}{$w};
+					}
+					delete($hcorrelgroup{$v});
+				}
+			}
+		}
+	}
+	
+	foreach my $t (@tdelete){
+		delete($hcorrelgroup{$t});
+	}
+	
+	
+	
+	####################################################
+	### Choose the representative ion for each group ###
+	####################################################
+	
+	my %hgrouprepres;
+		
+	open(F3, $dataMatrix);
+	
+	while (my $line = <F3>){
+		chomp $line;
+		
+		my @tline = split (/\t/, $line);
+		
+		
+		
+			foreach my $k (keys %hcorrelgroup){
+				foreach my $i (keys %{$hcorrelgroup{$k}}){
+					
+					if($tline[0] eq $i){
+						$hgrouprepres{$k}{$i}{mass}=$hrtmz{$tline[0]}{mz};
+					
+						my $intensity;
+						my $nbsubjects=0;
+						for(my $y=1;$y<scalar(@tline);$y++){
+							$intensity += $tline[$y];
+							$nbsubjects ++;
+						}
+						my $meanintensity = $intensity/$nbsubjects;
+						$hgrouprepres{$k}{$i}{intensity}=$meanintensity;
+						$hgrouprepres{$k}{$i}{squaredmassint}=($hgrouprepres{$k}{$i}{mass}**2)/($hgrouprepres{$k}{$i}{intensity});
+					}
+				}
+			}
+	}
+	close F3;
+	
+	foreach my $z (keys %hgrouprepres){
+		my $max_intensity =  0;
+		my $max_int_ion = "";
+		my $max_mass = 0;
+		my $max_mass_ion = "";
+		my $max_squared = 0;
+		my $max_squared_ion = "";
+		foreach my $w (keys %{$hgrouprepres{$z}}){
+			if($hgrouprepres{$z}{$w}{intensity} > $max_intensity){
+				$max_intensity = $hgrouprepres{$z}{$w}{intensity};
+				$max_int_ion = $w;
+				
+			}
+			if($hgrouprepres{$z}{$w}{mass} > $max_mass){
+				$max_mass = $hgrouprepres{$z}{$w}{mass};
+				$max_mass_ion = $w;
+			}
+			if($hgrouprepres{$z}{$w}{squaredmassint} > $max_squared){
+				$max_squared = $hgrouprepres{$z}{$w}{squaredmassint};
+				$max_squared_ion = $w;
+			}
+		}
+		$hgrouprepres{$z}{max_int}=$max_int_ion;
+		$hgrouprepres{$z}{max_mass}=$max_mass_ion;
+		$hgrouprepres{$z}{max_squared}=$max_squared_ion;
+	}
+	
+	
+	######################
+	### Print result ! ###
+	######################
+	
+	open(F4, ">$output_tabular");
+	open(F5, $combined_DMVM);
+	
+	my $line_nb = 0;
+	my %hheader;
+	while (my $line = <F5>){
+		chomp $line;
+		
+		
+		my @tline = split (/\t/, $line);
+		
+		if($line_nb == 0){
+			print F4 "$line\tanalytic_correl_groups";
+			if($opt == 1){
+				print F4 "\tintensity_repres\tanalytic_corr_filtration\n";
+			}
+			else{
+				if($repres_opt eq "intensity"){print F4 "\tintensity_repres\tfragments\tanalytic_corr_filtration\n"}
+				if($repres_opt eq "mass"){print F4 "\tmass_repres\tfragments\tanalytic_corr_filtration\n"}
+				if($repres_opt eq "mixt"){print F4 "\tmass2intens_repres\tfragments\tanalytic_corr_filtration\n"}
+			}
+			
+			
+			### Creation of a header hash
+			for(my $i=0; $i<scalar(@tline);$i++){
+				my $a = $tline[$i];
+				$hheader{$a}=$i;
+			}
+		}
+		
+		else{
+			my $find = 0;
+			foreach my $v (keys %hcorrelgroup){
+					if(defined($hgrouprepres{$v}{$tline[0]})){
+						print F4 "$line\t$v";
+						
+						
+						if($repres_opt eq "intensity"){print F4 "\t$hgrouprepres{$v}{max_int}\t"}
+						if($repres_opt eq "mass"){print F4 "\t$hgrouprepres{$v}{max_mass}\t"}
+						if($repres_opt eq "mixt"){print F4 "\t$hgrouprepres{$v}{max_squared}\t"}
+						
+
+						if(defined($hcorrelgroup{$v}{frag})){
+							print F4 "$hcorrelgroup{$v}{frag}\t";
+						}
+						
+						if($repres_opt eq "intensity"){
+							if($tline[0] eq $hgrouprepres{$v}{max_int}){
+								print F4 "conserve\n";
+							}
+							else{
+								print F4 "elimine\n";
+							}
+							$find = 1;
+						}
+						if($repres_opt eq "mass"){
+							if($tline[0] eq $hgrouprepres{$v}{max_mass}){
+								print F4 "conserve\n";
+							}
+							else{
+								print F4 "elimine\n";
+							}
+							$find = 1;
+						}
+						if($repres_opt eq "mixt"){
+							if($tline[0] eq $hgrouprepres{$v}{max_squared}){
+								print F4 "conserve\n";
+							}
+							else{
+								print F4 "elimine\n";
+							}
+							$find = 1;
+						}
+						
+					}
+			}
+			if($find == 0){
+				$groupct ++;
+				my $group = "group".$groupct;
+				print F4 "$line\t$group\t\t-\n";	
+			}
+			
+			
+		}
+		
+		$line_nb ++;
+	}
+	
+	
+	return ($output_sif, $output_tabular);
+}
+
+
+#############################################################################
+### Removing all duplicates in correlation matrice and filtered all pairs ###
+#############################################################################
+
+#
+#sub CorrelationFiltering{
+#	
+#	
+#	my $file = $_[0];
+#	my $subfile = $_[1];
+#	my $opt = $_[2];
+#	my $rt_threshold = $_[3];
+#	my $mass_threshold = $_[4];
+#	my $refhmass = $_[5];
+#	
+#	my $rt_pos = $rt_threshold;
+#	my $rt_neg = -$rt_threshold;
+#	
+#	my $mass_pos = $mass_threshold;
+#	my $mass_neg = -$mass_threshold;
+#	
+##	foreach my $k (keys %$refhmass){
+##		print "clé : $k\n";
+##		print "$refhmass->{$k}\n";
+##	}
+#	
+#	open(F1, $file) or die "Impossible to read \"$file\"\n";
+#	open(F2, ">$subfile");
+#	
+#	my %hcorrel;
+#	
+#	while (my $line = <F1>){
+#		chomp($line);
+#		
+#		my @tline = split(/\t/,$line);
+#		my $a=$tline[0];
+#		my $b=$tline[2];
+#		my $coef=$tline[1];
+#		
+#		if($a eq $b){
+##			print "This is a correlation between A ($a) and A ($b) !\n"
+#		}
+#		else{
+#			
+#			if($a =~m/M(.+)T(\d+\.\d+)_?/){
+#				my $amass=$1;
+#				my $atemp=$2;
+#				if($b =~m/M(.+)T(\d+\.\d+)_?/){
+#					my $bmass= $1;
+#	#				print "$1\n";
+#					my $btemp=$2;
+#					my $diff = $amass-$bmass;
+#					$diff = abs($diff);
+#				
+#	### Don't take into acount mass information ###
+#	
+#				
+#					if($opt == 1){
+#						my $btplus = $btemp + $rt_pos;
+#						my $btmoins = $btemp + $rt_neg;
+#						if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+#							print F2 "$line\n";
+#							
+#							#print "$k ET $v font parti du même groupe de corrélations !\n";
+#							#$hcorrelgroup{$k}{$v}=$hcorrel{$k}{$v};
+#						}
+#					}
+#				
+#	### Define value for time and mass differences ###	
+#	
+#					elsif($opt == 2){
+#						if(($diff<$mass_pos) && ($diff>$mass_neg)){
+#							my $btplus = $btemp + $rt_pos;
+#							my $btmoins = $btemp + $rt_neg;
+#							if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+#								print F2 "$line\n";
+#								
+#								#print "$k ET $v font parti du même groupe de corrélations !\n";
+#								#$hcorrelgroup{$k}{$v}=$hcorrel{$k}{$v};
+#							}
+#						}
+#					}
+#				
+#	### Check that all mass differences are include in a specific list taking into account RT information ###
+#	
+#					elsif($opt == 3){
+#						
+#						my $print = 0;
+#						foreach my $r (keys %$refhmass){
+#							my $rm = $r + $mass_neg;
+#							my $rp = $r + $mass_pos;
+#							if(($diff <= $rp) && ($diff >= $rm)){
+#								if($print == 0){
+#									
+#									my $btplus = $btemp + $rt_pos;
+#									my $btmoins = $btemp + $rt_neg;
+#									if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+#										foreach my $s (keys %{%$refhmass{$r}}){
+#		#									print F2 "$line\t$hmass{$r}{$s} : $s ($r)\n";
+#											print F2 "$line\n";
+#											$print = 1;
+#										}
+#										
+#										#print "$k ET $v font parti du même groupe de corrélations !\n";
+#										#$hcorrelgroup{$k}{$v}=$hcorrel{$k}{$v};
+#									}
+#								}
+#							}
+#						}
+#					}
+#					
+#				
+#	### Check that all mass differences are include in a specific list, ignoring RT information ###
+#
+#					elsif($opt == 4){
+#						
+#						my $print = 0;
+#						foreach my $r (keys %$refhmass){
+#							my $rm = $r + $mass_neg;
+#							my $rp = $r + $mass_pos;
+#							if(($diff <= $rp) && ($diff >= $rm)){
+#								if($print == 0){
+#									
+##									my $btplus = $btemp + $rt_pos;
+##									my $btmoins = $btemp + $rt_neg;
+##									if(($btmoins <= $atemp) && ($atemp <= $btplus)){
+#										foreach my $s (keys %{%$refhmass{$r}}){
+#		#									print F2 "$line\t$hmass{$r}{$s} : $s ($r)\n";
+#											print F2 "$line\n";
+#											$print = 1;
+#										}
+#										
+#										#print "$k ET $v font parti du même groupe de corrélations !\n";
+#										#$hcorrelgroup{$k}{$v}=$hcorrel{$k}{$v};
+##									}
+#								}
+#							}
+#						}
+#					}
+#				}
+#			}	
+#		}
+#	}
+#	
+#	
+#	close F1;
+#	close F2;
+#	
+#	return $subfile;
+#}
+
+
+################################################
+### Duplicates removing into filtered file ! ### 
+################################################
+
+
+#sub DuplicatesRemoving{
+#	
+#	my $file = $_[0];
+#	my $no_duplica = $_[1];
+#	
+#	my %hduplicate;
+#	
+#	open (F1, $file);
+#	open (F2, ">$no_duplica");
+#	
+#	while (my $line = <F1>){
+#		chomp($line);
+#		
+#		my @tline = split(/\t/,$line);
+#		my $a=$tline[0];
+#		my $b=$tline[2];
+#		my $coef=$tline[1];
+#		
+#		my $y = $a."/".$b;
+#		my $z = $b."/".$a;
+#		
+#		if((!(defined($hduplicate{$y}))) && (!(defined($hduplicate{$z})))){
+#			print F2 "$line\n";
+#			
+#			$hduplicate{$y}=1;
+#		}
+#	}
+#	
+#	close F1;
+#	close F2;
+#	
+#	return $no_duplica;
+#}
+
+
+
+####################################
+### Correlation groups formation ### 
+####################################
+
+
+#sub CorrelGroups{
+#	
+#	my $file = $_[0];
+#	my $subfile = $_[1];
+#	
+#	my %hcorrelgroup;
+#	my $groupct=1;
+#	
+#	open (F3, $subfile);
+#	
+#	while (my $line = <F3>){
+#		chomp($line);
+#		
+#		my @tline = split(/\t/,$line);
+#		my $a=$tline[0];
+#		my $b=$tline[2];
+#		my $coef=$tline[1];
+#
+#		my $count=0;
+#		
+#		foreach my $k (keys %hcorrelgroup){
+#			if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
+#				$hcorrelgroup{$k}{$a}=1;
+#				$hcorrelgroup{$k}{$b}=1;
+#				$count++;
+#				last;
+#			}
+#		}
+#		if($count == 0){
+#			my $groupnb="group".$groupct;
+#			$hcorrelgroup{$groupnb}{$a}=1;
+#			$hcorrelgroup{$groupnb}{$b}=1;
+#			$groupct ++;
+#		}
+#	}
+#	
+#	close F3;
+#	
+#	### Join group that have been subdivided
+#	
+#	my @tdelete;
+#	
+#	foreach my $k (keys %hcorrelgroup){
+#		foreach my $i (keys %{$hcorrelgroup{$k}}){
+##			if($i eq "M533.3656T14.71"){print"je passe bien par là !\n"}
+#			foreach my $v (keys %hcorrelgroup){
+#				my $count = 0;
+#				if ($v ne $k){
+#					foreach my $w (keys %{$hcorrelgroup{$v}}){
+#						if($w eq $i){
+#							$count = 1;
+#							push(@tdelete, $v);
+#						}
+#					}
+#				}
+#				if($count == 1){
+#					foreach my $w (keys %{$hcorrelgroup{$v}}){
+#						$hcorrelgroup{$k}{$w}=1;
+#					}
+#					delete($hcorrelgroup{$v});
+#				}
+#			}
+#		}
+#	}
+#	
+#	foreach my $t (@tdelete){
+#		delete($hcorrelgroup{$t});
+#	}
+#	
+#	
+#	### Do it twice to see if it fix the problem of unmerge groups
+#	
+#	foreach my $k (keys %hcorrelgroup){
+#		foreach my $i (keys %{$hcorrelgroup{$k}}){
+##			if($i eq "M533.3656T14.71"){print"je passe bien par là !\n"}
+#			foreach my $v (keys %hcorrelgroup){
+#				my $count = 0;
+#				if ($v ne $k){
+#					foreach my $w (keys %{$hcorrelgroup{$v}}){
+#						if($w eq $i){
+#							$count = 1;
+#							push(@tdelete, $v);
+#						}
+#					}
+#				}
+#				if($count == 1){
+#					foreach my $w (keys %{$hcorrelgroup{$v}}){
+#						$hcorrelgroup{$k}{$w}=1;
+#					}
+#					delete($hcorrelgroup{$v});
+#				}
+#			}
+#		}
+#	}
+#	
+#	foreach my $t (@tdelete){
+#		delete($hcorrelgroup{$t});
+#	}
+#	
+#	
+#	
+#	my $result_file;
+#	if($file =~ m/(.+)\.sif/){
+#		$result_file = $1."_group_result.tabular";
+#	}
+#	
+#	
+#	open(F4, ">$result_file");
+#	
+#	$groupct=1;
+#	
+#	foreach my $x (keys %hcorrelgroup){
+#		my $groupnb="group".$groupct;
+#		print F4 "$groupnb\n";
+#		foreach my $y (keys %{$hcorrelgroup{$x}}){
+#			print F4 "\t$y";
+#		}
+#		print F4 "\n";
+#		$groupct ++;
+#	}
+#	
+#	close F4;
+#	
+#	return $result_file;
+#}
+
+
+#########################################################################
+### Representative ion selection for each analytics correlation group ###
+#########################################################################
+
+
+#sub FiltrationResult{
+#	
+#	my $dataMatrix = $_[0];
+#	my $group_file = $_[1];
+#	my $combined_DMVM = $_[2];
+#	my $repres_opt = $_[3];
+#	my $output_tabular = $_[4];
+#	my $ANOVA = $_[3];
+#	my $Approch1 = $_[4];
+	
+#	my %hgrouprepres;
+#	my $groupname;
+	
+#	open(F1, $group_file);
+#		
+#	while (my $line = <F1>){
+#		chomp $line;
+#		
+#		if($line =~ m/^group/){
+#			$groupname=$line;
+#		}
+#		else{
+#			my @tline = split(/\t/,$line);
+#			foreach my $v (@tline){
+#				if (!($v eq "")){
+#					if($v =~ m/^M(\d*\.\d*)T.*/){
+#						$hgrouprepres{$groupname}{$v}{mass}=$1;
+#						$hgrouprepres{$groupname}{$v}{intensity}="";
+#						$hgrouprepres{$groupname}{$v}{squaredmassint}="";
+#					}
+#				}
+#			}
+#		}
+#	}
+	
+#	open(F2, $dataMatrix);
+#	
+#	while (my $line = <F2>){
+#		chomp $line;
+#		
+#		my @tline = split (/\t/, $line);
+#		
+#		foreach my $k (keys %hgrouprepres){
+#			foreach my $i (keys %{$hgrouprepres{$k}}){
+#				if($tline[0] eq $i){
+#					my $intensity;
+#					my $nbsubjects=0;
+#					for(my $y=1;$y<scalar(@tline);$y++){
+#						$intensity += $tline[$y];
+#						$nbsubjects ++;
+#					}
+#					my $meanintensity = $intensity/$nbsubjects;
+#					$hgrouprepres{$k}{$i}{intensity}=$meanintensity;
+#					$hgrouprepres{$k}{$i}{squaredmassint}=($hgrouprepres{$k}{$i}{mass}**2)/($hgrouprepres{$k}{$i}{intensity});
+#				}
+#			}
+#		}
+#	}
+#	
+#	### Choose the group representative ion
+#	
+#	foreach my $v (keys %hgrouprepres){
+#		my $max_intensity =  0;
+#		my $max_int_ion = "";
+#		my $max_mass = 0;
+#		my $max_mass_ion = "";
+#		my $max_squared = 0;
+#		my $max_squared_ion = "";
+#		foreach my $w (keys %{$hgrouprepres{$v}}){
+#			if($hgrouprepres{$v}{$w}{intensity} > $max_intensity){
+#				$max_intensity = $hgrouprepres{$v}{$w}{intensity};
+#				$max_int_ion = $w;
+#				
+#			}
+#			if($hgrouprepres{$v}{$w}{mass} > $max_mass){
+#				$max_mass = $hgrouprepres{$v}{$w}{mass};
+#				$max_mass_ion = $w;
+#			}
+#			if($hgrouprepres{$v}{$w}{squaredmassint} > $max_squared){
+#				$max_squared = $hgrouprepres{$v}{$w}{squaredmassint};
+#				$max_squared_ion = $w;
+#			}
+#		}
+##		print "Pour le $v, l'ion avec la plus grande intensité est : $max_int_ion ; l'ion avec la plus grande masse est $max_mass_ion ; l'ion avec le plus grand (masse²*intensité) est $mass_squared_ion !\n";
+#		$hgrouprepres{$v}{max_int}=$max_int_ion;
+#		$hgrouprepres{$v}{max_mass}=$max_mass_ion;
+#		$hgrouprepres{$v}{max_squared}=$max_squared_ion;
+#	}
+#	
+#	
+#	
+#	### Print result !
+#	
+#	my $repres_file;
+#	my $group_nb=0;
+#	if($group_file =~ m/(.+)\.tabular/){
+#		$repres_file = $1."_representative_ion.tabular";
+#	} 
+#	
+#	open (F3, ">$repres_file");
+#	
+#	foreach my $v (keys %hgrouprepres){
+#		print F3 "$v\n\t";
+#		$group_nb ++;
+#		foreach my $w (keys %{$hgrouprepres{$v}}){
+#			if(($w ne "max_int") && ($w ne "max_mass") && ($w ne "max_squared")){
+#				print F3 "$w\t";
+#			}
+#		}
+#		print F3 "\n";
+#		print F3 "\tL'ion avec la plus forte intensite est : $hgrouprepres{$v}{max_int} !\n";
+#		print F3 "\tL'ion avec la plus grande masse est : $hgrouprepres{$v}{max_mass} !\n";
+#		print F3 "\tL'ion avec le plus grand (masse^2*intensite) est : $hgrouprepres{$v}{max_squared} !\n";
+#	}
+	
+	
+	### Print new DM_VM with resultats included
+	
+#	my $repres_VM;
+#	if($combined_DMVM =~ m/.*[\/\\](.*)\.tabular$/){
+#		$repres_VM = $output_tabular."/".$1."_representative_ion.tabular";
+#	}
+#	if($combined_DMVM =~ m/.*[\/\\](.*)\.tsv$/){
+#		$repres_VM = $output_tabular."/".$1."_representative_ion.tsv";
+#	}
+#	
+#	open(F4, ">$repres_VM");
+#	open(F5, $combined_DMVM);
+#	
+#	my $line_nb = 0;
+#	my %hheader;
+#	while (my $line = <F5>){
+#		chomp $line;
+#		
+#		
+#		my @tline = split (/\t/, $line);
+#		
+#		if($line_nb == 0){
+#			print F4 "$line\tanalytic_correl_groups";
+#			if($repres_opt eq "intensity"){print F4 "\tintensity_repres\tanalytic_corr_filtration\n"}
+#			if($repres_opt eq "mass"){print F4 "\tmass_repres\tanalytic_corr_filtration\n"}
+#			if($repres_opt eq "mixt"){print F4 "\tmass2intens_repres\tanalytic_corr_filtration\n"}
+#			
+#			### Creation of a header hash
+#			for(my $i=0; $i<scalar(@tline);$i++){
+##				print "$i ==> \"$tline[$i]\"\n";
+#				my $a = $tline[$i];
+#				$hheader{$a}=$i;
+#			}
+#		}
+#		
+#		else{
+#			my $find = 0;
+#			foreach my $v (keys %hgrouprepres){
+#					if(defined($hgrouprepres{$v}{$tline[0]})){
+#						print F4 "$line\t$v";
+#						if($repres_opt eq "intensity"){print F4 "\t$hgrouprepres{$v}{max_int}\t"}
+#						if($repres_opt eq "mass"){print F4 "\t$hgrouprepres{$v}{max_mass}\t"}
+#						if($repres_opt eq "mixt"){print F4 "\t$hgrouprepres{$v}{max_squared}\t"}
+#						
+#						
+#						if($repres_opt eq "intensity"){
+#							if($tline[0] eq $hgrouprepres{$v}{max_int}){
+#								print F4 "conserve\n";
+#							}
+#							else{
+#								print F4 "elimine\n";
+#							}
+#							$find = 1;
+#						}
+#						if($repres_opt eq "mass"){
+#							if($tline[0] eq $hgrouprepres{$v}{max_mass}){
+#								print F4 "conserve\n";
+#							}
+#							else{
+#								print F4 "elimine\n";
+#							}
+#							$find = 1;
+#						}
+#						if($repres_opt eq "mixt"){
+#							if($tline[0] eq $hgrouprepres{$v}{max_squared}){
+#								print F4 "conserve\n";
+#							}
+#							else{
+#								print F4 "elimine\n";
+#							}
+#							$find = 1;
+#						}
+#						
+#					}
+#			}
+#			if($find == 0){
+#				$group_nb ++;
+#				my $group = "group".$group_nb;
+#				print F4 "$line\t$group\t\t-\n";	
+#			}
+			
+			
+			### Indicate if the ion is conserved or not depending on the Approche 1 + Approche 2 intensity
+			
+#			my $b = scalar(keys %hheader);
+#			$hheader{correl_analytic_groups}=$b;
+#			$b ++;
+#			$hheader{intens_repres}=$b;
+#			$b ++;
+#			$hheader{mass_repres}=$b;
+#			$b ++;
+#		}
+#		
+#		$line_nb ++;
+#	}
+#	
+#	close F4;
+#	close F5;
+#	
+#	return $repres_VM;
+#}
+
+
+
+
+1;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACF/analytic_correlation_filtration.xml	Fri Oct 05 12:10:45 2018 -0400
@@ -0,0 +1,131 @@
+<tool id="Analytic_correlation_filtration" name="Analytic correlation filtration" version="2018-08-20">
+	<description>
+		: Detect analytic correlation among data and remove them.
+	</description>
+	
+	<requirements>
+		<requirement type="package">perl-statistics</requirement>
+		<requirement type="package" version="1.19">perl-soap-lite</requirement>
+	</requirements>
+	
+	 <command><![CDATA[
+		
+		
+		
+		#if str($mass_file.mass_choice)=="false":
+			#if str($rt_cond.rt_choice)=="false":
+				perl $__tool_directory__/analytic_correlation_filtration.pl -f "$file_in" -o 1 -d "$dataMatrix_in" -v "$variableMetadata_in" -r "$repres_opt" -rt 9999999999
+			#else:
+				perl $__tool_directory__/analytic_correlation_filtration.pl -f "$file_in" -o 1 -d "$dataMatrix_in" -v "$variableMetadata_in" -r "$repres_opt" -rt "$mass_file.rt_threshold" 
+			#end if
+		#else:
+			#if str($rt_cond.rt_choice)=="true":
+				perl $__tool_directory__/analytic_correlation_filtration.pl -f "$file_in" -m "$mass_file_in" -o 2 -d "$dataMatrix_in" -v "$variableMetadata_in" -r "$repres_opt" -rt "$mass_file.rt_cond.rt_threshold" -mass "$mass_file.mass_threshold" 
+			#end if
+			#if str($rt_cond.rt_choice)=="false":
+				perl $__tool_directory__/analytic_correlation_filtration.pl -f "$file_in" -m "$mass_file_in" -o 3 -d "$dataMatrix_in" -v "$variableMetadata_in" -r "$repres_opt" -mass "$mass_file.mass_threshold" 
+			#end if
+		#end if
+	
+		-correl "$correl_threshold"
+		-output_sif "$sif_out"
+		-output_tabular "$variableMetadata_out"
+		
+	]]></command>
+	
+	<inputs>
+		<param type="data" name="file_in" format="txt" help="The .txt correlation table (you can obtain it by using the XXX tool) " label="Correlation table file" />
+		<param type="data" name="dataMatrix_in" format="tabular" help="" label="dataMatrix file" />
+		<param type="data" name="variableMetadata_in" format="tabular" help="" label="variableMetadata file" />
+		
+		<param help="Define the minimum correlation threshold accepted to determine analytic correlation" label="Correlation threshold" type="float" name="correl_threshold" value="0.90"/>
+		
+		<conditional name="mass_file">
+		  <param checked="true" falsevalue="false" help="'YES' if you have an available mass differences list to use; 'NO' if you don't want to take into account mass information" label="Do you want to take into account mass differences between 2 ions? (you will need a mass differences file) " name="mass_choice" truevalue="true" type="boolean"/>
+				<when value="true">
+					<param type="data" name="mass_file_in" format="tabular,csv" help="The file containing all your report and known mass differences (format = difference type \t difference name \t mass difference)" label="Mass differences table (format: tabular or csv) " />
+					<param help="2 ions need to have a difference mass included in the list at +/- mass difference range to be considered as analytically correlated" label="Mass difference range" type="float" name="mass_threshold" value="0.005"/>
+					
+					
+					
+				</when>
+				<when value="false">
+			
+				</when>
+		</conditional>
+		
+		<conditional name="rt_cond">
+			<param checked="true" falsevalue="false" help="'YES' if want to take into account retention time information; 'NO' if you don't want to take into account retention time information" label="Do you want to take into account retention time differences between 2 ions? " name="rt_choice" truevalue="true" type="boolean"/>
+				<when value="true">
+					<param help="Choose a retention time difference threshold between 2 ions considered as analytically correlated" label="Retention time difference threshold" type="float" name="rt_threshold" value="0.1"/>
+				</when>
+				<when value="false">
+					
+				</when>
+		</conditional>
+		
+		<param name="repres_opt" label="Which representative ion do you want to select for each group" type="select" display="radio" help="">
+			<option value="intensity">Highest intensity</option>
+			<option value="mass">Highest mass</option>
+			<option value="mixt">Highest (mass2 x intensity) </option>
+		</param>
+	</inputs>
+	
+	<outputs>
+		<data format="sif" label="${file_in.name}_sif" name="sif_out"/>
+		<data format="tabular" label="${variableMetadata_in.name}_representative_ion" name="variableMetadata_out"/>
+	</outputs>
+	
+	<help>
+	
+	.. class:: infomark
+
+	**Authors**
+
+	| **Stephanie Monnerie (stephanie.monnerie@inra.fr)** wrote this tool for analytic correlation detection.
+
+	---------------------------------------------------
+
+	.. class:: infomark
+
+	**References**
+
+	| A completer avec les éventuelles refs.
+
+	---------------------------------------------------
+
+	-----------
+	Input files
+	-----------
+
+	+------------------------------+---------------+
+	| File                         |     Format    |
+	+==============================+===============+
+	| 1)  Correlation matrix       |  txt          |
+	+------------------------------+---------------+
+	| 2)  Mass differences list    |  csv/tabular  |
+	+------------------------------+---------------+
+	| 3)  Data matrix              |  tabular      |
+	+------------------------------+---------------+
+	| 4)  Variable metadata        |  tabular      |
+	+------------------------------+---------------+
+
+	----------
+	Parameters
+	----------
+	
+	Correlation matrix
+		| 
+		| File format :
+		|		Fist_Ion_ID \t Correlation_Value \t Second_Ion_ID
+	
+	Data matrix file
+		| "variable x sample" **dataMatrix** tabular separated file of the numeric data matrix, with . as decimal, and NA for missing values; the table must not contain metadata apart from row and column names; the row and column names must be identical to the rownames of the variable metadata (see below)
+		|
+		
+	Variable metadata file
+		| "variable x metadata" **variableMetadata** tabular separated file of the numeric and/or character variable metadata, with . as decimal and NA for missing values
+		|
+
+	</help>
+</tool>
\ No newline at end of file
--- a/CorrTable/Corr.xml	Fri Oct 05 10:21:42 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,300 +0,0 @@
-<tool id="corrtable" name="Between-table Correlation" version="0.0.0">
-	<description>Correlation table between two tables and graphic representation </description>
-	  <requirements>
-			<requirement type="package" version="1.1_4">r-batch</requirement>
-			<requirement type="package" version="3.0.0">r-ggplot2</requirement>
-			<requirement type="package" version="1.4.3">r-reshape2</requirement>
-	</requirements>
-	<command interpreter="Rscript">
-	
-		Corr_wrap.r
-		
-		tab1_in "$tab1_in"
-		tab2_in "$tab2_in"
-		
-		tab1_samples "$tab1_samples"
-		tab2_samples "$tab2_samples"
-		
-		corr_method "$corr_method"
-		
-		test_corr "${filter_section.testcorr_cond.test_corr}"
-		#if str($filter_section.testcorr_cond.test_corr) == 'yes' :
-			correct_multi "${filter_section.testcorr_cond.correct_multi}"
-			risk_alpha "${filter_section.testcorr_cond.risk_alpha}"
-		#end if
-		
-		filter "${filter_section.filter_cond.filter}"
-		#if str($filter_section.filter_cond.filter) == 'yes' :
-			filters_choice "${filter_section.filter_cond.filtchoice_cond.filters_choice}"
-			#if str($filter_section.filter_cond.filtchoice_cond.filters_choice) == 'filters_0_thr' :
-				threshold "${filter_section.filter_cond.filtchoice_cond.threshold}"
-			#end if
-		#end if
-		
-		reorder_var "$out_section.reorder_var"
-		
-		color_heatmap "${out_section.heatmap_cond.color_heatmap}"
-		#if str($out_section.heatmap_cond.color_heatmap) == 'yes' :
-			type_classes "${out_section.heatmap_cond.typeclass_cond.type_classes}"
-			#if str($out_section.heatmap_cond.typeclass_cond.type_classes) == 'regular' :
-				reg_class_value "${out_section.heatmap_cond.typeclass_cond.reg_class_value}"
-			#elif str($out_section.heatmap_cond.typeclass_cond.type_classes) == 'irregular' :
-				irreg_class_vect "${out_section.heatmap_cond.typeclass_cond.irreg_class_vect}"
-			#end if
-		#end if	
-		
-		tabcorr_out "$tabcorr_out"
-		heatmap_out "$heatmap_out"
-		
-	</command>
-	
-	<inputs>
-	
-		<param name="tab1_in" type="data" label="Table 1 file" help="The two input tables must have the same sample IDs" format="tabular" />
-		<param name="tab1_samples" label="Where are the samples in table 1?" type="select" display="radio" help="">
-			<option value="row">Row</option>
-			<option value="column">Column</option>
-		</param>
-		
-		<param name="tab2_in" type="data" label="Table 2 file" help="The two input tables must have the same sample IDs" format="tabular" />
-		<param name="tab2_samples" label="Where are the samples in table 2?" type="select" display="radio" help="">
-			<option value="row">Row</option>
-			<option value="column">Column</option>		
-		</param>
-		
-		<param name="corr_method" label="Method to calculate the correlation coefficients" type="select" help="">
-			<option value="pearson">Pearson</option>
-			<option value="spearman">Spearman</option>
-			<option value="kendall">Kendall</option>
-		</param>	
-		
-		<section name="filter_section" title="Filtering options" expanded="False">
-			<conditional name="testcorr_cond">
-				<param name="test_corr" label="Significance test for the correlation coefficients" type="select" display="radio" help="">
-					<option value="no">No</option>
-					<option value="yes">Yes</option>
-				</param>
-				<when value="yes">
-					<param name="correct_multi" label="Method for multiple testing correction" type="select" help="">
-						<option value="none">none</option>				
-						<option value="fdr">fdr</option>
-						<option value="BH">BH</option>
-						<option value="bonferroni">bonferroni</option>
-						<option value="BY">BY</option>
-						<option value="hochberg">hochberg</option>
-						<option value="holm">holm</option>
-						<option value="hommel">hommel</option>
-					</param>
-					<param name="risk_alpha" label="(Corrected) p-value significance threshold" type="float" value="0.05" help="Must be between 0 and 1" />
-				</when>
-				<when value="no">
-				</when>
-			</conditional>
-			
-			<conditional name="filter_cond">
-				<param name="filter" label="Filter the correlation table" type="select" display="radio" help="">
-					<option value="no">No</option>
-					<option value="yes">Yes</option>
-				</param>
-
-				<when value ="yes">
-					<conditional name="filtchoice_cond">
-						<param name="filters_choice" label="Do you want to use only zero filter or combine it with the threshold filter?" type="select" display="radio" help="The zero filter removes variables which have all their correlation coefficients equal to 0. The threshold filter removes variables which have all their correlation coefficients, in absolute value, strictly below a threshold.">
-							<option value="filter_0">Only zero filter</option>
-							<option value="filters_0_thr">Threshold filter</option>
-						</param>
-						
-						<when value="filters_0_thr">
-							<param name="threshold" label="Threshold" type="float" value="" help="Must be between 0 and 1" />
-						</when>
-						
-						<when value="filter_0">
-						</when>
-					</conditional>	
-				</when>
-				
-				<when value="no">
-				</when>
-			</conditional>		
-		</section>
-		
-		<section name="out_section" title="Graphical outputs" expanded="False">
-			<param name="reorder_var" label="Reorder variables (using Hierarchical Cluster Analysis)" type="select" display="radio" help="">
-				<option value="no">No</option>
-				<option value="yes">Yes</option>
-			</param>
-		
-			<conditional name="heatmap_cond">
-				<param name="color_heatmap" label="Colored correlation table strategy" type="select" display="radio" help="Standard corresponds to a scale with a smooth gradient between three colors: red, white and green (continuous case). Customized creates classes for the correlation coefficients - the scale has discrete values.">
-					<option value="no">Standard</option>
-					<option value="yes">Customized</option>
-				</param>		
-		
-				<when value="yes">
-					<conditional name="typeclass_cond">
-						<param name="type_classes" label="Choose the type of classes" type="select" display="radio" help="Regular means the classes have the same size. Irregular means it is possible to choose any intervals." >
-							<option value="regular">Regular classes</option>
-							<option value="irregular">Irregular classes</option>
-						</param>
-							
-						<when value="regular">
-							<param name="reg_class_value" label="Class size" type="float" value="" help="Must be between 0 and 1" />
-						</when>
-						
-						<when value="irregular">
-							<param name="irreg_class_vect" label="Vector with values for classes" type="text" value="" help="The vector must be of the following form: (value1,value2,value3,..). The values must be between -1 and 1 not included. For example: (-0.8,-0.5,-0.4,0,0.4,0.5,0.8)." />
-						</when>
-					</conditional>	
-				</when>
-				
-				<when value ="no">	
-				</when>
-	
-			</conditional>
-		</section>
-		
-	</inputs>	
-	
-	<outputs>
-		<data name="tabcorr_out" label="CorrTable" format="tabular" />
-		<data name="heatmap_out" label="CT_plot" format="pdf" />
-	</outputs>
-	
-	<help>
-	
-.. class:: infomark
-
-**Author:** 
-Ophelie Barbet for original code (PFEM - INRA) 
-Maintainer: Melanie Petera (PFEM - INRA - MetaboHUB)
-
----------------------------------------------------
-
-=========================
-Between-table Correlation
-=========================
-
------------
-Description
------------
-
- | Allows to visualise links existing between two data tables, with the creation of a correlation table between the variables of these tables, and a heatmap representing the correlation table colored according to the coefficients. 
- |
-
------------
-Input files
------------
-
-+----------------------------+------------+
-| Parameter                  |   Format   |
-+============================+============+
-| 1 : Table 1 file           |   tabular  |
-+----------------------------+------------+
-| 2 : Table 2 file           |   tabular  |
-+----------------------------+------------+
-
-|
-| The two input tables must have the same sample IDs.
-|
-
-----------
-Parameters
-----------
-
-Positions of samples in table 1 and table 2
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-        | Essential to correctly calculate the correlations.
-        |
-
-Method for calculating the correlation coefficients
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-        | - 'Pearson': Measures the intensity of the linear association between two continuous variables.
-		| - The 'Spearman' and 'Kendall' methods are explained in the R documentation of the 'cor' function as follows: " Kendall's tau or Spearman's rho statistic is used to estimate a rank-based measure of association. These are more robust and have been recommended if the data do not necessarily come from a bivariate normal distribution.".
-		|
-		
-Significance test for the correlation coefficients
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-        | This test is performed on each correlation coefficient, with the following hypotheses:
-        |         H0: The correlation coefficient is not significantly different from zero.
-        |         H1: The correlation coefficient is significantly different from zero.
-        |
-        | Coefficients whose null hypothesis (H0) are not rejected are replaced by zeros in the correlation table.
-        |
-
-| **Method for multiple testing correction (only if significance test is 'Yes'):**
-| The 7 methods implemented in the 'p.adjust' R function are available and documented as follows:
-| "The adjustment methods include the Bonferroni correction ("bonferroni") in which the p-values are multiplied by the number of comparisons. Less conservative corrections are also included by Holm (1979) ("holm"), Hochberg (1988) ("hochberg"), Hommel (1988) ("hommel"), Benjamini and Hochberg (1995) ("BH" or its alias "fdr"), and Benjamini and Yekutieli (2001) ("BY"), respectively. A pass-through option ("none") is also included. The set of methods are contained in the p.adjust.methods vector for the benefit of methods that need to have the method as an option and pass it on to p.adjust. The first four methods are designed to give strong control of the family-wise error rate. There seems no reason to use the unmodified Bonferroni correction because it is dominated by Holm's method, which is also valid under arbitrary assumptions. Hochberg's and Hommel's methods are valid when the hypothesis tests are independent or when they are non-negatively associated (Sarkar, 1998; Sarkar and Chang, 1997). Hommel's method is more powerful than Hochberg's, but the difference is usually small and the Hochberg p-values are faster to compute. The "BH" (aka "fdr") and "BY" method of Benjamini, Hochberg, and Yekutieli control the false discovery rate, the expected proportion of false discoveries amongst the rejected hypotheses. The false discovery rate is a less stringent condition than the family-wise error rate, so these methods are more powerfil than the others."
-|
-
-| **(Corrected) p-value significance threshold (only if significance test is 'Yes'):**
-| A value between 0 and 1, usually 0.05.
-|
-	
-Filter the correlation table
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^	
-        | Allows to reduce the correlation table size by keeping only variables considered relevant.
-        |
-
-| **Choose the filters to apply (only if filter is 'Yes'):**
-| 	- 'Only zero filter': Remove variables with all their correlation coefficients equal to zero.
-| 	- 'Threshold filter': Remove variables with all their correlation coefficients (in absolute value) strictly below a threshold.
-	
-| *Choose a threshold (only threshold filter is used):* A value between 0 and 1.
-|
-
-Reorder variables using Hierarchical Cluster Analysis (HCA)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-        | Allows the most linked variables to be close in the correlation table.
-        | A HCA is performed on each input tables, with:
-        |    - 1 - correlation coefficient, as distance
-        |    - Ward as aggregation method.
-        |
-
-        
-Colored correlation table strategy
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-		| Allows to create a colored correlation table. Variables of table 1 and variables of table 2 are related using colored rectangles. 
-		| 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.
-		| 	- 'Standard': the graphical representation has a scale with a smooth gradient between three colors: red, white and green.
-		| 	- 'Customized': the colored correlation table has coefficient classes. It is possible to create regular or irregular classes. The scale is discreet.
-		|
-		
-| **Choose the type of classes (only if colored correlation table strategy is 'Customized'):**
-
-| 	- 'Regular': classes are all (or almost) the same size. 	
-| 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.	
-
-| *Size of classes (if regular classes):* A value between 0 and 1.
-
-| 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].
-|
-
-| 	- 'Irregular': classes have variable lengths.
-| 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.
-
-| *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.
-
-| 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].
-|
-
-	
-------------
-Output files
-------------
-
-Correlation Table
-^^^^^^^^^^^^^^^^^
-	| Tabular output
-	| Correlation table between the variables of the two input tables
-	|
-	
-Heatmap (colored correlation table)
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-	| Pdf output
-	| 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.
-	|
-	
-	
-	</help>
-	
-</tool>	
\ No newline at end of file
--- a/CorrTable/Corr_Script_samples_row.R	Fri Oct 05 10:21:42 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,410 +0,0 @@
-  #################################################################################################
-  # CORRELATION TABLE                                                                             #
-  #                                                                                               #
-  #                                                                                               #
-  # Input : 2 tables with common samples                                                          #
-  # Output : Correlation table ; Heatmap (pdf)                                                    #
-  #                                                                                               #
-  # Dependencies : Libraries "ggplot2" and "reshape2"                                             #
-  #                                                                                               #
-  #################################################################################################
-  
-  
-  # Parameters (for dev)
-  if(FALSE){
-    
-    rm(list = ls())
-    setwd(dir = "Y:/Developpement")
-
-    tab1.name <- "Test/Ressources/Inputs/CT2_DM.tabular"
-    tab2.name <- "Test/Ressources/Inputs/CT2_base_Diapason_14ClinCES_PRIN.txt"
-    param1.samples <- "column"
-    param2.samples <- "row"
-    corr.method <- "pearson"
-    test.corr <- "yes"
-    alpha <- 0.05
-    multi.name <- "none"
-    filter <- "yes"
-    filters.choice <- "filters_0_thr"
-    threshold <- 0.2
-    reorder.var <- "yes"
-    color.heatmap <- "yes"
-    type.classes <-"irregular"
-    reg.value <- 1/3
-    irreg.vect <- c(-0.3, -0.2, -0.1, 0, 0.3, 0.4)
-    output1 <- "Correlation_table.txt"
-    output2 <- "Heatmap.pdf"
-    
-  }
-  
-  
-  
-  correlation.tab <- function(tab1.name, tab2.name, param1.samples, param2.samples, corr.method, test.corr, alpha, 
-                              multi.name, filter, filters.choice, threshold, reorder.var, color.heatmap, type.classes, 
-                              reg.value, irreg.vect, output1, output2){
-
-    # This function allows to visualize the correlation between two tables
-    # 
-    # Parameters:
-    # - tab1.name: table 1 file's access
-    # - tab2.name: table 2 file's access
-    # - param1.samples ("row" or "column"): where the samples are in tab1
-    # - param2.samples ("row" or "column"): where the samples are in tab2
-    # - corr.method ("pearson", "spearman", "kendall"): 
-    # - test.corr ("yes" or "no"): test the significance of a correlation coefficient
-    # - alpha (value between 0 and 1): risk for the correlation significance test
-    # - multi.name ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"): correction of multiple tests
-    # - filter ("yes", "no"): use filter.0 or/and filter.threshold
-    # - filters.choice ("filter_0" or "filters_0_thr"): zero filter removes variables with all their correlation coefficients = 0
-    #   and threshold filter remove variables with all their correlation coefficients in abs < threshold
-    # - threshold (value between 0 and 1): threshold for filter threshold
-    # - reorder.var ("yes" or "no"): reorder variables in the correlation table thanks to the HCA
-    # - color.heatmap ("yes" or "no"): color the heatmap with classes defined by the user
-    # - type.classes ("regular" or "irregular"): choose to color the heatmap with regular or irregular classes
-    # - reg.value (value between 0 and 1): value for regular classes
-    # - irreg.vect (vector with values between -1 and 1): vector which indicates values for intervals (irregular classes)
-    # - output1: correlation table file's access
-    # - output2: heatmap (colored correlation table) file's access
-  
-  
-  # Input ----------------------------------------------------------------------------------------------
-  
-  tab1 <- read.table(tab1.name, sep = "\t", header = TRUE, check.names = FALSE, row.names = 1) 
-  tab2 <- read.table(tab2.name, sep = "\t", header = TRUE, check.names = FALSE, row.names = 1)  
-  
-  # Transpose tables according to the samples
-  if(param1.samples == "column"){
-    tab1 <- t(tab1)
-  } 
-  
-  if(param2.samples == "column"){
-    tab2 <- t(tab2)
-  }
-  
-  # Sorting tables in alphabetical order of the samples
-  tab1 <- tab1[order(rownames(tab1)),]
-  tab2 <- tab2[order(rownames(tab2)),]
-  
-  
-  # Check if the 2 datasets match regarding samples identifiers
-  # Adapt from functions "check.err" and "match2", RcheckLibrary.R
-    
-  err.stock <- NULL
-    
-  id1 <- rownames(tab1)
-  id2 <- rownames(tab2)
-    
-  if(sum(id1 != id2) > 0){
-    err.stock <- c("\nThe two tables do not match regarding sample identifiers.\n")
-      
-    if(length(which(id1%in%id2)) != length(id1)){
-      identif <- id1[which(!(id1%in%id2))]
-      if (length(identif) < 4){
-        err.stock <- c(err.stock, "\nThe following identifier(s) found in the first table do not appear in the second table:\n")
-      }
-      else {
-        err.stock <- c(err.stock, "\nFor example, the following identifiers found in the first table do not appear in the second table:\n")
-      }
-      identif <- identif[1:min(3,length(which(!(id1%in%id2))))]
-      err.stock <- c(err.stock,"    ",paste(identif,collapse="\n    "),"\n")
-    }
-      
-    if(length(which(id2%in%id1)) != length(id2)){
-      identif <- id2[which(!(id2%in%id1))]
-      if (length(identif) < 4){
-        err.stock <- c(err.stock, "\nThe following identifier(s) found in the second table do not appear in the first table:\n")
-      }
-      else{
-        err.stock <- c(err.stock, "\nFor example, the following identifiers found in the second table do not appear in the first table:\n")
-      }
-      identif <- identif[1:min(3,length(which(!(id2%in%id1))))] 
-      err.stock <- c(err.stock,"    ",paste(identif,collapse="\n    "),"\n")
-    }
-    err.stock <- c(err.stock,"\nPlease check your data.\n")
-  }
-  
-  if(length(err.stock)!=0){ 
-    stop("\n- - - - - - - - -\n",err.stock,"\n- - - - - - - - -\n\n")
-  }
-  
-    
-  # Check qualitative variables in each input tables
-  err.msg <- NULL
-  
-  var1.quali <- vector()
-  var2.quali <- vector()
-  
-  for (i in 1:dim(tab1)[2]){
-    if(class(tab1[,i]) != "numeric" & class(tab1[,i]) != "integer"){
-      var1.quali <- c(var1.quali,i)
-    }
-  }
-  
-  for (j in 1:dim(tab2)[2]){
-    if(class(tab2[,j]) != "numeric" & class(tab2[,j]) != "integer"){
-      var2.quali <- c(var2.quali, j)
-    }
-  }
-  
-  if (length(var1.quali) != 0 | length(var2.quali) != 0){
-    err.msg <- c(err.msg, "\nThere are qualitative variables in your input tables which have been removed to compute the correlation table.\n\n")
-    
-    if(length(var1.quali) != 0 && length(var1.quali) < 4){
-      err.msg <- c(err.msg, "In table 1, the following qualitative variables have been removed:\n",
-                   "  ",paste(colnames(tab1)[var1.quali],collapse="\n    "),"\n")
-    } else if(length(var1.quali) != 0 && length(var1.quali) > 3){
-      err.msg <- c(err.msg, "For example, in table 1, the following qualitative variables have been removed:\n",
-                   "  ",paste(colnames(tab1)[var1.quali[1:3]],collapse="\n    "),"\n")
-    }
-    
-    if(length(var2.quali) != 0 && length(var2.quali) < 4){
-      err.msg <- c(err.msg, "In table 2, the following qualitative variables have been removed:\n", 
-                   "  ",paste(colnames(tab2)[var2.quali],collapse="\n    "),"\n")
-    } else if(length(var2.quali) != 0 && length(var2.quali) > 3){
-      err.msg <- c(err.msg, "For example, in table 2, the following qualitative variables have been removed:\n", 
-                   "  ",paste(colnames(tab2)[var2.quali[1:3]],collapse="\n    "),"\n")
-    }  
-  }
-  
-  if(length(var1.quali) != 0){
-    tab1 <- tab1[,-var1.quali]
-  }
-  if(length(var2.quali) != 0){
-    tab2 <- tab2[,-var2.quali]
-  }
-  
-  if(length(err.msg) != 0){ 
-    cat("\n- - - - - - - - -\n",err.msg,"\n- - - - - - - - -\n\n")
-  }
-  
-  # Correlation table ---------------------------------------------------------------------------------
-  
-  tab.corr <- matrix(nrow = dim(tab2)[2], ncol = dim(tab1)[2])
-  for (i in 1:dim(tab2)[2]){
-    for (j in 1:dim(tab1)[2]){
-      tab.corr[i,j] <- cor(tab2[,i], tab1[,j], method = corr.method, use = "pairwise.complete.obs") 
-    }
-  }
-  
-  colnames(tab.corr) <- colnames(tab1)
-  rownames(tab.corr) <- colnames(tab2)
-  
-  
-  
-  # Significance of correlation test  ------------------------------------------------------------------
-  
-  if (test.corr == "yes"){
-    
-    pvalue <- vector()
-    for (i in 1:dim(tab.corr)[1]){
-      for (j in 1:dim(tab.corr)[2]){
-        suppressWarnings(corrtest <- cor.test(tab2[,i], tab1[,j], method = corr.method))
-        pvalue <- c(pvalue, corrtest$p.value)
-        if (multi.name == "none"){
-          if (corrtest$p.value > alpha){
-            tab.corr[i,j] <- 0
-          }
-        }
-      }
-    }
-  
-    if(multi.name != "none"){
-      adjust <- matrix(p.adjust(pvalue, method = multi.name), nrow = dim(tab.corr)[1], ncol = dim(tab.corr)[2], byrow = T)
-      tab.corr[adjust > alpha] <- 0
-    }
-  }  
-  
-  
-  # Filter settings ------------------------------------------------------------------------------------
-  
-  if (filter == "yes"){
-    
-    # Remove variables with all their correlation coefficients = 0 :
-    if (filters.choice == "filter_0"){
-      threshold <- 0
-    } 
-      
-    var2.thres <- vector()
-    for (i in 1:dim(tab.corr)[1]){
-      if (length(which(abs(tab.corr[i,]) <= threshold)) == dim(tab.corr)[2]){
-        var2.thres <- c(var2.thres, i)
-      }
-    }
-    
-    if (length(var2.thres) != 0){
-      tab.corr <- tab.corr[-var2.thres,]
-      tab2 <- tab2[, -var2.thres]
-    }
-    
-    var1.thres <- vector()
-    for (i in 1:dim(tab.corr)[2]){
-      if (length(which(abs(tab.corr[,i]) <= threshold)) == dim(tab.corr)[1]){
-        var1.thres <- c(var1.thres, i)
-      }
-    }
-      
-    if (length(var1.thres) != 0){
-      tab.corr <- tab.corr[,-var1.thres]
-      tab1 <- tab1[,-var1.thres]
-    }
-    
-  } 
-  
-  
-  # Reorder variables in the correlation table (with the HCA) ------------------------------------------
-  if (reorder.var == "yes"){
-    
-    cormat.tab2 <- cor(tab2, method = corr.method, use = "pairwise.complete.obs")
-    dist.tab2 <- as.dist(1 - cormat.tab2)
-    hc.tab2 <- hclust(dist.tab2, method = "ward.D2")
-    tab.corr <- tab.corr[hc.tab2$order,]
-    
-    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]
-    
-  }
-  
-  
-  
-  # Output 1 : Correlation table -----------------------------------------------------------------------
-  
-  # Export correlation table
-  write.table(x = data.frame(name = rownames(tab.corr), tab.corr), file = output1, sep = "\t", quote = FALSE, row.names = FALSE)
-  
-  
-  
-  # Create the heatmap ---------------------------------------------------------------------------------
-  
-  # A message if no variable kept
-  if(length(tab.corr)==0){
-	pdf(output2)
-	plot.new()
-	legend("center","Filtering leads to no remaining correlation coefficient.")
-	dev.off()
-  } else {
-  
-  
-  library(ggplot2)
-  library(reshape2)
-  
-  # Melt the correlation table :
-  melted.tab.corr <- melt(tab.corr)
-  
-  if (color.heatmap == "yes") {
-     
-    # Add a column for the classes of each correlation coefficient
-    classe <- rep(0, dim(melted.tab.corr)[1])
-    melted <- cbind(melted.tab.corr, classe)
-    
-    if (type.classes == "regular"){
-      
-      vect <- vector()
-      if (seq(-1,0,reg.value)[length(seq(-1,0,reg.value))] == 0){
-        vect <- c(seq(-1,0,reg.value)[-length(seq(-1,0,reg.value))], 
-                  rev(seq(1,0,-reg.value)))
-      } else {
-        vect <- c(seq(-1,0,reg.value), 0, rev(seq(1,0,-reg.value)))
-      }
-      
-    } else if (type.classes == "irregular") {
-      
-      irreg.vect <- c(-1, irreg.vect, 1) 
-      vect <- irreg.vect
-      
-    }
-    
-    # Color palette :  
-    myPal <- colorRampPalette(c("#00CC00", "white", "red"), space = "Lab", interpolate = "spline")
-    
-    # Create vector intervals
-    cl <- vector()
-    cl <- paste("[", vect[1], ";", round(vect[2],3), "]", sep = "")
-    
-    for (x in 2:(length(vect)-1)) {
-      if (vect[x+1] == 0) {
-        cl <- c(cl, paste("]", round(vect[x],3), ";", round(vect[x+1],3), "[", sep = ""))
-      } else {
-        cl <- c(cl, paste("]", round(vect[x],3), ";", 
-                          round(vect[x+1],3), "]", sep = ""))
-      }
-    }
-    
-    # Assign an interval to each correlation coefficient
-    for (i in 1:dim(melted.tab.corr)[1]){
-      for (j in 1:(length(cl))){
-        if (vect[j] == -1){
-          melted$classe[i][melted$value[i] >= vect[j] 
-                           && melted$value[i] <= vect[j+1]] <- cl[j]
-        } else {
-          melted$classe[i][melted$value[i] > vect[j] 
-                           && melted$value[i] <= vect[j+1]] <- cl[j]
-        }
-      }
-    }
-    
-    # Find the 0 and assign it the white as name
-    if (length(which(vect == 0)) == 1) {
-      melted$classe[melted$value == 0] <- "0"
-      indic <- which(vect == 0)
-      cl <- c(cl[1:(indic-1)], 0, cl[indic:length(cl)])
-      names(cl)[indic] <- "#FFFFFF"
-    } else if (length(which(vect == 0)) == 0) {
-      indic <- 0
-      for (x in 1:(length(vect)-1)) {
-        if (0 > vect[x] && 0 <= vect[x+1]) {
-          names(cl)[x] <- "#FFFFFF"
-          indic <- x
-        }
-      }
-    }
-    
-    indic <- length(cl) - indic + 1
-    cl <- rev(cl)
-    
-    # Assign the colors of each intervals as their name
-    names(cl)[1:(indic-1)] <- myPal(length(cl[1:indic])*2-1)[1:indic-1]
-    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))]
-    
-    
-    melted$classe <- factor(melted$classe)
-    melted$classe <- factor(melted$classe, levels = cl[cl%in%levels(melted$classe)])
-    
-    # Heatmap if color.heatmap = yes :
-    ggplot(melted, aes(Var2, Var1, fill = classe)) +
-      ggtitle("Colored correlation table" ) + xlab("Table 1") + ylab("Table 2") +
-      geom_tile(color ="ghostwhite") +
-      scale_fill_manual( breaks = levels(melted$classe),
-                         values = names(cl)[cl%in%levels(melted$classe)],
-                         name = paste(corr.method, "correlation", sep = "\n")) +
-      theme_classic() +
-      theme(axis.text.x = element_text(angle = 90, vjust = 0.5), 
-            plot.title = element_text(hjust = 0.5)) 
-    
-  } else {
-    
-    # Heatmap if color.heatmap = no :
-    ggplot(melted.tab.corr, aes(Var2, Var1, fill = value)) +
-      ggtitle("Colored correlation table" ) + xlab("Table 1") + ylab("Table 2") +
-      geom_tile(color ="ghostwhite") +
-      scale_fill_gradient2(low = "red", high = "#00CC00", mid = "white", midpoint = 0, limit = c(-1,1),
-                           name = paste(corr.method, "correlation", sep = "\n")) +
-      theme_classic() +
-      theme(axis.text.x = element_text(angle = 90, vjust = 0.5), 
-            plot.title = element_text(hjust = 0.5))
-  }
-  
-  
-  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 correlation.tab
-  
-  
-  # Function call
-  # correlation.tab(tab1.name, tab2.name, param1.samples, param2.samples, corr.method, test.corr, alpha, multi.name, filter,
-  #                             filters.choice, threshold, reorder.var, color.heatmap, type.classes,
-  #                             reg.value, irreg.vect, output1, output2)
--- a/CorrTable/Corr_wrap.r	Fri Oct 05 10:21:42 2018 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-#!/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