Skip to content

Instantly share code, notes, and snippets.

@alisterburt
Created October 2, 2020 21:08
Show Gist options
  • Save alisterburt/6fc7381aa7f48b3e1dd32ab6428448bf to your computer and use it in GitHub Desktop.
Save alisterburt/6fc7381aa7f48b3e1dd32ab6428448bf to your computer and use it in GitHub Desktop.
select classes from relion STAR files
#!/usr/bin/env python
import click
import starfile
@click.command()
@click.option('--star_file', prompt='Input STAR file')
@click.option('--class_idx', type=int, prompt='Class number')
def class_select(star_file, class_idx):
star = starfile.read(star_file)
subset = star[star['rlnClassNumber']==class_idx]
out_fname = star_file.replace(f'.star', f'_class{class_idx}.star')
starfile.write(subset, out_fname)
click.echo(f'Before: {star.shape[0]} particles')
click.echo(f'After: {subset.shape[0]} particles')
return
if __name__ == '__main__':
class_select()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment