This is used as storage for all object references concerning a particular gene.
sub delete_Obj
{ my $self = shift;
my @values= values %{$self};
my @keys= keys %{$self};
foreach my $key ( @keys ) {
delete $self->{$key};
}
foreach my $value ( @values ) {
if (index(ref($value),"LiveSeq") != -1) { eval {
$value->delete_Obj;
};
} elsif (index(ref($value),"ARRAY") != -1) { my @array=@{$value};
my $element;
foreach $element (@array) {
eval {
$element->delete_Obj;
};
}
} elsif (index(ref($value),"HASH") != -1) { my %hash=%{$value};
my $element;
foreach $element (%hash) {
eval {
$element->delete_Obj;
};
}
}
}
return(1); } |
sub new
{ my ($thing, %args) = @_;
my $class = ref($thing) || $thing;
my ($i,$self,%gene);
my ($name,$inputfeatures,$upbound,$downbound)=($args{-name},$args{-features},$args{-upbound},$args{-downbound});
unless (ref($inputfeatures) eq "HASH") {
carp "$class not initialised because features hash not given";
return (-1);
}
my %features=%{$inputfeatures}; my $features=\%features;
my $DNA=$features->{'DNA'};
unless (ref($DNA) eq "Bio::LiveSeq::DNA") {
carp "$class not initialised because DNA feature not found";
return (-1);
}
my ($minstart,$maxend);
my ($start,$end);
my @Transcripts=@{$features->{'Transcripts'}};
my $strand;
unless (ref($Transcripts[0]) eq "Bio::LiveSeq::Transcript") {
$self->warn("$class not initialised: first Transcript not a LiveSeq object");
return (-1);
} else {
$strand=$Transcripts[0]->strand; }
for $i (@Transcripts) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Transcript")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Transcripts feature");
return (-1);
} else {
}
unless($minstart) { $minstart=$start; } unless($maxend) { $maxend=$end; } if ($i->strand != $strand) {
$self->warn("$class not initialised because exon-CDS-prim_transcript features do not share the same strand!");
return (-1);
}
if (($strand == 1)&&($start < $minstart)||($strand == -1)&&($start > $minstart)) { $minstart=$start; }
if (($strand == 1)&&($end > $maxend)||($strand == -1)&&($end < $maxend)) { $maxend=$end; }
}
my @Translations; my @Introns; my @Repeat_Units; my @Repeat_Regions;
my @Prim_Transcripts; my @Exons;
if (defined($features->{'Translations'})) {
@Translations=@{$features->{'Translations'}}; }
if (defined($features->{'Exons'})) {
@Exons=@{$features->{'Exons'}}; }
if (defined($features->{'Introns'})) {
@Introns=@{$features->{'Introns'}}; }
if (defined($features->{'Repeat_Units'})) {
@Repeat_Units=@{$features->{'Repeat_Units'}}; }
if (defined($features->{'Repeat_Regions'})) {
@Repeat_Regions=@{$features->{'Repeat_Regions'}}; }
if (defined($features->{'Prim_Transcripts'})) {
@Prim_Transcripts=@{$features->{'Prim_Transcripts'}}; }
if (@Translations) {
for $i (@Translations) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Translation")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Translations feature");
return (-1);
}
}
}
if (@Exons) {
for $i (@Exons) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Exon")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Exons feature");
return (-1);
}
if ($i->strand != $strand) {
$self->warn("$class not initialised because exon-CDS-prim_transcript features do not share the same strand!");
return (-1);
}
if (($strand == 1)&&($start < $minstart)||($strand == -1)&&($start > $minstart)) { $minstart=$start; }
if (($strand == 1)&&($end > $maxend)||($strand == -1)&&($end < $maxend)) { $maxend=$end; }
}
}
if (@Introns) {
for $i (@Introns) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Intron")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Introns feature");
return (-1);
}
}
}
if (@Repeat_Units) {
for $i (@Repeat_Units) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Repeat_Unit")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Repeat_Units feature");
return (-1);
}
}
}
if (@Repeat_Regions) {
for $i (@Repeat_Regions) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Repeat_Region")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Repeat_Regions feature");
return (-1);
}
}
}
if (@Prim_Transcripts) {
for $i (@Prim_Transcripts) {
($start,$end)=($i->start,$i->end);
unless ((ref($i) eq "Bio::LiveSeq::Prim_Transcript")&&($DNA->valid($start))&&($DNA->valid($end))) {
$self->warn("$class not initialised because of problems in Prim_Transcripts feature");
return (-1);
}
if ($i->strand != $strand) {
$self->warn("$class not initialised because exon-CDS-prim_transcript features do not share the same strand!");
return (-1);
}
if (($strand == 1)&&($start < $minstart)||($strand == -1)&&($start > $minstart)) { $minstart=$start; }
if (($strand == 1)&&($end > $maxend)||($strand == -1)&&($end < $maxend)) { $maxend=$end; }
}
}
my @allfeatures;
push (@allfeatures,$DNA,@Transcripts,@Translations,@Exons,@Introns,@Repeat_Units,@Repeat_Regions,@Prim_Transcripts);
my %multiplicity;
my $key; my @array;
foreach $key (keys(%features)) {
unless ($key eq "DNA") {
@array=@{$features{$key}};
$multiplicity{$key}=scalar(@array);
}
}
$multiplicity{DNA}=1;
my $maxtranscript=Bio::LiveSeq::Prim_Transcript->new(-start => $minstart, -end => $maxend, -strand => $strand, -seq => $DNA);
if (defined($upbound)) {
unless ($DNA->valid($upbound)) {
$self->warn("$class not initialised because upbound label not valid");
return (-1);
}
} else {
$upbound=$DNA->start;
}
if (defined($downbound)) {
unless ($DNA->valid($downbound)) {
$self->warn("$class not initialised because downbound label not valid");
return (-1);
}
} else {
$downbound=$DNA->end;
}
%gene = (name => $name, features => $features,multiplicity =>\% multiplicity,
upbound => $upbound, downbound => $downbound, allfeatures =>\@ allfeatures, maxtranscript => $maxtranscript);
$self =\% gene;
$self = bless $self, $class;
_set_Gene_in_all($self,@allfeatures);
return $self;
}
} |