forked from mroosmalen/nanosv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreakpoint.pm
executable file
·64 lines (54 loc) · 1.79 KB
/
Breakpoint.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/perl
package Breakpoint;
use strict;
sub new {
my ( $class, $id, $segment_1, $segment_2 ) = @_;
my %self = (
'_id' => $id,
'_segment_1' => {
'_id' => $segment_1->{_id},
'_rname' => $segment_1->{_rname},
'_flag' => $segment_1->{_flag},
'_mapq' => $segment_1->{_mapq}
},
'_segment_2' => {
'_id' => $segment_2->{_id},
'_rname' => $segment_2->{_rname},
'_flag' => $segment_2->{_flag},
'_mapq' => $segment_2->{_mapq}
}
);
return bless \%self, $class;
}
sub setGap {
my ( $self, $gap ) = @_;
$self->{_gap} = $gap;
}
sub setBreakpoint {
my ( $self, $segment_1, $segment_2 ) = @_;
$self->{_segment_1}{_pos} = $segment_1->{_flag} & 16 ? $segment_1->{_pos} : $segment_1->{_end};
$self->{_segment_2}{_pos} = $segment_2->{_flag} & 16 ? $segment_2->{_end} : $segment_2->{_pos};
}
sub setPlength {
my ( $self, $segment_1, $segment_2, $read ) = @_;
$self->{_segment_1}{_plength} = ( $segment_1->{_length} / $read->{_length} );
$self->{_segment_2}{_plength} = ( $segment_2->{_length} / $read->{_length} );
}
sub switchSegments {
my ( $self ) = @_;
( $self->{_segment_1}, $self->{_segment_2} ) = ( $self->{_segment_2}, $self->{_segment_1} );
$self->{_segment_1}{_flag} = $self->{_segment_1}{_flag} & 16 ? 0 : 16;
$self->{_segment_2}{_flag} = $self->{_segment_2}{_flag} & 16 ? 0 : 16;
}
sub setSVtype {
my ( $self ) = @_;
if ( $self->{_segment_1}{_rname} !~ /^$self->{_segment_2}{_rname}$/ ) {
$self->{_svtype} = "BND";
} else {
$self->{_svtype} = $self->{_segment_1}{_flag} & 16 ? $self->{_segment_2}{_flag} & 16 ? "DUP" : "BND" : $self->{_segment_2}{_flag} & 16 ? "BND" : "DEL";
if ( abs( $self->{_segment_2}{_pos} - $self->{_segment_1}{_pos} ) < $self->{_gap} and $self->{_svtype} eq "DEL") {
$self->{_svtype} = "INS";
}
}
}
1;