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

View of /FigKernelScripts/make_sim_tab.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Fri Mar 23 19:15:40 2007 UTC (12 years, 7 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, 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, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, 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, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.7: +15 -2 lines
compute_pchs_from_sims.pl

#
# 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 FIG;
use strict;

my $fig = new FIG;

my $usage = "usage: make_sim_tab [-no-map] SimTab [SimFile1 SimFile2 ...]";

my($simD, %figs_of);

my $map_pegs = 1;
if ($ARGV[0] eq '-no-map' or $ARGV[0] eq '-nomap')
{
    shift @ARGV;
    $map_pegs = 0;
}

($simD = shift @ARGV)
    || die $usage;

if (-d $simD) 
{
    if (@ARGV == 0) 
    {
	die "$simD already exists";
    }
}
else
{
    mkdir($simD,0777) || die "could not make $simD";
}

open(SYNS,"<$FIG_Config::data/Global/peg.synonyms") || die "aborted";
while (defined($_ = <SYNS>))
{
    if ($_ =~ /^([^,]+),\d+\t(\S+)/)
    {
	my $to = $1;
	my $from = $2;
	my @from = map { $_ =~ /^([^,]+)/; $1 } split(/;/,$from);
	my @fig = grep { $_ =~ /^fig\|/ } (@from,$to);
	if (@fig > 0)
	{
	    $figs_of{$to} = [@fig];
	}
    }
}
print STDERR "loaded synonyms\n";

my @files;

if (@ARGV == 0)
{
    opendir(SIMS,"$FIG_Config::data/Sims") || die "aborted";
    @files = map { "$FIG_Config::data/Sims/$_" } sort grep { $_ !~ /^\./ } readdir(SIMS);
    closedir(SIMS);
}
else
{
    @files = @ARGV;
}

foreach my $file (@files)
{
    print STDERR "processing $file\n";
    open(IN,"cut -f1,2,3,11 $file |") || die "bad: $file";

    my $last_part;
    $file =~ /([^\/]+)$/;
    my $last_part = $1;

    if (-s "$simD/$last_part")
    {
	die "$simD/$last_part already exists";
    }
    open(OUT,">$simD/$last_part") || die "bad: $simD/$last_part";

    my $sim = <IN>;
    while ($sim && ($sim =~ /^(\S+)/))
    {
	my $curr = $1;
	my %sims;
	my $last;
	while ($sim && ($sim =~ /^(\S+)/) && ($curr eq $1))
	{
	    if (($sim =~ /^((\S+)\t(\S+))\t(\S+\t(\S+))/) &&
		((! $last) || ($last ne $1)) &&
		($5 <= 1.0e-20))
	    {
		#
		# $1 is id1\tid2
		# $2 is id1
		# $3 is id2
		# $4 is pct-ident\tscore
		# $5 is score
		#

		my $to1 = $figs_of{$2};
		my $to2 = $figs_of{$3};

		$last = $1;
		my($id1, $id2, $extra) = ($2, $3, $4);

		#
		# Perform lookup into peg.synonyms to determine fig ids for id1 and id2.
		#
		if ((! $to1) && ($id1 =~ /^fig\|/)) { $to1 = [$id1] }
		if ((! $to2) && ($id2 =~ /^fig\|/)) { $to2 = [$id2] }
		if ($to1 && $to2)
		{
		    #
		    # Expand the mapped pegs.
		    #
		    foreach my $peg1 (@$to1)
		    {
			my($g1, $p1);
			($g1, $p1) = $fig->map_peg_to_ids($peg1) if $map_pegs;

			#
			# Find contig / location info
			#

			my $loc1 = $fig->feature_location($peg1);
			my($contig1, $beg1, $end1) = $loc1 =~ /(.*)_(\d+)_(\d+)$/;
			($beg1, $end1) = ($end1, $beg1) if $end1 < $beg1;
			    
			foreach my $peg2 (@$to2)
			{
			    my $loc2 = $fig->feature_location($peg2);
			    my($contig2, $beg2, $end2) = $loc2 =~ /(.*)_(\d+)_(\d+)$/;
			    ($beg2, $end2) = ($end2, $beg2) if $end2 < $beg2;
			    my @locinfo = ($contig1, $beg1, $end1, $contig2, $beg2, $end2);
			    if ($map_pegs)
			    {
				my ($g2, $p2) = $fig->map_peg_to_ids($peg2);
			    
				push(@{$sims{"$g1\t$p1\t$g2"}},[$g1, $p1, $g2, $p2, @locinfo, $extra]);
			    }
			    else
			    {
				my $genome = &FIG::genome_of($peg2);
				push(@{$sims{"$peg1\t$genome"}},[$peg1, $peg2, @locinfo, $extra]);
			    }
			}
		    }
		}
	    }
	    $sim = <IN>;
	}
					 

	my($x, $y, $n, $z);
	foreach $x (keys(%sims))
	{
	    $y = $sims{$x};
	    $n = @$y;
	    foreach $z (@$y)
	    {
		print OUT join("\t",(@$z,$n)),"\n";
	    }
	}
    }
    close(IN);
    close(OUT);
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3