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