[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.2, Mon Mar 2 22:22:11 2009 UTC revision 1.9, Mon Feb 1 20:14:28 2010 UTC
# Line 26  Line 26 
26      use BasicLocation;      use BasicLocation;
27      use HyperLink;      use HyperLink;
28      use AliasAnalysis;      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 44  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 64  Line 67 
67      # Create the table list.      # Create the table list.
68      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink
69                           FeatureVirulent IsOwnerOf IsLocatedIn Identifies                           FeatureVirulent IsOwnerOf IsLocatedIn Identifies
70                           Identifier IsNamedBy ProteinSequence Concerns Publication);                           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 86  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 120  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        # Get the genome's aliases.
145        my $aliasDir = $sapling->LoadDirectory() . "/AliasData";
146        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 128  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 164  Line 197 
197              $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN,              $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN,
198                          begin => $loc->Left(), dir => $dir, len => $loc->Length());                          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));                      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.
# Line 223  Line 295 
295                  }                  }
296              }              }
297          }          }
298          # Now we need to compute the identifiers. We start with the aliases          # Now we need to compute the identifiers. We start with the aliases.
299          # We need to insure we don't put multiple copies of the same alias          # Get the alias data for this feature. If there is none, we force an
300          # in the keyword list, so we'll put all aliases found in this hash.          # empty list.
301          my %aliasHash;          my $aliasList = $aliasHash->{$fid} || [];
302          # Loop through the aliases, recording the normal and natural forms/          # Loop through the aliases found.
303          for my $alias (split /,/, $aliases) {          for my $aliasTuple (@$aliasList) {
304              # Compute the alias type.              my ($aliasID, $aliasType, $aliasConf) = @$aliasTuple;
305              my $aliasType = AliasAnalysis::TypeOf($alias);              # Get the natural form. If there is none, then the canonical
306              # Is this alias a known type?              # form IS the natural form.
307              if (! defined $aliasType) {              my $natural = AliasAnalysis::Type($aliasType => $aliasID) || $aliasID;
308                  # Check to see if it's a locus tag.              # Create the identifier record.
309                  if ($alias =~ /^[A-Z]{3}\d+$/) {              $self->PutE(Identifier => $aliasID, natural_form => $natural,
310                      # It is, so convert it to internal form.                          source => $aliasType);
311                      my $normalized = AliasAnalysis::Normalize(LocusTag => $alias);              # Is this a protein alias?
312                      $aliasHash{$normalized} = 'LocusTag';              if ($aliasConf eq 'C' && $proteinID) {
313                  } else {                  # Yes. Connect it using IsNamedBy.
314                      # Here it's a complete mystery. If we haven't seen it yet,                  $self->PutR(IsNamedBy => $proteinID, $aliasID);
                     # mark it as being an unknown type.  
                     if (! exists $aliasHash{$alias}) {  
                         $aliasHash{$alias} = "";  
                     }  
                 }  
             } else {  
                 # Here we have a known type.  
                 $aliasHash{$alias} = $aliasType;  
             }  
         }  
         # Add the corresponding IDs. We ask for 2-tuples of the form (id, database).  
         my @corresponders = $fig->get_corresponding_ids($fid, 1);  
         for my $tuple (@corresponders) {  
             my ($id, $xdb) = @{$tuple};  
             # Ignore SEED: that's us. Also ignore contig IDs. Those result from a bug  
             # at PIR.  
             if ($xdb ne 'SEED' && ! ($xdb eq 'RefSeq' && $id =~ /^[A-Z][A-Z]_\d+$/)) {  
                 # Compute the ID's normalized form.  
                 my $normalized = AliasAnalysis::Normalize($xdb => $id);  
                 # Add it to the alias hash.  
                 $aliasHash{$normalized} = $xdb;  
             }  
         }  
         # Convert the aliases to feature identifiers.  
         for my $alias (keys %aliasHash) {  
             # Compute the identifier's natural form and the real type.  
             my $type = $aliasHash{$alias};  
             my $naturalForm;  
             if (! $type) {  
                 # Here we have an unknown type. The natural form is the same  
                 # as the internal form.  
                 $naturalForm = $alias;  
                 $type = 'Miscellaneous';  
315              } else {              } else {
316                  # Here we have a known type.                  # No. Connect it to the feature.
317                  $naturalForm = AliasAnalysis::Type($type => $alias);                  $self->PutR(Identifies => $aliasID, $fid, conf => $aliasConf);
318              }              }
             # Create the identifier and connect it to the feature.  
             $self->PutE(Identifier => $alias, source => $type,  
                         natural_form => $naturalForm);  
             $self->PutR(Identifies => $alias, $fid);  
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.2  
changed lines
  Added in v.1.9

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3