[Bio] / Sprout / SaplingAssignments.pl Repository:
ViewVC logotype

Annotation of /Sprout/SaplingAssignments.pl

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 :     =head1 Sapling Functional Assignment Script
4 :    
5 :     This script reads a file of feature IDs and functional assignments and
6 :     applies them to the Sapling database. Unlike the normal function loader,
7 :     no annotation changes are made.
8 :    
9 :     The input file must be in tab-delimited format, with the feature IDs in
10 :     the first field and the functional assignments in the second.
11 :    
12 :     There is a single positional parameter: the name of the input file.
13 :    
14 :     The currently-supported command-line options are as follows.
15 :    
16 :     =over 4
17 :    
18 :     =item user
19 :    
20 :     Name suffix to be used for log files. If omitted, the PID is used.
21 :    
22 :     =item trace
23 :    
24 :     Numeric trace level. A higher trace level causes more messages to appear. The
25 :     default trace level is 2. Tracing will be directly to the standard output
26 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
27 :     where I<User> is the value of the B<user> option above.
28 :    
29 :     =item sql
30 :    
31 :     If specified, turns on tracing of SQL activity.
32 :    
33 :     =item background
34 :    
35 :     Save the standard and error output to files. The files will be created
36 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
37 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
38 :     B<user> option above.
39 :    
40 :     =item h
41 :    
42 :     Display this command's parameters and options.
43 :    
44 :     =item host
45 :    
46 :     Alternate database host, if the database is located somewhere other than the
47 :     default. This is necessary on some Sapling machines to insure we get a writable
48 :     copy of the database.
49 :    
50 :     =item port
51 :    
52 :     Alternate database access port. This is used for debugging.
53 :    
54 :     =item dbname
55 :    
56 :     Alternate database name. This is used for debugging.
57 :    
58 :     =back
59 :    
60 :     =cut
61 :    
62 :     use strict;
63 :     use Tracer;
64 :     use Sapling;
65 :     use Stats;
66 :    
67 :     use SaplingFunctionLoader;
68 :    
69 :     # Get the command-line options and parameters.
70 :     my ($options, @parameters) = StandardSetup([qw(SaplingFuctionLoader) ],
71 :     { host => ["", "alternate database host machine"],
72 :     port => ["", "alternate database access port"],
73 :     dbname => ["", "alternate datbase name"] },
74 :     "<inputFile>",
75 :     @ARGV);
76 :     # Create the statistics object.
77 :     my $stats = Stats->new();
78 :     # Insure we catch errors.
79 :     eval {
80 :     Trace("Connecting to database.") if T(2);
81 :     # Get the Sapling database.
82 :     my $sap = Sapling->new(dbhost => $options->{host}, port => $options->{port},
83 :     dbName => $options->{dbname});
84 :     # Create the function loader.
85 :     my $loader = SaplingFunctionLoader->new($sap);
86 :     # Attach our statistics object.
87 :     $loader->{stats} = $stats;
88 :     # Compute the input file. If no file name is specified, we use "-", which translates to
89 :     # STDIN.
90 :     my $inFileName = $parameters[0] || "-";
91 :     if ($inFileName eq "-") {
92 :     Trace("Assignments will be taken from standard input.") if T(2);
93 :     } else {
94 :     Trace("Assignments will be taken from $inFileName.") if T(2);
95 :     }
96 :     my $ih = Open(undef, "<$inFileName");
97 :     # Insure the input counter only refers to our input file.
98 :     local $.;
99 :     # Loop through the assignments.
100 :     while (! eof $ih) {
101 :     # Get the next assignment.
102 :     my ($fid, $function) = Tracer::GetLine($ih);
103 :     my $count = $stats->Add(inputLines => 1);
104 :     # Check to see if the feature already has this function.
105 :     my ($oldFunction) = $sap->GetFlat('Feature', 'Feature(id) = ?', [$fid],
106 :     'Feature(function)');
107 :     if (! defined $oldFunction) {
108 :     # Here the feature does not exist.
109 :     $stats->Add(missingFeature => 1);
110 :     } elsif ($oldFunction eq $function) {
111 :     # Here the feature already has this functino.
112 :     $stats->Add(skippedFeature => 1);
113 :     } else {
114 :     # Here we need to make the update. Disconnect the feature
115 :     # from its current roles.
116 :     $sap->Disconnect('IsFunctionalIn', Feature => $fid);
117 :     # Connect it to its new roles.
118 :     $loader->ConnectFunctionRoles($fid, $function);
119 :     # Update the feature with the new functional role.
120 :     $sap->UpdateEntity('Feature', $fid, function => $function);
121 :     $stats->Add(updatedFeature => 1);
122 :     }
123 :     # Track our progress.
124 :     Trace("$count assignments processed.") if ($count % 5000 == 0) && T(3);
125 :     }
126 :     Trace("Processing complete.") if T(2);
127 :     };
128 :     if ($@) {
129 :     Trace("Script failed with error: $@") if T(0);
130 :     } else {
131 :     Trace("Script complete.") if T(2);
132 :     }
133 :     Trace("Statistics for this run: " . $stats->Show()) if T(2);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3