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

Annotation of /Sprout/CopyCombinedMaps.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 Copy Combined Maps
4 :    
5 :     This script takes as parameters a directory name and parses the combined map files
6 :     it contains to break them into component parts. The component parts are then
7 :     copied to the appropriate directory in the organism cache so they can be read
8 :     as correspondence-map files by the servers.
9 :    
10 :     This script connects to the Sapling server to store the correspondences, so the
11 :     environment variables should be set to point to the correct server.
12 :    
13 :     The currently-supported command-line options are as follows.
14 :    
15 :     =over 4
16 :    
17 :     =item user
18 :    
19 :     Name suffix to be used for log files. If omitted, the PID is used.
20 :    
21 :     =item trace
22 :    
23 :     Numeric trace level. A higher trace level causes more messages to appear. The
24 :     default trace level is 2. Tracing will be directly to the standard output
25 :     as well as to a C<trace>I<User>C<.log> file in the FIG temporary directory,
26 :     where I<User> is the value of the B<user> option above.
27 :    
28 :     =item background
29 :    
30 :     Save the standard and error output to files. The files will be created
31 :     in the FIG temporary directory and will be named C<err>I<User>C<.log> and
32 :     C<out>I<User>C<.log>, respectively, where I<User> is the value of the
33 :     B<user> option above.
34 :    
35 :     =item passive
36 :    
37 :     If specified, then correspondences that already exist will not be updated on the server.
38 :    
39 :     =back
40 :    
41 :     =cut
42 :    
43 :     use strict;
44 :     use Tracer;
45 :     use SeedUtils;
46 :     use Cwd;
47 :     use Stats;
48 :     use ServerThing;
49 :     use SAPserver;
50 :    
51 :     # Get the command-line options and parameters.
52 :     my ($options, @parameters) = StandardSetup([],
53 :     { passive => ["", "if specified, existing correspondence files will not be overwritten"] },
54 :     "<dirname>",
55 :     @ARGV);
56 :     # We'll keep statistics in here.
57 :     my $stats = Stats->new();
58 :     # Get the directory name.
59 :     my $dirName = $parameters[0];
60 :     if (! $dirName) {
61 :     $dirName = getcwd();
62 :     Trace("No directory specified. Current directory $dirName used.") if T(1);
63 :     } elsif (! -d $dirName) {
64 :     Trace("Directory $dirName not found.") if T(0);
65 :     } else {
66 :     Trace("Working in directory $dirName.") if T(2);
67 :     }
68 :     # Get the names of all the genome files in the target directory.
69 :     my @genomes = sort grep { $_ =~ /^\d+\.\d+$/ } OpenDir($dirName);
70 :     Trace(scalar(@genomes) . " genome files found in $dirName.") if T(2);
71 :     # Connect to the server.
72 :     my $sapObject = SAPserver->new();
73 :     Trace("Connected to Sapling server.") if T(2);
74 :     # Loop through the genomes.
75 :     for my $genome (@genomes) {
76 :     # Open the genome's file.
77 :     my $ih = Open(undef, "<$dirName/$genome");
78 :     Trace("Processing $genome file.") if T(2);
79 :     $stats->Add(genomes => 1);
80 :     # Loop through the file, We'll accumulate data rows in here.
81 :     my @rows;
82 :     while (! eof $ih) {
83 :     # Get the current row of data.
84 :     my @row = Tracer::GetLine($ih);
85 :     $stats->Add(lines => 1);
86 :     # Is this the end of a section?
87 :     if ($row[0] eq '//') {
88 :     # Yes, output the section.
89 :     ProcessSection($sapObject, $stats, $options, $genome, \@rows);
90 :     $stats->Add(groups => 1);
91 :     # Clear the row list to start the next section.
92 :     @rows = ();
93 :     } else {
94 :     # No, add this row to the current section.
95 :     push @rows, \@row;
96 :     $stats->Add(rows => 1);
97 :     }
98 :     }
99 :     # All done with this file.
100 :     if (@rows) {
101 :     # Here we have a section without an end marker.
102 :     ProcessSection($sapObject, $stats, $options, $genome, \@rows);
103 :     $stats->Add(orphanGroup => 1);
104 :     }
105 :     }
106 :     # All done. Output the statistics.
107 :     Trace("All done.\n" . $stats->Show()) if T(2);
108 :    
109 :     # This method actually submits the correspondence data accumulated from the current file.
110 :     sub ProcessSection {
111 :     # Get the parameters.
112 :     my ($sapObject, $stats, $options, $genome, $rows) = @_;
113 :     # Look at the first row to determine the target genome.
114 :     my $firstRow = $rows->[0];
115 :     if (! $firstRow) {
116 :     # No first row, so the group is empty.
117 :     Trace("Empty group found in file for $genome: group ignored.") if T(1);
118 :     $stats->Add(emptyGroup => 1);
119 :     } elsif ($firstRow->[1] !~ /^fig\|(\d+\.\d+)/) {
120 :     # Invalid row contents, because the second column is not a gene ID. This should never
121 :     # happen.
122 :     Trace("Invalid entry \"$firstRow->[1]\" found in group for $genome: group ignored.") if T(0);
123 :     $stats->Add(errorGroup => 1);
124 :     } else {
125 :     # Get the target genome ID, which was remembered when we checked the target gene ID in the
126 :     # first row.
127 :     my $genome2 = $1;
128 :     # Determine the passivity option.
129 :     my $passive = $options->{passive};
130 :     # Ask the server to store this correspondence.
131 :     Trace("Submitting correspondence from $genome to $genome2.") if T(3);
132 :     $stats->Add(submission => 1);
133 :     my $status;
134 :     eval {
135 :     $status = $sapObject->submit_gene_correspondence(-genome1 => $genome,
136 :     -genome2 => $genome2,
137 :     -correspondences => $rows,
138 :     -passive => $passive);
139 :     };
140 :     if ($@) {
141 :     Trace("Error in correspondence from $genome to $genome2:\n$@") if T(0);
142 :     $stats->Add(submitError => 1);
143 :     } elsif (! $status) {
144 :     Trace("Correspondence from $genome to $genome2 not stored.") if T(1);
145 :     $stats->Add(submitFailure => 1);
146 :     } else {
147 :     $stats->Add(submitSuccess => 1);
148 :     }
149 :     }
150 :     }
151 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3