annotate ACF/Analytic_correlation_filtration.pl @ 0:d03fcbeb0a77 draft

Uploaded
author melpetera
date Fri, 18 Oct 2019 04:59:51 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
1 #!usr/bin/perl
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
2
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
3 ### Perl modules
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
4 use warnings;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
5 use strict;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
6 use Getopt::Long qw(GetOptions); #Creation of script options
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
7 use Pod::Usage qw(pod2usage); #Creation of script options
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
8
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
9 #Personnal packages
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
10 use FindBin ; ## Allows you to locate the directory of original perl script
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
11 #use lib $FindBin::Bin;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
12 use lib "$FindBin::Bin/lib";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
13 use IonFiltration;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
14
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
15 my ($file, $mass_file, $opt, $dataMatrix, $combined_DMVM, $repres_opt, $rt_threshold, $mass_threshold, $output_sif, $output_tabular, $correl_threshold, $intensity_threshold, $intensity_pourc); #Options to complete
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
16
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
17 ########################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
18 ### Options and help ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
19 ########################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
20
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
21 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, "IT=f"=>\$intensity_threshold, "IP=f"=>\$intensity_pourc) or pod2usage(2);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
22
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
23 ### Check required parameters :
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
24 pod2usage({-message=>q{Mandatory argument '-f' is missing}, -exitval=>1, -verbose=>0}) unless $file;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
25 #pod2usage({-message=>q{Mandatory argument '-m' is missing}, -exitval=>1, -verbose=>0}) unless $mass_file;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
26 pod2usage({-message=>q{Mandatory argument '-o' is missing. It correspond to the grouping method for analytical correlation groups formation.
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
27 #It should be a number (1 ; 2 or 3) :
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
28 # 1 : Don't take into acount mass information (only RT) ;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
29 # 2 : Check that all mass differences are include in a specific list and taking into acount RT information
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
30 # 3 : Check that all mass differences are include in a specific list, ignoring RT information
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
31 #To use the tool without takinf into account mass and RT information, use option 1 and define the RT threshold to 999999999.}, -exitval=>1, -verbose=>0}) unless $opt;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
32 pod2usage({-message=>q{Mandatory argument '-r' is missing. It correspond to the group representent choosing method for analytical correlation groups formation.
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
33 It should be one of the 3 options below :
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
34 "mass" : choose the ion with the highest mass as the representant
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
35 "intensity" : choose the ion with the highest intensity as the representant
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
36 "mixt" : choose the ion with the highest (mass^2 * intensity) as the representant
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
37 "max_intensity_max_mass" : choose tha ion witht he highest intenisty among the 5 most intense ions of the group}, -exitval=>1, -verbose=>0}) unless $repres_opt;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
38 pod2usage({-message=>q{Mandatory argument '-d' is missing}, -exitval=>1, -verbose=>0}) unless $dataMatrix;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
39 pod2usage({-message=>q{Mandatory argument '-v' is missing}, -exitval=>1, -verbose=>0}) unless $combined_DMVM;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
40 #pod2usage({-message=>q{Mandatory argument '-rt' is missing}, -exitval=>1, -verbose=>0}) unless $rt_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
41 #pod2usage({-message=>q{Mandatory argument '-mass' is missing}, -exitval=>1, -verbose=>0}) unless $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
42 pod2usage({-message=>q{Mandatory argument '-correl' is missing}, -exitval=>1, -verbose=>0}) unless $correl_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
43 pod2usage({-message=>q{Mandatory argument '-output_tabular' is missing}, -exitval=>1, -verbose=>0}) unless $output_tabular;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
44 pod2usage({-message=>q{Mandatory argument '-output_sif' is missing}, -exitval=>1, -verbose=>0}) unless $output_sif;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
45
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
46
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
47 #if(($opt != 1) && ($opt != 2) && ($opt != 3)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
48 # print "you must indicate \"1\", \"2\" or \"3\" for the --o otpion\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
49 # exit;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
50 #}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
51
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
52
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
53
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
54 if(($repres_opt ne "mass") && ($repres_opt ne "intensity") && ($repres_opt ne "mixt") && ($repres_opt ne "max_intensity_max_mass")){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
55 print "you must indicate \"mass\", \"intensity\", \"mix\" or \"max_intensity_max_mass\" for the --r otpion\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
56 exit;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
57 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
58
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
59
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
60
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
61 #########################################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
62 #### Création of a hash containing all adduits and fragments possible ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
63 #########################################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
64
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
65 my %hmass;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
66 if($opt != 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
67 %hmass = IonFiltration::MassCollecting($mass_file);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
68
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
69 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
70
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
71 my $refhmass = \%hmass;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
72
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
73 print "Création of a hash containing all adduits and fragments possible\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
74
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
75
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
76 ########################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
77 ### Creation of a sif table + correlation filtration ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
78 ########################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
79
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
80 my %hrtmz;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
81 ($output_sif, %hrtmz) = IonFiltration::sifTableCreation($file, $output_sif, $opt, $rt_threshold, $mass_threshold, $correl_threshold, $dataMatrix, $output_tabular, $combined_DMVM, $repres_opt, $intensity_threshold, $intensity_pourc, \%hmass);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
82 print "Creation of a sif table + correlation filtration done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
83
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
84
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
85 ######################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
86 ### Analytic correlation filtrering follow options ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
87 ######################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
88
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
89 my %hheader_file;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
90 my %hduplicate;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
91
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
92 my %hcorrelgroup;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
93 my $groupct=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
94
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
95 my $linenb3=0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
96 my %hheader_line;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
97
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
98
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
99
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
100 open (F1, $output_sif) or die "Impossible to open $output_sif\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
101
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
102 while(my $line = <F1>){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
103 my $count=0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
104 chomp $line;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
105 my @tline = split(/\t/, $line);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
106 my $a = $tline[0];
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
107 my $b = $tline[2];
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
108
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
109 my $amass=$hrtmz{$a}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
110 my $atemp=$hrtmz{$a}{rt};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
111 my $bmass= $hrtmz{$b}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
112 my $btemp=$hrtmz{$b}{rt};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
113 my $diff = $amass-$bmass;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
114 $diff = abs($diff);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
115
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
116 ### Option 1: Don't take into acount mass information ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
117
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
118 if($opt == 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
119 my $btplus = $btemp + $rt_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
120 my $btmoins = $btemp - $rt_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
121 if(($btmoins <= $atemp) && ($atemp <= $btplus)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
122 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
123 if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
124 $hcorrelgroup{$k}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
125 $hcorrelgroup{$k}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
126 $count++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
127 last;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
128 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
129 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
130 if($count == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
131 my $groupnb="group".$groupct;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
132 $hcorrelgroup{$groupnb}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
133 $hcorrelgroup{$groupnb}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
134 $groupct ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
135 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
136 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
137 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
138
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
139
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
140
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
141 ### Option 2: Check that all mass differences are include in a specific list taking into account RT information ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
142
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
143 elsif($opt == 2){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
144
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
145 my $print = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
146 foreach my $s (keys %{$refhmass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
147 foreach my $r (keys %{$refhmass->{$s}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
148 my $rm = $r - $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
149 my $rp = $r + $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
150 if(($diff <= $rp) && ($diff >= $rm)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
151 if($print == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
152 my $btplus = $btemp + $rt_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
153 my $btmoins = $btemp - $rt_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
154
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
155 if(($btmoins <= $atemp) && ($atemp <= $btplus)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
156 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
157 if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
158 $hcorrelgroup{$k}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
159 $hcorrelgroup{$k}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
160 $count++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
161 last;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
162 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
163 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
164 if($count == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
165 my $groupnb="group".$groupct;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
166 $hcorrelgroup{$groupnb}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
167 $hcorrelgroup{$groupnb}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
168 $groupct ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
169 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
170 $print = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
171 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
172 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
173 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
174 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
175 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
176 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
177
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
178
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
179 ### Option 3: Check that all mass differences are include in a specific list, ignoring RT information ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
180
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
181 elsif($opt == 3){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
182
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
183 my $print = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
184 foreach my $s (keys %{$refhmass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
185 foreach my $r (keys %{$refhmass->{$s}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
186 my $rm = $r - $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
187 my $rp = $r + $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
188 if(($diff <= $rp) && ($diff >= $rm)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
189 if($print == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
190
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
191 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
192 if((defined($hcorrelgroup{$k}{$a})) || (defined($hcorrelgroup{$k}{$b}))){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
193 $hcorrelgroup{$k}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
194 $hcorrelgroup{$k}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
195 $count++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
196 last;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
197 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
198 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
199 if($count == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
200 my $groupnb="group".$groupct;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
201 $hcorrelgroup{$groupnb}{$a}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
202 $hcorrelgroup{$groupnb}{$b}=1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
203 $groupct ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
204 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
205 $print = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
206 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
207 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
208 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
209 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
210 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
211 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
212 close F1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
213
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
214 print "Analytic correlation filtrering follow options done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
215
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
216
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
217 #############################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
218 ### Join groups that have been subdivided ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
219 #############################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
220
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
221 my @tdelete;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
222
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
223 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
224 foreach my $i (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
225 foreach my $v (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
226 my $count = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
227 if ($v ne $k){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
228 foreach my $w (keys %{$hcorrelgroup{$v}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
229 if($w eq $i){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
230 $count = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
231 push(@tdelete, $v);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
232 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
233 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
234 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
235 if($count == 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
236 foreach my $w (keys %{$hcorrelgroup{$v}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
237 $hcorrelgroup{$k}{$w}=$hcorrelgroup{$v}{$w};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
238 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
239 delete($hcorrelgroup{$v});
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
240 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
241 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
242 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
243 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
244
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
245 foreach my $t (@tdelete){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
246 delete($hcorrelgroup{$t});
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
247 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
248
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
249
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
250 ### Do it twice to see if it fix the problem of unmerge groups
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
251
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
252 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
253 foreach my $i (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
254 foreach my $v (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
255 my $count = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
256 if ($v ne $k){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
257 foreach my $w (keys %{$hcorrelgroup{$v}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
258 if($w eq $i){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
259 $count = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
260 push(@tdelete, $v);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
261 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
262 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
263 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
264 if($count == 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
265 foreach my $w (keys %{$hcorrelgroup{$v}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
266 $hcorrelgroup{$k}{$w}=$hcorrelgroup{$v}{$w};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
267 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
268 delete($hcorrelgroup{$v});
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
269 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
270 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
271 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
272 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
273
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
274 foreach my $t (@tdelete){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
275 delete($hcorrelgroup{$t});
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
276 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
277
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
278 print "Join groups that have been subdivided done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
279
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
280 #######################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
281 ### Addition of annotation information among groups ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
282 #######################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
283
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
284 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
285 foreach my $i (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
286 foreach my $j (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
287 my $count = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
288 if ($i ne $j){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
289
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
290 my $a = $hrtmz{$i}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
291 my $b = $hrtmz{$j}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
292
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
293 my $diff = $a - $b;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
294 my $sign;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
295 if($diff>0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
296 $sign="+";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
297 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
298 if($diff<0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
299 $sign="-";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
300 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
301 $diff = abs($diff);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
302
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
303 foreach my $z (keys %{$refhmass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
304
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
305 foreach my $y (keys %{$refhmass->{$z}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
306 my $ym = $y - $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
307 my $yp = $y + $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
308
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
309
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
310 if(($diff <= $yp) && ($diff >= $ym)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
311 my $diff_list = $diff - $y;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
312 $diff_list = abs($diff_list);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
313 $diff_list = sprintf ("%0.6f", $diff_list);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
314
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
315 if($hcorrelgroup{$k}{$i} eq 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
316 my $val = "@".$j."|".$sign."(".$z.")(".$diff_list.")|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
317 $hcorrelgroup{$k}{$i}=$val;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
318 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
319 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
320 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
321 if($count == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
322 my $val = "@".$j."|".$sign."(".$z.")(".$diff_list.")|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
323 $hcorrelgroup{$k}{$i}.=$val;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
324 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
325 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
326 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
327 my $val = $sign."(".$z.")(".$diff_list.")|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
328 $hcorrelgroup{$k}{$i}.=$val;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
329 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
330 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
331 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
332 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
333 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
334 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
335 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
336 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
337 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
338 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
339
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
340
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
341 print "Addition of annotation information among groups done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
342
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
343
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
344 ####################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
345 ### Choose the representative ion for each group ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
346 ####################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
347
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
348 my %hgrouprepres;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
349
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
350 open(F3, $dataMatrix);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
351
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
352 while (my $line = <F3>){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
353 chomp $line;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
354
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
355 my @tline = split (/\t/, $line);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
356
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
357 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
358 foreach my $i (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
359 if($tline[0] eq $i){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
360 $hgrouprepres{$k}{$i}{mass}=$hrtmz{$tline[0]}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
361 my $intensity;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
362 my $nbsubjects=0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
363 for(my $y=1;$y<scalar(@tline);$y++){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
364 $intensity += $tline[$y];
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
365 $nbsubjects ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
366 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
367 my $meanintensity = $intensity/$nbsubjects;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
368 $hgrouprepres{$k}{$i}{intensity}=$meanintensity;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
369 $hgrouprepres{$k}{$i}{squaredmassint}=($hgrouprepres{$k}{$i}{mass}**2)/($hgrouprepres{$k}{$i}{intensity});
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
370 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
371 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
372 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
373 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
374 close F3;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
375
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
376 foreach my $z (keys %hgrouprepres){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
377 my $max_intensity = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
378 my $max_int_ion = "";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
379 my $max_mass = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
380 my $max_mass_ion = "";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
381 my $max_squared = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
382 my $max_squared_ion = "";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
383 foreach my $w (keys %{$hgrouprepres{$z}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
384 if($hgrouprepres{$z}{$w}{intensity} > $max_intensity){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
385 $max_intensity = $hgrouprepres{$z}{$w}{intensity};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
386 $max_int_ion = $w;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
387 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
388 if($hgrouprepres{$z}{$w}{mass} > $max_mass){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
389 $max_mass = $hgrouprepres{$z}{$w}{mass};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
390 $max_mass_ion = $w;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
391 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
392 if($hgrouprepres{$z}{$w}{squaredmassint} > $max_squared){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
393 $max_squared = $hgrouprepres{$z}{$w}{squaredmassint};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
394 $max_squared_ion = $w;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
395 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
396 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
397
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
398 my $max_int_max_mass_ion="";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
399
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
400 if($repres_opt eq "max_intensity_max_mass"){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
401 my %hfirst;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
402 my $first=0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
403 foreach my $w (reverse sort {$hgrouprepres{$z}{$a}{intensity} <=> $hgrouprepres{$z}{$b}{intensity} } keys %{$hgrouprepres{$z}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
404 $first ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
405 if ($first <= 3){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
406 $hfirst{$w} = $hgrouprepres{$z}{$w}{intensity};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
407 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
408 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
409
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
410 my $first_2 = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
411 my $intens_max = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
412 my $mass_max = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
413
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
414 foreach my $y (reverse sort {$hfirst{$a} <=> $hfirst{$b}} keys %hfirst){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
415
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
416 $first_2 ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
417 if($first_2 == 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
418 $intens_max = $hfirst{$y};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
419 if($intensity_threshold > $intens_max){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
420 $intensity_threshold = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
421 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
422 $max_int_max_mass_ion = $y;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
423 $mass_max = $hgrouprepres{$z}{$y}{mass};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
424 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
425 if($hgrouprepres{$z}{$y}{mass} > $mass_max){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
426 if($hfirst{$y}>$intensity_threshold){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
427 my $a = $intens_max * $intensity_pourc;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
428 if($hfirst{$y} > $a){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
429 $max_int_max_mass_ion = $y;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
430 $mass_max = $hgrouprepres{$z}{$y}{mass};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
431 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
432 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
433 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
434 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
435 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
436
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
437 $hgrouprepres{$z}{max_int}=$max_int_ion;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
438 $hgrouprepres{$z}{max_mass}=$max_mass_ion;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
439 $hgrouprepres{$z}{max_squared}=$max_squared_ion;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
440 $hgrouprepres{$z}{max_int_max_mass}=$max_int_max_mass_ion;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
441
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
442 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
443
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
444
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
445 print "Choose the representative ion for each group done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
446
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
447 #############################################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
448 ### Addition of annotation information relative to the representative ion ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
449 #############################################################################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
450
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
451 my %hreprescomparison;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
452
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
453 my $representative="";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
454
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
455 if($opt != 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
456 foreach my $k (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
457 foreach my $i (keys %{$hcorrelgroup{$k}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
458
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
459 if($repres_opt eq "mass"){$representative = $hgrouprepres{$k}{max_mass}}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
460 if($repres_opt eq "intensity"){$representative = $hgrouprepres{$k}{max_int}}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
461 if($repres_opt eq "mixt"){$representative = $hgrouprepres{$k}{max_squared}}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
462 if($repres_opt eq "max_intensity_max_mass"){$representative = $hgrouprepres{$k}{max_int_max_mass}}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
463
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
464
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
465 my $count = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
466 if ($i ne $representative){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
467
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
468 my $a = $hrtmz{$i}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
469 my $b = $hrtmz{$representative}{mz};
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
470
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
471 my $diff = $a - $b;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
472 my $sign;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
473 if($diff>0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
474 $sign="+";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
475 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
476 if($diff<0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
477 $sign="-";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
478 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
479 $diff = abs($diff);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
480
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
481 foreach my $z (keys %{$refhmass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
482
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
483 foreach my $y (keys %{$refhmass->{$z}}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
484 my $ym = $y - $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
485 my $yp = $y + $mass_threshold;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
486
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
487 if(($diff <= $yp) && ($diff >= $ym)){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
488 my $diff_list = $diff - $y;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
489 $diff_list = abs($diff_list);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
490 $diff_list = sprintf ("%0.4f", $diff_list);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
491 if($hcorrelgroup{$k}{$i} eq 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
492 my $valrep = "[M ".$sign."(".$z.")]|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
493 $hreprescomparison{$k}{$i}{repres_diff}=$valrep;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
494 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
495 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
496 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
497 if($count == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
498 my $valrep = "[M ".$sign."(".$z.")]|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
499 $hreprescomparison{$k}{$i}{repres_diff}.=$valrep;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
500 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
501 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
502 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
503 my $valrep = "[M ".$sign."(".$z.")]|";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
504 $hreprescomparison{$k}{$i}{repres_diff}.=$valrep;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
505 $count ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
506 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
507 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
508 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
509 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
510 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
511 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
512 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
513 $hreprescomparison{$k}{$i}{repres_diff}="M";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
514 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
515 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
516 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
517 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
518
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
519
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
520 print "Addition of annotation information relative to the representative ion done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
521
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
522 ##############################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
523 ### Print in result file ! ###
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
524 ##############################
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
525
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
526 open(F4, ">$output_tabular");
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
527 open(F5, $combined_DMVM);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
528
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
529 my $line_nb = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
530 my %hheader;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
531 while (my $line = <F5>){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
532 chomp $line;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
533
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
534
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
535 my @tline = split (/\t/, $line);
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
536
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
537 if($line_nb == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
538 print F4 "$line\tACorF_groups";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
539 if($opt == 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
540 if($repres_opt eq "intensity"){print F4 "\tACorF_filter\tintensity_repres\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
541 if($repres_opt eq "mass"){print F4 "\tACorF_filter\tmass_repres\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
542 if($repres_opt eq "mixt"){print F4 "\tACorF_filter\tmass2intens_repres\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
543 if($repres_opt eq "max_intensity_max_mass"){print F4 "\tACorF_filter\tmax_intensity_max_mass_repres\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
544 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
545 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
546 if($repres_opt eq "intensity"){print F4 "\tisotopes_adducts_fragments_[\@id|annotation(delta_annotation)]\tACorF_filter\tintensity_repres\tannotation_relative_to_representative\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
547 if($repres_opt eq "mass"){print F4 "\tisotopes_adducts_fragments_[\@id|annotation(delta_annotation)]\tACorF_filter\tmass_repres\tannotation_relative_to_representative\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
548 if($repres_opt eq "mixt"){print F4 "\tisotopes_adducts_fragments_[\@id|annotation(delta_annotation)]\tACorF_filter\tmass2intens_repres\tannotation_relative_to_representative\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
549 if($repres_opt eq "max_intensity_max_mass"){print F4 "\tisotopes_adducts_fragments_[\@id|annotation(delta_annotation)]\tACorF_filter\tmax_intensity_max_mass_repres\tannotation_relative_to_representative\n"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
550 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
551
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
552
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
553 ### Creation of a header hash
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
554 for(my $i=0; $i<scalar(@tline);$i++){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
555 my $a = $tline[$i];
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
556 $hheader{$a}=$i;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
557 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
558 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
559
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
560 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
561 my $find = 0;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
562 foreach my $v (keys %hcorrelgroup){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
563 if(defined($hgrouprepres{$v}{$tline[0]})){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
564 print F4 "$line\t$v";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
565
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
566 if($opt != 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
567 if(defined($hcorrelgroup{$v}{$tline[0]})){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
568 print F4 "\t$hcorrelgroup{$v}{$tline[0]}\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
569
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
570 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
571 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
572 print F4 "\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
573 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
574 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
575
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
576 if($repres_opt eq "intensity"){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
577 if($tline[0] eq $hgrouprepres{$v}{max_int}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
578 print F4 "1\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
579 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
580 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
581 print F4 "0\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
582 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
583 $find = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
584 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
585 if($repres_opt eq "mass"){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
586 if($tline[0] eq $hgrouprepres{$v}{max_mass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
587 print F4 "1\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
588 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
589 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
590 print F4 "0\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
591 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
592 $find = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
593 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
594 if($repres_opt eq "mixt"){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
595 if($tline[0] eq $hgrouprepres{$v}{max_squared}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
596 print F4 "1\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
597 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
598 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
599 print F4 "0\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
600 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
601 $find = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
602 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
603 if($repres_opt eq "max_intensity_max_mass"){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
604 if($tline[0] eq $hgrouprepres{$v}{max_int_max_mass}){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
605 print F4 "1\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
606 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
607 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
608 print F4 "0\t";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
609 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
610 $find = 1;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
611 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
612
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
613 if($repres_opt eq "intensity"){print F4 "$hgrouprepres{$v}{max_int}\t"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
614 if($repres_opt eq "mass"){print F4 "$hgrouprepres{$v}{max_mass}\t"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
615 if($repres_opt eq "mixt"){print F4 "$hgrouprepres{$v}{max_squared}\t"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
616 if($repres_opt eq "max_intensity_max_mass"){print F4 "$hgrouprepres{$v}{max_int_max_mass}\t"}
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
617
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
618 if(defined($hreprescomparison{$v}{$tline[0]}{repres_diff})){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
619 print F4 "$hreprescomparison{$v}{$tline[0]}{repres_diff}\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
620 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
621 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
622 print F4 "-\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
623 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
624 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
625 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
626 if($find == 0){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
627 $groupct ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
628 my $group = "group".$groupct;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
629 if($opt != 1){
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
630 print F4 "$line\t$group\t-\t-\t-\t-\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
631 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
632 else{
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
633 print F4 "$line\t$group\t-\t-\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
634 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
635 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
636 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
637 $line_nb ++;
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
638 }
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
639
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
640 print "Print in result file done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
641
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
642 print "All steps done\n";
d03fcbeb0a77 Uploaded
melpetera
parents:
diff changeset
643