File Coverage

lib/App/Sandy/Read/PairedEnd.pm
Criterion Covered Total %
statement 22 24 91.6
branch 2 4 50.0
condition 3 6 50.0
subroutine 3 3 100.0
pod 0 1 0.0
total 30 38 78.9


line stmt bran cond sub pod time code
1             package App::Sandy::Read::PairedEnd;
2             # ABSTRACT: App::Sandy::Read subclass for simulate paired-end reads.
3              
4 6     6   2860 use App::Sandy::Base 'class';
  6         19  
  6         99  
5              
6 6     6   65 use constant NUM_TRIES => 1000;
  6         18  
  6         3636  
7              
8             extends 'App::Sandy::Read';
9              
10             our $VERSION = '0.25'; # VERSION
11              
12             has 'fragment_mean' => (
13             is => 'ro',
14             isa => 'My:IntGt0',
15             required => 1
16             );
17              
18             has 'fragment_stdd' => (
19             is => 'ro',
20             isa => 'My:IntGe0',
21             required => 1
22             );
23              
24             sub gen_read {
25 2832     2832 0 25784 my ($self, $ptable, $ptable_size, $read_size, $is_leader, $rng, $blacklist) = @_;
26              
27 2832 50 33     79658 unless ($read_size <= $self->fragment_mean && $self->fragment_mean <= $ptable_size) {
28 0         0 croak sprintf
29             "read_size (%d) must be leseer or equal to fragment_mean (%d) and\n" .
30             "fragment_mean (%d) must be lesser or equal to ptable_size (%d)"
31             => $read_size, $self->fragment_mean, $self->fragment_mean, $ptable_size;
32             }
33              
34 2832         4893 my $fragment_size = 0;
35 2832         4033 my $random_tries = 0;
36              
37 2832   66     9889 until (($fragment_size <= $ptable_size) && ($fragment_size >= $read_size)) {
38             # ptable_size must be greater or equal to fragment_size and
39             # fragment_size must be greater or equal to read_size
40             # As fragment_size is randomly calculated, try out NUM_TRIES times
41 2832 50       5635 if (++$random_tries > NUM_TRIES) {
42 0         0 croak sprintf
43             "So many tries to calculate a fragment. the constraints were not met:\n" .
44             "fragment_size <= ptable_size (%d) and fragment_size >= read_size (%d)"
45             => $ptable_size, $read_size;
46             }
47              
48 2832         75638 $fragment_size = $rng->get_norm($self->fragment_mean, $self->fragment_stdd);
49             }
50              
51             # Build the fragment string
52 2832         10743 my ($fragment_ref, $attr) = $self->subseq_rand_ptable($ptable,
53             $ptable_size, $fragment_size, $read_size, $rng, $blacklist);
54              
55             # Catch R1 substring
56 2832         7465 my $read1_ref = $self->subseq($fragment_ref, $fragment_size, $read_size, 0);
57 2832         11641 @$attr{qw/start1 end1/} = ($attr->{start}, $attr->{start} + $read_size - 1);
58              
59             # Insert sequencing error
60 2832         7030 $attr->{error1} = $self->insert_sequencing_error($read1_ref, $read_size, $rng);
61              
62             # Catch R2 substring
63 2832         8606 my $read2_ref = $self->subseq($fragment_ref, $fragment_size, $read_size,
64             $fragment_size - $read_size);
65 2832         8186 @$attr{qw/start2 end2/} = ($attr->{end}, $attr->{end} - $read_size + 1);
66              
67             # Reverse completement
68 2832         8232 $self->reverse_complement($read2_ref);
69              
70             # Insert sequencing error
71 2832         6770 $attr->{error2} = $self->insert_sequencing_error($read2_ref, $read_size, $rng);
72              
73 2832         12579 return ($read1_ref, $read2_ref, $attr);
74             }
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             App::Sandy::Read::PairedEnd - App::Sandy::Read subclass for simulate paired-end reads.
85              
86             =head1 VERSION
87              
88             version 0.25
89              
90             =head1 AUTHORS
91              
92             =over 4
93              
94             =item *
95              
96             Thiago L. A. Miller <tmiller@mochsl.org.br>
97              
98             =item *
99              
100             J. Leonel Buzzo <lbuzzo@mochsl.org.br>
101              
102             =item *
103              
104             Felipe R. C. dos Santos <fsantos@mochsl.org.br>
105              
106             =item *
107              
108             Helena B. Conceição <hconceicao@mochsl.org.br>
109              
110             =item *
111              
112             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
113              
114             =item *
115              
116             Gabriela Guardia <gguardia@mochsl.org.br>
117              
118             =item *
119              
120             Fernanda Orpinelli <forpinelli@mochsl.org.br>
121              
122             =item *
123              
124             Rafael Mercuri <rmercuri@mochsl.org.br>
125              
126             =item *
127              
128             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
129              
130             =item *
131              
132             Pedro A. F. Galante <pgalante@mochsl.org.br>
133              
134             =back
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is Copyright (c) 2023 by Teaching and Research Institute from Sírio-Libanês Hospital.
139              
140             This is free software, licensed under:
141              
142             The GNU General Public License, Version 3, June 2007
143              
144             =cut