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

Annotation of /Sprout/PropertySproutLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     #
4 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
5 :     # for Interpretations of Genomes. All Rights Reserved.
6 :     #
7 :     # This file is part of the SEED Toolkit.
8 :     #
9 :     # The SEED Toolkit is free software. You can redistribute
10 :     # it and/or modify it under the terms of the SEED Toolkit
11 :     # Public License.
12 :     #
13 :     # You should have received a copy of the SEED Toolkit Public License
14 :     # along with this program; if not write to the University of Chicago
15 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
16 :     # Genomes at veronika@thefig.info or download a copy from
17 :     # http://www.theseed.org/LICENSE.TXT.
18 :     #
19 :    
20 :     package PropertySproutLoader;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use base 'BaseSproutLoader';
26 :    
27 :     =head1 Sprout Property Load Group Class
28 :    
29 :     =head2 Introduction
30 :    
31 :     The Load Group includes all of the major searchable attribute tables.
32 :    
33 :     =head3 new
34 :    
35 :     my $sl = SproutLoader->new($erdb, $source, $options, @tables);
36 :    
37 :     Construct a new SproutLoader object.
38 :    
39 :     =over 4
40 :    
41 :     =item erdb
42 :    
43 :     [[SproutPm]] object for the database being loaded.
44 :    
45 :     =item options
46 :    
47 :     Reference to a hash of command-line options.
48 :    
49 :     =item tables
50 :    
51 :     List of tables in this load group.
52 :    
53 :     =back
54 :    
55 :     =cut
56 :    
57 :     sub new {
58 :     # Get the parameters.
59 : parrello 1.2 my ($class, $erdb, $options) = @_;
60 : parrello 1.1 # Create the table list.
61 :     my @tables = sort qw(Property HasProperty);
62 :     # Create the BaseSproutLoader object.
63 : parrello 1.2 my $retVal = BaseSproutLoader::new($class, $erdb, $options, @tables);
64 : parrello 1.1 # Return it.
65 :     return $retVal;
66 :     }
67 :    
68 :     =head2 Public Methods
69 :    
70 :     =head3 Generate
71 :    
72 :     $sl->Generate();
73 :    
74 :     Generate the data for the searchable attribute files.
75 :    
76 :     =cut
77 :    
78 :     sub Generate {
79 :     # Get the parameters.
80 :     my ($self) = @_;
81 :     # Get the sprout object.
82 :     my $sprout = $self->db();
83 :     # Get the FIG object.
84 :     my $fig = $self->source();
85 :     # All of the property stuff is done globally.
86 :     if ($self->global()) {
87 : parrello 1.2 # Get the list of attributes we need for these searches. Currently, it's
88 :     # essentials and PFAM.
89 : parrello 1.1 my @keys = $fig->get_group_keys('essential');
90 : parrello 1.2 push @keys, 'PFAM';
91 : parrello 1.1 # Get a hash of genome IDs.
92 : parrello 1.2 my %genomes = map { $_ => 1 } BaseSproutLoader::GetSectionList($sprout, $fig);
93 : parrello 1.1 # This will be where we compute the property IDs.
94 :     my %propIDs = ();
95 :     my $nextID = 1;
96 :     # Loop through these keys, getting feature IDs.
97 :     for my $key (@keys) {
98 :     # Get all the attributes for this key.
99 : parrello 1.2 $self->Track(keys => $key, 10);
100 : parrello 1.1 my @attributes = $fig->get_attributes(undef, $key);
101 :     Trace(scalar(@attributes) . " attribute values found for $key.") if T(3);
102 :     $self->Add('attribute-keys' => 1);
103 :     # Loop through them, extracting the ones for genomes in the genome hash.
104 :     for my $attributeTuple (@attributes) {
105 :     # Extract the pieces.
106 :     my ($pegID, $key, $value, $url) = @{$attributeTuple};
107 :     # Default the URL to an empty string.
108 :     $url = "" if ! defined $url;
109 :     # Only proceed if the peg ID is valid and for a known genome.
110 : parrello 1.2 if ($pegID =~ /^fig\|(\d+\.\d+)/ && $genomes{$1}) {
111 : parrello 1.1 # It is. Compute the property ID.
112 :     my $propertyKeyValue = "$key::$value";
113 :     my $propID = $propIDs{$propertyKeyValue};
114 :     if (! defined $propID) {
115 :     # Here we have a new key/value pair, so it gets a new ID number.
116 :     $self->Add('attribute-pairs' => 1);
117 :     $propID = $nextID++;
118 :     $propIDs{$propertyKeyValue} = $propID;
119 :     # Add this ID to the property table.
120 :     $self->PutE(Property => $propID, 'property-name' => $key, 'property-value' => $value);
121 :     }
122 :     # Connect the feature to the property.
123 :     $self->PutR(HasProperty => $pegID, $propID, evidence => $url);
124 :     $self->Add('attributes-kept' => 1);
125 :     } else {
126 :     # The object isn't a feature, or it isn't for an NMPDR genome, so we skip it.
127 :     $self->Add('attributes-skipped' => 1);
128 :     }
129 :     }
130 :     }
131 :     }
132 :     }
133 :    
134 :    
135 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3