annotate lib/writter.pm @ 0:023c380900ef draft default tip

Init repository with last massbank_ws_searchspectrum master version
author fgiacomoni
date Wed, 19 Apr 2017 11:31:58 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
1 package lib::writter ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
2
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
3 use strict;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
4 use warnings ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
5 use Exporter ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
6 use Carp ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
7
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
8 use Data::Dumper ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
9 use JSON ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
10 use HTML::Template ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
11
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
12 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
13
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
14 our $VERSION = "1.0";
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
15 our @ISA = qw(Exporter);
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
16 our @EXPORT = qw( write_csv_skel write_xls_skel write_json_skel write_html_skel );
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
17 our %EXPORT_TAGS = ( ALL => [qw( write_csv_skel write_xls_skel write_json_skel write_html_skel )] );
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
18
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
19 =head1 NAME
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
20
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
21 My::Module - An example module
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
22
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
23 =head1 SYNOPSIS
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
24
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
25 use My::Module;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
26 my $object = My::Module->new();
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
27 print $object->as_string;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
28
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
29 =head1 DESCRIPTION
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
30
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
31 This module does not really exist, it
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
32 was made for the sole purpose of
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
33 demonstrating how POD works.
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
34
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
35 =head1 METHODS
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
36
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
37 Methods are :
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
38
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
39 =head2 METHOD new
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
40
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
41 ## Description : new
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
42 ## Input : $self
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
43 ## Ouput : bless $self ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
44 ## Usage : new() ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
45
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
46 =cut
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
47
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
48 sub new {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
49 ## Variables
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
50 my $self={};
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
51 bless($self) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
52 return $self ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
53 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
54 ### END of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
55
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
56 =head2 METHOD write_csv_skel
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
57
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
58 ## Description : prepare and write csv output file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
59 ## Input : $csv_file, $rows
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
60 ## Output : $csv_file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
61 ## Usage : my ( $csv_file ) = write_csv_skel( $csv_file, $rows ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
62
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
63 =cut
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
64 ## START of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
65 sub write_csv_skel {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
66 ## Retrieve Values
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
67 my $self = shift ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
68 my ( $csv_file, $rows ) = @_ ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
69
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
70 my $ocsv = lib::csv::new( {is_binary => 1 , quote_binary => 0, quote_char => undef }) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
71 my $csv = $ocsv->get_csv_object("\t") ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
72 $ocsv->write_csv_from_arrays($csv, $$csv_file, $rows) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
73
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
74 return($csv_file) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
75 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
76 ## END of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
77
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
78 =head2 METHOD write_xls_skel
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
79
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
80 ## Description : prepare and write xls output file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
81 ## Input : $xls_file, $rows
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
82 ## Output : $xls_file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
83 ## Usage : my ( $xls_file ) = write_xls_skel( $xls_file, $rows ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
84
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
85 =cut
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
86 ## START of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
87 sub write_xls_skel {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
88 ## Retrieve Values
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
89 my $self = shift ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
90 my ( $out_xls, $mzs, $pcs, $pcgroups, $records ) = @_ ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
91
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
92 my $results = undef ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
93 my $i = 0 ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
94
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
95 open(XLS, '>:utf8', "$$out_xls") or die "Cant' create the file $$out_xls\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
96 print XLS "ID\tPCGROUP\tQuery(Da)\tScore\tMetabolite_name\tCpd_Mw(Da)\tFormula\tAdduct\tMASSBANK_ID\tInstrument\tMS_level\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
97
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
98 $results = ['ID','PCGROUP','Query(Da)','Score','Metabolite_name','Cpd_Mw(Da)','Formula','Adduct','MASSBANK_ID','Instrument','MS_level'] ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
99
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
100 foreach my $pc (@{$pcs}) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
101
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
102 if ($pcgroups->{$pc}) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
103 # print "------>$pc - $pcgroups->{$pc}{annotation}{num_res}\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
104
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
105 if ( $pcgroups->{$pc}{'annotation'} ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
106 my $result = undef ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
107 my $well_id = "mz_0".sprintf("%04s", $i+1 ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
108
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
109 if ($pcgroups->{$pc}{'annotation'}{'num_res'} > 0) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
110
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
111 my @entries = @{$pcgroups->{$pc}{'annotation'}{'res'} } ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
112 my $status = undef ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
113 foreach my $entry (@entries) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
114 my $match = undef ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
115 ## manage if the queried mz is really in the mzs spectrum list...
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
116
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
117 if ( $pcgroups->{$pc}{'enrich_annotation'}{$mzs->[$i]} ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
118
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
119 my @matching_ids = @{$pcgroups->{$pc}{'enrich_annotation'}{$mzs->[$i]}} ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
120
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
121 ##
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
122 if ( scalar @matching_ids == 0 ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
123 $result .= $well_id."\t".$pc."\t".$mzs->[$i]."\t".'0'."\t".'UNKNOWN'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
124 print XLS "$well_id\t$pc\t$mzs->[$i]\t0\tNA\tNA\tNA\tNA\tNA\tNA\tNA\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
125 last ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
126 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
127 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
128 # search the massbank matched id
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
129 foreach (@matching_ids) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
130 if ($_ eq $entry->{'id'} ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
131 $match = 'TRUE' ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
132 last ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
133 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
134 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
135
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
136 if ( ( defined $match ) and ($match eq 'TRUE') ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
137 ## sort by ['ID','PCGROUP','Query(Da)','Score','Metabolite_name','Cpd_Mw(Da)','Formula','Adduct','MASSBANK_ID','Instrument','MS_level']
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
138
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
139 ## print mz_id
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
140 if ($mzs->[$i]) { print XLS "$well_id\t" ; $result .= $well_id."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
141 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
142 ## print submitted pcgroup
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
143 if ($pc ) { print XLS "$pc\t" ; $result .= $pc."\t" ; } ## pb de clean de la derniere ligne !!!!!!
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
144 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
145 ## print Query(Da)
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
146 if ($mzs->[$i]) { print XLS "$mzs->[$i]\t" ; $result .= $mzs->[$i]."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
147 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
148
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
149 ## print Score
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
150 if ($entry->{'score'}) { print XLS "$entry->{'score'}\t" ; $result .= $entry->{'score'}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
151 else { print XLS "NA\n" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
152 ## print Met_name
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
153 if ($entry->{'id'}) { print XLS "$records->{$entry->{'id'}}{names}[0]\t" ; $result .= $records->{$entry->{'id'}}{names}[0]."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
154 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
155 ## print Cpd_mw
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
156 if ($entry->{'exactMass'}) { print XLS "$entry->{'exactMass'}\t" ; $result .= $entry->{'exactMass'}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
157 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
158 ## print Formula
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
159 if ($entry->{'formula'}) { print XLS "$entry->{'formula'}\t" ; $result .= $entry->{'formula'}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
160 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
161 ## print Adduct (precursor type)
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
162 if ($entry->{'id'}) { print XLS "$records->{$entry->{'id'}}{precursor_type}\t" ; $result .= $records->{$entry->{'id'}}{precursor_type}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
163 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
164 ## print Massbank ID
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
165 if ($entry->{'id'}) { print XLS "$entry->{'id'}\t" ; $result .= $entry->{'id'}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
166 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
167 ## print Instrument
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
168 if ($entry->{'id'}) { print XLS "$records->{$entry->{'id'}}{instrument_type}\t" ; $result .= $records->{$entry->{'id'}}{instrument_type}."\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
169 else { print XLS "NA\t" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
170 ## print MS_Level
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
171 if ($entry->{'id'}) { print XLS "$records->{$entry->{'id'}}{ms_type}\n" ; $result .= $records->{$entry->{'id'}}{ms_type}."\n" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
172 else { print XLS "NA\n" ; }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
173
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
174 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
175 ## else match is not TRUE
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
176 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
177 next ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
178 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
179 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
180 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
181 } ## End foreach entries
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
182 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
183 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
184 $result .= $well_id."\t".$pc."\t".$mzs->[$i]."\t".'0'."\t".'UNKNOWN'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\t".'NA'."\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
185 print XLS "$well_id\t$pc\t$mzs->[$i]\t0\tNA\tNA\tNA\tNA\tNA\tNA\tNA\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
186 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
187 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
188 else{
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
189 warn "Not possible to get number of found ids on MassBank\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
190 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
191 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
192 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
193 croak "No such pc group exists in your pcgroups object - No xls written\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
194 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
195 $i++ ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
196
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
197 } ## End foreach pcs
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
198
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
199 close(XLS) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
200 return($results) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
201 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
202 ## END of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
203
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
204 =head2 METHOD write_json_skel
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
205
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
206 ## Description : prepare and write json output file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
207 ## Input : $json_file, $scalar
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
208 ## Output : $json_file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
209 ## Usage : my ( $json_file ) = write_json_skel( $csv_file, $scalar ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
210
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
211 =cut
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
212 ## START of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
213 sub write_json_skel {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
214 ## Retrieve Values
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
215 my $self = shift ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
216 my ( $json_file, $scalar ) = @_ ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
217
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
218 my $utf8_encoded_json_text = encode_json $scalar ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
219 open(JSON, '>:utf8', "$$json_file") or die "Cant' create the file $$json_file\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
220 print JSON $utf8_encoded_json_text ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
221 close(JSON) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
222
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
223 return($json_file) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
224 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
225 ## END of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
226
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
227 =head2 METHOD write_html_skel
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
228
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
229 ## Description : prepare and write the html output file
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
230 ## Input : $html_file_name, $html_object, $html_template
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
231 ## Output : $html_file_name
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
232 ## Usage : my ( $html_file_name ) = write_html_skel( $html_file_name, $html_object ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
233
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
234 =cut
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
235 ## START of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
236 sub write_html_skel {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
237 ## Retrieve Values
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
238 my $self = shift ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
239 my ( $html_file_name, $html_object, $pages , $search_condition, $html_template, $js_path, $css_path ) = @_ ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
240
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
241 my $html_file = $$html_file_name ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
242
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
243 if ( defined $html_file ) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
244 open ( HTML, ">$html_file" ) or die "Can't create the output file $html_file " ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
245
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
246 if (-e $html_template) {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
247 my $ohtml = HTML::Template->new(filename => $html_template);
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
248 $ohtml->param( JS_GALAXY_PATH => $js_path, CSS_GALAXY_PATH => $css_path ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
249 $ohtml->param( CONDITIONS => $search_condition ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
250 $ohtml->param( PAGES_NB => $pages ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
251 $ohtml->param( PAGES => $html_object ) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
252 print HTML $ohtml->output ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
253 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
254 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
255 croak "Can't fill any html output : No template available ($html_template)\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
256 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
257
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
258 close (HTML) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
259 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
260 else {
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
261 croak "No output file name available to write HTML file\n" ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
262 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
263 return(\$html_file) ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
264 }
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
265 ## END of SUB
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
266
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
267 1 ;
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
268
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
269
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
270 __END__
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
271
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
272 =head1 SUPPORT
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
273
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
274 You can find documentation for this module with the perldoc command.
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
275
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
276 perldoc writter.pm
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
277
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
278 =head1 Exports
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
279
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
280 =over 4
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
281
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
282 =item :ALL is ...
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
283
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
284 =back
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
285
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
286 =head1 AUTHOR
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
287
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
288 Franck Giacomoni E<lt>franck.giacomoni@clermont.inra.frE<gt>
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
289
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
290 =head1 LICENSE
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
291
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
292 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
293
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
294 =head1 VERSION
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
295
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
296 version 1 : 14 / 08 / 2015
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
297
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
298 version 2 : ??
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
299
023c380900ef Init repository with last massbank_ws_searchspectrum master version
fgiacomoni
parents:
diff changeset
300 =cut