[Bio] / FortyEightMeta / mg_create_seed_org.pl Repository:
ViewVC logotype

View of /FortyEightMeta/mg_create_seed_org.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Fri Mar 5 17:59:17 2010 UTC (10 years, 1 month ago) by dsouza
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, mgrast_dev_10262011, mgrast_dev_02212011, mgrast_release_3_0, mgrast_dev_03252011, 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, mgrast_dev_04052011, mgrast_dev_02222011, HEAD
Changes since 1.3: +37 -226 lines
stripped down to bare essentials -- create a directory, rewrite the sequence file into it.

#
# Postprocess the metagenome LSU/SSU/Greengene sims runs.
#

use DB_File;
use Data::Dumper;

use JobStage;
use strict;
use FIG;
use FIGV;
use FIG_Config;
use File::Basename;
use File::Copy;
use GenomeMeta;
use Carp 'croak';
use FortyEightMeta::ExpandSims;

my $STAGE = "create_seed_org";

@ARGV == 1 or die "Usage: $0 job-dir\n";

my $jobdir = shift;

my $stage = new JobStage('Job48', $STAGE, $jobdir);
$stage or die "Cannot create job for $jobdir\n";

my $job_id = basename($jobdir);
my $job = $stage->job();
my $genome = $job->genome_id();

my $meta = $job->meta;

print "Running job! $jobdir\n";

# this rewrites the sequence file -- replaced by code below
#my $correct_contigs_exe = "$FIG_Config::bin/correct_gff_missing_contigs";
#-x $correct_contigs_exe or $stage->fatal("Executable $correct_contigs_exe missing");

$stage->set_status("in_progress");
$stage->set_running("yes");

my $genome = $job->genome_id();
makedir("$jobdir/rp");
my $orgdir = "$jobdir/rp/$genome";

#
# if an organism directory already exists, move it out of the way
#
if (-d $orgdir)
{
    my $new = "$orgdir." . time;
    print "Moving $orgdir to $new\n";
    rename $orgdir, $new or $stage->fatal("Cannot rename $orgdir to $new: $!");
}

makedir("$jobdir/rp/$genome");

my $fasta = $meta->get_metadata("preprocess.fasta_file");
($fasta and -f $fasta) or $stage->fatal("fasta not found: '$fasta'");

#
# Copy in missing contigs
#
my $contigs_file = "$orgdir/contigs";	
open(RP, ">$contigs_file") or $stage->fatal("could not open file: '$contigs_file'");
open(PROC, "<$fasta") or $stage->fatal("could not open file: '$fasta'");

my $line = <PROC>;
print RP $line;

while ( defined($line = <PROC>) )
{
    if ( $line =~ /^>/ )
    {
	print RP "\n$line";
    }
    else
    {
	chomp $line;
	print RP $line;
    }
}
		
print RP "\n";

close(PROC) or $stage->fatal("could not close file: '$fasta'");
close(RP) or $stage->fatal("could not close file: '$contigs_file'");

#&run_pipe(\*STDOUT, $correct_contigs_exe, "-orgdir", $orgdir, $fasta, $genome);

$stage->set_status("complete");
$stage->set_running("no");

exit(0);
    
sub run_pipe
{
    my($outfh, $cmd, @args) = @_;

    my $pid = open(BOUT, "-|");
    if ($pid == 0)
    {
	exec { $cmd } $cmd, @args;
	die "Failed: $!: $cmd @args";
    }

    print "Started pid=$pid $cmd @args\n";

    while (<BOUT>)
    {
	print $outfh $_;
    }

    if (!close(BOUT))
    {
	$stage->fatal("Failed with \$!=$! \$?=$?: $cmd @args");
    }
}

sub makedir
{
    my($dir) = @_;

    if (! -d $dir)
    {
	mkdir($dir, 0777) or $stage->fatal("mkdir $dir failed: $!");
    }
    chmod 0777, $dir;
}

sub touch
{
    my($file) = @_;
    my $fh = new FileHandle(">$file") or $stage->fatal("touch: cannot open $file for writing: $!");
    close($fh);
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3