Bsoft  2.1.0
Bernard's software package
bpartmulti.cpp
Go to the documentation of this file.
1 
9 #include "rwmg.h"
10 #include "mg_processing.h"
11 #include "mg_multiple.h"
12 #include "mg_particle_select.h"
13 #include "Matrix.h"
14 #include "utilities.h"
15 #include "options.h"
16 #include "timer.h"
17 
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20 
21 // Usage assistance
22 const char* use[] = {
23 " ",
24 "Usage: bpartmulti [options] input.star [input.star]",
25 "---------------------------------------------------",
26 "Selection and analysis of single particles from multiple parameter files.",
27 "Selects particles based on correlation coefficient values",
28 "returning the number of the input file with the best value.",
29 " ",
30 "Actions:",
31 "-reconstructions Operate on reconstruction parameters rather than micrographs.",
32 "-all Reset selection to all particles before other selections (default not).",
33 "-setasu D3 Set the views to the asymmetric unit.",
34 "-select var Select based on: fom (FOM), err (error between first 2),",
35 " rmsd (RMSD between first 2), msd or var (variance).",
36 "-merge Merge multiple files, keeping selected particle parameters.",
37 "-divide 3 Divide the project into a number of subsets of fields.",
38 "-Compare Compare selections.",
39 "-Statistics Do selection statistics.",
40 " ",
41 "Parameters:",
42 "-verbose 7 Verbosity of output.",
43 "-symmetry D6 Symmetry: Point group identifier.",
44 "-fom 0.2,2,1 FOM cutoff, index and flag to weigh with defocus (default 0,0,0).",
45 "-Origin 1.2 Origin deviation to accept (default 10 pixels).",
46 "-View 13.5 View deviation to accept (default 180 degrees).",
47 "-Angle 5.8 Rotation angle deviation to accept (default 180 degrees).",
48 "-Magnification 0.03 Magnification deviation to accept (default 2).",
49 " ",
50 "Input:",
51 "-template input.star Template parameter file to merge in data blocks from other input files.",
52 " ",
53 "Output:",
54 "-output file.star Output parameter file.",
55 " ",
56 NULL
57 };
58 
59 int main(int argc, char** argv)
60 {
61  // Initializing variables
62  int flags(0); // Flags to process reconstructions (bit 1), use template (bit 2), reset selections (bit 3)
63  Bstring selection_type;
64  int merge(0); // Flag to merge files
65  int divide(0); // Number of output project subsets
66  Bstring symmetry_string; // No symmetry specified
67  Bstring symmetry_asu; // Point group to set views to the asymmetric unit
68  double fom_cut(0); // Minimum FOM cutoff
69  int fom_index(0); // Index of FOM to use
70  int fom_def_flag(0); // Flag to adjust the cutoff for defocus
71  double origin_dev(10); // Origin deviation
72  double view_dev(M_PI); // View vector deviation
73  double angle_dev(M_PI); // View rotation angle deviation
74  double mag_dev(2); // Magnification deviation
75  int selection_compare(0); // Flag to compare selections
76  int selection_stats(0); // Flag to do selection statistics
77  Bstring masterfile; // Template parameter file
78  Bstring outfile; // Output parameter file
79 
80  int optind;
81  Boption* option = get_option_list(use, argc, argv, optind);
82  Boption* curropt;
83  for ( curropt = option; curropt; curropt = curropt->next ) {
84  if ( curropt->tag == "reconstructions" ) flags |= 1;
85  if ( curropt->tag == "all" ) flags |= 4;
86  if ( curropt->tag == "setasu" )
87  symmetry_asu = curropt->symmetry_string();
88  if ( curropt->tag == "merge" )
89  merge = 1;
90  if ( curropt->tag == "divide" )
91  if ( ( divide = curropt->value.integer() ) < 2 )
92  cerr << "-divide: A number of subsets must be specified!" << endl;
93  if ( curropt->tag == "select" ) {
94  selection_type = curropt->value.lower();
95  if ( selection_type.length() < 1 )
96  cerr << "-select: A selection type (fom/var/err) must be specified!" << endl;
97  }
98  if ( curropt->tag == "symmetry" )
99  symmetry_string = curropt->symmetry_string();
100  if ( curropt->tag == "fom" ) {
101  if ( curropt->values(fom_cut, fom_index, fom_def_flag) < 1 )
102  cerr << "-fom: A cutoff value must be specified" << endl;
103  else
104  selection_type = "fom";
105  }
106  if ( curropt->tag == "Origin" ) {
107  if ( ( origin_dev = curropt->value.real() ) <= 0 )
108  cerr << "-Origin: An acceptable origin deviation must be specified!" << endl;
109  else
110  if ( origin_dev < 0.01 ) origin_dev = 0.01;
111  }
112  if ( curropt->tag == "View" ) {
113  if ( ( view_dev = curropt->value.real() ) <= 0 )
114  cerr << "-View: An acceptable view deviation must be specified!" << endl;
115  else {
116  view_dev *= M_PI/180.0;
117  if ( view_dev < 0.001 ) view_dev = 0.001;
118  }
119  }
120  if ( curropt->tag == "Angle" ) {
121  if ( ( angle_dev = curropt->value.real() ) <= 0 )
122  cerr << "-Angle: An acceptable angle deviation must be specified!" << endl;
123  else {
124  angle_dev *= M_PI/180.0;
125  if ( angle_dev < 0.001 ) angle_dev = 0.001;
126  }
127  }
128  if ( curropt->tag == "Magnification" ) {
129  if ( ( mag_dev = curropt->value.real() ) <= 0 )
130  cerr << "-Magnification: An acceptable magnification deviation must be specified!" << endl;
131  else
132  if ( mag_dev < 0.0001 ) mag_dev = 0.0001;
133  }
134  if ( curropt->tag == "Compare" )
135  selection_compare = 1;
136  if ( curropt->tag == "Statistics" )
137  selection_stats = 1;
138  if ( curropt->tag == "template" )
139  masterfile = curropt->filename();
140  if ( curropt->tag == "output" )
141  outfile = curropt->filename();
142  }
143  option_kill(option);
144 
145  double ti = timer_start();
146 
147  Bsymmetry* sym = init_point_group_symmetry(symmetry_string);
148 
149  // Read all the parameter files
150  Bproject* first_project = NULL;
151  Bproject* project = NULL;
152  Bstring* file_list = NULL;
153  int np = 0;
154 
155  if ( merge ) {
156  if ( masterfile.length() ) {
157  flags |= 2;
158  string_add(&file_list, masterfile);
159  }
160  while ( optind < argc ) string_add(&file_list, argv[optind++]);
161  if ( !file_list ) {
162  cerr << "Error: No parameter or image files specified!" << endl;
163  bexit(-1);
164  }
165  first_project = project_multi_merge(file_list, fom_index, flags);
166  string_kill(file_list);
167  if ( flags & 4 ) part_reset_selection(first_project);
168  } else {
169  for ( np=0; optind < argc; np++ ) {
170  if ( first_project ) {
171  project->next = read_project(argv[optind++]);
172  project = project->next;
173  } else {
174  first_project = project = read_project(argv[optind++]);
175  }
176  if ( flags & 1 ) project->select = 1;
177 // project_show_selected(project);
178  }
179  if ( verbose & VERB_PROCESS )
180  cout << np << " parameter files read" << endl << endl;
181  if ( np < 1 ) {
182  cerr << "Error: No parameter or image files specified!" << endl;
183  bexit(-1);
184  }
185 
186  for ( project = first_project; project; project = project->next ) {
187  if ( flags & 4 ) part_reset_selection(project, 3);
188  if ( symmetry_asu.length() )
190  }
191 
192  if ( selection_type.contains("err") )
193  project_multi_select_low_difference(first_project, first_project->next, sym,
194  origin_dev, view_dev, angle_dev, mag_dev);
195 
196  if ( selection_type.contains("var") )
197  project_multi_select_low_variance(first_project, sym,
198  origin_dev, view_dev, angle_dev, mag_dev);
199 
200  if ( selection_type.contains("msd") )
201  project_multi_select_low_rmsd(first_project, first_project->next,
202  sym, origin_dev, view_dev, angle_dev, mag_dev,
203  1-selection_type.contains("rmsd"));
204 
205  if ( selection_type.contains("fom") )
206  project_multi_select_best_FOM(first_project, fom_cut, fom_index, fom_def_flag);
207 
208  if ( selection_compare )
209  project_multi_selection_compare(first_project, first_project->next);
210 
211  if ( selection_stats )
212  project_multi_selection_stats(first_project);
213 
214  // Delete all but the first project which should have all the results
215  project_kill(first_project->next);
216  first_project->next = NULL;
217  }
218 
219  if ( verbose & VERB_PROCESS )
220  project_show_selected(first_project);
221 
222  // Write an output parameter file if a name is given
223  Bstring filename;
224  if ( outfile.length() ) {
225  if ( divide > 1 ) {
226  project_divide(first_project, divide);
227  for ( np=1, project = first_project; project; project = project->next, np++ ) {
228  filename = outfile.pre_rev('.') + Bstring(np, "_%02d.") + outfile.post_rev('.');
229  write_project(filename, project, 0, 0);
230  }
231  } else {
232  write_project(outfile, first_project, 0, 0);
233  }
234  }
235 
236  project_kill(first_project);
237 
238  kill_symmetry(sym);
239 
240  if ( verbose & VERB_TIME )
241  timer_report(ti);
242 
243  bexit(0);
244 }
245 
Boption
A class for a command line input option.
Definition: options.h:26
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
mg_particle_select.h
Select particles.
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Bproject::next
Bproject * next
Definition: mg_processing.h:337
Bproject::select
int select
Definition: mg_processing.h:342
Bstring
Definition: Bstring.h:29
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
Boption::next
Boption * next
Definition: options.h:28
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
project_multi_select_low_difference
long project_multi_select_low_difference(Bproject *project1, Bproject *project2, Bsymmetry *sym, double origin_err, double view_err, double angle_err, double mag_err)
Selects the best particle orientations from two parameter files.
Definition: mg_multiple.cpp:769
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
Bsymmetry
Definition: symmetry.h:38
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
project_multi_select_low_rmsd
long project_multi_select_low_rmsd(Bproject *project1, Bproject *project2, Bsymmetry *sym, double origin_rmsd, double view_rmsd, double angle_rmsd, double mag_rmsd, int flag)
Selects the best particle orientations from two parameter files.
Definition: mg_multiple.cpp:920
project_multi_select_low_variance
long project_multi_select_low_variance(Bproject *project_list, Bsymmetry *sym, double origin_dev, double view_dev, double angle_dev, double mag_dev)
Selects the best particle orientations from multiple parameter files.
Definition: mg_multiple.cpp:598
Boption::value
Bstring value
Definition: options.h:30
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
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
main
int main(int argc, char **argv)
Definition: bpartmulti.cpp:59
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:233
verbose
int verbose
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
project_multi_selection_stats
long project_multi_selection_stats(Bproject *project_list)
Counts particle assignment distributions using selection arrays.
Definition: mg_multiple.cpp:460
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
utilities.h
Header file for general utilities.
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
merge
int merge(Bimage *p, int padd)
Pads an image and shifts it to the middle.
Definition: sin_gal.cpp:270
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
Matrix.h
Generalized matrix class.
mg_processing.h
Header file for micrograph processing.
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
project_multi_selection_compare
long project_multi_selection_compare(Bproject *project1, Bproject *project2)
Calculates the number of selections that are the same.
Definition: mg_multiple.cpp:1032
mg_multiple.h
Selection of single particle parameters from multiple files for classification.
project_multi_select_best_FOM
long project_multi_select_best_FOM(Bproject *project_list, double fom_cut, int fom_index, int fom_def_flag)
Selects the best particle orientations from multiple parameter files.
Definition: mg_multiple.cpp:338
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:316
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
use
const char * use[]
Definition: bpartmulti.cpp:22
project_multi_merge
Bproject * project_multi_merge(Bstring *file_list, int fom_index, int flags)
Merges multiple projects.
Definition: mg_multiple.cpp:68