Beispiel #1
0
def sanity_checks(command_args, input_vol):

    if os.path.isfile(
            os.path.join(command_args.output_dir,
                         command_args.prefix + '_mask.hdf')):
        if not command_args.override:
            global_def.ERROR(
                'sxmask',
                'Output mask already exists! Please provide the override option if you want to override the existing mask.',
                1)

    if command_args.second_mask_shape in ('cylinder', 'sphere'):
        nx = input_vol.get_xsize()
        ny = input_vol.get_ysize()
        nz = input_vol.get_zsize()
        if command_args.s_radius > nx // 2 or \
          command_args.s_radius > ny // 2:
            global_def.ERROR(
                'sxmask',
                'Provided radius is larger than input image dimensions!', 1)

    if command_args.second_mask_shape is not None:
        nx = input_vol.get_xsize()
        ny = input_vol.get_ysize()
        nz = input_vol.get_zsize()
        if command_args.s_nx > nx or \
          command_args.s_ny > ny or \
          command_args.s_nz > nz:
            global_def.ERROR(
                'sxmask',
                'Provided s_nx, s_ny, s_nz mask dimension is larger than input image dimensions!',
                1)
Beispiel #2
0
def import_partres_file(partres_file):
	"""
	Import the information from a SPHIRE partres file.

	Arguments:
	partres_file - Partres file name

	Returns:
	Array containing the ctf information.
	"""
	with open(partres_file, 'r') as r:
		number_of_columns = len(r.readline().split())

	if number_of_columns == 22:
		columns = [0, 1, 2, 3, 6, 7, 17, 19, 20, 21]
		dtype_import_list = [
			('defocus', float),
			('cs', float),
			('voltage', float),
			('pixel_size', float),
			('astig_amp', float),
			('astig_angle', float),
			('max_resolution', float),
			('amplitude_contrast', float),
			('phase_shift', float),
			('micrograph_name', '|S1000'),
			]
		dtype_output_list = [
			('_rlnDefocusU', float),
			('_rlnDefocusV', float),
			('_rlnDefocusAngle', float),
			('_rlnMicrographName', '|S1000'),
			('_rlnDetectorPixelSize', float),
			('_rlnMagnification', float),
			('_rlnCtfMaxResolution', float),
			('_rlnPhaseShift', float),
			('_rlnAmplitudeContrast', float),
			('_rlnSphericalAberration', float),
			('_rlnVoltage', float),
			]
	else:
		global_def.ERROR('Number of columns in partres file not known: {0}'.format(number_of_columns), 'sxsphire2relion', 1)

	assert len(columns) == len(dtype_import_list)
	partres_import_array = np.genfromtxt(partres_file, dtype=dtype_import_list, usecols=columns)
	partres_array = np.empty(partres_import_array.shape[0], sorted(dtype_output_list))

	partres_array['_rlnDefocusU'] = (20000 * partres_import_array['defocus'] - 10000 * partres_import_array['astig_amp']) / 2
	partres_array['_rlnDefocusV'] = 20000 * partres_import_array['defocus'] - partres_array['_rlnDefocusU']
	partres_array['_rlnDefocusAngle'] = 45 - partres_import_array['astig_angle']
	partres_array['_rlnMicrographName'] = partres_import_array['micrograph_name']
	partres_array['_rlnAmplitudeContrast'] = partres_import_array['amplitude_contrast'] / 100
	partres_array['_rlnVoltage'] = partres_import_array['voltage']
	partres_array['_rlnSphericalAberration'] = partres_import_array['cs']
	partres_array['_rlnPhaseShift'] = partres_import_array['phase_shift']
	partres_array['_rlnDetectorPixelSize'] = partres_import_array['pixel_size']
	partres_array['_rlnMagnification'] = 10000
	partres_array['_rlnCtfMaxResolution'] = 1 / partres_import_array['max_resolution']

	return partres_array
Beispiel #3
0
def sanity_checks(args):
	"""
	Check if the settings are valid.

	Arguments:
	args - Command line arguments parsed via argparse

	Returns:
	Output file name
	"""
	file_exists_check = [
		args.particle_stack,
		args.partres_file,
		args.params_2d_file,
		args.params_3d_file,
		args.params_3d_index_file,
		args.list,
		args.exlist,
		]
	stack_dependency_check = [
		args.params_2d_file,
		args.params_3d_file,
		args.params_3d_index_file,
		args.list,
		args.exlist,
		]

	if not args.particle_stack and not args.partres_file:
			global_def.ERROR(
				'Particle_stack or partres_file option needs to be present!'.format(option),
				'sxsphire2relion',
				1
				)


	for option in stack_dependency_check:
		if option and not args.particle_stack:
			global_def.ERROR(
				'{0} requires particle stack option!'.format(option),
				'sxsphire2relion',
				1
				)

	for idx, option in enumerate(file_exists_check):
		if option:
			if option.startswith('bdb:'):
				if '#' in option:
					raw_dirnames, basename = option.split('#')
					dirnames = raw_dirnames[4:]
				else:
					dirnames = os.path.dirname(option[4:])
					if not dirnames:
						dirnames = '.'
					basename = os.path.basename(option[4:])
				option = '{0}/EMAN2DB/{1}.bdb'.format(dirnames,basename)
			if not os.path.isfile(option):
				global_def.ERROR(
					'{0} stack must exist!'.format(option),
					'sxsphire2relion',
					1
					)

	if args.list and args.exlist:
		global_def.ERROR(
			'Arguments list and exlist cannot be used at the same time.',
			'sxsphire2relion',
			1
			)

	if args.params_2d_file and args.params_3d_file:
		global_def.ERROR(
			'Arguments params_2d_file and params_3d_file cannot be used at the same time.',
			'sxsphire2relion',
			1
			)

	if args.params_3d_index_file and not args.params_3d_file:
		global_def.ERROR(
			'Arguments params_3d_index_file requires params_3d_file to be set.',
			'sxsphire2relion',
			1
			)

	if args.params_3d_chunk_files and not args.params_3d_file:
		global_def.ERROR(
			'Arguments params_3d_chunk_files requires params_3d_file to be set.',
			'sxsphire2relion',
			1
			)

	try:
		os.mkdir(args.output_dir)
	except OSError:
		pass

	output_path = os.path.join(args.output_dir, args.output_name)
	if os.path.exists(output_path) and args.force:
		pass
	elif os.path.exists(output_path) and not args.force:
		global_def.ERROR(
			'Output file {0} must not exist! Use the --force flag to overwrite existing files'.format(output_path),
			'sxsphire2relion',
			1
			)
	else:
		pass

	return output_path
Beispiel #4
0
import subprocess
import glob
import re
import global_def
import os

parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('submission_command', type=str, help='Submission command, e.g., qsub, qsub -V, sbatch, bash')
parser.add_argument('input_run_dir', type=str, help='Directory containin the pipeline submission files')
parser.add_argument('--hold_flag', type=str, default=None, help='Hold flag for the submission command, e.g. -hold_jid')
parser.add_argument('--first_hold_number', type=str, default=None, help='Wait number of an already running job')
args = parser.parse_args()

global_def.BATCH = True
if not os.path.exists(args.input_run_dir):
    global_def.ERROR('Input directory does not exist!', 'sxbatch.py', 1)

qsub_dict = {
    'qsub': re.compile('Your job (\w+)'),
    'sbatch': re.compile('Submitted batch job (\w+)'),
    }
if args.submission_command.split()[0] not in qsub_dict and args.hold_flag:
    global_def.ERROR('Qsub return output not known! Please contact the SPHIRE authors!', 'sxbatch.py', 1)

if args.first_hold_number:
    prev_hold = args.first_hold_number
else:
    prev_hold = 'aaa'
for idx, file_name in enumerate(sorted(glob.glob('{0}/*'.format(args.input_run_dir)))):
    command = args.submission_command.split()
    if args.hold_flag and (idx != 0 or args.first_hold_number):