Home > Archive > PERL Beginners > June 2005 > please help me to check why this perl script does not work!
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
please help me to check why this perl script does not work!
|
|
| Fei Li 2005-05-29, 8:56 am |
| I wish to submit some protein sequences via LWP:UserAgent to the
http://www.cbs.dtu.dk/services/ChloroP/
The error message is given as follows:
<HTML><HEAD><TITLE>Webface Error</TITLE></HEAD><font
color=3Dred><h1>Webface Error: </h1><h4>
Read: Field not declared; 'seqpaste'</h4>
<br>
</font></HTML>
*********************************
#! /usr/bin/perl -w
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
my $browser =3D LWP::UserAgent->new;
my @seq;
my $count =3D0;
my $infile =3D "my_test_file"; #input my Fasta file
open INPUT, "$infile" or die "can not open $infile:$!";
open OUTPUT, ">>$infile.ChloroP.res" or die "Cannot create the output file:=
$!";
@seq =3D <INPUT>;
my $total =3D @seq;
foreach my $item (@seq){
$count ++;
chomp $item;
my $response =3D
$browser->post('http://www.cbs.dtu.dk/cgi-bin/nph-webface',
[ "SEQPASTE" =3D> "$item",
"submit" =3D> "Submit"]
);
warn "WARN!: ", $response->status_line, "\n" unless
$response->is_success;
if($response->is_success){
my $result =3D $response->content;
open OUTPUT, ">>$infile.ChloroP.res" or die "Cannot
create the output file: $!";
print OUTPUT "$result\n";
print OUTPUT " \n*********************************\n\n\
n";
}
print "$count of $total finished\n";
}
close OUTPUT;
close INPUT;
| |
| Bob Showalter 2005-05-29, 3:55 pm |
| Fei Li wrote:
> I wish to submit some protein sequences via LWP:UserAgent to the
> http://www.cbs.dtu.dk/services/ChloroP/
>
> The error message is given as follows:
>
> <HTML><HEAD><TITLE>Webface Error</TITLE></HEAD><font
> color=red><h1>Webface Error: </h1><h4>
> Read: Field not declared; 'seqpaste'</h4>
> <br>
> </font></HTML>
[snip]
> my $response =
> $browser->post('http://www.cbs.dtu.dk/cgi-bin/nph-webface',
> [ "SEQPASTE" => "$item",
> "submit" => "Submit"]
> );
Just, a guess, but you're passing "SEQPASTE" when perhaps you should be
passing "seqpaste"?
| |
| Chris Heiland 2005-05-31, 3:57 pm |
|
> -----Original Message-----
> From: Bob Showalter [mailto:bob_showalter@taylorwhite.com]
> Sent: Sunday, May 29, 2005 5:41 AM
> To: Fei Li; beginners@perl.org
> Subject: Re: please help me to check why this perl script
> does not work!
>
> Fei Li wrote:
>
> [snip]
>
>
> Just, a guess, but you're passing "SEQPASTE" when perhaps you
> should be passing "seqpaste"?
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
Assuming that was the case, here is what should be a much faster version of
the same code.
UNTESTED:
#!/usr/bin/perl
use warnings;
use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
my $infile = "my_test_file"; #input my Fasta file
open( INPUT, "$infile" ) or die "can not open $infile: $!";
my $total = <INPUT>;
open( OUTPUT, ">>$infile.ChloroP.res" ) or die "Cannot create the output
file: $!";
while (<INPUT> ) {
chomp;
my $response =
$browser->post('http://www.cbs.dtu.dk/cgi-bin/nph-webface',
[ "seqpaste" => "$_", "submit" => "Submit"]
);
if ($response->is_success) {
print OUTPUT "$response->content\n";
print OUTPUT " \n*********************************\n\n\
n";
} else {
warn "WARN!: ", $response->status_line, "\n";
}
print "$. of $total finished\n";
}
close OUTPUT;
close INPUT;
Chris
| |
| Fei Li 2005-06-01, 3:55 am |
| Hi, Chris,
=20
Thanks for your code. I have test in my computer and it works with
necessary modification to suit for my case.
Can you give me some brief ideas that why this code is much faster
than previous one. thanks much!
--Frank
On 5/31/05, Chris Heiland <CHeiland@uwb.edu> wrote:
>=20
>=20
> Assuming that was the case, here is what should be a much faster version =
of
> the same code.
>=20
> UNTESTED:
>=20
> #!/usr/bin/perl
>=20
> use warnings;
> use strict;
>=20
> use HTTP::Request::Common;
> use LWP::UserAgent;
>=20
> my $browser =3D LWP::UserAgent->new;
>=20
> my $infile =3D "my_test_file"; #input my Fasta file
>=20
> open( INPUT, "$infile" ) or die "can not open $infile: $!";
> my $total =3D <INPUT>;
> open( OUTPUT, ">>$infile.ChloroP.res" ) or die "Cannot create the output
> file: $!";
>=20
> while (<INPUT> ) {
> chomp;
> my $response =3D
> $browser->post('http://www.cbs.dtu.dk/cgi-bin/nph-webface',
> [ "seqpaste" =3D> "$_", "submit" =3D> "Submit"]
> );
>=20
> if ($response->is_success) {
> print OUTPUT "$response->content\n";
> print OUTPUT " \n*********************************\n\n\
n";
> } else {
> warn "WARN!: ", $response->status_line, "\n";
> }
>=20
> print "$. of $total finished\n";
> }
>=20
> close OUTPUT;
> close INPUT;
>=20
> Chris
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20
>=20
>=20
--=20
Do not guess who I am. I am not Bush in BlackHouse
| |
| Chris Heiland 2005-06-02, 3:56 pm |
|
> -----Original Message-----
> From: Fei Li [mailto:lifei03@gmail.com]
> Sent: Tuesday, May 31, 2005 6:59 PM
> To: Chris Heiland
> Cc: beginners@perl.org
> Subject: Re: please help me to check why this perl script
> does not work!
>
> Hi, Chris,
>
> Thanks for your code. I have test in my computer and it works with
> necessary modification to suit for my case.
>
> Can you give me some brief ideas that why this code is much
> faster than previous one. thanks much!
>
> --Frank
>
> On 5/31/05, Chris Heiland <CHeiland@uwb.edu> wrote:
[snip]
We just need the total number of lines right now, nothing else stored[color=darkred]
> my $total
Mostly the different is we are attacking the file one line at a time.
Before everything was loaded in a variable then gone through.
Much faster not to load the entire file into memory first.
Here is the for every line in the file part:[color=darkred]
Let's kill off any return characters[color=darkred]
Take advantage of the "$_" Special variable representing a line in the file[color=darkred]
Could warn first but we assume most cases will not fail, test to see if
They succeed first, then worry if they fail[color=darkred]
> " \n*********************************\n\n\
n";
$. Prints the current line number of the file handle opened
No need to use a counter in this case
Also the total is gathered before[color=darkred]
[snip][color=darkred]
>
Sure, see comments above.
Chris
|
|
|
|
|