sub
new {
my
(
$thing
,
%args
) =
@_
;
my
$class
=
ref
(
$thing
) ||
$thing
;
my
(
$obj
,
%translation
);
my
$transcript
=
$args
{-transcript};
$obj
= \
%translation
;
$obj
=
bless
$obj
,
$class
;
unless
(
$transcript
) {
$obj
->throw(
"$class not initialised because no -transcript given"
);
}
unless
(
ref
(
$transcript
) eq
"Bio::LiveSeq::Transcript"
) {
$obj
->throw(
"$class not initialised because no object of class Transcript given"
);
}
my
$strand
=
$transcript
->strand;
my
$seq
=
$transcript
->{
'seq'
};
$obj
->{
'strand'
}=
$strand
;
$obj
->{
'seq'
}=
$seq
;
$obj
->{
'transcript'
}=
$transcript
;
$obj
->{
'alphabet'
}=
"protein"
;
$transcript
->{
'translation'
}=
$obj
;
return
$obj
;
}
sub
get_Transcript {
my
$self
=
shift
;
return
(
$self
->{
'transcript'
});
}
sub
change {
my
(
$self
)=
@_
;
$self
->
warn
(
"Cannot change a Translation object!\nChanges have to be issued at the nucleotide level!"
);
return
(-1);
}
sub
positionchange {
my
(
$self
)=
@_
;
$self
->
warn
(
"Cannot change a Translation object!\nChanges have to be issued at the nucleotide level!"
);
return
(-1);
}
sub
labelchange {
my
(
$self
)=
@_
;
$self
->
warn
(
"Cannot change a Translation object!\nChanges have to be issued at the nucleotide level!"
);
return
(-1);
}
sub
transl_seq {
my
$self
=
shift
;
my
$transcript
=
$self
->get_Transcript;
my
$translation
=
$transcript
->translate(
undef
,
undef
,
undef
,
$self
->translation_table)->seq;
return
$translation
;
}
sub
seq {
my
$self
=
shift
;
my
$proteinseq
;
my
$transcript
=
$self
->get_Transcript;
my
$translation
=
$transcript
->translate(
undef
,
undef
,
undef
,
$self
->translation_table)->seq;
my
$stop_pos
=
index
(
$translation
,
"*"
);
if
(
$stop_pos
== -1) {
my
$downstreamseq
=
$transcript
->downstream_seq();
my
$cdnaseq
=
$transcript
->seq();
my
$extendedseq
= new Bio::PrimarySeq(
-seq
=>
"$cdnaseq$downstreamseq"
,
-alphabet
=>
'dna'
);
$translation
=
$extendedseq
->translate(
undef
,
undef
,
undef
,
$self
->translation_table)->seq;
$stop_pos
=
index
(
$translation
,
"*"
);
if
(
$stop_pos
== -1) {
$self
->
warn
(
"Warning: no stop codon found in the retrieved sequence downstream of Transcript "
,1);
undef
$stop_pos
;
$proteinseq
=
$translation
;
}
else
{
$proteinseq
=
substr
(
$translation
,0,
$stop_pos
+1);
}
}
else
{
$proteinseq
=
substr
(
$translation
,0,
$stop_pos
+1);
}
return
$proteinseq
;
}
sub
length
{
my
$self
=
shift
;
my
$seq
=
$self
->seq;
my
$length
=
length
(
$seq
);
return
$length
;
}
sub
all_labels {
my
$self
=
shift
;
return
$self
->get_Transcript->all_labels;
}
sub
valid {
my
(
$self
,
$label
)=
@_
;
my
$i
;
my
@labels
=
$self
->get_Transcript->all_labels;
my
$length
=
$#labels
;
while
(
$i
<=
$length
) {
if
(
$label
==
$labels
[
$i
]) {
return
(1);
}
$i
=
$i
+3;
}
return
(0);
}
sub
label {
my
(
$self
,
$position
)=
@_
;
my
$firstlabel
=
$self
->coordinate_start;
if
(
$position
> 0) {
$position
=
$position
*3-2;
}
else
{
$position
=
$position
*3;
}
return
$self
->get_Transcript->label(
$position
,
$firstlabel
);
}
sub
position {
my
(
$self
,
$label
)=
@_
;
my
$firstlabel
=
$self
->coordinate_start;
my
$position
=
$self
->get_Transcript->position(
$label
,
$firstlabel
);
my
$modulus
=
$position
% 3;
if
(
$position
== 0) {
return
(0);
}
elsif
(
$position
> 0) {
if
(
$modulus
!= 1) {
$self
->
warn
(
"Attention! Label $label is not in frame "
.
"(1st position of triplet) with protein"
,1)
if
$self
->verbose > 0;
if
(
$modulus
== 2) {
return
(
$position
/ 3 + 1);
}
else
{
return
(
$position
/ 3);
}
}
return
(
$position
/ 3 + 1);
}
else
{
if
(
$modulus
!= 0) {
$self
->
warn
(
"Attention! Label $label is not in frame "
.
"(1st position of triplet) with protein"
,1)
if
$self
->verbose > 0;
return
(
$position
/ 3 - 1);
}
return
(
$position
/ 3);
}
$self
->throw(
"WEIRD: execution shouldn't have reached here"
);
return
(0);
}
sub
start {
my
$self
=
shift
;
return
(
$self
->{
'transcript'
}->start);
}
sub
end {
my
$self
=
shift
;
return
(
$self
->{
'transcript'
}->end);
}
sub
aa_ranges {
my
$self
=
shift
;
return
(
$self
->{
'aa_ranges'
});
}
sub
translation_table {
my
$self
=
shift
;
$self
->get_Transcript->translation_table(
@_
);
}
sub
labelsubseq {
my
(
$self
,
$start
,
$length
,
$end
)=
@_
;
my
(
$pos1
,
$pos2
);
my
$transcript
=
$self
->get_Transcript;
if
(
$start
) {
unless
(
$transcript
->valid(
$start
)) {
$self
->
warn
(
"Start label not valid"
);
return
(-1);
}
$pos1
=
$self
->position(
$start
);
}
if
(
$end
) {
if
(
$end
==
$start
) {
$length
=1;
}
else
{
unless
(
$transcript
->valid(
$end
)) {
$self
->
warn
(
"End label not valid"
);
return
(-1);
}
unless
(
$transcript
->follows(
$start
,
$end
) == 1) {
$self
->
warn
(
"End label does not follow Start label!"
);
return
(-1);
}
$pos2
=
$self
->position(
$end
);
$length
=
$pos2
-
$pos1
+1;
}
}
my
$sequence
=
$self
->seq;
return
(
substr
(
$sequence
,
$pos1
-1,
$length
));
}
sub
offset {
my
$self
=
shift
;
return
(
$self
->{
'offset'
});
}
1;