Mercurial > repos > joachim-jacob > blat
comparison blat_wrapper.pl @ 0:3cec538aab33 draft
Uploaded
| author | joachim-jacob |
|---|---|
| date | Thu, 30 May 2013 07:13:55 -0400 |
| parents | |
| children | da4426cac227 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3cec538aab33 |
|---|---|
| 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); | |
| 31 open(CONFIG,"<$configfile"); | |
| 32 while (<CONFIG>) { | |
| 33 if (/(\S+)==(.+)$/){ $para{ $1 } = $2 ; } | |
| 34 } | |
| 35 close(CONFIG); | |
| 36 | |
| 37 =Excerpt Config parameters | |
| 38 ## first we pass some galaxy environment variables | |
| 39 galtemp==${__new_file_path__} | |
| 40 | |
| 41 ## first we pass some galaxy environment variables | |
| 42 galtemp==${__new_file_path__} | |
| 43 | |
| 44 #if $refGenomeSource.genomeSource == "indexed" | |
| 45 referencepath==${refGenomeSource.index.fields.path} | |
| 46 range=$refGenomeSource.range | |
| 47 #else | |
| 48 referencepath==${refGenomeSource.ownFile} | |
| 49 #end if | |
| 50 | |
| 51 input==$input | |
| 52 output==$output | |
| 53 q==$q | |
| 54 t==$t | |
| 55 | |
| 56 advanced_params.use==$advanced_params.use | |
| 57 #if $advanced_params.use=="yes" | |
| 58 tileSize==$advanced_params.tileSize | |
| 59 stepSize==$advanced_params.stepSize | |
| 60 oneOff==$advanced_params.oneOff | |
| 61 minMatch==$advanced_params.minMatch | |
| 62 minScore==$advanced_params.minScore | |
| 63 maxGap==$advanced_params.maxGap | |
| 64 mask==$advanced_params.mask | |
| 65 qMask==$advanced_params.qMask | |
| 66 repeats==$advanced_params.repeats | |
| 67 trimT==$advanced_params.trimT | |
| 68 noTrimA==$advanced_params.noTrimA | |
| 69 fine==$advanced_params.fine | |
| 70 maxIntron==$advanced_params.maxIntron | |
| 71 extendThroughN==$advanced_params.extendThroughN | |
| 72 #end if | |
| 73 =cut | |
| 74 | |
| 75 for my $para (keys %para){ | |
| 76 INFO "$para\tset to\t$para{$para}"; | |
| 77 } | |
| 78 | |
| 79 | |
| 80 # ---------------------- Prepping temp dir ----------------------------# | |
| 81 ######################################################################## | |
| 82 # within the temporary directory of Galaxy, we create a temporary dir | |
| 83 | |
| 84 my $galtemp = $para{'galtemp'}; | |
| 85 delete($para{'galtemp'}); | |
| 86 DEBUG "\nReceived Galaxy temporary directory:\n$galtemp"; | |
| 87 | |
| 88 | |
| 89 my $tempdir = File::Temp->tempdir('tmpXXXXX', DIR => $galtemp, CLEANUP => 1); | |
| 90 mkdir "$tempdir", 077 unless -d "$tempdir"; | |
| 91 INFO "\nTemporary directory:\n$tempdir"; | |
| 92 | |
| 93 | |
| 94 # -------------------- Assembling command ----------------------------# | |
| 95 ######################################################################## | |
| 96 my $command = "blat "; # this will ultimately be executed | |
| 97 $command .= " $para{'referencepath'}"; | |
| 98 if ( $para{'range'} ) { | |
| 99 ## format checking of the provided range | |
| 100 if ($para{'range'} !~ //){ | |
| 101 ERROR "Range has be wrongly formatted: $para{'range'}"; | |
| 102 } else { | |
| 103 $command .= ":$para{'range'}"; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 $command .= " $para{'input'}"; | |
| 108 delete($para{'referencepath'}); | |
| 109 delete($para{'range'}); | |
| 110 delete($para{'input'}); | |
| 111 | |
| 112 $command .= " -out=blast9 -q=$para{'q'} -t=$para{'t'}"; | |
| 113 delete($para{'q'}); | |
| 114 delete($para{'t'}); | |
| 115 | |
| 116 my $output = " $para{'output'}"; | |
| 117 delete($para{'output'}); | |
| 118 | |
| 119 if ( $para{'advanced_params.use'} eq "yes" ){ | |
| 120 delete($para{'advanced_params.use'}); | |
| 121 $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'} "; | |
| 122 if($para{'repeats'} eq 'yes' ){ | |
| 123 $command .= " -repeats=$para{'qMask'}"; | |
| 124 } | |
| 125 if($para{'extendThroughN'} eq 'yes' ){ | |
| 126 $command .= " -extendThroughN"; | |
| 127 } | |
| 128 if($para{'fine'} eq 'yes' ){ | |
| 129 $command .= " -fine"; | |
| 130 } | |
| 131 if($para{'trimT'} eq 'yes' ){ | |
| 132 $command .= " -trimT"; | |
| 133 } | |
| 134 if($para{'noTrimA'} eq 'yes' ){ | |
| 135 $command .= " -noTrimA"; | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 $command .= " $output"; | |
| 140 | |
| 141 | |
| 142 # --------------------- Executing command ----------------------------# | |
| 143 ######################################################################## | |
| 144 run_process($command, "BLAT alignment", $tempdir); | |
| 145 | |
| 146 # --------------------------- Exiting --------------------------------# | |
| 147 ######################################################################## | |
| 148 exit 0; | |
| 149 | |
| 150 | |
| 151 ### Subroutines ### | |
| 152 ######################################################################## | |
| 153 sub run_process { | |
| 154 my ($command, $name, $tempdir)= @_; | |
| 155 my $logger = get_logger(); | |
| 156 INFO "\nProcess to launch:\n $command\n"; | |
| 157 system("cd $tempdir; $command 2>/dev/null") == 0 or die "$name failed\nExit status $?\nCommand: $command"; | |
| 158 if ($? == -1) { | |
| 159 print "failed to execute: $!\n"; | |
| 160 } elsif ($? & 127) { | |
| 161 printf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without'; | |
| 162 } else { | |
| 163 printf "$name executed successfully\n", $? >> 8; | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 |
