Mercurial > repos > bioitcore > splicetrap
comparison SpliceTrap.pl @ 1:adc0f7765d85 draft
planemo upload
| author | bioitcore |
|---|---|
| date | Thu, 07 Sep 2017 15:06:58 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:d4ca551ca300 | 1:adc0f7765d85 |
|---|---|
| 1 #!/usr/bin/perl | |
| 2 # Author: wuj@cshl.edu | |
| 3 # Modified: Baekdoo Kim (baegi7942@gmail.com) | |
| 4 use strict; | |
| 5 use Getopt::Long; | |
| 6 use Data::Dumper; | |
| 7 #################### | |
| 8 use Cwd; | |
| 9 my $PROG = $0; | |
| 10 my $CUR_DIR = Cwd::abs_path(Cwd::cwd()); | |
| 11 my $PROG_ABS_PATH = Cwd::abs_path($PROG); | |
| 12 #my $SrcFolder=`dirname $PROG_ABS_PATH`; | |
| 13 #chomp($SrcFolder); | |
| 14 #my %config=do "$ENV{HOME}/.SpliceTrap.pl.ini"; | |
| 15 #my $SrcFolder=$config{SrcFolder}; | |
| 16 | |
| 17 my @programs = ('R','echo','cat','bash','perl','ln','mkdir','paste','grep','sort','basename','awk','wc','mv','cd','rm','split','head' ); | |
| 18 foreach my $program (@programs) | |
| 19 { | |
| 20 die ("CHECK: $program not found\n") if(system("hash $program >/dev/null")); | |
| 21 | |
| 22 } | |
| 23 | |
| 24 #################### | |
| 25 my $SrcFolder=""; | |
| 26 my $MapSoftware="bowtie"; | |
| 27 my $DatabasePrefix="hg38"; | |
| 28 my $ReadFileFormat=""; | |
| 29 my $ReadFile1Name=""; | |
| 30 my $ReadFile2Name=""; | |
| 31 my $CutoffLevel="M"; | |
| 32 my $Outputfolder=$CUR_DIR; | |
| 33 my $OutputPrefix="Result"; | |
| 34 #my $CutoffOnly=0; | |
| 35 my $ReadSize=36; | |
| 36 my $JunctionCut=5; | |
| 37 my $onGalaxy_raw=""; | |
| 38 my $onGalaxy_txt=""; | |
| 39 my $BowtieThreads=1; | |
| 40 my $noIRMstr=""; | |
| 41 my $noIRM = 0; | |
| 42 | |
| 43 my $num_args = $#ARGV; | |
| 44 $onGalaxy_raw = $ARGV[$num_args-1]; | |
| 45 $onGalaxy_txt = $ARGV[$num_args]; | |
| 46 | |
| 47 GetOptions ( | |
| 48 "l:s"=>\$SrcFolder, | |
| 49 "m:s"=>\$MapSoftware, | |
| 50 "d:s"=>\$DatabasePrefix, | |
| 51 # "f:s"=>\$ReadFileFormat, | |
| 52 "1:s"=>\$ReadFile1Name, | |
| 53 "2:s"=>\$ReadFile2Name, | |
| 54 "c:s"=>\$CutoffLevel, | |
| 55 "outdir:s"=>\$Outputfolder, | |
| 56 "o:s"=>\$OutputPrefix, | |
| 57 "j:i"=>\$JunctionCut, | |
| 58 "s:i"=>\$ReadSize, | |
| 59 "p:i"=>\$BowtieThreads, | |
| 60 "noIRM|noirm"=>\$noIRM | |
| 61 # "local:s"=>\$local, | |
| 62 # "rerun"=>\$CutoffOnly | |
| 63 ); | |
| 64 #-O for galaxy output | |
| 65 | |
| 66 | |
| 67 my $InputParaDes=" Usage of the script: | |
| 68 -l Base Location (required) | |
| 69 -m Mapping software: [bowtie]/rmap | |
| 70 -d Database prefix: [hg18]/mm9/rn4/userdefined | |
| 71 -1 Read File 1 | |
| 72 -2 Read File 2 | |
| 73 -c Cutoff Level:H/[M]/L | |
| 74 Means High, Middle or Low | |
| 75 -j Junction reads requirement per junction for each exon-isoform [5] | |
| 76 -o Output prefix {Result} | |
| 77 -s Read Size [36] | |
| 78 --outdir Output folder [./] | |
| 79 -p Bowtie parameter, threads number, only use this when you don't use qsub [1] | |
| 80 --noIRM Skip the IRM correction step | |
| 81 | |
| 82 This is a quick help, please refer to the README file for details. | |
| 83 "; | |
| 84 | |
| 85 | |
| 86 if($SrcFolder eq "") { | |
| 87 print "[CHECK] - Please provide the location of the script (option '-l')\n\n"; | |
| 88 exit; | |
| 89 } | |
| 90 | |
| 91 if($ReadFile2Name eq "") | |
| 92 { | |
| 93 $ReadFile2Name = $ReadFile1Name; | |
| 94 #trigger singled end mode | |
| 95 } | |
| 96 | |
| 97 if($ReadFile1Name eq "" or $ReadFile2Name eq "" ) | |
| 98 { | |
| 99 print $InputParaDes; | |
| 100 exit; | |
| 101 } | |
| 102 | |
| 103 if($BowtieThreads < 1) | |
| 104 { | |
| 105 print $InputParaDes; | |
| 106 exit; | |
| 107 } | |
| 108 | |
| 109 if (! -e "$SrcFolder/db/$DatabasePrefix/parallel") | |
| 110 { | |
| 111 print "CHECK: Error, the database you specified is not properly installed.\n"; | |
| 112 #print $InputParaDes; | |
| 113 exit; | |
| 114 | |
| 115 } | |
| 116 | |
| 117 if($CutoffLevel ne "H" and $CutoffLevel ne "M" and $CutoffLevel ne "L") | |
| 118 { | |
| 119 print $InputParaDes; | |
| 120 exit; | |
| 121 } | |
| 122 | |
| 123 | |
| 124 $ReadFile1Name = Cwd::abs_path($ReadFile1Name); | |
| 125 $ReadFile2Name = Cwd::abs_path($ReadFile2Name); | |
| 126 | |
| 127 #check the files | |
| 128 open(check,$ReadFile1Name) or die ("CHECK: Error when opening $ReadFile1Name\n"); | |
| 129 my $checkoneline = <check>; | |
| 130 if(substr($checkoneline,0,1) eq ">") | |
| 131 { | |
| 132 $ReadFileFormat = "fasta"; | |
| 133 } | |
| 134 elsif(substr($checkoneline,0,1) eq "@") | |
| 135 { | |
| 136 $ReadFileFormat = "fastq"; | |
| 137 } | |
| 138 else | |
| 139 { | |
| 140 die("CHECK: ERROR:Please check $ReadFile1Name\n"); | |
| 141 } | |
| 142 close(check); | |
| 143 | |
| 144 open(check,$ReadFile2Name) or die ("CHECK: Error when opening $ReadFile2Name\n"); | |
| 145 my $checkoneline = <check>; | |
| 146 if(substr($checkoneline,0,1) eq ">") | |
| 147 { | |
| 148 die("CHECK: $ReadFile2Name has a different format as $ReadFile1Name\n") if ($ReadFileFormat ne "fasta"); | |
| 149 } | |
| 150 elsif(substr($checkoneline,0,1) eq "@") | |
| 151 { | |
| 152 die("CHECK: $ReadFile2Name has a different format as $ReadFile1Name\n") if ($ReadFileFormat ne "fastq"); | |
| 153 } | |
| 154 else | |
| 155 { | |
| 156 die("CHECK: ERROR:Please check $ReadFile2Name\n"); | |
| 157 } | |
| 158 close(check); | |
| 159 | |
| 160 $Outputfolder= Cwd::abs_path($Outputfolder); | |
| 161 if($Outputfolder eq "/tmp") | |
| 162 { | |
| 163 while(-e $Outputfolder) | |
| 164 { | |
| 165 my $random_foldername = random_sessid(); | |
| 166 $Outputfolder = "/tmp/".$random_foldername; | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 | |
| 171 if(! -e $Outputfolder) | |
| 172 { | |
| 173 mkdir $Outputfolder or die "CHECK: cannot mkdir $Outputfolder\n"; | |
| 174 } | |
| 175 if(! -d $Outputfolder) | |
| 176 { | |
| 177 die "CHECK: $Outputfolder is not a folder\n"; | |
| 178 } | |
| 179 | |
| 180 if($MapSoftware eq "bowtie") | |
| 181 { | |
| 182 print "CHECK: whether bowtie installed and in PATH\n"; | |
| 183 my $bowtiechecker=`bowtie --version`; | |
| 184 if($bowtiechecker ne "") | |
| 185 { | |
| 186 print "CHECK: bowtie found, information below:\n"; | |
| 187 print $bowtiechecker,"\n"; | |
| 188 } | |
| 189 else | |
| 190 { | |
| 191 die "CHECK: No bowtie found in PATH, EXIT!\n"; | |
| 192 } | |
| 193 } | |
| 194 elsif($MapSoftware eq "rmap") | |
| 195 { | |
| 196 print "CHECK: checking rmap...\n"; | |
| 197 if(system("type rmap &>/dev/null") ==0 ) | |
| 198 { | |
| 199 print "CHECK: rmap found, continue\n"; | |
| 200 } | |
| 201 else | |
| 202 { | |
| 203 die "CHECK: No rmap found in PATH, EXIT!\n"; | |
| 204 } | |
| 205 } | |
| 206 else | |
| 207 { | |
| 208 die "CHECK: option -m only takes rmap or bowtie as inputs\n"; | |
| 209 } | |
| 210 | |
| 211 if($ReadSize == 0) | |
| 212 { | |
| 213 die "CHECK: Please check option -s Read size\n"; | |
| 214 } | |
| 215 | |
| 216 if($noIRM) | |
| 217 { | |
| 218 $noIRMstr= "noirm"; | |
| 219 } | |
| 220 | |
| 221 #write more checks later | |
| 222 print "PARAMETERS:\tMapping software: ",$MapSoftware,"\n"; | |
| 223 print "PARAMETERS:\tDatabase prefix: ",$DatabasePrefix,"\n"; | |
| 224 print "PARAMETERS:\tRead end 1: ",$ReadFile1Name,"\n"; | |
| 225 print "PARAMETERS:\tRead end 2: ",$ReadFile2Name,"\n" if($ReadFile2Name ne $ReadFile1Name); | |
| 226 print "PARAMETERS:\tGalaxy_raw: ",$onGalaxy_raw,"\n"; #if($onGalaxy_raw ne ""); | |
| 227 print "PARAMETERS:\tGalaxy_txt: ",$onGalaxy_txt,"\n"; #if($onGalaxy_txt ne ""); | |
| 228 print "PARAMETERS:\tCutoff level: ",$CutoffLevel,"\n"; | |
| 229 print "PARAMETERS:\tJunction reads.min:",$JunctionCut,"\n"; | |
| 230 print "PARAMETERS:\tOutput folder: ",$Outputfolder,"\n"; | |
| 231 print "PARAMETERS:\tOutput prefix: ",$OutputPrefix,"\n"; | |
| 232 print "PARAMETERS:\tRead size: ",$ReadSize,"\n"; | |
| 233 print "PARAMETERS:\tBowtie threads #: ",$BowtieThreads,"\n"; | |
| 234 print "PARAMETERS:\tNo IRM.\n" if ($noIRM); | |
| 235 | |
| 236 if($MapSoftware eq "bowtie") | |
| 237 { | |
| 238 print "=================STAGE 1 MAPPING===================\n"; | |
| 239 system("bash $SrcFolder/bin/mapping_bowtie.sh $ReadFile1Name $ReadFileFormat $DatabasePrefix $Outputfolder $SrcFolder $BowtieThreads"); | |
| 240 system("bash $SrcFolder/bin/mapping_bowtie.sh $ReadFile2Name $ReadFileFormat $DatabasePrefix $Outputfolder $SrcFolder $BowtieThreads") if($ReadFile2Name ne $ReadFile1Name); | |
| 241 print "=================STAGE 2 ESTIMATION================\n"; | |
| 242 # ratio, log, nums | |
| 243 system("bash $SrcFolder/bin/batch_para_cov10p_fit.sh $ReadFile1Name $ReadFile2Name $OutputPrefix $ReadSize $DatabasePrefix $Outputfolder $SrcFolder $noIRMstr") ; | |
| 244 print "=================STAGE 3 CUTOFF====================\n"; | |
| 245 # raw | |
| 246 system("bash $SrcFolder/bin/apply_cutoff.sh $OutputPrefix $CutoffLevel $Outputfolder $JunctionCut $SrcFolder $noIRMstr"); | |
| 247 | |
| 248 | |
| 249 } | |
| 250 | |
| 251 if($MapSoftware eq "rmap") | |
| 252 { | |
| 253 print "=================STAGE 1 MAPPING===================\n"; | |
| 254 | |
| 255 system("bash $SrcFolder/bin/mapping_rmap.sh $ReadFile1Name $ReadFileFormat $DatabasePrefix $Outputfolder $SrcFolder") ; | |
| 256 system("bash $SrcFolder/bin/mapping_rmap.sh $ReadFile2Name $ReadFileFormat $DatabasePrefix $Outputfolder $SrcFolder") if($ReadFile2Name ne $ReadFile1Name); | |
| 257 print "=================STAGE 2 ESTIMATION================\n"; | |
| 258 | |
| 259 system("bash $SrcFolder/bin/batch_para_cov10p_fit.sh $ReadFile1Name $ReadFile2Name $OutputPrefix $ReadSize $DatabasePrefix $Outputfolder $SrcFolder $noIRMstr") ; | |
| 260 print "=================STAGE 3 CUTOFF====================\n"; | |
| 261 system("bash $SrcFolder/bin/apply_cutoff.sh $OutputPrefix $CutoffLevel $Outputfolder $JunctionCut $SrcFolder $noIRMstr"); | |
| 262 | |
| 263 | |
| 264 } | |
| 265 | |
| 266 #print "============ALL DONE, OUTPUTFILE:$OutputPrefix.txt\n"; | |
| 267 | |
| 268 if($onGalaxy_raw ne "" && $onGalaxy_txt ne "") | |
| 269 { | |
| 270 print "OUTPUTFILE:$OutputPrefix.raw\n"; | |
| 271 system("grep -v na $Outputfolder/$OutputPrefix.raw >$onGalaxy_raw"); | |
| 272 print "OUTPUTFILE:$OutputPrefix.txt\n"; | |
| 273 system("grep -v na $Outputfolder/$OutputPrefix.txt >$onGalaxy_txt"); | |
| 274 } | |
| 275 | |
| 276 print "============Clean up\n"; | |
| 277 system("rm -r $Outputfolder/$OutputPrefix.*"); | |
| 278 | |
| 279 sub random_sessid { | |
| 280 #my @chars = (0..9,a..z,A..Z); | |
| 281 my @chars = ('a'..'z','A'..'Z'); | |
| 282 my $len = 10; | |
| 283 my $string = join '', map {$chars[rand(@chars)]} (1..$len); | |
| 284 return $string; | |
| 285 } |
