annotate ACorF/lib/IonFiltration.pm @ 1:26aa3a8f95ce draft

Uploaded
author melpetera
date Wed, 30 Oct 2019 06:54:20 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
1 #!usr/bin/perl
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
2 package IonFiltration;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
3
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
4 ### Perl modules
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
5 use strict;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
6 use warnings;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
7
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
8
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
9
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
10
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
11
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
12
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
13 ########################################################################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
14 ### Création of a hash containing all adduits and fragments possible ###
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
15 ########################################################################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
16
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
17
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
18 sub MassCollecting{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
19
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
20 my $mass_file = $_[0];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
21 my %hmass;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
22
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
23 open (F1, $mass_file);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
24
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
25 while(my $line = <F1>){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
26 chomp $line;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
27 my @tline = split(/[\t;]/, $line);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
28 if(defined($hmass{$tline[2]})){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
29 print "The mass difference already exists : $tline[2] !\n";
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
30 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
31 $hmass{$tline[1]}{$tline[2]}=$tline[0];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
32 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
33
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
34 close F1;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
35 return %hmass;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
36
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
37 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
38
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
39
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
40
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
41
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
42
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
43
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
44
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
45 ########################################################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
46 ### Creation of a sif table + correlation filtration ###
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
47 ########################################################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
48
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
49
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
50 sub sifTableCreation{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
51
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
52 my $file = $_[0];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
53 my $output_sif = $_[1];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
54 # my $opt = $_[2];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
55 # my $rt_threshold = $_[3];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
56 # my $mass_threshold = $_[4];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
57 my $correl_threshold = $_[5];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
58 # my $dataMatrix = $_[6];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
59 # my $output_tabular = $_[7];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
60 my $combined_DMVM = $_[8];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
61 # my $repres_opt = $_[9];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
62 # my $intensity_threshold = $_[10];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
63 # my $intensity_pourc = $_[11];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
64 # my $refhmass = $_[12];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
65
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
66
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
67
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
68
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
69 my %hheader_file;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
70 my %hduplicate;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
71
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
72 my %hcorrelgroup;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
73 my $groupct=1;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
74
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
75
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
76 my $linenb3=0;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
77 my %hheader_line;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
78 my %hrtmz;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
79
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
80 open (F5, $combined_DMVM);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
81 while(my $line = <F5>){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
82 chomp $line;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
83 my @tline = split(/\t/, $line);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
84
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
85 if($linenb3 == 0){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
86 for(my $i=0; $i<scalar(@tline);$i++){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
87 my $a = $tline[$i];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
88 $hheader_line{$a}=$i;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
89 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
90 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
91 else{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
92 if(defined($hheader_line{mzmed})){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
93 my $b = $tline[$hheader_line{mzmed}];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
94 $hrtmz{$tline[0]}{mz}=$b;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
95 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
96 else{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
97 my $b = $tline[$hheader_line{mz}];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
98 $hrtmz{$tline[0]}{mz}=$b;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
99 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
100 if(defined($hheader_line{rtmed})){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
101 my $d = $tline[$hheader_line{rtmed}];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
102 $hrtmz{$tline[0]}{rt}=$d;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
103 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
104 else{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
105 my $d = $tline[$hheader_line{rt}];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
106 $hrtmz{$tline[0]}{rt}=$d;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
107 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
108 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
109
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
110 $linenb3 ++;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
111 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
112 close F5;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
113
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
114
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
115 my $linenb=0;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
116
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
117 open (F1, $file) or die "Impossible to open $file\n";
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
118 open(F2, ">$output_sif") or die "Impossible to open $output_sif\n";
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
119
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
120
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
121 while(my $line = <F1>){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
122 chomp $line;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
123 my @tline = split(/\t/, $line);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
124
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
125 ###############################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
126 ### Création of a sif table ###
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
127 ###############################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
128
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
129 if($linenb == 0){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
130 for(my $i=0; $i<scalar(@tline);$i++){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
131 my $a = $tline[$i];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
132 $hheader_file{$i}=$a;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
133 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
134 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
135 else{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
136 for(my $i=1; $i<scalar(@tline);$i++){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
137 my $a=$tline[0];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
138 my $b=$hheader_file{$i};
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
139 my $coef=$tline[$i];
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
140
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
141 if($a eq $b){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
142 # print "This is a correlation between A ($a) and A ($b) !\n"
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
143 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
144 else{
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
145
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
146 #########################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
147 ### Remove duplicates ###
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
148 #########################
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
149
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
150 my $y = $a."/".$b;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
151 my $z = $b."/".$a;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
152
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
153 if((!(defined($hduplicate{$y}))) && (!(defined($hduplicate{$z})))){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
154
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
155 $hduplicate{$y}=1;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
156 # my $abcoef=abs($coef); # Only when you want to consider negative correlations
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
157
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
158 # if($abcoef > $correl_threshold){ # Only when you want to consider negative correlations
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
159 if($coef > $correl_threshold){
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
160
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
161 print F2 "$a\t$coef\t$b\n";
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
162
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
163 my $count=0;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
164
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
165 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
166 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
167 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
168 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
169 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
170 $linenb ++;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
171 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
172 close F1;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
173 close F2;
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
174 return ($output_sif, %hrtmz);
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
175 }
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
176
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
177
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
178
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
179
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
180
26aa3a8f95ce Uploaded
melpetera
parents:
diff changeset
181 1;