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

View of /FigKernelScripts/make_figfam_tree_worker.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Thu Nov 11 17:36:00 2010 UTC (9 years, 3 months ago) by disz
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2011_0119, 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, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.1: +1 -1 lines
FigFam 6 digit problem

use strict;

#print $fh "build_muscle_tree $id\n";

use FIG;
my $fig = new FIG;

use FigFam;

# usage: make_figfam_tree_worker [FAMdir]

my $default_dir;
if (@ARGV > 0)
{
    $default_dir = $ARGV[0];
}
else
{
    $default_dir = &FIG::get_figfams_data();
}

my($fam_id,$dir);
#my $req = <STDIN>;
#my $req = join (" ", @ARGV);
my $echo       = 0;
my $time_cmds  = 0;

if (@ARGV > 0)  { $req = join( " ", @ARGV ); }
while ( (defined($req) && $req) || ((@ARGV == 0) && ($req = &get_req)) )
#while (my $req = &get_req)
{
    if ($req =~ /\s*build_muscle_tree\s+(FIG\d+)?\s*$/)
    {
	$fam_id = $1;
	print STDERR "working on: $fam_id in process $ARGV[1]\n";
	my ($suffix) = ($fam_id) =~ /^FIG\d\d\d(\d\d\d)/; 
	$dir = $default_dir . "/FIGFAMS/" . $suffix . "/" . $fam_id;
	
	# check if the split directory is current, else create a current one
	open(PEGS,"cut -f1 $dir/PEGs | sort -u |") || die "Incomplete FIGfam directory: $fam_id\n";
	my @pegs_qty = <PEGS>;
	
	my $set_qty = 0;
	if (-f "$dir/Split/set.sizes"){
	    open(SIZES, "$dir/Split/set.sizes") || die "Could not open set.sizes file in $fam_id\n";
	    while ($_ = <SIZES>){
		chomp($_);
		$_ =~ m/\t(\d+)/;
		$set_qty += $1;
	    }
	}
	
	if ($set_qty != scalar (@pegs_qty)){
	    # create current split directory
	    &FIG::run("rm -rf $dir/Split");
	    #&FIG::run("mkdir $dir/Split");
	    my $blast_file = "$dir/blastout";
	    &FIG::run("split_and_trim_sequences $dir/Split 1.0e-10 0.7 blastout=$blast_file < $dir/PEGs.fasta");
	}
	
	my @nwk_array = glob("$dir/Split/*.nwk");
	if (scalar @nwk_array < 1){
	    # create the aln and tree file in the Split directory
	    foreach my $file (glob ("$dir/Split/*")){
		if ($file !~ /set\.sizes|distance\.matrix/){
		    my ($ff) = ($file) =~ /.*\/(\w+)\.?/;
		    my $fullF   = "/tmp/seqs.$$";
		    
		    # use only the fig id on the fasta header
		    open(TMP,">$fullF") || die "could not open $fullF";
		    open(FH,"$file") || die "could not open $ff";
		    $/ = "\n>";
		    while (defined($_ = <FH>))
		    {
			chomp;
			if ($_ =~ /^>?(\S+)[^\n]*\n(.*)/s)
			{
			    my $id  =  $1;
			    my $seq =  $2;
			    $seq =~ s/\s//gs;
			    $seq =~ s/[uU]/x/g;
			    print TMP ">$id\n$seq\n";
			}
		    }
		    close(FH);
		    close(TMP);
		    $/ = "\n";
		    
		    # run muscle to generate tree and alignment
		    system("(/vol/biotools/bin/muscle -in $fullF  -out $dir/Split/$ff.aln -tree1 $dir/Split/$ff.nwk -cluster1 neighborjoining -cluster2 neighborjoining -root1 midlongestspan -root2 midlongestspan > /dev/null) &> /dev/null");
		    #system("/vol/biotools/bin/muscle -in $fullF  -out $dir/Split/$ff.aln -tree1 $dir/Split/$ff.nwk -cluster1 neighborjoining -cluster2 neighborjoining -root1 midlongestspan -root2 midlongestspan > /dev/null");
		    
		    ### generate the tree display
		    ##system("display_tree $output/$ff.nwk > $output/$ff.tree");
		    ##
		    ### generate the node index file
		    ##system("/home/arodri7/FIGfam_testing/FIG000087/work/tree_manipulations $output/$ff.nwk > $output/$ff.node_index");
		    ##
		    ### generate the tree display with the nodes
		    ##system("/home/arodri7/FIGfam_testing/FIG000087/work/add_node_tax_to_tree $output/$ff.tree $output/$ff.node_index > $output/$ff.tree2");
		}
	    }
	}
    }
    else {
	print "invalid comman\n";
    }
    print "\n";
    $req = "";
}

sub get_req {
    my($x);
    my $echo;

    print "?? ";
    $x = <STDIN>;
    while (defined($x) && ($x =~ /^h$/i) )
    {
        #&help;
        print "?? ";
        $x = <STDIN>;
    }

    if ((! defined($x)) || ($x =~ /^\s*[qQxX]/))
    {
        return "";
    }
    else
    {
        if ($echo)
        {
            print ">> $x\n";
        }
        return $x;
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3