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
;
}
sub
_set_Gene_in_all {
my
$Gene
=
shift
;
my
$self
;
foreach
$self
(
@_
) {
$self
->gene(
$Gene
);
}
}
sub
name {
my
(
$self
,
$value
) =
@_
;
if
(
defined
$value
) {
$self
->{
'name'
} =
$value
;
}
unless
(
exists
$self
->{
'name'
}) {
return
"unknown"
;
}
else
{
return
$self
->{
'name'
};
}
}
sub
features {
my
$self
=
shift
;
return
(
$self
->{
'features'
});
}
sub
get_DNA {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'DNA'
});
}
sub
get_Transcripts {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Transcripts'
});
}
sub
get_Translations {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Translations'
});
}
sub
get_Prim_Transcripts {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Prim_Transcripts'
});
}
sub
get_Repeat_Units {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Repeat_Units'
});
}
sub
get_Repeat_Regions {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Repeat_Regions'
});
}
sub
get_Introns {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Introns'
});
}
sub
get_Exons {
my
$self
=
shift
;
return
(
$self
->{
'features'
}->{
'Exons'
});
}
sub
featuresnum {
my
$self
=
shift
;
return
(
$self
->{
'multiplicity'
});
}
sub
upbound {
my
$self
=
shift
;
return
(
$self
->{
'upbound'
});
}
sub
downbound {
my
$self
=
shift
;
return
(
$self
->{
'downbound'
});
}
sub
printfeaturesnum {
my
$self
=
shift
;
my
(
$key
,
$value
);
my
%hash
=%{
$self
->featuresnum};
foreach
$key
(
keys
(
%hash
)) {
$value
=
$hash
{
$key
};
print
"\t$key => $value\n"
;
}
}
sub
maxtranscript {
my
$self
=
shift
;
return
(
$self
->{
'maxtranscript'
});
}
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
verbose {
my
$self
=
shift
;
my
$value
=
shift
;
return
$self
->{
'features'
}->{
'DNA'
}->verbose(
$value
);
}
sub
warn
{
my
$self
=
shift
;
my
$value
=
shift
;
return
$self
->{
'features'
}->{
'DNA'
}->
warn
(
$value
);
}
1;