annotate bamqc_wrapper.pl @ 2:934cd08c77af draft

Uploaded
author joachim-jacob
date Tue, 12 Feb 2013 04:48:36 -0500
parents
children 3d690162d629
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
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
69 # ---------------------- Output files ---------------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
70 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
71 # Two possible scenarios
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
72 # - output is written to the file at the output location in config file
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
73 # - output is moved to the output file location
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
74
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
75 # open (SAMOUTPUT, ">$para{'output_sam'}")
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
76 # or ( ERROR "Could not open output file for writing! (file:$para{'output_sam'}" and die );
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
77 # print SAMOUTPUT "Here comes sam\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
78 # close (SAMOUTPUT);
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
79
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
80
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
81 # -------------------- Assembling command ----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
82 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
83 my $outdir="bamqc_output";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
84 my $qualimap_path=""; # for tool_dependency later on
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
85 my $command = $qualimap_path."qualimap bamqc --outdir $outdir"; # this will ultimately be executed
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
86
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
87 # based on parameters, which are called by $para{'parametername'}
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
88 # the command is assembled
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
89 $command .= " -bam $para{'bam'} -hm $para{'hm'} -nr $para{'nr'}";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
90 if($para{'c'}){$command .= " $para{'c'} "; }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
91 if ( $para{'gff'} ){
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
92 $command .= " -gff $para{'gff'} -p $para{'p'} ";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
93 if($para{'os'}) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
94 $command .= $para{'os'};
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
95 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
96 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
97
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
98 $command .= " -nt 4 -outformat HTML";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
99
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
100
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
101 # --------------------- Executing command ----------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
102 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
103 run_process($command, "qualimap bamqc", ".");
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
104
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
105
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
106 # ----------------- Postprocessing command ---------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
107 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
108 # Hackish !!
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
109
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
110 my $librarydir = dirname($para{'bamqc_result'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
111 my $jobworkdir = dirname($para{'outputdir'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
112 my $files_path_name = basename($para{'outputdir'});
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
113 INFO "\n Librarydir = $librarydir \n jobworkdir = $jobworkdir \n files_path_name = $files_path_name \n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
114 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
115 system("rm -rf $para{'bamqc_result'}") == 0 or die "Could not post-process the results...\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
116 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
117
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
118
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
119 # --------------------------- Exiting --------------------------------#
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
120 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
121 exit 0;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
122
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
123
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
124
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
125 ### Subroutines ###
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
126 ########################################################################
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
127 sub run_process {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
128 my ($command, $name, $tempdir)= @_;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
129 my $logger = get_logger();
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
130 INFO "\nProcess to launch:\n $command\nIn directory\n$tempdir\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
131 system("cd $tempdir; $command 2>/dev/null") == 0 or die "$name failed\nExit status $?\nCommand: $command";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
132 if ($? == -1) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
133 print "failed to execute: $!\n";
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
134 } elsif ($? & 127) {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
135 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
136 } else {
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
137 printf "$name executed successfully\n", $? >> 8;
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
138 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
139 }
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
140
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
141
934cd08c77af Uploaded
joachim-jacob
parents:
diff changeset
142