0

I'm trying to get user input from a web page written in Perl and send it to a local program (blastp), then display the results.

This is what I have right now:

(input code)

print $q->p, "Your database: $bd",
$q->p, "Your protein is: $prot",
$q->p, "Executing...";

print $q->p, system("blastp","-db $bd","-query $prot","-out results.out");

Now, I've done a little research, but I can't quite grasp how you're supposed to do things like this in Perl. I've tried opening a file, writing to it, and sending it over to blastp as an input, but I was unsuccessful.

For reference, this line produces a successful output file:

 kold@sazabi ~/BLAST/pataa $ blastp -db pataa -query ../teste.fs -out results.out

I may need to force the bd to load from an absolute path, but that shouldn't be difficult.

edit: Yeah, the DBs have an environmental variable, that's fixed. Ok, all I need is to get the input into a file, pass it to the command, and then print the output file to the CGI page.

edit2: for clarification:

I am receiving user input in $prot, I want to pass it over to blastp in -query, have the program blastp execute, and then print out to the user the results.out file (or just have a link to it, since blastp can output in HTML)

EDIT:

All right, fixed everything I needed to fix. The big problem was me not seeing what was going wrong: I had to install Tiny:Capture and print out stderr, which was when I realized the environmental variable wasn't getting set correctly, so BLAST wasn't finding my databases. Thanks for all the help!

José Maia
  • 310
  • 5
  • 21
  • i dont understan what you want, explain more – inye May 24 '14 at 13:55
  • Added some more detail. – José Maia May 24 '14 at 14:12
  • Is $prot going to contain the NAME of the file, or contents? – DVK May 24 '14 at 14:40
  • Right now, I was planning on $prot to receive FASTA text, namely something that looks like this: >gi|218093591|emb|CAT70956.1| unnamed protein product [Thermococcus kodakarensis KOD1] MKVLVAAPLHEKAIEVLKNAGFEVVYEEYPDEDRLVELVKDVDAIIVRSKPKVTRKVIEAAPKLKVIGRA GVGLDNIDLKAAEERGIKVVNSPGASSRSVAELAIGLIFAVARKIAFADRKMREGVWAKKQCMGIELEGK TIGVVGFGRIGYQVAKIANALGMKVLFYDPYPNEERAKEVGGKFADLETLLKESDVVTLHVPLVDATYHL INEERLKLMKPTAILINAARGAVVDTDALVKALQEGWIAGAGLDVFEEEPLPADHPLTKLDNVVLTPHIG ASTVEAQMRAGVEVAEKIVEALKG – José Maia May 24 '14 at 14:42

1 Answers1

0
  1. Write $prot to the file. Assuming you need to do it as-is without processing the text to split it or something:

    • For a fixed file name (may be problematic):

      use File::Slurp;
      write_file("../teste.fs", $prot, "\n") or print_error_to_web(); 
            # Implement the latter to print error in nice HTML format
      
    • For a temp file (better):

      my ($fh, $filename) = tempfile( $template, DIR => "..", CLEANUP => 1);
      # You can also create temp directory which is even better, via tempdir()
      print $fh "$prot\n";
      close $fh;
      
  2. Step 2: Run your command as you indicated:

    my $rc = system("$BLASTP_PATH/blastp", "-db", "pataa"
                    ,"-query", "../teste.fs", "-out", "results.out");
    # Process $rc for errors
    # Use qx[] instead of system() if you want to capture 
    #      standard output of the command
    
  3. Step 3: Read the output file in:

    use File::Slurp;
    my $out_file_text = read_file("results.out");
    
  4. Send back to web server

    print $q->p, $out_file_text;
    

The above code has multiple issues (e.g. you need better file/directory paths, more error handling etc...) but should start you on the right track.

DVK
  • 126,886
  • 32
  • 213
  • 327
  • Thank you, this has helped a lot. There's still a problem, though: apparently I need to preserve the newlines and write_file isn't doing it correctly. My input file, and the test print I do of $prot, show a newline after the first bit, like the comment I made up there, but the file produced by write_file has everything in one line, making BLAST unable to recognize it. – José Maia May 24 '14 at 15:07
  • @JoséMaia - that's exactly why I said "Assuming you need to do it as-is without processing the text to split it or something". If you need to know how to do that, look into `split` – DVK May 24 '14 at 15:09
  • Ok, having fixed the problems, the code is now producing a correct input.fs file, as well as a correct (blastp -db pataa -query input.fs -out results.out) query. However, the results.out file is empty, despite the query working if I execute it manually in the terminal. Is there a place I should be looking at for the logs to figure out what happened? – José Maia May 24 '14 at 15:37
  • Don't think it's a permissions problem either, seeing as if I su into www-data and execute the code, it works. – José Maia May 24 '14 at 16:15