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

Diff of /Sprout/FeatureSaplingLoader.pm

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

revision 1.1, Mon Jan 19 21:43:27 2009 UTC revision 1.9, Mon Feb 1 20:14:28 2010 UTC
# Line 25  Line 25 
25      use CGI qw(-nosticky);      use CGI qw(-nosticky);
26      use BasicLocation;      use BasicLocation;
27      use HyperLink;      use HyperLink;
28        use AliasAnalysis;
29        use LoaderUtils;
30        use Digest::MD5;
31        use SeedUtils;
32      use base 'BaseSaplingLoader';      use base 'BaseSaplingLoader';
33    
34  =head1 Sapling Feature Load Group Class  =head1 Sapling Feature Load Group Class
# Line 43  Line 47 
47    
48  =item erdb  =item erdb
49    
50  [[SaplingPm]] object for the database being loaded.  L<Sapling> object for the database being loaded.
51    
52  =item options  =item options
53    
# Line 61  Line 65 
65      # Get the parameters.      # Get the parameters.
66      my ($class, $erdb, $options) = @_;      my ($class, $erdb, $options) = @_;
67      # Create the table list.      # Create the table list.
68      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink FeatureVirulent      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink
69                          Identifier IsSequenceFor ProteinSequence Concerns Publication                           FeatureVirulent IsOwnerOf IsLocatedIn Identifies
70                          IdentifierSet IncludesIdentifier IsLocatedIn IsOwnerOf);                           Identifier IsNamedBy ProteinSequence Concerns
71                             IsAttachmentSiteFor Publication IsProteinFor
72                             Role IsFunctionalIn);
73      # Create the BaseSaplingLoader object.      # Create the BaseSaplingLoader object.
74      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
75      # Return it.      # Return it.
# Line 85  Line 91 
91      my ($self) = @_;      my ($self) = @_;
92      # Get the database object.      # Get the database object.
93      my $erdb = $self->db();      my $erdb = $self->db();
94      # Only proceed if this is a normal section. There's no global feature data.      # Check for local or global.
95      if (! $self->global()) {      if (! $self->global()) {
96          # Get the section ID.          # Here we are generating data for a genome.
97          my $genomeID = $self->section();          my $genomeID = $self->section();
98          # Load this genome's features.          # Load this genome's features.
99          $self->LoadGenomeFeatures($genomeID);          $self->LoadGenomeFeatures($genomeID);
100        } else {
101            # The global data is the roles from subsystems.
102            my $fig = $self->source();
103            # First, we get the subsystem list.
104            my $subHash = $erdb->SubsystemHash();
105            for my $sub (sort keys %$subHash) {
106                $self->Add(subsystems => 1);
107                Trace("Processing roles for $sub.") if T(3);
108                # Get this subsystem's roles and write them out.
109                my @roles = $fig->subsystem_to_roles($sub);
110                for my $role (@roles) {
111                    $self->Add(subsystemRoles => 1);
112                    $self->PutE(Role => $role, hypothetical => hypo($role));
113                }
114            }
115            Trace("Subsystem roles generated.") if T(3);
116      }      }
117  }  }
118    
# Line 119  Line 141 
141      my $sapling = $self->db();      my $sapling = $self->db();
142      # Get the maximum location  segment length. We'll need this later.      # Get the maximum location  segment length. We'll need this later.
143      my $maxLength = $sapling->TuningParameter('maxLocationLength');      my $maxLength = $sapling->TuningParameter('maxLocationLength');
144      # This hash will be used to track identifiers. Each identifier can only      # Get the genome's aliases.
145      # be used once.      my $aliasDir = $sapling->LoadDirectory() . "/AliasData";
146      my %identifiers;      my $aliasHash = LoaderUtils::ReadAliasFile($aliasDir, $genomeID);
147        if (! defined $aliasHash) {
148            Trace("No aliases found for $genomeID.") if T(ERDBLoadGroup => 1);
149            $self->Add(missingAliasFile => 1);
150            $aliasHash = {};
151        }
152      # Get all of this genome's features.      # Get all of this genome's features.
153      my $featureList = $fig->all_features_detailed_fast($genomeID);      my $featureList = $fig->all_features_detailed_fast($genomeID);
154      # Loop through them.      # Loop through them.
# Line 130  Line 157 
157          my ($fid, $locationString, $aliases, $type, undef, undef, $assignment,          my ($fid, $locationString, $aliases, $type, undef, undef, $assignment,
158              $assignmentMaker, $quality) = @$feature;              $assignmentMaker, $quality) = @$feature;
159          $self->Track(Features => $fid, 1000);          $self->Track(Features => $fid, 1000);
160          # Fix the assignment for non-PEG features.          # Fix missing assignments. For RNAs, the assignment may be in the alias list.
161          if (! defined $assignment) {          if (! defined $assignment) {
162                if ($type eq 'rna') {
163              $assignment = $aliases;              $assignment = $aliases;
164              $assignmentMaker ||= 'master';              $assignmentMaker ||= 'master';
165                } else {
166                    $assignment = '';
167                }
168          }          }
169          # Convert the location string to a list of location objects.          # Convert the location string to a list of location objects.
170          my @locs = map { BasicLocation->new($_) } split /\s*,\s*/, $locationString;          my @locs = map { BasicLocation->new($_) } split /\s*,\s*/, $locationString;
# Line 156  Line 187 
187              # to the feature.              # to the feature.
188              my $peel = $loc->Peel($maxLength);              my $peel = $loc->Peel($maxLength);
189              while (defined $peel) {              while (defined $peel) {
190                  $self->PutR(IsLocatedIn => $fid, $contigID, beg => $peel->Left(),                  $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN++,
191                              dir => $dir, len => $maxLength, locN => $locN++);                              begin => $peel->Left(), len => $peel->Length(),
192                                dir => $dir);
193                  $peel = $loc->Peel($maxLength);                  $peel = $loc->Peel($maxLength);
194              }              }
195              # Output the residual. There will always be one, because of the way              # Output the residual. There will always be one, because of the way
196              # Peel works.              # Peel works.
197              $self->PutR(IsLocatedIn => $fid, $contigID, beg => $loc->Left(),              $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN,
198                          dir => $dir, len => $loc->Length(), locN => $locN);                          begin => $loc->Left(), dir => $dir, len => $loc->Length());
199            }
200            # Is this an attachment site?
201            if ($type eq 'att') {
202                # Yes, connect it to the attached feature.
203                if ($assignment =~ /att([LR])\s+for\s+(fig\|.+)/) {
204                    $self->PutR(IsAttachmentSiteFor => $fid, $2, edge => $1);
205                } else {
206                    Trace("Invalid attachment function for $fid: $assignment") if T(ERDBLoadGroup => 1);
207                    $self->Add(badAttachment => 1);
208                }
209          }          }
210          # Emit the feature record.          # Emit the feature record.
211          $self->PutE(Feature => $fid, feature_type => $type,          $self->PutE(Feature => $fid, feature_type => $type,
212                      sequence_length => $seqLen, function => $assignment);                      sequence_length => $seqLen, function => $assignment,
213                        locked => $fig->is_locked_fid($fid));
214          # Connect the feature to its genome.          # Connect the feature to its genome.
215          $self->PutR(IsOwnerOf => $genomeID, $fid);          $self->PutR(IsOwnerOf => $genomeID, $fid);
216            # Connect the feature to its roles.
217            my ($roles, $errors) = LoaderUtils::RolesForLoading($assignment);
218            if (! defined $roles) {
219                # Here the functional assignment was suspicious.
220                $self->Add(suspiciousFunction => 1);
221                Trace("$fid has a suspicious function: $assignment") if T(ERDBLoadGroup => 1);
222            } else {
223                # Here we have a good assignment.
224                for my $role (@$roles) {
225                    $self->Add(featureRole => 1);
226                    $self->PutR(IsFunctionalIn => $role, $fid);
227                    $self->PutE(Role => $role, hypothetical => hypo($role));
228                }
229                $self->Add(badFeatureRoles => $errors);
230            }
231          # Now we have a whole bunch of attribute-related stuff to store in          # Now we have a whole bunch of attribute-related stuff to store in
232          # secondary Feature tables. First is the evidence codes.          # secondary Feature tables. First is the evidence codes.
233          my @evidenceTuples = $fig->get_attributes($fid, 'evidence_code');          my @evidenceTuples = $fig->get_attributes($fid, 'evidence_code');
# Line 194  Line 252 
252          my @essentials = $fig->get_attributes($fid, undef, ['essential', 'potential-essential']);          my @essentials = $fig->get_attributes($fid, undef, ['essential', 'potential-essential']);
253          for my $essentialTuple (@essentials) {          for my $essentialTuple (@essentials) {
254              my (undef, undef, $essentialityType, $url) = @$essentialTuple;              my (undef, undef, $essentialityType, $url) = @$essentialTuple;
255                # Only keep this datum if it has a URL. The ones without URLs are
256                # all duplicates.
257                if ($url) {
258              # Form a hyperlink from this essentiality tuple.              # Form a hyperlink from this essentiality tuple.
259              my $link = HyperLink->new($essentialityType, $url);              my $link = HyperLink->new($essentialityType, $url);
260              # Store it as essentiality data for this feature.              # Store it as essentiality data for this feature.
261              $self->PutE(FeatureEssential => $fid, essential => $link);              $self->PutE(FeatureEssential => $fid, essential => $link);
262          }          }
263            }
264          # If this is a PEG, we have a protein sequence.          # If this is a PEG, we have a protein sequence.
265            my $proteinID;
266          if ($type eq 'peg') {          if ($type eq 'peg') {
267              # Get the translation.              # Get the translation.
268              my $proteinSequence = $fig->get_translation($fid);              my $proteinSequence = $fig->get_translation($fid);
269                if (! $proteinSequence) {
270                    Trace("No protein sequence found for $fid.") if T(2);
271                    $self->Add(missingProtein => 1);
272                    # Here there was some sort of error and the protein sequence did
273                    # not come back. Ask for the DNA and translate it instead.
274                    my $dna = $fig->get_dna_seq($fid);
275                    $proteinSequence = FIG::translate($dna, undef, 1);
276                }
277              # Compute the ID.              # Compute the ID.
278              my $proteinID = ERDB::DigestKey($proteinSequence);              $proteinID = $sapling->ProteinID($proteinSequence);
279              # Create the protein record.              # Create the protein record.
280              $self->PutE(ProteinSequence => $proteinID, sequence => $proteinSequence);              $self->PutE(ProteinSequence => $proteinID, sequence => $proteinSequence);
281                $self->PutR(IsProteinFor => $proteinID, $fid);
282              # Get the publications for this PEG.              # Get the publications for this PEG.
283              my @pubs = $fig->get_attributes($fid, 'PUBMED_CURATED_RELEVANT');              my @pubs = $fig->get_attributes($fid, 'PUBMED_CURATED_RELEVANT');
284              for my $pub (@pubs) {              for my $pub (@pubs) {
285                  # Parse out the article title from the data.                  # Parse out the article title from the data.
286                  my (undef, undef, $data, $url) = @_;                  my (undef, undef, $data, $url) = @$pub;
287                  my @pieces = split /,/, $data, 3;                  my @pieces = split /,/, $data, 3;
288                  if (defined $pieces[2]) {                  if (defined $pieces[2]) {
289                      # Create the publication record.                      # Create the publication record.
290                      my $hl = Hyperlink->new($pieces[2], $url);                      my $hl = HyperLink->new($pieces[2], $url);
291                      my $key = ERDB::DigestKey($url);                      my $key = ERDB::DigestKey($url);
292                      $self->PutE(Publication => $key, citation => $hl);                      $self->PutE(Publication => $key, citation => $hl);
293                      # Connect it to the protein.                      # Connect it to the protein.
294                      $self->PutR(Concerns => $key, $proteinID);                      $self->PutR(Concerns => $key, $proteinID);
295                  }                  }
296              }              }
             # Now we need to get the identifiers for this feature and put  
             # them in the protein's identifier set. The "1" tells FigPm to  
             # send back the database name with each identifier. Note that  
             # the FIG ID will come back with this list, but there may not be  
             # a list if the genome is new.  
             my @idTuples = grep { $_->[0] !~ /^[A-Z][A-Z]_\d+$/ } $fig->get_corresponding_ids($fid, 1); ##HACK: grep out the contig IDs  
             if (! @idTuples) {  
                 push @idTuples, [$fid, 'SEED'];  
             }  
             # Compute the identifier set name and create the set.  
             my $setID = "$proteinID:$genomeID";  
             $self->PutE(IdentifierSet => $setID);  
             # Create the identifiers and onnect them to the protein and  
             # the set.  
             for my $idTuple (@idTuples) {  
                 my ($id, $source) = @$idTuple;  
                 # Only process this identifier if it's new. An identifier  
                 # can only be in one identifier set. Thankfully, the  
                 # identifiers belong to genomes, so we don't need to worry  
                 # about duplicates in other sections.  
                 if (exists $identifiers{$id} && $identifiers{$id} ne $proteinID) {  
                     $self->Add(ambiguousProtein => 1);  
                 } else {  
                     $self->PutE(Identifier => $id, source => $source);  
                     $self->PutR(IsSequenceFor => $proteinID, $id);  
                     $self->PutR(IncludesIdentifier => $setID, $id);  
                     $identifiers{$id} = $proteinID;  
297                  }                  }
298            # Now we need to compute the identifiers. We start with the aliases.
299            # Get the alias data for this feature. If there is none, we force an
300            # empty list.
301            my $aliasList = $aliasHash->{$fid} || [];
302            # Loop through the aliases found.
303            for my $aliasTuple (@$aliasList) {
304                my ($aliasID, $aliasType, $aliasConf) = @$aliasTuple;
305                # Get the natural form. If there is none, then the canonical
306                # form IS the natural form.
307                my $natural = AliasAnalysis::Type($aliasType => $aliasID) || $aliasID;
308                # Create the identifier record.
309                $self->PutE(Identifier => $aliasID, natural_form => $natural,
310                            source => $aliasType);
311                # Is this a protein alias?
312                if ($aliasConf eq 'C' && $proteinID) {
313                    # Yes. Connect it using IsNamedBy.
314                    $self->PutR(IsNamedBy => $proteinID, $aliasID);
315                } else {
316                    # No. Connect it to the feature.
317                    $self->PutR(Identifies => $aliasID, $fid, conf => $aliasConf);
318              }              }
319          }          }
320            # Finally, this feature is an alias of itself.
321            $self->PutE(Identifier => $fid, natural_form => $fid,
322                        source => 'SEED');
323            $self->PutR(Identifies => $fid, $fid, conf => 'A');
324      }      }
325  }  }
326    

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3