#!/usr/bin/perl -W use CGI qw(:standard :cgi-lib); #use CGI::Carp qw//; use CGI::Pretty; use Data::Dumper; use strict; my %Input=Vars(); # process the inputs whose keys match the regex pattern my @single_keys = grep (/^single_/, keys %Input); my @single_list; map { if ($Input{$_} eq 'on') { $_=~s/^single_//; push @single_list, $_; } } @single_keys; my $single_list = join ',', @single_list; map { delete $Input{$_} } @single_keys; if ($single_list ne '') { $Input{fastq_file_list1} = $single_list; } # process paired runs my @paired_keys = grep (/^paired_/, keys %Input); my @paired_list; map { if ($Input{$_} eq 'on') { my $key = $_; $key =~s/^paired_//; push @paired_list, [split ',', $key]; } } @paired_keys; if (@paired_list) { $Input{fastq_file_list1} = join ',', (map {sprintf "%s", $_->[0]} @paired_list); $Input{fastq_file_list2} = join ',', (map {sprintf "%s", $_->[1]} @paired_list); } # make a checksum of the input files only. Further checksums will be # calculated by the backend script when it is launched my $paired_end_mode = (exists $Input{fastq_file_list2}) ? 1 : 0; my $source_files = $paired_end_mode ? $Input{fastq_file_list1} . ',' . $Input{fastq_file_list2} : $Input{fastq_file_list1}; $Input{source_files} = $source_files; #$Input{reads_checksum} = qx%echo "$source_files" | cksum - | cut -f 1 -d " "%; #chomp $Input{reads_checksum}; # Now delete irrelevant options for single_end mode my @paired_end_only_keys = qw/map_2 map_a map_A assemble_s pileup_s pileup_p/; if (! $paired_end_mode){ map { delete $Input{$_} } @paired_end_only_keys; } map { delete $Input{$_} } @paired_keys; my $op; # clone options from map for mapcheck. Specific for maq version 0.7.1 for $op (qw/s Q m q/){ if (exists $Input{'assemble_'.$op}) { $Input{'mapcheck_'.$op} = $Input{'assemble_'.$op}; } } $Input{mapcheck_c} = 'on'; my $Error = ''; # check that the filename prefix is valid # this is now handled by the run_maq.sh script # Substitute space with underscore chomp $Input{outfile_prefix}; if ($Input{outfile_prefix} eq ''){ $Error = sprintf "You did not specify an output file prefix. (See General Settings section)"; $Error .= sprintf Dumper \%Input; } # Translate all illegal characters $Input{outfile_prefix} =~ s/[^a-zA-Z0-9_]+/_/g; # Disallow dots at beginning $Input{outfile_prefix} =~ s/^\.+//g; # $Error = sprintf "The output file prefix you specified, '%s', contains disallowed characters\n", # $Input{outfile_prefix}; #} # For those, collect them into a comma separated list my $argstring = ''; for my $k (keys %Input){ $argstring .= sprintf "%s\t%s\n", $k, $Input{$k}; } my $outfile_subdir = $Input{outfile_prefix}; my $outfile_stub = $Input{outfile_prefix}; my $outuri = "/$ENV{MAQGENE_OUT_ALIAS}/$Input{user_results_dir}/$outfile_subdir"; my $outdir = "$ENV{MAQGENE_OUT_DIR}/$Input{user_results_dir}/$outfile_subdir"; # For easy deleting of these files by non-root umask 0000; mkdir $outdir; if ($Error eq ''){ open O, ">$outdir/$outfile_stub.input"; printf O "%s", $argstring; close O; system "$ENV{MAQGENE_EXE_DIR}/run_maq.sh $outdir/$outfile_stub.input nosave > $outdir/${outfile_stub}_messages.txt 2>&1 &"; print &redirect($outuri); #&PrintPage($message); } else { &PrintPage($Error); } sub PrintPage { my $message = $_[0]; print &header(), &start_html(-title=>'MAQGene Results', -dtd=>['-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'], -style=>{-src=>"../../run/maqgene.css"} #-head=>meta({-http_equiv=>'refresh', -content=>'10'}) ), &pre($message), #&pre(`env`); &end_html; }