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

View of /FigKernelScripts/cluster_objects.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (download) (as text) (annotate)
Sun Apr 10 11:44:34 2011 UTC (8 years, 10 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, myrast_rel40, mgrast_dev_05262011, mgrast_dev_06072011, mgrast_release_3_0_4, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2011_0928, mgrast_dev_10262011
Changes since 1.4: +1 -1 lines
require connections to begin each line

# -*- perl -*-
#
# 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 Carp;
use strict;

# usage: cluster_objects < related > sets

$| = 1;

my %to_cluster;
my %in_cluster;

my $nxt = 1;
while (defined($_ = <STDIN>))
{
    if ($_ =~ /^(\S+)\t(\S+)/)
    {
	my $obj1 = $1;
	my $obj2 = $2;
	my $in1 = $to_cluster{$obj1};
	my $in2 = $to_cluster{$obj2};

	if (defined($in1) && defined($in2) && ($in1 != $in2))
	{
	    push(@{$in_cluster{$in1}},@{$in_cluster{$in2}});
	    foreach $_ (@{$in_cluster{$in2}})
	    {
		$to_cluster{$_} = $in1;
	    }
	    delete $in_cluster{$in2};
	}
	elsif ((! defined($in1)) && defined($in2))
	{
	    push(@{$in_cluster{$in2}},$obj1);
	    $to_cluster{$obj1} = $in2;
	}
	elsif ((! defined($in2)) && defined($in1))
	{
	    push(@{$in_cluster{$in1}},$obj2);
	    $to_cluster{$obj2} = $in1;
	}
	elsif ((! defined($in1)) && (! defined($in2)))
	{
	    $to_cluster{$obj1} = $to_cluster{$obj2} = $nxt;
	    $in_cluster{$nxt} = [$obj1,$obj2];
	    $nxt++;
	}
    }
}

foreach my $cluster (keys(%in_cluster))
{
    my $set = $in_cluster{$cluster};
    print join("\t",sort @$set),"\n";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3