comparison lib/hmdb.pm @ 15:beb9619263b0 draft

Master branch Updating - - Fxx
author fgiacomoni
date Wed, 16 Jan 2019 10:18:18 -0500
parents 625fa968d99a
children 49f87ddb2c78
comparison
equal deleted inserted replaced
14:625fa968d99a 15:beb9619263b0
201 else { 201 else {
202 ## None supported http code error ## 202 ## None supported http code error ##
203 croak "Internal Server Error $$status..." ; 203 croak "Internal Server Error $$status..." ;
204 } 204 }
205 } 205 }
206 if ( $$status == 200 ) { print "The HMDB server returns that your request was fulfilled" ; } 206 if ( $$status == 200 ) { print "\tThe HMDB server returns that your request (connexion test) was fulfilled\n" ; }
207 } 207 }
208 208
209 return (1) ; 209 return (1) ;
210 } 210 }
211 ## END of SUB 211 ## END of SUB
235 235
236 $req->content_type('application/x-www-form-urlencoded'); 236 $req->content_type('application/x-www-form-urlencoded');
237 $req->content('utf8=TRUE&mode='.$mode.'&query_masses='.$masses.'&tolerance='.$delta.'&database=HMDB&commit=Download Results As CSV'); 237 $req->content('utf8=TRUE&mode='.$mode.'&query_masses='.$masses.'&tolerance='.$delta.'&database=HMDB&commit=Download Results As CSV');
238 # print Dumper $req ; 238 # print Dumper $req ;
239 my $res = $ua->request($req); 239 my $res = $ua->request($req);
240 my $status_line = undef ;
240 # print $res->as_string; 241 # print $res->as_string;
241 if ($res->is_success) { 242 if ($res->is_success) {
242 @page = split ( /\n/, $res->decoded_content ) ; 243 @page = split ( /\n/, $res->decoded_content ) ;
244 $status_line = 'OK' ;
243 } else { 245 } else {
244 my $status_line = $res->status_line ; 246 $status_line = $res->status_line ;
245 ($status_line) = ($status_line =~ /(\d+)/); 247 ($status_line) = ($status_line =~ /(\d+)/);
246 croak "HMDB service none available !! Status of the HMDB server is : $status_line\n" ; 248 warn "\tHMDB service issue !! the server returned a $status_line HTTP error\n" ;
247 } 249 }
248 250
249 251
250 return (\@page) ; 252 return (\@page, $status_line) ;
251 } 253 }
252 ## END of SUB 254 ## END of SUB
253 255
254 =head2 METHOD parse_hmdb_csv_results 256 =head2 METHOD parse_hmdb_csv_results
255 257
277 279
278 foreach my $line (@{$csv}) { 280 foreach my $line (@{$csv}) {
279 ## NEW HMDB format V4.0 - dec2017 281 ## NEW HMDB format V4.0 - dec2017
280 if ($line !~ /query_mass,compound_id,compound_name,kegg_id,formula,monoisotopic_mass,adduct,adduct_type,adduct_m\/z,delta\(ppm\)/) { 282 if ($line !~ /query_mass,compound_id,compound_name,kegg_id,formula,monoisotopic_mass,adduct,adduct_type,adduct_m\/z,delta\(ppm\)/) {
281 283
282 if ( $line =~ /(\d+\.\d+),(\w+),(.*),([\w|n\/a]+)\s*,(\w+),(\d+\.\d+),(.*),(\+|\-),(\d+\.\d+),(\d+)/ ) { 284 if ( $line =~ /(\d+\.\d+),(\w+),(.*),([\w|n\/a|\s+]+)\s*,(\w+),(\d+\.\d+),(.*),(\+|\-),(\d+\.\d+),(\d+)/ ) {
283 my @entry = ("$1","$2","$3","$4","$5","$6","$7","$8","$9","$10") ; 285 my @entry = ("$1","$2","$3","$4","$5","$6","$7","$8","$9","$10") ;
284 286
285 if ( !exists $result_by_entry{$entry[0]} ) { $result_by_entry{$entry[0]} = [] ; } 287 if ( !exists $result_by_entry{$entry[0]} ) { $result_by_entry{$entry[0]} = [] ; }
286 288
287 $features{ENTRY_ENTRY_ID} = $entry[1] ; 289 $features{ENTRY_ENTRY_ID} = $entry[1] ;
290 $features{ENTRY_ENTRY_NAME} = $entry[2] ;
288 $features{ENTRY_FORMULA} = $entry[4] ; 291 $features{ENTRY_FORMULA} = $entry[4] ;
289 $features{ENTRY_CPD_MZ} = $entry[5] ; 292 $features{ENTRY_CPD_MZ} = $entry[5] ;
290 $features{ENTRY_ADDUCT} = $entry[6] ; 293 $features{ENTRY_ADDUCT} = $entry[6] ;
291 $features{ENTRY_ADDUCT_TYPE} = $entry[7] ; 294 $features{ENTRY_ADDUCT_TYPE} = $entry[7] ;
292 $features{ENTRY_ADDUCT_MZ} = $entry[8] ; 295 $features{ENTRY_ADDUCT_MZ} = $entry[8] ;
293 $features{ENTRY_DELTA} = $entry[9] ; 296 $features{ENTRY_DELTA} = $entry[9] ;
294 297
295 my %temp = %features ; 298 my %temp = %features ;
296 push (@{$result_by_entry{$entry[0]} }, \%temp) ; 299 push (@{$result_by_entry{$entry[0]} }, \%temp) ;
297 } 300 }
298 else { 301 # elsif ($line =~ /(\d+\.\d+)/) { #
299 warn "The parsed line ($line) does not match your pattern\n " ; 302 # ## 288.082286511284,HMDB0002255,R-Methylmalonyl-CoA, C01213 ,C25H40N7O19P3S,867.131252359,M-3H,-,288.036475,159
300 } 303 # ## 283.108004472276,"Bicyclo_3,1,1heptane-2,3-diol,2,6,6_trimethyl","2,3-Pinanediol",n/a,C10H18O2,170.13067982,M+TFA-H,-,283.116266,29
304 # ## 174.034120330029,HMDB0011723,2-Methylhippuric acid, C01586,C10H11NO3,193.073893223,M-H20-H,-,174.055503,123
305 # ## 193.139160745841,HMDB0012109,"7-[(1R,2R,3R,5S)-3,5-Dihydroxy-2-[(1E,3S)-3-hydroxyoct-1-en-1-yl]cyclopentyl]-5,6-dihydroxyheptanoic acid", C06475,C20H36O7,388.246103506,M-2H,-,193.115776,121
306 # ## 214.018826827064,HMDB0011723,2-Methylhippuric acid, C01586,C10H11NO3,193.073893223,M+Na-2H,-,214.048559,139
307 # }
308 # else {
309 #
310 # warn "The parsed line ($line) does not match your pattern\n " ;
311 # }
301 } 312 }
302 else { 313 else {
303 next ; 314 next ;
304 } 315 }
305 } ## end foreach 316 } ## end foreach
595 else { 606 else {
596 $entries->{'ENTRY_ENTRY_LOGP'} = 'NA' ; 607 $entries->{'ENTRY_ENTRY_LOGP'} = 'NA' ;
597 } 608 }
598 } 609 }
599 else { 610 else {
600 warn "This HMDB id doesn't match any collected ids\n" ; 611 # if ($features) {
612 # warn "This HMDB id doesn't match any collected ids\n" ;
613 # }
614 $entries->{'ENTRY_ENTRY_INCHI'} = 'NONEDATA' ;
615 $entries->{'ENTRY_ENTRY_LOGP'} = 'NONEDATA' ;
601 } 616 }
602 } 617 }
603 } 618 }
604 } 619 }
605 620
897 sub set_hmdb_matrix_object_with_ids { 912 sub set_hmdb_matrix_object_with_ids {
898 ## Retrieve Values 913 ## Retrieve Values
899 my $self = shift ; 914 my $self = shift ;
900 my ( $header, $init_mzs, $entries ) = @_ ; 915 my ( $header, $init_mzs, $entries ) = @_ ;
901 916
917 # print Dumper $entries ;
918
902 my @hmdb_matrix = () ; 919 my @hmdb_matrix = () ;
903 920
904 if ( defined $header ) { 921 if ( defined $header ) {
905 my @headers = () ; 922 my @headers = () ;
906 923
932 949
933 if ( $check_rebond == 0 ) { 950 if ( $check_rebond == 0 ) {
934 951
935 push ( @anti_redondant, $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ) ; 952 push ( @anti_redondant, $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ) ;
936 ## 953 ##
937 my $hmdb_name = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME} ; 954
938 my $hmdb_id = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ; 955 my ($hmdb_name, $hmdb_id, $hmdb_formula, $hmdb_cpd_mz, $hmdb_adduct, $hmdb_delta) = (undef, undef, undef, undef, undef, undef) ;
939 my $hmdb_formula = $entries->[$index_mz][$index_entries]{ENTRY_FORMULA} ; 956
940 my $hmdb_cpd_mz = $entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ} ; 957 if ($entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME} ) { $hmdb_name = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME} ; }
941 my $hmdb_adduct = $entries->[$index_mz][$index_entries]{ENTRY_ADDUCT} ; 958 else { $hmdb_name = 'UNKNOWN' ; }
942 my $hmdb_delta = $entries->[$index_mz][$index_entries]{ENTRY_DELTA} ; 959
960 if ($entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ) { $hmdb_id = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ; }
961 else { $hmdb_id = 0 ; }
962
963 if ($entries->[$index_mz][$index_entries]{ENTRY_FORMULA} ) { $hmdb_formula = $entries->[$index_mz][$index_entries]{ENTRY_FORMULA} ; }
964 else { $hmdb_formula = 'N/A' ; }
965
966 if ($entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ} ) { $hmdb_cpd_mz = $entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ} ; }
967 else { $hmdb_cpd_mz = 'N/A' ; }
968
969 if ($entries->[$index_mz][$index_entries]{ENTRY_ADDUCT} ) { $hmdb_adduct = $entries->[$index_mz][$index_entries]{ENTRY_ADDUCT} ; }
970 else { $hmdb_adduct = 'N/A' ; }
971
972 if ($entries->[$index_mz][$index_entries]{ENTRY_DELTA} ) { $hmdb_delta = $entries->[$index_mz][$index_entries]{ENTRY_DELTA} ; }
973 else { $hmdb_delta = 0 ; }
974
943 975
944 ## METLIN data display model 976 ## METLIN data display model
945 ## entry1= ENTRY_DELTA::ENTRY_ENTRY_NAME::ENTRY_CPD_MZ::ENTRY_FORMULA::ENTRY_ADDUCT::ENTRY_ENTRY_ID | entry2=VAR1::VAR2::VAR3::VAR4|... 977 ## entry1= ENTRY_DELTA::ENTRY_ENTRY_NAME::ENTRY_CPD_MZ::ENTRY_FORMULA::ENTRY_ADDUCT::ENTRY_ENTRY_ID | entry2=VAR1::VAR2::VAR3::VAR4|...
946 my $entry = $hmdb_delta.'::['."$hmdb_name".']::'.$hmdb_cpd_mz.'::'.$hmdb_formula.'::['.$hmdb_adduct.']::'.$hmdb_id ; 978 my $entry = $hmdb_delta.'::['."$hmdb_name".']::'.$hmdb_cpd_mz.'::'.$hmdb_formula.'::['.$hmdb_adduct.']::'.$hmdb_id ;
947 979