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

Diff of /Sprout/BaseSproutLoader.pm

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

revision 1.1, Tue Sep 30 15:23:55 2008 UTC revision 1.3, Thu Oct 2 16:32:42 2008 UTC
# Line 22  Line 22 
22      use strict;      use strict;
23      use Tracer;      use Tracer;
24      use ERDB;      use ERDB;
25        use Time::HiRes;
26      use base 'ERDBLoadGroup';      use base 'ERDBLoadGroup';
27    
28      # Name of the global section      # Name of the global section
# Line 65  Line 66 
66  sub new {  sub new {
67      # Get the parameters.      # Get the parameters.
68      my ($class, $erdb, $source, $options, @tables) = @_;      my ($class, $erdb, $source, $options, @tables) = @_;
69      # Create the BaseSproutLoader object.      # Create the base load group object.
70      my $retVal = ERDBLoadGroup::new($class, $source, $erdb, $erdb->LoadDirectory(),      my $retVal = ERDBLoadGroup::new($class, $source, $erdb, $options, @tables);
71                                      $options, @tables);      # Return it.
     # Bless and return it.  
     bless $retVal, $class;  
72      return $retVal;      return $retVal;
73  }  }
74    
# Line 78  Line 77 
77    
78  =head3 GetGenomeAttributes  =head3 GetGenomeAttributes
79    
80      my $aHashRef = $sl->GetGenomeAttributes($genomeID);      my $aHashRef = $sl->GetGenomeAttributes($genomeID, \@fids);
81    
82  Return a hash of attributes keyed on feature ID. This method gets all the NMPDR-related  Return a hash of attributes keyed on feature ID. This method gets all the NMPDR-related
83  attributes for all the features of a genome in a single call, then organizes them into  attributes for all the features of a genome in a single call, then organizes them into
# Line 96  Line 95 
95    
96  =item fids  =item fids
97    
98  Reference to a list of the feature IDs whose attributes are to be kept.  Reference to a list of feature IDs whose attributes are to be kept. If it is a list
99    of lists, the feature IDs will be taken from the first element in each sub-list.
 =item propKeys  
   
 A list of the keys to retrieve.  
100    
101  =item RETURN  =item RETURN
102    
# Line 114  Line 110 
110    
111  sub GetGenomeAttributes {  sub GetGenomeAttributes {
112      # Get the parameters.      # Get the parameters.
113      my ($self, $genomeID) = @_;      my ($self, $genomeID, $fids) = @_;
114      # Declare the return variable.      # Start a timer.
115      my $retVal = {};      my $start = time();
116        # Declare the return variable and initialize it with all the features.
117        my %retVal = map { (ref $_ ? $_->[0] : $_) => [] } @$fids;
118      # Get the source object.      # Get the source object.
119      my $fig = $self->source();      my $fig = $self->source();
     # Get the features for this genome.  
     my @fids = $fig->all_features($genomeID);  
     # Initialize the hash. This not only enables us to easily determine which FIDs to  
     # keep, it insures that the caller sees a list reference for every known fid,  
     # simplifying the logic.  
     for my $fid (@fids) {  
         $retVal->{$fid} = [];  
     }  
     # Get the list of NMPDR-related attributes.  
     my @propKeys = $fig->get_group_keys("NMPDR");  
120      # Get the attributes. If ev_code_cron is running, we may get a timeout error, so      # Get the attributes. If ev_code_cron is running, we may get a timeout error, so
121      # an eval is used.      # an eval is used.
122      my @aList = ();      my @aList = ();
123      eval {      eval {
124          @aList = $fig->get_attributes("fig|$genomeID%", \@propKeys);          @aList = $fig->get_attributes("fig|$genomeID%");
125          Trace(scalar(@aList) . " attributes returned for genome $genomeID.") if T(ERDBLoadGroup => 3);          Trace(scalar(@aList) . " attributes returned for genome $genomeID.") if T(ERDBLoadGroup => 3);
126      };      };
127      # Check for a problem.      # Check for a problem.
# Line 141  Line 129 
129          Trace("Retrying attributes for $genomeID due to error: $@") if T(ERDBLoadGroup => 1);          Trace("Retrying attributes for $genomeID due to error: $@") if T(ERDBLoadGroup => 1);
130          # Our fallback plan is to process the attributes in blocks of 100. This is much slower,          # Our fallback plan is to process the attributes in blocks of 100. This is much slower,
131          # but allows us to continue processing.          # but allows us to continue processing.
132          my $nFids = scalar @fids;          my $nFids = scalar @$fids;
133          for (my $i = 0; $i < $nFids; $i += 100) {          for (my $i = 0; $i < $nFids; $i += 100) {
134              # Determine the index of the last feature ID we'll be specifying on this pass.              # Determine the index of the last feature ID we'll be specifying on this pass.
135              # Normally it's $i + 99, but if we're close to the end it may be less.              # Normally it's $i + 99, but if we're close to the end it may be less.
136              my $end = ($i + 100 > $nFids ? $nFids - 1 : $i + 99);              my $end = ($i + 100 > $nFids ? $nFids - 1 : $i + 99);
137              # Get a slice of the fid list.              # Get a slice of the fid list.
138              my @slice = @fids[$i .. $end];              my @slice = @{$fids}[$i .. $end];
139              # Get the relevant attributes.              # Get the relevant attributes.
140              Trace("Retrieving attributes for fids $i to $end.") if T(ERDBLoadGroup => 3);              Trace("Retrieving attributes for fids $i to $end.") if T(ERDBLoadGroup => 3);
141              my @aShort = $fig->get_attributes(\@slice, \@propKeys);              my @aShort = $fig->get_attributes(\@slice);
142              Trace(scalar(@aShort) . " attributes returned for fids $i to $end.") if T(ERDBLoadGroup => 3);              Trace(scalar(@aShort) . " attributes returned for fids $i to $end.") if T(ERDBLoadGroup => 3);
143              push @aList, @aShort;              push @aList, @aShort;
144          }          }
# Line 159  Line 147 
147      # them.      # them.
148      for my $aListEntry (@aList) {      for my $aListEntry (@aList) {
149          my $fid = $aListEntry->[0];          my $fid = $aListEntry->[0];
150          if (exists $retVal->{$fid}) {          if (exists $retVal{$fid}) {
151              push @{$retVal->{$fid}}, $aListEntry;              push @{$retVal{$fid}}, $aListEntry;
152                $self->Add(attributes => 1);
153          }          }
154      }      }
155        $self->Add('attribute-time' => time() - $start);
156      # Return the result.      # Return the result.
157      return $retVal;      return \%retVal;
158  }  }
159    
160  =head3 GetSubsystems  =head3 GetSubsystems

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3