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

Annotation of /Sprout/AnnotationSproutLoader.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (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 AnnotationSproutLoader;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use base 'BaseSproutLoader';
26 :    
27 :     =head1 Sprout Annotation Load Group Class
28 :    
29 :     =head2 Introduction
30 :    
31 :     The Load Group includes all of the major annotation data 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 source
46 :    
47 :     [[FigPm]] object used to access the source data. If this parameter is undefined,
48 :     it will be created the first time the L</source> method is called.
49 :    
50 :     =item options
51 :    
52 :     Reference to a hash of command-line options.
53 :    
54 :     =item tables
55 :    
56 :     List of tables in this load group.
57 :    
58 :     =back
59 :    
60 :     =cut
61 :    
62 :     sub new {
63 :     # Get the parameters.
64 :     my ($class, $erdb, $source, $options) = @_;
65 :     # Create the table list.
66 :     my @tables = sort qw(Annotation IsTargetOfAnnotation SproutUser MadeAnnotation);
67 :     # Create the BaseSproutLoader object.
68 :     my $retVal = BaseSproutLoader::new($class, $erdb, $source, $options, @tables);
69 :     # Return it.
70 :     return $retVal;
71 :     }
72 :    
73 :     =head2 Public Methods
74 :    
75 :     =head3 Generate
76 :    
77 :     $sl->Generate();
78 :    
79 :     Generate the data for the annotation data files.
80 :    
81 :     =cut
82 :    
83 :     sub Generate {
84 :     # Get the parameters.
85 :     my ($self) = @_;
86 :     # Get the sprout object.
87 :     my $sprout = $self->db();
88 :     # Get the FIG object.
89 :     my $fig = $self->source();
90 :     # Check for global mode.
91 :     if ($self->global()) {
92 :     # In global mode, we create the built-in users.
93 :     Trace("Creating default users.") if T(3);
94 :     $self->PutE(SproutUser => "FIG", description => "Fellowship for Interpretation of Genomes");
95 :     $self->PutE(SproutUser => "FIG", description => "Fellowship for Interpretation of Genomes");
96 :     } else {
97 :     # Get the section ID, which is the relevant genome.
98 :     my $genomeID = $self->section();
99 :     # Process the annotations for the specified genome.
100 :     # Get the current time.
101 :     my $time = time();
102 :     # Create a hash of timestamps. We use this to prevent duplicate time stamps
103 :     # from showing up for a single PEG's annotations.
104 :     my %seenTimestamps = ();
105 :     # Get the genome's annotations.
106 :     my @annotations = $fig->read_all_annotations($genomeID);
107 :     Trace("Processing annotations.") if T(2);
108 :     for my $tuple (@annotations) {
109 :     # Get the annotation tuple.
110 :     my ($peg, $timestamp, $user, $text) = @{$tuple};
111 :     # Here we fix up the annotation text. "\r" is removed,
112 :     # and "\t" and "\n" are escaped. Note we use the "gs"
113 :     # modifier so that new-lines inside the text do not
114 :     # stop the substitution search.
115 :     $text =~ s/\r//gs;
116 :     $text =~ s/\t/\\t/gs;
117 :     $text =~ s/\n/\\n/gs;
118 :     # Change assignments by the master user to FIG assignments.
119 :     $text =~ s/Set master function/Set FIG function/s;
120 :     # Insure the time stamp is valid.
121 :     if ($timestamp =~ /^\d+$/) {
122 :     # Here it's a number. We need to insure the one we use to form
123 :     # the key is unique.
124 :     my $keyStamp = $timestamp;
125 :     while ($seenTimestamps{"$peg:$keyStamp"}) {
126 :     $keyStamp++;
127 :     }
128 :     my $annotationID = "$peg:$keyStamp";
129 :     $seenTimestamps{$annotationID} = 1;
130 :     # Insure the user exists.
131 :     $self->PutE(SproutUser => $user, name => "SEED user");
132 :     # Generate the annotation.
133 :     $self->putE(Annotation => $annotationID, time => $timestamp,
134 :     annotation => $text);
135 :     $self->PutR(IsTargetOfAnnotation => $peg, $annotationID);
136 :     $self->PutR(MadeAnnotation => $user, $annotationID);
137 :     } else {
138 :     # Here we have an invalid time stamp.
139 :     Trace("Invalid time stamp \"$timestamp\" in annotations for $peg.") if T(1);
140 :     }
141 :     }
142 :     }
143 :     }
144 :    
145 :    
146 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3