line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Sandy::Role::Template::Sam; |
2
|
|
|
|
|
|
|
# ABSTRACT: Sam template role |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
3585
|
use App::Sandy::Base 'role'; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use constant { |
7
|
6
|
|
|
|
|
2502
|
PAIRED => 0x1, |
8
|
|
|
|
|
|
|
PROPER_PAIR => 0x2, |
9
|
|
|
|
|
|
|
UNMAP => 0x4, |
10
|
|
|
|
|
|
|
MUNMAP => 0x8, |
11
|
|
|
|
|
|
|
REVERSE => 0x10, |
12
|
|
|
|
|
|
|
MREVERSE => 0x20, |
13
|
|
|
|
|
|
|
READ1 => 0x40, |
14
|
|
|
|
|
|
|
READ2 => 0x80, |
15
|
|
|
|
|
|
|
SECONDARY => 0x100, |
16
|
|
|
|
|
|
|
QCFAIL => 0x200, |
17
|
|
|
|
|
|
|
DUP => 0x400, |
18
|
|
|
|
|
|
|
SUPPLEMENTARY => 0x800, |
19
|
|
|
|
|
|
|
SAM_VERSION => '1.0' |
20
|
6
|
|
|
6
|
|
47
|
}; |
|
6
|
|
|
|
|
12
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.22'; # VERSION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has '_flags' => ( |
25
|
|
|
|
|
|
|
traits => ['Array'], |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'ArrayRef', |
28
|
|
|
|
|
|
|
builder => '_build_flags', |
29
|
|
|
|
|
|
|
lazy_build => 1, |
30
|
|
|
|
|
|
|
handles => { |
31
|
|
|
|
|
|
|
_get_flag => 'get' |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_flags { |
36
|
0
|
|
|
0
|
|
|
my $single_end = UNMAP; |
37
|
0
|
|
|
|
|
|
my $read1 = PAIRED|UNMAP|MUNMAP|READ1; |
38
|
0
|
|
|
|
|
|
my $read2 = PAIRED|UNMAP|MUNMAP|READ2; |
39
|
0
|
|
|
|
|
|
return [$single_end, $read1, $read2]; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub with_eof_marker { |
43
|
0
|
|
|
0
|
0
|
|
my $eof = pack("C28", |
44
|
|
|
|
|
|
|
0x1f, 0x8b, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, |
45
|
|
|
|
|
|
|
0x00, 0xff, 0x06, 0x00, 0x42, 0x43, 0x02, 0x00, |
46
|
|
|
|
|
|
|
0x1b, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, |
47
|
|
|
|
|
|
|
0x00, 0x00, 0x00, 0x00 |
48
|
|
|
|
|
|
|
); |
49
|
0
|
|
|
|
|
|
return \$eof; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub with_sam_header_template { |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $argv) = @_; |
54
|
0
|
|
|
|
|
|
my $cl = "sandy @$argv"; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
## no critic |
57
|
6
|
0
|
|
6
|
|
58
|
my $vn = do { no strict 'vars'; $VERSION || "dev" }; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
2725
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
## use critic |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $header = sprintf "\@HD\tVN:%s\tSO:queryname\n\@PG\tID:%s\tPN:%s\tVN:%s\tCL:%s\n" |
61
|
|
|
|
|
|
|
=> SAM_VERSION, 'sandy', 'sandy', $vn, $cl; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return \$header; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub with_sam_align_template { |
67
|
0
|
|
|
0
|
0
|
|
my ($self, $seqid_ref, $read_ref, $quality_ref, $read_flag) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $sam = sprintf "%s\t%d\t*\t0\t0\t*\t*\t0\t0\t%s\t%s\n" |
70
|
|
|
|
|
|
|
=> $$seqid_ref, $self->_get_flag($read_flag), $$read_ref, $$quality_ref; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return \$sam; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub with_bam_header_template { |
76
|
0
|
|
|
0
|
0
|
|
my ($self, $argv) = @_; |
77
|
0
|
|
|
|
|
|
my $header_ref = $self->with_sam_header_template($argv); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $l_text = length($$header_ref); |
80
|
0
|
|
|
|
|
|
my $block = pack("c4l<", 66, 65, 77, 1, $l_text) . $$header_ref . pack("l<", 0); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return \$block; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub with_bam_align_template { |
86
|
0
|
|
|
0
|
0
|
|
my ($self, $seqid_ref, $read_ref, $quality_ref, $read_flag, $read_size) = @_; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Catch the seqid size nul padded |
89
|
0
|
|
|
|
|
|
my $seqid_size = length($$seqid_ref) + 1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Encode all bases in 4 bits 0-15 (hex 0x0-0xf) and |
92
|
|
|
|
|
|
|
# pack the codes to high level nibbles |
93
|
0
|
|
|
|
|
|
my $packed_read = pack("H*", |
94
|
|
|
|
|
|
|
$$read_ref =~ tr [=ACMGRSVTWYHKDBNacmgrsvtwyhkdbn\x00-\xff] [\x00-\x0f\x01-\x0f]r); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# quality to ascii and calculate the phred score [!-~] |
97
|
0
|
|
|
|
|
|
my $packed_quality = $$quality_ref =~ tr [\x21-\x7e\x00-\xff] [\x00-\x5d\x00]r; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Calculate the total block size in bytes |
100
|
0
|
|
|
|
|
|
my $block_size = $seqid_size + $read_size + int(($read_size + 1) / 2) + 32; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Lets set this align block |
103
|
0
|
|
|
|
|
|
my $block = pack("l<3C2S<3l<4", |
104
|
|
|
|
|
|
|
$block_size, |
105
|
|
|
|
|
|
|
-1, |
106
|
|
|
|
|
|
|
-1, |
107
|
|
|
|
|
|
|
$seqid_size, |
108
|
|
|
|
|
|
|
0, |
109
|
|
|
|
|
|
|
4680, |
110
|
|
|
|
|
|
|
0, |
111
|
|
|
|
|
|
|
$self->_get_flag($read_flag), |
112
|
|
|
|
|
|
|
$read_size, |
113
|
|
|
|
|
|
|
-1, |
114
|
|
|
|
|
|
|
-1, |
115
|
|
|
|
|
|
|
0 |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Cat the seqid, read and quality packs to block |
119
|
0
|
|
|
|
|
|
$block .= $$seqid_ref . pack("x") . $packed_read . $packed_quality; |
120
|
0
|
|
|
|
|
|
return \$block; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=pod |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=encoding UTF-8 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NAME |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
App::Sandy::Role::Template::Sam - Sam template role |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 VERSION |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
version 0.22 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHORS |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
J. Leonel Buzzo <lbuzzo@mochsl.org.br> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Felipe R. C. dos Santos <fsantos@mochsl.org.br> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Helena B. Conceição <hconceicao@mochsl.org.br> |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Gabriela Guardia <gguardia@mochsl.org.br> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Fernanda Orpinelli <forpinelli@mochsl.org.br> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Pedro A. F. Galante <pgalante@mochsl.org.br> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This software is Copyright (c) 2018 by Teaching and Research Institute from SÃrio-Libanês Hospital. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This is free software, licensed under: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |