Created
December 2, 2015 00:46
-
-
Save DustinMorado/dc5bee41987962f67c81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env talua | |
local tomoauto = require('tomoauto') | |
local yalgo = require('yalgo') | |
local io = io | |
local parser = yalgo:new_parser('Convert pos file from rotx tomogram to slab.') | |
parser:add_argument({ | |
name = 'tomogram', | |
description = 'Slab style tomogram to change pos file onto.', | |
meta_value = 'TOMOGRAM.mrc', | |
is_positional = true, | |
is_required = true, | |
}) | |
parser:add_argument({ | |
name = 'posfile', | |
description = 'Original posfile to transform; 3 coordinates per line X, Y, Z', | |
meta_value = 'POSFILE.pos', | |
is_positional = true, | |
is_required = true, | |
}) | |
parser:add_argument({ | |
name = 'output', | |
description = 'New posfile name', | |
meta_value = 'NEW_POSFILE.pos', | |
is_positional = true, | |
is_required = true, | |
}) | |
local options = parser:get_arguments() | |
assert(tomoauto.utils.is_file(options.tomogram), 'Tomogram file not found.') | |
assert(tomoauto.utils.is_file(options.posfile), 'Position file not found.') | |
local MRC = assert(tomoauto.mrcio.new_MRC(options.tomogram)) | |
local posfile = assert(io.open(options.posfile, 'r')) | |
local newpos = assert(io.open(options.output, 'w')) | |
local ny = MRC.header.ny | |
for line in posfile:lines() do | |
local old_x, old_y, old_z = line:match('(%d+)%s+(%d+)%s+(%d+)') | |
local new_x, new_y, new_z = old_x, ny - old_z, old_y | |
local new_line = string.format('%d\t%d\t%d\n', new_x, new_y, new_z) | |
newpos:write(new_line) | |
end | |
assert(posfile:close()) | |
assert(newpos:close()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment