[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.2, Wed Oct 1 03:07:08 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 68  Line 69 
69      # Create the BaseSproutLoader object.      # Create the BaseSproutLoader object.
70      my $retVal = ERDBLoadGroup::new($class, $source, $erdb, $erdb->LoadDirectory(),      my $retVal = ERDBLoadGroup::new($class, $source, $erdb, $erdb->LoadDirectory(),
71                                      $options, @tables);                                      $options, @tables);
72      # Bless and return it.      # Return it.
     bless $retVal, $class;  
73      return $retVal;      return $retVal;
74  }  }
75    
# Line 78  Line 78 
78    
79  =head3 GetGenomeAttributes  =head3 GetGenomeAttributes
80    
81      my $aHashRef = $sl->GetGenomeAttributes($genomeID);      my $aHashRef = $sl->GetGenomeAttributes($genomeID, \@fids);
82    
83  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
84  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 96 
96    
97  =item fids  =item fids
98    
99  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
100    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.  
101    
102  =item RETURN  =item RETURN
103    
# Line 114  Line 111 
111    
112  sub GetGenomeAttributes {  sub GetGenomeAttributes {
113      # Get the parameters.      # Get the parameters.
114      my ($self, $genomeID) = @_;      my ($self, $genomeID, $fids) = @_;
115      # Declare the return variable.      # Start a timer.
116      my $retVal = {};      my $start = time();
117        # Declare the return variable and initialize it with all the features.
118        my %retVal = map { (ref $_ ? $_->[0] : $_) => [] } @$fids;
119      # Get the source object.      # Get the source object.
120      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");  
121      # 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
122      # an eval is used.      # an eval is used.
123      my @aList = ();      my @aList = ();
124      eval {      eval {
125          @aList = $fig->get_attributes("fig|$genomeID%", \@propKeys);          @aList = $fig->get_attributes("fig|$genomeID%");
126          Trace(scalar(@aList) . " attributes returned for genome $genomeID.") if T(ERDBLoadGroup => 3);          Trace(scalar(@aList) . " attributes returned for genome $genomeID.") if T(ERDBLoadGroup => 3);
127      };      };
128      # Check for a problem.      # Check for a problem.
# Line 141  Line 130 
130          Trace("Retrying attributes for $genomeID due to error: $@") if T(ERDBLoadGroup => 1);          Trace("Retrying attributes for $genomeID due to error: $@") if T(ERDBLoadGroup => 1);
131          # 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,
132          # but allows us to continue processing.          # but allows us to continue processing.
133          my $nFids = scalar @fids;          my $nFids = scalar @$fids;
134          for (my $i = 0; $i < $nFids; $i += 100) {          for (my $i = 0; $i < $nFids; $i += 100) {
135              # 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.
136              # 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.
137              my $end = ($i + 100 > $nFids ? $nFids - 1 : $i + 99);              my $end = ($i + 100 > $nFids ? $nFids - 1 : $i + 99);
138              # Get a slice of the fid list.              # Get a slice of the fid list.
139              my @slice = @fids[$i .. $end];              my @slice = @{$fids}[$i .. $end];
140              # Get the relevant attributes.              # Get the relevant attributes.
141              Trace("Retrieving attributes for fids $i to $end.") if T(ERDBLoadGroup => 3);              Trace("Retrieving attributes for fids $i to $end.") if T(ERDBLoadGroup => 3);
142              my @aShort = $fig->get_attributes(\@slice, \@propKeys);              my @aShort = $fig->get_attributes(\@slice);
143              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);
144              push @aList, @aShort;              push @aList, @aShort;
145          }          }
# Line 159  Line 148 
148      # them.      # them.
149      for my $aListEntry (@aList) {      for my $aListEntry (@aList) {
150          my $fid = $aListEntry->[0];          my $fid = $aListEntry->[0];
151          if (exists $retVal->{$fid}) {          if (exists $retVal{$fid}) {
152              push @{$retVal->{$fid}}, $aListEntry;              push @{$retVal{$fid}}, $aListEntry;
153                $self->Add(attributes => 1);
154          }          }
155      }      }
156        $self->Add('attribute-time' => time() - $start);
157      # Return the result.      # Return the result.
158      return $retVal;      return \%retVal;
159  }  }
160    
161  =head3 GetSubsystems  =head3 GetSubsystems

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3