def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",
                        "--input",
                        type=str,
                        nargs='+',
                        help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input': args.input, 'output': args.output}

    # Create an EM project object
    new_project = em.ProjectIntersect(name='EMIntersect')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Run the project
    new_project.run(args_dict['input'])

    # Write output files
    new_project.write_output_files()
示例#2
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-flip",     "--flip",      type=str,   help="Flip particle star file")
    parser.add_argument("-noflip",   "--noflip",    type=str,   help="No flip particle star file")
    parser.add_argument("-o",        "--output",    type=str,   help="Output directory", default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'flip':     args.flip,
                 'noflip':   args.noflip,
                 'output':   args.output}

    # Check if the input file exists
    if args_dict['flip'] is None or not os.path.isfile(args_dict['flip']):
        parser.print_help()
        sys.exit('Flip file does not exist!')

    # Check if the input file exists
    if args_dict['noflip'] is None or not os.path.isfile(args_dict['noflip']):
        parser.print_help()
        sys.exit('Noflip file does not exist!')

    # Create an EM project object
    new_project = em.ProjectFlip(name='EMParticleMergeFlip')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Prepare project
    new_project.prepare_merge_project(args_dict['flip'], args_dict['noflip'])
示例#3
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-cols",
                        "--columns",
                        type=str,
                        help="Columns to copy",
                        nargs='*',
                        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'columns': args.columns
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Get the new column parameters
    if args_dict['columns'] is not None:
        new_column_parameters = util.parse_star_parameters(
            args_dict['columns'])
    else:
        new_column_parameters = None

    # Create an EM project object
    new_project = em.Project(name='EMRenameColumns')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Add new columns
    new_project.rename_columns(new_column_parameters)

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
示例#4
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-n",
                        "--numptcls",
                        type=int,
                        help="Number of ptcls in the subset",
                        default=100000)
    parser.add_argument("-r",
                        "--randseed",
                        type=int,
                        help="Random seed",
                        default=1)
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'numptcls': args.numptcls,
        'randseed': args.randseed,
        'output': args.output
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMSubset')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Add new columns
    new_project.pick_random_set(args_dict['numptcls'], args_dict['randseed'])

    # Write output files
    new_project.write_output_files()
示例#5
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",              "--input",           type=str,            help="Particle star file")
    parser.add_argument("-invert-angles",  "--invertangles",    action='store_true', help="Invert eular angles")
    parser.add_argument("-invert-origin",  "--invertorigin",    action='store_true', help="Invert origins(shifts)")
    parser.add_argument("-o",              "--output",          type=str,            help="Output directory", default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':         args.input,
                 'invertangles':  args.invertangles,
                 'invertorigin':  args.invertorigin,
                 'output':        args.output}

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Cistem(name='EMStar2Par')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Sort particles based on imagename
    new_project.sort_images()

    # Prepare project
    new_project.prepare_project()

    # If invert-origin
    if args_dict['invertorigin']:
        new_project.invert_origin()

    # If invert-origin
    if args_dict['invertangles']:
        new_project.invert_angles()

    # Convert to par
    new_project.convert2par()

    # Write output file
    new_project.write_output_file()

    # Write also star file
    new_project.write_star_file()
示例#6
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",        "--input",       type=str, help="Particle star file")
    parser.add_argument("-o",        "--output",      type=str, help="Output directory", default=None)
    parser.add_argument("-ref",      "--reference",   type=str, help="Reference class star file")
    parser.add_argument("-cols",     "--columns",     type=str, help="Columns to copy", nargs='+')
    parser.add_argument("-comp",     "--compare",     type=str, help="Criteria to compare", choices=['img','mic'], default='img')

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':       args.input,
                 'output':      args.output,
                 'reference':   args.reference,
                 'columns':     args.columns,
                 'compare':     args.compare
                 }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the reference file exists
    if args_dict['reference'] is None and not os.path.isfile(args_dict['reference']):
        parser.print_help()
        sys.exit('Reference file file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMCopy')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    new_project.read_class_refs(args_dict['reference'])
    print('Read class reference file {}'.format(args_dict['reference']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Add new columns
    new_project.copy_from_ref(args_dict['columns'], args_dict['compare'])

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-offsetrot",
                        "--offsetrot",
                        type=float,
                        help="Rotation offset",
                        default=0)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'offsetrot': args.offsetrot
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMApplyBarcode')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Add new columns
    new_project.apply_barcode(args_dict['offsetrot'])

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
示例#8
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",            "--input",         type=str,   help="Particle star file")
    parser.add_argument("-o",            "--output",        type=str,   help="Output directory", default=None)
    parser.add_argument("-batch",        "--batch",         type=int,   help="Particle batch size", default=100)
    parser.add_argument("-relion",       "--relion",        action='store_true',   help="Use relion for flipping")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':         args.input,
                 'output':        args.output,
                 'batch':         args.batch,
                 'relion':        args.relion
                 }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.ProjectFlip()
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Determine pixel size from particle star file
    new_project.read_particle_apix()

    if args_dict['relion']:
        new_project.prepare_project_relion()
        new_project.flip_particles_relion()
    else:
        new_project.prepare_project()
        new_project.flip_particles(batch_size=args_dict['batch'])
示例#9
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",     "--input",       type=str, nargs='+', help="Star file(s)")
    parser.add_argument("-o",     "--output",      type=str, help="Output directory", default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':       args.input,
                 'output':      args.output
                 }

    # Check if the input file exists
    if args_dict['input'] is None:
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMMergeStar')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particle_stars(args_dict['input'])
    print('Read particle star files {}'.format(','.join(args_dict['input'])))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Write output files
    new_project.write_output_files()
示例#10
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",          "--input",       type=str, help="Particle star file")
    parser.add_argument("-o",          "--output",      type=str, help="Output directory", default=None)
    parser.add_argument("-ref",        "--reference",   type=str, help="Reference class star file", default=None)
    parser.add_argument("-newclassid", "--newclassid",
                        action='store_true', help="Create new class ids for the reference file")
    parser.add_argument("-addcols",    "--addcolumns",
                        type=str, help="Add new columns with same value for all particles", nargs='*', default=None)
    parser.add_argument("-recenter",   "--recenter",  action='store_true', help="Recenter particles")
    parser.add_argument("-offset",     "--offset",    nargs=2, type=float, default=[0, 0], help="Final offset")
    parser.add_argument("-offsetcom",  "--offsetcom", action='store_true', help="Set final offset from center-of-mass")
    parser.add_argument("-apix",       "--apix",  type=float,
                        help="Micrograph pixel size", default=1.82)
    parser.add_argument("-rotatepsi",  "--rotatepsi",  type=float, help="Rotate psi by angle", default=0)
    parser.add_argument("-flipX",      "--flipX", action='store_true', help='Modify star file for flip around X axis')

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':       args.input,
                 'output':      args.output,
                 'reference':   args.reference,
                 'addcolumns':  args.addcolumns,
                 'recenter':    args.recenter,
                 'newclassid':  args.newclassid,
                 'apix':        args.apix,
                 'offset':      args.offset,
                 'offsetcom':   args.offsetcom,
                 'rotatepsi':   args.rotatepsi,
                 'flipX':       args.flipX
                 }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Get the new column parameters
    if not args_dict['addcolumns'] is None:
        new_column_parameters = util.parse_star_parameters(args_dict['addcolumns'])
    else:
        new_column_parameters = None

    # Create an EM project object
    new_project = em.Project(name='EMTransform')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Set microgragraph pixel size
    new_project.set_mic_apix(args_dict['apix'])

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Check if the input file exists
    if args_dict['reference'] is not None and os.path.isfile(args_dict['reference']):
        new_project.read_class_refs(args_dict['reference'], new_classids=args_dict['newclassid'])
        print('Read class reference file {}'.format(args_dict['reference']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Perform reference based particle star transformation
    new_project.transform_particles(final_offset=args_dict['offset'], com_offset=args_dict['offsetcom'], rotate_psi=args_dict['rotatepsi'])

    # Add new columns
    new_project.add_columns(new_column_parameters)

    # Recenter
    if args_dict['recenter']:
        new_project.read_particle_apix()
        new_project.recenter_particles()

    if args_dict['flipX']:
        new_project.flipX_particles()

    # Write output files
    new_project.write_output_files()
示例#11
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-Zflip",
                        "--Zflip",
                        action='store_true',
                        help="Z-Flip particles in star file")
    parser.add_argument("-tilt90",
                        "--tilt90",
                        action='store_true',
                        help="Set tilt of particles to 90-degree side")
    parser.add_argument("-aligntopriors",
                        "--aligntopriors",
                        type=str,
                        nargs='*',
                        default=None)
    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'Zflip': args.Zflip,
        'tilt90': args.tilt90,
        'output': args.output,
        'aligntopriors': args.aligntopriors
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMRotate')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Make tilt angle around 90 degree
    if args_dict['tilt90']:
        new_project.tilt90_particles()

    # Z-flip particles
    if args_dict['Zflip']:
        new_project.Zflip_particles()

    # Align to priors
    if args_dict['aligntopriors'] is not None:
        new_project.align_to_priors(args_dict['aligntopriors'])

    # Write output files
    new_project.write_output_files()
示例#12
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('-half1', "--half1", type=str, help='Half map 1')
    parser.add_argument('-half2', "--half2", type=str, help='Half map 2')
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument('-hp',
                        "--highpass",
                        type=float,
                        default=40,
                        help='highpass filter for FSC plots')
    parser.add_argument('-whole',
                        "--whole",
                        type=str,
                        default=None,
                        help='Whole map')
    parser.add_argument('-mask',
                        "--mask",
                        type=str,
                        default=None,
                        help='Mask for FSC calculation')
    parser.add_argument('-apix',
                        "--apix",
                        type=float,
                        default=1.82,
                        help='Pixel size (Angstroms)')
    parser.add_argument('-bfactor',
                        "--bfactor",
                        type=float,
                        default=None,
                        help='B-factor for global sharpening (Negative)')

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'half1': args.half1,
        'half2': args.half2,
        'whole': args.whole,
        'highpass': args.highpass,
        'mask': args.mask,
        'apix': args.apix,
        'bfactor': args.bfactor,
        'output': args.output
    }

    # Create an EM project object
    new_project = em.ProjectFsc(name='EMFsc')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Set parameters
    new_project.set_params(args_dict['half1'], args_dict['half2'],
                           args_dict['whole'], args_dict['mask'],
                           args_dict['apix'], args_dict['bfactor'],
                           args_dict['highpass'])

    # Prepare project
    new_project.prepare_project()

    # Prepare io files
    new_project.prepare_io_files()

    # Calculate cross correlations
    new_project.calc_cc()

    # Run the project
    new_project.run_fsc()

    # Write output files
    new_project.write_output_files()
示例#13
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-batch",
                        "--batch",
                        type=int,
                        help="Particle batch size",
                        default=100)
    parser.add_argument("-transform",
                        "--transform",
                        action='store_true',
                        help='Transform the images before writing the stacks')
    parser.add_argument("-hp",
                        "--highpass",
                        type=float,
                        help="Highpass filter in Angstrom units",
                        default=None)
    parser.add_argument("-lp",
                        "--lowpass",
                        type=float,
                        help="Lowpass filter in Angstrom units",
                        default=None)
    parser.add_argument("-clip",
                        "--clip",
                        type=int,
                        help="Clip images to new box size",
                        default=None)
    parser.add_argument("-origapix",
                        "--origapix",
                        type=float,
                        help="Original micrograph pixel size (A)",
                        default=1.82)
    parser.add_argument(
        "-recenter",
        "--recenter",
        action='store_true',
        help=
        "Recenter the images prior to clipping. Use with clip option only.",
        default=None)
    parser.add_argument(
        "-diameter",
        "--diameter",
        type=int,
        help=
        "Particle diameter for normalization. If provided, perform normalization",
        default=None)
    parser.add_argument("-n",
                        "--numptcls",
                        type=int,
                        help="Number of particles to process",
                        default=None)
    parser.add_argument(
        "-copymics",
        "--copymics",
        action='store_true',
        help="Copy micrographs instead of making particle stack",
        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'batch': args.batch,
        'transform': args.transform,
        'highpass': args.highpass,
        'lowpass': args.lowpass,
        'clip': args.clip,
        'diameter': args.diameter,
        'recenter': args.recenter,
        'origapix': args.origapix,
        'numptcls': args.numptcls,
        'copymics': args.copymics
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.ProjectStack(name='EMStack')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Set particle number
    new_project.set_particle_num(args_dict['numptcls'])

    # Set original pixel
    new_project.set_orig_apix(args_dict['origapix'])

    # Read particle diameter
    new_project.set_particle_diameter(args_dict['diameter'])

    # Prepare project
    new_project.prepare_project(args_dict['highpass'], args_dict['lowpass'],
                                args_dict['clip'])

    # Copy micrographs
    if args_dict['copymics']:
        new_project.copy_micrographs()
    else:
        # Flip particles
        new_project.create_stack(args_dict['batch'], args_dict['transform'],
                                 args_dict['clip'], args_dict['recenter'])
示例#14
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle cs file")
    parser.add_argument("-ref",
                        "--reference",
                        type=str,
                        help="Template cs file",
                        default=None)
    parser.add_argument("-pass",
                        "--passthrough",
                        type=str,
                        help="Passthrough cs file from cryosparc",
                        default=None)
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-orig",
                        "--original",
                        type=str,
                        help="Original star file",
                        default=None)
    parser.add_argument("-micpath",
                        "--micpath",
                        type=str,
                        help="Micrographs path",
                        default="Micrographs")
    parser.add_argument("-projpath",
                        "--projpath",
                        type=str,
                        help="Cryosparc project path",
                        default="")
    parser.add_argument("-delclass",
                        "--delclass",
                        type=int,
                        nargs='+',
                        help="Classes to delete",
                        default=[])
    parser.add_argument("-delstr",
                        "--delstr",
                        type=str,
                        help="String to delete from Micrograph name",
                        default='')
    parser.add_argument("-restore-offsets",
                        "--restoreoffsets",
                        action='store_true',
                        help="Restore offsets from original star file")
    parser.add_argument("-merge-orig",
                        "--mergeoriginal",
                        action='store_true',
                        help="Merge with original star file")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'reference': args.reference,
        'passthrough': args.passthrough,
        'output': args.output,
        'original': args.original,
        'micpath': args.micpath,
        'projpath': args.projpath,
        'delclass': args.delclass,
        'delstr': args.delstr,
        'restoreoffsets': args.restoreoffsets,
        'mergeoriginal': args.mergeoriginal
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMcsparc2star')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Set cs files
    new_project.set_cs_files(blob_cs_file=args_dict['input'],
                             passthrough_cs_file=args_dict['passthrough'],
                             original_star_file=args_dict['original'],
                             ref_class_cs_file=args_dict['reference'])

    # Read cs files
    new_project.read_cs_files()

    # Prepare input and output files
    new_project.prepare_io_files_cs()

    # Conert cs to star
    new_project.convert_cs2star(args_dict['micpath'], args_dict['projpath'],
                                args_dict['delclass'], args_dict['delstr'],
                                args_dict['restoreoffsets'],
                                args_dict['mergeoriginal'])

    # Write output files
    new_project.write_output_files()
示例#15
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",            "--input",         type=str,     help="Particle star file")
    parser.add_argument("-o",            "--output",        type=str,     help="Output directory", default=None)
    parser.add_argument("-maxprob",      "--maxprob",       type=float,   help="Maximum probability", default=None)
    parser.add_argument("-maxclass",     "--maxclass",      type=int,     help="Maximum number of classes assigned for a particle", default=None)
    parser.add_argument("-tilt",         "--tilt",          type=float,   nargs=2, help="Accepted range of tilt angles. [ min ,max]",       default=[0, 360])
    parser.add_argument("-dtilt",        "--dtilt",         type=float,   nargs=2, help="Accepted range of diff-tilt angles. [ min ,max]",  default=[0, 360])
    parser.add_argument("-dpsi",         "--dpsi",          type=float,   nargs=2, help="Accepted range of diff-psi angles. [ min ,max]",   default=[0, 360])
    parser.add_argument("-drot",         "--drot",          type=float,   nargs=2, help="Accepted range of diff-rot angles. [ min ,max]",   default=[0, 360])
    parser.add_argument("-dalign",       "--dalign",        type=float,   nargs=2, help="Accepted range of diff-align angles. [ min ,max]", default=[-1, 1])

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':         args.input,
                 'output':        args.output,
                 'maxprob':       args.maxprob,
                 'maxclass':      args.maxclass,
                 'tilt':          args.tilt,
                 'dtilt':         args.dtilt,
                 'dpsi':          args.dpsi,
                 'drot':          args.drot,
                 'dalign':        args.dalign}

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMFilter')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Determine pixel size from particle star file
    new_project.read_particle_apix()

    # Subtract class mrc from particle mrc
    new_project.filter_ptcls(maxprob=args_dict['maxprob'],
                             maxclass=args_dict['maxclass'],
                             tilt_range=args_dict['tilt'],
                             dpsi_range=args_dict['dpsi'],
                             dtilt_range=args_dict['dtilt'],
                             drot_range=args_dict['drot'],
                             dalign_range=args_dict['dalign'])

    # Write output files
    new_project.write_output_files()
示例#16
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-refclass",
                        "--refclass",
                        type=str,
                        help="Class star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-diameter",
                        "--diameter",
                        type=float,
                        help="Particle diameter in Angstroms",
                        default=None)
    parser.add_argument("-maskalign",
                        "--maskalign",
                        type=str,
                        help="Mask used for 2D classification",
                        default=None)
    parser.add_argument("-refalign",
                        "--refalign",
                        type=str,
                        help="Reference mrc file used for alignment",
                        default=None)
    parser.add_argument("-refnum",
                        "--refnum",
                        type=int,
                        help="Reference class number",
                        default=1)
    parser.add_argument(
        "-skip-rotate",
        "--skiprotate",
        action='store_true',
        help="Skip rotation in alignment of class averages to reference")
    parser.add_argument("-use-unmasked",
                        "--useunmasked",
                        action='store_true',
                        help="Use unmasked classes for alignment of classes")
    parser.add_argument("-sigma-psi",
                        "--sigmapsi",
                        type=float,
                        help="Sigma-psi for alignment of classes",
                        default=-1)
    parser.add_argument("-offset-range",
                        "--offsetrange",
                        type=int,
                        help="Offset range for alignment of classes",
                        default=20)
    parser.add_argument("-skip-particles",
                        "--skipparticles",
                        action='store_true',
                        help="Skip particle alignment")
    parser.add_argument("-final-offset",
                        "--finaloffset",
                        type=float,
                        nargs=2,
                        help="Final offset",
                        default=[0, 0])

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'refclass': args.refclass,
        'output': args.output,
        'diameter': args.diameter,
        'maskalign': args.maskalign,
        'refalign': args.refalign,
        'refnum': args.refnum,
        'skiprotate': args.skiprotate,
        'useunmasked': args.useunmasked,
        'sigmapsi': args.sigmapsi,
        'skipparticles': args.skipparticles,
        'offsetrange': args.offsetrange,
        'finaloffset': args.finaloffset
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the class reference file exists
    if args_dict['refclass'] is None and not os.path.isfile(
            args_dict['refclass']):
        parser.print_help()
        sys.exit('Class Reference file file does not exist!')

    # Create an EM project object
    new_project = em.ProjectAlign2D()
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    new_project.read_class_refs(args_dict['refclass'])
    print('Read class reference file {}'.format(args_dict['refclass']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Determine pixel size from particle star file
    new_project.read_particle_apix()

    # Set particle diameter
    new_project.set_particle_diameter(args_dict['diameter'])

    # Set alignment mask
    new_project.set_alignment_mask(args_dict['maskalign'])

    # Set alignment reference
    new_project.set_alignment_ref(args_dict['refalign'])

    # Set alignment reference
    new_project.set_ref_class_num(args_dict['refnum'])

    # Prepare project files
    new_project.prepare_project(use_unmasked_classes=args_dict['useunmasked'])

    # Normalize class averages
    new_project.normalize_class_refs()

    # Run relion
    new_project.set_relion_refine_args(skip_rotate=args_dict['skiprotate'],
                                       sigma_psi=args_dict['sigmapsi'],
                                       offset_range=args_dict['offsetrange'])
    new_project.run_refine2D()

    # Process 2D refine files
    new_project.prepare_refine2D()

    # Check if we skip particle alignment
    if not args_dict['skipparticles']:
        # Transform particles
        new_project.transform_particles(final_offset=args_dict['finaloffset'])

        # Write output files
        new_project.write_output_files()

    # Make transformed class stacks
    new_project.create_transformed_class_stacks()
示例#17
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle par file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-orig",
                        "--original",
                        type=str,
                        help="Original star file")
    parser.add_argument("-del-classes",
                        "--delclasses",
                        type=int,
                        nargs='*',
                        help="Classes to be deleted",
                        default=None)
    parser.add_argument("-sel-classes",
                        "--selclasses",
                        type=int,
                        nargs='*',
                        help="Selected classes",
                        default=None)
    parser.add_argument("-score-cutoff",
                        "--scorecutoff",
                        type=float,
                        help="Frealign score lower cutoff",
                        default=None)
    parser.add_argument("-sigma-cutoff",
                        "--sigmacutoff",
                        type=float,
                        help="Frealign sigma noise lower cutoff",
                        default=None)
    parser.add_argument("-ml-cutoff",
                        "--mlcutoff",
                        type=float,
                        help="Frealign maximum-likelihood lower cutoff",
                        default=None)
    parser.add_argument("-db",
                        "--db",
                        type=str,
                        help="Cistem database file",
                        default=None)
    parser.add_argument("-dont-copy",
                        "--dontcopy",
                        action='store_true',
                        help="Dont copy alignment offset and angle values")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'original': args.original,
        'delclasses': args.delclasses,
        'selclasses': args.selclasses,
        'scorecutoff': args.scorecutoff,
        'sigmacutoff': args.sigmacutoff,
        'mlcutoff': args.mlcutoff,
        'db': args.db,
        'dontcopy': args.dontcopy,
        'output': args.output
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the input file exists
    if args_dict['original'] is None or not os.path.isfile(
            args_dict['original']):
        parser.print_help()
        sys.exit('Original star file does not exist!')

    # Create an EM project object
    new_project = em.Cistem(name='EMPar2Star')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['original'])
    print('Read particle star file {}'.format(args_dict['original']))

    # Read apix from star file
    new_project.read_particle_apix()

    # Prepare output star files
    new_project.prepare_io_files_star()

    # Create write formatter
    new_project.create_write_formatter()

    # Read par file
    new_project.read_par(args_dict['input'])
    print('Read particle par file {}'.format(args_dict['input']))

    # Prepare project
    new_project.set_par2star_params(args_dict['delclasses'],
                                    args_dict['selclasses'],
                                    args_dict['scorecutoff'],
                                    args_dict['sigmacutoff'],
                                    args_dict['mlcutoff'])

    # Read cistem database
    new_project.read_db(args_dict['db'])

    # Select particles that exist in the refinement package
    new_project.select_particles()

    # Convert to par
    if not args_dict['dontcopy']:
        new_project.copy2star()

    # Write output file
    new_project.write_star_file()
示例#18
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-refclass",
                        "--refclass",
                        type=str,
                        help="Class star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-diameter",
                        "--diameter",
                        type=float,
                        help="Particle diameter in Angstroms",
                        default=None)
    parser.add_argument("-masksolvent",
                        "--masksolvent",
                        type=str,
                        help="Solvent mask used for 2D classification",
                        default=None)
    parser.add_argument("-masksub",
                        "--masksub",
                        type=str,
                        help="Mask used for the subtraction",
                        default=None)
    parser.add_argument(
        "-maskref",
        "--maskref",
        type=str,
        help="Reference mask that defines the boundary of the structure",
        default=None)
    parser.add_argument("-batch",
                        "--batch",
                        type=int,
                        help="Particle batch size",
                        default=100)
    parser.add_argument("-maxptcl",
                        "--maxptcl",
                        type=int,
                        help="Maximum number of particles to write",
                        default=None)
    parser.add_argument("-method",
                        "--method",
                        type=str,
                        help="Particle subtraction method",
                        choices=['subctf', 'cropctf', 'crop'],
                        default='subctf')
    parser.add_argument("-norm",
                        "--norm",
                        type=str,
                        help="Normalization method for subtraction",
                        choices=['ccc', 'intensity', 'frc'],
                        default='frc')
    parser.add_argument("-subtractbg",
                        "--subtractbg",
                        action='store_true',
                        help="Subtract background. For crop methods only.")
    parser.add_argument("-skipfirstpeak",
                        "--skipfirstpeak",
                        action='store_true',
                        help="Skip first peak in CTF.")
    parser.add_argument("-innerdiameter",
                        "--innerdiameter",
                        type=float,
                        help="Inner diameter for the region of interest",
                        default=None)
    parser.add_argument("-clip",
                        "--clip",
                        type=int,
                        help="Clip box size in pixels",
                        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'refclass': args.refclass,
        'output': args.output,
        'diameter': args.diameter,
        'masksolvent': args.masksolvent,
        'masksub': args.masksub,
        'maskref': args.maskref,
        'batch': args.batch,
        'maxptcl': args.maxptcl,
        'method': args.method,
        'norm': args.norm,
        'subtractbg': args.subtractbg,
        'skipfirstpeak': args.skipfirstpeak,
        'innerdiameter': args.innerdiameter,
        'clip': args.clip
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the class reference file exists
    if args_dict['refclass'] is None and not os.path.isfile(
            args_dict['refclass']):
        parser.print_help()
        sys.exit('Class Reference file file does not exist!')

    # Create an EM project object
    new_project = em.ProjectSubtract2D()
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    new_project.read_class_refs(args_dict['refclass'])
    print('Read class reference file {}'.format(args_dict['refclass']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Determine pixel size from particle star file
    new_project.read_particle_apix()

    # Set particle diameter
    new_project.set_particle_diameter(args_dict['diameter'])

    # Set alignment mask
    new_project.set_alignment_mask(args_dict['masksolvent'])

    # Set subtraction mask
    new_project.set_subtraction_mask(args_dict['masksub'])

    # Set alignment reference
    new_project.set_structure_mask(args_dict['maskref'])

    # Set inner diameter
    new_project.set_inner_diameter(args_dict['innerdiameter'])

    # Set clip box
    new_project.set_clip_box(args_dict['clip'])

    # Prepare project files
    new_project.prepare_project()

    # Subtract class mrc from particle mrc
    new_project.subtract_class_mrc(
        max_ptcl=args_dict['maxptcl'],
        batch_size=args_dict['batch'],
        subtract_func=args_dict['method'],
        subtract_bg=args_dict['subtractbg'],
        norm_method=args_dict['norm'],
        skip_to_firstpeak=args_dict['skipfirstpeak'])

    # Write output files
    new_project.write_output_files()
示例#19
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-mic",
                        "--micrograph",
                        type=str,
                        help="Micrograph star file")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'micrograph': args.micrograph
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the reference file exists
    if args_dict['micrograph'] is None and not os.path.isfile(
            args_dict['micrograph']):
        parser.print_help()
        sys.exit('Micrographs file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMClean')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Read particle pixel size information
    new_project.read_particle_apix()

    new_project.read_micrographs(args_dict['micrograph'])
    print('Read micrographs star file {}'.format(args_dict['micrograph']))

    # Read micrograph pixel size information
    new_project.read_mic_apix()

    # Read micrograph header
    new_project.read_mic_header()

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Check particle positions
    new_project.check_particle_pos()

    # Delete outside particles
    new_project.delete_outside_ptcls()

    # Write output files
    new_project.write_output_files()
示例#20
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",             "--input",        type=str, help="Particle star file")
    parser.add_argument("-o",             "--output",       type=str, help="Output directory", default=None)
    parser.add_argument("-copytopriors",  "--copypriors",   action='store_true', help="Copy offset and/or angle parameters to priors", default=True)
    parser.add_argument("-copytooffsets", "--copyoffsets",  action='store_true', help="Copy priors to angle and distance offset parameters")
    parser.add_argument("-fliponly",      "--fliponly",     action='store_true', help="Set only flip ratio to 0")
    parser.add_argument("-fliprot",       "--fliprot",      action='store_true', help="Set flip ratio to 0 and delete rlnAngleRotPrior")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':        args.input,
                 'output':       args.output,
                 'copypriors':   args.copypriors,
                 'copyoffsets':  args.copyoffsets,
                 'fliponly':     args.fliponly,
                 'fliprot':      args.fliprot
                 }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Copy offsets to priors overwrites
    if args_dict['copypriors']:
        add_column_parameters  = {'rlnAngleTilt':90,
                                  'rlnAngleTiltPrior':90,
                                  'rlnAnglePsiFlipRatio':0}

        del_column_parameters  = {'rlnAngleRotPrior':None}

        copy_column_parameters = {'rlnOriginX':  'rlnOriginXPrior',
                                  'rlnOriginY':  'rlnOriginYPrior',
                                  'rlnAnglePsi': 'rlnAnglePsiPrior',
                                  'rlnAngleTilt':'rlnAngleTiltPrior'}
           
    if args_dict['copyoffsets']:
        add_column_parameters  = {}

        del_column_parameters  = {}

        copy_column_parameters = {'rlnOriginXPrior':  'rlnOriginX',
                                  'rlnOriginYPrior':  'rlnOriginY',
                                  'rlnAnglePsiPrior': 'rlnAnglePsi',
                                  'rlnAngleTiltPrior':'rlnAngleTilt'}
    if args_dict['fliponly']:
        add_column_parameters   = {'rlnAnglePsiFlipRatio':0}

        del_column_parameters   = {}

        copy_column_parameters  = {}

    if args_dict['fliprot']:
        add_column_parameters   = {'rlnAnglePsiFlipRatio':0}

        del_column_parameters   = {'rlnAngleRotPrior':None}

        copy_column_parameters  = {}


    # Create an EM project object
    new_project = em.Project(name='EMHelixReady')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Delete columns
    new_project.delete_columns(del_column_parameters)

    # Add new columns
    new_project.add_columns(add_column_parameters)

    # Add new columns
    new_project.copy_columns(copy_column_parameters)

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
示例#21
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument(
        "-maxmics",
        "--maxmics",
        type=int,
        help="Maximum number of micrographs allowed in a group",
        default=50)
    parser.add_argument("-method",
                        "--method",
                        type=str,
                        help="Grouping method",
                        choices=['defocus', 'intensity'],
                        default='defocus')
    parser.add_argument("-ref",
                        "--reference",
                        type=str,
                        help="Reference file to make the groups")
    parser.add_argument("-threshdef",
                        "--thresholddefocus",
                        type=float,
                        help="Defocus threshold value for grouping (Angstrom)",
                        default=100)
    parser.add_argument("-threshint",
                        "--thresholdintensity",
                        type=float,
                        help="Intensity scale threshold value for grouping",
                        default=0.1)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'maxmics': args.maxmics,
        'method': args.method,
        'reference': args.reference,
        'thresholddefocus': args.thresholddefocus,
        'thresholdintensity': args.thresholdintensity
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.ProjectGroup(name='EMGroup')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Set project parameters
    new_project.set_params(maxmics=args_dict['maxmics'],
                           threshdef=args_dict['thresholddefocus'],
                           threshint=args_dict['thresholdintensity'])

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Read micrographs
    if args_dict['reference'] is not None and os.path.isfile(
            args_dict['reference']):
        new_project.read_micrographs(args_dict['reference'])
        print('Read micrographs star file {}'.format(args_dict['reference']))

        # Group particles based on a method
        new_project.group_micrographs()

        # Assign the groups
        new_project.assign_groups()

    else:
        print('Reference file does not exist!')
        new_project.group_particles()

    # Write output files
    new_project.write_output_files()
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-selbarcode",
                        "--selbarcode",
                        type=str,
                        help="Barcode to select",
                        nargs='*',
                        default={})
    parser.add_argument("-delbarcode",
                        "--delbarcode",
                        type=str,
                        help="Barcode to delete",
                        nargs='*',
                        default={})

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'selbarcode': args.selbarcode,
        'delbarcode': args.delbarcode
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.Project(name='EMSelectBarcode')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Select barcode
    new_project.select_by_barcode(args_dict['selbarcode'])

    # Delete barcode
    new_project.delete_by_barcode(args_dict['delbarcode'])

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
示例#23
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-cols",
                        "--columns",
                        type=str,
                        help="Columns to copy",
                        nargs='*',
                        default=None)
    parser.add_argument("-copytopriors",
                        "--copypriors",
                        type=str,
                        help="Copy offset and/or angle parameters to priors",
                        default=None,
                        choices=['angle', 'all', 'helix'])
    parser.add_argument(
        "-copytooffsets",
        "--copyoffsets",
        type=str,
        help="Copy priors to angle and distance offset parameters",
        default=None,
        choices=['angle', 'all', 'helix'])
    parser.add_argument("-reset-priors",
                        "--resetpriors",
                        action='store_true',
                        help="Delete prior offset and angle columngs")
    parser.add_argument("-reset-offsets",
                        "--resetoffsets",
                        action='store_true',
                        help="Assign angle and origin offsets to 0")
    parser.add_argument("-invert-psi",
                        "--invertpsi",
                        action='store_true',
                        help="Invert psi angle")
    parser.add_argument("-invert-origin",
                        "--invertorigin",
                        action='store_true',
                        help="Invert originX and originY")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'columns': args.columns,
        'copypriors': args.copypriors,
        'copyoffsets': args.copyoffsets,
        'resetpriors': args.resetpriors,
        'resetoffsets': args.resetoffsets,
        'invertpsi': args.invertpsi,
        'invertorigin': args.invertorigin
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Get the new column parameters
    if args_dict['columns'] is not None:
        new_column_parameters = util.parse_star_parameters(
            args_dict['columns'])
    else:
        new_column_parameters = None

    # Copy offsets to priors overwrites
    if args_dict['copypriors'] == 'all':
        new_column_parameters = {
            'rlnOriginX': 'rlnOriginXPrior',
            'rlnOriginY': 'rlnOriginYPrior',
            'rlnAnglePsi': 'rlnAnglePsiPrior',
            'rlnAngleRot': 'rlnAngleRotPrior',
            'rlnAngleTilt': 'rlnAngleTiltPrior'
        }
    elif args_dict['copypriors'] == 'angle':
        new_column_parameters = {
            'rlnAnglePsi': 'rlnAnglePsiPrior',
            'rlnAngleRot': 'rlnAngleRotPrior',
            'rlnAngleTilt': 'rlnAngleTiltPrior'
        }
    elif args_dict['copypriors'] == 'helix':
        new_column_parameters = {
            'rlnOriginX': 'rlnOriginXPrior',
            'rlnOriginY': 'rlnOriginYPrior',
            'rlnAnglePsi': 'rlnAnglePsiPrior',
            'rlnAngleTilt': 'rlnAngleTiltPrior'
        }

    # Copy priors to offsets overwrites
    if args_dict['copyoffsets'] == 'all':
        new_column_parameters = {
            'rlnOriginXPrior': 'rlnOriginX',
            'rlnOriginYPrior': 'rlnOriginY',
            'rlnAnglePsiPrior': 'rlnAnglePsi',
            'rlnAngleRotPrior': 'rlnAngleRot',
            'rlnAngleTiltPrior': 'rlnAngleTilt'
        }
    elif args_dict['copyoffsets'] == 'angle':
        new_column_parameters = {
            'rlnAnglePsiPrior': 'rlnAnglePsi',
            'rlnAngleRotPrior': 'rlnAngleRot',
            'rlnAngleTiltPrior': 'rlnAngleTilt'
        }
    elif args_dict['copyoffsets'] == 'helix':
        new_column_parameters = {
            'rlnOriginXPrior': 'rlnOriginX',
            'rlnOriginYPrior': 'rlnOriginY',
            'rlnAnglePsiPrior': 'rlnAnglePsi',
            'rlnAngleTiltPrior': 'rlnAngleTilt'
        }

    # Create an EM project object
    new_project = em.Project(name='EMCopyColumns')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # If reset priors option is ON
    if args_dict['resetpriors']:
        new_project.reset_priors()

    # If reset offset option is on
    if args_dict['resetoffsets']:
        new_project.reset_offsets()

    # If invert-psi option is on
    if args_dict['invertpsi']:
        new_project.invert_psi()

    # If invert-origin
    if args_dict['invertorigin']:
        new_project.invert_origin()

    # Add new columns
    new_project.copy_columns(new_column_parameters)

    # Write output files
    new_project.write_output_files(write_ref_class_star=False)
示例#24
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i", "--input", type=str, help="Particle star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-orimic",
                        "--orimic",
                        type=str,
                        help="Original micrograph star file")
    parser.add_argument("-newmic",
                        "--newmic",
                        type=str,
                        help="New micrograph star file")

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'orimic': args.orimic,
        'newmic': args.newmic
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Check if the reference file exists
    if args_dict['orimic'] is None and not os.path.isfile(args_dict['orimic']):
        parser.print_help()
        sys.exit('Original micrographs file does not exist!')

    # Check if the reference file exists
    if args_dict['newmic'] is None and not os.path.isfile(args_dict['newmic']):
        parser.print_help()
        sys.exit('New micrographs file does not exist!')

    # Create an EM project object
    new_project = em.ProjectScale(name='EMScale')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Read particle pixel size information
    new_project.read_particle_apix()

    new_project.read_micrographs(args_dict['orimic'])
    print('Read original micrographs star file {}'.format(args_dict['orimic']))

    # Read original micrographs apix
    new_project.read_mic_apix()

    new_project.read_new_micrographs(args_dict['newmic'])
    print('Read new micrographs star file {}'.format(args_dict['newmic']))

    # Read new micrographs apix
    new_project.read_new_mic_apix()

    # Perform the transformation
    new_project.run()

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Write output files
    new_project.write_output_files()
示例#25
0
def main():

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",            "--input",         type=str,     help="Particle star file")
    parser.add_argument("-o",            "--output",        type=str,     help="Output directory", default=None)
    parser.add_argument("-cols",         "--columns",       type=str,     nargs='*', default=['rlnDefocusU',
                                                                                              'rlnDefocusV',
                                                                                              'rlnDefocusAngle',
                                                                                              'rlnCtfFigureOfMerit',
                                                                                              'rlnFinalResolution',
                                                                                              'rlnMaxValueProbDistribution',
                                                                                              'rlnNrOfSignificantSamples',
                                                                                              'rlnLogLikeliContribution',
                                                                                              'rlnAngleRot',
                                                                                              'rlnAngleRotPrior',
                                                                                              'rlnAngleTilt',
                                                                                              'rlnAngleTiltPrior',
                                                                                              'rlnAnglePsi',
                                                                                              'rlnOriginX',
                                                                                              'rlnOriginY'])

    parser.add_argument("-pairs",        "--pairs",         type=str,     nargs='*', default=['rlnCtfFigureOfMerit:rlnFinalResolution',
                                                                                              'rlnAngleTilt:rlnAngleRot',
                                                                                              'rlnMaxValueProbDistribution:rlnNrOfSignificantSamples',
                                                                                              'rlnOriginX:rlnOriginY',
                                                                                              'rlnAngleRot:rlnAngleRotPrior',
                                                                                              'rlnAngleTilt:rlnAngleTiltPrior',
                                                                                              'rlnAnglePsi:rlnAnglePsiPrior'])
    parser.add_argument("-diffs",        "--diffs",         type=str,     nargs='*', default=['rlnOriginX:rlnOriginXPrior',
                                                                                              'rlnOriginY:rlnOriginYPrior',
                                                                                              'rlnAngleRot:rlnAngleRotPrior',
                                                                                              'rlnAngleTilt:rlnAngleTiltPrior',
                                                                                              'rlnAnglePsi:rlnAnglePsiPrior'])

    parser.add_argument("-orientation",  "--orientation",   action='store_true', help="Plot orientation of the particles with respect to priors")

    parser.add_argument("-nbins",        "--nbins",         type=int,     default=30)
    parser.add_argument("-fontsize",     "--fontsize",      type=int,     default=5)
    parser.add_argument("-format",       "--format",        type=str,     default='svg', choices=['png','svg'])

    parser.add_argument("-ref",          "--reference",     type=str,     help="Reference star file", default=None)
    parser.add_argument("-barcode",      "--barcode",       type=str,     help="Barcode to select", nargs='*', default={})
    parser.add_argument("-offsetrot",    "--offsetrot",     type=int,     default=0)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {'input':         args.input,
                 'output':        args.output,
                 'columns':       args.columns,
                 'pairs':         args.pairs,
                 'diffs':         args.diffs,
                 'orientation':   args.orientation,
                 'fontsize':      args.fontsize,
                 'reference':     args.reference,
                 'nbins':         args.nbins,
                 'format':        args.format,
                 'barcode':       args.barcode,
                 'offsetrot':     args.offsetrot}

    # Get the new column parameters
    if args_dict['barcode'] is not None:
        barcode_parameters = util.parse_star_parameters(args_dict['barcode'])
    else:
        barcode_parameters = None

    # Create an EM project object
    new_project = em.ProjectPlot(name='EMPlot')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory+'/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    # Select based on the barcode
    if barcode_parameters is not None:
      new_project.select_by_barcode(args_dict['barcode'])

    # Read particle mrc paths
    new_project.read_ptcl_mrc_paths()

    # Prepare io files
    new_project.prepare_io_files(args_dict['format'])

    # Set rotation angle offset
    new_project.set_offsetrot(args_dict['offsetrot'])

    # Set tick fontsizes
    new_project.set_tick_fontsize(size=args_dict['fontsize'])

    # Read references if it is provided
    if args_dict['reference'] is not None and os.path.isfile(args_dict['reference']):
      # Read particles
      new_project.read_reference(args_dict['reference'])
      print('Read reference star file {}'.format(args_dict['reference']))

    # Run ptcl project
    new_project.run_ptcl(args_dict['columns'], args_dict['pairs'], args_dict['diffs'], args_dict['orientation'], args_dict['nbins'])

    # Write output files
    new_project.write_output_files(args_dict['format'])
示例#26
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",
                        "--input",
                        type=str,
                        help="Input particle star file")
    parser.add_argument("-ref",
                        "--reference",
                        type=str,
                        help="Reference star file")
    parser.add_argument("-addsuffix",
                        "--addsuffix",
                        type=str,
                        nargs='*',
                        help="Suffix to add to the image names",
                        default=None)
    parser.add_argument("-remsuffix",
                        "--removesuffix",
                        type=str,
                        help="Suffix to remove from the image names",
                        default=None)
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'reference': args.reference,
        'addsuffix': args.addsuffix,
        'removesuffix': args.removesuffix,
        'output': args.output
    }

    # Check if the input file exists
    if args_dict['input'] is None or not os.path.isfile(args_dict['input']):
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.ProjectImgName(name='EMReplaceImgName')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_particles(args_dict['input'])
    print('Read particle star file {}'.format(args_dict['input']))

    if args_dict['addsuffix'] is not None:
        new_project.add_suffix(args_dict['addsuffix'])
    elif args_dict['removesuffix'] is not None:
        new_project.remove_suffix(args_dict['removesuffix'])
    else:
        # Check if the reference file exists
        if args_dict['reference'] is None or not os.path.isfile(
                args_dict['reference']):
            parser.print_help()
            sys.exit('Reference file does not exist!')

        # Read particles
        new_project.read_reference(args_dict['reference'])
        print('Read reference star file {}'.format(args_dict['reference']))

        # Prepare project
        new_project.replace_particle_img()

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Write output files
    new_project.write_output_files()
示例#27
0
def main():

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument("-i",
                        "--input",
                        type=str,
                        help="Class reference star file")
    parser.add_argument("-o",
                        "--output",
                        type=str,
                        help="Output directory",
                        default=None)
    parser.add_argument("-use-unmasked",
                        "--useunmasked",
                        action='store_true',
                        help='Use unmasked classes for alignment')
    parser.add_argument("-apix",
                        "--apix",
                        type=float,
                        help='Pixel size in anstroms',
                        default=1.82)
    parser.add_argument("-diameter",
                        "--diameter",
                        type=float,
                        help='Particle diameter in Anstroms',
                        default=1000)
    parser.add_argument("-numiter",
                        "--numiter",
                        type=int,
                        help='Number of iterations',
                        default=20)
    parser.add_argument("-sigma-psi",
                        "--sigmapsi",
                        type=float,
                        help="Sigma-psi for alignment of classes",
                        default=-1)
    parser.add_argument("-offset-range",
                        "--offsetrange",
                        type=int,
                        help="Offset range for alignment of classes",
                        default=10)

    args = parser.parse_args()

    # Prepare args dict
    args_dict = {
        'input': args.input,
        'output': args.output,
        'useunmasked': args.useunmasked,
        'apix': args.apix,
        'diameter': args.diameter,
        'numiter': args.numiter,
        'sigmapsi': args.sigmapsi,
        'offsetrange': args.offsetrange
    }

    # Check if the input file exists
    if args_dict['input'] is None:
        parser.print_help()
        sys.exit('Input file does not exist!')

    # Create an EM project object
    new_project = em.ProjectAlign2D(name='EMAlignClasses')
    new_project.set_output_directory(args_dict['output'], project_root='.')

    # Write parameters to args filename
    args_filename = new_project.output_directory + '/args.yaml'
    util.write_config_file(args_filename, args_dict)

    # Read particles
    new_project.read_class_refs(args_dict['input'])
    print('Read class reference file {}'.format(args_dict['input']))

    # Prepare input and output files
    new_project.prepare_io_files_star()

    # Set parameters
    new_project.set_params(args_dict['apix'], args_dict['diameter'])

    # Prepare project files
    new_project.prepare_project(use_unmasked_classes=args_dict['useunmasked'])

    # Normalize class averages
    new_project.normalize_class_refs()

    # Run relion
    new_project.set_relion_refine_args(offset_range=args_dict['offsetrange'],
                                       sigma_psi=args_dict['sigmapsi'],
                                       num_iter=args_dict['numiter'],
                                       firstiter_cc=False,
                                       T=4)
    new_project.run_refine2D()

    # Process 2D refine files
    new_project.prepare_refine2D()

    # Make transformed class stacks
    new_project.create_transformed_class_stacks()