Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def parse_barcode(ptcl_star):
    '''
    Parse barcode
    '''
    barcode_dict = {}
    if 'rlnParticleName' in ptcl_star:
        barcode_arr = ptcl_star['rlnParticleName'].strip().split(',')

        # Get barcode dictionary
        barcode_dict = util.parse_star_parameters(barcode_arr)

    return barcode_dict
Ejemplo n.º 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)
    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)
Ejemplo n.º 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("-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'])
Ejemplo n.º 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("-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()