comparison qualimap_suite/bamqc_wrapper.pl @ 0:776730cc0cf6 draft

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