def main(args): log = logging.getLogger('root') hdlr = logging.StreamHandler(sys.stdout) log.addHandler(hdlr) log.setLevel(logging.getLevelName(args.loglevel.upper())) dfs = [metadata.parse_fx_par(fn) for fn in args.input] n = dfs[0].shape[0] if not np.all(np.array([df.shape[0] for df in dfs]) == n): log.error("Input files are not aligned!") return 1 df = pd.concat(dfs, axis=0, ignore_index=True) df["CLASS"] = np.repeat(np.arange(1, len(dfs) + 1), n) if args.min_occ: df = df[df["OCC"] >= args.min_occ] df = df.sort_values(by="OCC") df = df.drop_duplicates("C", keep="last") df = df.sort_values(by="C") df = metadata.par2star(df, data_path=args.stack, apix=args.apix, cs=args.cs, ac=args.ac, kv=args.voltage, invert_eulers=args.relion) if args.cls is not None: df = star.select_classes(df, args.cls) star.write_star(args.output, df, reindex=True) return 0
def main(args): if args.data_path is None: args.data_path = args.input.rstrip(".par") + ".mrcs" print("No stack path provided, using %s" % args.data_path) df = parse_fx_par(args.input) df = par2star(df, data_path=args.data_path, apix=args.apix, cs=args.cs, ac=args.ac, kv=args.voltage) write_star(args.output, df, reindex=True) return 0
def main(args): par = [parse_par(inp) for inp in args.input] if len(par) > 1: idx = par[:, :, "OCC"].idxmax(axis=1) else: par = par[0] if args.data_path is not None: par["Input particle images"] = args.data_path if args.voltage is not None: par["Beam energy (keV)"] = args.voltage if args.cs is not None: par["Spherical aberration (mm)"] = args.cs if args.ac is not None: par["Amplitude contrast"] = args.ac if args.apix is not None: par["Pixel size of images (A)"] = args.apix star = par2star(par) write_star(args.output, star, reindex=True) return 0
def main(args): log = logging.getLogger('root') hdlr = logging.StreamHandler(sys.stdout) log.addHandler(hdlr) log.setLevel(logging.getLevelName(args.loglevel.upper())) dfs = [metadata.parse_fx_par(fn) for fn in args.input] n = dfs[0].shape[0] if not np.all(np.array([df.shape[0] for df in dfs]) == n): log.error("Input files are not aligned!") return 1 df = pd.concat(dfs, axis=0, ignore_index=True) df["CLASS"] = np.repeat(np.arange(1, len(dfs) + 1), n) if args.min_occ: df = df[df["OCC"] >= args.min_occ] df = df.sort_values(by="OCC") df = df.drop_duplicates("C", keep="last") df = df.sort_values(by="C") df.reset_index(inplace=True) if args.min_score is not None: if args.min_score < 1: args.min_score = np.percentile(df["SCORE"], (1 - args.min_score) * 100) df = df.loc[df["SCORE"] >= args.min_score] if args.merge is not None: dfo = star.parse_star(args.merge) args.apix = star.calculate_apix(dfo) args.cs = dfo.iloc[0][star.Relion.CS] args.ac = dfo.iloc[0][star.Relion.AC] args.voltage = dfo.iloc[0][star.Relion.VOLTAGE] df = metadata.par2star(df, data_path=args.stack, apix=args.apix, cs=args.cs, ac=args.ac, kv=args.voltage, invert_eulers=args.invert_eulers) if args.stack is None: df[star.UCSF.IMAGE_INDEX] = dfo[star.UCSF.IMAGE_INDEX] df[star.UCSF.IMAGE_PATH] = dfo[star.UCSF.IMAGE_PATH] key = [star.UCSF.IMAGE_INDEX, star.UCSF.IMAGE_PATH] fields = star.Relion.MICROGRAPH_COORDS + [ star.UCSF.IMAGE_ORIGINAL_INDEX, star.UCSF.IMAGE_ORIGINAL_PATH ] + [star.Relion.OPTICSGROUP ] + star.Relion.OPTICSGROUPTABLE + [star.Relion.RANDOMSUBSET] df = star.smart_merge(df, dfo, fields=fields, key=key) if args.revert_original: df = star.revert_original(df, inplace=True) else: df = metadata.par2star(df, data_path=args.stack, apix=args.apix, cs=args.cs, ac=args.ac, kv=args.voltage, invert_eulers=args.invert_eulers) if args.cls is not None: df = star.select_classes(df, args.cls) df = star.check_defaults(df, inplace=True) df = star.compatible(df, relion2=args.relion2, inplace=True) star.write_star(args.output, df, optics=(not args.relion2)) return 0
def main(args): log = logging.getLogger('root') hdlr = logging.StreamHandler(sys.stdout) log.addHandler(hdlr) log.setLevel(logging.getLevelName(args.loglevel.upper())) # apix = args.apix = hdr["xlen"] / hdr["nx"] for fn in args.input: if not (fn.endswith(".star") or fn.endswith(".mrcs") or fn.endswith(".mrc") or fn.endswith(".par")): log.error("Only .star, .mrc, .mrcs, and .par files supported") return 1 first_ptcl = 0 dfs = [] with mrc.ZSliceWriter(args.output) as writer: for fn in args.input: if fn.endswith(".star"): df = star.parse_star(fn, keep_index=False) star.augment_star_ucsf(df) star.set_original_fields(df, inplace=True) df = df.sort_values([ star.UCSF.IMAGE_ORIGINAL_PATH, star.UCSF.IMAGE_ORIGINAL_INDEX ]) gb = df.groupby(star.UCSF.IMAGE_ORIGINAL_PATH) for name, g in gb: with mrc.ZSliceReader(name) as reader: for i in g[star.UCSF.IMAGE_ORIGINAL_INDEX].values: writer.write(reader.read(i)) elif fn.endswith(".par"): if args.stack_path is None: log.error(".par file input requires --stack-path") return 1 df = metadata.par2star(metadata.parse_fx_par(fn), data_path=args.stack_path) # star.set_original_fields(df, inplace=True) # Redundant. star.augment_star_ucsf(df) elif fn.endswith(".csv"): return 1 elif fn.endswith(".cs"): return 1 else: if fn.endswith(".mrcs"): with mrc.ZSliceReader(fn) as reader: for img in reader: writer.write(img) df = pd.DataFrame({ star.UCSF.IMAGE_ORIGINAL_INDEX: np.arange(reader.nz) }) df[star.UCSF.IMAGE_ORIGINAL_PATH] = fn else: print("Unrecognized input file type") return 1 if args.star is not None: df[star.UCSF.IMAGE_INDEX] = np.arange(first_ptcl, first_ptcl + df.shape[0]) df[star.UCSF.IMAGE_PATH] = writer.path df["index"] = df[star.UCSF.IMAGE_INDEX] star.simplify_star_ucsf(df) dfs.append(df) first_ptcl += df.shape[0] if args.star is not None: df = pd.concat(dfs, join="inner") # df = pd.concat(dfs) # df = df.dropna(df, axis=1, how="any") star.write_star(args.star, df, reindex=True) return 0
def main(args): log = logging.getLogger('root') hdlr = logging.StreamHandler(sys.stdout) log.addHandler(hdlr) log.setLevel(logging.getLevelName(args.loglevel.upper())) # apix = args.apix = hdr["xlen"] / hdr["nx"] for fn in args.input: if not (fn.endswith(".star") or fn.endswith(".mrcs") or fn.endswith(".mrc") or fn.endswith(".par")): log.error("Only .star, .mrc, .mrcs, and .par files supported") return 1 first_ptcl = 0 dfs = [] with mrc.ZSliceWriter(args.output) as writer: for fn in args.input: if fn.endswith(".star"): df = star.parse_star(fn, augment=True) if args.cls is not None: df = star.select_classes(df, args.cls) star.set_original_fields(df, inplace=True) if args.resort: df = df.sort_values([star.UCSF.IMAGE_ORIGINAL_PATH, star.UCSF.IMAGE_ORIGINAL_INDEX]) for idx, row in df.iterrows(): if args.stack_path is not None: input_stack_path = os.path.join(args.stack_path, row[star.UCSF.IMAGE_ORIGINAL_PATH]) else: input_stack_path = row[star.UCSF.IMAGE_ORIGINAL_PATH] with mrc.ZSliceReader(input_stack_path) as reader: i = row[star.UCSF.IMAGE_ORIGINAL_INDEX] writer.write(reader.read(i)) elif fn.endswith(".par"): if args.stack_path is None: log.error(".par file input requires --stack-path") return 1 df = metadata.par2star(metadata.parse_fx_par(fn), data_path=args.stack_path) # star.set_original_fields(df, inplace=True) # Redundant. star.augment_star_ucsf(df) elif fn.endswith(".csv"): return 1 elif fn.endswith(".cs"): return 1 else: if fn.endswith(".mrcs"): with mrc.ZSliceReader(fn) as reader: for img in reader: writer.write(img) df = pd.DataFrame( {star.UCSF.IMAGE_ORIGINAL_INDEX: np.arange(reader.nz)}) df[star.UCSF.IMAGE_ORIGINAL_PATH] = fn else: print("Unrecognized input file type") return 1 if args.star is not None: df[star.UCSF.IMAGE_INDEX] = np.arange(first_ptcl, first_ptcl + df.shape[0]) if args.abs_path: df[star.UCSF.IMAGE_PATH] = writer.path else: df[star.UCSF.IMAGE_PATH] = os.path.relpath(writer.path, os.path.dirname(args.star)) df["index"] = df[star.UCSF.IMAGE_INDEX] star.simplify_star_ucsf(df) dfs.append(df) first_ptcl += df.shape[0] if args.star is not None: df = pd.concat(dfs, join="inner") # df = pd.concat(dfs) # df = df.dropna(df, axis=1, how="any") if not args.relion2: # Relion 3.1 style output. df = star.remove_deprecated_relion2(df, inplace=True) star.write_star(args.star, df, resort_records=False, optics=True) else: df = star.remove_new_relion31(df, inplace=True) star.write_star(args.star, df, resort_records=False, optics=False) return 0