comparison 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
comparison
equal deleted inserted replaced
25:8f7546d0b925 26:76872ac24fb2
12 use SOAP::Lite; 12 use SOAP::Lite;
13 use Encode qw(encode_utf8); 13 use Encode qw(encode_utf8);
14 use HTML::Template ; 14 use HTML::Template ;
15 use XML::Twig ; 15 use XML::Twig ;
16 use Text::CSV ; 16 use Text::CSV ;
17 use URI::Encode ;
18 use open qw( :std :encoding(UTF-8) );
17 19
18 use Data::Dumper ; 20 use Data::Dumper ;
19 21
20 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS); 22 use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS);
21 23
167 169
168 ## counting selected adducts 170 ## counting selected adducts
169 $nbAdducts = scalar( my @adducts = ( split (/,/, $adductString) ) ) ; 171 $nbAdducts = scalar( my @adducts = ( split (/,/, $adductString) ) ) ;
170 172
171 ## Converting string into http post format 173 ## Converting string into http post format
172 $adductString =~ s/\+/%2B/g ; 174 # $adductString =~ s/\+/%2B/g ;
173 $adductString =~ s/,/%20/g ; 175 # $adductString =~ s/,/%20/g ;
174 $formattedAdductString = $adductString ; 176 # $formattedAdductString = $adductString ;
177
178 my $uri = URI::Encode->new( { encode_reserved => 1 } );
179 foreach my $adduct (@adducts) {
180 # &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
181 my $EncodedAdduct = $uri->encode($adduct);
182 $formattedAdductString .= '&results%5Badduct_type%5D%5B%5D='.$EncodedAdduct ;
183 }
175 } 184 }
176 else { 185 else {
177 warn "\t[WARN]the adduct type is not defined...It will set to 'Unknown'\n" ; 186 warn "\t[WARN]the adduct type is not defined...It will set to 'Unknown'\n" ;
178 } 187 }
179 188
638 $mech->add_header('Connection', 'keep-alive'); 647 $mech->add_header('Connection', 'keep-alive');
639 $mech->add_header('Content-Type', 'application/x-www-form-urlencoded'); 648 $mech->add_header('Content-Type', 'application/x-www-form-urlencoded');
640 $mech->add_header('Referer', 'https://www.hmdb.ca/spectra/ms/search'); 649 $mech->add_header('Referer', 'https://www.hmdb.ca/spectra/ms/search');
641 $mech->add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); 650 $mech->add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
642 } 651 }
643 ## adduct format is adduct_type=M%2BH%202M%2BH
644
645 if ( (!defined $adducts) or ( $adducts eq '') ) { 652 if ( (!defined $adducts) or ( $adducts eq '') ) {
646 $adducts = 'Unknown' ; 653 $adducts = 'Unknown' ;
647 } 654 }
655 #&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
656 # Query
657 #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
658 #&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
648 659
649 my $res = $mech->get( 660 my $res = $mech->get(
650 'https://hmdb.ca/spectra/ms/generate_csv.csv?' 661 'https://hmdb.ca/spectra/ms/generate_csv.csv?'
651 .'results%5Baction%5D=search' 662 .'results%5Baction%5D=search'
652 .'&results%5Badduct_type%5D%5B%5D='.$adducts 663 #.'&results%5Badduct_type%5D%5B%5D='.$adducts
664 .$adducts
653 #.'&results%5Bauthenticity_token%5D=' 665 #.'&results%5Bauthenticity_token%5D='
654 .'&results%5Bccs_predictors%5D=' 666 .'&results%5Bccs_predictors%5D='
655 .'&results%5Bccs_tolerance%5D=' 667 .'&results%5Bccs_tolerance%5D='
656 .'&results%5Bcommit%5D=Search' 668 .'&results%5Bcommit%5D=Search'
657 .'&results%5Bcontroller%5D=specdb%2Fms' 669 .'&results%5Bcontroller%5D=specdb%2Fms'