annotate bamqc_wrapper.pl @ 4:3d690162d629 draft

Added more details for the required dependencies.
author Joachim Jacob <joachim.jacob@gmail.com>
date Wed, 20 Mar 2013 09:35:07 +0100
parents 934cd08c77af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
1 #!/usr/bin/perl
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
2 # bamqc_wrapper.pl
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
3 # Joachim Jacob - joachim.jacob@gmail.com - 2013
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
4
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
5 use strict;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
6 use File::Temp 'tempdir';
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
7 use File::Basename;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
8 use Log::Log4perl qw(:easy);
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
9
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
10 # ---------------------- Prepping Logging -----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
11 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
12 # Log levels: $DEBUG $INFO $WARN $ERROR $FATAL
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
13 # ConversionPattern: %d %-5p %F{1} [%M] (line %L): %m%n%n
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
14 my $log_conf = q/
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
15 log4perl.category = ERROR, Screen
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
16 log4perl.appender.Screen.stderr=1
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
17 log4perl.appender.Screen.layout=Log::Log4perl::Layout::PatternLayout
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
18 log4perl.appender.Screen.layout.ConversionPattern = %d %-5p %m%n
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
19 log4perl.appender.Screen = Log::Log4perl::Appender::Screen
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
20 /;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
21
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
22 Log::Log4perl::init( \$log_conf );
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
23 my $logger = get_logger();
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
24
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
25 # ----------------- Getting parameters file ---------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
26 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
27 my ($configfile) = @ARGV;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
28 my (%para);
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
29 open(CONFIG,"<$configfile");
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
30 while (<CONFIG>) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
31 if (/(\S+)==(.+)$/){ $para{ $1 } = $2 ; }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
32 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
33 close(CONFIG);
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
34
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
35 =Excerpt Config parameters
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
36
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
37 ## first we pass some galaxy environment variables
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
38 galtemp==${__new_file_path__}
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
39
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
40 bam==$bam
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
41 c==$c
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
42 hm==$hm
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
43 nr==$nr
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
44 #if $customgtf.upload=="yes"
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
45 gff==$customgtf.gff
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
46 os==$customgtf.os
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
47 p==$customgtf.p
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
48 #end if
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
49
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
50 =cut
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
51
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
52 for my $para (keys %para){
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
53 INFO "$para\tset to\t$para{$para}";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
54 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
55
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
56
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
57 # ---------------------- Prepping temp dir ----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
58 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
59 # within the temporary directory of Galaxy, we create a temporary dir
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
60
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
61 my $galtemp = $para{'galtemp'};
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
62 DEBUG "\nReceived Galaxy temporary directory:\n$galtemp";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
63
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
64 my $tempdir = File::Temp->tempdir('tmpXXXXX', DIR => $galtemp, CLEANUP => 1);
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
65 mkdir "$tempdir", 077 unless -d "$tempdir";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
66 INFO "\nTemporary directory:\n$tempdir";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
67
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
68 # -------------------- Assembling command ----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
69 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
70 my $outdir="bamqc_output";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
71 my $qualimap_path=""; # for tool_dependency later on
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
72 my $command = $qualimap_path."qualimap bamqc --outdir $outdir"; # this will ultimately be executed
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
73
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
74 # based on parameters, which are called by $para{'parametername'}
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
75 # the command is assembled
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
76 $command .= " -bam $para{'bam'} -hm $para{'hm'} -nr $para{'nr'}";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
77 if($para{'c'}){$command .= " $para{'c'} "; }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
78 if ( $para{'gff'} ){
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
79 $command .= " -gff $para{'gff'} -p $para{'p'} ";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
80 if($para{'os'}) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
81 $command .= $para{'os'};
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
82 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
83 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
84
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
85 $command .= " -nt 4 -outformat HTML";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
86
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
87
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
88 # --------------------- Executing command ----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
89 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
90 run_process($command, "qualimap bamqc", ".");
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
91
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
92
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
93 # ----------------- Postprocessing command ---------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
94 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
95 # Hackish !!
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
96
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
97 my $librarydir = dirname($para{'bamqc_result'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
98 my $jobworkdir = dirname($para{'outputdir'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
99 my $files_path_name = basename($para{'outputdir'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
100 INFO "\n Librarydir = $librarydir \n jobworkdir = $jobworkdir \n files_path_name = $files_path_name \n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
101 system("mv $jobworkdir/bamqc_output $librarydir/$files_path_name") == 0 or die "Could not move output data to $librarydir\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
102 system("rm -rf $para{'bamqc_result'}") == 0 or die "Could not post-process the results...\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
103 system("ln -s $librarydir/$files_path_name/qualimapReport.html $para{'bamqc_result'}") == 0 or die "Could not move output data to $librarydir\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
104
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
105
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
106 # --------------------------- Exiting --------------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
107 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
108 exit 0;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
109
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
110
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
111
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
112 ### Subroutines ###
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
113 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
114 sub run_process {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
115 my ($command, $name, $tempdir)= @_;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
116 my $logger = get_logger();
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
117 INFO "\nProcess to launch:\n $command\nIn directory\n$tempdir\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
118 system("cd $tempdir; $command 2>/dev/null") == 0 or die "$name failed\nExit status $?\nCommand: $command";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
119 if ($? == -1) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
120 print "failed to execute: $!\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
121 } elsif ($? & 127) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
122 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
123 } else {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
124 printf "$name executed successfully\n", $? >> 8;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
125 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
126 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
127
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
128
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
129