[Bio] / FigKernelScripts / EmergencyMapFlipper.pl Repository:
ViewVC logotype

View of /FigKernelScripts/EmergencyMapFlipper.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Fri Apr 23 18:48:02 2010 UTC (9 years, 6 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.1: +5 -5 lines
*** empty log message ***

#!/usr/bin/perl -w
use strict;

use SeedEnv;
use Tracer;
use Stats;
use ServerThing;

=head1 EmergencyMapFlipper

    EmergencyMapFlipper <directory>

This is a script that runs on the server in order to find correspondence files
that need to be flipped. Each correspondence file directory is searched for files
that won't be found by the server because they are pointing in the wrong
direction. If no file exists that points in the right direction, the wrong-direction
file will be flipped and moved to the correct location.

The single positional parameter should be the location of the organism cache
directory.

=cut

my ($options, $directory) = StandardSetup([qw(SAP ServerThing)], { }, "<directory>", @ARGV);
if (! $directory) {
    Confess("No directory specified.");
} elsif (! -d $directory) {
    Confess("Directory not found.");
} else {
    # Get a sapling server object.
    my $sapObject = SAPserver->new(url => $options->{url});
    # Create a statistics object.
    my $stats = Stats->new();
    # Locate the organism directory cache.
    my @orgs = sort grep { $_ =~ /^\d+\.\d+$/ } OpenDir($directory, 0);
    Trace(scalar(@orgs) . " organism directories found.") if T(2);
    # Loop through the directories.
    for my $org (@orgs) {
        $stats->Add(sourceOrgs => 1);
        Trace("Processing directory for $org.") if T(2);
        # Check the organisms in this directory.
        my $subDir = "$directory/$org";
        my @files = sort grep { $_ =~ /^\d+\.\d+$/ } OpenDir($subDir, 0);
        for my $file (@files) {
            # Check to see if this file is findable.
            if (! ServerThing::MustFlipGenomeIDs($org, $file)) {
                $stats->Add(goodFiles => 1);
            } else {
                # Here we have a file in the wrong direction. Compute the file name.
                my $oldFileName = "$directory/$org/$file";
                # Here we have to fip the file. Read in the whole thing and flip it in place.
                Trace("Reading $oldFileName.") if T(3);
                my $dataRows = ServerThing::ReadGeneCorrespondenceFile($oldFileName, 1, 1);
                if (! defined $dataRows) {
                    # Here the old file was invalid.
                    Trace("$oldFileName is invalid: not moved.") if T(2);
                    $stats->Add(badFiles => 1);
                } else {
                    # Submit the file to the server.
                    my $flag = $sapObject->submit_gene_correspondence(-genome1 => $file,
                                                                      -genome2 => $org,
                                                                      -correspondences => $dataRows,
                                                                      -passive => 1);
                    if ($flag) {
                        Trace("$oldFileName submitted to server.") if T(2);
                        $stats->Add(submitted => 1);
                    } else {
                        Trace("$oldFileName rejected or ignored.") if T(1);
                        $stats->Add(copyFailed => 1);
                    }
                }
            }
        }
    }
    Trace("Run complete.\n" . $stats->Show()) if T(2);
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3