| 1 | #!/usr/bin/env perl | ||
| 2 | # -*-CPerl-*- | ||
| 3 | # Last changed Time-stamp: <2017-06-08 17:24:10 michl> | ||
| 4 | # | ||
| 5 | # *********************************************************************** | ||
| 6 | # * Copyright notice | ||
| 7 | # * | ||
| 8 | # * Copyright 2017 Michael T. Wolfinger <michael@wolfinger.eu> | ||
| 9 | # * All rights reserved | ||
| 10 | # * | ||
| 11 | # * This program is free software: you can redistribute it and/or modify | ||
| 12 | # * it under the terms of the GNU General Public License as published by | ||
| 13 | # * the Free Software Foundation, either version 3 of the License, or | ||
| 14 | # * (at your option) any later version. | ||
| 15 | # * | ||
| 16 | # * This program is distributed in the hope that it will be useful, | ||
| 17 | # * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | # * GNU General Public License for more details. | ||
| 20 | # * | ||
| 21 | # * You should have received a copy of the GNU General Public License | ||
| 22 | # * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 23 | # * | ||
| 24 | # * This copyright notice MUST APPEAR in all copies of the script! | ||
| 25 | # *********************************************************************** | ||
| 26 | |||
| 27 | use strict; | ||
| 28 | use warnings; | ||
| 29 | use Getopt::Long qw( :config posix_default bundling no_ignore_case ); | ||
| 30 | use Pod::Usage; | ||
| 31 | use Path::Class; | ||
| 32 | use Data::Dumper; | ||
| 33 | use Bio::ViennaNGS::Util qw(bed2bigBed mkdircheck); | ||
| 34 | use Bio::ViennaNGS::SpliceJunc qw(bed6_ss_from_bed12 bed6_ss_from_rnaseq intersect_sj); | ||
| 35 | use Bio::ViennaNGS::Fasta; | ||
| 36 | |||
| 37 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 38 | #^^^^^^^^^^ Variables ^^^^^^^^^^^# | ||
| 39 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 40 | |||
| 41 | my ($path_out,$path_annot,$path_ss,$fastaO); | ||
| 42 | my $mincov = 10; | ||
| 43 | my $window = 10; | ||
| 44 | my $max_intron_length = 7000; # 7000 for A. thaliana | ||
| 45 | my $outdir = "./"; | ||
| 46 | my $prefix = ""; | ||
| 47 | my $dirname_annot = "annotated"; | ||
| 48 | my $dirname_ss = "mapped"; | ||
| 49 | my $want_canonical = 0; | ||
| 50 | my $want_bigbed = 0; | ||
| 51 | my $s_in = '-'; | ||
| 52 | my $bed12_in = '-'; | ||
| 53 | my $fa_in = '-'; | ||
| 54 | my $cs_in = '-'; | ||
| 55 | my %fastaobj = (); | ||
| 56 | my @result = (); | ||
| 57 | |||
| 58 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 59 | #^^^^^^^^^^^^^^ Main ^^^^^^^^^^^^^# | ||
| 60 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^# | ||
| 61 | |||
| 62 | Getopt::Long::config('no_ignore_case'); | ||
| 63 | pod2usage(-verbose => 1) unless GetOptions("s=s" => \$s_in, | ||
| 64 | "a=s" => \$bed12_in, | ||
| 65 | "f=s" => \$fa_in, | ||
| 66 | "c=s" => \$cs_in, | ||
| 67 | "n" => sub{$want_canonical=1}, | ||
| 68 | "b" => sub{$want_bigbed=1}, | ||
| 69 | "o=s" => \$outdir, | ||
| 70 | "r=s" => \$mincov, | ||
| 71 | "i=s" => \$max_intron_length, | ||
| 72 | "p=s" => \$prefix, | ||
| 73 | "w=s" => \$window, | ||
| 74 | "man" => sub{pod2usage(-verbose => 2)}, | ||
| 75 | "help|h" => sub{pod2usage(1)} | ||
| 76 | ); | ||
| 77 | |||
| 78 | unless ($bed12_in =~ /^\//) {$bed12_in = "./".$bed12_in;} | ||
| 79 | unless (-f $bed12_in) { | ||
| 80 | warn "Could not find input file $bed12_in given via -a option"; | ||
| 81 | pod2usage(-verbose => 0); | ||
| 82 | } | ||
| 83 | |||
| 84 | unless ($s_in =~ /^\//) {$s_in = "./".$s_in;} | ||
| 85 | unless (-f $s_in){ | ||
| 86 | warn "Could not find input file $s_in given via -s option"; | ||
| 87 | pod2usage(-verbose => 0); | ||
| 88 | } | ||
| 89 | |||
| 90 | if ($want_canonical==1){ | ||
| 91 | unless ($fa_in =~ /^\//) {$fa_in = "./".$fa_in;} | ||
| 92 | unless (-f $fa_in){ | ||
| 93 | warn "Could not find input file $fa_in given via -f option"; | ||
| 94 | pod2usage(-verbose => 0); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | if($want_bigbed==1){ | ||
| 99 | unless ($cs_in =~ /^\//) {$cs_in = "./".$cs_in;} | ||
| 100 | unless (-f $cs_in){ | ||
| 101 | warn "Could not find input file $cs_in given via -c option"; | ||
| 102 | pod2usage(-verbose => 0); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | #TODO check if we are allowed to write to $outdir | ||
| 107 | $path_annot = dir($outdir,$dirname_annot); | ||
| 108 | $path_ss = dir($outdir,$dirname_ss); | ||
| 109 | unless (-d $outdir){mkdircheck($outdir);} | ||
| 110 | unless (-d $path_annot){mkdircheck($path_annot);} | ||
| 111 | unless (-d $path_ss){mkdircheck($path_ss);} | ||
| 112 | |||
| 113 | if($want_canonical){ | ||
| 114 | $fastaO = Bio::ViennaNGS::Fasta->new(fasta=>$fa_in); | ||
| 115 | } | ||
| 116 | |||
| 117 | # Extract annotated splice sites from a BED12 file | ||
| 118 | bed6_ss_from_bed12($bed12_in,$path_annot,$window,$want_canonical,$fastaO); | ||
| 119 | |||
| 120 | # Extract mapped splice junctions and create a BED6 file for each | ||
| 121 | # of them | ||
| 122 | bed6_ss_from_rnaseq($s_in,$path_ss,$window,$mincov,$want_canonical,$fastaO); | ||
| 123 | |||
| 124 | # Check for each splice junction seen in RNA-seq if it overlaps with | ||
| 125 | # any annotated splice junction | ||
| 126 | @result = intersect_sj($path_annot,$path_ss,$outdir,$prefix,$window,$max_intron_length); | ||
| 127 | my ($exist,$novel) = @result; | ||
| 128 | |||
| 129 | if($want_bigbed){ | ||
| 130 | my $bbe = bed2bigBed($exist,$cs_in,$outdir,undef); | ||
| 131 | my $bbn = bed2bigBed($novel,$cs_in,$outdir,undef); | ||
| 132 | } | ||
| 133 | |||
| 134 | __END__ |