lib/App/Sandy/Seq/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/Seq.pm ↑ Summary lib/App/Sandy/Seq/SingleEnd.pm »
1 package App::Sandy::Seq::PairedEnd;
2 # ABSTRACT: App::Sandy::Seq subclass for simulate paired-end entries.
3  
4 1 ▶use App::Sandy::Base 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use App::Sandy::Read::PairedEnd;
6  
7 extends 'App::Sandy::Seq';
8  
9 our $VERSION = '0.25'; # VERSION
10  
11 has 'fragment_mean' => (
12 is => 'ro',
13 isa => 'My:IntGt0',
14 required => 1
15 );
16  
17 has 'fragment_stdd' => (
18 is => 'ro',
19 isa => 'My:IntGe0',
20 required => 1
21 );
22  
23 has '_read' => (
24 is => 'ro',
25 isa => 'App::Sandy::Read::PairedEnd',
26 builder => '_build_read',
27 lazy_build => 1,
28 handles => ['gen_read']
29 );
30  
31 sub BUILD {
32 my $self = shift;
33 ## Just to ensure that the lazy attributes are built before &new returns
34 $self->_read;
35 }
36  
37 sub _build_read {
38 my $self = shift;
39 App::Sandy::Read::PairedEnd->new(
40 sequencing_error => $self->sequencing_error,
41 fragment_mean => $self->fragment_mean,
42 fragment_stdd => $self->fragment_stdd
43 );
44 }
45  
46 override '_build_sym_table' => sub {
47 my $self = shift;
48 my $sym_table = super();
49  
50 my %sym_table_paired_end = (
51 '%M' => '$info->{fragment_mean}',
52 '%D' => '$info->{fragment_stdd}',
53 '%f' => '$info->{fragment_size}',
54 '%S' => '$info->{fragment_start}',
55 '%E' => '$info->{fragment_end}',
56 '%X' => '$info->{fragment_start_ref}',
57 '%Z' => '$info->{fragment_end_ref}',
58 '%F' => '$info->{fragment_strand}',
59 '%A' => '$info->{mate_start_ref}',
60 '%B' => '$info->{mate_end_ref}',
61 '%T' => '$info->{mate_start}',
62 '%N' => '$info->{mate_end}',
63 '%L' => '$info->{tlen}',
64 );
65  
66 @$sym_table{keys %sym_table_paired_end} = values %sym_table_paired_end;
67 return $sym_table;
68 };
69  
70 override '_build_info' => sub {
71 my $self = shift;
72 my $info = super();
73  
74 my %info_paired_end = (
75 fragment_mean => $self->fragment_mean,
76 fragment_stdd => $self->fragment_stdd
77 );
78  
79 @$info{keys %info_paired_end} = values %info_paired_end;
80 return $info;
81 };
82  
83 sub sprint_seq {
84 my ($self, $id, $num, $seq_id, $seq_id_type, $ptable, $ptable_size, $is_leader, $rng, $blacklist) = @_;
85  
86 my $read_size = $self->_get_read_size($rng);
87  
88 # In order to work third gen sequencing
89 # simulator, it is necessary to truncate
90 # the read according to the ptable size
91 if ($read_size > $ptable_size) {
92 $read_size = $ptable_size;
93 }
94  
95 my ($read1_ref, $read2_ref, $attr) = $self->gen_read($ptable, $ptable_size,
96 $read_size, $is_leader, $rng, $blacklist);
97  
98 my $annot_a = $attr->{annot};
99  
100 $self->_set_info(
101 'id' => $id,
102 'num' => $num,
103 'seq_id' => $seq_id,
104 'seq_id_type' => $seq_id_type,
105 'read_size' => $read_size,
106 'fragment_start' => $attr->{start},
107 'fragment_end' => $attr->{end},
108 'fragment_start_ref' => $attr->{start_ref},
109 'fragment_end_ref' => $attr->{end_ref},
110 'fragment_size' => $attr->{end} - $attr->{start} + 1,
111 'fragment_strand' => $is_leader ? 'P' : 'M',
112 'var' => @$annot_a ? join ',' => @$annot_a : 'none'
113 );
114  
115 return $is_leader
116 ? ($self->_sprint_seq($read1_ref, $read_size, 1, $attr, 1, $rng), $self->_sprint_seq($read2_ref, $read_size, 2, $attr, 0, $rng))
117 : ($self->_sprint_seq($read2_ref, $read_size, 1, $attr, 0, $rng), $self->_sprint_seq($read1_ref, $read_size, 2, $attr, 1, $rng));
118 }
119  
120 sub _sprint_seq {
121 my ($self, $read_ref, $read_size, $read_num, $attr, $is_leader, $rng) = @_;
122  
123 if ($is_leader) {
124 my $error_a = $attr->{error1};
125 my $tlen = $attr->{end2} - $attr->{end1};
126  
127 $self->_set_info(
128 'start' => $attr->{start1},
129 'end' => $attr->{end1},
130 'start_ref' => $attr->{start_ref},
131 'end_ref' => $attr->{read_end_ref},
132 'mate_start' => $attr->{start2},
133 'mate_end' => $attr->{end2},
134 'mate_start_ref' => $attr->{end_ref},
135 'mate_end_ref' => $attr->{read_start_ref},
136 'read' => $read_num,
137 'strand' => 'P',
138 'tlen' => $tlen > 0 ? $tlen : 0,
139 'error' => @$error_a ? join ',' => @$error_a : 'none'
140 );
141 } else {
142 my $error_a = $attr->{error2};
143 my $tlen = $attr->{end1} - $attr->{end2};
144  
145 $self->_set_info(
146 'start' => $attr->{start2},
147 'end' => $attr->{end2},
148 'start_ref' => $attr->{end_ref},
149 'end_ref' => $attr->{read_start_ref},
150 'mate_start' => $attr->{start1},
151 'mate_end' => $attr->{end1},
152 'mate_start_ref' => $attr->{start_ref},
153 'mate_end_ref' => $attr->{read_end_ref},
154 'read' => $read_num,
155 'strand' => 'M',
156 'tlen' => $tlen < 0 ? $tlen : 0,
157 'error' => @$error_a ? join ',' => @$error_a : 'none'
158 );
159 }
160  
161 my $seqid = $self->_gen_id($self->_info);
162 my $quality_ref = $self->gen_quality($read_size, $rng);
163  
164 return $self->_gen_seq(\$seqid, $read_ref, $quality_ref, $read_num, $read_size);
165 }
166  
167 __END__
« lib/App/Sandy/Seq.pm ↑ Summary lib/App/Sandy/Seq/SingleEnd.pm »