#!/usr/bin/env ruby # 2010-04-20 # Written by Michael Matschiner # http://www.evolution.unibas.ch/salzburger/software.htm # # This script modifies tps files produced by Jim Rohlf's TPS series (used for geometric morphometrics) in a # way that individual's ID numbers in the TPS file are replaced with the file names of the images. # This facilitates its use in subsequent analysis software, such as PAST. # The original file remains untouched, a separate output file is written. # # Usage: You'll need Ruby to run this script. Ruby is installed by default on Macintosh computers, # but on Windows, you'll need to get it first from www.ruby-lang.org/en/ # Once you have it, copy this script into the directory of your tps-file. Use the Terminal (Mac) # or the Console (Win) to cd into this directory, and then execute the script by typing # # ruby tpsrename.rb FILENAME.tps fileIn = ARGV[0] ary = Array.new ary = IO.readlines( fileIn ) #ary.each {|x| x.gsub!(/(\d+\.\d{5})\ (\d+\.\d{5})/,"\\1\t\\2")} this separates coordinates with tabs output = "" linecount = 0 count = 1 ary.size.times do |x| if ary[x].to_s[0..5] == "IMAGE=" var = ary[x].scan(/\w+\./)[0].chomp(".") ary[x+1] = "ID=" + var + "\n" end end fileOutName = fileIn.scan(/\w+./)[0].chomp(".") + "_renamed" + ".tps" fileOut = File.new( fileOutName, "w" ) fileOut.print ary.to_s puts "successfully written file " + fileOutName