annotate lib/bih.pm @ 0:be582bcd6585 draft

Master branch Updating - - Fxx
author fgiacomoni
date Thu, 04 Oct 2018 10:37:14 -0400
parents
children 52798007c6b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1 package lib::bih ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
2
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
3 use strict;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
4 use warnings ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
5 use Exporter ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
6 use Carp ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
7 use Math::BigFloat;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
8
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
9 use LWP::Simple;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
10 use LWP::UserAgent;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
11 use URI::URL;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
12 use SOAP::Lite;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
13 use Encode;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
14 use HTML::Template ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
15 #use Net::SSL ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
16 use Data::Dumper ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
17 #use REST::Client;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
18 use JSON;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
19
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
20 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
21
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
22 our $VERSION = "1.0";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
23 our @ISA = qw(Exporter);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
24 our @EXPORT = qw( db_pforest_get_clean_range map_pfjson_bankobject prepare_multi_masses_query );
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
25 our %EXPORT_TAGS = ( ALL => [qw( db_pforest_get_clean_range map_pfjson_bankobject prepare_multi_masses_query )] );
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
26
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
27 =head1 NAME
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
28
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
29 My::Module - An example module
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
30
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
31 =head1 SYNOPSIS
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
32
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
33 use My::Module;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
34 my $object = My::Module->new();
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
35 print $object->as_string;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
36
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
37 =head1 DESCRIPTION
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
38
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
39 This module does not really exist, it
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
40 was made for the sole purpose of
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
41 demonstrating how POD works.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
42
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
43 =head1 METHODS
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
44
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
45 Methods are :
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
46
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
47 =head2 METHOD new
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
48
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
49 ## Description : new
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
50 ## Input : $self
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
51 ## Ouput : bless $self ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
52 ## Usage : new() ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
53
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
54 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
55
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
56 sub new {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
57 ## Variables
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
58 my $self={};
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
59 bless($self) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
60 return $self ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
61 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
62 ### END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
63
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
64 =head2 METHOD check_interval
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
65
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
66 ## Description : checks that the value is in the interval
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
67 ## Input : $value, $min, $max
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
68 ## Output : $message
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
69 ## Usage : $message= check_interval($value, $min, $max) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
70
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
71 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
72 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
73 sub check_interval {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
74 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
75 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
76 my ( $value, $min, $max ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
77
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
78 my ( $message ) = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
79 if ( $min !~ m/^-?\d+\.?\d*$/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
80 $message="the minimum '".$min."' isn't a valid number!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
81 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
82 elsif ( $max !~ m/^-?\d+\.?\d*$/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
83 $message="the maximum '".$max."' isn't a valid number!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
84 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
85 elsif ( $value !~ m/^-?\d+\.?\d*$/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
86 $message="'".$value."' isn't a valid number!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
87 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
88 elsif ( $value < $min ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
89 $message="'".$value."' is below the minimum!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
90 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
91 elsif ( $value > $max ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
92 $message="'".$value."' is greater than the maximum!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
93 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
94 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
95 $message="OK" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
96 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
97 return($message) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
98 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
99 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
100
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
101 =head2 METHOD format_manual_list_values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
102
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
103 ## Description : extract a list of values and built identifiers
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
104 ## Input : $value, $sep
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
105 ## Output : \@values, \@ids
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
106 ## Usage : ($masses, $ids)= format_manual_list_values($mass, $sep) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
107
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
108 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
109 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
110 sub format_manual_list_values {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
111 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
112 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
113 my ( $value, $sep ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
114
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
115 my ( @values, @ids ) = ( (), () ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
116
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
117 if ( ( defined $value ) and ( $value ne "" ) and ( defined $sep ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
118 @values = split($sep, $value);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
119 my $nb = 1+int(log($#values+1)/log(10));
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
120 my $sf = '%0'.$nb.'s';
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
121 for (my $i=1 ; $i<=$#values+1 ; $i++){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
122 my $id = sprintf($sf, $i) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
123 push (@ids,"value_".$id );
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
124 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
125 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
126 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
127 croak "No value list found \n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
128 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
129 return(\@values, \@ids) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
130 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
131 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
132
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
133 =head2 METHOD parse_bank_interest
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
134
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
135 ## Description : parse csv object and return a two-dimensional array in a hash by grouping information according to the interest value as key.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
136 ## Input : $csv, \$file, $col_interest
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
137 ## Output : \%bank_interest, \$head
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
138 ## Usage : my ( $bank_interest, $head ) = parse_bank_interest ( $csv, $file, $col_interest ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
139
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
140 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
141 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
142 sub parse_bank_interest {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
143 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
144 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
145 my ( $csv, $file, $col_interest ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
146
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
147 my $bank_interest = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
148 my $oBih = new() ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
149
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
150 open my $fh, "<:encoding(utf8)", $$file or die "Can't open csv file $$file: $!";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
151
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
152 my $head = $csv->getline( $fh );
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
153 my $nb_line = 1 ; ## for error messages
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
154
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
155 while ( my $row = $csv->getline( $fh ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
156 $nb_line++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
157 if ($#$head != $#$row) { croak "Not the same number of columns over the file of the interest bank! See the line: $nb_line in your input bank file!\n" ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
158 ## it would be more general to do the following masse check out this function
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
159 my ($MZmessage) = $oBih->check_interval($$row[$col_interest], 0, 10000) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
160 if ($MZmessage ne 'OK') { $col_interest++; croak "There is at least one row (See the line : $nb_line) where in the column $col_interest : $MZmessage\n" ; } #/!\ col_interest++ to print to user a not-table (@) value.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
161
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
162 push (@{$bank_interest->{$$row[$col_interest]}}, $row ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
163 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
164 # print Dumper $bank_interest; exit;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
165 $csv->eof or $csv->error_diag();
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
166 close $fh;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
167 return($bank_interest, $head) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
168 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
169 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
170
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
171 =head2 METHOD mz_delta_conversion
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
172
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
173 ## Description : returns the minimum and maximum mass according to the delta
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
174 ## Input : \$mass, \$delta_type, \$mz_delta
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
175 ## Output : \$min, \$max
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
176 ## Usage : ($min, $max)= mz_delta_conversion($mass, $delta_type, $mz_delta) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
177
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
178 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
179 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
180 sub mz_delta_conversion {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
181 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
182 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
183 my ( $mass, $delta_type, $mz_delta ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
184 my ( $min, $max ) = ( undef, undef ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
185
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
186 if ($$delta_type eq 'ppm'){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
187 $min = $$mass - ($$mz_delta * 10**-6 * $$mass);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
188 $max = $$mass + ($$mz_delta * 10**-6 * $$mass) + 0.0000000001; ## it's to included the maximum value in the search
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
189 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
190 elsif ($$delta_type eq 'Da'){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
191 $min = $$mass - $$mz_delta;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
192 $max = $$mass + $$mz_delta + 0.0000000001; ## it's to included the maximum value in the search
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
193 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
194 else { croak "The masses delta type '$$delta_type' isn't a valid type !\n" ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
195
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
196 return(\$min, \$max) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
197 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
198 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
199
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
200 =head2 METHOD dichotomi_search
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
201
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
202 ## Description : returns the index of the position or the interval value
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
203 ## does not work if there are duplicates in the table
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
204 ## Input : \@tab, \$search
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
205 ## Output : \$index
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
206 ## Usage : ($index)= dichotomi_search($mass, $sep) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
207
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
208 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
209 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
210 sub dichotomi_search {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
211 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
212 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
213 my ( $tab, $search ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
214 my ($sup, $inf, $demi) = (scalar(@{$tab})-1, 0, 0);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
215
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
216 while(1) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
217 $demi = int(($sup + $inf)/2);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
218 if($sup < $inf) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
219 if($inf==0){ $demi=-1; } elsif($sup==scalar(@{$tab})-1){ $demi=scalar(@{$tab}); } ## to distinguish items off limits
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
220 last;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
221 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
222 elsif ( ($$search == $$tab[$demi]) ) { last; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
223 elsif ( ($$search > $$tab[$demi-1]) && ($$search < @$tab[$demi]) ) { last; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
224 elsif($$search < $$tab[$demi]) { $sup = $demi - 1; next; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
225 else { $inf = $demi + 1; next; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
226 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
227
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
228 return(\$demi) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
229 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
230 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
231
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
232 =head2 METHOD extract_sub_mz_lists
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
233
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
234 ## Description : extract a couples of sublist from a long mz list (more than $HMDB_LIMITS)
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
235 ## Input : $HMDB_LIMITS, $masses
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
236 ## Output : $sublists
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
237 ## Usage : my ( $sublists ) = extract_sub_mz_lists( $HMDB_LIMITS, $masses ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
238
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
239 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
240 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
241 sub extract_sub_mz_lists {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
242 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
243 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
244 my ( $masses, $HMDB_LIMITS ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
245
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
246 my ( @sublists, @sublist ) = ( (), () ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
247 my $nb_mz = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
248 my $nb_total_mzs = scalar(@{$masses}) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
249
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
250 for ( my $current_pos = 0 ; $current_pos < $nb_total_mzs ; $current_pos++ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
251
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
252 if ( $nb_mz < $HMDB_LIMITS ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
253 if ( $masses->[$current_pos] ) { push (@sublist, $masses->[$current_pos]) ; $nb_mz++ ; } # build sub list
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
254 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
255 elsif ( $nb_mz == $HMDB_LIMITS ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
256 my @tmp = @sublist ; push (@sublists, \@tmp) ; @sublist = () ; $nb_mz = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
257 $current_pos-- ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
258 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
259 if ($current_pos == $nb_total_mzs-1) { my @tmp = @sublist ; push (@sublists, \@tmp) ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
260 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
261 return(\@sublists) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
262 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
263 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
264
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
265 =head2 METHOD prepare_multi_masses_query
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
266
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
267 ## Description : permet de generer une liste de masses au format d'interrogation de hmdb
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
268 ## Input : $masses
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
269 ## Output : $hmdb_masses
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
270 ## Usage : my ( $hmdb_masses ) = prepare_multi_masses_query( $masses ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
271
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
272 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
273 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
274 sub prepare_multi_masses_query {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
275 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
276 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
277 my ( $masses ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
278
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
279 my $hmdb_masses = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
280 my $sep = '%0D%0A' ; ## retour chariot encode
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
281 my ($nb_masses, $i) = (0, 0) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
282
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
283 if ( defined $masses ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
284 my @masses = @{$masses} ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
285 my $nb_masses = scalar ( @masses ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
286 if ( $nb_masses == 0 ) { croak "Your mass list is empty \n" ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
287 elsif ( $nb_masses >= 150 ) { croak "Your mass list is too long : HMDB allows maximum 150 query masses per request \n" ; } ## Del it --- temporary patch
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
288
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
289 foreach my $mass (@masses) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
290
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
291 if ($i < $nb_masses) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
292 $hmdb_masses .= $mass.$sep ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
293 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
294 elsif ( $i == $nb_masses ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
295 $hmdb_masses .= $mass ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
296 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
297 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
298 last ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
299 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
300 $i ++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
301 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
302 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
303 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
304 croak "No mass list found \n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
305 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
306 return($hmdb_masses, $nb_masses) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
307 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
308 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
309
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
310 =head2 METHOD get_matches_from_hmdb
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
311
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
312 ## Description : permet de requeter sur hmdb avec une masse, un delta de masse sur la banque de metabolites hmdb
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
313 ## Input : $mass, $delta, $mode
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
314 ## Output : $results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
315 ## Usage : my ( $results ) = get_matches_from_hmdb( $mass, $delta, $mode ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
316
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
317 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
318 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
319 sub get_matches_from_hmdb {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
320 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
321 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
322 my ( $mass, $delta, $mode ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
323
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
324 my @pages = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
325 my $page = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
326
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
327 if ( (defined $mass) and (defined $delta) and (defined $mode) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
328 my $url = 'http://www.hmdb.ca/spectra/spectra/ms/search?utf8=TRUE&query_masses='.$mass.'&tolerance='.$delta.'&mode='.$mode.'&commit=Search' ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
329
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
330 # print $url."\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
331
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
332 my $oUrl = url($url);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
333 $page = get($oUrl);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
334 # print $page."\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
335
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
336 ## manage output
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
337 if ( ( !defined $page ) or ( $page eq "" ) ) { die "Problem to connect to HMDB, page empty or undefined.\n" ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
338 else { @pages = split(/\n/, $page); }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
339 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
340 return(\@pages) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
341 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
342 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
343
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
344 =head2 METHOD get_matches_from_hmdb_ua
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
345
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
346 ## Description : permet de requeter via un user agent sur hmdb avec une masse, un delta de masse sur la banque de metabolites hmdb
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
347 ## Input : $mass, $delta, $mode
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
348 ## Output : $results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
349 ## Usage : my ( $results ) = get_matches_from_hmdb( $mass, $delta, $mode ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
350
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
351 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
352 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
353 sub get_matches_from_hmdb_ua {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
354 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
355 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
356 my ( $masses, $delta, $mode ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
357
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
358 my @page = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
359
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
360 my $ua = new LWP::UserAgent;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
361 $ua->agent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36");
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
362
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
363 my $req = HTTP::Request->new(
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
364 POST => 'http://specdb.wishartlab.com/ms/search.csv');
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
365
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
366 $req->content_type('application/x-www-form-urlencoded');
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
367 $req->content('utf8=TRUE&mode='.$mode.'&query_masses='.$masses.'&tolerance='.$delta.'&database=HMDB&commit=Download Results As CSV');
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
368
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
369 my $res = $ua->request($req);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
370 # print $res->as_string;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
371 @page = split ( /\n/, $res->decoded_content ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
372
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
373 return (\@page) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
374 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
375 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
376
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
377
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
378
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
379 =head2 METHOD parse_hmdb_csv_results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
380
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
381 ## Description : parse the csv results and get data
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
382 ## Input : $csv
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
383 ## Output : $results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
384 ## Usage : my ( $results ) = parse_hmdb_csv_results( $csv ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
385
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
386 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
387 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
388 sub parse_hmdb_csv_results {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
389 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
390 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
391 my ( $csv, $masses ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
392
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
393 my $test = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
394 my ($query_mass,$compound_id,$formula,$compound_mass,$adduct,$adduct_type,$adduct_mass,$delta) = (0, undef, undef, undef, undef, undef, undef, undef) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
395
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
396 my %result_by_entry = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
397 my %features = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
398
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
399 foreach my $line (@{$csv}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
400
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
401 if ($line !~ /query_mass,compound_id,formula,compound_mass,adduct,adduct_type,adduct_mass,delta/) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
402 my @entry = split(/,/, $line) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
403
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
404 if ( !exists $result_by_entry{$entry[0]} ) { $result_by_entry{$entry[0]} = [] ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
405
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
406 $features{ENTRY_ENTRY_ID} = $entry[1] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
407 $features{ENTRY_FORMULA} = $entry[2] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
408 $features{ENTRY_CPD_MZ} = $entry[3] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
409 $features{ENTRY_ADDUCT} = $entry[4] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
410 $features{ENTRY_ADDUCT_TYPE} = $entry[5] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
411 $features{ENTRY_ADDUCT_MZ} = $entry[6] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
412 $features{ENTRY_DELTA} = $entry[7] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
413
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
414 my %temp = %features ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
415
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
416 push (@{$result_by_entry{$entry[0]} }, \%temp) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
417 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
418 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
419 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
420 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
421 } ## end foreach
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
422
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
423 ## manage per query_mzs (keep query masses order by array)
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
424 my @results = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
425 foreach (@{$masses}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
426 if ($result_by_entry{$_}) { push (@results, $result_by_entry{$_}) ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
427 else {push (@results, [] ) ;} ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
428 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
429 return(\@results) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
430 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
431 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
432
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
433 =head2 METHOD parse_hmdb_page_results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
434
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
435 ## Description : permet de parser le contenu des resultats hmdb
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
436 ## Input : $page
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
437 ## Output : $results
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
438 ## Usage : my ( $results ) = parse_hmdb_page_result( $pages ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
439
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
440 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
441 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
442 sub parse_hmdb_page_results {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
443 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
444 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
445 my ( $page ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
446
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
447 my @results = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
448 my ($catch_table, $catch_name) = (0, 0) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
449 my ($name, $adduct, $adduct_mw, $cpd_mw, $delta) = (undef, undef, undef, undef, undef) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
450
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
451 if ( defined $page ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
452
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
453 my @page = @{$page} ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
454 my $ID = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
455 my @result_by_mz = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
456 my %result_by_entry = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
457
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
458 foreach my $line (@page) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
459
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
460 #Section de la page contenant les resultat
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
461 if( $line =~/<table>/ ) { $catch_table = 1 ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
462
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
463 ## Si il existe un resultat :
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
464 if($catch_table == 1) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
465
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
466 #Id de la molecule, et creation du lien
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
467 if( $line =~ /<a href=\"\/metabolites\/(\w+)\" (.*)>/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
468 $ID = $1 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
469 $catch_name = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
470 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
471 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
472 #Nom de la molecule ONLY!!
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
473 if ( $catch_name == 0 ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
474
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
475 if( $line =~ /<td>(.+)<\/td>/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
476
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
477 if ( !defined $name ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
478 $name = $1 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
479 $result_by_entry{'ENTRY_ENTRY_ID'} = $ID ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
480 $result_by_entry{'ENTRY_NAME'} = $name ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
481 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
482 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
483 if ( !defined $adduct ) { $adduct = $1 ; $result_by_entry{'ENTRY_ADDUCT'} = $adduct ; next ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
484 if ( !defined $adduct_mw ) { $adduct_mw = $1 ; $result_by_entry{'ENTRY_ADDUCT_MZ'} = $adduct_mw ; next ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
485 if ( !defined $cpd_mw ) { $cpd_mw = $1 ; $result_by_entry{'ENTRY_CPD_MZ'} = $cpd_mw ; next ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
486 if ( !defined $delta ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
487 $delta = $1 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
488 $result_by_entry{'ENTRY_DELTA'} = $delta ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
489 $catch_name = 1 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
490 my %tmp = %result_by_entry ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
491 push (@result_by_mz, \%tmp) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
492 %result_by_entry = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
493 ( $name, $cpd_mw, $delta, $adduct, $adduct_mw ) = ( undef, undef, undef, undef, undef ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
494 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
495 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
496 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
497 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
498 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
499 #Fin de la section contenant les resultats
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
500 if( $line =~ /<\/table>/ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
501 $catch_table = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
502 my @Tmp = @result_by_mz ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
503 push(@results, \@Tmp) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
504 @result_by_mz = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
505 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
506 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
507 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
508 return(\@results) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
509 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
510 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
511
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
512 =head2 METHOD set_html_tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
513
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
514 ## Description : initializes and build the tbody object (perl array) need to html template
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
515 ## Input : $nb_pages, $nb_items_per_page
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
516 ## Output : $tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
517 ## Usage : my ( $tbody_object ) = set_html_tbody_object($nb_pages, $nb_items_per_page) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
518
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
519 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
520 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
521 sub set_html_tbody_object {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
522 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
523 my ( $nb_pages, $nb_items_per_page ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
524
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
525 my ( @tbody_object ) = ( ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
526
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
527 for ( my $i = 1 ; $i <= $nb_pages ; $i++ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
528
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
529 my %pages = (
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
530 # tbody feature
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
531 PAGE_NB => $i,
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
532 MASSES => [], ## end MASSES
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
533 ) ; ## end TBODY N
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
534 push (@tbody_object, \%pages) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
535 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
536 return(\@tbody_object) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
537 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
538 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
539
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
540 =head2 METHOD add_mz_to_tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
541
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
542 ## Description : initializes and build the mz object (perl array) need to html template
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
543 ## Input : $tbody_object, $nb_items_per_page, $mz_list
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
544 ## Output : $tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
545 ## Usage : my ( $tbody_object ) = add_mz_to_tbody_object( $tbody_object, $nb_items_per_page, $mz_list ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
546
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
547 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
548 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
549 sub add_mz_to_tbody_object {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
550 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
551 my ( $tbody_object, $nb_items_per_page, $mz_list, $ids_list ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
552
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
553 my ( $current_page, $mz_index ) = ( 0, 0 ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
554
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
555 foreach my $page ( @{$tbody_object} ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
556
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
557 my @colors = ('white', 'green') ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
558 my ( $current_index, , $icolor ) = ( 0, 0 ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
559
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
560 for ( my $i = 1 ; $i <= $nb_items_per_page ; $i++ ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
561 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
562 if ( $current_index > $nb_items_per_page ) { ## manage exact mz per html page
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
563 $current_index = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
564 last ; ##
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
565 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
566 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
567 $current_index++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
568 if ( $icolor > 1 ) { $icolor = 0 ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
569
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
570 if ( exists $mz_list->[$mz_index] ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
571
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
572 my %mz = (
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
573 # mass feature
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
574 MASSES_ID_QUERY => $ids_list->[$mz_index],
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
575 MASSES_MZ_QUERY => $mz_list->[$mz_index],
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
576 MZ_COLOR => $colors[$icolor],
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
577 MASSES_NB => $mz_index+1,
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
578 ENTRIES => [] ,
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
579 ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
580 push ( @{ $tbody_object->[$current_page]{MASSES} }, \%mz ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
581 # Html attr for mass
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
582 $icolor++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
583 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
584 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
585 $mz_index++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
586 } ## foreach mz
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
587
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
588 $current_page++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
589 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
590 return($tbody_object) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
591 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
592 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
593
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
594 =head2 METHOD add_entries_to_tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
595
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
596 ## Description : initializes and build the mz object (perl array) need to html template
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
597 ## Input : $tbody_object, $nb_items_per_page, $mz_list, $entries
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
598 ## Output : $tbody_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
599 ## Usage : my ( $tbody_object ) = add_entries_to_tbody_object( $tbody_object, $nb_items_per_page, $mz_list, $entries ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
600
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
601 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
602 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
603 sub add_entries_to_tbody_object {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
604 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
605 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
606 my ( $tbody_object, $nb_items_per_page, $mz_list, $entries ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
607
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
608 my $index_page = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
609 my $index_mz_continous = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
610
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
611 foreach my $page (@{$tbody_object}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
612
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
613 my $index_mz = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
614
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
615 foreach my $mz (@{ $tbody_object->[$index_page]{MASSES} }) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
616
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
617 my $index_entry = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
618
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
619 my @anti_redondant = ('N/A') ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
620 my $check_rebond = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
621
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
622 foreach my $entry (@{ $entries->[$index_mz_continous] }) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
623
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
624 ## dispo anti doublons des entries
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
625 foreach my $rebond (@anti_redondant) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
626 if ( $rebond eq $entries->[$index_mz_continous][$index_entry]{ENTRY_ENTRY_ID} ) { $check_rebond = 1 ; last ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
627 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
628
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
629 if ( $check_rebond == 0 ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
630
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
631 push ( @anti_redondant, $entries->[$index_mz_continous][$index_entry]{ENTRY_ENTRY_ID} ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
632
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
633 my %entry = (
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
634 ENTRY_COLOR => $tbody_object->[$index_page]{MASSES}[$index_mz]{MZ_COLOR},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
635 ENTRY_ENTRY_ID => $entries->[$index_mz_continous][$index_entry]{ENTRY_ENTRY_ID},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
636 ENTRY_ENTRY_ID2 => $entries->[$index_mz_continous][$index_entry]{ENTRY_ENTRY_ID},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
637 ENTRY_FORMULA => $entries->[$index_mz_continous][$index_entry]{ENTRY_FORMULA},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
638 ENTRY_CPD_MZ => $entries->[$index_mz_continous][$index_entry]{ENTRY_CPD_MZ},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
639 ENTRY_ADDUCT => $entries->[$index_mz_continous][$index_entry]{ENTRY_ADDUCT},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
640 ENTRY_ADDUCT_TYPE => $entries->[$index_mz_continous][$index_entry]{ENTRY_ADDUCT_TYPE},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
641 ENTRY_ADDUCT_MZ => $entries->[$index_mz_continous][$index_entry]{ENTRY_ADDUCT_MZ},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
642 ENTRY_DELTA => $entries->[$index_mz_continous][$index_entry]{ENTRY_DELTA},
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
643 ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
644
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
645 push ( @{ $tbody_object->[$index_page]{MASSES}[$index_mz]{ENTRIES} }, \%entry) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
646 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
647 $check_rebond = 0 ; ## reinit double control
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
648 $index_entry++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
649 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
650 $index_mz ++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
651 $index_mz_continous ++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
652 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
653 $index_page++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
654 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
655 return($tbody_object) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
656 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
657 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
658
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
659 =head2 METHOD write_html_skel
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
660
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
661 ## Description : prepare and write the html output file
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
662 ## Input : $html_file_name, $html_object, $html_template
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
663 ## Output : $html_file_name
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
664 ## Usage : my ( $html_file_name ) = write_html_skel( $html_file_name, $html_object ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
665
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
666 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
667 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
668 sub write_html_skel {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
669 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
670 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
671 my ( $html_file_name, $html_object, $pages , $search_condition, $html_template, $js_path, $css_path ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
672
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
673 my $html_file = $$html_file_name ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
674
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
675 if ( defined $html_file ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
676 open ( HTML, ">$html_file" ) or die "Can't create the output file $html_file " ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
677
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
678 if (-e $html_template) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
679 my $ohtml = HTML::Template->new(filename => $html_template);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
680 $ohtml->param( JS_GALAXY_PATH => $js_path, CSS_GALAXY_PATH => $css_path ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
681 $ohtml->param( CONDITIONS => $search_condition ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
682 $ohtml->param( PAGES_NB => $pages ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
683 $ohtml->param( PAGES => $html_object ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
684 print HTML $ohtml->output ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
685 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
686 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
687 croak "Can't fill any html output : No template available ($html_template)\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
688 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
689
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
690 close (HTML) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
691 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
692 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
693 croak "No output file name available to write HTML file\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
694 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
695 return(\$html_file) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
696 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
697 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
698
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
699 =head2 METHOD set_lm_matrix_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
700
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
701 ## Description : build the bih_row under its ref form
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
702 ## Input : $header, $init_mzs, $col_mzdb, $results, $rts, $col_rtdb, $bank_head, $sep
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
703 ## Output : $hmdb_matrix
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
704 ## Usage : my ( $hmdb_matrix ) = set_lm_matrix_object( $header, $init_mzs, $col_mzdb, $results, $rts, $col_rtdb, $bank_head, $sep ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
705
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
706 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
707 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
708 sub set_lm_matrix_object {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
709 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
710 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
711 my ( $header, $init_mzs, $col_mzdb, $results, $rts, $col_rtdb, $bank_head, $sep ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
712
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
713 my @bih_matrix = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
714
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
715 if ( defined $header ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
716 my @headers = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
717 push @headers, $header ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
718 push @bih_matrix, \@headers ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
719 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
720
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
721 my $index_mz = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
722 $col_mzdb -= 1; $col_rtdb -= 1; ## conversion in array number
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
723
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
724 foreach my $mz ( @{$init_mzs} ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
725
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
726 my $index_entries = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
727 my @clusters = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
728 my $cluster_col = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
729
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
730 foreach my $entry (@{ $results->[$index_mz] }) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
731
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
732 my $format_float = Math::BigFloat->new($entry->[$col_mzdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
733 my $delta_mz = abs( $format_float-$mz ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
734 # manage final pipe
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
735 if ($index_entries == 0){ $cluster_col .= $delta_mz.$sep.$entry->[$col_mzdb].$sep ; } ## Managing multiple results transition pipes "|"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
736 else{ $cluster_col .= '|'.$delta_mz.$sep.$entry->[$col_mzdb].$sep ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
737
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
738 if ( ( defined $rts ) and ( $rts ne "" ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
739 my $rt = $rts->[$index_mz] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
740 my $format_float_rt = Math::BigFloat->new($entry->[$col_rtdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
741 my $delta_rt = abs( $format_float_rt-$rt ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
742 $cluster_col .= $delta_rt.$sep.$entry->[$col_rtdb].$sep;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
743 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
744 for (my $i=0; $i<=$#$entry; $i++){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
745 if($i == $#$entry){ $cluster_col .= $entry->[$i]; } ## Managing multiple results transition "#"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
746 else { $cluster_col .= $entry->[$i].$sep; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
747 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
748 $index_entries++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
749 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
750 if ( !defined $cluster_col ) { $cluster_col = 'No_result_found_in_bank_inhouse' ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
751
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
752 ## $cluster_col like METLIN data display model but the "::" have been modified (#) for ease of Excel reading
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
753 ## entry1=VAR1::VAR2::VAR3::VAR4|entry2=VAR1::VAR2::VAR3::VAR4|...
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
754 push (@clusters, $cluster_col) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
755 push (@bih_matrix, \@clusters) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
756 $index_mz++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
757 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
758 return(\@bih_matrix) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
759 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
760 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
761
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
762 =head2 METHOD add_lm_matrix_to_input_matrix
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
763
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
764 ## Description : build a full matrix (input + lm column)
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
765 ## Input : $input_matrix_object, $lm_matrix_object, $nb_header
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
766 ## Output : $output_matrix_object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
767 ## Usage : my ( $output_matrix_object ) = add_lm_matrix_to_input_matrix( $input_matrix_object, $lm_matrix_object, $nb_header ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
768
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
769 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
770 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
771 sub add_lm_matrix_to_input_matrix {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
772 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
773 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
774 my ( $input_matrix_object, $lm_matrix_object, $nb_header ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
775
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
776 my @output_matrix_object = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
777 my $index_row = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
778 my $line = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
779
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
780 foreach my $row ( @{$input_matrix_object} ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
781 my @init_row = @{$row} ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
782 $line++;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
783
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
784 if ( ( defined $nb_header ) and ( $line <= $nb_header) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
785 push (@output_matrix_object, \@init_row) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
786 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
787 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
788
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
789 if ( $lm_matrix_object->[$index_row] ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
790 my $dim = scalar(@{$lm_matrix_object->[$index_row]}) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
791
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
792 if ($dim > 1) { warn "the add method can't manage more than one column\n" ;}
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
793 if (defined $lm_matrix_object->[$index_row][$dim-1]) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
794 my $lm_col = $lm_matrix_object->[$index_row][$dim-1] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
795 push (@init_row, $lm_col) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
796 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
797
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
798 $index_row++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
799 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
800 push (@output_matrix_object, \@init_row) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
801 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
802 return(\@output_matrix_object) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
803 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
804 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
805
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
806 =head2 METHOD write_csv_skel
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
807
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
808 ## Description : prepare and write csv output file
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
809 ## Input : $csv_file, $rows
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
810 ## Output : $csv_file
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
811 ## Usage : my ( $csv_file ) = write_csv_skel( $csv_file, $rows ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
812
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
813 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
814 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
815 sub write_csv_skel {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
816 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
817 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
818 my ( $csv_file, $rows ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
819
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
820 my $ocsv = lib::csv::new() ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
821 my $csv = $ocsv->get_csv_object("\t") ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
822 $ocsv->write_csv_from_arrays($csv, $$csv_file, $rows) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
823
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
824 return($csv_file) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
825 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
826 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
827
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
828
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
829 =head2 METHOD write_full_excel_like
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
830
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
831 ## Description : allows to print a tsv file
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
832 ## Input : $input_matrix_object, $sep, $masses, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $nb_header, $bank_head, $bank_name
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
833 ## Output : N/A
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
834 ## Usage : write_full_excel_like( $input_matrix_object, $sep, $masses, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $nb_header, $bank_head, $bank_name ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
835
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
836 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
837 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
838 sub write_full_excel_like {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
839 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
840 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
841 my ( $input_matrix_object, $sep, $masses, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $nb_header, $bank_head, $bank_name ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
842
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
843 open(CSV, '>:utf8', $file) or die "Cant' create the file $file\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
844
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
845 my $line = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
846 my $index_mz = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
847 $col_mzdb -= 1; $col_rtdb -= 1; ## conversion in array number
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
848
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
849 foreach my $row ( @{$input_matrix_object} ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
850 my $join_row = join($sep, @$row);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
851
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
852 if ( defined $nb_header ){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
853 $line++;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
854 if ( $line < $nb_header ) { print CSV $join_row."\n"; next ; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
855 elsif ( $line == $nb_header ){
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
856 my $head = join("_".$bank_name.$sep, @$bank_head);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
857 print CSV $join_row.$sep.$head."_".$bank_name."\n";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
858 next ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
859 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
860 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
861
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
862 my $mass = $masses->[$index_mz] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
863 my $results4mass = $results->[$index_mz];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
864
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
865 if ( ref($results4mass) eq 'ARRAY' and defined $results4mass and $results4mass ne [] and $#$results4mass>=0) { ## an requested id has a result in the list of array $results.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
866 foreach my $entry (@{$results->[$index_mz]}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
867 print CSV $join_row."\t";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
868 my $format_float = Math::BigFloat->new($entry->[$col_mzdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
869 my $delta_mass = abs( $format_float-$mass ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
870 print CSV $delta_mass."\t".$entry->[$col_mzdb];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
871
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
872 if ( ( defined $rts ) and ( $rts ne "" ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
873 my $rt = $rts->[$index_mz] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
874 my $format_float_rt = Math::BigFloat->new($entry->[$col_rtdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
875 my $delta_rt = abs( $format_float_rt-$rt ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
876 print CSV "\t".$rt."\t".$delta_rt."\t".$entry->[$col_rtdb];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
877 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
878 for (my $i=0; $i<=$#$entry; $i++){ print CSV "\t".$entry->[$i]; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
879 print CSV "\n";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
880 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
881 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
882 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
883 print CSV $join_row."\tno results found";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
884 for (my $i=0; $i<$#$bank_head; $i++){ print CSV "\t"; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
885 print CSV "\n";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
886 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
887 $index_mz++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
888 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
889 close(CSV) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
890 return() ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
891 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
892 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
893
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
894
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
895 =head2 METHOD write_excel_like_mass
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
896
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
897 ## Description : allows to print a tsv file if retention time is required
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
898 ## Input : $masses, $ids, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $bank_head
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
899 ## Output : N/A
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
900 ## Usage : write_excel_like_mass( $masses, $ids, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $bank_head ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
901 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
902 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
903 sub write_excel_like_mass {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
904 ## Retrieve Values
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
905 my $self = shift ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
906 my ( $masses, $mz_delta_type, $mz_delta, $col_mzdb, $rts, $rt_delta, $col_rtdb, $results, $file, $out_head ) = @_ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
907
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
908 open(CSV, '>:utf8', $file) or die "Cant' create the file $file\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
909
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
910 my $index_mz = 0 ; my @bank_head = @$out_head;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
911 $col_mzdb -= 1; ## conversion in array number
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
912 if ( ( defined $rts ) and ( $rts ne "" ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
913 splice (@bank_head, 2, 0, "RT_Submit");
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
914 $col_rtdb -= 1; ## conversion in array number
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
915 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
916 my $head = join("\t", @bank_head);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
917 print CSV "MASS_Submit\t".$head."\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
918
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
919 foreach my $mass (@{$masses}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
920 my $results4mass = $results->[$index_mz];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
921
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
922 if ( ref($results4mass) eq 'ARRAY' and defined $results4mass and $results4mass ne [] and $#$results4mass>=0) { ## an requested id has a result in the list of array $results.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
923 foreach my $entry (@{$results->[$index_mz]}) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
924 print CSV $mass."\t";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
925 my $format_float = Math::BigFloat->new($entry->[$col_mzdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
926 my $delta_mass = abs( $format_float-$mass ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
927 print CSV $delta_mass."\t".$entry->[$col_mzdb];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
928
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
929 if ( ( defined $rts ) and ( $rts ne "" ) ) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
930 my $rt = $rts->[$index_mz] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
931 my $format_float_rt = Math::BigFloat->new($entry->[$col_rtdb]); ## requires "use Math::BigFloat;"
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
932 my $delta_rt = abs( $format_float_rt-$rt ); ## management problem on small float
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
933 print CSV "\t".$rt."\t".$delta_rt."\t".$entry->[$col_rtdb];
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
934 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
935 for (my $i=0; $i<=$#$entry; $i++){ print CSV "\t".$entry->[$i]; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
936 print CSV "\n";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
937 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
938 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
939 else {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
940 print CSV $mass."\tno results found";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
941 for (my $i=0; $i<$#bank_head; $i++){ print CSV "\t"; }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
942 print CSV "\n";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
943 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
944 $index_mz++ ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
945 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
946 close(CSV) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
947 return() ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
948 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
949 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
950
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
951
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
952 =head2 METHOD db_pforest_get_clean_range
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
953
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
954 ## Description : get a clean range of mass from PeakForest and REST
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
955 ## Input : $ws_host, $query, $max
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
956 ## Output : $json
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
957 ## Usage : $json = db_pforest_get_clean_range( $ws_host, $query, $max ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
958 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
959 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
960
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
961
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
962 #sub db_pforest_get_clean_range {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
963 # my $self = shift;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
964 # my ( $ws_host, $query, $min, $max, $mode) = @_;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
965 # my $json = undef ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
966 # # init
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
967 ## my $ws_url = "https://rest.peakforest.org/search/compounds/monoisotopicmass/59.048/0.02";
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
968 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
969 # $ENV{HTTPS_VERSION} = 3;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
970 # #$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
971 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
972 # my $headers = {Accept => 'application/json', Authorization => 'Basic '};
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
973 # my $client = REST::Client->new({
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
974 # host => $ws_host,
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
975 ## cert => '/path/to/ssl.crt',
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
976 ## key => '/path/to/ssl.key',
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
977 ## ca => '/path/to/ca.file',
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
978 # timeout => 100,
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
979 # });
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
980 # my $complete_query = $query.'/'.$min.'/'.$max ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
981 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
982 # if (defined $mode) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
983 # $complete_query = $complete_query.'?mode='.$mode ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
984 # }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
985 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
986 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
987 # print $complete_query."\n" ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
988 # $client->GET($complete_query , $headers);
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
989 # $json = from_json ($client->responseContent()) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
990 #
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
991 # return ($json) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
992 #}
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
993
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
994 =head2 METHOD map_pfjson_bankobject
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
995
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
996 ## Description : map PForest json with the original BiH Bank object
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
997 ## Input : $json
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
998 ## Output : $complete_bank, $bank_head
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
999 ## Usage : ($complete_bank, $bank_heads) = map_pfjson_bankobject( json ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1000 =cut
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1001 ## START of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1002 sub map_pfjson_bankobject {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1003 my $self = shift;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1004 my ( $json ) = @_;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1005
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1006 my ( %complete_bank ) = () ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1007 my ( @bank_head ) = ('id', 'mz') ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1008
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1009 foreach my $cpd (@$json) {
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1010 $complete_bank{$cpd->{'mz'}} = [] ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1011 my @tmp = @{$cpd->{'cpds'}} ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1012
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1013 push ( @tmp, $cpd->{'mz'} ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1014 push ( @{ $complete_bank{$cpd->{'mz'} } }, \@tmp ) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1015
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1016 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1017 return (\%complete_bank, \@bank_head) ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1018 }
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1019 ## END of SUB
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1020
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1021 1 ;
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1022
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1023
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1024 __END__
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1025
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1026 =head1 SUPPORT
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1027
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1028 You can find documentation for this module with the perldoc command.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1029
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1030 perldoc bih.pm
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1031
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1032 =head1 Exports
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1033
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1034 =over 4
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1035
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1036 =item :ALL is prepare_multi_masses_query
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1037
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1038 =back
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1039
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1040 =head1 AUTHOR
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1041
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1042 Marion Landi E<lt>marion.landi@clermont.inra.frE<gt>
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1043
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1044 =head1 LICENSE
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1045
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1046 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1047
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1048 =head1 VERSION
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1049
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1050 version 1 : 19 / 11 / 2014
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1051
be582bcd6585 Master branch Updating - - Fxx
fgiacomoni
parents:
diff changeset
1052 =cut