Advertisement
Guest User

test_proc_website.pm

a guest
Oct 11th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.19 KB | None | 0 0
  1. package test_proc_website;
  2. use Dancer ':syntax';
  3. use Dancer::Plugin::Email;
  4. use Dancer::Plugin::Database;
  5. use DBI;
  6. use Try::Tiny;
  7. use File::Temp;
  8. use File::Slurp;
  9. use Data::Table;
  10. use Data::Dumper;
  11. use Time::Piece;
  12. use Time::HiRes qw(gettimeofday);
  13. use Cwd;
  14. use Statistics::R;
  15. use Archive::Zip qw(:ERROR_CODES);
  16. use Number::Bytes::Human qw(format_bytes);
  17. use Proc::Simple;
  18. #use Proc::Background;
  19. use feature qw(say);
  20.  
  21. our $VERSION = '0.1';
  22.  
  23. my $UPLOAD_FILE_SIZE = 450000000;                               #450MB file
  24. my $TEMP_DIR = "/Users/tushardave26/Documents/Perl/Dancer/test_proc_website/tmp";
  25. my $LOG_FILE = "/tmp/edn_log.csv";
  26.  
  27. get '/' => sub {
  28.     template 'index';
  29. };
  30.  
  31. get '/qqPlot' => sub {
  32.     template 'qqPlot.tt';
  33. };
  34.  
  35. post '/qqPlot' => sub {
  36.  
  37.         my $script_start_time = gettimeofday;
  38.         my $temp_dir_template = "Q-QPlot"."_".localtime->ymd("")."_".localtime->time("")."_".$$."_"."XXXX";
  39.         my ($name,$email,$y_limit,$xy_limit,$chart_title,$plot_name,$output_format,$pval_col,$log_line);
  40.         my $email_mess = "Thank you so much for submitting your request for Q-Q plot utility. Your Q-Q plot is attached to this email. If you have any question regarding your plot, please contact Tushar Dave (Bioinforamtics Analyst 1) at tdave\@medicine.umaryland.edu.\n\nRegards,\nEDN Team";
  41.  
  42.         my $file = request->upload('upload-file');
  43.         my $size = $file->size;
  44.     my $filename = $file->filename;
  45.         my $type = $file->type;
  46.  
  47.         my $size_readable = format_bytes($size);
  48.  
  49.         if ($size > $UPLOAD_FILE_SIZE) {
  50.                 template 'upload_file_size_error.tt', {size => $size};
  51.         } else {
  52.  
  53.                 $pval_col = params->{'p-val-col'};
  54.                 #$y_limit = params->{'y-limit'} ? params->{'y-limit'} : 100;
  55.                 #$xy_limit = params->{'xy-limit'} ? params->{'xy-limit'} : 100;
  56.                 $chart_title = params->{'chart-title'} ? params->{'chart-title'} : "";
  57.                 $output_format = params->{'output-file-type'} ? params->{'output-file-type'} : "png";
  58.                 $plot_name = params->{'output-file'} ? params->{'output-file'}.".".$output_format : "Q_Q_Plot".localtime->ymd("")."_".localtime->time("")."_".$$.".".$output_format;
  59.                 #my $zip_file_name = params->{'output-file'} ? params->{'output-file'} : "Q_Q_Plot".localtime->ymd("")."_".localtime->time("")."_".$$;
  60.  
  61.                 my $temp_dir = File::Temp->newdir($temp_dir_template,
  62.                                           CLEANUP => 0,
  63.                                           DIR => $TEMP_DIR);
  64.  
  65.                 chdir($temp_dir);
  66.  
  67.                 $file->copy_to("$temp_dir/$filename");
  68.  
  69.                 my $process = Proc::Simple->new();                      # creates a new process object
  70.                 Proc::Simple::debug(0);
  71.                 open my $f, ">", "test.txt" or die "Can not open test file $!";
  72.                 my $c = 0;
  73.  
  74.                 #change made was to add full path to test_qqPlot.pl
  75.                 $process->start("perl /Users/tushardave26/Documents/Perl/Dancer/test_proc_website/scripts/test_qqPlot.pl --tempdir $temp_dir --filename $filename --filetype $type --pvalcol $pval_col --charttitle $chart_title --outputformat $output_format --plotname $plot_name");
  76.  
  77.                 while ($process->poll()) {
  78.                        template 'processing.tt';
  79.                        sleep 10;
  80.                 }
  81.                 close $f;
  82.  
  83.                 try {
  84.                         email {
  85.                                 from    => '[email protected]',
  86.                                 to      => params->{'email'},
  87.                                 subject => 'Q-Q Plot Result from EDN Bioinformatics Toolkit',
  88.                                 body    => $email_mess,
  89.                                 #attach  => "$temp_dir/$zip_file"
  90.                                 attach => "$temp_dir/$plot_name"
  91.                         };
  92.                 } catch {
  93.                         error "Could not send email: $_";
  94.                 };
  95.  
  96.                 template 'qqplot_submit.tt', {email => params->{'email'},
  97.                                               image => "$temp_dir/$plot_name"};
  98.         }
  99. };
  100.  
  101. true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement