| Bsoft 2.0.5 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) 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 name
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);
188 if ( symmetry_asu.length() )
189 project_set_particle_asu_views(project, symmetry_asu);
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("rmsd") )
201 project_multi_select_low_rmsd(first_project, first_project->next, sym,
202 origin_dev, view_dev, angle_dev, mag_dev);
203
204 if ( selection_type.contains("fom") )
205 project_multi_select_best_FOM(first_project, fom_cut, fom_index, fom_def_flag);
206
207 if ( selection_compare )
208 project_multi_selection_compare(first_project, first_project->next);
209
210 if ( selection_stats )
211 project_multi_selection_stats(first_project);
212
213 // Delete all but the first project which should have all the results
214 project_kill(first_project->next);
215 first_project->next = NULL;
216 }
217
218 if ( verbose & VERB_PROCESS )
219 project_show_selected(first_project);
220
221 // Write an output parameter file if a name is given
222 Bstring filename;
223 if ( outfile.length() ) {
224 project_update_comment(first_project, argc, argv);
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
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
rwmg.h
Header file for reading and writing micrograph parameters.
Bstring::real
double real()
Definition: Bstring.cpp:545
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
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:595
Boption::symmetry_string
Bstring symmetry_string()
Definition: options.h:245
mg_particle_select.h
Select particles.
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:3792
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:1012
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
Matrix.h
Generalized matrix class.
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
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_show_selected
long project_show_selected(Bproject *project)
Shows the selected particles in a project.
Definition: mg_processing.cpp:2446
mg_multiple.h
Selection of single particle parameters from multiple files for classification.
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
M_PI
#define M_PI
Definition: utilities.h:59
Boption
A class for a command line input option.
Definition: options.h:26
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:766
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
verbose
int verbose
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
merge
int merge(Bimage *p, int padd)
Pads an image and shifts it to the middle.
Definition: sin_gal.cpp:270
main
int main(int argc, char **argv)
Definition: bpartmulti.cpp:59
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:335
Bproject::next
Bproject * next
Definition: mg_processing.h:334
part_reset_selection
long part_reset_selection(Bproject *project)
Resets selection to all particles.
Definition: mg_particle_select.cpp:131
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bsymmetry
Definition: symmetry.h:38
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
Bproject::select
int select
Definition: mg_processing.h:339
project_divide
long project_divide(Bproject *project, long n)
Divides a project into a number of micrograph subsets.
Definition: mg_processing.cpp:1962
project_multi_merge
Bproject * project_multi_merge(Bstring *file_list, int fom_index, int flags)
Merges multiple projects.
Definition: mg_multiple.cpp:65
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)
Selects the best particle orientations from two parameter files.
Definition: mg_multiple.cpp:916
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:308
use
const char * use[]
Definition: bpartmulti.cpp:22
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
mg_processing.h
Header file for micrograph processing.
options.h
Header file for option handlers.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
project_update_comment
int project_update_comment(Bproject *project, int n, char **strings)
Puts a set of strings and time in the main comment of a project.
Definition: rwmg.cpp:468
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
project_multi_selection_stats
long project_multi_selection_stats(Bproject *project_list)
Counts particle assignment distributions using selection arrays.
Definition: mg_multiple.cpp:457
Bproject
Definition: mg_processing.h:333
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760