#!/usr/bin/env ruby # 2010-07-22 # Written by Michael Matschiner # http://www.evolution.unibas.ch/salzburger/software.htm # # This script reads tps files produced by Jim Rohlf's TPS series (used for geometric morphometrics) # and splits these files into separate files for every landmark coordinate set. # Files are named according to landmark coordinate set IDs. # This facilitates its use in subsequent analysis software, such as PAST. # The original file remains untouched. # # 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 tpssplit.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 oldX = 0 var2 = "bla" ary.size.times do |x| var1 = ary[x] if var1.to_s[0..2] == "ID=" var2 = var1[3..-1].chomp ary[x] = "ID=" + var2 + "\n" end if ary[x].to_s[0..2] == "LM=" and x > 0 output = ary[oldX..(x-1)] oldX = x fileOutName = var2.to_s + ".tps" puts fileOutName fileOut = File.new( fileOutName, "w" ) fileOut.print output.to_s end end output = ary[oldX..ary.size] fileOutName = var2.to_s + ".tps" puts fileOutName fileOut = File.new( fileOutName, "w" ) fileOut.print output.to_s puts "successfully written files"