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

View of /FigKernelScripts/ex_add_conditions.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Sat Sep 7 14:32:04 2013 UTC (6 years, 2 months ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
add conditions/samples

use Data::Dumper;
use File::Basename;
use Getopt::Long;
use SeedEnv;
use strict;

my $usage = "usage: ex_add_conditions.pl -d DataDir\n";
my($i,$j);
my $dataD;
my $rc  = GetOptions('d=s' => \$dataD);

if ((! $rc) || (! -d $dataD))
{ 
    print STDERR $usage; exit ;
}

if (! -s "$dataD/sample_condition.txt") { die "you need a sample_condition.txt file" }

my %sample_to_condition;
my %condition_to_samples;
foreach $_ (`cat $dataD/sample_condition.txt`)
{
    if ($_ =~ /^(\S+)\s+(\d+)$/)
    {
	$sample_to_condition{$1} = $2;
	push(@{$condition_to_samples{$2}},$1);
    }
}

my %condition_on_off;
my %arH;
foreach $_ (`cat $dataD/atomic.regulon.on.off.calls`)
{
    chomp;
    my($sample,$ar,$val) = split(/\t/,$_);
    my $cond = $sample_to_condition{$sample};
    if (! $arH{$ar}->{$cond}) { $arH{$ar}->{$cond} = [0,0,0] }
    $arH{$ar}->{$cond}->[$val+1]++;
}
open(OUT,">$dataD/condition.AR.on.off")
    || die "could not open $dataD/condition.AR.on.off";

my %counts;
foreach my $ar (sort { $a <=> $b } keys(%arH))
{
    my $x = $arH{$ar};
    foreach my $cond (sort { $a <=> $b } keys(%$x))
    {
	my $counts = $x->{$cond};
	if ($counts->[0] > $counts->[2])
	{
	    $counts{$ar}->{'OFF'}++;
	    print OUT join("\t",($cond,$ar,-1)),"\n";
	}
	elsif ($counts->[0] < $counts->[2])
	{
	    $counts{$ar}->{'ON'}++;
	    print OUT join("\t",($cond,$ar,1)),"\n";
	}
	else
	{
	    print OUT join("\t",($cond,$ar,0)),"\n";
	}
    }
}
close(OUT);

open(OUT,">$dataD/AR.condition.summary")
    || die "could not open $dataD/AR.condition.summary";
open(IN,"<$dataD/atomic.regulons.expanded") ||
    die "could not open $dataD/atomic.regulons.expanded";

while (defined($_ = <IN>))
{
    chomp;
    my($ar,$peg,$alias,$pcc) = split(/\t/,$_);
    my $on = $counts{$ar}->{'ON'};
    if (! defined($on)) { $on = 0 }
    my $off = $counts{$ar}->{'OFF'};
    if (! defined($off)) { $off = 0 }
    print OUT join("\t",($ar,$peg,$alias,$pcc,$on,$off)),"\n";
}
close(OUT);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3