genbank has asked for the wisdom of the Perl Monks concerning the following question:

hello perlmonks, recently I encount with a problem. The program script as following. My system is windows xp.

use strict; use LWP; my $protein = "MSSSTPFDPYALSEHDEERPQNVQSKSRTAELQAEIDDTVGIMRDNINKVAERGE +RLTSI"; my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->post( 'http://dis.embl.de/cgiDict.py', # That's the URL that the real form submits to. [ 'key' => "process", 'SP_entry' => "", 'sequence_string' => $protein, 'smooth_frame' => "8", 'peak_frame' => "8", 'join_frame' => "4", 'fold_coils' => "1.20", 'fold_rem465' => "1.20", 'fold_hotloops' => "1.40", 'plot_title' => "", 'doApplet' => "true", 'tango_PH' => "7.40", 'tango_T' => "298.15", 'tango_I' => "0.02", 'tango_TFE' => "0.00", 'fold_tango' => "1.00", ] ); die "Error: ", $response->status_line, "\n" unless $response->is_success; open(FILE, '>D:\perl\tmp2.html') || die "Can't write-open out_file: $! +"; my $dat=$response->content; print FILE $dat; close FILE; system('C:\Program Files\Internet Explorer\IEXPLORE.EXE','D:\per +l\tmp2.html');

When I run this script, always don't show the correct picture as I wish. The place should show the picture always appear the sentence “plots are not rendered as ASCII art”.
Maybe you can visit the website "http://dis.embl.de/cgiDict.py" and then paste the protein sequence "MSSSTPFDPYALSEHDEERPQNVQSKSRTAELQAEIDDTVGIMRDNINKVAERGERLTSI".
You will watch the webpage what I want to. The black picture is absent from my file instead of a sentence mensioned above.
what shoud I do? Thanks in advance.

Replies are listed 'Best First'.
Re: what's "plots are not rendered as ASCII art" ?
by Util (Priest) on Apr 15, 2011 at 03:30 UTC

    The chart (black picture) that is just above the text "Download PostScript file" is an interactive Java applet; notice that numbers in the legend (upper-right corner) change as you move your cursor across the chart.

    Perhaps you could configure that applet to run locally, to achieve the same result after downloading the page? I am not sure what you intend, and this problem is not caused by Perl; you would get the same result with `wget` or `curl`.

    Alternately, you could download the (non-interactive) chart as Encapsulated PostScript, and view it without an applet (although you will need the free Win32 Postscript programs GhostScript and GhostView.
    This code works for me:

    use strict; use warnings; use LWP; my $base_url = 'http://dis.embl.de'; my $protein = 'MSSSTPFDPYALSEHDEERPQNVQSKSRTAELQAEIDDTVGIMRDNINKVAERGE +RLTSI'; my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->post( "$base_url/cgiDict.py", # That's the URL that the real form submits +to. [ key => 'process', SP_entry => '', sequence_string => $protein, smooth_frame => '8', peak_frame => '8', join_frame => '4', fold_coils => '1.20', fold_rem465 => '1.20', fold_hotloops => '1.40', plot_title => '', doApplet => 'true', tango_PH => 7.40, tango_T => 298.15, tango_I => 0.02, tango_TFE => 0.00, fold_tango => 1.00, ] ); die "Error: ", $response->status_line, "\n" unless $response->is_success; my $html = $response->content; my ($eps) = ( $html =~ m{<a href="([^"]+)">Download PostScript file</a +>} ) or die; $response = $browser->get("$base_url/$eps"); die "Error: ", $response->status_line, "\n" unless $response->is_success; my $out_path = 'tmp.eps'; open my $out_fh, '>', $out_path or die "Can't write-open out_file: $!"; print {$out_fh} $response->content; close $out_fh; system( 'C:/Program Files/Ghostgum/gsview/gsview32.exe', $out_path );

      Yeah, it's not a simple picture. This script you provided is so great. However I want to show the webpage normally including the "black chart".


      what about the script as following?


      use strict; use LWP; my $protein = "MSSSTPFDPYALSEHDEERPQNVQSKSRTAELQAEIDDTVGIMRDNINKVAERGE +RLTSI"; my $browser = LWP::UserAgent->new; $browser->env_proxy(); my $response = $browser->post( 'http://dis.embl.de/cgiDict.py', # That's the URL that the real form submits to. [ 'key' => "process", 'SP_entry' => "", 'sequence_string' => $protein, 'smooth_frame' => "8", 'peak_frame' => "8", 'join_frame' => "4", 'fold_coils' => "1.20", 'fold_rem465' => "1.20", 'fold_hotloops' => "1.40", 'plot_title' => "", 'doApplet' => "true", 'tango_PH' => "7.40", 'tango_T' => "298.15", 'tango_I' => "0.02", 'tango_TFE' => "0.00", 'fold_tango' => "1.00", ] ); die "Error: ", $response->status_line, "\n" unless $response->is_success; open(FILE, '>D:\perl\tmp2.html') || die "Can't write-open out_file: $! +"; my $dat=$response->content; $dat=~s/"\//"http:\/\/dis.embl.de\//g; print FILE $dat; close FILE; system('C:\Program Files\Internet Explorer\IEXPLORE.EXE','D:\per +l\tmp2.html');

      This script can make the "black chart" correctly show up at the tmp2.html. The difference between the two script I post is "$dat=~s/"\//"http:\/\/dis.embl.de\//g;". But I don't know what's the function of "$dat=~s/"\//"http:\/\/dis.embl.de\//g;". Could you give me a explanation? Thanks a lot!

        But I don't know what's the function of "$dat=~s/"\//"http:\/\/dis.embl.de\//g;"

        It substitutes "/ with "http://dis.embl.de/, which presumably has the effect that IE will fetch URIs affected by the substitution remotely instead of trying to load them from your local disk (where tmp2.html resides).

        For example:

        my $dat = '<img src="/foo.jpg">'; $dat=~s/"\//"http:\/\/dis.embl.de\//g; print $dat; # <img src="http://dis.embl.de/foo.jpg">
Re: what's "plots are not rendered as ASCII art" ?
by JavaFan (Canon) on Apr 15, 2011 at 09:19 UTC
    Uhm, you download a page full of relative links, dump it in a file, then try to display it. It's not magically going to resolve the relative links. For instance, the "plots are not rendered as ASCII art" is an alt text, displayed because it cannot download the image.

    At least you need to throw in a <base> element. Or, if the goal is to show the page in a browser, make a GET URL, and start the browser with that URL.

      Thanks a lot!
Re: what's "plots are not rendered as ASCII art" ?
by Anonymous Monk on Apr 15, 2011 at 03:25 UTC
    I'm surprised you get any kind of picture or text at all, after all, img inside applet isn't exactly valid html

    what shoud I do?

    Try downloading the image instead of some broken html