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

View of /Sprout/FIGRules.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.3 - (download) (as text) (annotate)
Wed Apr 19 03:36:54 2006 UTC (13 years, 11 months ago) by parrello
Branch: MAIN
Changes since 1.2: +0 -0 lines
Removed duplicate version of the package.

package FIGRules;

	require Exporter;
	@ISA = ('Exporter');
	@EXPORT = qw(NormalizeAlias FigCompare);
	use strict;

=head1 FIG Rules Module

=head2 Introduction

This module contains methods that are shared by both B<FIG.pm> and B<Sprout.pm>.



=head2 Public Methods

=head3 NormalizeAlias

C<< my ($newAlias, $flag) = NormalizeAlias($alias); >>

Convert a feature alias to a normalized form. The incoming alias is examined to determine
whether it is a FIG feature name, a UNIPROT feature name, or a GenBank feature name. A
prefix is then applied to convert the alias to the form in which it occurs in the Sprout
database. The supported feature name styles are as follows.

C<fig|>I<dd..d>C<.>I<dd..d>C<.peg.>I<dd..d> where "I<dd..d>" is a sequence of one or more
digits, is a FIG feature name.

I<dd..dd> where "I<dd..d>" is a sequence of one or more digits, is a GenBank feature name.

I<XXXXXX> where "I<XXXXXX>" is a sequence of exactly 6 letters and/or digits, is a UNIPROT
feature name.

=over 4

=item alias

Alias to be converted to its normal form.

=item RETURN

Returns a two-element list. The first element (newAlias) is the normalized alias; the second 
(flag) is 1 if the aliias is a FIG feature name, 0 if it is not. Thus, if the flag value is
1, the alias will be expected in the B<Feature(id)> field of the Sprout data, and if it is
0, the alias will be expected in the B<Feature(alias)> field.



sub NormalizeAlias {
	# Get the parameters.
	my ($alias) = @_;
	# Declare the return variables.
	my ($retVal,$flag);
	# Determine the type of alias.
    if ($alias =~ /^fig\|\d+\.\d+\.peg\.\d+$/) {
		# Here we have a FIG feature ID.
		$retVal = $alias;
		$flag = 1;
	} elsif ($alias =~ /^\d+$/) {
		# Here we have a GenBank alias.
		$retVal = "gi|" . $alias;
		$flag = 0;
    } elsif ($alias =~ /^[A-Z0-9]{6}$/) {
		# Here we have a UNIPROT alias.
		$retVal = "uni|" . $alias;
		$flag = 0;
	} else {
		# Here we have an unknown alias type. We assumed that it does not require
		# normalization. (If it does, then additional ELSIF-cases need to be added
		# above.)
		$retVal = $alias;
		$flag = 0;
	# Return the normalized alias and the flag.
	return ($retVal, $flag);

=head3 FIGCompare

C<< my $cmp = FIGCompare($aPeg, $bPeg); >>

Compare two FIG IDs. This method is designed for use in sorting a list of FIG-style
feature IDs. For example, to sort the list C<@pegs>, you would use.

C<< my @sortedPegs = sort { &FIGCompare($a,$b) } @pegs; >>

=over 4

=item aPeg

First feature ID to compare.

=item bPeg

Second feature ID to compare.

=item RETURN

Returns a negative number if C<aPeg> should sort before C<bPeg>, a positive number if C<aPeg>
should sort after C<bPeg>, and zero if both should sort to the same place.



sub FIGCompare {
	# Get the parameters.
    my($aPeg, $bPeg) = @_;
	# Declare the work variables.
	# Declare the return variable.
	my $retVal;
	# The IF-condition parses out the pieces of the IDs. If both IDs are FIG IDs, then
	# the condition will match and we'll do a comparison of the pieces. If either one is
	# not a FIG ID, we'll do a strict string comparison. The FIG ID pieces are,
	# respectively, the Genome ID, the feature type, and the feature index number. These
	# are all dot-delimited, except that the genome ID already has a dot in it.
    if (($aPeg =~ /^fig\|(\d+\.\d+).([^\.]+)\.(\d+)$/) && (($g1,$t1,$n1) = ($1,$2,$3)) &&
	($bPeg =~ /^fig\|(\d+\.\d+).([^\.]+)\.(\d+)$/) && (($g2,$t2,$n2) = ($1,$2,$3))) {
		$retVal = (($g1 <=> $g2) or ($t1 cmp $t2) or ($n1 <=> $n2));
    } else {
		$retVal = ($a cmp $b);
	# Return the comparison indicator.
	return $retVal;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3