6 # Copyright (C) 2003 Christian M. Zmasek
9 # Author: Christian M. Zmasek
10 # zmasek@genetics.wustl.edu
11 # http://www.genetics.wustl.edu/eddy/people/zmasek/
14 # Created on: 09/05/03
15 # Last modified: 09/05/03
19 # Calculates trees based on all alignments/files in a given directory using
26 use lib $FindBin::Bin;
30 my $PREPROCESSING_COMMAND = "";
31 my $PERFORM_PREPROCESSING = 0;
33 my $POSTPROCESSING_COMMAND = "/nfs/dm3/homedir1/czmasek/RIO1.24/perl/extractSpecies.pl";
34 my $PERFORM_POSTPROCESSING = 1;
37 my $MY_TEMP_DIR = $TEMP_DIR_DEFAULT; # $TEMP_DIR_DEFAULT is inherited
43 my $options = ""; # Options for makeTree.pl, see makeTree.pl.
60 # Analyzes the options:
61 # ---------------------
63 unless ( @ARGV == 3 || @ARGV == 4 ) {
67 $options = $ARGV[ 0 ];
68 $input_dir = $ARGV[ 1 ];
69 $output_dir = $ARGV[ 2 ];
74 elsif ( @ARGV == 4 ) {
80 $input_dir = &addSlashAtEndIfNotPresent( $input_dir );
81 $output_dir = &addSlashAtEndIfNotPresent( $output_dir );
82 $MY_TEMP_DIR = &addSlashAtEndIfNotPresent( $MY_TEMP_DIR );
87 # This adds a "-" before the options for makeTree:
88 # ------------------------------------------------
89 unless ( $options =~ /^-/ ) {
90 $options = "-".$options;
97 # This creates the temp file:
98 # --------------------------
103 my $temp_file = $MY_TEMP_DIR."mt".$time.$ii;
105 while ( -e $temp_file ) {
107 $temp_file = $MY_TEMP_DIR."mt".$time.$ii;
112 opendir( DIR, $input_dir ) || error( "Cannot open directory \"$input_dir\": $!" );
116 while( defined( $filename = readdir( DIR ) ) ) {
117 if ( $filename =~ /^\.\.?$/ ) {
120 if ( $use_suffixes == 1 && $filename !~ /$suffix$/ ) {
124 $filenames[ $i ] = $filename;
132 FOREACH: foreach $filename ( @filenames ) {
134 # If the corresponding tree seems to already exists, do next one.
135 if ( -e "$output_dir$filename.nhx" ) {
141 print "working on: $filename\n";
143 print "[tree calculation $i]\n";
144 print "=====================================================================\n\n\n";
147 unlink( "$output_dir$filename.aln",
148 "$output_dir$filename.log",
149 "$output_dir$filename.nbd" );
151 print( "MT.PL: executing:\n" );
153 my $inputfile = $input_dir.$filename;
155 my $outputfilename = "";
157 if ( $use_suffixes == 1 ) {
158 $outputfilename = $output_dir . $filename;
159 $outputfilename =~ s/$suffix$//;
160 $outputfilename =~ s/\.$//;
161 $outputfilename .= ".nhx";
164 $outputfilename = $output_dir . $filename . ".nhx";
169 if ( $PERFORM_PREPROCESSING == 1 ) {
170 my $pre_command = "$PREPROCESSING_COMMAND";
172 print( "$pre_command\n" );
173 system( $pre_command ) && &error( "Could not execute \"$pre_command\"" );
176 $MAKETREE = "/nfs/dm3/homedir1/czmasek/RIO1.24/perl/makeTree2.pl"; # <<<<<<<<<<<<<<<<<<<<<<<-------------------~~~~~~~~~~~~~~~~~~~~~~~
178 my $command = "$MAKETREE $options $inputfile $outputfilename";
180 print( "$command\n" );
181 system( $command ) && &error( "Could not execute \"$command\"" );
185 if ( $PERFORM_POSTPROCESSING == 1 ) {
186 my $post_command = "$POSTPROCESSING_COMMAND $outputfilename";
188 print( "$post_command\n" );
189 system( $post_command ) && &error( "Could not execute \"$post_command\"" );
200 print( "\n\n\nMT.PL: Done!\n" );
213 print( "\nxt.pl: ERROR:\n" );
214 print( "$text\n\n" );
228 print " Copyright (C) 2003 Christian M. Zmasek\n";
229 print " All rights reserved\n";
231 print " Author: Christian M. Zmasek\n";
232 print " zmasek\@genetics.wustl.edu\n";
233 print " http://www.genetics.wustl.edu/eddy/forester/\n";
239 print " Tree construction using makeTree.pl on all alignments/files\n";
240 print " in a given directory.\n";
246 print " mt.pl <options for makeTree.pl> <input directory: aligments> <output\n";
247 print " directory> [suffix for alignments to be used in input directory]\n";
249 print " If a suffix is given, it will be removed for the output files.\n";
255 print " \"mt.pl NS21UTRB100DX alignments/ trees/ .aln\"\n";