Skip to content

Instantly share code, notes, and snippets.

@mhl
Created February 23, 2012 14:13
Show Gist options
  • Save mhl/1893022 to your computer and use it in GitHub Desktop.
Save mhl/1893022 to your computer and use it in GitHub Desktop.
Convert TileConfiguration.registered.txt to a format TrakEM2 can load
#!/usr/bin/env python
# This script takes the output of Stephan Preibisch's stitching plugins
# for 3D stacks and outputs tab separated data suitable for loading
# into TrakEM2. What TrakEM2 expects is described here:
#
# http://www.ini.uzh.ch/~acardona/trakem2_manual.html#importing_list
import sys, re
if len(sys.argv) != 1:
print "Usage: %s < tile-configuration.txt > trakem2-tils.txt" % (sys.argv[0])
sys.exit(1)
# A verbose regular expression to match the format of lines in
# TileConfiguration.registered.txt:
matcher = re.compile(r'''
(\S+) # Match the filename
;\s+;\s+ # Match semi-colons followed by whitespace
\( # Match opening bracket
([-+0-9\.eE]+) # A floating point number
,\s* # A comma and zero or more spaces
([-+0-9\.eE]+) # A floating point number
,\s* # A comma and zero or more spaces
([-+0-9\.eE]+) # A floating point number
\s*\) # Zero or more spaces, then a close bracket
''', re.VERBOSE)
for line in sys.stdin:
m = matcher.match(line)
if m:
# Output all of the groups matched by the regular expression
# joined by tabs. I think TrakEM2 is just expecting fields
# naively joined by tabs, rather than fields quoted properly
# as in tab-separated data:
print "\t".join(m.groups())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment