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