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

View of /FigKernelScripts/form_clusters.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Thu Oct 29 18:29:51 2009 UTC (10 years 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_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_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.1: +1 -2 lines
Final Server updates.

#
# form_clusters Genome < scores > clusters
#

my $usage   = "usage: form_clusters Genome < connections > clusters";
my $genome;
(
	($genome = shift @ARGV)
)
	|| die $usage;

use FIG;

use strict;

my %connected;

while (defined($_ = <STDIN>))
{
    chop;
    my($peg1,$peg2) = split(/:/,$_);
    my $genome1 = &FIG::genome_of($peg1);
    if ($genome1 eq $genome)
    {
	$connected{$peg1}->{$peg2} = 1;
	$connected{$peg2}->{$peg1} = 1;
    }
}

my %seen;
my @pegs = sort { keys(%{$connected{$b}}) <=> keys(%{$connected{$a}}) } keys(%connected);
while (my $peg = shift @pegs)
{
    if (! $seen{$peg})
    {
	$seen{$peg} = 1;
	my @to = keys(%{$connected{$peg}});
	if (@to == 1)
	{
	    print "$peg\t$to[0]\n";
	    $seen{$to[0]} = 1;
	}
	else
	{
	    my @core = ($peg);
	    my %in_ring = map { $_ => 1 } @to;
	    my $extend = 1;
	    while ($extend)
	    {
		$extend = 0;
		my @ring = keys(%in_ring);
		my @new_in_core;
		foreach my $peg1 (@ring)
		{
		    my @hits = grep { $in_ring{$_} } keys(%{$connected{$peg1}});
		    if (@hits > 0)
		    {
			push(@new_in_core,$peg1);
		    }
		}
		if (@new_in_core > 0)
		{
		    $extend = 1;
		    foreach $_ (@new_in_core)
		    {
			delete $in_ring{$_};
		    }
		    push(@core,@new_in_core);
		}
	    }
	    foreach $_ (@core) { $seen{$_} = 1 }
	    print join("\t",(join(",",sort @core),join(",",sort keys(%in_ring)))),"\n";
	}
    }
}
			    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3