lib/App/Sandy/Read/PairedEnd.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
« lib/App/Sandy/Read.pm ↑ Summary lib/App/Sandy/Read/SingleEnd.pm »
1 package App::Sandy::Read::PairedEnd;
2 # ABSTRACT: App::Sandy::Read subclass for simulate paired-end reads.
3  
4 1 ▶use App::Sandy::Base 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 use constant NUM_TRIES => 1000;
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 my ($self, $ptable, $ptable_size, $read_size, $is_leader, $rng, $blacklist) = @_;
26  
27 unless ($read_size <= $self->fragment_mean && $self->fragment_mean <= $ptable_size) {
28 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 my $fragment_size = 0;
35 my $random_tries = 0;
36  
37 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 if (++$random_tries > NUM_TRIES) {
42 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 $fragment_size = $rng->get_norm($self->fragment_mean, $self->fragment_stdd);
49 }
50  
51 # Build the fragment string
52 my ($fragment_ref, $attr) = $self->subseq_rand_ptable($ptable,
53 $ptable_size, $fragment_size, $read_size, $rng, $blacklist);
54  
55 # Catch R1 substring
56 my $read1_ref = $self->subseq($fragment_ref, $fragment_size, $read_size, 0);
57 @$attr{qw/start1 end1/} = ($attr->{start}, $attr->{start} + $read_size - 1);
58  
59 # Insert sequencing error
60 $attr->{error1} = $self->insert_sequencing_error($read1_ref, $read_size, $rng);
61  
62 # Catch R2 substring
63 my $read2_ref = $self->subseq($fragment_ref, $fragment_size, $read_size,
64 $fragment_size - $read_size);
65 @$attr{qw/start2 end2/} = ($attr->{end}, $attr->{end} - $read_size + 1);
66  
67 # Reverse completement
68 $self->reverse_complement($read2_ref);
69  
70 # Insert sequencing error
71 $attr->{error2} = $self->insert_sequencing_error($read2_ref, $read_size, $rng);
72  
73 return ($read1_ref, $read2_ref, $attr);
74 }
75  
76 __END__
« lib/App/Sandy/Read.pm ↑ Summary lib/App/Sandy/Read/SingleEnd.pm »