469,275 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Error opening a File

76
hi guys,
can anyone tell me what's wrong with the following script. i can print $fasta_file on the browser, but i get an error saying i can't open the file ( $fasta_file) when it comes to this line:
my $seq_in=Bio::SeqIO->new('-file' => '$fasta_file', '-format' => 'fasta');

Expand|Select|Wrap|Line Numbers
  1. ##### script ########
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5. use Bio::Perl;
  6. use Bio::SearchIO;
  7. use Bio:B::GenPept;
  8. use Bio::SearchIO::Writer::HTMLResultWriter;
  9. use Bio::SeqIO;
  10. use Bio::Tools::Run::StandAloneBlast;
  11. use CGI;
  12. use CGI::Carp qw(fatalsToBrowser);
  13. use CGI qw(:standard);
  14.  
  15. #generate a new CGI object from the input to the CGI script
  16. my $query = new CGI;
  17.  
  18. my @s1array;
  19. my $fasta_file;
  20.  
  21. print STDOUT $query->header();
  22. print STDOUT $query->start_html(
  23.     -title        => "Response from blast",
  24.     -BGCOLOR    => "#FFFFFF"
  25. );
  26. print STDOUT "\n<h1><center><font face=times new roman>Results from the BLAST</font></center></h1>\n";
  27. print STDOUT "<br>The contents of the uploaded file:\n<br></b>\n";
  28.  
  29. my $fasta_file = $query->param('sequence');
  30.  
  31. print STDOUT $fasta_file;
  32.  
  33. my $seq_in=Bio::SeqIO->new(
  34.     '-file'        => '$fasta_file',
  35.     '-format'    => 'fasta'
  36. );
  37. my $queryin=$seq_in->next_seq();
  38. my @params = (
  39.     'program'        => 'blastp',
  40.     'database'        => 'database/nrpart',
  41.     'outfile'        => 'result/repo.bls',
  42.     '_READMETHOD'    => $
  43. my $factory=Bio::Tools::Run::StandAloneBlast->new(@params);
  44. my $blast_report=$factory->blastall($queryin);
  45.  
......

thanks alot
Mar 27 '07 #1
16 3621
miller
1,089 Expert 1GB
Hi idorjee,

Note, you have a syntax error in your definition of @params. Most likely this is simply a copy and past error.

As for why it can't open the file, practically all file errors can be traced to three possible issues:

1) The file doesn't exist
2) The file exists but your aren't refering to it correctly. You're either assuming a specific working directory or relative path that is incorrect. Try having an explicit path.
3) You do not have permissions to access the file under that user the webserver is running under.

Check each of these three things.
- Miller
Mar 27 '07 #2
KevinADC
4,059 Expert 2GB
single-quotes around the scalar is killing the variable interpolation:

Expand|Select|Wrap|Line Numbers
  1. my $seq_in=Bio::SeqIO->new(
  2.     '-file'        => '$fasta_file',
  3.     '-format'    => 'fasta'
  4. );
remove the single-quotes
Mar 27 '07 #3
miller
1,089 Expert 1GB
single-quotes around the scalar is killing the variable interpolation:
ah ha!

Right you are Kev. I missed that, or more accurately, failed to look at all.

- Miller
Mar 27 '07 #4
idorjee
76
Sorry, I think I posted the same thing twice, thinking that you've deleted the first one. Anyways, I tried by removing the single-quotes, and I got the following errors:
By the way, the line starting with '>' symbol followed by few more lines of alphabets is the same protein sequence that I pasted on the textarea of the html form.

Software error:

------------- EXCEPTION -------------
MSG: Could not open >gi|18676474|dbj|BAB84889.1| FLJ00134 protein [Homo sapiens]
HLSAQKASVGPESVSGLGTRTWPRVSCEVTVQCWPGCHLKVGGFKMAPWQ GVGRRPWFLTWGPLCGAASVSPSMTVASSQ
QGWDCTAGRRWLGEGEIEALAQVSEFKTVLSFQGPAASPDGSSATRVPQD VTQGPGATGGKEDSGMIPLAGTAPGAEGPA
PGDSQAVRPYKQEPSSPPLAPGLPAFLAAPGTTSCPECGKTSLKPAHLLR HRQSHSGEKPHACPECGKAFRRKEHLRRHR
DTHPGSPGSPGPALRPLPAREKPHACCECGKTFYWREHLVRHRKTHSGAR PFACWECGKGFGRREHVLRHQRIHGRAAAS
AQGAVAPGPDGGGPFPPWPLG
: File name too long
STACK Bio::Root::IO::_initialize_io /usr/perl5/5.6.1/lib/Bio/Root/IO.pm:273
STACK Bio::SeqIO::_initialize /usr/perl5/5.6.1/lib/Bio/SeqIO.pm:447
STACK Bio::SeqIO::fasta::_initialize /usr/perl5/5.6.1/lib/Bio/SeqIO/fasta.pm:83
STACK Bio::SeqIO::new /usr/perl5/5.6.1/lib/Bio/SeqIO.pm:358
STACK Bio::SeqIO::new /usr/perl5/5.6.1/lib/Bio/SeqIO.pm:378
STACK toplevel /usr/local/apache2/htdocs/ncbitc.pl:40

--------------------------------------

thanks

single-quotes around the scalar is killing the variable interpolation:

Expand|Select|Wrap|Line Numbers
  1. my $seq_in=Bio::SeqIO->new(
  2.     '-file'        => '$fasta_file',
  3.     '-format'    => 'fasta'
  4. );
remove the single-quotes
Mar 27 '07 #5
KevinADC
4,059 Expert 2GB
It's another example of how using quotes needlessly messes up perl scripts. That really needs to be reinforced more in the perl books and classes: how, where and when to use quotes in perl code.
Mar 27 '07 #6
KevinADC
4,059 Expert 2GB
Seems obvious:

: File name too long

is that really the name of a file?

gi|18676474|dbj|BAB84889.1| FLJ00134 protein [Homo sapiens]
HLSAQKASVGPESVSGLGTRTWPRVSCEVTVQCWPGCHLKVGGFKMAPWQ GVGRRPWFLTWGPLCGAASVSPSMTVASSQ
QGWDCTAGRRWLGEGEIEALAQVSEFKTVLSFQGPAASPDGSSATRVPQD VTQGPGATGGKEDSGMIPLAGTAPGAEGPA
PGDSQAVRPYKQEPSSPPLAPGLPAFLAAPGTTSCPECGKTSLKPAHLLR HRQSHSGEKPHACPECGKAFRRKEHLRRHR
DTHPGSPGSPGPALRPLPAREKPHACCECGKTFYWREHLVRHRKTHSGAR PFACWECGKGFGRREHVLRHQRIHGRAAAS
AQGAVAPGPDGGGPFPPWPLG
Mar 27 '07 #7
idorjee
76
No, Kevin. That whole thing isn't the name of the file. Infact, the first line, starting with the '>' symbol is the description of the sequence, and the rest of it (HLSAQKASVGPESVSGL......GGPFPPWPLG) is the sequence itself. Here is the whole thing (the description and the sequence) that I'm using as the input (I need them both as the input for the blast program that i'm trying to run). For your information, when I save the file in a directory and do the blast step with it, it works fine.

>gi|18676474|dbj|BAB84889.1| FLJ00134 protein [Homo sapiens]
HLSAQKASVGPESVSGLGTRTWPRVSCEVTVQCWPGCHLKVGGFKMAPWQ GVGRRPWFLTWGPLCGAASVSPSMTVASSQ
QGWDCTAGRRWLGEGEIEALAQVSEFKTVLSFQGPAASPDGSSATRVPQD VTQGPGATGGKEDSGMIPLAGTAPGAEGPA
PGDSQAVRPYKQEPSSPPLAPGLPAFLAAPGTTSCPECGKTSLKPAHLLR HRQSHSGEKPHACPECGKAFRRKEHLRRHR
DTHPGSPGSPGPALRPLPAREKPHACCECGKTFYWREHLVRHRKTHSGAR PFACWECGKGFGRREHVLRHQRIHGRAAAS
AQGAVAPGPDGGGPFPPWPLG



Seems obvious:

: File name too long

is that really the name of a file?
Mar 27 '07 #8
KevinADC
4,059 Expert 2GB
Sorry but I am not familiar with the Bio class of modules you are using. I have no idea if you're using them correctly or not. All I could do is try and read the module documentation to try and figure it out, but you can do that too and you are already at least somewhat familiar with the Bio stuff so you are really at an advantage over me at this point.
Mar 27 '07 #9
idorjee
76
I feel so stupid asking you this, but can you plz point me to the syntax error in my definition of @params.
^ ^*

Oh! i see you mean here. '_READMETHOD' => 'Blast' ???

Hi idorjee,

Note, you have a syntax error in your definition of @params. Most likely this is simply a copy and past error.

As for why it can't open the file, practically all file errors can be traced to three possible issues:

1) The file doesn't exist
2) The file exists but your aren't refering to it correctly. You're either assuming a specific working directory or relative path that is incorrect. Try having an explicit path.
3) You do not have permissions to access the file under that user the webserver is running under.

Check each of these three things.
- Miller
Mar 27 '07 #10
idorjee
76
thanks alot, kevin
^ ^*

Sorry but I am not familiar with the Bio class of modules you are using. I have no idea if you're using them correctly or not. All I could do is try and read the module documentation to try and figure it out, but you can do that too and you are already at least somewhat familiar with the Bio stuff so you are really at an advantage over me at this point.
Mar 27 '07 #11
miller
1,089 Expert 1GB
an you plz point me to the syntax error in my definition of @params.

Oh! i see you mean here. '_READMETHOD' => 'Blast' ???
I put CODE tags around and reformatted the code in your first post to make it more legible. The error was in this definition:

Expand|Select|Wrap|Line Numbers
  1. my @params = (
  2.     'program'        => 'blastp',
  3.     'database'        => 'database/nrpart',
  4.     'outfile'        => 'result/repo.bls',
  5.     '_READMETHOD'    => $
  6.  
You'll notice how the definition of @params appears to end early. I surmise that this is simply a copy and paste error, and that your code is actually correct in your own script. But I pointed it out regardless, since it might be an issue.

- Miller
Mar 27 '07 #12
idorjee
76
hi Kevin,
i know that perl regular expression '[A-Z]+' means one or more of any of the alphabets from A to Z, but how could i say something like 10 of the alphates or 10 of the specified alphabets (for instance, 'ACDEFGHIKLMNPQRSTVWY').
thanks





Sorry but I am not familiar with the Bio class of modules you are using. I have no idea if you're using them correctly or not. All I could do is try and read the module documentation to try and figure it out, but you can do that too and you are already at least somewhat familiar with the Bio stuff so you are really at an advantage over me at this point.
Mar 28 '07 #13
KevinADC
4,059 Expert 2GB
use the {n} quantifier

[A-Z]{10}


perldoc regexp tutorial: Matching Repititions
Mar 28 '07 #14
idorjee
76
hi Kevin,
i'm back with another question. i know you told me that you're not so familiar with the Bio modules, but could you plz tell me what does the following exception mean and how can i catch them.
------------- EXCEPTION -------------
MSG: (0) not Bio::Seq object or array of Bio::Seq objects or file name!
STACK Bio::Tools::Run::StandAloneBlast::blastall /usr/perl5/5.6.1/lib/Bio/Tools/Run/StandAloneBlast.pm:532
STACK toplevel /usr/local/apache2/htdocs/ncbitc.pl:52
--------------------------------------

I also tried the following lines in the script:

eval { $factory->blastall($seqobj); };
if ($@) { print "Failed to load, because : $@" }

but i got the following message:

Failed to load, because :
------------- EXCEPTION -------------
MSG: (0) not Bio::Seq object or array of Bio::Seq objects or file name!
STACK Bio::Tools::Run::StandAloneBlast::blastall /usr/perl5/5.6.1/lib/Bio/Tools/Run/StandAloneBlast.pm:532
STACK (eval) /usr/local/apache2/htdocs/ncbitc.pl:53
STACK toplevel /usr/local/apache2/htdocs/ncbitc.pl:52
--------------------------------------

thanks alot.


use the {n} quantifier

[A-Z]{10}


perldoc regexp tutorial: Matching Repititions
Mar 31 '07 #15
KevinADC
4,059 Expert 2GB
you already are catching the exception:

Expand|Select|Wrap|Line Numbers
  1. eval { $factory->blastall($seqobj); };
  2. if ($@) { print "Failed to load, because : $@" } 
if the question is why is the excepton being raised in the first place, I don't know. Somethings wrong with $seqobj is my guess.
Mar 31 '07 #16
hi guys,
can anyone tell me what's wrong with the following script. i can print $fasta_file on the browser, but i get an error saying i can't open the file ( $fasta_file) when it comes to this line:
my $seq_in=Bio::SeqIO->new('-file' => '$fasta_file', '-format' => 'fasta');

Expand|Select|Wrap|Line Numbers
  1. ##### script ########
  2. #!/usr/bin/perl -w
  3.  
  4. use strict;
  5. use Bio::Perl;
  6. use Bio::SearchIO;
  7. use Bio:B::GenPept;
  8. use Bio::SearchIO::Writer::HTMLResultWriter;
  9. use Bio::SeqIO;
  10. use Bio::Tools::Run::StandAloneBlast;
  11. use CGI;
  12. use CGI::Carp qw(fatalsToBrowser);
  13. use CGI qw(:standard);
  14.  
  15. #generate a new CGI object from the input to the CGI script
  16. my $query = new CGI;
  17.  
  18. my @s1array;
  19. my $fasta_file;
  20.  
  21. print STDOUT $query->header();
  22. print STDOUT $query->start_html(
  23.     -title        => "Response from blast",
  24.     -BGCOLOR    => "#FFFFFF"
  25. );
  26. print STDOUT "\n<h1><center><font face=times new roman>Results from the BLAST</font></center></h1>\n";
  27. print STDOUT "<br>The contents of the uploaded file:\n<br></b>\n";
  28.  
  29. my $fasta_file = $query->param('sequence');
  30.  
  31. print STDOUT $fasta_file;
  32.  
  33. my $seq_in=Bio::SeqIO->new(
  34.     '-file'        => '$fasta_file',
  35.     '-format'    => 'fasta'
  36. );
  37. my $queryin=$seq_in->next_seq();
  38. my @params = (
  39.     'program'        => 'blastp',
  40.     'database'        => 'database/nrpart',
  41.     'outfile'        => 'result/repo.bls',
  42.     '_READMETHOD'    => $
  43. my $factory=Bio::Tools::Run::StandAloneBlast->new(@params);
  44. my $blast_report=$factory->blastall($queryin);
  45.  
......

thanks alot

In this line:

my $fasta_file = $query->param('sequence');

$fasta_file contains the sequence(s) which have been submitted on you r webpage. $fasta_file is not the name of a file.

This bit of code

my $seq_in=Bio::SeqIO->new(
'-file' => '$fasta_file',
'-format' => 'fasta'
);

expects a filename, not the contents of a fasta file. You don't have a fasta file name at all. What you have is some sequences in the fasta format in a variable named $fasta_file.

You need to store these in a file (a temporary file possibly) and then use that in Bio::SeqIO->new().

I always use File::Temp to get safe temporary filenames for such uses.
Apr 4 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Ximo | last post: by
3 posts views Thread by jois.de.vivre | last post: by
7 posts views Thread by mattsniderppl | last post: by
2 posts views Thread by Axel Gallus | last post: by
3 posts views Thread by jcor | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.