0
|
1 #!/usr/bin/perl
|
|
2 # blat_wrapper.pl
|
|
3 # Joachim Jacob - joachim.jacob@gmail.com - 2013
|
|
4
|
|
5 use strict;
|
|
6 use File::Temp 'tempdir';
|
|
7 use File::Copy qw(move);
|
|
8 use File::Basename;
|
|
9 use File::Spec qw(join);
|
|
10 use Log::Log4perl qw(:easy);
|
|
11
|
|
12 # ---------------------- Prepping Logging -----------------------------#
|
|
13 ########################################################################
|
|
14 # Log levels: $DEBUG $INFO $WARN $ERROR $FATAL
|
|
15 # ConversionPattern: %d %-5p %F{1} [%M] (line %L): %m%n%n
|
|
16 my $log_conf = q/
|
|
17 log4perl.category = ERROR, Screen
|
|
18 log4perl.appender.Screen.stderr=1
|
|
19 log4perl.appender.Screen.layout=Log::Log4perl::Layout::PatternLayout
|
|
20 log4perl.appender.Screen.layout.ConversionPattern = %d %-5p %m%n
|
|
21 log4perl.appender.Screen = Log::Log4perl::Appender::Screen
|
|
22 /;
|
|
23
|
|
24 Log::Log4perl::init( \$log_conf );
|
|
25 my $logger = get_logger();
|
|
26
|
|
27 # ----------------- Getting parameters file ---------------------------#
|
|
28 ########################################################################
|
|
29 my ($configfile) = @ARGV;
|
|
30 my (%para);
|
1
|
31 open(CONFIG,"<",$configfile);
|
0
|
32 while (<CONFIG>) {
|
|
33 if (/(\S+)==(.+)$/){ $para{ $1 } = $2 ; }
|
|
34 }
|
|
35 close(CONFIG);
|
|
36
|
|
37 =Excerpt Config parameters
|
1
|
38
|
0
|
39 ## first we pass some galaxy environment variables
|
|
40 galtemp==${__new_file_path__}
|
|
41
|
|
42 #if $refGenomeSource.genomeSource == "indexed"
|
|
43 referencepath==${refGenomeSource.index.fields.path}
|
|
44 range=$refGenomeSource.range
|
|
45 #else
|
|
46 referencepath==${refGenomeSource.ownFile}
|
|
47 #end if
|
|
48
|
|
49 input==$input
|
|
50 output==$output
|
|
51 q==$q
|
|
52 t==$t
|
|
53
|
|
54 advanced_params.use==$advanced_params.use
|
|
55 #if $advanced_params.use=="yes"
|
|
56 tileSize==$advanced_params.tileSize
|
|
57 stepSize==$advanced_params.stepSize
|
|
58 oneOff==$advanced_params.oneOff
|
|
59 minMatch==$advanced_params.minMatch
|
|
60 minScore==$advanced_params.minScore
|
|
61 maxGap==$advanced_params.maxGap
|
|
62 mask==$advanced_params.mask
|
|
63 qMask==$advanced_params.qMask
|
|
64 repeats==$advanced_params.repeats
|
|
65 trimT==$advanced_params.trimT
|
|
66 noTrimA==$advanced_params.noTrimA
|
|
67 fine==$advanced_params.fine
|
|
68 maxIntron==$advanced_params.maxIntron
|
|
69 extendThroughN==$advanced_params.extendThroughN
|
|
70 #end if
|
|
71 =cut
|
|
72
|
|
73 for my $para (keys %para){
|
|
74 INFO "$para\tset to\t$para{$para}";
|
|
75 }
|
|
76
|
|
77 # ---------------------- Prepping temp dir ----------------------------#
|
|
78 ########################################################################
|
|
79 # within the temporary directory of Galaxy, we create a temporary dir
|
|
80
|
|
81 my $galtemp = $para{'galtemp'};
|
|
82 delete($para{'galtemp'});
|
|
83 DEBUG "\nReceived Galaxy temporary directory:\n$galtemp";
|
|
84
|
|
85
|
|
86 my $tempdir = File::Temp->tempdir('tmpXXXXX', DIR => $galtemp, CLEANUP => 1);
|
|
87 mkdir "$tempdir", 077 unless -d "$tempdir";
|
|
88 INFO "\nTemporary directory:\n$tempdir";
|
|
89
|
1
|
90 # --------------------- Checking executable ---------------------------#
|
|
91 ########################################################################
|
|
92 #~ my $command = "which blat ";
|
|
93 #~ run_process($command, "Testing path", $tempdir);
|
0
|
94
|
|
95 # -------------------- Assembling command ----------------------------#
|
|
96 ########################################################################
|
1
|
97 my $command = "blat "; # this will ultimately be executed
|
0
|
98 $command .= " $para{'referencepath'}";
|
|
99 if ( $para{'range'} ) {
|
|
100 ## format checking of the provided range
|
|
101 if ($para{'range'} !~ //){
|
|
102 ERROR "Range has be wrongly formatted: $para{'range'}";
|
|
103 } else {
|
|
104 $command .= ":$para{'range'}";
|
|
105 }
|
|
106 }
|
|
107
|
|
108 $command .= " $para{'input'}";
|
|
109 delete($para{'referencepath'});
|
|
110 delete($para{'range'});
|
|
111 delete($para{'input'});
|
|
112
|
|
113 $command .= " -out=blast9 -q=$para{'q'} -t=$para{'t'}";
|
|
114 delete($para{'q'});
|
|
115 delete($para{'t'});
|
|
116
|
|
117 my $output = " $para{'output'}";
|
|
118 delete($para{'output'});
|
|
119
|
|
120 if ( $para{'advanced_params.use'} eq "yes" ){
|
|
121 delete($para{'advanced_params.use'});
|
1
|
122 $command .= " -minScore=$para{'minScore'} -maxGap=$para{'maxGap'} -mask=$para{'mask'} -qMask=$para{'qMask'} -oneOff=$para{'oneOff'} -minMatch=$para{'minMatch'} -tileSize=$para{'tileSize'} -stepSize=$para{'stepSize'} -maxIntron=$para{'maxIntron'} ";
|
0
|
123 if($para{'repeats'} eq 'yes' ){
|
|
124 $command .= " -repeats=$para{'qMask'}";
|
|
125 }
|
|
126 if($para{'extendThroughN'} eq 'yes' ){
|
|
127 $command .= " -extendThroughN";
|
|
128 }
|
|
129 if($para{'fine'} eq 'yes' ){
|
|
130 $command .= " -fine";
|
|
131 }
|
|
132 if($para{'trimT'} eq 'yes' ){
|
|
133 $command .= " -trimT";
|
|
134 }
|
|
135 if($para{'noTrimA'} eq 'yes' ){
|
|
136 $command .= " -noTrimA";
|
|
137 }
|
|
138 }
|
|
139
|
|
140 $command .= " $output";
|
|
141
|
|
142
|
|
143 # --------------------- Executing command ----------------------------#
|
|
144 ########################################################################
|
|
145 run_process($command, "BLAT alignment", $tempdir);
|
|
146
|
|
147 # --------------------------- Exiting --------------------------------#
|
|
148 ########################################################################
|
|
149 exit 0;
|
|
150
|
|
151
|
|
152 ### Subroutines ###
|
|
153 ########################################################################
|
|
154 sub run_process {
|
|
155 my ($command, $name, $tempdir)= @_;
|
|
156 my $logger = get_logger();
|
|
157 INFO "\nProcess to launch:\n $command\n";
|
|
158 system("cd $tempdir; $command 2>/dev/null") == 0 or die "$name failed\nExit status $?\nCommand: $command";
|
|
159 if ($? == -1) {
|
|
160 print "failed to execute: $!\n";
|
|
161 } elsif ($? & 127) {
|
|
162 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without';
|
|
163 } else {
|
|
164 printf "$name executed successfully\n", $? >> 8;
|
|
165 }
|
|
166 }
|
|
167
|
|
168
|