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