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

View of /Sprout/FCTester.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.2 - (download) (as text) (annotate)
Tue Jun 30 19:53:01 2009 UTC (9 years, 7 months ago) by parrello
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, 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_2009_07_09, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_10262011, HEAD
Changes since 1.1: +1 -1 lines
Fixed documentation for more compatibility with non-NMPDR environment.

#!/usr/bin/perl -w

# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
# This file is part of the SEED Toolkit.
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License.
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.

use strict;
use Tracer;
use FC;
use ERDB;

=head1 FCTester Script

    FCTester [options] 

Test the functional coupling update methods

=head2 Introduction

This is a simple test script for functional coupling updates. We create a new
pair set for fictional features on the equally-fictional C<0.0> genome.

=head2 Command-Line Options

=over 4

=item trace

Specifies the tracing level. The higher the tracing level, the more messages
will appear in the trace log. Use E to specify emergency tracing.

=item user

Name suffix to be used for log files. If omitted, the PID is used.

=item sql

If specified, turns on tracing of SQL activity.

=item background

Save the standard and error output to files. The files will be created
in the FIG temporary directory and will be named C<err>I<User>C<.log> and
C<out>I<User>C<.log>, respectively, where I<User> is the value of the
B<user> option above.

=item help

Display this command's parameters and options.

=item warn

Create an event in the RSS feed when an error occurs.

=item phone

Phone number to message when the script is complete.



# Get the command-line options and parameters.
my ($options, @parameters) = StandardSetup([qw(FC ERDB) ],
                                              trace => ["3", "tracing level"],
                                              phone => ["", "phone number (international format) to call when load finishes"]
# Set a variable to contain return type information.
my $rtype;
# Get the sapling database.
my $sapling = ERDB::GetDatabase('Sapling');
# We'll store a list of the pair sets we create in here.
my @pairSetList;
# Insure we catch errors.
eval {
    # Create a pair set.
    my $pairSetID = FC::new_set($sapling);
    push @pairSetList, $pairSetID;
    # Verify it.
    my $pairSet = $sapling->GetEntity(PairSet => $pairSetID);
    Assert(defined $pairSet) || Confess("PairSet $pairSetID not found.");
    Assert($pairSet->PrimaryValue('id') == $pairSetID) || Confess("Invalid ID in pair set.");
    Assert($pairSet->PrimaryValue('score') == 0) || Confess("Invalid score in pair set.");
    # Update the score.
    FC::set_pair_set_sc($sapling, $pairSetID, 10);
    # Verify the updated score.
    my ($score) = $sapling->GetFlat('PairSet', 'PairSet(id) = ?', [$pairSetID],
    Assert($score == 10) || Confess("Invalid score for pairset.");
    # Add some pairings.
    FC::insert_pair($sapling, 'fig|0.0.peg.2', 'fig|0.0.peg.1', $pairSetID);
    FC::insert_pair($sapling, 'fig|0.0.peg.3', 'fig|0.0.peg.1', $pairSetID);
    FC::insert_pair($sapling, 'fig|0.0.peg.1', 'fig|0.0.peg.4', $pairSetID);
    # Read them back.
    my @pairingsInSet = $sapling->GetFlat('PairSet IsDeterminedBy Pairing',
                                         'PairSet(id) = ?', [$pairSetID],
    # There should be three.
    Assert(scalar(@pairingsInSet) == 3) || Confess("PairSet does not contain three pairings.");
    # Verify the IDs.
    my %checkerHash = map { $_ => 1 } @pairingsInSet;
    my @pairList = qw(fig|0.0.peg.1:fig|0.0.peg.2 fig|0.0.peg.1:fig|0.0.peg.3
    for my $pairs (@pairList) {
        Assert($checkerHash{$pairs}) || Confess("$pairs not found in set.");
        my @elements = sort { $a cmp $b } $sapling->GetFlat('IsPairOf', 'IsPairOf(from-link) = ?',
                                                            [$pairs], 'IsPairOf(to-link)');
        Assert(scalar(@elements) > 0) || Confess("No elements found for $pairs.");
        Assert(scalar(@elements) == 2) || Confess("Invalid elements for $pairs: " .
                                                  join(", ", @elements));
        my @pieces = split /:/, $pairs;
        Assert($pieces[0] eq $elements[0]) || Confess("Error in first piece of $pairs.");
        Assert($pieces[1] eq $elements[1]) || Confess("Error in second piece of $pairs.");
    # Delete the 1/2 pair.
    my $pair12 = 'fig|0.0.peg.1:fig|0.0.peg.2';
    FC::delete_pair_from_PairSet($sapling, $pair12, $pairSetID);
    @pairingsInSet = $sapling->GetFlat('PairSet IsDeterminedBy',
                                       'PairSet(id) = ?', [$pairSetID],
    Assert(@pairingsInSet == 2) || Confess("Wrong pairing count after disconnect.");
    %checkerHash = map { $_ => 1 } @pairingsInSet;
    Assert(! exists $checkerHash{$pair12}) || Confess("$pair12 still connected.");
    my $pair12Record = $sapling->GetEntity(Pairing => $pair12);
    Assert(defined $pair12Record) || Confess("Pairing deleted by disconnect.");
    # Delete the pair set.
    my $deleteCheck = $sapling->GetEntity(PairSet => $pairSetID);
    Assert(! defined $deleteCheck) || Confess("Pairset not deleted.");
    my $connections = $sapling->GetFlat('IsDeterminedBy', 'IsDeterminedBy(from-link) = ?',
                                        [$pairSetID], 'IsDeterminedBy(to-link)');
    Assert($connections == 0) || Confess("Connections not deleted by pair set delete.");
    for my $pair (@pairList) {
        my $pairing = $sapling->GetEntity(Pairing => $pair);
        Assert(defined $pairing) || Confess("$pair deleted with pairset.");
if ($@) {
    Trace("Script failed with error: $@") if T(0);
    $rtype = "error";
} else {
    Trace("Script complete.") if T(2);
    $rtype = "no error";
Restore($sapling, \@pairSetList);
if ($options->{phone}) {
    my $msgID = Tracer::SendSMS($options->{phone}, "FCTester terminated with $rtype.");
    if ($msgID) {
        Trace("Phone message sent with ID $msgID.") if T(2);
    } else {
        Trace("Phone message not sent.") if T(2);

=head3 Restore

    Restore($db, \@list);

Remove all the testing data in the specified L<Sapling> database. All
pairings involving C<0.0> features will be removed, along with their
associated pair sets.

=over 4

=item db

Sapling database object.

=item list

Reference to a list of pair set IDs.



sub Restore {
    # Get the parameters.
    my ($db, $list) = @_;
    # Loop through the pair sets. When we delete them, we should get most of the
    # pairings, too.
    Trace("Deleting pair sets.") if T(2);
    for my $pairSetID (@$list) {
        my $stats = $db->Delete(PairSet => $pairSetID);
        Trace("Deleted $pairSetID: " . $stats->Display()) if T(3);
    # Now delete any leftover pairings.
    Trace("Deleting pairings.") if T(2);
    my %testPairings = map { $_ => 1 } $db->GetFlat("Pairing", "Pairing(id) LIKE ?",
                                                    ['fig|0.0%'], 'id');
    for my $pairingID (keys %testPairings) {
        my $stats = $db->Delete(Pairing => $pairingID);
        Trace("Deleted $pairingID: " . $stats->Display()) if T(3);
    Trace("Database cleaning complete.") if T(2);


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3