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

Annotation of /Sprout/ExportAttributes.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 ExportAttributes
4 :    
5 :     Export attributes to a tab-delimited file.
6 :    
7 :     This method will export attribute data for a single entity type. The
8 :     three parameters are the entity type, an optional entity instance ID,
9 :     and an optional key name.
10 :    
11 :     SQL-style patterns can be specified for the key name or instance ID. For
12 :     example,
13 :    
14 :     ExportAttributes Feature "fig|100226.1%" "virulen%"
15 :    
16 :     will get all virulence-related attributes for features of the C<100226.1>
17 :     genome. Omitting arguments causes them to be treated like pure wildcards.
18 :     For example,
19 :    
20 :     ExportAttributes Feature
21 :    
22 :     would get all attributes for all features.
23 :    
24 :     The attributes will be exported to the standard output in tab-delimited format.
25 :    
26 :     The currently-supported command-line options are as follows.
27 :    
28 :     =over 4
29 :    
30 :     =item user
31 :    
32 :     Name suffix to be used for log files. If omitted, the PID is used.
33 :    
34 :     =item trace
35 :    
36 :     Numeric trace level. A higher trace level causes more messages to appear. The
37 :     default trace level is 2. Tracing will be to a C<trace>I<User>C<.log> file
38 :     in the FIG temporary directory, where I<User> is the value of the B<user>
39 :     option above. A bare number will send trace to the standard output as well as
40 :     the trace log file. To prevent this, use a minus sign. Thus, C<3> will
41 :     trace into the standard output, but C<3-> will only go to the log file.
42 :     Specify C<E> to use emergency tracing.
43 :    
44 :     =item sql
45 :    
46 :     If specified, turns on tracing of SQL activity.
47 :    
48 :     =item background
49 :    
50 :     Save the standard and error output to files. The files will be created
51 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
52 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
53 :     B<user> option above.
54 :    
55 :     =item h
56 :    
57 :     Display this command's parameters and options.
58 :    
59 :     =item phone
60 :    
61 :     Phone number to message when the script is complete.
62 :    
63 :     =back
64 :    
65 :     =cut
66 :    
67 :     use strict;
68 :     use Tracer;
69 :     use DocUtils;
70 :     use TestUtils;
71 :     use Cwd;
72 :     use File::Copy;
73 :     use File::Path;
74 :     use FIG;
75 :    
76 :     # Get the command-line options and parameters.
77 :     my ($options, @parameters) = StandardSetup([qw(CustomAttributes RemoteCustomAttributes ERDB) ],
78 :     {
79 :     trace => ["2-", "trace level"],
80 :     phone => ["", "phone number (international format) to call when load finishes"],
81 :     },
82 :     "<entityName> <id> <keyName>",
83 :     @ARGV);
84 :     # Set a variable to contain return type information.
85 :     my $rtype;
86 :     # Insure we catch errors.
87 :     eval {
88 :     # Insure we have an entity name.
89 :     if (! $parameters[0]) {
90 :     Confess("No entity name specified. (NOTE: the most common entity names are \"Feature\" and \"Genome\".)");
91 :     } else {
92 :     Trace("Connecting to FIG.") if T(2);
93 :     my $fig = FIG->new();
94 :     # Compute the entity pattern.
95 :     my $pattern = [$parameters[0]];
96 :     if ($parameters[1]) {
97 :     push @{$pattern}, $parameters[1];
98 :     }
99 :     # Retrieve the attributes.
100 :     Trace("Calling for attributes.") if T(2);
101 :     my @attrList = $fig->get_attributes($pattern, $parameters[2]);
102 :     Trace(scalar(@attrList) . " attribute values returned.") if T(2);
103 :     for my $row (@attrList) {
104 :     print join("\t", @{$row}) . "\n";
105 :     }
106 :     Trace("Export complete.") if T(2);
107 :     }
108 :     };
109 :     if ($@) {
110 :     Trace("Script failed with error: $@") if T(0);
111 :     $rtype = "error";
112 :     } else {
113 :     Trace("Script complete.") if T(2);
114 :     $rtype = "no error";
115 :     }
116 :     if ($options->{phone}) {
117 :     my $msgID = Tracer::SendSMS($options->{phone}, "ExportAttributes terminated with $rtype.");
118 :     if ($msgID) {
119 :     Trace("Phone message sent with ID $msgID.") if T(2);
120 :     } else {
121 :     Trace("Phone message not sent.") if T(2);
122 :     }
123 :     }
124 :    
125 :    
126 :    
127 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3