annotate lib/hr.pm @ 0:86296c048e46 draft

Init repository for [hr2]
author fgiacomoni
date Wed, 05 Jun 2019 09:40:20 -0400
parents
children e2cbcf6fa22e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
1 package lib::hr ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
2
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
3 use strict;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
4 no strict "refs" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
5 use warnings ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
6 use Exporter ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
7 use threads ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
8 use HTML::Template ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
9 use Carp ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
10
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
11 use Data::Dumper ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
12
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
13 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
14
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
15 our $VERSION = "1.0";
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
16 our @ISA = qw(Exporter);
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
17 our @EXPORT = qw( manage_atoms_and_ranges manage_atoms check_hr_exe manage_atom_and_range manage_tolerance manage_mode config_hr_exe );
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
18 our %EXPORT_TAGS = ( ALL => [qw(manage_atoms_and_ranges manage_atoms check_hr_exe manage_atom_and_range manage_tolerance manage_mode config_hr_exe )] );
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
19
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
20 =head1 NAME
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
21
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
22 lib::hr - A module for managing / launching hr binary (structure elucidation c++ progr)
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
23
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
24 =head1 SYNOPSIS
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
25
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
26 use lib::hr;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
27 my $object = lib::hr->new();
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
28 print $object->as_string;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
29
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
30 =head1 DESCRIPTION
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
31
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
32 This module does not really exist, it
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
33 was made for the sole purpose of
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
34 demonstrating how POD works.
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
35
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
36 =head1 METHODS
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
37
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
38 Methods are :
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
39
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
40 =head2 METHOD new
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
41
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
42 ## Description : new
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
43 ## Input : $self
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
44 ## Ouput : bless $self ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
45 ## Usage : new() ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
46
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
47 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
48
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
49 sub new {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
50 ## Variables
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
51 my $self={};
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
52 bless($self) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
53 return $self ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
54 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
55 ### END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
56
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
57 =head2 METHOD manage_atoms_and_ranges
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
58
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
59 ## Description : allow from an initial config to add or delete atoms and their range
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
60 ## Input : $atomsconfig, $atombasic, $atomsupp
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
61 ## Output : $atomcleanconfig
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
62 ## Usage : my ( $atomcleanconfig ) = manage_atoms_and_ranges ( $atomsconfig, $atombasic, $atomsupp ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
63
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
64 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
65 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
66 sub manage_atoms_and_ranges {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
67 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
68 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
69 my ( $atomsconfig, $CONF, $atombasic, $atomsupp ) = @_;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
70 my ( $atomcleanconfig ) = ( undef ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
71
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
72 # basic atoms case:
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
73 foreach my $atom ( (split(",", $atombasic )) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
74 if ( exists $CONF->{$atom} ) { $atomsconfig->{$atom}{'max'} = $CONF->{$atom} ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
75 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
76
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
77 # suppl. atoms case
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
78 foreach my $atom ( (split(",", $atomsupp )) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
79 print "*** $atom***\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
80 if ( exists $atomsconfig->{$atom} ) { $atomsconfig->{$atom} = $CONF->{'DEFAULT_MAX'} ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
81 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
82
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
83 # Create atoms and range parameters:
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
84 foreach my $selectedAtom ( keys %{$atomsconfig} ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
85 $atomcleanconfig .= ' -'.$selectedAtom.' '.$atomsconfig->{$selectedAtom}{'min'}.'-'.$atomsconfig->{$selectedAtom}{'max'} ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
86 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
87
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
88 return ($atomcleanconfig) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
89 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
90 ### END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
91
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
92
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
93
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
94 =head2 METHOD manage_atoms ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
95
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
96 ## Description : controles atoms input list and prepare it like hr binary parameter
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
97 ## Input : $input_atoms, $conf_atoms
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
98 ## Output : $hr_atoms_param
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
99 ## Usage : my ( $hr_atoms_param ) = manage_atoms( $input_atoms, $conf_atoms ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
100 ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
101
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
102 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
103 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
104 sub manage_atoms { ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
105 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
106 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
107 my ( $input_atoms, $conf_atoms ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
108 my $hr_atoms_param = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
109
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
110 if ( ( defined $$input_atoms ) and ( defined $$conf_atoms ) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
111 if ( ( $$input_atoms eq 'None' ) or ( $$input_atoms eq '' ) or ( $$input_atoms eq ' ' ) ) { $hr_atoms_param = $$conf_atoms ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
112 elsif ( $$input_atoms =~ /[P|S|F|L|K|B|A|1|,]+/ ) { $hr_atoms_param = $$conf_atoms.','.$$input_atoms ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
113 else { $hr_atoms_param = $$conf_atoms ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
114 } ## END IF
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
115 elsif ( !defined $$input_atoms ) { $hr_atoms_param = $$conf_atoms ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
116 elsif ( !defined $$conf_atoms ) { warn "hr module can't manage any atom list (undef values in conf)\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
117 else { warn "hr module musn't manage any atom list\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
118
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
119 return(\$hr_atoms_param) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
120 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
121 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
122
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
123 =head2 METHOD manage_atom_and_range ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
124
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
125 ## Description : build atom range with defined value in conf file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
126 ## Input : $atom, $min, $max
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
127 ## Output : $hr_range
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
128 ## Usage : my ( ) = manage_atom_and_range( $atom, $min, $max ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
129 ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
130
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
131 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
132 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
133 sub manage_atom_and_range { ### DEPRECATED
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
134 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
135 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
136 my ( $atom, $min, $max ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
137 my $hr_range = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
138
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
139 if ( ( defined $$atom ) and ( defined $$min ) and ( defined $$max ) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
140 ## manage ragne like "-C 0-200"
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
141 $hr_range = ' -'.$$atom.' '.$$min.'-'.$$max ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
142 } ## END IF
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
143 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
144 warn "Some argvts are missing to build the current atom range line\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
145 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
146 return(\$hr_range) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
147 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
148 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
149
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
150 =head2 METHOD manage_tolerance
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
151
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
152 ## Description : check range and format of tolerance
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
153 ## Input : $tolerance, $default_value
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
154 ## Output : $set_tol
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
155 ## Usage : my ( $set_tol ) = manage_tolerance( $tolerance, $default_value ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
156
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
157 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
158 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
159 sub manage_tolerance {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
160 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
161 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
162 my ( $tolerance, $default_value ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
163 my ($set_tol, $tmp_tol ) = (undef, undef) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
164
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
165 if ( ( defined $$tolerance ) and ( defined $$default_value )) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
166 $tmp_tol = $$tolerance ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
167 $tmp_tol =~ tr/,/./;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
168 ## tolerance doit etre >0 et <10
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
169 if ( $tmp_tol <= 0 || $tmp_tol >= 10 ){
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
170 $set_tol = $$default_value ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
171 warn "The used tolerance is set to $$default_value (out of authorized range)\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
172 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
173 else{ $set_tol = $tmp_tol ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
174 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
175 else { warn "Your tolerance or the default tol are not defined\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
176
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
177 return(\$set_tol) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
178 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
179 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
180
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
181 =head2 METHOD manage_mode
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
182
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
183 ## Description : manage mode and apply mass correction (positive/negative/neutral)
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
184 ## Input : $mode, $charge, $electron, $proton, $mass
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
185 ## Output : $exact_mass
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
186 ## Usage : my ( $exact_mass ) = manage_mode( $mode, $charge, $electron, $proton, $mass ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
187
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
188 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
189 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
190 sub manage_mode {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
191 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
192 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
193 my ( $mode, $charge, $electron, $proton, $mass ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
194 my ($exact_mass, $tmp_mass) = ( undef, undef ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
195
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
196 ## some explanations :
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
197 # MS in + mode = adds H+ (proton) and molecule is positive : el+ => $charge = "positive"
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
198 # For HR, need to subtrack proton mz and to add electron mz (1 electron per charge) to the input mass which comes neutral!
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
199
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
200 if ( ( defined $$electron ) and ( defined $$proton ) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
201 # check mass
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
202 if ( defined $$mass ) { $tmp_mass = $$mass ; $tmp_mass =~ tr/,/./ ; } # manage . and , in case of...
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
203 else { warn "No mass is defined\n" }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
204
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
205 # manage charge
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
206 if ( ( !defined $$charge ) || ($$charge < 0) ){ warn "Charge is not defined or value is less than zero\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
207
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
208 # set neutral mass in function of ms mode
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
209 if($$mode eq 'positive') { $exact_mass = ( $tmp_mass - $$proton + $$electron) * $$charge ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
210 elsif($$mode eq 'negative') { $exact_mass = ( $tmp_mass + $$proton - $$electron) * $$charge ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
211 elsif($$mode eq "neutral") { $exact_mass = $tmp_mass ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
212 else { warn "This mode doesn't exist : please select positive/negative or neutral mode\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
213 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
214 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
215 warn "Missing some parameter values (electron, neutron masses), please check your conf file\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
216 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
217 return(\$exact_mass) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
218 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
219 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
220
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
221 =head2 METHOD check_hr_exe
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
222
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
223 ## Description : permit to check the path of hr.exe and its full availability
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
224 ## Input : $hr_path, $hr_version
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
225 ## Output : true/false
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
226 ## Usage : my ( $res ) = check_hr_exe( $hr_path, $hr_version ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
227
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
228 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
229 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
230 sub check_hr_exe {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
231 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
232 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
233 my ( $hr_path, $hr_version ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
234 my $success = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
235 my $check_res = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
236
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
237 ## test path :
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
238 if ( ( defined $$hr_path ) and ( defined $$hr_version ) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
239 if ( defined $$hr_path ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
240 $success = `$$hr_path -version`;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
241 print "$success\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
242 if ($success !~/^$$hr_version/) { warn "You do not use the expected version of hr2 ($$hr_version)\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
243 else { $check_res = 1 ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
244 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
245 else { warn "Can't use HR because the binary file doesn't exist at the specified path ($$hr_path)\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
246
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
247 } ## END IF
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
248 else { warn "No HR path or Hr version defined\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
249
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
250 return($check_res) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
251 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
252 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
253
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
254 =head2 METHOD config_hr_exe
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
255
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
256 ## Description : builds hr execute line with needed params
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
257 ## Input : $hr_path, $hr_delta, $mass, $has_goldenrules, $atoms_and_ranks
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
258 ## Output : var2
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
259 ## Usage : my ( var2 ) = config_hr_exe( $hr_path, $hr_delta, $mass, $has_goldenrules, $atoms_and_ranks ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
260
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
261 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
262 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
263 sub config_hr_exe {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
264 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
265 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
266 my ( $hr_path, $hr_delta, $mass, $has_goldenrules, $atoms_and_ranks ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
267 my $hr_cmd = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
268
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
269 if ( ( defined $$hr_path ) and ( defined $$hr_delta ) and ( defined $$mass ) and ( defined $$atoms_and_ranks ) ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
270 $hr_cmd = $$hr_path.' -t '.$$hr_delta.' -m '.$$mass.' '.$$atoms_and_ranks ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
271 if ( defined $$has_goldenrules ) { $$hr_cmd .= ' -g ' ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
272 } ## END IF
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
273 else { warn "Some argvts are missing to build the current hr exec line\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
274
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
275 return(\$hr_cmd) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
276 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
277 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
278
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
279 =head2 METHOD threading_hr_exe
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
280
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
281 ## Description : prepare 5 threads for hr executing
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
282 ## Input : $method, $list
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
283 ## Output : $results
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
284 ## Usage : my ( $results ) = threading_hr_exe( $method, $list ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
285
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
286 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
287 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
288 sub threading_hr_exe {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
289 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
290 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
291 my ( $method, $list ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
292
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
293 my @results = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
294
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
295 if ( ( defined $list ) and ( defined $method )) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
296
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
297 for (my $i = 0; $i < (scalar @{$list}); $i+=6 ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
298 my $thr1 = threads->create($method, $self, $list->[$i]) if $list->[$i] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
299 my $thr2 = threads->create($method, $self, $list->[$i+1]) if $list->[$i+1] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
300 my $thr3 = threads->create($method, $self, $list->[$i+2]) if $list->[$i+2] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
301 my $thr4 = threads->create($method, $self, $list->[$i+3]) if $list->[$i+3] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
302 my $thr5 = threads->create($method, $self, $list->[$i+4]) if $list->[$i+4] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
303 my $thr6 = threads->create($method, $self, $list->[$i+5]) if $list->[$i+5] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
304 push ( @results, $thr1->join ) if $list->[$i] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
305 push ( @results, $thr2->join ) if $list->[$i+1] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
306 push ( @results, $thr3->join ) if $list->[$i+2] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
307 push ( @results, $thr4->join ) if $list->[$i+3] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
308 push ( @results, $thr5->join ) if $list->[$i+4] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
309 push ( @results, $thr6->join ) if $list->[$i+5] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
310 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
311 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
312 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
313 warn "Your input list or your method is undefined\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
314 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
315
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
316 return(\@results) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
317 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
318 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
319
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
320 =head2 METHOD hr_exe
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
321
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
322 ## Description : hr_exe launches hr and catches result
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
323 ## Input : $cmd
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
324 ## Output : $res
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
325 ## Usage : my ( $res ) = hr_exe( $cmd ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
326
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
327 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
328 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
329 sub hr_exe {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
330 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
331 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
332 my ( $cmd ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
333 my $res = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
334
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
335 if (defined $cmd){
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
336 #print "\n--CMD used : $cmd\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
337 $res = `$cmd` ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
338 sleep(0.5) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
339 #print "Results : $res\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
340 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
341
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
342 return (\$res) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
343 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
344 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
345
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
346
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
347 =head2 METHOD hr_out_parser
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
348
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
349 ## Description : parse output of hr and return a hash of features
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
350 ## Input : $res
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
351 ## Output : $parsed_res
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
352 ## Usage : my ( $parsed_res ) = hr_out_parser( $res ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
353
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
354 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
355 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
356 sub hr_out_parser {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
357 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
358 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
359 my ( $res ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
360
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
361 my %parsed_res = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
362 my ( @formula, @rings_and_double_bond_equivalents, @formula_mz, @mmus ) = ( (), (), (), () ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
363 my ( $formula_nb, $formula_total, $time ) = ( undef, undef, undef ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
364
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
365 if ( defined $$res ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
366 # foreach line
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
367 foreach my $line (split(/\n/,$$res)){
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
368 ## v1.02 - parse result line "C7.H17.N5. 2.0 171.1484 +17.2 mmu"
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
369 ## v1.03 - parse result line "C10.H25.N5.O5.P2.S2. C10H25N5O5P2S2 8.00 421.0772333 0 0 +0.40"
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
370 ## $1 = "C10.H25.N5.O5.P2.S2. " $2 = "C10H25N5O5P2S2" $3 = "8.00" $4="421.0772333" $5="0" $6="0" $7="+0.40"
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
371 ## if ( $line =~ /([\w|\.]+)\s+(\d+.?\d*)\s+(\d+.?\d*)\s+([+|-]\d+.?\d*)\s+(.*)/ ) { ## for hr2 1.02
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
372
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
373 if ( $line =~ /([\w|\.]+)\s+(\w+)\s+(\d+.?\d*)\s+(\d+.?\d*)\s+(\d+.?\d*)\s+(\d+.?\d*)\s+([+|-]\d+.?\d*)/ ) { # for hr2 1.03
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
374 my ( $formula, $cleanformula, $rings_and_double_bond_equivalent, $formula_mz, $abscharge, $nadd, $mmu_value ) = ( $1, $2, $3, $4, $5, $6, $7 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
375
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
376 if (defined $formula ) { $formula =~ s/\.//g ; push (@formula, $formula) ; } # clean \.
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
377 if (defined $rings_and_double_bond_equivalent ) { push (@rings_and_double_bond_equivalents, $rings_and_double_bond_equivalent) ; } #
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
378 if (defined $formula_mz ) { push (@formula_mz, $formula_mz) ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
379 if (defined $mmu_value ) { $mmu_value =~ s/\+// ; push (@mmus, $mmu_value) ; } # clean (+)
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
380 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
381 elsif ( $line =~ /(\d+)\s+formulas.+\s+(\d+)\s+seconds.+\s+(\d+)\s+formulae/ ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
382 ( $formula_nb, $time, $formula_total ) = ( $1, $2, $3 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
383 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
384 else { next; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
385 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
386 # build parser
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
387 if ( scalar(@formula) > 0 ){
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
388 $parsed_res{'ENTRY_FORMULA'} = \@formula ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
389 $parsed_res{'rings_and_double_bond_equivalents'} = \@rings_and_double_bond_equivalents ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
390 $parsed_res{'ENTRY_CPD_MZ'} = \@formula_mz ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
391 $parsed_res{'ENTRY_DELTA'} = \@mmus ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
392 $parsed_res{'MASSES_TOTAL'} = \$formula_nb ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
393 $parsed_res{'time'} = \$time ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
394 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
395 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
396 return(\%parsed_res) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
397 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
398 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
399
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
400
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
401 =head2 METHOD set_html_tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
402
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
403 ## Description : initializes and build the tbody object (perl array) need to html template
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
404 ## Input : $nb_pages, $nb_items_per_page
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
405 ## Output : $tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
406 ## Usage : my ( $tbody_object ) = set_html_tbody_object($nb_pages, $nb_items_per_page) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
407
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
408 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
409 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
410 sub set_html_tbody_object {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
411 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
412 my ( $nb_pages, $nb_items_per_page ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
413
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
414 my ( @tbody_object ) = ( ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
415
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
416 for ( my $i = 1 ; $i <= $nb_pages ; $i++ ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
417
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
418 my %pages = (
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
419 # tbody feature
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
420 PAGE_NB => $i,
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
421 MASSES => [], ## end MASSES
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
422 ) ; ## end TBODY N
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
423 push (@tbody_object, \%pages) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
424 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
425 return(\@tbody_object) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
426 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
427 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
428
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
429 =head2 METHOD add_mz_to_tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
430
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
431 ## Description : initializes and build the mz object (perl array) need to html template
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
432 ## Input : $tbody_object, $nb_items_per_page, $mz_list
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
433 ## Output : $tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
434 ## Usage : my ( $tbody_object ) = add_mz_to_tbody_object( $tbody_object, $nb_items_per_page, $mz_list ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
435
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
436 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
437 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
438 sub add_mz_to_tbody_object {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
439 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
440 my ( $tbody_object, $nb_items_per_page, $mz_list, $ids_list, $totals ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
441
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
442 my ( $current_page, $mz_index ) = ( 0, 0 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
443
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
444 foreach my $page ( @{$tbody_object} ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
445
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
446 my @colors = ('white', 'green') ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
447 my ( $current_index, , $icolor ) = ( 0, 0 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
448
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
449 for ( my $i = 1 ; $i <= $nb_items_per_page ; $i++ ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
450 #
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
451 if ( $current_index > $nb_items_per_page ) { ## manage exact mz per html page
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
452 $current_index = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
453 last ; ##
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
454 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
455 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
456 $current_index++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
457 if ( $icolor > 1 ) { $icolor = 0 ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
458
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
459 if ( exists $mz_list->[$mz_index] ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
460 my $total = \0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
461 if ( $totals->[$mz_index]{'MASSES_TOTAL'} ) { $total = $totals->[$mz_index]{'MASSES_TOTAL'} }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
462
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
463 my %mz = (
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
464 # mass feature
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
465 MASSES_ID_QUERY => $ids_list->[$mz_index],
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
466 MASSES_MZ_QUERY => $mz_list->[$mz_index],
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
467 MZ_COLOR => $colors[$icolor],
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
468 MASSES_NB => $mz_index+1,
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
469 MASSES_TOTAL => $$total ,
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
470 ENTRIES => [] ,
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
471 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
472 push ( @{ $tbody_object->[$current_page]{MASSES} }, \%mz ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
473 # Html attr for mass
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
474 $icolor++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
475 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
476 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
477 $mz_index++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
478 } ## foreach mz
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
479
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
480 $current_page++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
481 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
482 return($tbody_object) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
483 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
484 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
485
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
486 =head2 METHOD add_entries_to_tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
487
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
488 ## Description : initializes and build the mz object (perl array) need to html template
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
489 ## Input : $tbody_object, $nb_items_per_page, $mz_list, $entries
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
490 ## Output : $tbody_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
491 ## Usage : my ( $tbody_object ) = add_entries_to_tbody_object( $tbody_object, $nb_items_per_page, $mz_list, $entries ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
492
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
493 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
494 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
495 sub add_entries_to_tbody_object {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
496 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
497 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
498 my ( $tbody_object, $results ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
499
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
500 my $index_page = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
501 my $index_mz_continous = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
502
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
503 foreach my $page (@{$tbody_object}) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
504
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
505 my $index_mz = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
506
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
507 foreach my $mz (@{ $tbody_object->[$index_page]{MASSES} }) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
508
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
509 my $index_res = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
510 if ( $results->[$index_mz_continous]{ENTRY_FORMULA} ){
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
511
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
512 my $entry_nb = scalar( @{ $results->[$index_mz_continous]{ENTRY_FORMULA} } ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
513 for( my $i = 0 ; $i<$entry_nb; $i++ ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
514 my %entry = (
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
515 ENTRY_COLOR => $tbody_object->[$index_page]{MASSES}[$index_mz]{MZ_COLOR},
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
516 ENTRY_FORMULA => $results->[$index_mz_continous]->{ENTRY_FORMULA}[$i],
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
517 ENTRY_CPD_MZ => $results->[$index_mz_continous]->{ENTRY_CPD_MZ}[$i],
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
518 ENTRY_DELTA => $results->[$index_mz_continous]->{ENTRY_DELTA}[$i]
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
519 ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
520 push ( @{ $tbody_object->[$index_page]{MASSES}[$index_mz]{ENTRIES} }, \%entry) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
521 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
522 $index_res++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
523 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
524 $index_mz ++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
525 $index_mz_continous ++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
526 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
527 $index_page++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
528 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
529 return($tbody_object) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
530 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
531 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
532
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
533 =head2 METHOD write_html_skel
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
534
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
535 ## Description : prepare and write the html output file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
536 ## Input : $html_file_name, $html_object, $html_template
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
537 ## Output : $html_file_name
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
538 ## Usage : my ( $html_file_name ) = write_html_skel( $html_file_name, $html_object ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
539
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
540 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
541 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
542 sub write_html_skel {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
543 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
544 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
545 my ( $html_file_name, $html_object, $pages , $search_condition, $html_template, $js_path, $css_path ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
546
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
547 my $html_file = $$html_file_name ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
548
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
549 if ( defined $html_file ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
550 open ( HTML, ">$html_file" ) or die "Can't create the output file $html_file " ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
551
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
552 if (-e $html_template) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
553 my $ohtml = HTML::Template->new(filename => $html_template);
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
554 $ohtml->param( JS_GALAXY_PATH => $js_path, CSS_GALAXY_PATH => $css_path ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
555 $ohtml->param( CONDITIONS => $search_condition ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
556 $ohtml->param( PAGES_NB => $pages ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
557 $ohtml->param( PAGES => $html_object ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
558 print HTML $ohtml->output ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
559 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
560 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
561 croak "Can't fill any html output : No template available ($html_template)\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
562 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
563
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
564 close (HTML) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
565 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
566 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
567 croak "No output file name available to write HTML file\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
568 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
569 return(\$html_file) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
570 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
571 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
572
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
573 =head2 METHOD write_csv_one_mass
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
574
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
575 ## Description : print a csv file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
576 ## Input : $masses, $ids, $results, $file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
577 ## Output : N/A
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
578 ## Usage : write_csv_one_mass( $ids, $results, $file ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
579
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
580 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
581 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
582 sub write_csv_one_mass {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
583 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
584 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
585 my ( $masses, $ids, $results, $file, ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
586
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
587 open(CSV, '>:utf8', "$file") or die "Cant' create the file $file\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
588 print CSV "ID\tMASS_SUBMIT\tCPD_FORMULA\tCPD_MW\tDELTA\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
589
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
590 my $i = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
591
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
592 foreach my $id (@{$ids}) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
593 my $mass = $masses->[$i] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
594
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
595 if ( $results->[$i] ) { ## an requested id has a result in the list of hashes $results.
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
596
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
597 my $entry_nb = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
598
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
599 ## in case of no results -- Hr_parsed Results : $VAR1 = [ { 'ENTRY_FORMULA' => [] } ];
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
600 if ( !$results->[$i]{'ENTRY_FORMULA'} ) { print CSV "$id\t$mass\tN/A\t0.0\t0.0\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
601
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
602 foreach (@{$results->[$i]{'ENTRY_FORMULA'}}) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
603
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
604 print CSV "$id\t$mass\t" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
605 ## print cpd formula
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
606 if ( $results->[$i]{'ENTRY_FORMULA'}[$entry_nb] ) { print CSV "$results->[$i]{'ENTRY_FORMULA'}[$entry_nb]\t" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
607 else { print CSV "N/A\t" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
608 ## print cpd name
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
609 if ( $results->[$i]{'ENTRY_CPD_MZ'}[$entry_nb] ) { print CSV "$results->[$i]{'ENTRY_CPD_MZ'}[$entry_nb]\t" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
610 else { print CSV "0.0\t" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
611 ## print delta
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
612 if ( $results->[$i]{'ENTRY_DELTA'}[$entry_nb] ) { print CSV "$results->[$i]{'ENTRY_DELTA'}[$entry_nb]\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
613 else { print CSV "0.0\n" ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
614 $entry_nb++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
615 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
616 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
617 else {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
618 print CSV "$id\t$mass\tN/A\t0.0\t0.0\n" ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
619 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
620 $i++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
621 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
622 close(CSV) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
623 return() ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
624 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
625 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
626
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
627 =head2 METHOD add_hr_matrix_to_input_matrix
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
628
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
629 ## Description : build a full matrix (input + lm column)
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
630 ## Input : $input_matrix_object, $lm_matrix_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
631 ## Output : $output_matrix_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
632 ## Usage : my ( $output_matrix_object ) = add_hr_matrix_to_input_matrix( $input_matrix_object, $hr_matrix_object ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
633
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
634 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
635 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
636 sub add_hr_matrix_to_input_matrix {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
637 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
638 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
639 my ( $input_matrix_object, $hr_matrix_object ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
640
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
641 my @output_matrix_object = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
642 my $index_row = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
643
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
644 foreach my $row ( @{$input_matrix_object} ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
645 my @init_row = @{$row} ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
646
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
647 if ( $hr_matrix_object->[$index_row] ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
648 my $dim = scalar(@{$hr_matrix_object->[$index_row]}) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
649
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
650 if ($dim > 1) { warn "the add method can't manage more than one column\n" ;}
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
651 my $lm_col = $hr_matrix_object->[$index_row][$dim-1] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
652
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
653 push (@init_row, $lm_col) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
654 $index_row++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
655 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
656 push (@output_matrix_object, \@init_row) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
657 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
658 return(\@output_matrix_object) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
659 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
660 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
661
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
662 =head2 METHOD write_csv_skel
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
663
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
664 ## Description : prepare and write csv output file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
665 ## Input : $csv_file, $rows
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
666 ## Output : $csv_file
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
667 ## Usage : my ( $csv_file ) = write_csv_skel( $csv_file, $rows ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
668
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
669 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
670 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
671 sub write_csv_skel {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
672 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
673 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
674 my ( $csv_file, $rows ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
675
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
676 my $ocsv = lib::csv::new() ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
677 my $csv = $ocsv->get_csv_object("\t") ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
678 $ocsv->write_csv_from_arrays($csv, $$csv_file, $rows) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
679
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
680 return($csv_file) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
681 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
682 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
683
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
684 =head2 METHOD set_hr_matrix_object
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
685
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
686 ## Description : build the hr_row under its ref form
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
687 ## Input : $header, $init_mzs, $entries
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
688 ## Output : $hr_matrix
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
689 ## Usage : my ( $hmdb_matrix ) = set_hr_matrix_object( $header, $init_mzs, $entries ) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
690
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
691 =cut
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
692 ## START of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
693 sub set_hr_matrix_object {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
694 ## Retrieve Values
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
695 my $self = shift ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
696 my ( $header, $init_mzs, $entries ) = @_ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
697
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
698 my @hr_matrix = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
699
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
700 if ( defined $header ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
701 my @headers = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
702 push @headers, $header ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
703 push @hr_matrix, \@headers ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
704 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
705
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
706 my $index_mz = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
707
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
708 foreach my $mz ( @{$init_mzs} ) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
709
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
710 my $index_entries = 0 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
711 my @clusters = () ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
712 my $cluster_col = undef ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
713
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
714 my $nb_entries = $entries->[$index_mz]{MASSES_TOTAL} ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
715
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
716 foreach (@{$entries->[$index_mz]{'ENTRY_FORMULA'}}) {
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
717
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
718 my $delta = $entries->[$index_mz]{'ENTRY_DELTA'}[$index_entries] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
719 my $hr_formula = $entries->[$index_mz]{'ENTRY_FORMULA'}[$index_entries] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
720 my $hr_mz = $entries->[$index_mz]{'ENTRY_CPD_MZ'}[$index_entries] ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
721
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
722
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
723 ## METLIN data display model
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
724 ## entry1=VAR1::VAR2::VAR3::VAR4|entry2=VAR1::VAR2::VAR3::VAR4|...
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
725 # manage final pipe
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
726 if ($index_entries < $$nb_entries-1 ) { $cluster_col .= $delta.'::('.$hr_formula.')::'.$hr_mz.'|' ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
727 else { $cluster_col .= $delta.'::('.$hr_formula.')::'.$hr_mz ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
728
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
729 $index_entries++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
730 } ## end foreach
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
731 if ( !defined $cluster_col ) { $cluster_col = 'No_result_found_with HR' ; }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
732 push (@clusters, $cluster_col) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
733 push (@hr_matrix, \@clusters) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
734 $index_mz++ ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
735 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
736 return(\@hr_matrix) ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
737 }
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
738 ## END of SUB
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
739
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
740
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
741
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
742 1 ;
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
743
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
744
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
745 __END__
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
746
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
747 =head1 SUPPORT
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
748
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
749 You can find documentation for this module with the perldoc command.
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
750
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
751 perldoc hr.pm
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
752
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
753 =head1 Exports
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
754
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
755 =over 4
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
756
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
757 =item :ALL is manage_atoms, check_hr_exe, manage_tolerance
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
758
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
759 =back
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
760
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
761 =head1 AUTHOR
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
762
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
763 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt>
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
764
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
765 =head1 LICENSE
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
766
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
767 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
768
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
769 =head1 VERSION
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
770
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
771 version 1 : 02 / 20 / 2014
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
772
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
773 version 2 : ??
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
774
86296c048e46 Init repository for [hr2]
fgiacomoni
parents:
diff changeset
775 =cut