my
$dumper
= new Dumpvalue();
sub
_initialize {
my
(
$self
,
@args
) =
@_
;
$self
->SUPER::_initialize(
@args
);
if
( !
defined
$self
->sequence_factory ) {
$self
->sequence_factory(new Bio::Seq::SeqFactory
(
-verbose
=>
$self
->verbose(),
-type
=>
'Bio::Seq::Quality'
));
}
}
sub
next_seq {
my
(
$self
,
@args
) =
@_
;
my
(
$entry
,
$done
,
$qual
,
$seq
);
my
(
$id
,
@lines
,
@bases
,
@qualities
,
@trace_indices
) = (
''
);
if
(!(
$entry
=
$self
->_readline)) {
return
; }
if
(
$entry
=~ /^BEGIN_SEQUENCE\s+(\S+)/) {
$id
= $1;
}
my
$in_comments
= 0;
my
$in_dna
= 0;
my
$base_number
= 0;
my
$comments
= {};
while
(
$entry
=
$self
->_readline) {
return
if
(!
$entry
);
chomp
(
$entry
);
if
(
$entry
=~ /^BEGIN_COMMENT/) {
$in_comments
= 1;
while
(
$in_comments
== 1) {
$entry
=
$self
->_readline();
chomp
(
$entry
);
if
(
$entry
) {
if
(
$entry
=~ /^END_COMMENT/) {
$in_comments
= 0;
}
else
{
my
(
$name
,
$content
) =
split
(/:/,
$entry
);
if
(
$content
) {
$content
=~ s/^\s//g; }
$comments
->{
$name
} =
$content
;
}
}
}
}
if
(
$entry
=~ /^BEGIN_CHROMAT:\s+(\S+)/) {
if
(!
$id
) {
$id
= $1;
}
$entry
=
$self
->_readline();
}
if
(
$entry
=~ /^BEGIN_DNA/) {
$entry
=~ /^BEGIN_DNA/;
$in_dna
= 1;
$entry
=
$self
->_readline();
}
if
(
$entry
=~ /^END_DNA/) {
$in_dna
= 0;
}
if
(
$entry
=~ /^END_SEQUENCE/) {
}
if
(!
$in_dna
) {
next
; }
$entry
=~ /(\S+)\s+(\S+)(?:\s+(\S+))?/;
push
@bases
,$1;
push
@qualities
,$2;
push
(
@trace_indices
,$3)
if
defined
$3;
push
(
@lines
,
$entry
);
}
my
$swq
=
$self
->sequence_factory->create
(
-seq
=>
join
(
''
,
@bases
),
-qual
=> \
@qualities
,
-trace
=> \
@trace_indices
,
-id
=>
$id
,
-primary_id
=>
$id
,
-display_id
=>
$id
,
);
if
(
$comments
) {
$swq
->{comments} =
$comments
; }
return
$swq
;
}
sub
write_seq {
my
(
$self
,
@args
) =
@_
;
my
@phredstack
;
my
(
$label
,
$arg
);
my
(
$swq
,
$swq2
,
$chromatfile
,
$abithumb
,
$phredversion
,
$callmethod
,
$qualitylevels
,
$time
,
$trace_min_index
,
$trace_max_index
,
$chem
,
$dye
) =
$self
->_rearrange([
qw(QUALITY
SEQWITHQUALITY
CHROMAT_FILE
ABI_THUMBPRINT
PHRED_VERSION
CALL_METHOD
QUALITY_LEVELS
TIME
TRACE_ARRAY_MIN_INDEX
TRACE_ARRAY_MAX_INDEX
CHEM
DYE
)
],
@args
);
$swq
=
$swq2
if
not
$swq
and
$swq2
;
unless
(
ref
(
$swq
) eq
"Bio::Seq::Quality"
) {
$self
->throw(
"You must pass a Bio::Seq::Quality object to write_scf as a parameter named \"Quality\""
);
}
my
$id
=
$swq
->id();
if
(!
$id
) {
$id
=
"UNDEFINED in Quality Object"
; }
push
@phredstack
,(
"BEGIN_SEQUENCE $id"
,
""
,
"BEGIN_COMMENT"
,
""
);
$chromatfile
=
'undefined in write_phd'
unless
defined
$chromatfile
;
push
@phredstack
,
"CHROMAT_FILE: $chromatfile"
;
$abithumb
= 0
unless
defined
$abithumb
;
push
@phredstack
,
"ABI_THUMBPRINT: $abithumb"
;
$phredversion
=
"0.980904.e"
unless
defined
$phredversion
;
push
@phredstack
,
"PHRED_VERSION: $phredversion"
;
$callmethod
=
'phred'
unless
defined
$callmethod
;
push
@phredstack
,
"CALL_METHOD: $callmethod"
;
$qualitylevels
= 99
unless
defined
$qualitylevels
;
push
@phredstack
,
"QUALITY_LEVELS: $qualitylevels"
;
$time
=
localtime
()
unless
defined
$time
;
push
@phredstack
,
"TIME: $time"
;
$trace_min_index
= 0
unless
defined
$trace_min_index
;
push
@phredstack
,
"TRACE_ARRAY_MIN_INDEX: $trace_min_index"
;
$trace_max_index
=
'10000'
unless
defined
$trace_max_index
;
push
@phredstack
,
"TRACE_ARRAY_MAX_INDEX: $trace_max_index"
;
$chem
=
'unknown'
unless
defined
$chem
;
push
@phredstack
,
"CHEM: $chem"
;
$dye
=
'unknown'
unless
defined
$dye
;
push
@phredstack
,
"DYE: $dye"
;
push
@phredstack
,(
"END_COMMENT"
,
""
,
"BEGIN_DNA"
);
foreach
(
@phredstack
) {
$self
->_print(
$_
.
"\n"
); }
my
$length
=
$swq
->
length
();
if
(
$length
eq
"DIFFERENT"
) {
$self
->throw(
"Can't create the phd because the sequence and the quality in the Quality object are of different lengths."
);
}
for
(
my
$curr
= 1;
$curr
<=
$length
;
$curr
++) {
$self
->_print (
uc
(
$swq
->baseat(
$curr
)).
" "
.
$swq
->qualat(
$curr
).
" 10"
.
"\n"
);
}
$self
->_print (
"END_DNA\n\nEND_SEQUENCE\n"
);
$self
->flush
if
$self
->_flush_on_write &&
defined
$self
->_fh;
return
1;
}
1;