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

Annotation of /FigKernelScripts/make_phob_from_seqs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (view) (download) (as text)

1 : overbeek 1.5 # -*- perl -*-
2 : olson 1.7 #
3 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 :     #
18 :    
19 : overbeek 1.6 use FIG;
20 : overbeek 1.1
21 : overbeek 1.3 &make_sure("clustalw","protdist","clustal_to_fasta","fasta_to_phylip","trim_sequences","neighbor");
22 : overbeek 1.1
23 :     $usage = "usage: make_phob_from_seqs Directory [-trim] < Seqs";
24 :    
25 :     (
26 :     ($puD = shift @ARGV)
27 :     )
28 :     || die $usage;
29 :    
30 :     $trim = (@ARGV > 0) && ($ARGV[0] =~ /^-trim/i);
31 :    
32 :     (! -e $puD) || die "$puD already exists -- check it (and delete it, if that is what you really wish)";
33 :     mkdir($puD,0777) || die "could not mkdir $puD";
34 :     open(SEQSOUT,">$puD/seqs.fasta") || die "could not open $puD/seqs";
35 :     open(IDS,">$puD/ids") || die "could not open $puD/ids";
36 :    
37 :     $n = 1;
38 :     $/ = "\n>";
39 :     while (defined($_ = <STDIN>))
40 :     {
41 :     chomp;
42 :     if ($_ =~ /^>?(\S+)[^\n]*\n(.*)/s)
43 :     {
44 :     $id = $1;
45 :     $seq = $2;
46 :     $idN = "id$n";
47 :     $n++;
48 :     print IDS "$idN\t$id\n";
49 :     $seq =~ s/\s//gs;
50 : overbeek 1.5 $seq =~ s/[uU]/x/g;
51 : overbeek 1.1 &display_id_and_seq($idN,\$seq,\*SEQSOUT);
52 :     }
53 :     }
54 :     close(IDS);
55 :     close(SEQSOUT);
56 :    
57 :     if ($trim)
58 :     {
59 :     rename("$puD/seqs.fasta","$puD/seqs.untrimmed");
60 : overbeek 1.2 &run("trim_sequences 1.0e-5 0.8 < \"$puD/seqs.untrimmed\" > \"$puD/seqs.fasta\"");
61 : overbeek 1.1 }
62 :    
63 :     chdir $puD;
64 :     &run("clustalw -infile=seqs.fasta -align -outorder=aligned > /dev/null");
65 :     rename("seqs.dnd","tree.dnd");
66 :     rename("seqs.aln","aln");
67 :     rename("seqs.fasta","seqs");
68 :     &run("clustal_to_fasta < aln > aln.fasta");
69 : overbeek 1.5 die "$puD/aln.fasta has zero size" unless (-s "aln.fasta");
70 :    
71 : overbeek 1.1 &run("fasta_to_phylip < aln.fasta > infile");
72 :     open(PROTDIST,"| protdist > /dev/null") || die "could not open protdist";
73 :     print PROTDIST "Y\n";
74 :     close(PROTDIST);
75 : overbeek 1.2 &run("cp outfile distance.matrix");
76 : overbeek 1.5 die "$puD/distance.matrix has zero size" unless (-s "distance.matrix");
77 :    
78 : overbeek 1.2 rename("outfile","infile");
79 : overbeek 1.3 open(NEIGHBOR,"| neighbor > /dev/null") || die "could not open neighbor";
80 :     print NEIGHBOR "Y\n";
81 :     close(NEIGHBOR);
82 : overbeek 1.2 rename("outtree","tree.dnd");
83 : overbeek 1.5 die "$puD/tree.dnd has zero size" unless (-s "tree.dnd");
84 : overbeek 1.1
85 :     unlink("infile");
86 : overbeek 1.4 unlink("outfile");
87 : overbeek 1.1
88 :     if (! ((-s "distance.matrix") && (-s "aln.fasta") && (-s "tree.dnd")))
89 :     {
90 :     print STDERR "*** Something went wrong\n";
91 :     exit(1);
92 :     }
93 :    
94 :     sub display_id_and_seq {
95 :     my( $id, $seq, $fh ) = @_;
96 :    
97 :     if (! defined($fh) ) { $fh = \*STDOUT; }
98 :    
99 :     print $fh ">$id\n";
100 :     &display_seq($seq, $fh);
101 :     }
102 :    
103 :     sub display_seq {
104 :     my ( $seq, $fh ) = @_;
105 :     my ( $i, $n, $ln );
106 :    
107 :     if (! defined($fh) ) { $fh = \*STDOUT; }
108 :    
109 :     $n = length($$seq);
110 :     # confess "zero-length sequence ???" if ( (! defined($n)) || ($n == 0) );
111 :     for ($i=0; ($i < $n); $i += 60)
112 :     {
113 :     if (($i + 60) <= $n)
114 :     {
115 :     $ln = substr($$seq,$i,60);
116 :     }
117 :     else
118 :     {
119 :     $ln = substr($$seq,$i,($n-$i));
120 :     }
121 :     print $fh "$ln\n";
122 :     }
123 :     }
124 :    
125 :     sub run {
126 :     my($cmd) = @_;
127 :    
128 :     # my @tmp = `date`; chomp @tmp; print STDERR "$tmp[0]: running $cmd\n";
129 :     (system($cmd) == 0) || confess "FAILED: $cmd";
130 :     }
131 :    
132 :     sub make_sure {
133 :     my(@progs) = @_;
134 :    
135 :     my $prog;
136 :     foreach $prog (@progs)
137 :     {
138 :     my @tmp = `which $prog`;
139 :     if ($tmp[0] =~ /^no $prog/)
140 :     {
141 :     print STDERR $tmp[0];
142 :     exit(1);
143 :     }
144 :     }
145 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3