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

View of /FigKernelScripts/get_best_set_of_genes_for_column.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (download) (as text) (annotate)
Mon Dec 5 18:56:37 2005 UTC (13 years, 11 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, caBIG-05Apr06-00, 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, caBIG-13Feb06-00, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
Changes since 1.2: +17 -0 lines
Add license words.

#
# 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;
my $fig = new FIG;

$usage = "usage: get_best_set_of_genes_for_column Subsystem Role > PEGs";

(
 ($sub  = shift @ARGV) &&
 ($role = shift @ARGV)
)
    || die $usage;

@genomes =  map { $_->[0] } @{$fig->subsystem_genomes($sub)};
foreach $genome (@genomes)
{
    @pegs_in_subsystem = $fig->pegs_in_subsystem_cell($sub,$genome,$role);
    for $peg (@pegs_in_subsystem)
    {
        if ( ! defined($peg))
        {
            print STDERR "skipping $peg reason: peg name is not 'defined'\n";
            next;
        }
        $loc = $fig->feature_location($peg);
        if ($loc =~ /,/)
        {
            print STDERR "skipping $peg reason: complex loc\n";
            next;
        }
        if ($fig->possibly_truncated($peg))
        {
            print STDERR "skipping $peg reason: possibly truncated\n";
            next;
        }
        $seq = uc $fig->dna_seq($genome,$loc);
        $t1 = $fig->get_translation($peg);
	$t2 = $fig->translate($seq,undef,1);    # 1 -> make all starts "M" to match db
	$t2 =~ s/\*$//;   # hack for SEED uncertainty relating to STOPs

	if (substr($t1,1) ne substr($t2,1))  # skip the start (odd in db ?)
        {
            print STDERR "skipping $peg reason: mismatch in translation\n";
	    print STDERR "$t1\n$t2\n";
            next;
        }
        push(@pegs,$peg);
    }
}
print STDERR "number of pegs kept = ", scalar(@pegs), "\n";
%pegs = map { $_ => 1 } @pegs;


foreach $peg (@pegs)
{
    foreach $sim (grep { $pegs{$_->id2} } $fig->sims($peg,500,1.0e-20,"fig"))
    {
	$id2 = $sim->id2;
	$ln1 = $sim->ln1;
	$ln2 = $sim->ln2;

	$len{$peg} = $ln1;
	$len{$id2} = $ln2;

	$b1  = $sim->b1;
	$e1  = $sim->e1;
	$b2  = $sim->b2;
	$e2  = $sim->e2;
	if (&ok($ln1,$b1,$e1) && &ok($ln2,$b2,$e2))
	{
            # print "$peg $b1 $e1 $ln1  $id2 $b2 $e2 $ln2\n";
	    push(@{$conn{$peg}},$id2);
	}
    }
}

@ordered = sort { $b->[0] <=> $a->[0] }
           map  { [scalar @{$conn{$_}},$_] } keys(%conn);
$seed = $ordered[0]->[1];
@cluster = ($seed);
$seen{$seed} = 1;
print STDERR "seed=$seed conn=$ordered[0]->[0] length=$len{$seed}\n";

for ($i=0; ($i < @cluster); $i++)
{
    $x = $conn{$cluster[$i]};
    foreach $peg1 (@$x)
    {
	if ((! $seen{$peg1}) && ($len{$peg1} >= (0.7 * $len{$seed})))
	{
	    push(@cluster,$peg1);
	    $seen{$peg1} = 1;
	}
    }
}

foreach $peg (sort { $len{$a} <=> $len{$b} } @cluster)
{
    $loc = $fig->feature_location($peg);
    # print "$peg\n";
    # print "$len{$peg}\t$peg\n";
    print "$peg\t$loc\n";    ## RMB: put them in tbl format for use by grader
}

sub ok {
    my($ln,$b,$e) = @_;

    $rc = ((abs($e+1-$b) / $ln) >= 0.7);

    if ($rc)
    {
        if ($b < $e)
        {
            if ($b > 100 || ($ln-$e) > 100)
            {
                $rc = 0;
            }
        }
        else
        {
            if ($e > 100 || ($ln-$b) > 100)
            {
                $rc = 0;
            }
        }
    }

    return $rc;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3