[Bio] / Sprout / FidCheck.pm Repository:
ViewVC logotype

Annotation of /Sprout/FidCheck.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     package FidCheck;
4 :    
5 :     require Exporter;
6 :     @ISA = ('Exporter');
7 :     @EXPORT = qw();
8 :     @EXPORT_OK = qw();
9 :    
10 :     use strict;
11 :     use Tracer;
12 :    
13 :     =head1 Feature ID Checker
14 :    
15 :     =head2 Introduction
16 :    
17 :     This object supports the C<is_deleted_fid> method to determine whether or not
18 : parrello 1.2 a feature exists in a Sprout or FIG data store. If a FIG data store is used, then
19 :     the the C<$fig> object is returned unmodified. In the Sprout case, it will check
20 :     to see if the incoming ID is for an existing feature or synonym group. In addition,
21 :     it will cache the identified IDs so they don't need to be checked against the
22 :     database if the method is called again.
23 : parrello 1.1
24 :     =head2 Public Methods
25 :    
26 :     =head3 new
27 :    
28 :     C<< my $fidCheck = FidCheck->new($sprout_or_fig); >>
29 :    
30 :     Construct a new FidCheck object from a specified Sprout, FIG, or SFXlate object.
31 :    
32 :     =over 4
33 :    
34 :     =item sprout_or_fig
35 :    
36 :     A Sprout object that may be used to access the database, or a FIG object that
37 :     may be used to access the data store.
38 :    
39 :     =back
40 :    
41 :     =cut
42 :    
43 :     sub new {
44 :     # Get the parameters.
45 :     my ($class, $sprout_or_fig) = @_;
46 :     # Declare the return variable.
47 :     my $retVal;
48 :     # Check the object type.
49 :     if (ref($sprout_or_fig) eq 'Sprout') {
50 :     # Here we have a Sprout object.
51 : parrello 1.2 $retVal = { db => $sprout_or_fig,
52 :     cache => { } };
53 :     bless $retVal, $class;
54 :     } elsif (ref($sprout_or_fig) eq 'SFXlate') {
55 :     # Here we have an SFXlate object. We need its internal Sprout object.
56 :     $retVal = { db => $sprout_or_fig->{sprout},
57 :     cache => { } };
58 : parrello 1.1 bless $retVal, $class;
59 :     } else {
60 :     # Return the object unmodified. It already has the required method.
61 :     $retVal = $sprout_or_fig;
62 :     }
63 :     # Return the new object.
64 :     return $retVal;
65 :     }
66 :    
67 :     =head3 is_deleted_fid
68 :    
69 :     C<< my $flag = $fidCheck->is_deleted_fid($fid); >>
70 :    
71 : parrello 1.2 Return TRUE if the specified feature does not exist, else FALSE. A feature exists if it is
72 :     in the B<Feature> table or the B<SynonymGroup> table. The synonym groups are not real features,
73 :     but they do have similarities, so it's important to
74 : parrello 1.1
75 :     =over 4
76 :    
77 :     =item fid
78 :    
79 :     ID of the feature whose existence is to be checked.
80 :    
81 :     =item RETURN
82 :    
83 :     Returns TRUE if the feature does NOT exist, else FALSE.
84 :    
85 :     =back
86 :    
87 :     =cut
88 :    
89 :     sub is_deleted_fid {
90 :     # Get the parameters.
91 :     my ($self, $fid) = @_;
92 : parrello 1.2 # Declare the return flag.
93 :     my $flag;
94 :     # Check the cache.
95 :     my $cache = $self->{cache};
96 :     if (exists $cache->{$fid}) {
97 :     $flag = $cache->{$fid};
98 :     Trace("$flag pulled from cache for $fid.") if T(4);
99 :     } else {
100 :     # Check the incoming ID type.
101 :     if ($fid =~ /^fig\|/i) {
102 :     # Here we have a feature ID. Test for existence of the feature.
103 :     $flag = $self->{db}->Exists('Feature', $fid);
104 :     Trace("$flag pulled from feature table for $fid.") if T(4);
105 :     } else {
106 :     # Here we have a synonym group ID. Test for its existence.
107 :     $flag = $self->{db}->Exists('SynonymGroup', $fid);
108 :     Trace("$flag pulled from synonym grup table for $fid.") if T(4);
109 :     }
110 :     # Cache the result.
111 :     $cache->{$fid} = $flag;
112 :     }
113 : parrello 1.1 # Return the result.
114 :     return ! $flag;
115 :     }
116 :    
117 :     1;
118 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3