| 1 | # -*-CPerl-*- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Last changed Time-stamp: <2017-06-10 19:08:57 michl> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package Bio::ViennaNGS::SpliceJunc; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Bio::ViennaNGS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Bio::ViennaNGS::Fasta; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IPC::Cmd qw(can_run run); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Path::Class; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | our @EXPORT = (); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our @EXPORT_OK = qw(bed6_ss_from_bed12 bed6_ss_from_rnaseq | |||||||||||||||||||||||||||||||||||||||||
| 21 | bed6_ss_to_bed12 intersect_sj ss_isCanonical); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # bed6_ss_from_bed12( $bed12,$dest,$window,$can,$fastaO) | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # Extracts splice junctions from BED12 annotation. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # Writes a BED6 file for each transcript found in the BED12, listing | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # all splice sites of this transcript, optionally flanking it with a | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # window of +/-$window nt. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | sub bed6_ss_from_bed12{ | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my ($bed12,$dest,$window,$can,$fastaobjR) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bed6_ss_from_bed12: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my ($i,$tr_name,$pos5,$pos3); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($splicesites,$c,$totalsj,$cansj) = (0)x4; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my @bedline = (); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | croak "ERROR [$this_function] $bed12 does not exists\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | unless (-e $bed12); | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | unless (-d $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | open(BED12IN, "< $bed12") or croak $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | while(<BED12IN>){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my ($chr,$chromStart,$chromEnd,$name,$score,$strand,$thickStart, | |||||||||||||||||||||||||||||||||||||||||
| 46 | $thickEnd,$itemRgb,$blockCount,$blockSizes,$blockStarts) = split("\t"); | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @blockSize = split(/,/,$blockSizes); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my @blockStart = split(/,/,$blockStarts); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless (scalar @blockSize == scalar @blockStart){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | croak "ERROR: unequal element count in blockStarts and blockSizes\n"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $fn = sprintf("%s_%d-%d_%s.annotatedSS.bed6",$chr,$chromStart,$chromEnd,$name); | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $bed6_fn = file($dest,$fn); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $tr_count = 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($blockCount >1){ # only transcripts with 2 or more exons (!!!) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | open(BED6OUT, "> $bed6_fn") or croak "cannot open BED6OUT $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | for ($i=0;$i<$blockCount-1;$i++){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $totalsj++; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $pos5 = $chromStart+$blockStart[$i]+$blockSize[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $pos3 = $chromStart+$blockStart[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if($can){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $c = ss_isCanonical($chr,$pos5,$pos3,$fastaobjR); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $cansj++; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $tr_name = sprintf("%s.%02d",$name,$tr_count++); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | @bedline = join("\t",$chr,eval($pos5-$window), | |||||||||||||||||||||||||||||||||||||||||
| 70 | eval($pos5+$window),$tr_name,$c,$strand); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | print BED6OUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | @bedline = join("\t",$chr,eval($pos3-$window), | |||||||||||||||||||||||||||||||||||||||||
| 73 | eval($pos3+$window),$tr_name,$c,$strand); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | print BED6OUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } # end for | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | close(BED6OUT); | |||||||||||||||||||||||||||||||||||||||||
| 78 | } # end if | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } # end while | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | close(BED12IN); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # bed6_ss_from_rnaseq ($bed_in,$dest,$window,$mincov,$can,$fastaO) | ||||||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # Extracts splice junctions from mapped RNA-seq data | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # Writes a BED6 file for each splice junction present in the input, | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # optionally flanking it with a window of +/-$window nt. Only splice | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # junctions supported by at least $mcov reads are considered. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | sub bed6_ss_from_rnaseq{ | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my ($bed_in,$dest,$window,$mcov,$can,$fastaobjR) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bed6_ss_from_rnaseq: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($reads,$proper,$passed,$pos5,$pos3); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my @bedline = (); | |||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | croak "ERROR [$this_function] $bed_in does not exist\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | unless (-e $bed_in); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | unless (-d $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | open(INBED, "< $bed_in") or croak $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | while(<INBED>){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my ($chr, $start, $end, $info, $score, $strand) = split("\t"); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $end = $end-2; # required for segemehl's BED6 files | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($info =~ /^splits\:(\d+)\:(\d+)\:(\d+):(\w):(\w)/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $reads = $1; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $proper = $4; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $passed = $5; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | next unless ($proper eq 'N'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | next unless ($passed =~ /[PFM]$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | next if($reads < $mcov); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | croak "ERROR [$this_function] unsupported INFO field in input BED:\n$info\n"; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $pos5 = $start; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $pos3 = $end; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if($can){$c = ss_isCanonical($chr,$pos5,$pos3,$fastaobjR);} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $fn = sprintf("%s_%d-%d.mappedSS.bed6",$chr,$start,$end); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $bed6_fn = file($dest,$fn); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | open(BED6OUT, "> $bed6_fn"); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | @bedline = join("\t",$chr,eval($start-$window), | |||||||||||||||||||||||||||||||||||||||||
| 126 | eval($start+$window),$info,$c,$strand); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | print BED6OUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | @bedline = join("\t",$chr,eval($end-$window), | |||||||||||||||||||||||||||||||||||||||||
| 129 | eval($end+$window),$info,$c,$strand); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | print BED6OUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | close(BED6OUT); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | close(INBED); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # bed6_ss_to_bed12 ($bed_in,$dest,$window,$mcov) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # Produce BED12 from BED6 file holdig splice junctions from mapped | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # RNA-seq data | ||||||||||||||||||||||||||||||||||||||||||
| 140 | sub bed6_ss_to_bed12{ | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my ($bed_in,$dest,$window,$mcov,$circ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bed6_ss_to_bed12: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my ($reads,$proper,$passed,$pos5,$pos3,$basename,$fn,$bed12_fn); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my @bedline = (); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | croak "ERROR [$this_function] $bed_in does not exist\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | unless (-e $bed_in); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | unless (-d $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $basename = fileparse($bed_in,qr/\.[^.]*/); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $fn = $basename.".bed12"; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $bed12_fn = file($dest,$fn); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | open(BED12OUT, "> $bed12_fn"); | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | open(INBED, "< $bed_in") or croak $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | while(<INBED>){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my ($chr, $start, $end, $info, $score, $strand) = split("\t"); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ($info =~ /^splits\:(\d+)\:(\d+)\:(\d+):(\w):(\w)/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $reads = $1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $proper = $4; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $passed = $5; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($circ == 1){ # skip 'N' (normal), 'L' (left) and 'R' (right) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | next unless ($proper =~ /[C]$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else { # skip 'L', 'R' and 'C' | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | next unless ($proper =~ /[N]$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | next unless ($passed =~ /[PM]$/); # ignore 'F' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | next if($reads < $mcov); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | croak "ERROR [$this_function] unsupported INFO field in input BED:\n$info\n"; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $pos5 = $start; | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $pos3 = $end; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | @bedline = join("\t",$chr,eval($start-$window), | |||||||||||||||||||||||||||||||||||||||||
| 182 | eval($end+$window),$info,$score,$strand,$start,$end, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | "0","2","1,1","0,".eval($end-$start-1)); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | print BED12OUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | close(INBED); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | close(BED12OUT); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | push (@result, $bed12_fn); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | # intersect_sj($p_annot,$p_mapped,$dest,$prefix,$window,$mil) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | # | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # Intersect splice junctions determined by RNA-seq with annotated | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # splice junctions. Determine novel and existing splice junctions. | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # Writes BED6 files for existing and novel splice junctions to $dest | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # and reurns an array with the absolute path to the two resulting BED | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # files | ||||||||||||||||||||||||||||||||||||||||||
| 201 | sub intersect_sj{ | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my ($p_annot,$p_mapped,$dest,$prefix,$window,$mil) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
intersect_sj: not called CC=26 SCAR=65.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my ($dha,$dhm); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $processed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my @junctions = (); | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my @transcript_beds = (); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my %asj = (); # annotated splice junctions hash | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $bedtools = can_run('bedtools') or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | croak "ERROR [$this_function] bedtools not found"; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my $sortBed = can_run('sortBed') or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | croak "ERROR [$this_function] sortBed not found"; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | croak "ERROR [$this_function] $p_annot does not exist\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | unless (-d $p_annot); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | croak "ERROR [$this_function] $p_mapped does not exist\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | unless (-d $p_mapped); | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | croak "ERROR [$this_function] $dest does not exist\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | unless (-d $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | # get a list of all files in $p_annot | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | opendir($dha, $p_annot) or croak "Cannot opendir $p_annot: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | while(readdir $dha) { push @transcript_beds, $_; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | closedir($dha); | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # get a list of all splice junctions seen in RNA-seq data | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | opendir($dhm, $p_mapped) or croak "Cannot opendir $p_mapped: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | @junctions = grep { /^(chr\d+)\_(\d+)-(\d+)\.mappedSS\.bed6/ } readdir($dhm); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # process splice junctions seen in RNA-seq data | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | foreach my $file (@junctions){ | |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $processed++; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | croak "Unexpected file name pattern\n" unless ($file =~ /(chr\d+)\_(\d+)-(\d+)/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $sc = $1; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $s5 = $2; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $s3 = $3; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $pattern = $sc."_".$s5."-".$s3; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my @annotated_beds = grep { /^(chr\d+)\_(\d+)-(\d+)/ && $2<=$s5 && $3>=$s3 && $sc eq $1} @transcript_beds; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
/^(chr\d+)\_(\d+)-(\d+)/ and $2 <= $s5 and $3 >= $s3
/^(chr\d+)\_(\d+)-(\d+)/ and $2 <= $s5
MC/DC0%0/3
/^(chr\d+)\_(\d+)-(\d+)/ and $2 <= $s5 and $3 >= $s3
/^(chr\d+)\_(\d+)-(\d+)/
$2 <= $s5
$3 >= $s3
Truth table0%0/4
A and B and C
A= /^(chr\d+)\_(\d+)-(\d+)/B= $2 <= $s5C= $3 >= $s3
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | #print"\t intersecting against ".(eval $#annotated_beds+1)." transcripts: @annotated_beds \n"; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | # intersect currently opened SJ against all transcripts in @annotated_beds | ||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | foreach my $i (@annotated_beds){ | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $a = file($p_mapped,$file); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $b = file($p_annot,$i); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $intersect_cmd = "$bedtools intersect -a $a -b $b -c -nobuf"; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | open(INTERSECT, $intersect_cmd."|"); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | while(<INTERSECT>){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($_ =~ /1$/) { $asj{$pattern} = 1;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | close(INTERSECT); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( $processed % 1000 == 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | print STDERR "processed $processed splice junctions\n"; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | closedir($dhm); | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # go through the mapped splice junctions files once again and | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # separate novel from existing splice junctions | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if (length($prefix)>0){$prefix .= ".";} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $outname_exist = file($dest, $prefix."exist.SS.bed"); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $outname_exist_u = file($dest, $prefix."exist.SS.u.bed"); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $outname_novel = file($dest, $prefix."novel.SS.bed"); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $outname_novel_u = file($dest, $prefix."novel.SS.u.bed"); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | open (EXISTOUT, "> $outname_exist_u"); | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | open (NOVELOUT, "> $outname_novel_u"); | |||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # write new ones to NOVELOUT; existing ones to EXISTOUT | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | foreach my $file (@junctions){ | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if ($file =~ m/^(chr\d+\_\d+-\d+)/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $pattern = $1; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $fn = file($p_mapped,$file); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | open (SJ, "< $fn") or croak "Cannot open $fn $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | while(<SJ>){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $_ = m/^(chr\w+)\s(\d+)\s(\d+)\s(splits:\d+:\d+:\d+:\w:\w)\s(\d+)\s([+-01])/; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $chr = $1; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $start = $2; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $end = $3; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $name = $4; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $score = $5; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $strand = $6; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my @bedline = join("\t",$chr,eval($start+$window), | |||||||||||||||||||||||||||||||||||||||||
| 287 | eval($start+$window+1),$name,$score,$strand); | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if (exists $asj{$pattern}){ # annotated splice junction | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | print EXISTOUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | else { # novel splice junction | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | print NOVELOUT "@bedline\n"; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | } # end while | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | close(SJ); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } # end if | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | else{ carp "Error with parsing BED6 junction file names __FILE__ __LINE__\n";} | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | close(EXISTOUT); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | close(NOVELOUT); | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | # sort the resulting bed files | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my $cmd = "$bedtools sort -i $outname_exist_u > $outname_exist"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||||||||||||||||
| 305 | run( command => $cmd, verbose => 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if( !$success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | print STDERR "ERROR [$this_function] Call to $bedtools unsuccessful\n"; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | croak $!; | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | unlink($outname_exist_u); | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $cmd = "$bedtools sort -i $outname_novel_u > $outname_novel"; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) = | |||||||||||||||||||||||||||||||||||||||||
| 316 | run( command => $cmd, verbose => 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if( !$success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | print STDERR "ERROR [$this_function] Call to $bedtools unsuccessful\n"; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | print STDERR "ERROR: this is what the command printed:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | print join "", @$full_buf; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | croak $!; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | unlink($outname_novel_u); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | printf STDERR "processed $processed splice junctions\n"; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my @result = (); | |||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | push(@result, $outname_exist); | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | push(@result, $outname_novel); | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return @result; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # ss_isCanonical ( $chr,$p5,$p3,$fastaO ) | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | # Checks whether a given splice junction is canonical, ie. whether the | ||||||||||||||||||||||||||||||||||||||||||
| 335 | # first and last two nucleotides of the enclosed intron correspond to | ||||||||||||||||||||||||||||||||||||||||||
| 336 | # a certain nucleotide motif. $chr is the chromosome name, $p5 and $p3 | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # the 5' and 3' ends of the splice junction and $fastaobjR is a | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # Bio::PrimarySeq::Fasta object holding the underlying reference | ||||||||||||||||||||||||||||||||||||||||||
| 339 | # genome. | ||||||||||||||||||||||||||||||||||||||||||
| 340 | # | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # Th most common canonical splice junction motif is GT-AG (shown | ||||||||||||||||||||||||||||||||||||||||||
| 342 | # below). Other canonical motifs are GC->AG and AT->AC. | ||||||||||||||||||||||||||||||||||||||||||
| 343 | # | ||||||||||||||||||||||||||||||||||||||||||
| 344 | # ------------------> | ||||||||||||||||||||||||||||||||||||||||||
| 345 | # 5'===]GT..........AG[====3' | ||||||||||||||||||||||||||||||||||||||||||
| 346 | # | ||||||||||||||||||||||||||||||||||||||||||
| 347 | # <----------------- | ||||||||||||||||||||||||||||||||||||||||||
| 348 | # 3'===]GA..........TG[====5' | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # | ||||||||||||||||||||||||||||||||||||||||||
| 350 | sub ss_isCanonical{ | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | my ($chr,$p5,$p3,$fo) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ss_isCanonical: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | my ($seqL,$seqR,$pattern); | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $ss_motif_length = 2; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $this_function = (caller(0))[3]; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $c = -1; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $seqL = $fo->stranded_subsequence($chr,$p5+1,$p5+$ss_motif_length,"+"); | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $seqR = $fo->stranded_subsequence($chr,$p3-$ss_motif_length+1,$p3,"+"); | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $pattern = sprintf("%s|%s",$seqL,$seqR); | |||||||||||||||||||||||||||||||||||||||||
| 361 | #print STDERR "[$this_function] p5->p3 ($p5 -- $p3) $seqL -- $seqR\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if ($pattern =~ /^GT|AG$/) { $c = 1000;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | elsif ($pattern =~ /^CT|AC$/) { $c = 1000; } | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | elsif ($pattern =~ /^GC|AG$/) { $c = 1000; } | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | elsif ($pattern =~ /^CT|GC$/) { $c = 1000; } | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | elsif ($pattern =~ /^AT|AC$/) { $c = 1000; } | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | elsif ($pattern =~ /^GT|AT$/) { $c = 1000; } | |||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | else { $c = 0;} | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 375 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | Bio::ViennaNGS::SpliceJunc - Perl extension for alternative splicing | ||||||||||||||||||||||||||||||||||||||||||
| 380 | analysis | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | use Bio::ViennaNGS::SpliceJunc; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | use Bio::ViennaNGS::Fasta; | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | # get a Bio::ViennaNGS::Fasta object | ||||||||||||||||||||||||||||||||||||||||||
| 388 | my $fastaO = Bio::ViennaNGS::Fasta->new($fasta_in); | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | # Extract annotated splice sites from BED12 | ||||||||||||||||||||||||||||||||||||||||||
| 391 | bed6_ss_from_bed12($bed12_in,$dest_annot,$window,$want_canonical,$fastaO); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | # Extract mapped splice junctions from RNA-seq data | ||||||||||||||||||||||||||||||||||||||||||
| 394 | bed6_ss_from_rnaseq($bed_in,$dest_ss,$window,$mincov,$want_canonical,$fastaO); | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | # Check for each splice junction seen in RNA-seq if it overlaps with | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # any annotated splice junction | ||||||||||||||||||||||||||||||||||||||||||
| 398 | @res = intersect_sj($dest_annot,$dest_ss,$dest,$prefix,$window,$mil); | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | # Convert splice junctions seen in RNA-seq data to BED12 | ||||||||||||||||||||||||||||||||||||||||||
| 401 | @res = bed6_ss_to_bed12($s_in,$outdir,$window,$mincov,$want_circular); | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | # Check whether a splice junction is canonical | ||||||||||||||||||||||||||||||||||||||||||
| 404 | $c = ss_isCanonical($chr,$pos5,$pos3,$fastaO); | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | L<Bio::ViennaNGS::SpliceJunc> is a Perl module for alternative | ||||||||||||||||||||||||||||||||||||||||||
| 409 | splicing (AS) analysis. It provides routines for identification, | ||||||||||||||||||||||||||||||||||||||||||
| 410 | characterization and visualization of novel and existing (annotated) | ||||||||||||||||||||||||||||||||||||||||||
| 411 | splice junctions from RNA-seq data. | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | Identification of novel splice junctions is based on intersecting | ||||||||||||||||||||||||||||||||||||||||||
| 414 | potentially novel splice junctions from RNA-seq data with annotated | ||||||||||||||||||||||||||||||||||||||||||
| 415 | splice junctions. | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | =head2 SUBROUTINES | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | =item bed6_ss_from_bed12($bed12,$dest,$window,$can,$fastaO) | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | Extracts splice junctions from a BED12 file (provided via argument | ||||||||||||||||||||||||||||||||||||||||||
| 424 | C<$bed12>), writes a BED6 file for each transcript to C<$dest>, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | containing all its splice junctions. If C<$can> is 1, canonical splice | ||||||||||||||||||||||||||||||||||||||||||
| 426 | junctions are reported in the 'name' field of the output BED6 file. | ||||||||||||||||||||||||||||||||||||||||||
| 427 | Output splice junctions can be flanked by a window of +/- C<$window> | ||||||||||||||||||||||||||||||||||||||||||
| 428 | nt. C<$fastaO> is a L<Bio::ViennaNGS::Fasta> object. Each splice | ||||||||||||||||||||||||||||||||||||||||||
| 429 | junction is represented as two bed lines in the output BED6. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | =item bed6_ss_from_rnaseq($bed_in,$dest,$window,$mcov,$can,$fastaO) | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | Extracts splice junctions from mapped RNA-seq data. The input BED6 | ||||||||||||||||||||||||||||||||||||||||||
| 434 | file should contain coordinates of introns in the following syntax: | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | chr1 3913 3996 splits:97:97:97:N:P 0 + | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | The fourth column in this BED file (correponding to the 'name' field | ||||||||||||||||||||||||||||||||||||||||||
| 439 | according to the L<BED | ||||||||||||||||||||||||||||||||||||||||||
| 440 | specification|http://genome.ucsc.edu/FAQ/FAQformat.html#format1>) | ||||||||||||||||||||||||||||||||||||||||||
| 441 | should be a colon-separated string of six elements, where the first | ||||||||||||||||||||||||||||||||||||||||||
| 442 | element should be 'splits' and the second element is assumed to hold | ||||||||||||||||||||||||||||||||||||||||||
| 443 | the number of reads supporting this splice junction. The fifth element | ||||||||||||||||||||||||||||||||||||||||||
| 444 | indicates the splice junction type: A capital 'N' determines a normal | ||||||||||||||||||||||||||||||||||||||||||
| 445 | splice junction, whereas 'C' indicates circular and 'T' indicates | ||||||||||||||||||||||||||||||||||||||||||
| 446 | trans-splice junctions, respectively. Only normal splice junctions | ||||||||||||||||||||||||||||||||||||||||||
| 447 | ('N') are considered, the rest is skipped. Elements 3, 4 and 6 are not | ||||||||||||||||||||||||||||||||||||||||||
| 448 | further processed. | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | We recommend using | ||||||||||||||||||||||||||||||||||||||||||
| 451 | F<segemehl|http://www.bioinf.uni-leipzig.de/Software/segemehl/> for | ||||||||||||||||||||||||||||||||||||||||||
| 452 | generating this type of BED6 files. This routine is, however, not | ||||||||||||||||||||||||||||||||||||||||||
| 453 | limited to F<segemehl> output. BED6 files containing splice junction | ||||||||||||||||||||||||||||||||||||||||||
| 454 | information from other short read mappers or third-party sources will | ||||||||||||||||||||||||||||||||||||||||||
| 455 | be processed if they are formatted as described above. | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | This routine writes a BED6 file for each splice junction provided in | ||||||||||||||||||||||||||||||||||||||||||
| 458 | the input to C<$dest>. Output splice junctions can be flanked by a | ||||||||||||||||||||||||||||||||||||||||||
| 459 | window of +/- C<$window> nt. Canonical splice junctions are reported | ||||||||||||||||||||||||||||||||||||||||||
| 460 | in the 'name' field of the output BED6 file if C<$can> is 1 and | ||||||||||||||||||||||||||||||||||||||||||
| 461 | C<$featO> is a L<Bio::ViennaNGS::Fasta> object. Each splice junction | ||||||||||||||||||||||||||||||||||||||||||
| 462 | is represented as two BED lines in the output BED6. Only splice | ||||||||||||||||||||||||||||||||||||||||||
| 463 | junctions that are supported by at least C<$mcov> reads are reported. | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | =item bed6_ss_to_bed12($bed_in,$dest,$window,$mcov,$circ) | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | Produce BED12 output for splice junctions found in RNA-seq data. Input | ||||||||||||||||||||||||||||||||||||||||||
| 468 | BED6 files (provided via C<$bed_in>) are supposed to conform to the | ||||||||||||||||||||||||||||||||||||||||||
| 469 | F<segemehl|http://www.bioinf.uni-leipzig.de/Software/segemehl/> | ||||||||||||||||||||||||||||||||||||||||||
| 470 | standard format for reporting splice junctions, which has the | ||||||||||||||||||||||||||||||||||||||||||
| 471 | following syntax: | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | chr1 3913 3996 splits:97:97:97:N:P 0 + | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | See L<bed6_ss_rom_rnaseq> for details. | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | C<$dest> is the output path. Output splice junctions can optionally be | ||||||||||||||||||||||||||||||||||||||||||
| 478 | flanked by a window of +/- C<$window> nt. Only splice junctions that | ||||||||||||||||||||||||||||||||||||||||||
| 479 | are supported by at least C<$mcov> reads are reported. If C<$circ> is | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 1, B<circular> splice junctions are reported (if present in the | ||||||||||||||||||||||||||||||||||||||||||
| 481 | input), else B<normal> splice junctions are processed. | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | =item intersect_sj($p_annot,$p_mapped,$dest,$prefix,$window,$mil) | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | Intersects all splice junctions identified in an RNA-seq experiment | ||||||||||||||||||||||||||||||||||||||||||
| 486 | with annotated splice junctions. Identifies and characterizes novel | ||||||||||||||||||||||||||||||||||||||||||
| 487 | and existing splice junctions. Each BED6 file in C<$p_mapped> is | ||||||||||||||||||||||||||||||||||||||||||
| 488 | intersected with those transcript splice junction BED6 files in | ||||||||||||||||||||||||||||||||||||||||||
| 489 | C<$p_annot>, whose genomic location spans the query splice | ||||||||||||||||||||||||||||||||||||||||||
| 490 | junction. This is to prevent the tool from intersecting each splice | ||||||||||||||||||||||||||||||||||||||||||
| 491 | site found in the mapped RNA-seq data with B<all> annotated | ||||||||||||||||||||||||||||||||||||||||||
| 492 | transcripts. C<$mil> specifies a maximum intron length. | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | The intersection operations are performed with F<bedtools intersect> | ||||||||||||||||||||||||||||||||||||||||||
| 495 | from the L<BEDtools|https://github.com/arq5x/bedtools2> suite). BED | ||||||||||||||||||||||||||||||||||||||||||
| 496 | sorting operations are performed with F<bedtools sort>. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | Writes two BED6 files to C<$dest> (optionally prefixed by C<$prefix>), which | ||||||||||||||||||||||||||||||||||||||||||
| 499 | contain novel and existing splice junctions, respectively. | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | =item ss_isCanonical($chr,$p5,$p3,$fo) | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | Checks whether a given splice junction is canonical, ie. whether the | ||||||||||||||||||||||||||||||||||||||||||
| 504 | first and last two nucleotides of the enclosed intron correspond to a | ||||||||||||||||||||||||||||||||||||||||||
| 505 | certain nucleotide motif. C<$chr> is the chromosome name, C<$p5> and | ||||||||||||||||||||||||||||||||||||||||||
| 506 | C<$p3> the 5' and 3' ends of the splice junction and C<$fo> is a | ||||||||||||||||||||||||||||||||||||||||||
| 507 | L<Bio::ViennaNGS::Fasta> object holding the underlying reference | ||||||||||||||||||||||||||||||||||||||||||
| 508 | genome | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | This routine does not explicitly consider standedness in the sense | ||||||||||||||||||||||||||||||||||||||||||
| 511 | that splice junction motifs are evaluated in terms of the forward | ||||||||||||||||||||||||||||||||||||||||||
| 512 | strand of the underlying reference sequence. This is best explained by | ||||||||||||||||||||||||||||||||||||||||||
| 513 | an example: Consider the splice junction motif GU->G on the reverse | ||||||||||||||||||||||||||||||||||||||||||
| 514 | strand. In 5' to 3' direction of the forward strandm this junction | ||||||||||||||||||||||||||||||||||||||||||
| 515 | reads CT->AC. A splice junction is canonical if its motif corresponds | ||||||||||||||||||||||||||||||||||||||||||
| 516 | to one of the following cases: | ||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 5'===]GT|CT....AG|AC[====3' ie GT->AG or CT->AC | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 5'===]GC|CT....AG|GC[====3' ie GC->AG or CT->GC | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 5'===]AT|GT....AC|AT[====3' ie AT->AC or GT->AT | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | This modules depends on the following Perl modules: | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | =item L<Bio::ViennaNGS> | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | =item L<Bio::ViennaNGS::Fasta> | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | =item L<IPC::Cmd> | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | =item L<Path::Class> | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | =item L<Carp> | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | L<Bio::ViennaNGS::SpliceJunc> uses third-party tools for computing | ||||||||||||||||||||||||||||||||||||||||||
| 543 | intersections of BED files: F<bedtools intersect> from the | ||||||||||||||||||||||||||||||||||||||||||
| 544 | L<BEDtools|http://bedtools.readthedocs.org/en/latest/content/tools/intersect.html> | ||||||||||||||||||||||||||||||||||||||||||
| 545 | suite is used to compute overlaps and F<bedtools sort> is used to sort | ||||||||||||||||||||||||||||||||||||||||||
| 546 | BED output files. Make sure that those third-party utilities are | ||||||||||||||||||||||||||||||||||||||||||
| 547 | available on your system, and that hey can be found and executed by | ||||||||||||||||||||||||||||||||||||||||||
| 548 | the perl interpreter. We recommend installing the latest version of | ||||||||||||||||||||||||||||||||||||||||||
| 549 | L<BEDtools|https://github.com/arq5x/bedtools2> on your system. | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | L<Bio::ViennaNGS> | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | Copyright (C) 2015-2017 Michael T. Wolfinger E<lt>michael@wolfinger.euE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 564 | it under the same terms as Perl itself, either Perl version 5.10.0 or, | ||||||||||||||||||||||||||||||||||||||||||
| 565 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | This software is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||||||||||||||||
| 568 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 569 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||||||||||||||||||||||||||||||||||||||||
| 570 | General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | =cut | ||||||||||||||||||||||||||||||||||||||||||