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