Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test_proc_website;
- use Dancer ':syntax';
- use Dancer::Plugin::Email;
- use Dancer::Plugin::Database;
- use DBI;
- use Try::Tiny;
- use File::Temp;
- use File::Slurp;
- use Data::Table;
- use Data::Dumper;
- use Time::Piece;
- use Time::HiRes qw(gettimeofday);
- use Cwd;
- use Statistics::R;
- use Archive::Zip qw(:ERROR_CODES);
- use Number::Bytes::Human qw(format_bytes);
- use Proc::Simple;
- #use Proc::Background;
- use feature qw(say);
- our $VERSION = '0.1';
- my $UPLOAD_FILE_SIZE = 450000000; #450MB file
- my $TEMP_DIR = "/Users/tushardave26/Documents/Perl/Dancer/test_proc_website/tmp";
- my $LOG_FILE = "/tmp/edn_log.csv";
- get '/' => sub {
- template 'index';
- };
- get '/qqPlot' => sub {
- template 'qqPlot.tt';
- };
- post '/qqPlot' => sub {
- my $script_start_time = gettimeofday;
- my $temp_dir_template = "Q-QPlot"."_".localtime->ymd("")."_".localtime->time("")."_".$$."_"."XXXX";
- my ($name,$email,$y_limit,$xy_limit,$chart_title,$plot_name,$output_format,$pval_col,$log_line);
- 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";
- my $file = request->upload('upload-file');
- my $size = $file->size;
- my $filename = $file->filename;
- my $type = $file->type;
- my $size_readable = format_bytes($size);
- if ($size > $UPLOAD_FILE_SIZE) {
- template 'upload_file_size_error.tt', {size => $size};
- } else {
- $pval_col = params->{'p-val-col'};
- #$y_limit = params->{'y-limit'} ? params->{'y-limit'} : 100;
- #$xy_limit = params->{'xy-limit'} ? params->{'xy-limit'} : 100;
- $chart_title = params->{'chart-title'} ? params->{'chart-title'} : "";
- $output_format = params->{'output-file-type'} ? params->{'output-file-type'} : "png";
- $plot_name = params->{'output-file'} ? params->{'output-file'}.".".$output_format : "Q_Q_Plot".localtime->ymd("")."_".localtime->time("")."_".$$.".".$output_format;
- #my $zip_file_name = params->{'output-file'} ? params->{'output-file'} : "Q_Q_Plot".localtime->ymd("")."_".localtime->time("")."_".$$;
- my $temp_dir = File::Temp->newdir($temp_dir_template,
- CLEANUP => 0,
- DIR => $TEMP_DIR);
- chdir($temp_dir);
- $file->copy_to("$temp_dir/$filename");
- my $process = Proc::Simple->new(); # creates a new process object
- Proc::Simple::debug(0);
- open my $f, ">", "test.txt" or die "Can not open test file $!";
- my $c = 0;
- #change made was to add full path to test_qqPlot.pl
- $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");
- while ($process->poll()) {
- template 'processing.tt';
- sleep 10;
- }
- close $f;
- try {
- email {
- to => params->{'email'},
- subject => 'Q-Q Plot Result from EDN Bioinformatics Toolkit',
- body => $email_mess,
- #attach => "$temp_dir/$zip_file"
- attach => "$temp_dir/$plot_name"
- };
- } catch {
- error "Could not send email: $_";
- };
- template 'qqplot_submit.tt', {email => params->{'email'},
- image => "$temp_dir/$plot_name"};
- }
- };
- true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement