Mercurial > repos > fgiacomoni > hmdb_ms_search
diff lib/hmdb.pm @ 14:625fa968d99a draft
Master branch Updating - - Fxx
author | fgiacomoni |
---|---|
date | Thu, 10 Jan 2019 09:10:14 -0500 |
parents | c32280662103 |
children | beb9619263b0 |
line wrap: on
line diff
--- a/lib/hmdb.pm Tue Oct 02 04:59:13 2018 -0400 +++ b/lib/hmdb.pm Thu Jan 10 09:10:14 2019 -0500 @@ -195,12 +195,15 @@ croak "No http status is defined for the distant server" ; } else { - unless ( $$status == 200 ) { + unless ( $$status == 200 ) { if ( $$status == 504 ) { croak "Gateway Timeout: The HMDB server was acting as a gateway or proxy and did not receive a timely response from the upstream server" ; } + if ( $$status == 500 ) { croak "Internal Server Error: The HMDB server returns an unexpected internal server error" ; } else { ## None supported http code error ## + croak "Internal Server Error $$status..." ; } } + if ( $$status == 200 ) { print "The HMDB server returns that your request was fulfilled" ; } } return (1) ; @@ -232,7 +235,7 @@ $req->content_type('application/x-www-form-urlencoded'); $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); # print $res->as_string; if ($res->is_success) { @@ -269,26 +272,10 @@ my %features = () ; # print Dumper $csv ; +# print Dumper $masses ; +# print Dumper $max_query ; foreach my $line (@{$csv}) { - ## HMDB csv output - [DEPRECATED]... -# if ($line !~ /query_mass,compound_id,formula,compound_mass,adduct,adduct_type,adduct_mass,delta/) { -# my @entry = split(/,/, $line) ; -# -# if ( !exists $result_by_entry{$entry[0]} ) { $result_by_entry{$entry[0]} = [] ; } -# -# $features{ENTRY_ENTRY_ID} = $entry[1] ; -# $features{ENTRY_FORMULA} = $entry[2] ; -# $features{ENTRY_CPD_MZ} = $entry[3] ; -# $features{ENTRY_ADDUCT} = $entry[4] ; -# $features{ENTRY_ADDUCT_TYPE} = $entry[5] ; -# $features{ENTRY_ADDUCT_MZ} = $entry[6] ; -# $features{ENTRY_DELTA} = $entry[7] ; -# -# my %temp = %features ; -# -# push (@{$result_by_entry{$entry[0]} }, \%temp) ; -# } ## 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\)/) { @@ -341,6 +328,7 @@ else {push (@results, [] ) ;} ; } + return(\@results) ; } ## END of SUB @@ -1030,7 +1018,8 @@ my $self = shift ; my ( $csv_file, $rows ) = @_ ; - my $ocsv = lib::csv::new( {is_binary => 1 , quote_binary => 0, quote_char => undef }) ; +# my $ocsv = lib::csv::new( {is_binary => 1 , quote_binary => 0, quote_char => undef }) ; + my $ocsv = lib::csv::new() ; my $csv = $ocsv->get_csv_object("\t") ; $ocsv->write_csv_from_arrays($csv, $$csv_file, $rows) ; @@ -1053,7 +1042,7 @@ my ( $masses, $ids, $results, $file, ) = @_ ; open(CSV, '>:utf8', "$file") or die "Cant' create the file $file\n" ; - print CSV "ID\tQuery(Da)\tDelta\tMetabolite_Name\tCpd_MW(Da)\tFormula\tAdduct\tAdduct_MW(Da)\tHMDB_ID\n" ; + print CSV "ID\tQuery(Da)\tDelta(ppm)\tMetabolite_Name\tCpd_MW(Da)\tFormula\tAdduct\tAdduct_MW(Da)\tHMDB_ID\n" ; my $i = 0 ;