[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.5, Wed Jul 15 23:39:58 2009 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 base 'BaseSaplingLoader';      use base 'BaseSaplingLoader';
31    
32  =head1 Sapling Feature Load Group Class  =head1 Sapling Feature Load Group Class
# Line 44  Line 45 
45    
46  =item erdb  =item erdb
47    
48  [[SaplingPm]] object for the database being loaded.  L<Sapling> object for the database being loaded.
49    
50  =item options  =item options
51    
# Line 64  Line 65 
65      # Create the table list.      # Create the table list.
66      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink      my @tables = sort qw(Feature FeatureEssential FeatureEvidence FeatureLink
67                           FeatureVirulent IsOwnerOf IsLocatedIn Identifies                           FeatureVirulent IsOwnerOf IsLocatedIn Identifies
68                           Identifier IsNamedBy ProteinSequence Concerns Publication);                           Identifier IsNamedBy ProteinSequence Concerns
69                             IsAttachmentSiteFor Publication IsProteinFor);
70      # Create the BaseSaplingLoader object.      # Create the BaseSaplingLoader object.
71      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);      my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
72      # Return it.      # Return it.
# Line 120  Line 122 
122      my $sapling = $self->db();      my $sapling = $self->db();
123      # Get the maximum location  segment length. We'll need this later.      # Get the maximum location  segment length. We'll need this later.
124      my $maxLength = $sapling->TuningParameter('maxLocationLength');      my $maxLength = $sapling->TuningParameter('maxLocationLength');
125        # Get the genome's aliases.
126        my $aliasDir = $sapling->LoadDirectory() . "/AliasData";
127        my $aliasHash = LoaderUtils::ReadAliasFile($aliasDir, $genomeID);
128        if (! defined $aliasHash) {
129            Trace("No aliases found for $genomeID.") if T(1);
130            $self->Add(missingAliasFile => 1);
131            $aliasHash = {};
132        }
133      # Get all of this genome's features.      # Get all of this genome's features.
134      my $featureList = $fig->all_features_detailed_fast($genomeID);      my $featureList = $fig->all_features_detailed_fast($genomeID);
135      # Loop through them.      # Loop through them.
# Line 164  Line 174 
174              $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN,              $self->PutR(IsLocatedIn => $fid, $contigID, ordinal => $locN,
175                          begin => $loc->Left(), dir => $dir, len => $loc->Length());                          begin => $loc->Left(), dir => $dir, len => $loc->Length());
176          }          }
177            # Is this an attachment site?
178            if ($type eq 'att') {
179                # Yes, connect it to the attached feature.
180                if ($assignment =~ /att([LR])\s+for\s+(fig\|.+)/) {
181                    $self->PutR(IsAttachmentSiteFor => $fid, $2, edge => $1);
182                } else {
183                    Trace("Invalid attachment function for $fid: $assignment") if T(1);
184                    $self->Add(badAttachment => 1);
185                }
186            }
187          # Emit the feature record.          # Emit the feature record.
188          $self->PutE(Feature => $fid, feature_type => $type,          $self->PutE(Feature => $fid, feature_type => $type,
189                      sequence_length => $seqLen, function => $assignment,                      sequence_length => $seqLen, function => $assignment,
# Line 194  Line 214 
214          my @essentials = $fig->get_attributes($fid, undef, ['essential', 'potential-essential']);          my @essentials = $fig->get_attributes($fid, undef, ['essential', 'potential-essential']);
215          for my $essentialTuple (@essentials) {          for my $essentialTuple (@essentials) {
216              my (undef, undef, $essentialityType, $url) = @$essentialTuple;              my (undef, undef, $essentialityType, $url) = @$essentialTuple;
217                # Only keep this datum if it has a URL. The ones without URLs are
218                # all duplicates.
219                if ($url) {
220              # Form a hyperlink from this essentiality tuple.              # Form a hyperlink from this essentiality tuple.
221              my $link = HyperLink->new($essentialityType, $url);              my $link = HyperLink->new($essentialityType, $url);
222              # Store it as essentiality data for this feature.              # Store it as essentiality data for this feature.
223              $self->PutE(FeatureEssential => $fid, essential => $link);              $self->PutE(FeatureEssential => $fid, essential => $link);
224          }          }
225            }
226          # If this is a PEG, we have a protein sequence.          # If this is a PEG, we have a protein sequence.
227            my $proteinID;
228          if ($type eq 'peg') {          if ($type eq 'peg') {
229              # Get the translation.              # Get the translation.
230              my $proteinSequence = $fig->get_translation($fid);              my $proteinSequence = $fig->get_translation($fid);
231              # Compute the ID.              # Compute the ID.
232              my $proteinID = ERDB::DigestKey($proteinSequence);              $proteinID = ERDB::DigestKey($proteinSequence);
233              # Create the protein record.              # Create the protein record.
234              $self->PutE(ProteinSequence => $proteinID, sequence => $proteinSequence);              $self->PutE(ProteinSequence => $proteinID, sequence => $proteinSequence);
235                $self->PutR(IsProteinFor => $proteinID, $fid);
236              # Get the publications for this PEG.              # Get the publications for this PEG.
237              my @pubs = $fig->get_attributes($fid, 'PUBMED_CURATED_RELEVANT');              my @pubs = $fig->get_attributes($fid, 'PUBMED_CURATED_RELEVANT');
238              for my $pub (@pubs) {              for my $pub (@pubs) {
239                  # Parse out the article title from the data.                  # Parse out the article title from the data.
240                  my (undef, undef, $data, $url) = @_;                  my (undef, undef, $data, $url) = @$pub;
241                  my @pieces = split /,/, $data, 3;                  my @pieces = split /,/, $data, 3;
242                  if (defined $pieces[2]) {                  if (defined $pieces[2]) {
243                      # Create the publication record.                      # Create the publication record.
244                      my $hl = Hyperlink->new($pieces[2], $url);                      my $hl = HyperLink->new($pieces[2], $url);
245                      my $key = ERDB::DigestKey($url);                      my $key = ERDB::DigestKey($url);
246                      $self->PutE(Publication => $key, citation => $hl);                      $self->PutE(Publication => $key, citation => $hl);
247                      # Connect it to the protein.                      # Connect it to the protein.
# Line 223  Line 249 
249                  }                  }
250              }              }
251          }          }
252          # Now we need to compute the identifiers. We start with the aliases          # Now we need to compute the identifiers. We start with the aliases.
253          # 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
254          # in the keyword list, so we'll put all aliases found in this hash.          # empty list.
255          my %aliasHash;          my $aliasList = $aliasHash->{$fid} || [];
256          # Loop through the aliases, recording the normal and natural forms/          # Loop through the aliases found.
257          for my $alias (split /,/, $aliases) {          for my $aliasTuple (@$aliasList) {
258              # Compute the alias type.              my ($aliasID, $aliasType, $aliasConf) = @$aliasTuple;
259              my $aliasType = AliasAnalysis::TypeOf($alias);              # Get the natural form. If there is none, then the canonical
260              # Is this alias a known type?              # form IS the natural form.
261              if (! defined $aliasType) {              my $natural = AliasAnalysis::Type($aliasType => $aliasID) || $aliasID;
262                  # Check to see if it's a locus tag.              # Create the identifier record.
263                  if ($alias =~ /^[A-Z]{3}\d+$/) {              $self->PutE(Identifier => $aliasID, natural_form => $natural,
264                      # It is, so convert it to internal form.                          source => $aliasType);
265                      my $normalized = AliasAnalysis::Normalize(LocusTag => $alias);              # Is this a protein alias?
266                      $aliasHash{$normalized} = 'LocusTag';              if ($aliasConf eq 'C' && $proteinID) {
267                    # Yes. Connect it using IsNamedBy.
268                    $self->PutR(IsNamedBy => $proteinID, $aliasID);
269                  } else {                  } else {
270                      # Here it's a complete mystery. If we haven't seen it yet,                  # No. Connect it to the feature.
271                      # mark it as being an unknown type.                  $self->PutR(Identifies => $aliasID, $fid, conf => $aliasConf);
                     if (! exists $aliasHash{$alias}) {  
                         $aliasHash{$alias} = "";  
272                      }                      }
273                  }                  }
274              } else {          # Finally, this feature is an alias of itself.
275                  # Here we have a known type.          $self->PutE(Identifier => $fid, natural_form => $fid,
276                  $aliasHash{$alias} = $aliasType;                      source => 'SEED');
277              }          $self->PutR(Identifies => $fid, $fid, conf => 'A');
278          }          if ($proteinID) {
279          # Add the corresponding IDs. We ask for 2-tuples of the form (id, database).              $self->PutR(IsNamedBy => $proteinID, $fid);
         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';  
             } else {  
                 # Here we have a known type.  
                 $naturalForm = AliasAnalysis::Type($type => $alias);  
             }  
             # Create the identifier and connect it to the feature.  
             $self->PutE(Identifier => $alias, source => $type,  
                         natural_form => $naturalForm);  
             $self->PutR(Identifies => $alias, $fid);  
280          }          }
281      }      }
282  }  }

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3