Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Utils/SeqRegionCache.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 =head1 NAME | |
22 | |
23 Bio::EnsEMBL::Utils::SeqRegionCache - A shared LRU cache of information about | |
24 seq_regions | |
25 | |
26 =head1 SYNOPSIS | |
27 | |
28 use Bio::EnsEMBL::DBSQL::DBAdaptor; | |
29 | |
30 $db = Bio::EnsEMBL::DBSQL::DBAdaptor->new(...); | |
31 | |
32 $seq_region_cache = $db->get_SeqRegionCache(); | |
33 | |
34 $key = "$seq_region_name:$coord_system_id"; | |
35 | |
36 $array = $seq_region_cache->{$key}; | |
37 | |
38 if ($array) { | |
39 $name = $array->[1]; | |
40 $length = $array->[3]; | |
41 } else { | |
42 # cache miss, get the info from the database | |
43 # ... | |
44 | |
45 # cache the retrieved information | |
46 $seq_region_cache->{$key} = [ | |
47 $seq_region_id, $seq_region_name, | |
48 $coord_system_id, $seq_region_length | |
49 ]; | |
50 } | |
51 | |
52 =head1 DESCRIPTION | |
53 | |
54 This module is simply a convenient place to put a cache of sequence | |
55 region information which is shared by several adaptors for a given | |
56 database. | |
57 | |
58 =head1 METHODS | |
59 | |
60 =cut | |
61 | |
62 use strict; | |
63 use Bio::EnsEMBL::Utils::Cache; | |
64 | |
65 package Bio::EnsEMBL::Utils::SeqRegionCache; | |
66 | |
67 our $SEQ_REGION_CACHE_SIZE = 40000; | |
68 | |
69 | |
70 | |
71 sub new { | |
72 my $class = shift; | |
73 | |
74 my %id_cache; | |
75 my %name_cache; | |
76 | |
77 # | |
78 # the items to cache should be listrefs to | |
79 # [ sr_id, sr_name, cs_id, sr_length ] | |
80 # | |
81 # The name cache key is "sr_name:cs_id" | |
82 # The id cache is keyed on "sr_id" | |
83 # | |
84 | |
85 tie(%name_cache, 'Bio::EnsEMBL::Utils::Cache', $SEQ_REGION_CACHE_SIZE); | |
86 tie(%id_cache, 'Bio::EnsEMBL::Utils::Cache', $SEQ_REGION_CACHE_SIZE); | |
87 | |
88 return bless {'name_cache' => \%name_cache, | |
89 'id_cache' => \%id_cache}, $class; | |
90 } | |
91 | |
92 | |
93 1; | |
94 | |
95 | |
96 | |
97 |