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

Annotation of /Sprout/FamilySaplingLoader.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 FamilySaplingLoader;
21 :    
22 :     use strict;
23 :     use Tracer;
24 :     use ERDB;
25 :     use FFs;
26 :     use base 'BaseSaplingLoader';
27 :    
28 :     =head1 Sapling Family Load Group Class
29 :    
30 :     =head2 Introduction
31 :    
32 :     The Family Load Group includes all of the major family and pairing tables.
33 :    
34 :     =head3 new
35 :    
36 :     my $sl = FamilySaplingLoader->new($erdb, $options);
37 :    
38 :     Construct a new FamilySaplingLoader object.
39 :    
40 :     =over 4
41 :    
42 :     =item erdb
43 :    
44 :     [[SaplingPm]] object for the database being loaded.
45 :    
46 :     =item options
47 :    
48 :     Reference to a hash of command-line options.
49 :    
50 :     =back
51 :    
52 :     =cut
53 :    
54 :     sub new {
55 :     # Get the parameters.
56 :     my ($class, $erdb, $options) = @_;
57 :     # Create the table list.
58 :     my @tables = sort qw(Family HasMember IsInPair Pairing IsDeterminedBy
59 :     PairSet OccursIn Cluster FamilyName Annotation
60 :     IsAnnotatedBy);
61 :     # Create the BaseSaplingLoader object.
62 :     my $retVal = BaseSaplingLoader::new($class, $erdb, $options, @tables);
63 :     # Return it.
64 :     return $retVal;
65 :     }
66 :    
67 :     =head2 Public Methods
68 :    
69 :     =head3 Generate
70 :    
71 :     $sl->Generate();
72 :    
73 :     Generate the data for the family and pairing files.
74 :    
75 :     =cut
76 :    
77 :     sub Generate {
78 :     # Get the parameters.
79 :     my ($self) = @_;
80 :     # Get the database object.
81 :     my $erdb = $self->db();
82 :     # Get the source object.
83 :     my $fig = $self->source();
84 :     # Is this the global section?
85 :     if ($self->global()) {
86 :     # Here we load the coupling data. The coupling data is stored in flat files
87 :     # in a Sapling data subdirectory.
88 :     my $couplingDir = $erdb->LoadDirectory() . '/FamilyData/Sapling';
89 :     $self->LoadFromFile(Pairing => "$couplingDir/Pairing", qw(id));
90 :     $self->LoadFromFile(Cluster => "$couplingDir/Cluster", qw(id));
91 :     $self->LoadFromFile(IsDeterminedBy => "$couplingDir/IsDeterminedBy",
92 :     qw(from-link inverted to-link));
93 :     $self->LoadFromFile(IsInPair => "$couplingDir/IsPairOf",
94 :     qw(from-link to-link));
95 :     $self->LoadFromFile(OccursIn => "$couplingDir/OccursInCluster",
96 :     qw(to-link from-link));
97 :     $self->LoadFromFile(PairSet => "$couplingDir/PairSet",
98 :     qw(id score));
99 :     } else {
100 :     # Get the section ID.
101 :     my $genomeID = $self->section();
102 :     # Here we load the FIGfams for the selected genome. First we need
103 :     # access to the FIGfam data.
104 :     my $figfam_data = &FIG::get_figfams_data();
105 : parrello 1.2 my $ffs = new FFs($figfam_data, $fig);
106 : parrello 1.1 # Get this genome's features.
107 :     my @fidList = $fig->all_features($genomeID);
108 :     # Loop through the features, generating their FIGfam data.
109 :     for my $featureID (@fidList) {
110 :     $self->Track(Features => $featureID, 1000);
111 :     # Ask for the figfams.
112 :     my @fams = $ffs->families_containing_peg($featureID);
113 :     # Connect them to the feature (if any).
114 :     for my $fam (@fams) {
115 :     $self->PutE(Family => $fam);
116 :     $self->PutR(HasMember => $fam, $featureID);
117 :     }
118 :     }
119 :     # Now we process the annotations for the specified genome.
120 :     # Get the current time.
121 :     my $time = time();
122 :     # Create a hash of timestamps. We use this to prevent duplicate time stamps
123 :     # from showing up for a single PEG's annotations.
124 :     my %seenTimestamps = ();
125 :     # Get the genome's annotations.
126 :     my @annotations = $fig->read_all_annotations($genomeID);
127 :     Trace("Processing annotations.") if T(2);
128 :     for my $tuple (@annotations) {
129 :     # Get the annotation tuple.
130 :     my ($peg, $timestamp, $user, $text) = @{$tuple};
131 :     $self->Track(Annotations => "$peg:$timestamp", 1000);
132 :     # Change assignments by the master user to FIG assignments.
133 :     $text =~ s/Set master function/Set FIG function/s;
134 :     # Insure the time stamp is valid.
135 :     if ($timestamp =~ /^\d+$/) {
136 :     # Here it's a number. We need to insure the one we use to form
137 :     # the key is unique.
138 :     my $keyStamp = $timestamp;
139 :     while ($seenTimestamps{"$peg:$keyStamp"}) {
140 :     $keyStamp++;
141 :     }
142 :     my $annotationID = "$peg:" . Tracer::Pad(9999999999 - $keyStamp, 10,
143 :     1, "0");
144 :     $seenTimestamps{"$peg:$keyStamp"} = 1;
145 :     # Generate the annotation.
146 :     $self->PutE(Annotation => $annotationID, annotation_time => $timestamp,
147 :     comment => $text, annotator => $user);
148 :     $self->PutR(IsAnnotatedBy => $peg, $annotationID);
149 :     } else {
150 :     # Here we have an invalid time stamp.
151 :     Trace("Invalid time stamp \"$timestamp\" in annotations for $peg.") if T(1);
152 :     }
153 :     }
154 :     }
155 :     }
156 :    
157 :    
158 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3