[Bio] / FigKernelPackages / gjolists.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/gjolists.pm

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

revision 1.1, Thu Dec 8 21:59:33 2005 UTC revision 1.2, Sun Feb 11 22:41:37 2007 UTC
# Line 1  Line 1 
 #  
 # Copyright (c) 2003-2006 University of Chicago and Fellowship  
 # for Interpretations of Genomes. All Rights Reserved.  
 #  
 # This file is part of the SEED Toolkit.  
 #  
 # The SEED Toolkit is free software. You can redistribute  
 # it and/or modify it under the terms of the SEED Toolkit  
 # Public License.  
 #  
 # You should have received a copy of the SEED Toolkit Public License  
 # along with this program; if not write to the University of Chicago  
 # at info@ci.uchicago.edu or the Fellowship for Interpretation of  
 # Genomes at veronika@thefig.info or download a copy from  
 # http://www.theseed.org/LICENSE.TXT.  
 #  
   
1  package gjolists;  package gjolists;
2    
3  #  Invoke with:  #  Invoke with:
# Line 163  Line 146 
146  #  #
147  #  @dups = duplicates( @list )  #  @dups = duplicates( @list )
148  #-------------------------------------------------------------------------------  #-------------------------------------------------------------------------------
149  sub duplicates {  sub duplicates
150    {
151      my %cnt = ();      my %cnt = ();
152      map { ( $cnt{$_} = $cnt{$_} ? $cnt{$_}+1 : 1 ) == 2 ? $_ : () } @_;      grep { ++$cnt{$_} == 2 } @_;
153  }  }
154    
155    
# Line 190  Line 174 
174  #  #
175  #  @union = union( \@set1, \@set2, ... )  #  @union = union( \@set1, \@set2, ... )
176  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
177  sub union {  sub union
178    {
179      my %cnt = ();      my %cnt = ();
180      foreach (map { @$_ } @_) { $cnt{$_} = 1 };      grep { ++$cnt{$_} == 1 } map { @$_ } @_;
     keys %cnt;  
181  }  }
182    
183    
# Line 202  Line 186 
186  #  #
187  #  @intersection = intersection( \@set1, \@set2, ... )  #  @intersection = intersection( \@set1, \@set2, ... )
188  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
189  sub intersection {  sub intersection
190      my %cnt = ();  {
191      my $set = shift;      my $set = shift;
192      foreach (@$set) { $cnt{$_} = 1 };      my @intersection = @$set;
193    
194      my $n = 1;      foreach $set ( @_ )
195      while ($set = shift) {      {
196          $n++;          my %set = map { ( $_ => 1 ) } @$set;
197          foreach (@$set) { if ( exists $cnt{$_} ) { $cnt{$_} = $n } }  # mark          @intersection = grep { exists $set{ $_ } } @intersection;
         delete @cnt{ map { $cnt{$_} != $n ? $_ : () } keys %cnt }  # not seen?  
198      }      }
199      keys %cnt;  
200        @intersection;
201  }  }
202    
203    
# Line 222  Line 206 
206  #  #
207  #  @difference = set_difference( \@set1, \@set2 )  #  @difference = set_difference( \@set1, \@set2 )
208  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
209  sub set_difference {  sub set_difference
210    {
211      my ($set1, $set2) = @_;      my ($set1, $set2) = @_;
212      my %cnt = ();      my %set2 = map { ( $_ => 1 ) } @$set2;
213      foreach (@$set2) { $cnt{$_} = 1 };      grep { ! ( exists $set2{$_} ) } @$set1;
     map { exists $cnt{$_} ? () : $_ } @$set1;  
214  }  }
215    
216    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3