| 1 | package GO::Utils::General; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | GO::Utils::General - provides some general utilities for clients of other GO classes | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use GO::Utils::General qw (CategorizeGenes); | ||
| 10 | |||
| 11 | CategorizeGenes(annotation => $annotation, | ||
| 12 | genes => \@genes, | ||
| 13 | ambiguous => \@ambiguous, | ||
| 14 | unambiguous => \@unambiguous, | ||
| 15 | notFound => \@notFound); | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use diagnostics; | ||
| 22 | |||
| 23 | use vars qw (@ISA @EXPORT_OK $VERSION); | ||
| 24 | use Exporter; | ||
| 25 | @ISA = ('Exporter'); | ||
| 26 | @EXPORT_OK = qw (CategorizeGenes); | ||
| 27 | |||
| 28 | $VERSION = 0.11; | ||
| 29 | |||
| 30 | my @kRequiredArgs = qw (annotation genes ambiguous unambiguous notFound); | ||
| 31 | |||
| 32 | ########################################################################## | ||
| 33 | sub CategorizeGenes{ | ||
| 34 | ########################################################################## | ||
| 35 | |||
| 36 | =head2 CategorizeGenes | ||
| 37 | |||
| 38 | CategorizeGenes categorizes a set of genes into three categories, whether they | ||
| 39 | are ambiguous, whether they are not found, or whether they are unambiguous. The | ||
| 40 | category to which they belong is determined by using an annotation provider. | ||
| 41 | |||
| 42 | Usage: | ||
| 43 | |||
| 44 | use GO::Utils::General qw (CategorizeGenes); | ||
| 45 | |||
| 46 | CategorizeGenes(annotation => $annotation, | ||
| 47 | genes => \@genes, | ||
| 48 | ambiguous => \@ambiguous, | ||
| 49 | unambiguous => \@unambiguous, | ||
| 50 | notFound => \@notFound); | ||
| 51 | |||
| 52 | All the above named arguments are required: | ||
| 53 | |||
| 54 | annotation : A GO::AnnotationProvider concrete subclass instance | ||
| 55 | genes : A reference to an array of gene names | ||
| 56 | |||
| 57 | The remaining arguments should be empty arrays, passed in by reference, that | ||
| 58 | will be populated by this function. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | ########################################################################## | ||
| 63 | |||
| 64 | my (%args) = @_; | ||
| 65 | |||
| 66 | foreach my $arg (@kRequiredArgs){ | ||
| 67 | |||
| 68 | if (!exists $args{$arg} || !defined $args{$arg}){ | ||
| 69 | |||
| 70 | die "You must provide a $arg argument to CategorizeGenes"; | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | } | ||
| 75 | |||
| 76 | my $annotation = $args{'annotation'}; | ||
| 77 | my $genesRef = $args{'genes'}; | ||
| 78 | my $ambiguousRef = $args{'ambiguous'}; | ||
| 79 | my $unambiguousRef = $args{'unambiguous'}; | ||
| 80 | my $notFoundRef = $args{'notFound'}; | ||
| 81 | |||
| 82 | foreach my $gene (@{$genesRef}){ | ||
| 83 | |||
| 84 | if ($annotation->nameIsAmbiguous($gene)){ | ||
| 85 | |||
| 86 | push(@{$ambiguousRef}, $gene); | ||
| 87 | next; | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | my $name = $annotation->standardNameByName($gene); | ||
| 92 | |||
| 93 | if (defined $name){ | ||
| 94 | |||
| 95 | push(@{$unambiguousRef}, $gene); | ||
| 96 | |||
| 97 | }else{ | ||
| 98 | |||
| 99 | push(@{$notFoundRef}, $gene); | ||
| 100 | |||
| 101 | } | ||
| 102 | |||
| 103 | } | ||
| 104 | |||
| 105 | } | ||
| 106 | |||
| 107 | 1; # keep Perl happy |