HTML::Form

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

    HTML::Form

    can anyone please give me an example of how to use
    HTML::Form module
    and its method
    @values = $form->param( $name )

    thanks alot.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Originally posted by idorjee
    can anyone please give me an example of how to use
    HTML::Form module
    and its method
    @values = $form->param( $name )

    thanks alot.
    Hi idorjee,

    Instead of fixating on a particular solution, I would suggest that you state what your real problem is. Maybe there is a module that would better serve what you're trying to do.

    Nevertheless, if you're wanting to figure out this module, always start with the cpan documentation:

    cpan HTML::Form

    As a secondary means of understanding it's usage, I'll often take a look at the test scripts that are provided with the package. This is definitely something for the more advanced, but it gives you more direct insight into how the authors expected the module to be used.



    - Miller

    Comment

    • idorjee
      New Member
      • Mar 2007
      • 76

      #3
      hi miller,
      i'm trying to get the input from the html textarea into a file or a variable, so that i could than execute with a perl script that i've written.
      I thought using HTML::Form module would do the thing, but unfortunately i haven't used it before and don't know how it works.

      --------part of myfile.html----------
      <b>Query sequence in fasta format:</b><br>
      <textarea name="sequence" cols="61" rows="10"></textarea>
      <br>

      ---------part of myfile.cgi------------
      $seq=$query->param('sequenc e');
      system("perl ncbi2tcblast.pl \$seq");

      the above doesn't work for some reason, which i think is because the sequence that i paste in the form (textarea) doesn't get it in $seq variable in the same format (ie, everything seems to be in one long line without any new line characters). so, i thought i should try HTML::Form. And also, i am trying to get the result of the 'system("perl ncbi2tcblast.pl \$seq");' on the browser.

      thanks
      :)

      Comment

      • miller
        Recognized Expert Top Contributor
        • Oct 2006
        • 1086

        #4
        Originally posted by idorjee
        ---------part of myfile.cgi------------
        $seq=$query->param('sequenc e');
        system("perl ncbi2tcblast.pl \$seq");
        Idorjee,

        I believe your problem is not in the parsing of the html textarea "sequence", but in how your calling ncbi2tcblast.pl .

        To verify that you textarea is being parsed correctly, set up a debugging check to a text file.

        Code:
        $seq = $query->param('sequence');
        open(VERIFY,"sequence.txt") or die "Can't open sequence.txt: $!";
        print VERIFY "'$seq'";
        close VERIFY;
        Obviously, you should probably specify an explicit path for sequence.txt if you want to be sure of where it lands. But look at its contents to verify that your $seq variable is being set correctly.

        I'm assuming that since this is textarea value, that it's going to be multiple lines. This will lead to problems in the system call. A system call essentially functions like any shell command does. If you can't have multiple lines in a shell call, you won't be able to get it to work froma system either.

        I suggest that you use the following method instead if your goal is to simply call the script ncbi2tcblast.pl will the first argument of $seq.

        Code:
        local @ARGV = ($seq);
        do 'ncbi2tcplast.pl';
        - Miller

        Comment

        • idorjee
          New Member
          • Mar 2007
          • 76

          #5
          Hi Miller,
          I really appreciate your trying to help me out with this, but nothing seem to be working. I tried what you told me to do, and I can't even get the 'sequence.txt' file to verify. Following is the entire script. Could you plz tell me where am I going wrong. I think it's something simple, but I can't figure that out.
          Thanks alot.

          ------ myscript.cgi ---------

          Code:
          #!/usr/bin/perl
          use CGI;
          
          use strict;
          
          my $infile = "tcresult.bls";
          open(INFILE, "$infile") or die "Can't open $infile: $!";
          
          my $query = new CGI;
          
          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";
          
          my $seq = $query->param('sequence');
          open(VERIFY,"sequence.txt") or die "Can't open sequence.txt: $!";
          print VERIFY "'$seq'";
          close VERIFY;
          
          print STDOUT "<pre>";
          local @ARGV = ($seq);
          do 'ncbi2tcblast.pl';
          while(<INFILE>){
          	print STDOUT $_;
          }
          print STDOUT "</pre>";
          
          unlink "/path/apache/htdocs";
          print STDOUT $query->end_html;
          print "\n";
          Last edited by miller; Mar 15 '07, 07:35 PM. Reason: Code Tag and ReFormatting

          Comment

          • miller
            Recognized Expert Top Contributor
            • Oct 2006
            • 1086

            #6
            Hi idorjee,

            Boy, the more code of yours I see, the more tired I become. Ok, this is my advice:

            Cut out everything dealing with running an external script and focus on getting CGI to work. This is a really simple requirement, so you want to make sure that this is working on it's own before adding any additional features.

            I notice two things currently:

            Where is your definition of the sequence textarea? And why are you trying to unlink your htdocs directory at the bottom of the script?

            Anyway, focus on CGI and once that is working you can add on more features.

            - Miller

            Comment

            • KevinADC
              Recognized Expert Specialist
              • Jan 2007
              • 4092

              #7
              You're script is quite confusing. Can you explain step-by-step what you are trying to do.

              1. get textarea data (sequence)
              2. ?
              3. ?
              etc
              etc


              this looks dangerous:

              Code:
              unlink "/path/apache/htdocs";
              Never delete directories using the unlink function, which is for files. That could hose up your computer quite nicely. Use rmdir() to delete a directory, but why do you want to delete the htdocs directory anyway?

              Comment

              • idorjee
                New Member
                • Mar 2007
                • 76

                #8
                Originally posted by KevinADC
                You're script is quite confusing. Can you explain step-by-step what you are trying to do.
                hi Kevin,
                following are the things that i am trying to do:
                1. get textarea data (sequence) from my html form
                2. run the 'ncbi2tcblast.p l' script with sequence from the textarea as the arg. and
                3. show the output (in html form) on the browser
                :(
                thanks alot

                Comment

                • idorjee
                  New Member
                  • Mar 2007
                  • 76

                  #9
                  Originally posted by miller
                  Hi idorjee,

                  Boy, the more code of yours I see, the more tired I become. Ok, this is my advice:
                  sorry about that, Miller. i'll try it from the scratch.
                  thanks

                  Comment

                  • idorjee
                    New Member
                    • Mar 2007
                    • 76

                    #10
                    hey kevin,

                    there's one more thing that i would like you to know. following is the part of the 'ncbi2tcblast.p l' script that i mentioned earlier. and as you can see that it takes an arg. file (@ARGV[0]) which should be the same (sequence) input from the html textarea, which i think is not getting here (in $fasta_file). all i could see on the browser is: "Blast in progress..." (until the line: print "Blast in progress...\n"; of the script).

                    thanks

                    --------- ncbi2tcblast.pl -------------

                    Code:
                    #!/usr/bin/perl
                    
                    use strict;
                    use Bio::Perl;
                    use Bio::SearchIO;
                    use Bio::DB::GenPept;
                    
                    my @s1array;
                    my $fasta_file=@ARGV[0];
                    
                    print "Blast in progress...\n";
                    
                    system ("blastall -p blastp -d ../database/nrpart -i $fasta_file -o repo.bls");
                    
                    my $in = new Bio::SearchIO(-format => 'blast', -file => 'repo.bls');
                    while( my $result = $in->next_result ) {
                    	while( my $hit = $result->next_hit ) {
                    		while( my $hsp = $hit->next_hsp ) {
                    			if ( $hsp->evalue <= 0.001 ) {
                    				print "Hit=", $hit->name, "\tDescription=", $hit->description, "\tAccession=", $hit->accession, "\tEvalue=", $hsp->evalue, "\tPercent_id=", $hsp->percent_identity, "\$
                    				push(@s1array, $hit->accession);
                    			}
                    		}
                    	}
                    }
                    Last edited by miller; Mar 16 '07, 07:57 PM. Reason: Code Tag and ReFormatting

                    Comment

                    • KevinADC
                      Recognized Expert Specialist
                      • Jan 2007
                      • 4092

                      #11
                      I think you're complicating things by having two scripts. Both of the scripts are very short and should be combined into one script unless there is some good reason not to do that I am not aware of.

                      Comment

                      • miller
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1086

                        #12
                        Originally posted by idorjee
                        sorry about that, Miller. i'll try it from the scratch.
                        thanks
                        Sorry if my comment appeared snide, but there is no reason to apologize.

                        I was simply wanting to point out that it is very important to ensure that your different technological layers are working individually before trying to integrate them.

                        No matter how much experience forum experts have, the person who is in the best position to fix a bug will always be the actually coder. That is why it's important that you and everyone learn good code design and debugging practices, as it will help you the most in the long run.

                        Anyway, I'm going to be extremely busy the rest of this weekend, so I won't be able to help anyone. Good luck, and catch you next week if you're still working in this design problem.

                        - Miller

                        Comment

                        • idorjee
                          New Member
                          • Mar 2007
                          • 76

                          #13
                          Hi Kevin,
                          So, here is what I did to my script. I combined them into one just like what you suggested, and, you're right, cos it makes no sense having two small scripts. But I still have a smally problem with it. The following script prints out the '$fasta_file' on the browser, but it can't seem to open the same for the 'blast' when it comes to line:
                          my $seq_in=Bio::Se qIO->new('-file' => '$fasta_file', '-format' => 'fasta');

                          Thanks alot.

                          #### my script ########
                          #!/usr/bin/perl -w

                          use strict;
                          use Bio::Perl;
                          use Bio::SearchIO;
                          use Bio::DB::GenPep t;
                          use Bio::SearchIO:: Writer::HTMLRes ultWriter;
                          use Bio::SeqIO;
                          use Bio::Tools::Run ::StandAloneBla st;
                          use CGI;
                          use CGI::Carp qw(fatalsToBrow ser);
                          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=>"Respons e from blast", -BGCOLOR=>"#FFFF FF");
                          print STDOUT "\n<h1><center> <font face=times new roman>Results from the BLAST</font></center></h1>\n";

                          #the input from the html form - textarea
                          my $fasta_file=$qu ery->param('sequenc e');
                          print STDOUT "<br>The contents of the uploaded file:\n<br></b>\n";

                          #prints out the sequence from the textarea on the browser
                          print STDOUT $fasta_file;

                          #performs blast of the sequence ($fasta_file) against the database (nr) and store the output in 'result/repo.bls'
                          my $seq_in=Bio::Se qIO->new('-file' => '$fasta_file', '-format' => 'fasta');
                          my $queryin=$seq_i n->next_seq();
                          my @params = ('program' => 'blastp','datab ase' => 'database/nr','outfile' => 'result/repo.bls', '_READMETHOD' => 'Blast');
                          my $factory=Bio::T ools::Run::Stan dAloneBlast->new(@params) ;
                          my $blast_report=$ factory->blastall($quer yin);





                          Originally posted by KevinADC
                          I think you're complicating things by having two scripts. Both of the scripts are very short and should be combined into one script unless there is some good reason not to do that I am not aware of.

                          Comment

                          • miller
                            Recognized Expert Top Contributor
                            • Oct 2006
                            • 1086

                            #14
                            Dude,

                            You've already posted this problem in a new thread. And answers have already been given.

                            Start keeping track of your threads. This is like the third time this has been an issue with you.



                            - Miller

                            Comment

                            • KevinADC
                              Recognized Expert Specialist
                              • Jan 2007
                              • 4092

                              #15
                              data sent from a textarea form widget can contain carraige returns and newlines or some combination of both, they need to be removed if that data is being used as a filename:

                              Code:
                              $string =~ s/[\r\n]//g;

                              where $string is the data from the textarea form widget.

                              Comment

                              Working...