comparison wsdl_hmdb.pl @ 15:beb9619263b0 draft

Master branch Updating - - Fxx
author fgiacomoni
date Wed, 16 Jan 2019 10:18:18 -0500
parents 625fa968d99a
children 8b2fbd449ffd
comparison
equal deleted inserted replaced
14:625fa968d99a 15:beb9619263b0
26 my ( $help ) = undef ; 26 my ( $help ) = undef ;
27 my ( $mass ) = undef ; 27 my ( $mass ) = undef ;
28 my ( $masses_file, $col_id, $col_mass, $header_choice, $nbline_header ) = ( undef, undef, undef, undef, undef ) ; 28 my ( $masses_file, $col_id, $col_mass, $header_choice, $nbline_header ) = ( undef, undef, undef, undef, undef ) ;
29 my $max_query = undef ; 29 my $max_query = undef ;
30 my ( $delta, $molecular_species, $out_tab, $out_html, $out_xls ) = ( undef, undef, undef, undef, undef ) ; 30 my ( $delta, $molecular_species, $out_tab, $out_html, $out_xls ) = ( undef, undef, undef, undef, undef ) ;
31 my $advancedFeatures = 0 ;
32 my $VERBOSE = ( 3 ) ;
31 33
32 34
33 #============================================================================= 35 #=============================================================================
34 # Manage EXCEPTIONS 36 # Manage EXCEPTIONS
35 #============================================================================= 37 #=============================================================================
44 "mode:s" => \$molecular_species, ## Molecular species (positive/negative/neutral) 46 "mode:s" => \$molecular_species, ## Molecular species (positive/negative/neutral)
45 "maxquery:i" => \$max_query, ## Maximum query return (default is 20 entries by query // min 1 & max 50 ) 47 "maxquery:i" => \$max_query, ## Maximum query return (default is 20 entries by query // min 1 & max 50 )
46 "output_tabular:s" => \$out_tab, ## option : path to the ouput (tabular : input+results ) 48 "output_tabular:s" => \$out_tab, ## option : path to the ouput (tabular : input+results )
47 "output_html|v:s" => \$out_html, ## option : path to the results view (output2) 49 "output_html|v:s" => \$out_html, ## option : path to the results view (output2)
48 "output_xlsx:s" => \$out_xls, ## option : path to the xls-like format output 50 "output_xlsx:s" => \$out_xls, ## option : path to the xls-like format output
51 "advancedFeatures:s"=> \$advancedFeatures, ## option : set to 1 to get advanced options or 0 to get first level only.
52 "verbose:i" => \$VERBOSE, ## VERBOSE Of the tool
49 ) ; 53 ) ;
50 54
51 #============================================================================= 55 #=============================================================================
52 # EXCEPTIONS 56 # EXCEPTIONS
53 #============================================================================= 57 #=============================================================================
55 59
56 #============================================================================= 60 #=============================================================================
57 # MAIN SCRIPT 61 # MAIN SCRIPT
58 #============================================================================= 62 #=============================================================================
59 63
64 print "* * * The hmdb client program is launched: * * *\n" if ($VERBOSE>1) ;
60 65
61 ## -------------- Conf file ------------------------ : 66 ## -------------- Conf file ------------------------ :
62 my ( $CONF ) = ( undef ) ; 67 my ( $CONF ) = ( undef ) ;
63 foreach my $conf ( <$binPath/*.cfg> ) { 68 foreach my $conf ( <$binPath/*.cfg> ) {
64 my $oConf = lib::conf::new() ; 69 my $oConf = lib::conf::new() ;
76 ## --------------- Global parameters ---------------- : 81 ## --------------- Global parameters ---------------- :
77 my ( $ids, $masses, $results ) = ( undef, undef, undef ) ; 82 my ( $ids, $masses, $results ) = ( undef, undef, undef ) ;
78 my ( $complete_rows, $nb_pages_for_html_out ) = ( undef, 1 ) ; 83 my ( $complete_rows, $nb_pages_for_html_out ) = ( undef, 1 ) ;
79 my $metabocard_features = undef ; 84 my $metabocard_features = undef ;
80 my $search_condition = "Search params : Molecular specie = $molecular_species / delta (mass-to-charge ratio) = $delta" ; 85 my $search_condition = "Search params : Molecular specie = $molecular_species / delta (mass-to-charge ratio) = $delta" ;
86
87 print "\t with $search_condition\n" if ($VERBOSE>1) ;
81 88
82 ## --------------- retrieve input data -------------- : 89 ## --------------- retrieve input data -------------- :
83 90
84 ## manage only one mass 91 ## manage only one mass
85 if ( ( defined $mass ) and ( $mass ne '' ) ) { 92 if ( ( defined $mass ) and ( $mass ne '' ) ) {
105 else { 112 else {
106 warn "[warning] Input data are missing : none mass or file of masses\n" ; 113 warn "[warning] Input data are missing : none mass or file of masses\n" ;
107 &help ; 114 &help ;
108 } 115 }
109 #print Dumper $masses ; 116 #print Dumper $masses ;
117
110 ## ---------------- launch queries -------------------- : 118 ## ---------------- launch queries -------------------- :
111 119
112 if ( ( defined $delta ) and ( $delta > 0 ) and ( defined $molecular_species ) and ( $molecular_species ne '' ) ) { 120 if ( ( defined $delta ) and ( $delta > 0 ) and ( defined $molecular_species ) and ( $molecular_species ne '' ) ) {
113 ## prepare masses list and execute query 121 ## prepare masses list and execute query
114 my $oHmdb = lib::hmdb::new() ; 122 my $oHmdb = lib::hmdb::new() ;
115 my $hmdb_pages = undef ; 123 my $hmdb_pages = undef ;
124 my $status = undef ;
116 my $hmdb_ids = undef ; 125 my $hmdb_ids = undef ;
117 126
118 $results = [] ; # prepare arrays ref 127 $results = [] ; # prepare arrays ref
119 my $submasses = $oHmdb->extract_sub_mz_lists($masses, $CONF->{HMDB_LIMITS} ) ; 128 my $submasses = $oHmdb->extract_sub_mz_lists($masses, $CONF->{HMDB_LIMITS} ) ;
120 129
130 print "\t and ".scalar(@$masses)." masses are submitted as ".scalar(@$submasses)." queries to HMDB \n\n" if ($VERBOSE>1) ;
131
121 ## get the hmdb server status by a test query - continuous queries or kill script. 132 ## get the hmdb server status by a test query - continuous queries or kill script.
122 my $status = $oHmdb->test_matches_from_hmdb_ua() ; 133 $status = $oHmdb->test_matches_from_hmdb_ua() ;
123 $oHmdb->check_state_from_hmdb_ua($status) ; ## can kill the script execution 134 $oHmdb->check_state_from_hmdb_ua($status) ; ## can kill the script execution
124 135
136 my $cluster = 1 ;
125 foreach my $mzs ( @{$submasses} ) { 137 foreach my $mzs ( @{$submasses} ) {
126 # print Dumper $mzs ; 138 # print Dumper $mzs ;
127 my $result = undef ; 139 my $result = undef ;
140
128 my ( $hmdb_masses, $nb_masses_to_submit ) = $oHmdb->prepare_multi_masses_query($mzs) ; 141 my ( $hmdb_masses, $nb_masses_to_submit ) = $oHmdb->prepare_multi_masses_query($mzs) ;
129 $hmdb_pages = $oHmdb->get_matches_from_hmdb_ua($hmdb_masses, $delta, $molecular_species) ; 142
130 143 print "\t Submission of m/z cluster ".sprintf '%04s',$cluster."" if ($VERBOSE>1) ;
131 # print Dumper $hmdb_pages ; 144
132 145 ($hmdb_pages, $status) = $oHmdb->get_matches_from_hmdb_ua($hmdb_masses, $delta, $molecular_species) ;
133 sleep(2) ; 146 print "...HMDB reply results with status: $status\n" if ($VERBOSE>1) ;
147
148 print Dumper $hmdb_pages ;
149
150 sleep(1) ;
134 151
135 ($result) = $oHmdb->parse_hmdb_csv_results($hmdb_pages, $mzs, $max_query) ; ## hash format result 152 ($result) = $oHmdb->parse_hmdb_csv_results($hmdb_pages, $mzs, $max_query) ; ## hash format result
136 ## This previous step return results with cutoff on the number of entries returned ! 153 ## This previous step return results with cutoff on the number of entries returned !
137 $results = [ @$results, @$result ] ; 154 $results = [ @$results, @$result ] ;
138 155
139 sleep(2) ; 156 # sleep(1) ;
140 } 157 $cluster ++ ;
141 158 }
142 ## foreach metabolite get its own metabocard 159
143 $hmdb_ids = $oHmdb->get_unik_ids_from_results($results) ; 160 ## Add more information of each found metabolite (1 for extra or 0 by default)
144 # $hmdb_ids->{'HMDB03125'} = 1 , 161 if ($advancedFeatures > 0) {
145 $metabocard_features = $oHmdb->get_hmdb_metabocard_from_id($hmdb_ids, $CONF->{'HMDB_METABOCARD_URL'}) ; ## Try to multithread the querying 162
146 163 ## foreach metabolite get its own metabocard
147 ## Map metabocards with results (add supplementary data) 164 $hmdb_ids = $oHmdb->get_unik_ids_from_results($results) ;
148 165
149 # print Dumper $results ; 166 print "\tComplementary annotation: asking for ".scalar(@$hmdb_ids)."metabocards\n" if ($VERBOSE>1) ;
150 # print Dumper $hmdb_ids ; 167
151 # print Dumper $metabocard_features ; 168 # $hmdb_ids->{'HMDB03125'} = 1 ,
152 169 $metabocard_features = $oHmdb->get_hmdb_metabocard_from_id($hmdb_ids, $CONF->{'HMDB_METABOCARD_URL'}) ; ## Try to multithread the querying
153 if ( ( defined $results ) and ( defined $metabocard_features ) ) { 170 # print Dumper $results ;
154 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, $metabocard_features) ; 171 # print Dumper $hmdb_ids ;
155 } 172 # print Dumper $metabocard_features ;
173 ## Map metabocards with results (add supplementary data)
174 if ( ( defined $results ) and ( defined $metabocard_features ) ) {
175 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, $metabocard_features) ;
176 }
177 }
178 else {
179 print "\tNo complementary annotation asked\n" if ($VERBOSE>1) ;
180 ## Fill with msg not asked advanced annotation
181 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, undef) ;
182 }
183
184
156 185
157 ## Uses N mz and theirs entries per page (see config file). 186 ## Uses N mz and theirs entries per page (see config file).
158 # how many pages you need with your input mz list? 187 # how many pages you need with your input mz list?
159 $nb_pages_for_html_out = ceil( scalar(@{$masses} ) / $CONF->{HTML_ENTRIES_PER_PAGE} ) ; 188 $nb_pages_for_html_out = ceil( scalar(@{$masses} ) / $CONF->{HTML_ENTRIES_PER_PAGE} ) ;
160 189
163 else { 192 else {
164 croak "Can't work with HMDB : missing paramaters (list of masses, delta or molecular species)\n" ; 193 croak "Can't work with HMDB : missing paramaters (list of masses, delta or molecular species)\n" ;
165 } ## end ELSE 194 } ## end ELSE
166 195
167 ## -------------- Produce HTML/CSV output ------------------ : 196 ## -------------- Produce HTML/CSV output ------------------ :
197 print "\n\tProducing html and tabular outputs\n" if ($VERBOSE>1) ;
168 198
169 if ( ( defined $out_html ) and ( defined $results ) ) { 199 if ( ( defined $out_html ) and ( defined $results ) ) {
170 my $oHtml = lib::hmdb::new() ; 200 my $oHtml = lib::hmdb::new() ;
171 my ($tbody_object) = $oHtml->set_html_tbody_object( $nb_pages_for_html_out, $CONF->{HTML_ENTRIES_PER_PAGE} ) ; 201 my ($tbody_object) = $oHtml->set_html_tbody_object( $nb_pages_for_html_out, $CONF->{HTML_ENTRIES_PER_PAGE} ) ;
172 ($tbody_object) = $oHtml->add_mz_to_tbody_object($tbody_object, $CONF->{HTML_ENTRIES_PER_PAGE}, $masses, $ids) ; 202 ($tbody_object) = $oHtml->add_mz_to_tbody_object($tbody_object, $CONF->{HTML_ENTRIES_PER_PAGE}, $masses, $ids) ;
207 if ( ( defined $out_xls ) and ( defined $results ) ) { 237 if ( ( defined $out_xls ) and ( defined $results ) ) {
208 my $ocsv = lib::hmdb::new() ; 238 my $ocsv = lib::hmdb::new() ;
209 $ocsv->write_csv_one_mass($masses, $ids, $results, $out_xls) ; 239 $ocsv->write_csv_one_mass($masses, $ids, $results, $out_xls) ;
210 } 240 }
211 241
242 print "\n* * * The hmdb client program ended * * *\n" if ($VERBOSE>1) ;
212 243
213 #==================================================================================== 244 #====================================================================================
214 # Help subroutine called with -h option 245 # Help subroutine called with -h option
215 # number of arguments : 0 246 # number of arguments : 0
216 # Argument(s) : 247 # Argument(s) :