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

Diff of /Sprout/Sapling.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11, Tue Jun 30 19:53:51 2009 UTC revision 1.12, Wed Jul 1 21:35:03 2009 UTC
# Line 258  Line 258 
258      return $retVal;      return $retVal;
259  }  }
260    
261    =head3 FilterByGenome
262    
263        my @filteredFids = $sapling->FilterByGenome(\@fids, $genomeFilter);
264    
265    Filter the features using the specified genome-based criterion. The
266    criterion can be either a comma-separated list of genome IDs, or a
267    partial organism name.
268    
269    =over 4
270    
271    =item fids
272    
273    Reference to a list of feature IDs.
274    
275    =item genomeFilter
276    
277    A string specifying the filtering criterion. If undefined or blank, then
278    no filter is applied. If a name, then only features from genomes with a
279    matching name will be returned. A name is a match if the filter is an
280    exact match for some prefix of the organism name. Thus, C<Listeria> would
281    get all Listerias, while C<Listeria monocytogenes EGD-e> would match only
282    the specific EGD-e strain. For a more precise match, you can specify
283    instead a comma-delimited list of genome IDs. In this latter case, only
284    features for the listed genomes will be included in the results.
285    
286    =item RETURN
287    
288    Returns the features from the incoming list that match the filter condition.
289    
290    =back
291    
292    =cut
293    
294    sub FilterByGenome {
295        # Get the parameters.
296        my ($self, $fids, $genomeFilter) = @_;
297        # Declare the return variable.
298        my @retVal;
299        # Check the type of filter.
300        if (! $genomeFilter) {
301            # No filter, so copy the input directly to the result.
302            @retVal = @$fids;
303        } else {
304            # Trim edge spaces from the filter.
305            $genomeFilter = Tracer::Trim($genomeFilter);
306            # This hash will contain the permissible genome IDs.
307            my %genomeIDs;
308            # Check for a name. We assume we have a name if there's an
309            # alphabetic letter anywhere in the filter string.
310            if ($genomeFilter =~ /[a-zA-Z]/) {
311                # The filter contains something that does not look like a genome
312                # ID, so it is treated as a genome name. We get the IDs of the
313                # genomes with that name and put them in the hash.
314                %genomeIDs = map { $_ => 1 } $self->GetFlat("Genome",
315                                                            'Genome(scientific-name) LIKE ?',
316                                                            ["$genomeFilter%"], 'id');
317            } else {
318                # We are expecting a comma-delimited list of genome IDs, so we
319                # put these in our hash.
320                %genomeIDs = map { $_ => 1 } split(/\s*,\s*/, $genomeFilter);
321            }
322            # Now we loop through the features, keeping the ones whose genome ID
323            # matches something in the hash.
324            @retVal = grep { $genomeIDs{genome_of($_)} } @$fids;
325        }
326        # Return the result.
327        return @retVal;
328    }
329    
330    
331  =head3 GetLocations  =head3 GetLocations
332    
333      my @locs = $sapling->GetLocations($fid);      my @locs = $sapling->GetLocations($fid);

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3