annotate lib/operations.pm @ 3:f4e6b77c46e3 draft default tip

Master branch Updating - - Fxx
author fgiacomoni
date Wed, 03 Oct 2018 05:47:14 -0400
parents e8bd49794291
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
1 package lib::operations ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
2
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
3 use strict;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
4 use warnings ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
5 use Exporter ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
6 use Carp ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
7 use Data::Dumper ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
8
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
9 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
10
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
11 our $VERSION = "1.0";
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
12 our @ISA = qw(Exporter);
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
13 our @EXPORT = qw( get_factorial truncate_num truncate_nums round_num round_nums manage_mode );
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
14 our %EXPORT_TAGS = ( ALL => [qw( get_factorial truncate_num truncate_nums round_num round_nums manage_mode )] );
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
15
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
16 =head1 NAME
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
17
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
18 My::operations - An example module
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
19
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
20 =head1 SYNOPSIS
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
21
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
22 use My::operations;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
23 my $object = My::Module->new();
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
24 print $object->as_string;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
25
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
26 =head1 DESCRIPTION
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
27
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
28 This module clusters several more used maths functions like factorial...
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
29
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
30 =head1 METHODS
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
31
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
32 Methods are :
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
33
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
34 =head2 METHOD new
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
35
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
36 ## Description : new
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
37 ## Input : $self
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
38 ## Ouput : bless $self ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
39 ## Usage : new() ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
40
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
41 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
42
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
43 sub new {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
44 ## Variables
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
45 my $self={};
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
46 bless($self) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
47 return $self ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
48 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
49 ### END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
50
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
51 =head2 METHOD get_factorial
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
52
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
53 ## Description :permet de retourner la factorielle d'un nombre
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
54 ## Input : $indice
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
55 ## Output : $factorial
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
56 ## Usage : my ( var2 ) = get_factorial( var1 ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
57
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
58 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
59 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
60 sub get_factorial {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
61 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
62 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
63 my ( $ind )= @_ ; # transmission des parametres
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
64 my ( $factorial, $indmun ) = ( 0, 0 ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
65
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
66 if ( defined $ind ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
67
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
68 if ( $ind == 0 ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
69 $factorial = 1 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
70 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
71 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
72 $indmun = $ind-1 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
73 $factorial = &get_factorial ( $self, $indmun ) * $ind ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
74 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
75 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
76 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
77 croak "Indice in \"get_factorial sub\" is undef\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
78 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
79
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
80 return ($factorial) ; # renvoi de la valeur
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
81 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
82 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
83
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
84 =head2 METHOD manage_mode
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
85
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
86 ## Description : manage mode and apply mass correction (positive/negative/neutral)
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
87 ## Input : $mode, $charge, $electron, $proton, $mass
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
88 ## Output : $exact_mass
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
89 ## Usage : my ( $exact_mass ) = manage_mode( $mode, $charge, $electron, $proton, $mass ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
90
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
91 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
92 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
93 sub manage_mode {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
94 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
95 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
96 my ( $mode, $charge, $electron, $proton, $mass ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
97 my ($exact_mass, $tmp_mass) = ( undef, undef ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
98
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
99 ## some explanations :
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
100 # MS in + mode = adds H+ (proton) and molecule is positive : el+ => $charge = "positive"
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
101 # For HR, need to subtrack proton mz and to add electron mz (1 electron per charge) to the input mass which comes neutral!
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
102
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
103 if ( ( defined $$electron ) and ( defined $$proton ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
104 # check mass
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
105 if ( defined $$mass ) { $tmp_mass = $$mass ; $tmp_mass =~ tr/,/./ ; } # manage . and , in case of...
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
106 else { warn "No mass is defined\n" }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
107
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
108 # manage charge
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
109 if ( ( !defined $$charge ) || ($$charge < 0) ){ warn "Charge is not defined or value is less than zero\n" ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
110
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
111 # set neutral mass in function of ms mode
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
112 if($$mode eq 'POS') { $exact_mass = ( $tmp_mass - $$proton + $$electron) * $$charge ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
113 elsif($$mode eq 'NEG') { $exact_mass = ( $tmp_mass + $$proton - $$electron) * $$charge ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
114 elsif($$mode eq "NEU") { $exact_mass = $tmp_mass ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
115 else { warn "This mode doesn't exist : please select positive/negative or neutral mode\n" ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
116 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
117 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
118 warn "Missing some parameter values (electron, neutron masses), please check your conf file\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
119 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
120 # print "$tmp_mass -> $exact_mass ($$mode) \n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
121 return(\$exact_mass) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
122 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
123 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
124
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
125 =head2 METHOD truncate_num
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
126
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
127 ## Description : truncate a number by the sended decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
128 ## Input : $number, $decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
129 ## Output : $trunk_num
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
130 ## Usage : my ( $trunk_num ) = truncate_num( $number, $decimal ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
131
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
132 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
133 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
134 sub truncate_num {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
135 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
136 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
137 my ( $number, $decimal ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
138 my $trunk_num = 0 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
139
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
140 if ( ( defined $decimal ) and ( $decimal > 0 ) and ( defined $number ) and ( $number > 0 ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
141 $trunk_num = ($number =~ m/(\d+[\.|,]\d{$decimal})/); ## on utilise une tronquature seche 5.3 -> 5 et 5.8 -> 5
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
142 if($number =~/^\-/) {$trunk_num = -$trunk_num ;} # For neg number
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
143 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
144 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
145 croak "Can't trunk any number : missing value or decimal\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
146 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
147
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
148 return(\$trunk_num) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
149 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
150 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
151
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
152 =head2 METHOD truncate_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
153
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
154 ## Description : truncate a list of numbers by the sended decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
155 ## Input : $numbers, $decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
156 ## Output : $trunk_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
157 ## Usage : my ( $trunk_nums ) = truncate_nums( $numbers, $decimal ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
158
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
159 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
160 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
161 sub truncate_nums {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
162 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
163 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
164 my ( $numbers, $decimal ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
165 my @trunk_nums = () ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
166
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
167 if ( ( defined $decimal ) and ( $decimal > 0 ) and ( defined $numbers ) and ( scalar(@{$numbers}) > 0 ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
168 foreach my $nb ( @{$numbers} ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
169 my ( $trunk_num ) = ( $nb =~ m/(\d+[\.|,]\d{$decimal})/ ); ## on utilise une tronquature seche 5.3 -> 5 et 5.8 -> 5
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
170 if( $nb =~/^\-/ ) { $trunk_num = -$trunk_num ; } # For neg number
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
171 push ( @trunk_nums, $trunk_num ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
172 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
173 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
174 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
175 croak "Can't trunk any number : missing values or decimal\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
176 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
177 return( \@trunk_nums ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
178 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
179 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
180
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
181 =head2 METHOD round_num
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
182
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
183 ## Description : round a number by the sended decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
184 ## Input : $number, $decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
185 ## Output : $round_num
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
186 ## Usage : my ( $round_num ) = round_num( $number, $decimal ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
187
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
188 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
189 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
190 sub round_num {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
191 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
192 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
193 my ( $number, $decimal ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
194 my $round_num = 0 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
195
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
196 if ( ( defined $decimal ) and ( $decimal > 0 ) and ( defined $number ) and ( $number > 0 ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
197 $round_num = sprintf("%.".$decimal."f", $number); ## on utilise un arrondit : 5.3 -> 5 et 5.5 -> 6
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
198 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
199 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
200 croak "Can't round any number : missing value or decimal\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
201 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
202
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
203 return(\$round_num) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
204 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
205 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
206
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
207 =head2 METHOD round_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
208
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
209 ## Description : round a list of numbers by the sended decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
210 ## Input : $numbers, $decimal
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
211 ## Output : $round_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
212 ## Usage : my ( $round_nums ) = round_nums( $numbers, $decimal ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
213
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
214 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
215 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
216 sub round_nums {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
217 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
218 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
219 my ( $numbers, $decimal ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
220 my @round_nums = () ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
221
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
222 # print Dumper $numbers ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
223
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
224 if ( ( defined $decimal ) and ( $decimal >= 0 ) and ( defined $numbers ) and ( scalar(@{$numbers}) > 0 ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
225 foreach my $nb ( @{$numbers} ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
226 if ( ( defined $nb ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
227 if ($nb =~ /^\d+\.\d+$/ ) { ## check float
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
228 my $round_num = sprintf("%.".$decimal."f", $nb); ## on utilise un arrondit : 5.3 -> 5 et 5.5 -> 6 mais 5.25 -> 5.2
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
229 push ( @round_nums, $round_num ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
230 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
231 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
232 warn "This var $nb is not a float\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
233 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
234 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
235 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
236 croak "This number is not defined or is a string\n ";
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
237 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
238
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
239 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
240 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
241 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
242 croak "Can't round any numbers : missing values or decimal\n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
243 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
244 return( \@round_nums ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
245 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
246 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
247
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
248 =head2 METHOD subtract_num
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
249
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
250 ## Description : subtracting a number to an other
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
251 ## Input : $number, $number_to_subtr
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
252 ## Output : $value
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
253 ## Usage : my ( $value ) = subtract_num( $number, $number_to_subtr ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
254
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
255 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
256 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
257 sub subtract_num {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
258 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
259 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
260 my ( $number, $number_to_subtr ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
261 my $value = 0 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
262
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
263 if ( ( defined $number ) and ( defined $number_to_subtr ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
264 $value = ($number - $number_to_subtr) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
265 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
266 else {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
267 warn "The \n" ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
268 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
269 return(\$value) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
270 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
271 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
272
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
273 =head2 METHOD subtract_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
274
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
275 ## Description : subtracting a number to a list of numbers
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
276 ## Input : $numbers, $numbers_to_subtr
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
277 ## Output : $values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
278 ## Usage : my ( $values ) = subtract_num( $numbers, $numbers_to_subtr ) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
279
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
280 =cut
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
281 ## START of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
282 sub subtract_nums {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
283 ## Retrieve Values
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
284 my $self = shift ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
285 my ( $numbers, $number_to_subtr ) = @_ ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
286 my @values = () ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
287
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
288 if ( ( defined $numbers ) and ( defined $number_to_subtr ) ) {
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
289 foreach my $num ( @{$numbers} ) { push ( @values, ( $num - $number_to_subtr ) ) ; }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
290 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
291 return(\@values) ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
292 }
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
293 ## END of SUB
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
294
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
295 1 ;
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
296
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
297
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
298 __END__
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
299
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
300 =head1 SUPPORT
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
301
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
302 You can find documentation for this module with the perldoc command.
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
303
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
304 perldoc operations.pm
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
305
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
306 =head1 Exports
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
307
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
308 =over 4
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
309
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
310 =item :ALL is get_factorial truncate_num truncate_nums round_num round_nums
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
311
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
312 =back
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
313
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
314 =head1 AUTHOR
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
315
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
316 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt>
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
317
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
318 =head1 LICENSE
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
319
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
320 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
321
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
322 =head1 VERSION
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
323
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
324 version 1 : 29 / 04 / 2013
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
325
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
326 version 2 : ??
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
327
e8bd49794291 Init repository with last lipidmaps_textsearch master version
fgiacomoni
parents:
diff changeset
328 =cut