$Bio::MUST::Core::IdMapper::VERSION
=
'0.250380'
;
has
$_
.
'_ids'
=> (
traits
=> [
'Array'
],
is
=>
'ro'
,
isa
=>
'Bio::MUST::Core::Types::full_ids'
,
default
=>
sub
{ [] },
coerce
=> 1,
writer
=>
'_set_'
.
$_
.
'_ids'
,
handles
=> {
'count_'
.
$_
.
'_ids'
=>
'count'
,
'all_'
.
$_
.
'_ids'
=>
'elements'
,
},
)
for
qw(long abbr)
;
has
'_'
.
$_
.
'_id_for'
=> (
traits
=> [
'Hash'
],
is
=>
'ro'
,
isa
=>
'HashRef[Str]'
,
init_arg
=>
undef
,
lazy
=> 1,
builder
=>
'_build_'
.
$_
.
'_id_for'
,
handles
=> {
$_
.
'_id_for'
=>
'get'
,
},
)
for
qw(long abbr)
;
sub
_build_long_id_for {
my
$self
=
shift
;
my
@abbr_ids
=
map
{
$_
->full_id }
$self
->all_abbr_seq_ids;
my
@long_ids
=
map
{
$_
->full_id }
$self
->all_long_seq_ids;
return
{ mesh
@abbr_ids
,
@long_ids
};
}
sub
_build_abbr_id_for {
my
$self
=
shift
;
my
@abbr_ids
=
map
{
$_
->full_id }
$self
->all_abbr_seq_ids;
my
@long_ids
=
map
{
$_
->full_id }
$self
->all_long_seq_ids;
return
{ mesh
@long_ids
,
@abbr_ids
};
}
sub
BUILD {
my
$self
=
shift
;
carp
'[BMC] Warning: long and abbreviated id list sizes differ!'
unless
$self
->count_long_ids ==
$self
->count_abbr_ids;
carp
'[BMC] Warning: non unique long ids!'
unless
$self
->count_long_ids == uniq @{
$self
->long_ids };
carp
'[BMC] Warning: non unique abbreviated ids!'
unless
$self
->count_abbr_ids == uniq @{
$self
->abbr_ids };
return
;
}
sub
all_long_seq_ids {
my
$self
=
shift
;
return
map
{ SeqId->new(
full_id
=>
$_
) }
$self
->all_long_ids;
}
sub
all_abbr_seq_ids {
my
$self
=
shift
;
return
map
{ SeqId->new(
full_id
=>
$_
) }
$self
->all_abbr_ids;
}
sub
load {
my
$class
=
shift
;
my
$infile
=
shift
;
my
$args
=
shift
// {};
my
$sep
=
$args
->{sep} //
qr{\t}
xms;
open
my
$in
,
'<'
,
$infile
;
my
$mapper
=
$class
->new();
my
@long_ids
;
my
@abbr_ids
;
LINE:
while
(
my
$line
= <
$in
>) {
chomp
$line
;
next
LINE
if
$line
=~
$EMPTY_LINE
||
$mapper
->is_comment(
$line
);
my
(
$long_id
,
$abbr_id
) =
split
$sep
,
$line
;
push
@long_ids
,
$long_id
;
push
@abbr_ids
,
$abbr_id
;
}
$mapper
->_set_long_ids( \
@long_ids
);
$mapper
->_set_abbr_ids( \
@abbr_ids
);
return
$mapper
;
}
sub
store {
my
$self
=
shift
;
my
$outfile
=
shift
;
my
$args
=
shift
// {};
my
$sep
=
$args
->{sep} //
"\t"
;
my
$header
=
$args
->{header} // 1;
open
my
$out
,
'>'
,
$outfile
;
print
{
$out
}
$self
->header
if
$header
;
my
$ea
= each_array @{
$self
->long_ids }, @{
$self
->abbr_ids };
while
(
my
(
$long_id
,
$abbr_id
) =
$ea
->() ) {
say
{
$out
}
join
$sep
,
$long_id
,
$abbr_id
;
}
return
;
}
__PACKAGE__->meta->make_immutable;
1;