annotate Perl/GenerateHeatmapFromPAV.pl @ 5:4157f435fa89 draft

Uploaded
author dereeper
date Thu, 30 May 2024 12:11:25 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 use strict;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4 use File::Basename;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 my $dirname = dirname(__FILE__);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7 my $infile = $ARGV[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8 my $heatmap = $ARGV[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 my %core_cluster;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 my %samples;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 my %sequences;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 my %matrix;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 my %hash;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 my $cl_num = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 my $nb_strains = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 open(M,">$heatmap.accessory_01matrix.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 open(PAN,">$heatmap.pangenes_01matrix.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 open(F,"$infile");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 my $firstline = <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 $firstline =~s/\n//g;$firstline =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 #my @infos = split(/","/,$firstline);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 my @infos = split(/\t/,$firstline);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 print M "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 print PAN "Gene";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 #for (my $j=14; $j <= $#infos; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 for (my $j=1; $j <= $#infos; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 my $gbfile = $infos[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 $gbfile =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 $gbfile =~s/\.gb\.filt//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 my $strain = $gbfile;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 my @words = split(/_/,$strain);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 my $genus = $words[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 my $species = $words[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 my $shortname = substr($genus,0,3) . "_". substr($species,0,2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 for (my $j = 2; $j <= $#words; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 $shortname.="_".$words[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 #$shortname = substr($shortname,0,25);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 print M "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 print PAN "\t".$strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 $samples{$j} = $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 $nb_strains++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 print PAN "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 $cl_num++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 #my @infos = split(/","/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 my @infos = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 my $concat_accessory = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 #for (my $i = 14; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 for (my $i = 1; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 my $val = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 my $sample = $samples{$i};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 $matrix{$sample}{$cl_num} = $val;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 $val =~s/\"//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 if ($val =~/\w+/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
63 $concat_accessory .= "\t1";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
64 $hash{$sample}{$cl_num} = 1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
65 $sequences{$sample}.= "T";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
66 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
67 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
68 $concat_accessory .= "\t0";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
69 $hash{$sample}{$cl_num} = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
70 $sequences{$sample}.= "A";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
71 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
72 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
73 if ($concat_accessory =~/0/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
74 print M $cl_num.$concat_accessory."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
75 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
76 else{
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
77 $core_cluster{$cl_num}=1;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
78 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
79 print PAN $cl_num.$concat_accessory."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
80 #if ($cl_num > 1000){last;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
81 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
82 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
83 close(M);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
84 close(PAN);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
85
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
86
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
87 system("ulimit -s 163840;Rscript $dirname/../R/heatmap.R -f $heatmap.accessory_01matrix.txt -o $heatmap.complete.pdf");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
88 #system("ulimit -s 163840;Rscript $dirname/../R/heatmaply.R -f $heatmap.accessory_01matrix.txt -o $heatmap.complete2.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
89 system("pdf2svg $heatmap.complete.pdf $heatmap.complete.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
90
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
91
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
92 open(A,">$heatmap.alignment.fa");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
93 foreach my $sample(keys(%sequences)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
94 my $seq = $sequences{$sample};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
95 print A ">$sample\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
96 print A "$seq\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
97 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
98 close(A);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
99
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
100
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
101
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
102 my $min_y = 10000000;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
103 my $min_x = 10000000;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
104 my $max_y = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
105 my $max_x = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
106 my $step_x;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
107 my $step_y;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
108 open(SVG,"$heatmap.complete.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
109 open(SVGNEW,">$heatmap.complete.new.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
110 while(<SVG>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
111 if (/rgb\(100%,0%,0%\)/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
112 $_ =~s/rgb\(100%,0%,0%\)/rgb\(100%,100%,100%\)/g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
113 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
114 if (/rgb\(100%,63.529968%,0%\)/){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
115 $_ =~s/rgb\(100%,63.529968%,0%\)/rgb\(41%,72%,64%\)/g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
116 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
117 print SVGNEW $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
118 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
119 close(SVG);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
120 close(SVGNEW);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
121
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
122
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
123
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
124 my @clusters;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
125 open(F,"$heatmap.complete.pdf.cols.csv");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
126 <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
127 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
128 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
129 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
130 push(@clusters,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
131 print $line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
132 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
133 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
134
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
135 my @strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
136 open(F,"$heatmap.complete.pdf.rows.csv");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
137 <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
138 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
139 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
140 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
141 push(@strains,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
142 print $line;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
143 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
144 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
145
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
146
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
147 open(O,">$infile.sorted");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
148 open(HP,">$infile.sorted.for_heatmap_plotly.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
149 print O "ClutserID"."\t".join("\t",@strains)."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
150 print HP "ClutserID"."\t".join("\t",@strains)."\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
151 foreach my $cl(reverse(@clusters)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
152 print O $cl;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
153 my $clnb = $cl;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
154 if (length($clnb) == 1){$clnb = "000".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
155 elsif (length($clnb) == 2){$clnb = "00".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
156 elsif (length($clnb) == 3){$clnb = "0".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
157 my $name = "CLUSTER".$clnb;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
158
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
159 print HP $name;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
160 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
161 my $val = $matrix{$strain}{$cl};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
162 print O "\t$val";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
163 if ($val =~/\w/){print HP "\t1";}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
164 else{print HP "\t0";}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
165 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
166 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
167 print HP "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
168 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
169 foreach my $cl(keys(%core_cluster)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
170 print O $cl;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
171 my $clnb = $cl;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
172 if (length($clnb) == 1){$clnb = "000".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
173 elsif (length($clnb) == 2){$clnb = "00".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
174 elsif (length($clnb) == 3){$clnb = "0".$clnb;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
175 my $name = "CLUSTER".$clnb;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
176 print HP $name;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
177 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
178 my $val = $matrix{$strain}{$cl};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
179 print O "\t$val";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
180 if ($val =~/\w/){print HP "\t1";}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
181 else{print HP "\t0";}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
182
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
183 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
184 print O "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
185 print HP "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
186 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
187 close(O);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
188 close(HP);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
189
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
190 my $svg_section = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
191
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
192 if (scalar @clusters == 0){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
193 system("touch $heatmap.upsetr.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
194 if (!-e "$heatmap"){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
195 system("touch $heatmap");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
196 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
197 exit;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
198 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
199 system("cp -rf $infile $infile.bkp");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
200 system("cp -rf $infile.sorted $infile");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
201
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
202 my %combinaisons;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
203 my $x = $min_x;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
204 my $length_matrix = ($max_x-$min_x);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
205 my $height_matrix = ($max_y-$min_y);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
206 my $step_x = $length_matrix / scalar @clusters;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
207 #my $step_y = $height_matrix / scalar @strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
208
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
209 print "$height_matrix $length_matrix $step_x $step_y\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
210 my $previous_combinaison = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
211 my $combinaison_id = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
212 my %combinaison_ids;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
213 open(M,">$heatmap.upsetr.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
214 print M "ClutserID";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
215 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
216 my @words = split(/_/,$strain);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
217 my $genus = $words[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
218 my $species = $words[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
219 my $shortname = substr($genus,0,3) . "_". substr($species,0,2);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
220 for (my $j = 2; $j <= $#words; $j++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
221 $shortname.="_".$words[$j];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
222 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
223 $shortname = substr($shortname,0,25);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
224 print M "\t".$shortname;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
225 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
226 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
227 foreach my $cluster(@clusters){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
228 $x = $x+$step_x;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
229 my $combinaison = "";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
230 my $numstrain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
231 print M "$cluster";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
232 foreach my $strain(@strains){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
233 $numstrain++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
234 my $val = $hash{$strain}{$cluster};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
235 print M "\t".$val;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
236 if ($val == 1){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
237 $combinaison .= ",$numstrain";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
238 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
239 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
240 if ($combinaison ne $previous_combinaison){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
241 $combinaison_id++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
242 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
243 print M "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
244 $previous_combinaison = $combinaison;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
245 $combinaison_ids{$combinaison_id}=$combinaison;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
246 #print "Cluster:$cluster Combinaison: $combinaison X:$x $combinaison_id\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
247 $combinaisons{$combinaison_id} .= "|".$x;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
248
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
249 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
250 close(M);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
251
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
252
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
253 my $nb_strains = scalar @strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
254 system("Rscript $dirname/../R/upsetr.R $heatmap.upsetr.txt $heatmap.upsetr.pdf $nb_strains >>$heatmap.upsetr.log 2>&1");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
255 system("pdf2svg $heatmap.upsetr.pdf $heatmap.upsetr.svg 2");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
256
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
257 system("python3 $dirname/../Python/Heatmap.py -i $infile.sorted.for_heatmap_plotly.txt -o $heatmap.heatmap_plotly.html >>$heatmap.heatmap_plotly.log 2>&1");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
258
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
259 if (!-e "$heatmap.upsetr.svg"){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
260 system("touch $heatmap.upsetr.svg");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
261 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
262 system("perl $dirname/../Perl/reformatHeatmapSVG.pl $heatmap.complete.svg $heatmap.complete.new.svg $infile.sorted.for_heatmap_plotly.txt");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
263 system("cp -rf $heatmap.complete.new.svg $heatmap");
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
264 system("gzip $heatmap");