sub add_TranslationObject
{ my ($cds_id,$nw_transcript,$cds_start,$cds_end,$cds_strand) = @_;
my $seq_start = -1;
my $seq_end = -1 ;
my ($first_coding_exon, $last_coding_exon);
for my $ex (@{$nw_transcript->get_all_Exons()}) {
if ($nw_transcript->strand == 1) {
if ($ex->start <= $cds_start && $cds_start <= $ex->end) {
$seq_start = convert_to_exon_coords($cds_start, $ex->start,$ex->end,$ex->strand );
$first_coding_exon = $ex;
$first_coding_exon->phase("0");
print "set first coding exon ".$ex->stable_id." 1\n";
}
if ($ex->start <= $cds_end && $cds_end <= $ex->end) {
$seq_end = convert_to_exon_coords($cds_end, $ex->start,$ex->end,$ex->strand ) + 3 ;
$last_coding_exon = $ex;
print "set last coding exon ".$ex->stable_id." 1\n";
}
}
elsif ($nw_transcript->strand == -1) {
if ( ($ex->start <= $cds_end) && ($cds_end <= $ex->end)) {
$first_coding_exon = $ex;
$seq_start = ($ex->end - $cds_end) + 1 ;
print "set first coding exon ".$ex->stable_id." -1\n";
}
if ( ($ex->start <= $cds_start) && ($cds_start <= $ex->end)) {
$last_coding_exon = $ex;
$seq_end = ($last_coding_exon->end - $cds_start)+ 1 + 3 ;
print "set last coding exon ".$ex->stable_id." -1\n";
}
} else {
throw("strand of transcript is not '1' or '-1'.");
}
}
my $tl = Bio::EnsEMBL::Translation->new(
-START_EXON => $first_coding_exon,
-END_EXON => $last_coding_exon,
-SEQ_START => $seq_start,
-SEQ_END => $seq_end,
-STABLE_ID => $cds_id,
-VERSION => "3",
);
$nw_transcript->translation($tl);
print "first ".$first_coding_exon->stable_id."\n ";
print "last ".$last_coding_exon->stable_id."\n ";
throw("There is a CDS-Start or CDS-End, but I can't find an exon which spans these points\n") unless ($first_coding_exon && $last_coding_exon );
if ($first_coding_exon eq $last_coding_exon) {
my $tl_end = $nw_transcript->translation->end;
if ($first_coding_exon->length - $tl_end > 0) {
$first_coding_exon->end_phase("-1");
} else {
my $endphase = ($first_coding_exon->length - $seq_start) % 3 ;
$first_coding_exon->end_phase($endphase);
}
}
throw("There seems to be no cds-region-start in CDS-ID $cds_id\n") if ($seq_start eq "-1");
throw("There seems to be no cds-region-end in CDS-ID $cds_id\n") if ($seq_end eq "-1") ;
return $nw_transcript; } |
sub convert_to_exon_coords
{ my ( $cds_coord, $exon_start, $exon_end, $exon_strand ) = @_;
my $cds_coord_converted = "-1";
warn_inconsistency("Exon-start-coord >= exon_end_coord: $exon_start\t$exon_end\n") if ($exon_start >= $exon_end);
if ($cds_coord >= $exon_start) {
if ($cds_coord <= $exon_end) {
if ($exon_strand eq "+1") {
$cds_coord_converted = $cds_coord - $exon_start +1 ;
} elsif ( $exon_strand eq "-1") {
$cds_coord_converted = $cds_coord - $exon_start +1 ;
} else {
warn_inconsistency("Exon is on unknown strand, coords: $exon_start:$exon_end:$exon_strand\n");
$cds_coord_converted =-1;
}
}
}
throw ("coord-error\n") if ($cds_coord_converted eq "0");
return $cds_coord_converted; } |
sub setExonPhases
{ my ( $self,$transcript) = @_;
my $fce = $transcript->translation->start_Exon;
my $lce = $transcript->translation->end_Exon;
my @all_exons = @{$transcript->get_all_Exons};
my $end_phase;
for my $exon (@all_exons) {
if ($exon->strand == 1 ) {
if ($exon->start < $fce->start && $exon->end < $fce->end) {
$exon->phase("-1");
$exon->end_phase("-1");
}
if ($exon->start >= $fce->start && $exon->end <=$lce->end) {
if ($exon eq $fce) {
$exon->phase( 0 ) ;
$end_phase = ($exon->length - $transcript->translation->start + 1 )%3;
$exon->end_phase($end_phase);
}
if ( $exon ne $fce && $exon ne $lce) {
$exon->phase($end_phase);
$end_phase =( $exon->phase + $exon->length ) % 3;
$exon->end_phase($end_phase);
}
if ($exon eq $lce) {
if ($exon ne $fce) {
$exon->phase($end_phase);
}
if ( ($exon->length - $transcript->translation->end ) == 0) {
$exon->end_phase( ($end_phase + $exon->length) % 3);
} else {
$exon->end_phase("-1");
}
}
}
if ($exon->start > $lce->end) {
$exon->end_phase("-1");
$exon->phase("-1");
}
} else {
if ($exon eq $fce) {
$exon->phase( 0 ) ;
$end_phase = ($exon->length - ($transcript->translation->start -1) ) % 3;
$exon->end_phase($end_phase);
}
if ($exon ne $fce && $exon ne $lce) {
$exon->phase($end_phase);
$end_phase = ($exon->phase + $exon->length) % 3;
$exon->end_phase($end_phase);
}
if ($exon eq $lce) {
if ($exon ne $fce) {
$exon->phase($end_phase);
}
if ( ($exon->length - $transcript->translation->end ) == 0) {
$exon->end_phase( ($end_phase + $exon->length) % 3);
} else {
$exon->end_phase("-1");
}
}
if ($exon->start > $fce->start) {
$exon->phase("-1");
$exon->end_phase("-1");
}
if ($exon->start < $lce->start) {
$exon->phase("-1");
$exon->end_phase("-1");
}
} }
return $transcript;
}
} |