#!/usr/bin/perl # written by DA Earl on 4/29/07 # daearl@ucla.edu # v0.2 # now takes arguments as to where to look for harvesting. ############################################################################## # This script is provided with no warranty whatsoever. MAKE A BACKUP OF YOUR # RESULTS FOLDER JUST IN CASE! ############################################################################## # Place this script in your STRUCTURE results folder and call it from the # terminal. The script will rename all of your files so that they have a uniform # numbering scheme (all _XXX_f instead of _X_f, _XX_f and _XXX_f). Next the script # will open each file and extract the relevant information and print it to the # command line. Just copy and paste that info wherever you need it! # -daearl@ucla.edu # / (\S+) populations assumed/ # /Estimated Ln Prob of Data = (\S+)/ # /Mean value of ln likelihood = (\S+)/ # /Variance of ln likelihood = (\S+)/ open(OUT,">out_file.txt") || die("Cannot Open File: $!"); if (defined(@ARGV)) { $path = join " ",@ARGV; print "$path\n"; chdir "$path" or die "Error while changing to dir: $!"; } @file_list = glob "*_f"; foreach(@file_list){ # this section of the code changes the naming format. it is optional. chomp; if(/(\S+)_(\d)_f/) { $new_name = "$1_00$2_f"; if (-e $new_name) { warn "can't rename $_ to $new_name: $new_name already exists\n"; } elsif (rename "$_", "$new_name") { ## it works } else { warn "rename $_ to $new_name failed: $!\n"; } } if(/(\S+)_(\d)(\d)_f/) { $new_name = "$1_0$2$3_f"; if (-e $new_name) { warn "can't rename $_ to $new_name: $new_name already exists\n"; } elsif (rename "$_", "$new_name") { ## it works } else { warn "rename $_ to $new_name failed: $!\n"; } } } @file_list = glob "*_f"; print OUT "\nFile Name\tRun #\t#Pops\tEst. Ln Prob of Data\tMean value of Ln likelihood\tVariance of ln likedlihood\n\n"; foreach (@file_list) { open FILE, $_ or die "ERROR - Unable to open '$_': $!\n"; print OUT "$_\t"; # this is the file name if(/(\S+)_(\d+)_f/) { print OUT "$2\t"; } while () { chomp; if(/ (\S+) populations assumed/) { # this is the assumed # of pops print OUT "$1\t"; } if (/Estimated Ln Prob of Data = (\S+)/) { # this handles estimated ln prob of data print OUT "$1\t"; } if (/Mean value of ln likelihood = (\S+)/) { # this handles mean value of ln likelihood print OUT "$1\t"; } if (/Variance of ln likelihood = (\S+)/) { # this handles variance of the ln likelihood print OUT "$1\n"; } } close FILE } print OUT "\nSoftware written by Dent Earl daearl (a) ucla (d) edu, EEB Dept. UCLA\nGo Bruins\n\n"; close(OUT);