line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::SimulateReads::Read; |
2
|
|
|
|
|
|
|
# ABSTRACT: Base class to simulate reads |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
2750
|
use App::SimulateReads::Base 'class'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'sequencing_error' => ( |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
isa => 'My:NumHS', |
11
|
|
|
|
|
|
|
required => 1 |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'read_size' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => 'My:IntGt0', |
17
|
|
|
|
|
|
|
required => 1 |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has '_count_base' => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'Int', |
23
|
|
|
|
|
|
|
default => 0 |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has '_base' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => 'Int', |
29
|
|
|
|
|
|
|
builder => '_build_base', |
30
|
|
|
|
|
|
|
lazy_build => 1 |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has '_not_base' => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
isa => 'HashRef', |
36
|
|
|
|
|
|
|
builder => '_build_not_base', |
37
|
|
|
|
|
|
|
lazy_build => 1 |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _build_not_base { |
41
|
27
|
|
|
27
|
|
569
|
my %not_base = ( |
42
|
|
|
|
|
|
|
A => ['T', 'C', 'G'], |
43
|
|
|
|
|
|
|
a => ['t', 'c', 'g'], |
44
|
|
|
|
|
|
|
T => ['A', 'C', 'G'], |
45
|
|
|
|
|
|
|
t => ['a', 'c', 'g'], |
46
|
|
|
|
|
|
|
C => ['A', 'T', 'G'], |
47
|
|
|
|
|
|
|
c => ['a', 't', 'g'], |
48
|
|
|
|
|
|
|
G => ['A', 'T', 'C'], |
49
|
|
|
|
|
|
|
g => ['a', 't', 'c'] |
50
|
|
|
|
|
|
|
); |
51
|
27
|
|
|
|
|
748
|
return \%not_base; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _build_base { |
55
|
27
|
|
|
27
|
|
57
|
my $self = shift; |
56
|
|
|
|
|
|
|
# If sequencing_error equal to zero, set _base to zero |
57
|
27
|
|
33
|
|
|
702
|
return $self->sequencing_error && int(1 / $self->sequencing_error); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub subseq { |
61
|
1547
|
|
|
1547
|
0
|
37371
|
my ($self, $seq_ref, $seq_len, $slice_len, $pos) = @_; |
62
|
1547
|
|
|
|
|
2567
|
my $read = substr $$seq_ref, $pos, $slice_len; |
63
|
1547
|
|
|
|
|
2825
|
return \$read; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub subseq_rand { |
67
|
2104
|
|
|
2104
|
0
|
46920
|
my ($self, $seq_ref, $seq_len, $slice_len) = @_; |
68
|
2104
|
|
|
|
|
3368
|
my $usable_len = $seq_len - $slice_len; |
69
|
2104
|
|
|
|
|
4453
|
my $pos = int(rand($usable_len + 1)); |
70
|
2104
|
|
|
|
|
4726
|
my $read = substr $$seq_ref, $pos, $slice_len; |
71
|
2104
|
|
|
|
|
4805
|
return (\$read, $pos); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub insert_sequencing_error { |
75
|
2930
|
|
|
2930
|
0
|
4528
|
my ($self, $seq_ref) = @_; |
76
|
2930
|
|
|
|
|
68486
|
my $err = int($self->_count_base * $self->sequencing_error); |
77
|
|
|
|
|
|
|
|
78
|
2930
|
|
|
|
|
6796
|
for (my $i = 0; $i < $err; $i++) { |
79
|
2790
|
|
|
|
|
63953
|
$self->update_count_base(-$self->_base); |
80
|
2790
|
|
|
|
|
65591
|
my $pos = $self->read_size - $self->_count_base - 1; |
81
|
2790
|
|
|
|
|
5140
|
my $b = substr($$seq_ref, $pos, 1); |
82
|
2790
|
|
|
|
|
5075
|
substr($$seq_ref, $pos, 1) = $self->_randb($b); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub update_count_base { |
87
|
5720
|
|
|
5720
|
0
|
8560
|
my ($self, $val) = @_; |
88
|
5720
|
|
|
|
|
130154
|
$self->_count_base($self->_count_base + $val); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub reverse_complement { |
92
|
1418
|
|
|
1418
|
0
|
17088
|
my ($self, $seq_ref) = @_; |
93
|
1418
|
|
|
|
|
2659
|
$$seq_ref = reverse $$seq_ref; |
94
|
1418
|
|
|
|
|
2747
|
$$seq_ref =~ tr/atcgATCG/tagcTAGC/; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _randb { |
98
|
2790
|
|
|
2790
|
|
4423
|
my ($self, $base) = @_; |
99
|
2790
|
|
33
|
|
|
63272
|
return $self->_not_base->{$base}[int(rand(3))] || $base; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=pod |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=encoding UTF-8 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
App::SimulateReads::Read - Base class to simulate reads |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 VERSION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
version 0.06 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Teaching and Research Institute from SÃrio-Libanês Hospital. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This is free software, licensed under: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |