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

View of /FigKernelScripts/process_otus.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (download) (as text) (annotate)
Sat Jan 12 16:21:14 2013 UTC (6 years, 10 months ago) by overbeek
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
Changes since 1.7: +1 -0 lines
do not use ref in sparse

use strict;
use Data::Dumper;
use SeedEnv;

my $usage = "usage: process_otus SetDir RectangleDir ConsistencyReports < OTUs";
my($setD,$rectD,$reportD);
(
 ($setD    = shift @ARGV) &&
 ($rectD   = shift @ARGV) &&
 ($reportD = shift @ARGV)
)
    || die $usage;

(-d $setD)    || mkdir($setD,0777)    || die "could not make $setD";
(-d $rectD)   || mkdir($rectD,0777)   || die "could not make $rectD";
(-d $reportD) || mkdir($reportD,0777) || die "could not make $reportD";

my $last = <STDIN>;
while ($last && ($last =~ /^(\d+)\t(\S+)/))
{
    my $otu = $1;
    my $ref = $2;
    $last = <STDIN>;
    my @genomes;
    while ($last && ($last =~ /^(\d+)\t(\S+)/) && ($otu == $1))
    {
	push(@genomes,$2);
 	$last = <STDIN>;
    }
    if (@genomes > 5)
    {
	&process_otu($setD,$rectD,$reportD,$otu,$ref,\@genomes);
    }
}

use File::Temp;
sub process_otu {
    my($setD,$rectD,$reportD,$otu,$ref,$genomes) = @_;

    my $fh1 = File::Temp->new();
    my $fh2 = File::Temp->new();
    my $filename1 = $fh1->filename;
    my $filename2 = $fh2->filename;

    open(DIV,"sparse_genome_sample $ref | cut -f1 | ") || die "could not get a diverse set";
    my $sparse = 0;
    while (defined($_ = <DIV>))
    {
	next if ($_ eq ($ref . "\n"));
	$sparse++;
	print $fh1 $_;
    }
    close(DIV);
    close($fh1);

    foreach $_ (@$genomes) { print $fh2 "$_\n" }
    close($fh2);

    my $req = 0.2 * $sparse;
    if ($req < 5) { $req = 5 }

    &SeedUtils::run("generate_clusters -r $ref -f $filename1 | keep_good_connections -h $req -r 0.4 | sort_sets_of_pegs | tabs2rel | svr_function_of > $setD/$otu");
    &SeedUtils::run("build_solid_set -g $filename2 < $setD/$otu > $rectD/$otu");
    &SeedUtils::run("check_consistency_of_rectangles < $rectD/$otu > $reportD/$otu");
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3