Mercurial > repos > fgiacomoni > golm_ws_lib_search
annotate lib/output.pm @ 3:28d579fa1718 draft default tip
Master branch Updating - - Fxx
author | fgiacomoni |
---|---|
date | Wed, 03 Oct 2018 05:35:16 -0400 |
parents | e3d43b8c987b |
children |
rev | line source |
---|---|
0
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
1 package lib::output ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
2 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
3 use strict; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
4 use warnings ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
5 use Exporter ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
6 use Carp ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
7 use HTML::Template ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
8 use JSON ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
9 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
10 use FindBin ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
11 use lib $FindBin::Bin ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
12 my $binPath = $FindBin::Bin ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
13 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
14 use Data::Dumper ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
15 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
16 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
17 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
18 our $VERSION = "1.0"; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
19 our @ISA = qw(Exporter); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
20 our @EXPORT = qw(build_json_res_object excel_output write_html_body add_entries_to_tbody_object write_json_skel write_ajax_data_source excel_like_output); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
21 our %EXPORT_TAGS = ( ALL => [qw(build_json_res_object excel_output write_html_body add_entries_to_tbody_object write_json_skel write_ajax_data_source excel_like_output)] ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
22 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
23 =head1 NAME |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
24 My::Module - An example module |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
25 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
26 =head1 SYNOPSIS |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
27 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
28 use My::Module; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
29 my $object = My::Module->new(); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
30 print $object->as_string; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
31 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
32 =head1 DESCRIPTION |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
33 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
34 This module does not really exist, it |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
35 was made for the sole purpose of |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
36 demonstrating how POD works. |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
37 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
38 =head1 METHODS |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
39 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
40 Methods are : |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
41 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
42 =head2 METHOD new |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
43 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
44 ## Description : new |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
45 ## Input : $self |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
46 ## Ouput : bless $self ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
47 ## Usage : new() ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
48 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
49 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
50 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
51 sub new { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
52 ## Variables |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
53 my $self={}; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
54 bless($self) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
55 return $self ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
56 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
57 ### END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
58 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
59 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
60 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
61 =head2 METHOD build_json_res_object |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
62 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
63 ## Description : build json from array of hits |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
64 ## Input : $results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
65 ## Output : \@json_results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
66 ## Usage : my ( \@json_results ) = build_json_res_object( $results ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
67 ## JSON structure: [ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
68 # { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
69 # 'id' : 'int', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
70 # 'nb_hits' : int, |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
71 # 'searchResults' : [ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
72 # { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
73 # 'metaboliteID' : GUID |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
74 # 'distance_scores' : { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
75 # 'EuclideanDistance' : float |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
76 # 'DotproductDistance' : int |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
77 # 'HammingDistance' : int |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
78 # 'JaccardDistance' : int |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
79 # 's12GowerLegendreDistance' : int |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
80 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
81 # 'ri_infos' : { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
82 # 'ri' : float |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
83 # 'riDiscrepancy' : float |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
84 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
85 # 'analyte' : { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
86 # 'id' : GUID |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
87 # 'name' : string |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
88 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
89 # 'spectrum' : { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
90 # 'id' : GUID |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
91 # 'name' : string |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
92 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
93 # }, |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
94 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
95 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
96 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
97 # ] |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
98 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
99 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
100 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
101 # . |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
102 # ] |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
103 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
104 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
105 sub build_json_res_object { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
106 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
107 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
108 my ( $results ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
109 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
110 my @json_results ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
111 my @array_results = @$results ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
112 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
113 my $nb_hits = 0 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
114 my $i = 0 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
115 my $spectrumID = 1 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
116 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
117 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
118 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
119 ## Loop on each spectra |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
120 foreach my $res (@array_results) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
121 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
122 if (@$res[0] eq 'no results'){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
123 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
124 my %hit_infos = () ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
125 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
126 $json_results[$i]{'id'} = $spectrumID++ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
127 $json_results[$i]{'nb_hits'} = $nb_hits ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
128 $hit_infos{'metaboliteID'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
129 $hit_infos{'distance_scores'}{'EuclideanDistance'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
130 $hit_infos{'distance_scores'}{'DotproductDistance'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
131 $hit_infos{'distance_scores'}{'HammingDistance'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
132 $hit_infos{'distance_scores'}{'JaccardDistance'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
133 $hit_infos{'distance_scores'}{'s12GowerLegendreDistance'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
134 $hit_infos{'ri_infos'}{'ri'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
135 $hit_infos{'ri_infos'}{'riDiscrepancy'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
136 $hit_infos{'analyte'}{'id'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
137 $hit_infos{'analyte'}{'name'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
138 $hit_infos{'spectrum'}{'id'} = "" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
139 $hit_infos{'spectrum'}{'name'} = "no results" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
140 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
141 push ( @{ $json_results[$i]{'searchResults'} } , \%hit_infos ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
142 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
143 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
144 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
145 $nb_hits = scalar @$res; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
146 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
147 $json_results[$i]{'id'} = $spectrumID++ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
148 $json_results[$i]{'nb_hits'} = $nb_hits ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
149 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
150 ## Loop on each hit of a spectrum + build json |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
151 foreach my $href (@$res) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
152 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
153 if (!defined $href){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
154 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
155 last ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
156 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
157 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
158 my %hash_res = %$href ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
159 my %hit_infos = () ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
160 # Get rid of false results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
161 if ($hash_res{'metaboliteID'} eq '00000000-0000-0000-0000-000000000000') { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
162 --$json_results[$i]{'nb_hits'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
163 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
164 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
165 $hit_infos{'metaboliteID'} = $hash_res{'metaboliteID'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
166 $hit_infos{'distance_scores'}{'EuclideanDistance'} = $hash_res{'EuclideanDistance'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
167 $hit_infos{'distance_scores'}{'DotproductDistance'} = $hash_res{'DotproductDistance'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
168 $hit_infos{'distance_scores'}{'HammingDistance'} = $hash_res{'HammingDistance'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
169 $hit_infos{'distance_scores'}{'JaccardDistance'} = $hash_res{'JaccardDistance'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
170 $hit_infos{'distance_scores'}{'s12GowerLegendreDistance'} = $hash_res{'s12GowerLegendreDistance'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
171 $hit_infos{'ri_infos'}{'ri'} = $hash_res{'ri'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
172 $hit_infos{'ri_infos'}{'riDiscrepancy'} = $hash_res{'riDiscrepancy'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
173 $hit_infos{'analyte'}{'id'} = $hash_res{'analyteID'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
174 $hit_infos{'analyte'}{'name'} = $hash_res{'analyteName'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
175 $hit_infos{'spectrum'}{'id'} = $hash_res{'spectrumID'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
176 $hit_infos{'spectrum'}{'name'} = $hash_res{'spectrumName'} ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
177 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
178 push ( @{ $json_results[$i]{'searchResults'} } , \%hit_infos ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
179 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
180 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
181 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
182 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
183 $i++ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
184 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
185 return \@json_results ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
186 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
187 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
188 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
189 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
190 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
191 =head2 METHOD add_entries_to_tbody_object |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
192 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
193 ## Description : initialize and build the entries object needed by HTML::Template |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
194 ## Input : $results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
195 ## Output : \@tbody_entries |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
196 ## Usage : my ( $tbody_entries ) = add_entries_to_tbody_object( $results ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
197 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
198 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
199 sub add_entries_to_tbody_object { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
200 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
201 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
202 my ( $results ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
203 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
204 my @tbody_entries = () ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
205 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
206 foreach my $href_grp (@$results) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
207 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
208 foreach my $hit ( @{$href_grp->{'searchResults'}} ){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
209 my %grp_res = () ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
210 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
211 ## Add hyperlinks |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
212 if ( $hit->{'spectrum'}{'name'} ne 'no results') { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
213 %grp_res = ( |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
214 ID => $href_grp->{id} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
215 ANALYTE_NAME => $hit->{analyte}{name} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
216 SPECTRUM_NAME => $hit->{spectrum}{name} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
217 RI => $hit->{ri_infos}{ri} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
218 RI_DISCREPANCY => $hit->{ri_infos}{riDiscrepancy} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
219 DOT_PRODUCT_DISTANCE => $hit->{distance_scores}{DotproductDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
220 EUCLIDEAN_DISTANCE => $hit->{distance_scores}{EuclideanDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
221 JACCARD_DISTANCE => $hit->{distance_scores}{JaccardDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
222 HAMMING_DISTANCE => $hit->{distance_scores}{HammingDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
223 S12_GOWER_LEGENDRE_DISTANCE => $hit->{distance_scores}{s12GowerLegendreDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
224 SPECTRUM_ID => $hit->{spectrum}{id} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
225 METABOLITE_ID => $hit->{metaboliteID} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
226 ANALYTE_ID => $hit->{analyte}{id}, |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
227 ANALYTE_REF => 'http://gmd.mpimp-golm.mpg.de/Analytes/'.$hit->{analyte}{id}.'.aspx', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
228 SPECTRUM_REF => 'http://gmd.mpimp-golm.mpg.de/Spectrums/'.$hit->{spectrum}{id}.'.aspx', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
229 METABOLITE_REF => 'http://gmd.mpimp-golm.mpg.de/Metabolites/'.$hit->{metaboliteID}.'.aspx', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
230 ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
231 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
232 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
233 %grp_res = ( |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
234 ID => $href_grp->{id} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
235 ANALYTE_NAME => $hit->{analyte}{name} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
236 SPECTRUM_NAME => $hit->{spectrum}{name} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
237 RI => $hit->{ri_infos}{ri} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
238 RI_DISCREPANCY => $hit->{ri_infos}{riDiscrepancy} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
239 DOT_PRODUCT_DISTANCE => $hit->{distance_scores}{DotproductDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
240 EUCLIDEAN_DISTANCE => $hit->{distance_scores}{EuclideanDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
241 JACCARD_DISTANCE => $hit->{distance_scores}{JaccardDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
242 HAMMING_DISTANCE => $hit->{distance_scores}{HammingDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
243 S12_GOWER_LEGENDRE_DISTANCE => $hit->{distance_scores}{s12GowerLegendreDistance} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
244 SPECTRUM_ID => $hit->{spectrum}{id} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
245 METABOLITE_ID => $hit->{metaboliteID} , |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
246 ANALYTE_ID => $hit->{analyte}{id}, |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
247 ANALYTE_REF => 'http://gmd.mpimp-golm.mpg.de/', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
248 SPECTRUM_REF => 'http://gmd.mpimp-golm.mpg.de/', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
249 METABOLITE_REF => 'http://gmd.mpimp-golm.mpg.de/', |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
250 ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
251 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
252 push (@tbody_entries , \%grp_res) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
253 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
254 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
255 return \@tbody_entries ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
256 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
257 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
258 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
259 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
260 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
261 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
262 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
263 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
264 =head2 METHOD write_html_body |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
265 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
266 ## Description : Write the html output file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
267 ## Input : $results, $tbody_entries, $html_file, $html_template |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
268 ## Output : $html_file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
269 ## Usage : $o_output->write_html_body( $results, $tbody_entries, $html_file, $html_template ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
270 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
271 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
272 sub write_html_body { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
273 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
274 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
275 my ( $results, $tbody_entries, $html_file_name, $html_template, $default_entries, $jsons_obj ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
276 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
277 if (defined $html_file_name){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
278 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
279 open (HTML, '>', $html_file_name) or die "Failed to open filehandle: $!" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
280 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
281 if (-e $html_template) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
282 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
283 my $ohtml = HTML::Template->new(filename => $html_template) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
284 # $ohtml->param( DATA => $jsons_obj ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
285 $ohtml->param( GROUPS => $tbody_entries ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
286 $ohtml->param( DEFAULT_ENTRIES => $default_entries ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
287 print HTML $ohtml->output ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
288 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
289 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
290 croak "Problem about your html template: no html template available\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
291 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
292 close (HTML) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
293 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
294 else { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
295 croak "Problem with the html output file: $html_file_name is not defined\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
296 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
297 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
298 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
299 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
300 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
301 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
302 =head2 METHOD excel_output |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
303 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
304 ## Description : create an excel XLS output of the results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
305 ## Input : $jsons, $excel_file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
306 ## Output : excel file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
307 ## Usage : $o_output->excel_output( $jsons, $excel_file ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
308 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
309 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
310 #sub excel_output { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
311 # ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
312 # my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
313 # my ( $excel_file, $jsons ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
314 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
315 # # Create a new workbook and add a worksheet |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
316 # my $workbook = Excel::Writer::XLSX->new( $excel_file ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
317 # my $worksheet = $workbook->add_worksheet() ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
318 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
319 # my $i = 0 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
320 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
321 # # Create a format for the headings |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
322 # my $format = $workbook->add_format() ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
323 # $format->set_bold() ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
324 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
325 # $worksheet->write( $i, 0, "Num Spectre" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
326 # $worksheet->write( $i, 1, "Analyte Name" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
327 # $worksheet->write( $i, 2, "Spectrum Name" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
328 # $worksheet->write( $i, 3, "Retention Index" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
329 # $worksheet->write( $i, 4, "RI Discrepancy" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
330 # $worksheet->write( $i, 5, "DotproductDistance" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
331 # $worksheet->write( $i, 6, "EuclideanDistance" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
332 # $worksheet->write( $i, 7, "JaccardDistance" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
333 # $worksheet->write( $i, 8, "HammingDistance" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
334 # $worksheet->write( $i, 9, "s12GowerLegendreDistance" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
335 # $worksheet->write( $i, 10, "Spectrum ID" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
336 # $worksheet->write( $i, 11, "Metabolite ID" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
337 # $worksheet->write( $i, 12, "Analyte ID" , $format); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
338 # $i++; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
339 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
340 # foreach my $href_grp (@$jsons) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
341 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
342 # foreach my $hit ( @{$href_grp->{'searchResults'}} ){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
343 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
344 # $worksheet->write( $i, 0, $href_grp->{id} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
345 # $worksheet->write( $i, 1, $hit->{analyte}{name} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
346 # $worksheet->write( $i, 2, $hit->{spectrum}{name} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
347 # $worksheet->write( $i, 3, $hit->{ri_infos}{ri} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
348 # $worksheet->write( $i, 4, $hit->{ri_infos}{riDiscrepancy} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
349 # $worksheet->write( $i, 5, $hit->{distance_scores}{DotproductDistance} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
350 # $worksheet->write( $i, 6, $hit->{distance_scores}{EuclideanDistance} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
351 # $worksheet->write( $i, 7, $hit->{distance_scores}{JaccardDistance} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
352 # $worksheet->write( $i, 8, $hit->{distance_scores}{HammingDistance} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
353 # $worksheet->write( $i, 9, $hit->{distance_scores}{s12GowerLegendreDistance} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
354 # $worksheet->write( $i, 10, $hit->{spectrum}{id} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
355 # $worksheet->write( $i, 11, $hit->{metaboliteID} ); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
356 # $worksheet->write( $i, 12, $hit->{analyte}{id}); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
357 # $i++; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
358 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
359 # } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
360 # |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
361 # $workbook->close(); |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
362 #} |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
363 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
364 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
365 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
366 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
367 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
368 =head2 METHOD excel_like_output |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
369 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
370 ## Description : create an excel like output of the results |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
371 ## Input : $jsons, $excel_file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
372 ## Output : excel file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
373 ## Usage : $o_output->excel_like_output( $jsons, $excel_file ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
374 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
375 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
376 sub excel_like_output { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
377 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
378 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
379 my ( $excel_file, $jsons ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
380 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
381 open (OUT , ">" , $excel_file) or die "Error at opening file $excel_file" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
382 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
383 print OUT "Num Spectre\tAnalyte Name\tSpectrum Name\tRetention Index\tRI Discrepancy\tDotproductDistance\tEuclideanDistance\tJaccardDistance\tHammingDistance\ts12GowerLegendreDistance\tSpectrum ID\tMetabolite ID\tAnalyte ID\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
384 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
385 foreach my $href_grp (@$jsons) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
386 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
387 foreach my $hit ( @{$href_grp->{'searchResults'}} ){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
388 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
389 print OUT "$href_grp->{id}\t$hit->{analyte}{name}\t$hit->{spectrum}{name}\t$hit->{ri_infos}{ri}\t$hit->{ri_infos}{riDiscrepancy}\t$hit->{distance_scores}{DotproductDistance}\t$hit->{distance_scores}{EuclideanDistance}\t$hit->{distance_scores}{JaccardDistance}\t$hit->{distance_scores}{HammingDistance}\t$hit->{distance_scores}{s12GowerLegendreDistance}\t$hit->{spectrum}{id}\t$hit->{metaboliteID}\t$hit->{analyte}{id}\n"; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
390 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
391 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
392 close (OUT) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
393 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
394 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
395 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
396 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
397 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
398 =head2 METHOD write_json_skel |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
399 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
400 ## Description : prepare and write json output file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
401 ## Input : $json_file, $scalar |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
402 ## Output : json file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
403 ## Usage : $o_output->write_json_skel( $csv_file, $scalar ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
404 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
405 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
406 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
407 sub write_json_skel { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
408 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
409 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
410 my ( $json_file, $json_obj ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
411 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
412 my $utf8_encoded_json_text = encode_json $json_obj ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
413 open(JSON, '>:utf8', $$json_file) or die "Can't create the file $$json_file\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
414 print JSON $utf8_encoded_json_text ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
415 close(JSON) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
416 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
417 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
418 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
419 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
420 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
421 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
422 =head2 METHOD write_csv |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
423 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
424 ## Description : write csv output file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
425 ## Input : $xlsx_file, $csv_file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
426 ## Output : csv file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
427 ## Usage : $o_output->write_csv( $xlsx_file, $csv_file ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
428 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
429 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
430 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
431 sub write_csv { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
432 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
433 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
434 my ( $csv_file, $jsons ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
435 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
436 open (CSV , ">" , $csv_file) or die "Can't create the file $csv_file\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
437 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
438 print CSV "\"Num Spectre\"\t\"Analyte Name\"\t\"Spectrum Name\"\t\"Retention Index\"\t\"RI Discrepancy\"\t\"DotproductDistance\"\t\"EuclideanDistance\"\t\"JaccardDistance\"\t\"HammingDistance\"\t\"s12GowerLegendreDistance\"\t\"Spectrum ID\"\t\"Metabolite ID\"\t\"Analyte ID\"\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
439 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
440 foreach my $href_grp (@$jsons) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
441 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
442 foreach my $hit ( @{$href_grp->{'searchResults'}} ){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
443 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
444 print CSV "\"$href_grp->{id}\"\t\"$hit->{analyte}{name}\"\t\"$hit->{spectrum}{name}\"\t\"$hit->{ri_infos}{ri}\"\t\"$hit->{ri_infos}{riDiscrepancy}\"\t\"$hit->{distance_scores}{DotproductDistance}\"\t\"$hit->{distance_scores}{EuclideanDistance}\"\t\"$hit->{distance_scores}{JaccardDistance}\"\t\"$hit->{distance_scores}{HammingDistance}\"\t\"$hit->{distance_scores}{s12GowerLegendreDistance}\"\t\"$hit->{spectrum}{id}\"\t\"$hit->{metaboliteID}\"\t\"$hit->{analyte}{id}\"\n" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
445 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
446 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
447 close(CSV) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
448 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
449 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
450 ## END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
451 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
452 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
453 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
454 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
455 =head2 METHOD write_ajax_data_source |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
456 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
457 ## Description : write csv output file |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
458 ## Input : $jsons_obj |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
459 ## Output : |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
460 ## Usage : $o_output->write_ajax_data_source( $jsons_obj ) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
461 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
462 =cut |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
463 ## START of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
464 sub write_ajax_data_source { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
465 ## Retrieve Values |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
466 my $self = shift ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
467 my ( $jsons_obj ) = @_ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
468 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
469 my %ajax = () ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
470 my $i = 0 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
471 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
472 #open (AJAX,">ajax.txt") or die "ERROR at opening file" ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
473 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
474 foreach my $href_grp (@$jsons_obj) { |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
475 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
476 foreach my $hit ( @{$href_grp->{'searchResults'}} ){ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
477 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
478 push (@{$ajax{ 'data' }[$i]} , $href_grp->{id}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
479 push (@{$ajax{ 'data' }[$i]} , $hit->{spectrum}{name}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
480 push (@{$ajax{ 'data' }[$i]} , $hit->{analyte}{name}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
481 push (@{$ajax{ 'data' }[$i]} , $hit->{ri_infos}{ri}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
482 push (@{$ajax{ 'data' }[$i]} , $hit->{ri_infos}{riDiscrepancy}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
483 push (@{$ajax{ 'data' }[$i]} , $hit->{distance_scores}{DotproductDistance}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
484 push (@{$ajax{ 'data' }[$i]} , $hit->{distance_scores}{EuclideanDistance}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
485 push (@{$ajax{ 'data' }[$i]} , $hit->{distance_scores}{JaccardDistance}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
486 push (@{$ajax{ 'data' }[$i]} , $hit->{distance_scores}{HammingDistance}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
487 push (@{$ajax{ 'data' }[$i]} , $hit->{distance_scores}{s12GowerLegendreDistance}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
488 push (@{$ajax{ 'data' }[$i]} , $hit->{spectrum}{id}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
489 push (@{$ajax{ 'data' }[$i]} , $hit->{metaboliteID}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
490 push (@{$ajax{ 'data' }[$i]} , $hit->{analyte}{ID}) ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
491 $i++ ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
492 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
493 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
494 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
495 my $ajax = encode_json \%ajax ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
496 return $ajax ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
497 #print AJAX $ajax ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
498 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
499 } |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
500 #END of SUB |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
501 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
502 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
503 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
504 1 ; |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
505 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
506 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
507 __END__ |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
508 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
509 =head1 SUPPORT |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
510 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
511 You can find documentation for this module with the perldoc command. |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
512 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
513 perldoc csv.pm |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
514 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
515 =head1 Exports |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
516 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
517 =over 4 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
518 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
519 =item :ALL is get_spectra |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
520 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
521 =back |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
522 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
523 =head1 AUTHOR |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
524 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
525 Gabriel Cretin E<lt>gabriel.cretin@clermont.inra.frE<gt> |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
526 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt> |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
527 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
528 =head1 LICENSE |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
529 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
530 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
531 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
532 =head1 VERSION |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
533 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
534 version 1 : ?? |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
535 |
e3d43b8c987b
Init repository with last tool-bank-golm-lib_search master version
fgiacomoni
parents:
diff
changeset
|
536 =cut |