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

View of /Sprout/FidCheck.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Thu Dec 6 14:58:03 2007 UTC (11 years, 2 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, rast_rel_2008_06_16, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2009_05_18, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.2: +3 -3 lines
Changed POD format for better compatability with Wiki.

#!/usr/bin/perl -w

package FidCheck;

    require Exporter;
    @ISA = ('Exporter');
    @EXPORT = qw();
    @EXPORT_OK = qw();

    use strict;
    use Tracer;

=head1 Feature ID Checker

=head2 Introduction

This object supports the C<is_deleted_fid> method to determine whether or not
a feature exists in a Sprout or FIG data store. If a FIG data store is used, then
the the C<$fig> object is returned unmodified. In the Sprout case, it will check
to see if the incoming ID is for an existing feature or synonym group. In addition,
it will cache the identified IDs so they don't need to be checked against the
database if the method is called again.

=head2 Public Methods

=head3 new

    my $fidCheck = FidCheck->new($sprout_or_fig);

Construct a new FidCheck object from a specified Sprout, FIG, or SFXlate object.

=over 4

=item sprout_or_fig

A Sprout object that may be used to access the database, or a FIG object that
may be used to access the data store.

=back

=cut

sub new {
    # Get the parameters.
    my ($class, $sprout_or_fig) = @_;
    # Declare the return variable.
    my $retVal;
    # Check the object type.
    if (ref($sprout_or_fig) eq 'Sprout') {
        # Here we have a Sprout object.
        $retVal = { db => $sprout_or_fig,
                    cache => { } };
        bless $retVal, $class;
    } elsif (ref($sprout_or_fig) eq 'SFXlate') {
        # Here we have an SFXlate object. We need its internal Sprout object.
        $retVal = { db => $sprout_or_fig->{sprout},
                    cache => { } };
        bless $retVal, $class;
    } else {
        # Return the object unmodified. It already has the required method.
        $retVal = $sprout_or_fig;
    }
    # Return the new object.
    return $retVal;
}

=head3 is_deleted_fid

    my $flag = $fidCheck->is_deleted_fid($fid);

Return TRUE if the specified feature does not exist, else FALSE. A feature exists if it is
in the B<Feature> table or the B<SynonymGroup> table. The synonym groups are not real features,
but they do have similarities, so it's important to

=over 4

=item fid

ID of the feature whose existence is to be checked.

=item RETURN

Returns TRUE if the feature does NOT exist, else FALSE.

=back

=cut

sub is_deleted_fid {
    # Get the parameters.
    my ($self, $fid) = @_;
    # Declare the return flag.
    my $flag;
    # Check the cache.
    my $cache = $self->{cache};
    if (exists $cache->{$fid}) {
        $flag = $cache->{$fid};
        Trace("$flag pulled from cache for $fid.") if T(4);
    } else {
        # Check the incoming ID type.
        if ($fid =~ /^fig\|/i) {
            # Here we have a feature ID. Test for existence of the feature.
            $flag = $self->{db}->Exists('Feature', $fid);
            Trace("$flag pulled from feature table for $fid.") if T(4);
        } else {
            # Here we have a synonym group ID. Test for its existence.
            $flag = $self->{db}->Exists('SynonymGroup', $fid);
            Trace("$flag pulled from synonym grup table for $fid.") if T(4);
        }
        # Cache the result.
        $cache->{$fid} = $flag;
    }
    # Return the result.
    return ! $flag;
}

1;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3