our
$VERSION
=
$Bio::Polloc::Polloc::Root::VERSION
;
sub
new {
my
(
$caller
,
@args
) =
@_
;
my
$class
=
ref
(
$caller
) ||
$caller
;
if
(
$class
!~ m/Bio::Polloc::Locus::(\S+)/){
my
$bme
= Bio::Polloc::Polloc::Root->new(
@args
);
my
(
$type
) =
$bme
->_rearrange([
qw(TYPE)
],
@args
);
if
(
$type
){
$type
= Bio::Polloc::LocusI->_qualify_type(
$type
);
$class
=
"Bio::Polloc::Locus::"
.
$type
if
$type
;
}
}
if
(
$class
=~ m/Bio::Polloc::Locus::(\S+)/){
my
$load
= 0;
if
(Bio::Polloc::RuleI->_load_module(
$class
)){
$load
=
$class
;
}
elsif
(Bio::Polloc::RuleI->_load_module(
"Bio::Polloc::Locus::generic"
)){
$load
=
"Bio::Polloc::Locus::generic"
;
}
if
(
$load
){
my
$self
=
$load
->SUPER::new(
@args
);
$self
->debug(
"Got the LocusI class $load"
);
my
(
$from
,
$to
,
$strand
,
$name
,
$rule
,
$seq
,
$id
,
$family
,
$source
,
$comments
,
$genome
,
$seqname
) =
$self
->_rearrange(
[
qw(FROM TO STRAND NAME RULE SEQ ID FAMILY SOURCE COMMENTS GENOME SEQNAME)
],
@args
);
$self
->from(
$from
);
$self
->to(
$to
);
$self
->strand(
$strand
);
$self
->name(
$name
);
$self
->rule(
$rule
);
$self
->seq(
$seq
);
$self
->id(
$id
);
$self
->family(
$family
);
$self
->source(
$source
);
$self
->comments(
$comments
);
$self
->genome(
$genome
);
$self
->seq_name(
$seqname
);
$self
->_initialize(
@args
);
return
$self
;
}
my
$bme
= Bio::Polloc::Polloc::Root->new(
@args
);
$bme
->throw(
"Impossible to load the module"
,
$class
);
}
my
$bme
= Bio::Polloc::Polloc::Root->new(
@args
);
$bme
->throw(
"Impossible to load the proper Bio::Polloc::LocusI class with "
.
"["
.
join
(
"; "
,
@args
).
"]"
,
$class
);
}
sub
type {
my
(
$self
,
$value
) =
@_
;
if
(
$value
){
my
$v
=
$self
->_qualify_type(
$value
);
$self
->throw(
"Attempting to set an invalid type of locus"
,
$value
)
unless
$v
;
$self
->{
'_type'
} =
$v
;
}
return
$self
->{
'_type'
};
}
sub
genome {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_genome'
} =
$value
if
defined
$value
;
return
unless
defined
$self
->{
'_genome'
};
$self
->throw(
"Unexpected type of genome"
,
$self
->{
'_genome'
})
unless
UNIVERSAL::can(
$self
->{
'_genome'
},
'isa'
)
and
$self
->{
'_genome'
}->isa(
'Bio::Polloc::Genome'
);
return
$self
->{
'_genome'
};
}
sub
name {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_name'
} =
$value
if
defined
$value
;
return
$self
->{
'_name'
};
}
sub
aliases {
return
shift
->{
'_aliases'
}; }
sub
add_alias {
my
(
$self
,
@values
) =
@_
;
$self
->{
'_aliases'
} ||= [];
push
(@{
$self
->{
'_aliases'
}},
@values
);
}
sub
parents {
return
shift
->{
'_parents'
}; }
sub
add_parent {
my
(
$self
,
@values
) =
@_
;
$self
->{
'_parents'
} ||= [];
for
(
@values
){
$self
->throw(
"Illegal parent class '"
.
ref
(
$_
).
"'"
,
$_
)
unless
$_
->isa(
'Bio::Polloc::LocusI'
) }
push
(@{
$self
->{
'_aliases'
}},
@values
);
}
sub
target {
my
(
$self
,
@args
) =
@_
;
if
(
$#args
>=0){
my
(
$id
,
$from
,
$to
,
$strand
) =
$self
->_rearrange([
qw(ID FROM TO STRAND)
],
@args
);
$self
->{
'_target'
} = {
'id'
=>
$id
,
'from'
=>
$from
,
'to'
=>
$to
,
'strand'
=>
$strand
};
}
return
$self
->{
'_target'
};
}
sub
comments {
my
(
$self
,
@comments
) =
@_
;
if
(
$#comments
>=0){
$self
->{
'_comments'
} ||=
""
;
for
(
@comments
) {
$self
->{
'_comments'
} .=
"\n"
.
$_
if
defined
$_
}
$self
->{
'_comments'
} =~ s/^\n+//;
$self
->{
'_comments'
} =~ s/\n+$//;
}
return
$self
->{
'_comments'
};
}
sub
xrefs {
return
shift
->{
'_xrefs'
} }
sub
add_xref {
my
$self
=
shift
;
$self
->{
'_xrefs'
} ||= [];
push
@{
$self
->{
'_xrefs'
}},
@_
if
$#_
>=0;
}
sub
ontology_terms_str{
return
shift
->{
'_ontology_terms_str'
} }
sub
add_ontology_term_str {
my
$self
=
shift
;
push
@{
$self
->{
'_ontology_terms_str'
}},
@_
if
$#_
>=0;
}
sub
from {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_from'
} ||= -1;
$self
->{
'_from'
} =
$value
+0
if
defined
$value
;
return
$self
->{
'_from'
};
}
sub
to {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_to'
} ||= -1;
$self
->{
'_to'
} =
$value
+0
if
defined
$value
;
return
$self
->{
'_to'
};
}
sub
length
{
my
$self
=
shift
;
return
unless
defined
$self
->from and
defined
$self
->to;
return
abs
(
$self
->to -
$self
->from);
}
sub
id {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_id'
} =
$value
if
defined
$value
;
return
$self
->{
'_id'
};
}
sub
family {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_family'
} =
$value
if
defined
$value
;
unless
(
defined
$self
->{
'_family'
} or not
defined
$self
->id){
if
(
$self
->id =~ m/(.*):\d+\.\d+/){
$self
->{
'_family'
} = $1;
}
}
$self
->{
'_family'
} =
$self
->rule->type
if
not
defined
$self
->{
'_family'
} and
defined
$self
->rule;
return
'unknown'
unless
defined
$self
->{
'_family'
};
return
$self
->{
'_family'
};
}
sub
source {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_source'
} =
$value
if
defined
$value
;
$self
->{
'_source'
} =
$self
->rule->source
if
not
defined
$self
->{
'_source'
} and
defined
$self
->rule;
return
'polloc'
if
not
defined
$self
->{
'_source'
};
return
$self
->{
'_source'
};
}
sub
strand {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_strand'
} ||=
'.'
;
$self
->{
'_strand'
} =
$value
if
defined
$value
;
return
$self
->{
'_strand'
};
}
sub
rule {
my
(
$self
,
$value
) =
@_
;
if
(
defined
$value
){
$self
->throw(
"Unexpected class of argument '"
.
ref
(
$value
).
"'"
,
$value
)
unless
$value
->isa(
'Bio::Polloc::RuleI'
);
$self
->{
'_rule'
} =
$value
;
}
return
$self
->{
'_rule'
};
}
sub
score {
$_
[0]->throw(
"score"
,
$_
[0],
"Bio::Polloc::Polloc::NotImplementedException"
) }
sub
seq {
my
(
$self
,
$seq
) =
@_
;
if
(
defined
$seq
){
$self
->throw(
"Illegal type of sequence"
,
$seq
)
unless
UNIVERSAL::can(
$seq
,
'isa'
) and
$seq
->isa(
'Bio::Seq'
);
$self
->{
'_seq'
} =
$seq
;
}
if
(not
defined
$self
->{
'_seq'
} and
defined
$self
->{
'_seq_name'
} and
defined
$self
->genome){
$self
->{
'_seq'
} =
$self
->genome->search_sequence(
$self
->seq_name);
}
return
$self
->{
'_seq'
};
}
sub
seq_name {
my
(
$self
,
$value
) =
@_
;
$self
->{
'_seq_name'
} =
$value
if
defined
$value
;
if
(not
defined
$self
->{
'_seq_name'
} and
defined
$self
->seq){
$self
->{
'_seq_name'
} =
$self
->seq->display_id;
}
return
$self
->{
'_seq_name'
};
}
sub
stringify {
my
(
$self
,
@args
) =
@_
;
my
$out
=
ucfirst
$self
->type;
$out
.=
" '"
.
$self
->id .
"'"
if
defined
$self
->id;
$out
.=
" at ["
.
$self
->from.
".."
.
$self
->to .
$self
->strand .
"]"
;
return
$out
;
}
sub
context_seq {
my
(
$self
,
$ref
,
$from
,
$to
) =
@_
;
$self
->_load_module(
'Bio::Polloc::GroupCriteria'
);
return
unless
defined
$self
->seq and
defined
$self
->from and
defined
$self
->to;
my
$seq
;
my
(
$start
,
$end
);
my
$revcom
= 0;
if
(
$ref
< 0){
if
(
$self
->strand eq
'?'
or
$self
->strand eq
'+'
){
$start
=
$self
->from -
$from
;
$end
=
$self
->from -
$to
;
}
else
{
$start
=
$self
->to +
$to
;
$end
=
$self
->to +
$from
;
$revcom
= !
$revcom
;
}
}
elsif
(
$ref
> 0){
if
(
$self
->strand eq
'?'
or
$self
->strand eq
'+'
){
$start
=
$self
->to +
$to
;
$end
=
$self
->to +
$from
;
$revcom
= !
$revcom
;
}
else
{
$start
=
$self
->from -
$from
;
$end
=
$self
->from -
$to
;
}
}
else
{
if
(
$self
->strand eq
'?'
or
$self
->strand eq
'+'
){
$start
=
$self
->from +
$from
;
$end
=
$self
->to +
$from
;
}
else
{
$start
=
$self
->to -
$from
;
$end
=
$self
->from -
$to
;
}
}
$start
= max(1,
$start
);
$end
= min(
$self
->seq->
length
,
$end
);
$self
->debug(
"Extracting context "
.
(
defined
$self
->seq->display_id?
$self
->seq->display_id:
''
).
"[$start..$end] "
.(
$revcom
?
"-"
:
"+"
));
$seq
= Bio::Polloc::GroupCriteria->_build_subseq(
$self
->seq,
$start
,
$end
);
return
unless
defined
$seq
;
$seq
=
$seq
->revcom
if
$revcom
;
return
$seq
;
}
sub
distance {
$_
[0]->throw(
"score"
,
$_
[0],
"Bio::Polloc::Polloc::NotImplementedException"
) }
sub
_qualify_type {
my
(
$self
,
$value
) =
@_
;
return
unless
$value
;
$value
=
lc
$value
;
$value
=
"pattern"
if
$value
=~/^(patt(ern)?)$/;
$value
=
"profile"
if
$value
=~/^(prof(ile)?)$/;
$value
=
"repeat"
if
$value
=~/^(rep(eat)?)$/;
$value
=
"similarity"
if
$value
=~/^((sequence)?sim(ilarity)?|homology|ident(ity)?)$/;
$value
=
"coding"
if
$value
=~/^(cod|cds)$/;
$value
=
"composition"
if
$value
=~/^(comp(osition)?|content)$/;
return
$value
;
}
sub
_initialize {
my
$self
=
shift
;
$self
->throw(
"_initialize"
,
$self
,
"Bio::Polloc::Polloc::NotImplementedException"
);
}
1;