Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
5e41496a
Commit
5e41496a
authored
17 years ago
by
Patrick Meidl
Browse files
Options
Downloads
Patches
Plain Diff
inherit from Serialisable, fixes to merge()
parent
7acbb8ee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Bio/EnsEMBL/IdMapping/ScoredMappingMatrix.pm
+57
-68
57 additions, 68 deletions
modules/Bio/EnsEMBL/IdMapping/ScoredMappingMatrix.pm
with
57 additions
and
68 deletions
modules/Bio/EnsEMBL/IdMapping/ScoredMappingMatrix.pm
+
57
−
68
View file @
5e41496a
...
...
@@ -33,30 +33,23 @@ use strict;
use
warnings
;
no
warnings
'
uninitialized
';
use
Bio::EnsEMBL::IdMapping::
Serialisable
;
our
@ISA
=
qw(Bio::EnsEMBL::IdMapping::Serialisable)
;
use
Bio::EnsEMBL::Utils::
Argument
qw(rearrange)
;
use
Bio::EnsEMBL::Utils::
Exception
qw(throw warning)
;
use
Bio::EnsEMBL::Utils::
ScriptUtils
qw(parse_bytes)
;
use
Bio::EnsEMBL::IdMapping::
Entry
;
use
Storable
qw(nfreeze thaw nstore retrieve)
;
sub
new
{
my
$caller
=
shift
;
my
$class
=
ref
(
$caller
)
||
$caller
;
my
(
$dump_path
,
$cache_file
)
=
rearrange
([
qw(DUMP_PATH CACHE_FILE)
],
@
_
);
throw
("
You must provide a cache file name
")
unless
(
$cache_file
);
my
$self
=
{};
bless
(
$self
,
$class
);
my
$self
=
$class
->
SUPER::
new
(
@
_
);
# initialise internal datastructure
$self
->
{'
cache
'}
->
{'
matrix
'}
=
{};
$self
->
{'
cache
'}
->
{'
source_list
'}
=
{};
$self
->
{'
cache
'}
->
{'
target_list
'}
=
{};
$self
->
{'
dump_path
'}
=
$dump_path
||
'
.
';
$self
->
{'
cache_file
'}
=
$self
->
dump_path
.
"
/
$cache_file
";
return
$self
;
}
...
...
@@ -75,6 +68,7 @@ sub add_Entry {
sub
remove_Entry
{
warning
('
Method ScoredMappingMatrix->remove_Entry not implemented (yet).
');
}
...
...
@@ -94,6 +88,16 @@ sub add_score {
}
sub
set_score
{
my
$self
=
shift
;
my
$source
=
shift
;
my
$target
=
shift
;
my
$score
=
shift
;
$self
->
{'
cache
'}
->
{'
matrix
'}
->
{"
$source
:
$target
"}
=
$score
;
}
sub
get_Entry
{
my
$self
=
shift
;
my
$source
=
shift
;
...
...
@@ -127,7 +131,16 @@ sub get_targets_for_source {
my
$self
=
shift
;
my
$source
=
shift
;
return
(
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$source
}
||
[]
);
return
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$source
}
||
[]
;
}
sub
get_Entries_for_source
{
my
$self
=
shift
;
my
$source
=
shift
;
return
[
map
{
$self
->
get_Entry
(
$source
,
$_
)
}
@
{
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$source
}
||
[]
}
];
}
...
...
@@ -135,7 +148,16 @@ sub get_sources_for_target {
my
$self
=
shift
;
my
$target
=
shift
;
return
(
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$target
}
||
[]
);
return
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$target
}
||
[]
;
}
sub
get_Entries_for_target
{
my
$self
=
shift
;
my
$target
=
shift
;
return
[
map
{
$self
->
get_Entry
(
$_
,
$target
)
}
@
{
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$target
}
||
[]
}
];
}
...
...
@@ -233,6 +255,7 @@ sub merge {
my
$c
=
0
;
# merge the matrices
foreach
my
$key
(
keys
%
{
$matrix
->
{'
cache
'}
->
{'
matrix
'}
})
{
if
(
!
defined
(
$self
->
{'
cache
'}
->
{'
matrix
'}
->
{
$key
})
or
$self
->
{'
cache
'}
->
{'
matrix
'}
->
{
$key
}
<
$matrix
->
{'
cache
'}
->
{'
matrix
'}
->
{
$key
})
{
...
...
@@ -241,66 +264,32 @@ sub merge {
}
}
return
$c
;
}
sub
write_to_file
{
my
$self
=
shift
;
# create dump directory if it doesn't exist
if
(
my
$dump_path
=
$self
->
dump_path
)
{
unless
(
-
d
$dump_path
)
{
system
("
mkdir -p
$dump_path
")
==
0
or
throw
("
Unable to create directory
$dump_path
.
\n
");
# merge sources and target lists
foreach
my
$key
(
keys
%
{
$matrix
->
{'
cache
'}
->
{'
source_list
'}
})
{
if
(
defined
(
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$key
}))
{
# need to merge lists
my
%unique
=
map
{
$_
=>
1
}
@
{
$self
->
get_targets_for_source
(
$key
)
};
map
{
$unique
{
$_
}
=
1
}
@
{
$matrix
->
get_targets_for_source
(
$key
)
};
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$key
}
=
[
keys
%unique
];
}
else
{
# no merging needed
$self
->
{'
cache
'}
->
{'
source_list
'}
->
{
$key
}
=
$matrix
->
{'
cache
'}
->
{'
source_list
'}
->
{
$key
};
}
}
my
$cache_file
=
$self
->
cache_file
;
eval
{
nstore
(
$self
->
{'
cache
'},
$cache_file
)
};
if
(
$@
)
{
throw
("
Unable to store
$cache_file
: $@
\n
");
}
my
$size
=
-
s $cache_file;
return parse_bytes($size);
}
sub read_from_file {
my $s
elf
=
shift
;
my
$cache_file
=
$self
->
cache_file
;
unless
(
-
s $cache_file) {
throw("No valid cache file found at $cache_file.");
}
eval { $s
elf
->
{'
cache
'}
=
retrieve
(
$cache_file
);
};
if
(
$@
)
{
throw
("
Unable to retrieve cache: $@
");
foreach
my
$key
(
keys
%
{
$matrix
->
{'
cache
'}
->
{'
target_list
'}
})
{
if
(
defined
(
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$key
}))
{
# need to merge lists
my
%unique
=
map
{
$_
=>
1
}
@
{
$self
->
get_sources_for_target
(
$key
)
};
map
{
$unique
{
$_
}
=
1
}
@
{
$matrix
->
get_sources_for_target
(
$key
)
};
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$key
}
=
[
keys
%unique
];
}
else
{
# no merging needed
$self
->
{'
cache
'}
->
{'
target_list
'}
->
{
$key
}
=
$matrix
->
{'
cache
'}
->
{'
target_list
'}
->
{
$key
};
}
}
return
$self
;
}
#
# getter/setters
#
sub
cache_file
{
my
$self
=
shift
;
$self
->
{'
cache_file
'}
=
shift
if
(
@
_
);
return
$self
->
{'
cache_file
'};
}
sub
dump_path
{
my
$self
=
shift
;
$self
->
{'
dump_path
'}
=
shift
if
(
@
_
);
return
$self
->
{'
dump_path
'};
return
$c
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment