Mercurial > repos > fgiacomoni > hmdb_ms_search
diff lib/hmdb.pm @ 26:76872ac24fb2 draft
master branch Updating with tag :CI_COMMIT_TAG - - Fxx
author | fgiacomoni |
---|---|
date | Wed, 27 Sep 2023 12:21:00 +0000 |
parents | 8f7546d0b925 |
children |
line wrap: on
line diff
--- a/lib/hmdb.pm Tue Jul 05 12:39:15 2022 +0000 +++ b/lib/hmdb.pm Wed Sep 27 12:21:00 2023 +0000 @@ -14,6 +14,8 @@ use HTML::Template ; use XML::Twig ; use Text::CSV ; +use URI::Encode ; +use open qw( :std :encoding(UTF-8) ); use Data::Dumper ; @@ -169,9 +171,16 @@ $nbAdducts = scalar( my @adducts = ( split (/,/, $adductString) ) ) ; ## Converting string into http post format - $adductString =~ s/\+/%2B/g ; - $adductString =~ s/,/%20/g ; - $formattedAdductString = $adductString ; +# $adductString =~ s/\+/%2B/g ; +# $adductString =~ s/,/%20/g ; +# $formattedAdductString = $adductString ; + + my $uri = URI::Encode->new( { encode_reserved => 1 } ); + foreach my $adduct (@adducts) { + # &results%5Badduct_type%5D%5B%5D=M%2BH&results%5Badduct_type%5D%5B%5D=M%2BNH4-H2O&results%5Badduct_type%5D%5B%5D=M%2BNa + my $EncodedAdduct = $uri->encode($adduct); + $formattedAdductString .= '&results%5Badduct_type%5D%5B%5D='.$EncodedAdduct ; + } } else { warn "\t[WARN]the adduct type is not defined...It will set to 'Unknown'\n" ; @@ -640,16 +649,19 @@ $mech->add_header('Referer', 'https://www.hmdb.ca/spectra/ms/search'); $mech->add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); } - ## adduct format is adduct_type=M%2BH%202M%2BH - if ( (!defined $adducts) or ( $adducts eq '') ) { $adducts = 'Unknown' ; } + #&results%5Badduct_type%5D%5B%5D=M%2BH&results%5Badduct_type%5D%5B%5D=M%2BNH4-H2O&results%5Badduct_type%5D%5B%5D=M%2BNa + # Query + #https://hmdb.ca/spectra/ms/generate_csv.csv?results%5Baction%5D=search&results%5Badduct_type%5D%5B%5D=M%2BH&results%5Badduct_type%5D%5B%5D=M%2BNH4-H2O&results%5Badduct_type%5D%5B%5D=M%2BNa&results%5Bauthenticity_token%5D=uN4r4Xme0bl5Lj%2Buv%2BrjebgrdF0oFO7mfxg0T7mHFlHcUSDkVAd%2BRB3qQDzm5fdz3BV4kKX%2F1i2uLOOdvBgK%2FA%3D%3D&results%5Bccs_predictors%5D=&results%5Bccs_tolerance%5D=&results%5Bcommit%5D=Search&results%5Bcontroller%5D=specdb%2Fms&results%5Bms_search_ion_mode%5D=positive&results%5Bquery_masses%5D=175.01&results%5Btolerance%5D=0.05&results%5Btolerance_units%5D=Da&results%5Butf8%5D=%E2%9C%93 + #&results%5Badduct_type%5D%5B%5D=M%2BH&results%5Badduct_type%5D%5B%5D=M%2BNH4-H2O&results%5Badduct_type%5D%5B%5D=M%2BNa my $res = $mech->get( 'https://hmdb.ca/spectra/ms/generate_csv.csv?' .'results%5Baction%5D=search' - .'&results%5Badduct_type%5D%5B%5D='.$adducts + #.'&results%5Badduct_type%5D%5B%5D='.$adducts + .$adducts #.'&results%5Bauthenticity_token%5D=' .'&results%5Bccs_predictors%5D=' .'&results%5Bccs_tolerance%5D='