| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::SimulateReads::Read; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Base class to simulate reads |
|
3
|
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
4471
|
use App::SimulateReads::Base 'class'; |
|
|
6
|
|
|
|
|
22
|
|
|
|
6
|
|
|
|
|
66
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
9
|
|
|
|
|
|
|
# Moose attributes |
|
10
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
11
|
|
|
|
|
|
|
has 'sequencing_error' => (is => 'ro', isa => 'My:NumHS', required => 1); |
|
12
|
|
|
|
|
|
|
has 'read_size' => (is => 'ro', isa => 'My:IntGt0', required => 1); |
|
13
|
|
|
|
|
|
|
has '_count_base' => (is => 'rw', isa => 'Int', default => 0); |
|
14
|
|
|
|
|
|
|
has '_base' => (is => 'rw', isa => 'Int'); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
17
|
|
|
|
|
|
|
# CLASS: Read |
|
18
|
|
|
|
|
|
|
# METHOD: BUILD (Moose) |
|
19
|
|
|
|
|
|
|
# PARAMETERS: Void |
|
20
|
|
|
|
|
|
|
# RETURNS: Void |
|
21
|
|
|
|
|
|
|
# DESCRIPTION: Set the _base attribute. If sequencing_error is zero, set it to |
|
22
|
|
|
|
|
|
|
# zero too |
|
23
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
24
|
|
|
|
|
|
|
# COMMENTS: none |
|
25
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
26
|
|
|
|
|
|
|
#=============================================================================== |
|
27
|
|
|
|
|
|
|
sub BUILD { |
|
28
|
52
|
|
|
52
|
0
|
131
|
my $self = shift; |
|
29
|
|
|
|
|
|
|
# If sequencing_error equal to zero, set _base to zero |
|
30
|
52
|
100
|
|
|
|
1626
|
$self->_base($self->sequencing_error ? int(1 / $self->sequencing_error) : 0); |
|
31
|
|
|
|
|
|
|
} ## --- end sub BUILD |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
34
|
|
|
|
|
|
|
# CLASS: Read |
|
35
|
|
|
|
|
|
|
# METHOD: subseq |
|
36
|
|
|
|
|
|
|
# PARAMETERS: $seq_ref Ref Str, $seq_len Int > 0, $slice_len Int > 0, $pos Int >= 0 |
|
37
|
|
|
|
|
|
|
# RETURNS: $read Ref Str |
|
38
|
|
|
|
|
|
|
# DESCRIPTION: Wrapper to substr built in function |
|
39
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
40
|
|
|
|
|
|
|
# COMMENTS: $slice_len, also plus $pos, must be lesser or equal to $seq_len |
|
41
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
42
|
|
|
|
|
|
|
#=============================================================================== |
|
43
|
|
|
|
|
|
|
sub subseq { |
|
44
|
2491
|
|
|
2491
|
0
|
46975
|
my ($self, $seq_ref, $seq_len, $slice_len, $pos) = @_; |
|
45
|
2491
|
|
|
|
|
5325
|
my $read = substr $$seq_ref, $pos, $slice_len; |
|
46
|
2491
|
|
|
|
|
5880
|
return \$read; |
|
47
|
|
|
|
|
|
|
} ## --- end sub subseq |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
50
|
|
|
|
|
|
|
# CLASS: Read |
|
51
|
|
|
|
|
|
|
# METHOD: subseq_rand |
|
52
|
|
|
|
|
|
|
# PARAMETERS: $seq_ref Ref Str, $seq_len Int > 0, $slice_len Int > 0 |
|
53
|
|
|
|
|
|
|
# RETURNS: $read Ref Str, $pos Int >= 0 |
|
54
|
|
|
|
|
|
|
# DESCRIPTION: Wrapper to substr built in function that slices into a random position |
|
55
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
56
|
|
|
|
|
|
|
# COMMENTS: $slice_len must must be lesser or equal than $seq_len |
|
57
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
58
|
|
|
|
|
|
|
#=============================================================================== |
|
59
|
|
|
|
|
|
|
sub subseq_rand { |
|
60
|
2488
|
|
|
2488
|
0
|
51971
|
my ($self, $seq_ref, $seq_len, $slice_len) = @_; |
|
61
|
2488
|
|
|
|
|
8343
|
my $usable_len = $seq_len - $slice_len; |
|
62
|
2488
|
|
|
|
|
6526
|
my $pos = int(rand($usable_len + 1)); |
|
63
|
2488
|
|
|
|
|
6925
|
my $read = substr $$seq_ref, $pos, $slice_len; |
|
64
|
2488
|
|
|
|
|
6986
|
return (\$read, $pos); |
|
65
|
|
|
|
|
|
|
} ## --- end sub subseq_rand |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
68
|
|
|
|
|
|
|
# CLASS: Read |
|
69
|
|
|
|
|
|
|
# METHOD: insert_sequencing_error |
|
70
|
|
|
|
|
|
|
# PARAMETERS: $seq_ref Ref Str |
|
71
|
|
|
|
|
|
|
# RETURNS: Void |
|
72
|
|
|
|
|
|
|
# DESCRIPTION: Insert sequencing error in place |
|
73
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
74
|
|
|
|
|
|
|
# COMMENTS: none |
|
75
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
76
|
|
|
|
|
|
|
#=============================================================================== |
|
77
|
|
|
|
|
|
|
sub insert_sequencing_error { |
|
78
|
3786
|
|
|
3786
|
0
|
8048
|
my ($self, $seq_ref) = @_; |
|
79
|
3786
|
|
|
|
|
108965
|
my $err = int($self->_count_base * $self->sequencing_error); |
|
80
|
|
|
|
|
|
|
|
|
81
|
3786
|
|
|
|
|
10584
|
for (my $i = 0; $i < $err; $i++) { |
|
82
|
3646
|
|
|
|
|
100586
|
$self->update_count_base(-$self->_base); |
|
83
|
3646
|
|
|
|
|
101774
|
my $pos = $self->read_size - $self->_count_base - 1; |
|
84
|
3646
|
|
|
|
|
8256
|
my $b = substr($$seq_ref, $pos, 1); |
|
85
|
3646
|
|
|
|
|
7986
|
substr($$seq_ref, $pos, 1) = $self->_randb($b); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} ## --- end sub insert_sequencing_error |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
90
|
|
|
|
|
|
|
# CLASS: Read |
|
91
|
|
|
|
|
|
|
# METHOD: update_count_base |
|
92
|
|
|
|
|
|
|
# PARAMETERS: $val Int |
|
93
|
|
|
|
|
|
|
# RETURNS: Void |
|
94
|
|
|
|
|
|
|
# DESCRIPTION: Increment or decrement _count_base which controls when insert an |
|
95
|
|
|
|
|
|
|
# error and how many: int($self->_count_base * $self->sequencing_error); |
|
96
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
97
|
|
|
|
|
|
|
# COMMENTS: none |
|
98
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
99
|
|
|
|
|
|
|
#=============================================================================== |
|
100
|
|
|
|
|
|
|
sub update_count_base { |
|
101
|
7432
|
|
|
7432
|
0
|
13763
|
my ($self, $val) = @_; |
|
102
|
7432
|
|
|
|
|
206904
|
$self->_count_base($self->_count_base + $val); |
|
103
|
|
|
|
|
|
|
} ## --- end sub update_count_base |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
106
|
|
|
|
|
|
|
# CLASS: Read |
|
107
|
|
|
|
|
|
|
# METHOD: reverse_complement |
|
108
|
|
|
|
|
|
|
# PARAMETERS: $seq_ref Ref Str |
|
109
|
|
|
|
|
|
|
# RETURNS: Void |
|
110
|
|
|
|
|
|
|
# DESCRIPTION: Compute the reverse complement sequence in place |
|
111
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
112
|
|
|
|
|
|
|
# COMMENTS: none |
|
113
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
114
|
|
|
|
|
|
|
#=============================================================================== |
|
115
|
|
|
|
|
|
|
sub reverse_complement { |
|
116
|
1860
|
|
|
1860
|
0
|
79529
|
my ($self, $seq_ref) = @_; |
|
117
|
1860
|
|
|
|
|
4348
|
$$seq_ref = reverse $$seq_ref; |
|
118
|
1860
|
|
|
|
|
4592
|
$$seq_ref =~ tr/atcgATCG/tagcTAGC/; |
|
119
|
|
|
|
|
|
|
} ## --- end sub reverse_complement |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#=== CLASS METHOD ============================================================ |
|
122
|
|
|
|
|
|
|
# CLASS: Read |
|
123
|
|
|
|
|
|
|
# METHOD: _randb (PRIVATE) |
|
124
|
|
|
|
|
|
|
# PARAMETERS: $not_b Char |
|
125
|
|
|
|
|
|
|
# RETURNS: $b Char |
|
126
|
|
|
|
|
|
|
# DESCRIPTION: Raffle a ramdom base, but $not_b |
|
127
|
|
|
|
|
|
|
# THROWS: no exceptions |
|
128
|
|
|
|
|
|
|
# COMMENTS: none |
|
129
|
|
|
|
|
|
|
# SEE ALSO: n/a |
|
130
|
|
|
|
|
|
|
#=============================================================================== |
|
131
|
|
|
|
|
|
|
sub _randb { |
|
132
|
3646
|
|
|
3646
|
|
8554
|
my ($self, $not_b) = ($_[0], uc $_[1]); |
|
133
|
3646
|
|
|
|
|
5306
|
my $b; |
|
134
|
3646
|
|
|
|
|
5022
|
do { $b = qw{A T C G}[int(rand(4))] } until ($b ne $not_b); |
|
|
4995
|
|
|
|
|
15543
|
|
|
135
|
3646
|
|
|
|
|
16971
|
return $b; |
|
136
|
|
|
|
|
|
|
} ## --- end sub _randb |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=pod |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=encoding UTF-8 |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 NAME |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
App::SimulateReads::Read - Base class to simulate reads |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 VERSION |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
version 0.05 |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 AUTHOR |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Teaching and Research Institute from SÃrio-Libanês Hospital. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
This is free software, licensed under: |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |