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

Diff of /Sprout/BaseSaplingLoader.pm

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

revision 1.2, Thu Feb 5 06:47:03 2009 UTC revision 1.4, Tue Jun 30 19:53:00 2009 UTC
# Line 46  Line 46 
46    
47  =item erdb  =item erdb
48    
49  [[SaplingPm]] object for the database being loaded.  L<Sapling> object for the database being loaded.
50    
51  =item source  =item source
52    
53  [[FigPm]] object used to access the source data.  L<FIG> object used to access the source data.
54    
55  =item options  =item options
56    
# Line 130  Line 130 
130      return $retVal;      return $retVal;
131  }  }
132    
133  =head3 AnalyzeSubsystemName  =head3 LoadFromFile
134    
135      my ($subsystemName, $subsystemID) = $sl->AnalyzeSubsystemName($rawSubsystemName);      $sl->LoadFromFile($tableName => $fileName, @fieldNames);
136    
137  This method will analyze the name of a subsystem, computing from it the  This method loads the specified table from the specified tab-delimited
138  display name and its ID for use in the database. The display name has  file. The list of field names indicates the order in which the fields are
139  underscores converted to spaces, and the ID is an MD5 digest.  present in the input file.
140    
141  =over 4  =over 4
142    
143  =item rawSubsystemName  =item tableName
144    
145  The raw name of the subsystem.  Name of the table to load.
146    
147  =item RETURN  =item fileName
148    
149    Name of the file containing the data for the table.
150    
151  Returns a two-element list, the first element being the subsystem's display  =item fieldNames
152  name, and the second its ID.  
153    List of the names of the fields found in the file, in the order they are
154    found in the load file.
155    
156  =back  =back
157    
158  =cut  =cut
159    
160  sub AnalyzeSubsystemName {  sub LoadFromFile {
161      # Get the parameters.      # Get the parameters.
162      my ($self, $rawSubsystemName) = @_;      my ($self, $tableName, $fileName, @fieldNames) = @_;
163      # Compute the subsystem's display name.      # Open the input file.
164      my $subsystemName = $rawSubsystemName;      my $ih = Open(undef, "<$fileName");
165      $subsystemName =~ tr/_/ /;      # We'll use this to count the number of records read.
166      # Compute the ID.      my $count = 0;
167      my $subsystemID = $self->db()->SubsystemID($rawSubsystemName);      # Loop through the file.
168      # Return the results.      while (! eof $ih) {
169      return ($subsystemName, $subsystemID);          # Get the next input record.
170            my @inFields = Tracer::GetLine($ih);
171            $self->Track(FileRecords => $fileName . " line " . ++$count, 1000);
172            # Create a map from field names to values.
173            my %map = map { $fieldNames[$_] => $inFields[$_] } 0 .. $#fieldNames;
174            # Insert it into the table.
175            $self->Put($tableName, %map);
176        }
177  }  }
178    
179    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3