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

View of /FigKernelScripts/align_with_clustal.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Fri Nov 12 03:15:25 2004 UTC (15 years, 2 months ago) by overbeek
Branch: MAIN
Changes since 1.3: +12 -2 lines
make it possible to save alignments

# -*- perl -*-

use Carp;
use Data::Dumper;
use tree_utilities;
use FIG;

my $fig = new FIG;

$| = 1;

$usage = "align_with_clustal [-org] [-func[=user]] [-tree] [-save=Dir] Id1 Id2 ... ";

(@ARGV > 1) || die "usage: $usage";

my $temp_dir = $FIG_Config::temp;
my $file     = "$temp_dir/tmp$$";
my $relabel  = {};
my $save = "";

while ($ARGV[0] =~ m/^-/)
{
    if ($ARGV[0] =~ /-org/)
    {
	$add_org = shift @ARGV;
    }
    elsif ($ARGV[0] =~ /-save=(\S+)/)
    {
	$save = $1;
    }
    elsif ($ARGV[0] =~ /-func/)
    {
	$add_func = shift @ARGV;
	if ($add_func =~ m/=(\S+)/)  { $user = $1; }
    }
    elsif ($ARGV[0] =~ /-tree/)
    {
	$tree =	shift @ARGV;
    }
    else
    {
	$trouble = 1;
	print STDERR "Invalid flag $ARGV[0]\n";
	shift @ARGV;
    }
}
die "\nusage: $usage\n\n" if $trouble;

open(TMP,">$file.fasta") || die "could not open $file";
foreach $id (@ARGV)
{
    next if ($seen{$id});
    $seen{$id} = 1;
    
    if ($seq = $fig->get_translation($id))
    {
	print TMP ">$id\n$seq\n";
	$func = $fig->function_of($id, $user);
	$org  = $fig->org_of($id);
    }
    else
    {
	print STDERR "could not find translation for $id\n";
    }
    
    $label = $id;
    if ($add_org && $org)    { $label .= " [$org]"; }
    if ($add_func && $func)  { $label .= " $func"; }
    
    $relabel->{$id} = $label;
}
close(TMP);
# print STDERR "$0;\n", Dumper($relabel);

system "$FIG_Config::ext_bin/clustalw -infile=$file.fasta -align -outorder=aligned > /dev/null";
print `cat $file.aln`;
if ($tree)
{
    print "=======================================================================\n\n\n";
    $tree = "";
 
    if (-s "$file.dnd")
    {
        @treefile = `cat $file.dnd`;
        if (@treefile && ($tree = &parse_newick_tree(join("",@treefile))))
        {
            $tree = &display_tree($tree,$relabel);
        }
    }
    print "$tree\n";
}
if ($save)
{
    system "cp $file.fasta \"$save/seqs\"";
    system "cp $file.aln \"$save/aln\"";
    system "cp $file.dnd \"$save/tree\"";
}
unlink("$file.fasta","$file.aln","$file.dnd");

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3