473,378 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 3935
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

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

Similar topics

5
by: Ximo | last post by:
Hello, I'm programing an advanced calculator, and I have many problems with the execution errors, specually with the division by 0. And my question is how can show the execution error whitout...
3
by: jois.de.vivre | last post by:
Hi, I'm trying to write to an ofstream, and for some reason it fails. I know I can check it with fail() or bad(), but it gives me no useful information as to why it fails. Are there any C++...
7
by: mattsniderppl | last post by:
Hi, i'm relatively new to C++ from java and am having a difficult time with pointers. I'm sure there is something simple that I am doing wrong, but I can't seem to write this in a way that doesn't...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
8
by: Claudio Grondi | last post by:
Here an example of what I mean (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte large file): Traceback (most recent call last): File "<pyshell#1>", line 1, in -toplevel-...
29
by: aarthi28 | last post by:
Hi, I have written this code, and at the end, I am trying to write a vector of strings into a text file. However, my program is nor compiling, and it gives me the following error when I try to...
2
by: Axel Gallus | last post by:
I am desperately looking for some resources dealing with error handling in c++. Don't get me wrong.... I have very detailed knowledge of exceptions, assertions and invariants, but what is...
3
by: jcor | last post by:
Hi, i'm trying to write a file with the contents of a directory. I create an array of files in the directory (@dirs_and_files). After that I try to write a file "/home/joao/PERLFOLDERTESTE/fff...
13
by: bytesc | last post by:
Hey guys, I have created many picture files using gd_library, I recently decided to rename all of my pictures files on my web server to text instead of just numbers. Example: productsssh.jpg ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.