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

View of /FigKernelScripts/make_phob_from_seqs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Tue Apr 5 18:30:12 2005 UTC (15 years ago) by overbeek
Branch: MAIN
CVS Tags: efrank-preMakefileToStandardMk
pu => phob

&make_sure("clustalw","protdist","clustal_to_fasta","fasta_to_phylip","trim_sequences");

$usage = "usage: make_phob_from_seqs Directory [-trim] < Seqs";

(
 ($puD     = shift @ARGV)
)
    || die $usage;

$trim = (@ARGV > 0) && ($ARGV[0] =~ /^-trim/i);

(! -e $puD) || die "$puD already exists -- check it (and delete it, if that is what you really wish)";
mkdir($puD,0777) || die "could not mkdir $puD";
open(SEQSOUT,">$puD/seqs.fasta") || die "could not open $puD/seqs";
open(IDS,">$puD/ids") || die "could not open $puD/ids";

$n = 1;
$/ = "\n>";
while (defined($_ = <STDIN>))
{
    chomp;
    if ($_ =~ /^>?(\S+)[^\n]*\n(.*)/s)
    {
	$id  =  $1;
	$seq =  $2;
	$idN = "id$n";
	$n++;
	print IDS "$idN\t$id\n";
	$seq =~ s/\s//gs;
	&display_id_and_seq($idN,\$seq,\*SEQSOUT);
    }
}
close(IDS);
close(SEQSOUT);

if ($trim)
{
    rename("$puD/seqs.fasta","$puD/seqs.untrimmed");
    &run("trim_sequences < \"$puD/seqs.untrimmed\" > \"$puD/seqs.fasta\"");
}

chdir $puD;
&run("clustalw -infile=seqs.fasta -align -outorder=aligned > /dev/null"); 
rename("seqs.dnd","tree.dnd");
rename("seqs.aln","aln");
rename("seqs.fasta","seqs");
&run("clustal_to_fasta < aln > aln.fasta"); 
&run("fasta_to_phylip < aln.fasta > infile"); 

open(PROTDIST,"| protdist > /dev/null") || die "could not open protdist";
print PROTDIST "Y\n";
close(PROTDIST);

rename("outfile","distance.matrix");
unlink("infile");

if (! ((-s "distance.matrix") && (-s "aln.fasta") && (-s "tree.dnd")))
{
    print STDERR "*** Something went wrong\n";
    exit(1);
}

sub display_id_and_seq {
    my( $id, $seq, $fh ) = @_;
    
    if (! defined($fh) )  { $fh = \*STDOUT; }
    
    print $fh ">$id\n";
    &display_seq($seq, $fh);
}

sub display_seq {
    my ( $seq, $fh ) = @_;
    my ( $i, $n, $ln );
    
    if (! defined($fh) )  { $fh = \*STDOUT; }

    $n = length($$seq);
#   confess "zero-length sequence ???" if ( (! defined($n)) || ($n == 0) );
    for ($i=0; ($i < $n); $i += 60)
    {
	if (($i + 60) <= $n)
	{
	    $ln = substr($$seq,$i,60);
	}
	else
	{
	    $ln = substr($$seq,$i,($n-$i));
	}
	print $fh "$ln\n";
    }
}

sub run {
    my($cmd) = @_;

#   my @tmp = `date`; chomp @tmp; print STDERR "$tmp[0]: running $cmd\n";
    (system($cmd) == 0) || confess "FAILED: $cmd";
}

sub make_sure {
    my(@progs) = @_;

    my $prog;
    foreach $prog (@progs)
    {
	my @tmp = `which $prog`;
	if ($tmp[0] =~ /^no $prog/)
	{
	    print STDERR $tmp[0];
	    exit(1);
	}
    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3