Last active
December 12, 2015 21:08
-
-
Save DustinMorado/91f5f25a3b62c34d72cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
--[[ | |
Copyright (c) 2015 Dustin Reed Morado | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
--]] | |
local tomoauto = require('tomoauto') | |
local yalgo = require('yalgo') | |
local io, os, string, table = io, os, string, table | |
local assert, ipairs, pairs = assert, ipairs, pairs | |
local print = print | |
_ENV = nil | |
local parser = yalgo:new_parser('Coarse align and reconstruct a tilt-series.') | |
parser:add_argument({ | |
name = 'input', | |
description = 'Input tilt-series for processing.', | |
meta_value = 'INPUT.st', | |
is_positional = true, | |
is_required = true | |
}) | |
parser:add_argument({ | |
name = 'local_configuration', | |
description = 'Use local configuration file.', | |
meta_value = 'CONFIG_FILE', | |
long_option = '--local-configuration', | |
short_option = '-L', | |
has_argument = true | |
}) | |
parser:add_argument({ | |
name = 'mdoc', | |
long_option = '--mdoc', | |
short_option = '-M', | |
has_argument = true, | |
description = 'Use provided mdoc file as opposed to default.', | |
meta_value = 'MDOC_FILE' | |
}) | |
parser:add_argument({ | |
name = 'tilt_axis_angle', | |
long_option = '--tilt-axis', | |
short_option = '-t', | |
description = 'Tilt axis angle as opposed to default in the MRC header.', | |
has_argument = true, | |
meta_value = 'TILT_ANGLE' | |
}) | |
local options = parser:get_arguments() | |
assert(tomoauto.utils.is_file(options.input)) | |
local MRC = assert(tomoauto.mrcio.new_MRC(options.input)) | |
local config_path = options.local_configuration | |
local sandbox = tomoauto.config.load_local_configuration(config_path) | |
-- Run ccderaser as in pre-processing step | |
local ccderaser = tomoauto.settings.ccderaser | |
ccderaser = ccderaser:apply_local_configuration(sandbox) | |
ccderaser = ccderaser:setup(MRC) | |
ccderaser:write() | |
ccderaser:run() | |
local ccderaser_log = ccderaser:get_log() | |
ccderaser:cleanup() | |
assert(tomoauto.utils.is_file(ccderaser.OutputFile.value)) | |
assert(tomoauto.utils.run('mv ' .. MRC.filename .. ' ' .. | |
MRC.basename .. '_orig.st')) | |
assert(tomoauto.utils.run('mv ' .. ccderaser.OutputFile.value .. ' ' .. | |
MRC.filename)) | |
-- Run tiltxcorr as in the coarse alignment step | |
assert(tomoauto.utils.run('get_tilt_angles ' .. MRC.filename .. ' ' .. | |
MRC.basename .. '.rawtlt')) | |
local tiltxcorr = tomoauto.settings.tiltxcorr | |
tiltxcorr = tiltxcorr:apply_local_configuration(sandbox) | |
tiltxcorr = tiltxcorr:setup(MRC) | |
tiltxcorr:write() | |
tiltxcorr:run() | |
local tiltxcorr_log = tiltxcorr:get_log() | |
tiltxcorr:cleanup() | |
assert(tomoauto.utils.is_file(tiltxcorr.OutputFile.value)) | |
-- Run xftoxg as in the coarse alignment step | |
local xftoxg = tomoauto.settings.xftoxg | |
xftoxg = xftoxg:apply_local_configuration(sandbox) | |
xftoxg = xftoxg:setup(MRC) | |
xftoxg:write() | |
xftoxg:run() | |
local xftoxg_log = xftoxg:get_log() | |
xftoxg:cleanup() | |
assert(tomoauto.utils.is_file(xftoxg.GOutputFile.value)) | |
assert(os.remove(tiltxcorr.OutputFile.value)) | |
-- Run newstack as in the coarse alignment step but with binning to 1K x 1K and | |
-- rotate the tilt-series by the tilt-axis angle. | |
local prenewstack = tomoauto.settings.prenewstack | |
local angle = options.tilt_axis_angle or MRC.tilt_axis_angle | |
local _prenewstack = { | |
BinByFactor = { use = true, value = 4 }, | |
RotateByAngle = { use = true, value = angle }, | |
} | |
prenewstack = prenewstack:update(_prenewstack) | |
prenewstack = prenewstack:apply_local_configuration(sandbox) | |
prenewstack = prenewstack:setup(MRC) | |
prenewstack:write() | |
prenewstack:run() | |
local prenewstack_log = prenewstack:get_log() | |
prenewstack:cleanup() | |
assert(tomoauto.utils.is_file(prenewstack.OutputFile.value)) | |
assert(os.remove(xftoxg.GOutputFile.value)) | |
-- Run tomo3d to generate the reconstruction | |
local tomo3d = tomoauto.settings.tomo3d | |
local _tomo3d = { | |
TiltFile = { use = true, value = '-a TOMOAUTO{basename}.rawtlt \\' }, | |
InputFile = { use = true, value = '-i TOMOAUTO{basename}.preali \\' }, | |
SIRT = { use = true, value = '-S \\' }, | |
Height = { use = true, value = '-z 800 \\' } | |
} | |
tomo3d = tomo3d:update(_tomo3d) | |
tomo3d = tomo3d:apply_local_configuration(sandbox) | |
tomo3d = tomo3d:setup(MRC) | |
tomo3d:write() | |
tomo3d:run() | |
local tomo3d_log = tomo3d:get_log() | |
tomo3d:cleanup() | |
assert(os.remove(MRC.basename .. '.rawtlt')) | |
assert(tomoauto.utils.run('mv ' .. MRC.basename .. '_orig.st ' .. MRC.filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment