sub AUTOLOAD
{ my $self = shift;
my $method = $AUTOLOAD;
$method =~ s/.*:://;
croak "invalid method: ->$method()" unless $ok_field{$method};
$self->{lc $method} = shift if(@_);
return $self->{lc $method}; } |
sub alignment_string
{ my ($self, $member) = @_;
unless (defined $self->cigar_line) {
throw("To get an alignment_string, the cigar_line needs to be define\n");
}
unless (defined $member) {
throw("To get an alignment_string, the peptide member needs to be passed as an option\n");
}
unless (defined $self->{'alignment_string'}) {
my $sequence = $member->sequence;
if ((defined($self->cigar_start) && ($self->cigar_start != 0))
|| (defined $self->cigar_end && ($self->cigar_end != 0))) {
unless ((defined($self->cigar_start) && ($self->cigar_start != 0)) &&
(defined $self->cigar_end && ($self->cigar_end != 0))) {
throw("both cigar_start and cigar_end should be defined");
}
my $offset = $self->cigar_start - 1;
my $length = $self->cigar_end - $self->cigar_start + 1;
$sequence = substr($sequence, $offset, $length);
}
my $cigar_line = $self->cigar_line;
$cigar_line =~ s/([MD])/$1 /g;
my @cigar_segments = split " ",$cigar_line;
my $alignment_string = "";
my $seq_start = 0;
foreach my $segment (@cigar_segments) {
if ($segment =~ /^(\d*)D$/) {
my $length = $1;
$length = 1 if ($length eq "");
$alignment_string .= "-" x $length;
} elsif ($segment =~ /^(\d*)M$/) {
my $length = $1;
$length = 1 if ($length eq "");
$alignment_string .= substr($sequence,$seq_start,$length);
$seq_start += $length;
}
}
$self->{'alignment_string'} = $alignment_string;
}
return $self->{'alignment_string'}; } |
sub cdna_alignment_string
{ my ($self, $member, $changeSelenos) = @_;
unless (defined $changeSelenos) {
$changeSelenos = 0;
}
if($member->source_name ne 'ENSEMBLPEP') {
warning("Don't know how to retrieve cdna for database [@{[$member->source_name]}]
SPECIES @{[ $member->adaptor->db->get_GenomeDBAdaptor->fetch_by_dbID($member->genome_db_id)->db_adaptor->dbname ]}" );
return undef;
}
unless (defined $self->{'cdna_alignment_string'}) {
my $genome_db_id = $member->genome_db_id;
my $genome_db =
$member->adaptor->db->get_GenomeDBAdaptor->fetch_by_dbID($genome_db_id);
my $ta = $genome_db->db_adaptor->get_TranscriptAdaptor;
my $transcript;
if ($member->stable_id =~ /^\d+$/) {
$transcript = $ta->fetch_by_translation_id($member->stable_id);
} else {
$transcript = $ta->fetch_by_translation_stable_id($member->stable_id);
}
if(!$transcript) {
warning("Could not retrieve transcript via peptide id [" .
$member->stable_id . "] from database [" .
$genome_db->db_adaptor->dbname . "]");
return undef;
}
my $cdna = $transcript->translateable_seq;
if (defined $self->cigar_start || defined $self->cigar_end) {
unless (defined $self->cigar_start && defined $self->cigar_end) {
throw("both cigar_start and cigar_end should be defined");
}
my $offset = $self->cigar_start * 3 - 3;
my $length = ($self->cigar_end - $self->cigar_start + 1) * 3;
$cdna = substr($cdna, $offset, $length);
}
my $start = 0;
my $cdna_align_string = '';
foreach my $pep (split(//,$self->alignment_string($member))) {
if($pep eq '-') {
$cdna_align_string .= '--- ';
} elsif ($pep eq 'U' && $changeSelenos or $pep eq '*') {
$cdna_align_string .= 'NNN ';
$start += 3;
} else {
my $codon = substr($cdna, $start, 3);
unless (length($codon) == 3) {
$codon .= 'N' x (3 - length($codon));
}
$cdna_align_string .= $codon . ' ';
$start += 3;
}
}
$self->{'cdna_alignment_string'} = $cdna_align_string;
}
return $self->{'cdna_alignment_string'}; } |
sub new
{ my ($class) = @_;
return bless {}, $class; } |
sub new_fast
{ my ($class, $hashref) = @_;
return bless $hashref, $class; } |