Bsoft  2.1.0
Bernard's software package
bpartsel.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "mg_img_proc.h"
11 #include "mg_ctf.h"
12 #include "rwmg.h"
13 #include "mg_particle_select.h"
14 #include "ps_micrograph.h"
15 #include "symmetry.h"
16 #include "utilities.h"
17 #include "options.h"
18 #include "timer.h"
19 
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22 
23 // Usage assistance
24 const char* use[] = {
25 " ",
26 "Usage: bpartsel [options] input.star [input.star]",
27 "-------------------------------------------------",
28 "Selects single particles for reconstruction and further processing.",
29 "Input particle selections are honoured, so that multiple restrictive selections",
30 " can be made. To reset for a new selection, use the -all option.",
31 " ",
32 "Actions:",
33 "-check Check particle records.",
34 "-reconstructions Operate on reconstruction parameters rather than micrographs.",
35 "-renumber Renumber particles starting from 1 for each micrograph or reconstruction.",
36 "-all Reset selection to all particles before other selections.",
37 "-none Unset selection to all particles before other selections.",
38 "-mgselect 3-5,8,12-15 Select micrographs:",
39 " Argument: 4-11,34: Select by the indicated micrographs (first = 1).",
40 " Argument: part: Select only micrographs with selected particles.",
41 "-divide 3 Divide the project into a number of subsets of fields.",
42 "-consolidate 5 Consolidate selection under the given selection number.",
43 "-setnumber 3 Select given selection number and set others to zero.",
44 "-setfom 0.3 Set the FOM (must be in the range 0-1).",
45 "-setasu D3 Set the views to the asymmetric unit.",
46 "-setgroups Transfer selection numbers to groups.",
47 "-fixdefocus 0.15 Reset particle defocus differing from micrograph defocus.",
48 "-group 3022 Select particles belonging to this group.",
49 "-sets 20,1 Generate sets of this size of selected particles, ",
50 " with a flag not to select across micrograph or reconstruction boundaries.",
51 "-series 25,1 Select: Particles that are all selected in a series and generating sets",
52 " with a flag not to select across micrograph or reconstruction boundaries.",
53 "-frames 3,11 Select: Particles from a series of frames of a field-of-view.",
54 "-alternate 3 Select: Assign successive particles to different numbers.",
55 "-reselect psi,0.1,0.9 Reselect based on a range of values associated with this tag.",
56 "-origin 150,150,0,8 Select: Within a distance from the nominal origin: x,y,z,distance.",
57 "-View 0.2,-0.5,0.3,15 Select: Within an angular distance from a view: x,y,z,angle.",
58 "-sideview 17.8 Select: Side views within an angular distance from the equator.",
59 "-Euler 2,50,-30,2,0,40 Select: Euler angle ranges: psi, theta, phi.",
60 "-rank 4,1 Select a number of groups from FOM ranking and flag to adjust for defocus.",
61 "-fom 0.25,1 Select: FOM cutoff and flag to adjust for defocus.",
62 "-cv 0.55,1 Select: Cross validation cutoff and flag to adjust for defocus.",
63 "-exclusion 210 Select: Deselect overlapping particles (default 0).",
64 "-top 12.0,1 Select: number or % particles and flag to adjust for defocus, ranked by FOM[index].",
65 "-deviation -2.0 Select: FOM >= average + factor*standard_deviation, using FOM[index].",
66 "-angle 2.4 Select: difference angle between view vectors in focal or tilt series.",
67 "-closesttofocus Select: Particles from micrographs closest to focus.",
68 "-furthestfromfocus Select: Particles from micrographs furthest from focus.",
69 "-random 23.6% Select: random selection to get the given number, ",
70 " number in groups (g), fraction (<1) or percentage (%).",
71 "-bootstrap 527 Select: random selection with replacement up to the given number.",
72 "-views 4.5,7.2,3 Select: random selection within views defined on a grid with the ",
73 " given theta and phi step sizes (degrees) and up to the given number.",
74 "-bestviews 4.5,7.2,3 Select: best particles within views defined on a grid with the ",
75 " given theta and phi step sizes (degrees), up to the given number.",
76 "-maxsmooth 0.7,3,5,4.4 Select: above fraction specified by smoothed maxima surface.",
77 " given theta and phi step sizes and smoothing sigma (degrees).",
78 "-Fomfirst Set orientations to first in field-of-view series.",
79 "-Fombest Set orientations to best FOM[index] in field-of-view series.",
80 "-filament 60 Selects filament particles with clear direction based on percentage.",
81 "-deselect 4,6,22 Deselect particles with the listed selection numbers.",
82 "-getselection Prints all the selection numbers.",
83 "-show particle.fom Show particle parameters indicated by the tag or selection number.",
84 "-Fomhistogram 100,0.1.2 Show FOM histogram with parameters: bins, minimum and maximum.",
85 "-focus Show defocus minimum and maximum.",
86 "-reset defocus Reset particle defocus to micrograph defocus.",
87 "-delete Delete all non-selected particles from the parameter file.",
88 "-remove Do not write non-selected micrographs into the parameter file.",
89 " ",
90 "Parameters:",
91 "-verbose 7 Verbosity of output.",
92 "-symmetry C5 Point group symmetry (required with the -angle and -views options).",
93 "-index 1 FOM index to select on (default 0, options -setfom, -top, -deviation, -bestviews, -Fombest).",
94 " ",
95 "Output:",
96 "-output file.star Output parameter file.",
97 "-split 3 Split micrograph or reconstruction data blocks into individual files:",
98 " Argument: 1-6: number of digits inserted before extension",
99 " Argument: \"id\": micrograph ID's are used as file names.",
100 " Argument: \"set\": particle sets based on selection are used as output.",
101 "-Particle views.ps Postscript output with particle view and origin distributions.",
102 "-Micrograph out.ps Postscript output with particle micrograph distributions.",
103 "-FOM histogram.ps Postscript output with particle FOM distributions.",
104 "-classes Write stacks of particle images based on classes.",
105 " ",
106 NULL
107 };
108 
110 {
111  ifstream f(filename.c_str());
112  if ( f.fail() ) {
113  cerr << "File " << filename << " not read!" << endl;
114  bexit(-1);
115  }
116 
117  string s;
118  Bstring list;
119 
120  f >> s;
121  list = s;
122 
123  while ( !f.eof() ) {
124  f >> s;
125  list += "," + s;
126  }
127 
128  f.close();
129 
130  cout << list << endl;
131 
132  return list;
133 }
134 
135 
136 int main(int argc, char** argv)
137 {
138  // Initializing variables
139  int check_flag(0); // Flag to check particle records
140  int use_rec(0); // Flag to process reconstructions
141  int split(0); // Output one big STAR file
142  int symmetry_asu(0); // Set views to the asymmetric unit
143  Bstring symmetry_string("C1"); // Point group string
144  int renumber(0); // Flag to renumber particles
145  double max_def_dev(0); // Maximum defocus deviation allowed
146  int all(0); // Flag to reset selection
147  int unset(0); // Flag to unset selection
148  Bstring mgselect; // Micrograph selection
149  int divide(0); // Number of output project subsets
150  int consolidate(0); // Flag to combine selections
151  int set_number(0); // Selection number to keep
152  int set_groups(0); // Flag to transfer selection numbers to groups
153  int group(0); // Group to select
154  int set_size(0); // Size of sets
155  int set_flag(0); // Flag to keep set within micrograph
156  int select_series(0); // Size of sets and to select particles where all are selected in a series
157  int alternate(0); // Assign successive particles to different numbers
158  int frame_start(0), frame_end(1000); // Frame selection from a field-of-view series
159  double setfom(-1); // Set the FOM
160  Bstring tag_reselect; // STAR tag for reselection
161  double reselect_min(-1e37); // Reselection minimum
162  double reselect_max(1e37); // Reselection maximum
163  Vector3<double> origin; // Nominal origin
164  double dev_origin(0); // Maximum distance to accept
165  View view; // View to select around
166  double dev_angle(0); // Angle from view
167  double side_angle(0); // Angle from side view
168  double euler[6] = {0,0,0,0,0,0}; // Euler angle ranges
169  int ngroups(0); // Group selection turned off
170  double angle_cutoff(0); // No selection based on angle deviation between focal pairs
171  int fom_index(0); // Index of FOM
172  double fom_cutoff[5] = {0,0,0,0,0}; // No selection based on FOM
173  int fom_defocus_adjust[5] = {0,0,0,0,0}; // Flag to adjust the FOM cutoff by defocus
174  double excl_dist(0); // Minimum distance between particles
175  double fom_percentage(-1); // Percentage particles to accept
176  int fom_best(0); // Best number of particles to select
177  double fom_std_factor(-1e37); // FOM standard deviation multiplier for cutoff
178  long random_number(0); // Number of particles for random selection
179  double random_fraction(0); // Fraction of particles for random selection
180  long random_group(0); // Number of particles for random group selection
181  int bootstrap(0); // Number of particles for bootstrap selection
182  int nviews(0); // Number within views to select randomly
183  double threshfrac(0), maxsmooth(0);// Maxima smoothed surface for selection: fraction and sigma
184  int bestviews(0); // Best number within views to select
185  double theta_step(0), phi_step(0); // Anglular step sizes for views selection
186  int closest_to_focus(0); // Flag to select closest to focus
187  int furthest_from_focus(0); // Flag to select furthest from focus
188  int select_first_in_series(0); // Flag to select first in series
189  int select_best_in_series(0); // Flag to select best in series
190  int ps_flag(1); // Show bits: 1=views, 2=micrograph locations, 4=FOMs
191  double filament(0); // Flag and percentage to check filament directions
192  Bstring reset; // Reset a particle parameter from its micrograph
193  Bstring deselect; // List of particles to deselect
194  int delete_deselected(0); // Flag to delete deselected particles
195  int getselection(0); // Flag to show all selection numbers
196  int show(-1); // Show selected particles
197  Bstring tag_show; // STAR tag for parameter selection
198  long FOMbins(0); // Flag and bins to show the FOM histogram
199  double FOMmin(0), FOMmax(0); // FOM histogram minimum and maximum
200  int focus(0); // Flag to show minumum and maximum defocus
201  Bstring outfile; // Output parameter file name
202  Bstring outps; // Output postscript file name
203  Bstring FOMps; // Output postscript file name for FOM histogram
204  int write_classes(0); // Flag to write stacks of particle classes
205  int write_flags(0); // Flags to pass to the parameter file writing function
206 
207  int i, optind;
208  Boption* option = get_option_list(use, argc, argv, optind);
209  Boption* curropt;
210  for ( curropt = option; curropt; curropt = curropt->next ) {
211  if ( curropt->tag == "check" ) check_flag = 1;
212  if ( curropt->tag == "reconstructions" ) use_rec = 1;
213  if ( curropt->tag == "renumber" ) renumber = 1;
214  if ( curropt->tag == "all" ) all = 2;
215  if ( curropt->tag == "none" ) unset = 1;
216  if ( curropt->tag == "mgselect" ) mgselect = curropt->value;
217  if ( curropt->tag == "setasu" ) {
218  symmetry_asu = 1;
219  symmetry_string = curropt->symmetry_string();
220  }
221  if ( curropt->tag == "fixdefocus" ) {
222  if ( ( max_def_dev = curropt->value.real() ) < 0.001 )
223  cerr << "-fixdefocus: A defocus difference must be specified!" << endl;
224  else
225  if ( max_def_dev < 10 ) max_def_dev *= 1e4; // assume in um
226  }
227  if ( curropt->tag == "divide" )
228  if ( ( divide = curropt->value.integer() ) < 2 )
229  cerr << "-divide: A number of subsets must be specified!" << endl;
230  if ( curropt->tag == "consolidate" )
231  if ( ( consolidate = curropt->value.integer() ) < 1 )
232  cerr << "-consolidate: A number must be specified!" << endl;
233  if ( curropt->tag == "setnumber" )
234  if ( ( set_number = curropt->value.integer() ) < 1 )
235  cerr << "-setnumber: A selection number must be specified!" << endl;
236  if ( curropt->tag == "sets" )
237  if ( curropt->values(set_size, set_flag) < 1 )
238  cerr << "-sets: A set size must be specified!" << endl;
239  if ( curropt->tag == "setgroups" ) set_groups = 1;
240  if ( curropt->tag == "group" )
241  if ( ( group = curropt->value.integer() ) < 1 )
242  cerr << "-group: A group must be specified!" << endl;
243  if ( curropt->tag == "series" )
244  if ( curropt->values(select_series, set_flag) < 1 )
245  cerr << "-series: A set size must be specified!" << endl;
246  if ( curropt->tag == "frames" )
247  if ( curropt->values(frame_start, frame_end) < 1 )
248  cerr << "-frames: A starting frame must be specified!" << endl;
249  if ( curropt->tag == "alternate" )
250  if ( ( alternate = curropt->value.integer() ) < 2 )
251  cerr << "-alternate: A number must be specified!" << endl;
252  if ( curropt->tag == "setfom" ) {
253  if ( ( setfom = curropt->value.real() ) <= 0 )
254  cerr << "-setfom: A FOM value must be specified!" << endl;
255  else {
256  if ( setfom < 0 || setfom > 1 ) {
257  cerr << "-setfom: The FOM value must be in the range 0-1! The FOM will not be changed." << endl;
258  setfom = -1;
259  }
260  }
261  }
262  if ( curropt->tag == "reselect" ) {
263  tag_reselect = curropt->value;
264  Bstring* slist = tag_reselect.split(",");
265  tag_reselect = *slist;
266  reselect_min = slist->next->real();
267  reselect_max = slist->next->next->real();
268  string_kill(slist);
269  }
270  if ( curropt->tag == "origin" )
271  if ( curropt->values(origin[0], origin[1], origin[2], dev_origin) < 4 )
272  cerr << "-origin: A 3-value origin and a distance must be specified!" << endl;
273  if ( curropt->tag == "View" ) {
274  view = curropt->view();
275  if ( view.angle() ) dev_angle = view.angle();
276  }
277  if ( curropt->tag == "sideview" ) {
278  if ( ( side_angle = curropt->value.real() ) < 0.01 )
279  cerr << "-sideview: An angle must be specified!" << endl;
280  else
281  side_angle *= M_PI/180.0;
282  }
283  if ( curropt->tag == "Euler" ) {
284  vector<double> d = curropt->value.split_into_doubles(",");
285  for ( size_t i=0; i<d.size(); i++ ) euler[i] = d[i] * M_PI/180;
286  if ( d.size() < 6 )
287  cerr << "-Euler: All 6 values for Euler angle ranges must be specified!" << endl;
288  }
289  if ( curropt->tag == "rank" )
290  if ( curropt->values(ngroups, fom_defocus_adjust[0]) < 1 )
291  cerr << "-rank: The number of groups must be specified!" << endl;
292  if ( curropt->tag == "fom" ) {
293  if ( curropt->values(fom_cutoff[0], fom_defocus_adjust[0]) < 1 )
294  cerr << "-fom: A FOM cutoff must be specified!" << endl;
295  else
296  if ( fom_defocus_adjust[0] > 0 ) fom_defocus_adjust[0] = 1;
297  }
298  if ( curropt->tag == "cv" ) {
299  if ( curropt->values(fom_cutoff[1], fom_defocus_adjust[1]) < 1 )
300  cerr << "-cv: A cross validation cutoff must be specified!" << endl;
301  else
302  if ( fom_defocus_adjust[1] > 0 ) fom_defocus_adjust[1] = 1;
303  }
304  if ( curropt->tag == "exclusion" )
305  if ( ( excl_dist = curropt->value.real() ) <= 0 )
306  cerr << "-exclusion: An separation distance must be specified." << endl;
307  if ( curropt->tag == "top" ) {
308  if ( curropt->values(fom_percentage, fom_defocus_adjust[fom_index]) < 1 )
309  cerr << "-top: A percentage must be specified!" << endl;
310  if ( !curropt->value.contains("%") && !curropt->value.contains(".") ) {
311  fom_best = (int) fom_percentage;
312  fom_percentage = -1;
313  }
314  }
315  if ( curropt->tag == "deviation" )
316  if ( ( fom_std_factor = curropt->value.real() ) < 0.001 )
317  cerr << "-deviation: A standard deviation multiplying factor must be specified!" << endl;
318  if ( curropt->tag == "angle" ) {
319  if ( ( angle_cutoff = curropt->value.real() ) < 1 )
320  cerr << "-angle: An angle cutoff must be specified!" << endl;
321  else {
322  if ( angle_cutoff < 1 ) angle_cutoff = 1;
323  if ( angle_cutoff > 180 ) angle_cutoff = 180;
324  angle_cutoff *= M_PI/180.0;
325  }
326  }
327  if ( curropt->tag == "closesttofocus" )
328  closest_to_focus = 1;
329  if ( curropt->tag == "furthestfromfocus" )
330  furthest_from_focus = 1;
331  if ( curropt->tag == "Fombest" )
332  select_best_in_series = 1;
333  if ( curropt->tag == "Fomfirst" )
334  select_first_in_series = 1;
335  if ( curropt->tag == "filament" )
336  if ( ( filament = curropt->value.real() ) < 0.01 )
337  cerr << "-filament: A percentage must be specified!" << endl;
338  if ( curropt->tag == "deselect" )
339  deselect = curropt->value;
340  if ( curropt->tag == "getselection" )
341  getselection = 1;
342  if ( curropt->tag == "show" ) {
343  if ( ( show = curropt->value.integer() ) < 1 ) {
344  tag_show = curropt->value;
345  if ( tag_show.length() < 1 )
346  cerr << "-show: A selection number or tag must be specified!" << endl;
347  }
348  }
349  if ( curropt->tag == "Fomhistogram" )
350  if ( curropt->values(FOMbins, FOMmin, FOMmax) < 1 )
351  cerr << "-Fomhistogram: A number of bins must be specified!" << endl;
352  if ( curropt->tag == "focus" )
353  focus = 1;
354  if ( curropt->tag == "random" ) {
355  if ( curropt->value.contains("g") ) {
356  if ( ( random_group = curropt->value.integer() ) < 1 )
357  cerr << "-random: A group must be specified!" << endl;
358  } else if ( ( random_fraction = curropt->value.real() ) < 0.001 ) {
359  cerr << "-random: A number, fraction or percentage must be specified!" << endl;
360  } else {
361  if ( curropt->value.contains("%") ) {
362  random_fraction /= 100;
363  } else if ( random_fraction >= 1.0 ) {
364  random_number = (long) random_fraction;
365  random_fraction = 0;
366  }
367  }
368  }
369  if ( curropt->tag == "bootstrap" )
370  if ( ( bootstrap = curropt->value.integer() ) < 1 )
371  cerr << "-bootstrap: A number of particles must be specified!" << endl;
372  if ( curropt->tag == "views" ) {
373  if ( curropt->values(theta_step, phi_step, nviews) < 3 )
374  cerr << "-views: Two angles and a number of particles must be specified!" << endl;
375  else {
376  theta_step *= M_PI/180.0;
377  phi_step *= M_PI/180.0;
378  }
379  }
380  if ( curropt->tag == "bestviews" ) {
381  if ( curropt->values(theta_step, phi_step, bestviews) < 3 )
382  cerr << "-bestviews: Two angles and a number of particles must be specified!" << endl;
383  else {
384  theta_step *= M_PI/180.0;
385  phi_step *= M_PI/180.0;
386  }
387  }
388  if ( curropt->tag == "maxsmooth" ) {
389  if ( curropt->values(threshfrac, theta_step, phi_step, maxsmooth) < 4 )
390  cerr << "-maxsmooth: A fraction, two angles and a sigma value must be specified!" << endl;
391  else {
392  theta_step *= M_PI/180.0;
393  phi_step *= M_PI/180.0;
394  maxsmooth *= M_PI/180.0;
395  }
396  }
397  if ( curropt->tag == "symmetry" )
398  symmetry_string = curropt->symmetry_string();
399  if ( curropt->tag == "index" ) {
400  if ( ( fom_index = curropt->value.integer() ) < 0 )
401  cerr << "-index: A FOM index must be specified!" << endl;
402  else if ( fom_index < 0 || fom_index >= NFOM ) fom_index = 0;
403  }
404  if ( curropt->tag == "reset" )
405  reset = curropt->value;
406  if ( curropt->tag == "delete" )
407  delete_deselected = 1;
408  if ( curropt->tag == "remove" ) write_flags |= 2;
409  if ( curropt->tag == "output" )
410  outfile = curropt->filename();
411  if ( curropt->tag == "split" ) {
412  if ( curropt->value.contains("id") || curropt->value.contains("ID") ) split = 9;
413  else if ( curropt->value.contains("set") || curropt->value.contains("SET") ) split = -1;
414  else if ( ( split = curropt->value.integer() ) < 1 )
415  cerr << "-split: An integer must be specified!" << endl;
416  else
417  if ( split > 6 ) split = 6;
418  }
419  if ( curropt->tag == "Particle" ) {
420  outps = curropt->filename();
421  ps_flag |= 1;
422  }
423  if ( curropt->tag == "Micrograph" ) {
424  outps = curropt->filename();
425  ps_flag |= 2;
426  }
427  if ( curropt->tag == "FOM" ) {
428  FOMps = curropt->filename();
429  ps_flag |= 4;
430  }
431  if ( curropt->tag == "classes" ) write_classes = 1;
432  }
433  option_kill(option);
434 
435  double ti = timer_start();
436 
437  // Read all the parameter files
438  Bstring* file_list = NULL;
439  while ( optind < argc ) string_add(&file_list, argv[optind++]);
440  if ( !file_list ) {
441  cerr << "Error: No parameter or image files specified!" << endl;
442  bexit(-1);
443  }
444 
445  Bproject* project = read_project(file_list, check_flag);
446  string_kill(file_list);
447 
448  if ( !project ) {
449  cerr << "Error: Input file not read!" << endl;
450  bexit(-1);
451  }
452 
453  if ( use_rec ) project->select = 1;
454 
455  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
456 
457  if ( renumber ) project_renumber_particles(project);
458 
459  if ( all ) part_reset_selection(project, all);
460 
461  if ( unset ) part_unset_selection(project);
462 
463  if ( mgselect.length() ) {
464  if ( mgselect[0] == 'p' ) project_select_with_particles(project, -1);
465  else part_select_micrograph(project, mgselect);
466  }
467 
468  if ( group > 0 ) part_select_group(project, group);
469 
470  if ( consolidate ) part_consolidate_selection(project, consolidate);
471 
472  if ( alternate > 0 ) part_set_multi_maps(project, -1, alternate);
473 
474  if ( set_number ) part_set_selection(project, set_number);
475 
476  if ( reset.length() ) project_reset(project, reset);
477 
478  if ( tag_reselect.length() )
479  part_reselect(project, tag_reselect, reselect_min, reselect_max);
480 
481  if ( symmetry_asu )
482  project_set_particle_asu_views(project, symmetry_string);
483 
484  if ( max_def_dev )
485  part_fix_defocus(project, max_def_dev);
486 
487  if ( dev_origin )
488  part_origin_select(project, origin, dev_origin);
489 
490  if ( dev_angle )
491  part_view_select(project, view, dev_angle);
492 
493  if ( side_angle )
494  part_side_view_select(project, side_angle);
495 
496  if ( euler[0]+euler[2]+euler[4] != 0 || euler[1]+euler[3]+euler[5] != 0 )
498 
499  for ( i=0; i<5; i++ ) {
500  if ( fom_cutoff[i] ) {
501  if ( fom_defocus_adjust[i] )
502  part_fom_defocus_fit_deselect(project, i, fom_cutoff[i]);
503  else
504  part_deselect(project, i, fom_cutoff[i]);
505  }
506  }
507 
508  if ( excl_dist )
509  part_deselect_redundant(project, excl_dist, -1, fom_index);
510 
511 
512  if ( fom_percentage >= 0 )
513  part_select_percentage(project, fom_percentage, fom_index, fom_defocus_adjust[fom_index]);
514 
515  if ( fom_best > 0 )
516  part_select_best(project, fom_best, fom_index, fom_defocus_adjust[fom_index]);
517 
518  if ( fom_std_factor > -1e36 )
519  part_select_FOM_avg_std(project, fom_std_factor, fom_index);
520 
521  if ( angle_cutoff )
522  part_series_comparison(project, sym, angle_cutoff);
523 
524  if ( closest_to_focus )
526 
527  if ( furthest_from_focus )
529 
530  if ( select_first_in_series )
532 
533  if ( select_best_in_series )
535 
536  if ( ngroups > 1 )
537  part_select_FOM_groups(project, ngroups, fom_index, fom_defocus_adjust[fom_index]);
538 
539  if ( random_number )
540  part_select_random(project, random_number);
541  else if ( random_fraction )
542  part_select_random_fraction(project, random_fraction);
543  else if ( random_group )
544  part_select_random_group(project, random_group);
545 
546  if ( bootstrap )
547  part_select_bootstrap(project, bootstrap);
548 
549  if ( nviews )
550  part_select_random_within_view(project, sym, theta_step, phi_step, nviews);
551 
552  if ( maxsmooth )
553  part_select_maxsmooth(project, sym, theta_step, phi_step, threshfrac, maxsmooth, fom_index);
554 
555  if ( bestviews )
556  part_select_best_within_view(project, sym, theta_step, phi_step, bestviews, fom_index);
557 
558  if ( setfom > -1 )
559  part_set_FOM(project, fom_index, setfom);
560 
561  if ( select_series ) part_select_series(project, select_series, set_flag);
562 
563  if ( set_size ) part_select_sets(project, set_size, set_flag);
564 
565  if ( frame_start ) part_select_frames(project, frame_start, frame_end);
566 
567  if ( filament > 0 ) part_filament_direction(project, filament);
568 
569  if ( set_groups ) part_select_to_group(project);
570 
571  if ( deselect.length() ) {
572  if ( deselect.contains(".") ) deselect = read_list(deselect);
573  part_deselect_from_list(project, deselect);
575  deselect = 0;
576  }
577 
578  if ( delete_deselected ) part_delete_deselected(project);
579 
582 
583  if ( getselection ) project_show_selection_numbers(project);
584 
586  if ( tag_show.length() > 0 ) {
587  if ( tag_show.contains("micro") ) project_show_mg_parameter(project, tag_show);
588  else project_show_part_parameter(project, tag_show);
589  }
590 
591  Bstring title;
592  if ( FOMbins > 1 )
593  project_show_fom_histogram(project, FOMbins, FOMmin, FOMmax);
594 
595  if ( focus ) project_defocus_range(project);
596 
597  if ( FOMps.length() )
599 
600  if ( outps.length() ) {
601  if ( ps_flag & 1 ) {
602  title = "Particle view distributions";
603  ps_particle_views_origins(outps, title, symmetry_string, project, -1);
604  } else {
605  title = "Particle micrograph distributions";
606  ps_mg_particle_positions(outps, title, project);
607  }
608  }
609 
610  if ( write_classes )
612 
613  // Write an output parameter format file if a name is given
614  if ( project && ( outfile.length() || split == 9 ) ) {
615  if ( divide > 1 ) {
616  Bstring filename;
617  Bproject* project2;
618  project_divide(project, divide);
619  for ( i=1, project2 = project; project2; project2 = project2->next, ++i ) {
620  filename = outfile.pre_rev('.') + Bstring(i, "_%02d.") + outfile.post_rev('.');
621  write_project(filename, project2, write_flags);
622  }
623  } else if ( split < 0 ) {
624  project_split_write(outfile, project);
625  } else {
626  project->split = split;
627  write_project(outfile, project, write_flags);
628  }
629  }
630 
631  kill_symmetry(sym);
632 
634 
635  if ( verbose & VERB_TIME )
636  timer_report(ti);
637 
638  bexit(0);
639 }
640 
Boption
A class for a command line input option.
Definition: options.h:26
part_series_comparison
double part_series_comparison(Bproject *project, Bsymmetry *sym, double angle_cutoff)
A function to select particles based on comparison of the orientations within a series.
Definition: mg_particle_select.cpp:828
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
mg_particle_select.h
Select particles.
part_set_selection
long part_set_selection(Bproject *project, int number)
Selects one selection number and sets all others to zero.
Definition: mg_particle_select.cpp:317
part_set_first_view_in_series
long part_set_first_view_in_series(Bproject *project)
Sets all orientation parameters for a particle to the first in the set.
Definition: mg_particle_select.cpp:2343
ps_micrograph.h
Header file for postscript tools dealing with micrograph particle sets.
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
project_show_selected_parameters
long project_show_selected_parameters(Bproject *project, int show)
Shows the selected particle parameters in a project.
Definition: mg_select.cpp:1098
project_trim_class_averages
int project_trim_class_averages(Bproject *project, Bstring &list)
Deletes selected class averages from the project..
Definition: mg_img_proc.cpp:1029
Bproject::next
Bproject * next
Definition: mg_processing.h:337
Bproject::select
int select
Definition: mg_processing.h:342
NFOM
#define NFOM
Definition: mg_processing.h:16
ps_particle_views_origins
int ps_particle_views_origins(Bstring &filename, Bstring &title, Bstring &symmetry_string, Bproject *project, int selection)
Generates asymmetric unit particle view and origin postscript plots.
Definition: ps_micrograph.cpp:121
Bstring
Definition: Bstring.h:29
project_defocus_range
JSvalue project_defocus_range(Bproject *project)
Determines the minimum and maximum defocus values.
Definition: mg_ctf.cpp:1211
Bproject::split
int split
Definition: mg_processing.h:340
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
project_divide
long project_divide(Bproject *project, long n)
Divides a project into a number of micrograph subsets.
Definition: mg_processing.cpp:1204
Bstring::integer
long integer()
Definition: Bstring.cpp:547
symmetry.h
Header file for general symmetry functions.
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
part_select_best_within_view
long part_select_best_within_view(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, int number, int fom_index)
Selects the best number of particles within each view.
Definition: mg_particle_select.cpp:1659
part_select_group
long part_select_group(Bproject *project, int group)
Selects particles with a given group identifier.
Definition: mg_particle_select.cpp:1792
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
use
const char * use[]
Definition: bpartsel.cpp:24
project_show_class_averages
long project_show_class_averages(Bproject *project)
Shows the class averages in a project.
Definition: mg_processing.cpp:1617
part_reselect
long part_reselect(Bproject *project, Bstring &tag, double reselect_min, double reselect_max)
Reselects particles identified by an input STAR tag and between a minimum and maximum.
Definition: mg_particle_select.cpp:749
View
Definition: View.h:26
ps_mg_particle_positions
int ps_mg_particle_positions(Bstring &filename, Bstring &title, Bproject *project)
Postscript plot of the positions of particles on micrographs.
Definition: ps_micrograph.cpp:30
part_select_to_group
long part_select_to_group(Bproject *project)
Transfer selection numbers to the group identifiers.
Definition: mg_particle_select.cpp:1748
Boption::view
View view()
Definition: options.h:247
Bsymmetry
Definition: symmetry.h:38
part_deselect_from_list
long part_deselect_from_list(Bproject *project, Bstring list)
Deselects particles with selection numbers from a list.
Definition: mg_particle_select.cpp:412
part_set_best_view_in_series
long part_set_best_view_in_series(Bproject *project, int fom_index)
Sets all orientation parameters for a particle to the best in the set.
Definition: mg_particle_select.cpp:2377
part_deselect_redundant
long part_deselect_redundant(Bparticle *partlist, double excl_dist, int part_select, int fom_index)
Deselects particles overlapping with better ones.
Definition: mg_particle_select.cpp:520
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
part_consolidate_selection
long part_consolidate_selection(Bproject *project, int number)
Consolidates selected particles under one selection number.
Definition: mg_particle_select.cpp:283
part_view_select
long part_view_select(Bproject *project, View view, double angle)
Selects particles based on a distance from a reference view.
Definition: mg_particle_select.cpp:2130
part_set_multi_maps
long part_set_multi_maps(Bproject *project, int part_select, int nmaps)
Sets selection for generating multiple maps.
Definition: mg_particle_select.cpp:590
part_select_random_fraction
long part_select_random_fraction(Bproject *project, double fraction)
Selects particles randomly based on a fraction of the total.
Definition: mg_particle_select.cpp:1243
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
rwmg.h
Header file for reading and writing micrograph parameters.
project_show_selected
long project_show_selected(Bproject *project)
Shows the selected particles in a project.
Definition: mg_select.cpp:907
part_reset_selection
long part_reset_selection(Bproject *project, int flag=0)
Resets selection to all particles.
Definition: mg_particle_select.cpp:133
part_filament_direction
long part_filament_direction(Bproject *project, double minpct)
Checks the direction of particles associated with filaments.
Definition: mg_particle_select.cpp:2081
part_select_furthest_from_focus
long part_select_furthest_from_focus(Bproject *project)
Deselects all particles except those from micrographs furthest from focus.
Definition: mg_particle_select.cpp:2699
part_deselect
long part_deselect(Bproject *project, int fom_index, double fommin, double fommax=1e30)
Deselects particles below a given FOM cutoff.
Definition: mg_particle_select.cpp:468
part_select_maxsmooth
long part_select_maxsmooth(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, double threshfrac, double sigma, int fom_index)
Selects particles based on a smoothed maximum surface.
Definition: mg_particle_select.cpp:1546
ps_part_fom_histogram
int ps_part_fom_histogram(Bstring &filename, Bproject *project)
Postscript plot of the particle FOM histogram.
Definition: ps_micrograph.cpp:382
part_select_random_group
long part_select_random_group(Bproject *project, long number)
Selects groups randomly to give at least a number of particles.
Definition: mg_particle_select.cpp:1292
verbose
int verbose
part_side_view_select
long part_side_view_select(Bproject *project, double angle)
Selects particles based on a distance from a side view.
Definition: mg_particle_select.cpp:2181
part_set_FOM
long part_set_FOM(Bproject *project, int fom_index, double fom)
Sets the FOM for all particles.
Definition: mg_particle_select.cpp:382
project_write_particle_classes
int project_write_particle_classes(Bproject *project)
Writes particles to different stacks based on class.
Definition: mg_img_proc.cpp:959
Boption::value
Bstring value
Definition: options.h:30
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
part_fix_defocus
long part_fix_defocus(Bproject *project, double max_dev)
Resets defocus values for particles thata are too far off.
Definition: mg_particle_select.cpp:2804
project_set_particle_asu_views
int project_set_particle_asu_views(Bproject *project, Bstring &symmetry_asu)
Sets particle views within the asymmetric unit.
Definition: mg_processing.cpp:2383
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:109
project_show_fom_histogram
long project_show_fom_histogram(Bproject *project, long bins, double min, double max)
Shows a histogram of the FOM values.
Definition: mg_select.cpp:1319
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
show
int show(0)
part_fom_defocus_fit_deselect
double part_fom_defocus_fit_deselect(Bproject *project, int fom_index, double cutoff)
Deselects particles below a given FOM cutoff, adjusted for the defocus.
Definition: mg_particle_select.cpp:2644
part_select_FOM_avg_std
long part_select_FOM_avg_std(Bproject *project, double factor, int fom_index)
Selects particles based on FOM average and standard deviation.
Definition: mg_particle_select.cpp:1108
part_select_best
long part_select_best(Bproject *project, long number, int fom_index, int defocus_fit)
Selects the best particles based on the FOM.
Definition: mg_particle_select.cpp:1052
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:673
part_select_percentage
long part_select_percentage(Bproject *project, double percentage, int fom_index, int defocus_fit)
Selects a percentage of particles based on the FOM.
Definition: mg_particle_select.cpp:995
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:233
project_show_selection_numbers
long project_show_selection_numbers(Bproject *project)
Shows the selection numbers for the particles in a project.
Definition: mg_select.cpp:852
mg_img_proc.h
Header file for image processing from micrograph structures.
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
project_show_part_parameter
long project_show_part_parameter(Bproject *project, Bstring &tag)
Shows the particle parameter indicated by the tag in a project.
Definition: mg_select.cpp:1268
part_select_bootstrap
long part_select_bootstrap(Bproject *project, int number)
Selects a given number of particles randomly with replacement.
Definition: mg_particle_select.cpp:1383
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
M_PI
#define M_PI
Definition: utilities.h:63
project_split_write
int project_split_write(Bstring &filename, Bproject *project)
Splits a project into sets of particle selections and write the files.
Definition: rwmg.cpp:742
utilities.h
Header file for general utilities.
part_select_FOM_groups
long part_select_FOM_groups(Bproject *project, int ngroups, int fom_index, int defocus_fit)
Selects groups of particles based on the FOM.
Definition: mg_particle_select.cpp:945
part_select_sets
long part_select_sets(Bproject *project, int size, int flag)
Selects sets of particles, each set with the same size.
Definition: mg_particle_select.cpp:1841
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
Bstring::length
long length() const
Definition: Bstring.cpp:263
init_point_group_symmetry
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
Definition: symmetry.cpp:39
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
project_renumber_particles
long project_renumber_particles(Bproject *project)
Renumbers particles.
Definition: mg_processing.cpp:2247
part_select_series
long part_select_series(Bproject *project, int size, int flag)
Select series where all are already selected.
Definition: mg_particle_select.cpp:2421
Bstring::next
Bstring * next
Definition: Bstring.h:31
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
part_unset_selection
long part_unset_selection(Bproject *project)
Unsets selection to no particles.
Definition: mg_particle_select.cpp:168
mg_processing.h
Header file for micrograph processing.
project_show_mg_parameter
long project_show_mg_parameter(Bproject *project, Bstring &tag)
Shows the micrograph parameter indicated by the tag in a project.
Definition: mg_select.cpp:1240
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
Boption::filename
Bstring filename()
Definition: options.h:85
part_delete_deselected
long part_delete_deselected(Bproject *project)
Deletes deselected particles and renumber the remaining.
Definition: mg_particle_select.cpp:2729
part_euler_angle_select
long part_euler_angle_select(Bproject *project, double *euler6)
Selects particles based on Euler angle limits.
Definition: mg_particle_select.cpp:2229
Bstring::split
Bstring * split()
Definition: Bstring.cpp:605
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
part_select_random
long part_select_random(Bproject *project, long number)
Selects a specific number of particles randomly.
Definition: mg_particle_select.cpp:1163
part_select_frames
long part_select_frames(Bproject *project, int frame_start, int frame_end)
Select particles from frames in a series.
Definition: mg_particle_select.cpp:1924
project_select_with_particles
long project_select_with_particles(Bproject *project, long part_sel)
Selects micrographs with particles.
Definition: mg_select.cpp:1541
project_reset
long project_reset(Bproject *project, Bstring &reset)
Reset a particle parameter from its micrograph.
Definition: mg_processing.cpp:2516
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
part_select_closest_to_focus
long part_select_closest_to_focus(Bproject *project)
Deselects all particles except those from micrographs closest to focus.
Definition: mg_particle_select.cpp:2669
main
int main(int argc, char **argv)
Definition: bpartsel.cpp:136
part_select_micrograph
long part_select_micrograph(Bproject *project, Bstring &mgselect)
Sets selection to the micrographs indicated.
Definition: mg_particle_select.cpp:247
part_select_random_within_view
long part_select_random_within_view(Bproject *project, Bsymmetry *sym, double theta_step, double phi_step, int number)
Selects a given number of particles within each view.
Definition: mg_particle_select.cpp:1442
View::angle
double angle()
Definition: View.h:98
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
read_list
Bstring read_list(Bstring filename)
Definition: bpartsel.cpp:109
part_origin_select
long part_origin_select(Bproject *project, Vector3< double > origin, double distance)
Selects particles based on the distance from the nominal origin.
Definition: mg_particle_select.cpp:2291