diff 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
line wrap: on
line diff
--- a/lib/hmdb.pm	Thu Jan 10 09:10:14 2019 -0500
+++ b/lib/hmdb.pm	Wed Jan 16 10:18:18 2019 -0500
@@ -203,7 +203,7 @@
     			croak "Internal Server Error $$status..." ;
     		}
     	}
-    	if  ( $$status == 200 ) { print "The HMDB server returns that your request was fulfilled" ; }
+    	if  ( $$status == 200 ) { print "\tThe HMDB server returns that your request (connexion test) was fulfilled\n" ; }
     }
     
     return (1) ;
@@ -237,17 +237,19 @@
 	$req->content('utf8=TRUE&mode='.$mode.'&query_masses='.$masses.'&tolerance='.$delta.'&database=HMDB&commit=Download Results As CSV');
 #	print Dumper $req ; 
 	my $res = $ua->request($req);
+	my $status_line = undef ;
 #	print $res->as_string;
 	if ($res->is_success) {
 	     @page = split ( /\n/, $res->decoded_content ) ;
+	     $status_line = 'OK' ;
 	 } else {
-	 	my $status_line = $res->status_line ;
+	 	$status_line = $res->status_line ;
 	 	($status_line) = ($status_line =~ /(\d+)/);
-	 	croak "HMDB service none available !! Status of the HMDB server is : $status_line\n" ;
+	 	warn "\tHMDB service issue !! the server returned a $status_line HTTP error\n" ;
 	 }
 	
 	
-	return (\@page) ;
+	return (\@page, $status_line) ;
 }
 ## END of SUB
 
@@ -279,12 +281,13 @@
     	## NEW HMDB format V4.0 - dec2017
 		if ($line !~ /query_mass,compound_id,compound_name,kegg_id,formula,monoisotopic_mass,adduct,adduct_type,adduct_m\/z,delta\(ppm\)/) {
     		
-    		if ( $line =~ /(\d+\.\d+),(\w+),(.*),([\w|n\/a]+)\s*,(\w+),(\d+\.\d+),(.*),(\+|\-),(\d+\.\d+),(\d+)/  ) {
+    		if ( $line =~ /(\d+\.\d+),(\w+),(.*),([\w|n\/a|\s+]+)\s*,(\w+),(\d+\.\d+),(.*),(\+|\-),(\d+\.\d+),(\d+)/  ) {
     			my @entry = ("$1","$2","$3","$4","$5","$6","$7","$8","$9","$10") ;
 
     			if ( !exists $result_by_entry{$entry[0]} ) { $result_by_entry{$entry[0]} = [] ; }
     			    		
 	    		$features{ENTRY_ENTRY_ID} = $entry[1] ;
+	    		$features{ENTRY_ENTRY_NAME} = $entry[2] ;
 	    		$features{ENTRY_FORMULA} = $entry[4] ;
 	    		$features{ENTRY_CPD_MZ} = $entry[5] ;
 	    		$features{ENTRY_ADDUCT} = $entry[6] ;
@@ -295,9 +298,17 @@
 	    		my %temp = %features ;
 	    		push (@{$result_by_entry{$entry[0]} }, \%temp) ;
     		}
-    		else {
-    			warn "The parsed line ($line) does not match your pattern\n " ;
-    		}
+#    		elsif ($line =~ /(\d+\.\d+)/) { #
+#    			## 288.082286511284,HMDB0002255,R-Methylmalonyl-CoA, C01213 ,C25H40N7O19P3S,867.131252359,M-3H,-,288.036475,159
+#    			## 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
+#    			## 174.034120330029,HMDB0011723,2-Methylhippuric acid,	 C01586,C10H11NO3,193.073893223,M-H20-H,-,174.055503,123
+#    			## 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
+#    			## 214.018826827064,HMDB0011723,2-Methylhippuric acid,	 C01586,C10H11NO3,193.073893223,M+Na-2H,-,214.048559,139
+#    		}
+#    		else {
+#    			
+#    			warn "The parsed line ($line) does not match your pattern\n " ;
+#    		}
     	}
     	else {
     		next ;
@@ -597,7 +608,11 @@
     				}
     			}
     			else {
-    				warn "This HMDB id doesn't match any collected ids\n" ;
+#    				if ($features) {
+#    					warn "This HMDB id doesn't match any collected ids\n" ;	
+#    				}
+    				$entries->{'ENTRY_ENTRY_INCHI'} = 'NONEDATA' ;
+    				$entries->{'ENTRY_ENTRY_LOGP'} = 'NONEDATA' ;
     			}
     		}
     	}
@@ -899,6 +914,8 @@
     my $self = shift ;
     my ( $header, $init_mzs, $entries ) = @_ ;
     
+#    print Dumper $entries ;
+    
     my @hmdb_matrix = () ;
     
     if ( defined $header ) {
@@ -934,12 +951,27 @@
     				
 	    		push ( @anti_redondant, $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ) ;
 	    		##
-	    		my $hmdb_name = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME}  ;
-	    		my $hmdb_id = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID}  ;
-	    		my $hmdb_formula = $entries->[$index_mz][$index_entries]{ENTRY_FORMULA}  ;
-	    		my $hmdb_cpd_mz = $entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ}  ;
-	    		my $hmdb_adduct = $entries->[$index_mz][$index_entries]{ENTRY_ADDUCT}  ;
-	    		my $hmdb_delta = $entries->[$index_mz][$index_entries]{ENTRY_DELTA}  ;
+	    		
+	    		my ($hmdb_name, $hmdb_id, $hmdb_formula, $hmdb_cpd_mz, $hmdb_adduct, $hmdb_delta) = (undef, undef, undef, undef, undef, undef) ;
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME} )	{	$hmdb_name = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_NAME} ; 	}
+	    		else 															{	$hmdb_name = 'UNKNOWN' ; }
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} )	{	$hmdb_id = $entries->[$index_mz][$index_entries]{ENTRY_ENTRY_ID} ; 	}
+	    		else 															{	$hmdb_id = 0 ; }
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_FORMULA} )	{	$hmdb_formula = $entries->[$index_mz][$index_entries]{ENTRY_FORMULA} ; 	}
+	    		else 															{	$hmdb_formula = 'N/A'  ; }
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ} )	{	$hmdb_cpd_mz = $entries->[$index_mz][$index_entries]{ENTRY_CPD_MZ} ; 	}
+	    		else 															{	$hmdb_cpd_mz = 'N/A' ; }
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_ADDUCT} )	{	$hmdb_adduct = $entries->[$index_mz][$index_entries]{ENTRY_ADDUCT} ; 	}
+	    		else 															{	$hmdb_adduct = 'N/A'  ; }
+	    		
+	    		if ($entries->[$index_mz][$index_entries]{ENTRY_DELTA} )	{	$hmdb_delta = $entries->[$index_mz][$index_entries]{ENTRY_DELTA} ; 	}
+	    		else 															{	$hmdb_delta = 0 ; }
+	    		
 		    	
 		    	## METLIN data display model
 		   		## entry1= ENTRY_DELTA::ENTRY_ENTRY_NAME::ENTRY_CPD_MZ::ENTRY_FORMULA::ENTRY_ADDUCT::ENTRY_ENTRY_ID | entry2=VAR1::VAR2::VAR3::VAR4|...