Error opening a File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idorjee
    New Member
    • Mar 2007
    • 76

    Error opening a File

    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::Se qIO->new('-file' => '$fasta_file', '-format' => 'fasta');

    Code:
    ##### script ########
    #!/usr/bin/perl -w
    
    use strict;
    use Bio::Perl;
    use Bio::SearchIO;
    use Bio:B::GenPept;
    use Bio::SearchIO::Writer::HTMLResultWriter;
    use Bio::SeqIO;
    use Bio::Tools::Run::StandAloneBlast;
    use CGI;
    use CGI::Carp qw(fatalsToBrowser);
    use CGI qw(:standard);
    
    #generate a new CGI object from the input to the CGI script
    my $query = new CGI;
    
    my @s1array;
    my $fasta_file;
    
    print STDOUT $query->header();
    print STDOUT $query->start_html(
    	-title		=> "Response from blast",
    	-BGCOLOR	=> "#FFFFFF"
    );
    print STDOUT "\n<h1><center><font face=times new roman>Results from the BLAST</font></center></h1>\n";
    print STDOUT "<br>The contents of the uploaded file:\n<br></b>\n";
    
    my $fasta_file = $query->param('sequence');
    
    print STDOUT $fasta_file;
    
    my $seq_in=Bio::SeqIO->new(
    	'-file'		=> '$fasta_file',
    	'-format'	=> 'fasta'
    );
    my $queryin=$seq_in->next_seq();
    my @params = (
    	'program'		=> 'blastp',
    	'database'		=> 'database/nrpart',
    	'outfile'		=> 'result/repo.bls',
    	'_READMETHOD'	=> $
    my $factory=Bio::Tools::Run::StandAloneBlast->new(@params);
    my $blast_report=$factory->blastall($queryin);
    ......

    thanks alot
    Last edited by miller; Mar 27 '07, 05:30 PM. Reason: Code Tag and ReFormatting
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    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

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

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

      Code:
      my $seq_in=Bio::SeqIO->new(
      	'-file'		=> [B]'$fasta_file',[/B]
      	'-format'	=> 'fasta'
      );
      remove the single-quotes

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Originally posted by KevinADC
        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

        Comment

        • idorjee
          New Member
          • Mar 2007
          • 76

          #5
          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|db j|BAB84889.1| FLJ00134 protein [Homo sapiens]
          HLSAQKASVGPESVS GLGTRTWPRVSCEVT VQCWPGCHLKVGGFK MAPWQGVGRRPWFLT WGPLCGAASVSPSMT VASSQ
          QGWDCTAGRRWLGEG EIEALAQVSEFKTVL SFQGPAASPDGSSAT RVPQDVTQGPGATGG KEDSGMIPLAGTAPG AEGPA
          PGDSQAVRPYKQEPS SPPLAPGLPAFLAAP GTTSCPECGKTSLKP AHLLRHRQSHSGEKP HACPECGKAFRRKEH LRRHR
          DTHPGSPGSPGPALR PLPAREKPHACCECG KTFYWREHLVRHRKT HSGARPFACWECGKG FGRREHVLRHQRIHG RAAAS
          AQGAVAPGPDGGGPF PPWPLG
          : File name too long
          STACK Bio::Root::IO:: _initialize_io /usr/perl5/5.6.1/lib/Bio/Root/IO.pm:273
          STACK Bio::SeqIO::_in itialize /usr/perl5/5.6.1/lib/Bio/SeqIO.pm:447
          STACK Bio::SeqIO::fas ta::_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

          Originally posted by KevinADC
          single-quotes around the scalar is killing the variable interpolation:

          Code:
          my $seq_in=Bio::SeqIO->new(
          	'-file'		=> [B]'$fasta_file',[/B]
          	'-format'	=> 'fasta'
          );
          remove the single-quotes

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            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.

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              Seems obvious:

              : File name too long

              is that really the name of a file?

              gi|18676474|dbj |BAB84889.1| FLJ00134 protein [Homo sapiens]
              HLSAQKASVGPESVS GLGTRTWPRVSCEVT VQCWPGCHLKVGGFK MAPWQ GVGRRPWFLTWGPLC GAASVSPSMTVASSQ
              QGWDCTAGRRWLGEG EIEALAQVSEFKTVL SFQGPAASPDGSSAT RVPQD VTQGPGATGGKEDSG MIPLAGTAPGAEGPA
              PGDSQAVRPYKQEPS SPPLAPGLPAFLAAP GTTSCPECGKTSLKP AHLLR HRQSHSGEKPHACPE CGKAFRRKEHLRRHR
              DTHPGSPGSPGPALR PLPAREKPHACCECG KTFYWREHLVRHRKT HSGAR PFACWECGKGFGRRE HVLRHQRIHGRAAAS
              AQGAVAPGPDGGGPF PPWPLG

              Comment

              • idorjee
                New Member
                • Mar 2007
                • 76

                #8
                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 (HLSAQKASVGPESV SGL......GGPFPP WPLG) 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|db j|BAB84889.1| FLJ00134 protein [Homo sapiens]
                HLSAQKASVGPESVS GLGTRTWPRVSCEVT VQCWPGCHLKVGGFK MAPWQGVGRRPWFLT WGPLCGAASVSPSMT VASSQ
                QGWDCTAGRRWLGEG EIEALAQVSEFKTVL SFQGPAASPDGSSAT RVPQDVTQGPGATGG KEDSGMIPLAGTAPG AEGPA
                PGDSQAVRPYKQEPS SPPLAPGLPAFLAAP GTTSCPECGKTSLKP AHLLRHRQSHSGEKP HACPECGKAFRRKEH LRRHR
                DTHPGSPGSPGPALR PLPAREKPHACCECG KTFYWREHLVRHRKT HSGARPFACWECGKG FGRREHVLRHQRIHG RAAAS
                AQGAVAPGPDGGGPF PPWPLG



                Originally posted by KevinADC
                Seems obvious:

                : File name too long

                is that really the name of a file?

                Comment

                • KevinADC
                  Recognized Expert Specialist
                  • Jan 2007
                  • 4092

                  #9
                  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.

                  Comment

                  • idorjee
                    New Member
                    • Mar 2007
                    • 76

                    #10
                    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' ???

                    Originally posted by miller
                    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

                    Comment

                    • idorjee
                      New Member
                      • Mar 2007
                      • 76

                      #11
                      thanks alot, kevin
                      ^ ^*

                      Originally posted by KevinADC
                      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.

                      Comment

                      • miller
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1086

                        #12
                        Originally posted by idorjee
                        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:

                        Code:
                        my @params = (
                        	'program'		=> 'blastp',
                        	'database'		=> 'database/nrpart',
                        	'outfile'		=> 'result/repo.bls',
                        	'_READMETHOD'	=> $
                        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

                        Comment

                        • idorjee
                          New Member
                          • Mar 2007
                          • 76

                          #13
                          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, 'ACDEFGHIKLMNPQ RSTVWY').
                          thanks





                          Originally posted by KevinADC
                          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.

                          Comment

                          • KevinADC
                            Recognized Expert Specialist
                            • Jan 2007
                            • 4092

                            #14
                            use the {n} quantifier

                            [A-Z]{10}


                            perldoc regexp tutorial: Matching Repititions

                            Comment

                            • idorjee
                              New Member
                              • Mar 2007
                              • 76

                              #15
                              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 ::StandAloneBla st::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($seqo bj); };
                              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 ::StandAloneBla st::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.


                              Originally posted by KevinADC
                              use the {n} quantifier

                              [A-Z]{10}


                              perldoc regexp tutorial: Matching Repititions

                              Comment

                              Working...