comparison wsdl_hmdb.pl @ 21:63ba1cb240b7 draft

Prod branch Updating - - Fxx
author fgiacomoni
date Thu, 14 Feb 2019 08:36:52 -0500
parents b5a1d5e43685
children 453fbe98925a
comparison
equal deleted inserted replaced
20:b5a1d5e43685 21:63ba1cb240b7
25 ## Initialized values 25 ## Initialized values
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 ( $adductType, $delta, $molecular_species, $out_tab, $out_html, $out_xls ) = ( undef, undef, undef, undef, undef, undef ) ;
31 my $advancedFeatures = 0 ; 31 my $advancedFeatures = 0 ;
32 my $VERBOSE = ( 3 ) ; 32 my $VERBOSE = ( 3 ) ;
33 33
34 34
35 #============================================================================= 35 #=============================================================================
40 "mass:s" => \$mass, ## option : one masse 40 "mass:s" => \$mass, ## option : one masse
41 "masses:s" => \$masses_file, ## option : path to the input 41 "masses:s" => \$masses_file, ## option : path to the input
42 "header_choice:s" => \$header_choice, ## Presence or not of header in tabular file 42 "header_choice:s" => \$header_choice, ## Presence or not of header in tabular file
43 "nblineheader:i" => \$nbline_header, ## numbre of header line present in file 43 "nblineheader:i" => \$nbline_header, ## numbre of header line present in file
44 "colfactor:i" => \$col_mass, ## Column id for retrieve formula list in tabular file 44 "colfactor:i" => \$col_mass, ## Column id for retrieve formula list in tabular file
45 "adduct_type:s" => \$adductType, ## A list of selected adducts
45 "delta:f" => \$delta, 46 "delta:f" => \$delta,
46 "mode:s" => \$molecular_species, ## Molecular species (positive/negative/neutral) 47 "mode:s" => \$molecular_species, ## Molecular species (positive/negative/neutral)
47 "maxquery:i" => \$max_query, ## Maximum query return (default is 20 entries by query // min 1 & max 50 ) 48 "maxquery:i" => \$max_query, ## Maximum query return (default is 20 entries by query // min 1 & max 50 )
48 "output_tabular:s" => \$out_tab, ## option : path to the ouput (tabular : input+results ) 49 "output_tabular:s" => \$out_tab, ## option : path to the ouput (tabular : input+results )
49 "output_html|v:s" => \$out_html, ## option : path to the results view (output2) 50 "output_html|v:s" => \$out_html, ## option : path to the results view (output2)
50 "output_xlsx:s" => \$out_xls, ## option : path to the xls-like format output 51 "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 "advancedFeatures:i"=> \$advancedFeatures, ## option : set to 1 to get advanced options or 0 to get first level only.
52 "verbose:i" => \$VERBOSE, ## VERBOSE Of the tool 53 "verbose:i" => \$VERBOSE, ## VERBOSE Of the tool
53 ) ; 54 ) ;
54 55
55 #============================================================================= 56 #=============================================================================
56 # EXCEPTIONS 57 # EXCEPTIONS
82 my ( $ids, $masses, $results ) = ( undef, undef, undef ) ; 83 my ( $ids, $masses, $results ) = ( undef, undef, undef ) ;
83 my ( $complete_rows, $nb_pages_for_html_out ) = ( undef, 1 ) ; 84 my ( $complete_rows, $nb_pages_for_html_out ) = ( undef, 1 ) ;
84 my $metabocard_features = undef ; 85 my $metabocard_features = undef ;
85 my $search_condition = "Search params : Molecular specie = $molecular_species / delta (mass-to-charge ratio) = $delta" ; 86 my $search_condition = "Search params : Molecular specie = $molecular_species / delta (mass-to-charge ratio) = $delta" ;
86 87
87 print "\t with $search_condition\n" if ($VERBOSE>1) ; 88 print "\twith $search_condition\n" if ($VERBOSE>1) ;
89
90 ## $adductType
91 if (defined $adductType ) {
92 print "\twith Adducts: $adductType\n" if ($VERBOSE>1) ;
93 }
94
88 95
89 ## --------------- retrieve input data -------------- : 96 ## --------------- retrieve input data -------------- :
90 97
91 ## manage only one mass 98 ## manage only one mass
92 if ( ( defined $mass ) and ( $mass ne '' ) ) { 99 if ( ( defined $mass ) and ( $mass ne '' ) ) {
120 if ( ( defined $delta ) and ( $delta > 0 ) and ( defined $molecular_species ) and ( $molecular_species ne '' ) ) { 127 if ( ( defined $delta ) and ( $delta > 0 ) and ( defined $molecular_species ) and ( $molecular_species ne '' ) ) {
121 ## prepare masses list and execute query 128 ## prepare masses list and execute query
122 my $oHmdb = lib::hmdb::new() ; 129 my $oHmdb = lib::hmdb::new() ;
123 my $hmdb_pages = undef ; 130 my $hmdb_pages = undef ;
124 my $status = undef ; 131 my $status = undef ;
125 my $hmdb_ids = undef ; 132 my ($hmdb_ids, $idsNumber) = (undef, 0) ;
126 133
127 $results = [] ; # prepare arrays ref 134 $results = [] ; # prepare arrays ref
128 my $submasses = $oHmdb->extract_sub_mz_lists($masses, $CONF->{HMDB_LIMITS} ) ; 135 my $submasses = $oHmdb->extract_sub_mz_lists($masses, $CONF->{HMDB_LIMITS} ) ;
129 136
130 print "\t and ".scalar(@$masses)." masses are submitted as ".scalar(@$submasses)." queries to HMDB \n\n" if ($VERBOSE>1) ; 137 print "\tand ".scalar(@$masses)." masses are submitted as ".scalar(@$submasses)." queries to HMDB \n\n" if ($VERBOSE>1) ;
131 138
132 ## get the hmdb server status by a test query - continuous queries or kill script. 139 ## get the hmdb server status by a test query - continuous queries or kill script.
133 $status = $oHmdb->testMatchesFromHmdbWithUA() ; 140 $status = $oHmdb->testMatchesFromHmdbWithUA() ;
134 $oHmdb->check_state_from_hmdb_ua($status) ; ## can kill the script execution 141 $oHmdb->check_state_from_hmdb_ua($status) ; ## can kill the script execution
135 142
137 foreach my $mzs ( @{$submasses} ) { 144 foreach my $mzs ( @{$submasses} ) {
138 # print Dumper $mzs ; 145 # print Dumper $mzs ;
139 my $result = undef ; 146 my $result = undef ;
140 147
141 my ( $hmdb_masses, $nb_masses_to_submit ) = $oHmdb->prepare_multi_masses_query($mzs) ; 148 my ( $hmdb_masses, $nb_masses_to_submit ) = $oHmdb->prepare_multi_masses_query($mzs) ;
149 my ($hmdb_adducts, $nb_selected_adducts) = $oHmdb->prepareAdductListFormat($adductType) ;
142 150
143 print "\n\tSubmission of m/z cluster ".sprintf '%04s',$cluster."" if ($VERBOSE>1) ; 151 print "\n\tSubmission of m/z cluster ".sprintf '%04s',$cluster."" if ($VERBOSE>1) ;
144 152
145 ($hmdb_pages, $status) = $oHmdb->getMatchesFromHmdbWithUA($hmdb_masses, $delta, $molecular_species) ; 153 ($hmdb_pages, $status) = $oHmdb->getMatchesFromHmdbWithUA($hmdb_masses, $delta, $molecular_species, $hmdb_adducts) ;
146 print "...HMDB reply results with status: $status\n" if ($VERBOSE>1) ; 154 print "...HMDB reply results with status: $status\n" if ($VERBOSE>1) ;
147 155
148 # print Dumper $hmdb_pages ; 156 # print Dumper $hmdb_pages ;
149 157
150 sleep(1) ; 158 sleep(1) ;
159 167
160 ## Add more information of each found metabolite (1 for extra or 0 by default) 168 ## Add more information of each found metabolite (1 for extra or 0 by default)
161 if ($advancedFeatures > 0) { 169 if ($advancedFeatures > 0) {
162 170
163 ## foreach metabolite get its own metabocard 171 ## foreach metabolite get its own metabocard
164 $hmdb_ids = $oHmdb->get_unik_ids_from_results($results) ; 172 ($hmdb_ids, $idsNumber) = $oHmdb->get_unik_ids_from_results($results) ;
165 173
166 print "\tComplementary annotation: asking for ".scalar(@$results)." metabocards\n" if ($VERBOSE>1) ; 174 print "\tComplementary annotation: asking for $idsNumber metabocards\n" if ($VERBOSE>1) ;
167 175
168 # $hmdb_ids->{'HMDB03125'} = 1 , 176 # $hmdb_ids->{'HMDB03125'} = 1 ,
169 $metabocard_features = $oHmdb->get_hmdb_metabocard_from_id($hmdb_ids, $CONF->{'HMDB_METABOCARD_URL'}) ; ## Try to multithread the querying 177 $metabocard_features = $oHmdb->get_hmdb_metabocard_from_id($hmdb_ids, $CONF->{'HMDB_METABOCARD_URL'}) ; ## Try to multithread the querying
170 # print Dumper $results ; 178 # print Dumper $results ;
171 # print Dumper $hmdb_ids ; 179 # print Dumper $hmdb_ids ;
172 # print Dumper $metabocard_features ; 180 # print Dumper $metabocard_features ;
173 ## Map metabocards with results (add supplementary data) 181 ## Map metabocards with results (add supplementary data)
174 if ( ( defined $results ) and ( defined $metabocard_features ) ) { 182 if ( ( defined $results ) and ( defined $metabocard_features ) ) {
175 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, $metabocard_features) ; 183 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, $metabocard_features) ;
176 } 184 }
177 } 185 }
178 else { 186 else {
179 print "\tNo complementary annotation asked\n" if ($VERBOSE>1) ; 187 print "\tNo complementary annotation asked\n" if ($VERBOSE>1) ;
180 ## Fill with msg not asked advanced annotation 188 ## Fill with msg not asked advanced annotation
181 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, undef) ; 189 $results = $oHmdb->map_suppl_data_on_hmdb_results($results, undef) ;
182 } 190 }
183
184
185 191
186 ## Uses N mz and theirs entries per page (see config file). 192 ## Uses N mz and theirs entries per page (see config file).
187 # how many pages you need with your input mz list? 193 # how many pages you need with your input mz list?
188 $nb_pages_for_html_out = ceil( scalar(@{$masses} ) / $CONF->{HTML_ENTRIES_PER_PAGE} ) ; 194 $nb_pages_for_html_out = ceil( scalar(@{$masses} ) / $CONF->{HTML_ENTRIES_PER_PAGE} ) ;
189 195
325 331
326 version 1.5 : 19 / 01 / 2018 - modify parser to match HMDB V4.0 formats 332 version 1.5 : 19 / 01 / 2018 - modify parser to match HMDB V4.0 formats
327 333
328 version 1.6 : 23 / 01 / 2019 - Manage UA http error and advanced feature from hmdb. 334 version 1.6 : 23 / 01 / 2019 - Manage UA http error and advanced feature from hmdb.
329 335
336 version 1.6.1 : 30 / 01 / 2019 - Adding adducts and fixxing minors bugs and requirements
337
330 =cut 338 =cut