3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
37 # create a new MappingList
39 -DUMP_PATH => $dump_path,
40 -CACHE_FILE =>
'gene_mappings.ser',
45 my $mappings->add_all( $entry2, $entry3 );
48 $mappings->write_to_file;
50 # later, read these mappings from file
52 -DUMP_PATH => $dump_path,
53 -CACHE_FILE =>
'gene_mappings.ser',
60 objects. It
's essentially an OO wrapper for an array with some type
61 checking and convenience methods.
75 package Bio::EnsEMBL::IdMapping::MappingList;
79 no warnings 'uninitialized
';
81 use Bio::EnsEMBL::IdMapping::Serialisable;
82 our @ISA = qw(Bio::EnsEMBL::IdMapping::Serialisable);
84 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
85 use Bio::EnsEMBL::Utils::ScriptUtils qw(path_append);
90 Arg[1-N] : see superclass
91 Example : my $gene_mappings = Bio::EnsEMBL::IdMapping::MappingList->new(
92 -DUMP_PATH => $dump_path,
93 -CACHE_FILE => 'gene_mappings.ser
',
95 Description : Constructor.
96 Return type : Bio::EnsEMBL::IdMapping::MappingList
106 my $class = ref($caller) || $caller;
107 my $self = $class->SUPER::new(@_);
109 # initialise internal datastructure unless we loaded a serialised object
110 unless ($self->loaded) {
111 $self->{'cache
'}->{'entries
'} = [];
120 Arg[1] : Bio::EnsEMBL::IdMapping::Entry - Entry to add
121 Example : $mappings->add_Entry($entry);
122 Description : Adds an Entry to the MappingList.
124 Exceptions : thrown on wrong or missing argument
136 throw("Need a Bio::EnsEMBL::IdMapping::Entry");
139 push @{ $self->{'cache
'}->{'entries
'} }, $entry;
143 =head2 get_all_Entries
145 Example : foreach my $entry (@{ $mappings->get_all_Entries }) {
146 # do something with the entry
148 Description : Gets all Entries in the MappingList.
149 Return type : Arrayref of Bio::EnsEMBL::IdMapping::Entry
157 sub get_all_Entries {
159 return $self->{'cache
'}->{'entries
'};
165 Arg[1] : List of Bio::EnsEMBL::IdMapping::Entry objects
166 Example : my @entries = ($entry1, $entry2);
167 $mappings->add_all(@entries);
168 Description : Adds a list of Entries to the MappingList.
170 Exceptions : thrown on wrong argument
181 foreach my $mapping (@mappings) {
184 throw("Need a Bio::EnsEMBL::IdMapping::MappingList");
187 push @{ $self->{'cache
'}->{'entries
'} }, @{ $mapping->get_all_Entries };
192 =head2 get_entry_count
194 Example : my $num_entries = $mappings->get_entry_count;
195 Description : Returns the number of Entries in the MappingList.
204 sub get_entry_count {
206 return scalar(@{ $self->{'cache
'}->{'entries
'} });
212 Arg[1] : String $type - object type (e.g. 'gene
')
213 Arg[2] : String $dump_path - path for writing output
214 Example : $mappings->log('gene
', $conf->param('basedir
'));
215 Description : Logs all Entries in the MappingList to a file. Used for
218 Exceptions : thrown on I/0 error
228 my $dump_path = shift;
230 my $debug_path = path_append($dump_path, 'debug');
231 my $logfile = "$debug_path/${type}_final_scores.txt";
233 open(my $fh, '>
', $logfile) or
234 throw("Unable to open $logfile for writing: $!");
236 foreach my $entry (@{ $self->get_all_Entries }) {
237 print $fh ($entry->to_string."\n");
246 Example : print LOG $mappings->to_string, "\n";
247 Description : Returns a string representation of the MappingList. This is
248 simply a multi-line string, where each line is a stringified
250 Useful for debugging and logging.
264 foreach my $entry (@{ $self->get_all_Entries }) {
265 $string .= $entry->to_string."\n";