| Bsoft 2.0.5 Bernard's software package

bpart.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_particles.h"
11 #include "rwmg.h"
12 #include "mg_particle_select.h"
13 #include "rwimg.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: bpart [options] input.star [input.star]",
25 "----------------------------------------------",
26 "Manipulates single particle images.",
27 " ",
28 "Actions:",
29 "-reconstructions Operate on reconstruction parameters rather than micrographs.",
30 "-all Reset selection to all particles before other selections.",
31 "-find 20 Finds the centers of the particle images (iterations).",
32 "-shift Center the actual particle images (new images with \"_cen\" in names).",
33 "-align Output aligned particle images (new images with \"_aln\" in names).",
34 "-rescale -0.1,5.2 Rescale particle images to average and standard deviation.",
35 "-settilt -30,45 Set micrograph tilt, axis and particle defocus.",
36 "-calctilt Calculate micrograph tilt parameters from particle defocus.",
37 " ",
38 "Parameters:",
39 "-verbose 7 Verbosity of output.",
40 "-select 14 Selection number of particles to process (default all selected).",
41 "-resolution 10,500 Resolution limits for cross-correlation (angstrom, default 20,1000).",
42 "-partpath dir/subdir Set the particle file paths.",
43 " ",
44 "Input:",
45 "-mask mask.pif Intput 3D mask file to mask particles.",
46 " ",
47 "Output:",
48 "-output file.star Output parameter file.",
49 "-reference file.pif Composite image reference file.",
50 " ",
51 NULL
52 };
53
54
55 int main(int argc, char** argv)
56 {
57 // Initializing variables
58 int use_rec(0); // Flag to process reconstructions
59 int reset(0); // Keep selection as read from file
60 int find(0); // Iterations to find the centers
61 int shift(0); // Flag to shift the actual images
62 int align(0); // Flag to align images
63 double nuavg(0), nustd(0); // Rescaling to average and stdev
64 int calc_tilt(0); // Flag to calculate micrograph tilt parameters
65 double axis(0), tilt(0); // Tilt axis and angle to set
66 int part_select(-1); // Process all selected particles
67 double hires(20); // High resolution limit
68 double lores(1000); // Low resolution limit
69 Bstring partpath; // Particle file path
70 Bstring maskfile; // Particle mask file
71 Bstring outfile; // Output parameter file
72 Bstring reffile; // Composite image reference file
73
74 int optind;
75 Boption* option = get_option_list(use, argc, argv, optind);
76 Boption* curropt;
77 for ( curropt = option; curropt; curropt = curropt->next ) {
78 if ( curropt->tag == "reconstructions" ) use_rec = 1;
79 if ( curropt->tag == "all" ) reset = 1;
80 if ( curropt->tag == "find" )
81 if ( ( find = curropt->value.integer() ) < 1 )
82 cerr << "-find: A number of iterations must be specified!" << endl;
83 if ( curropt->tag == "shift" ) shift = 1;
84 if ( curropt->tag == "align" ) align = 1;
85 if ( curropt->tag == "rescale" )
86 if ( curropt->values(nuavg, nustd) < 2 )
87 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
88 if ( curropt->tag == "calctilt" ) calc_tilt = 1;
89 if ( curropt->tag == "settilt" ) {
90 if ( curropt->values(tilt, axis) < 1 )
91 cerr << "-settilt: A tilt angle must be specified!" << endl;
92 else {
93 tilt *= M_PI/180.0;
94 axis *= M_PI/180.0;
95 }
96 }
97 if ( curropt->tag == "select" )
98 if ( ( part_select = curropt->value.integer() ) < 0 )
99 cerr << "-select: A selection number must be specified!" << endl;
100 if ( curropt->tag == "resolution" )
101 if ( curropt->values(hires, lores) < 1 )
102 cerr << "-resolution: A resolution limit must be specified!" << endl;
103 if ( curropt->tag == "partpath" ) {
104 partpath = curropt->value;
105 if ( partpath.length() < 1 )
106 cerr << "-partpath: The particle file path must be specified!" << endl;
107 else
108 if ( partpath[-1] != '/' ) partpath += "/";
109 }
110 if ( curropt->tag == "mask" )
111 maskfile = curropt->filename();
112 if ( curropt->tag == "output" )
113 outfile = curropt->filename();
114 if ( curropt->tag == "reference" )
115 reffile = curropt->filename();
116 }
117 option_kill(option);
118
119 double ti = timer_start();
120
121 if ( hires > lores ) swap(hires, lores);
122
123 // Read all the parameter files
124 Bstring* file_list = NULL;
125 while ( optind < argc ) string_add(&file_list, argv[optind++]);
126 if ( !file_list ) {
127 cerr << "Error: No parameter files specified!" << endl;
128 bexit(-1);
129 }
130
131 Bproject* project = read_project(file_list);
132 string_kill(file_list);
133
134 if ( project == NULL ) {
135 cerr << "Error: No input file read!" << endl;
136 bexit(-1);
137 }
138
139 project_update_comment(project, argc, argv);
140
141 if ( use_rec ) project->select = 1;
142
143 if ( reset ) part_reset_selection(project);
144
145 Bimage* pref = NULL;
146 Bimage* pmask = NULL;
147
148 if ( find )
149 pref = project_find_particle_centers(project, find, part_select, hires, lores);
150
151 if ( align )
152 project_align_particles(project, part_select, nuavg, nustd);
153 else if ( shift )
154 project_center_particles(project, part_select, nuavg, nustd);
155
156 if ( maskfile.length() ) {
157 pmask = read_img(maskfile, 1, 0);
158 if ( pmask ) {
159 project_mask_particles(project, pmask, partpath);
160 delete pmask;
161 }
162 }
163
164 if ( calc_tilt )
165 project_tilt_from_particle_defocus(project);
166
167 if ( fabs(tilt) > 0.01 )
168 project_set_particle_defocus_from_tilt(project, axis, tilt);
169
170 if ( outfile.length() )
171 write_project(outfile, project, 0, 0);
172
173 if ( pref && reffile.length() )
174 write_img(reffile, pref, 0);
175
176 delete pref;
177 project_kill(project);
178
179 if ( verbose & VERB_TIME )
180 timer_report(ti);
181
182 bexit(0);
183 }
184
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.
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
mg_particle_select.h
Select particles.
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
project_find_particle_centers
Bimage * project_find_particle_centers(Bproject *project, int max_iter, int part_select, double hires, double lores)
Calculates centers of single particle images.
Definition: mg_particles.cpp:408
project_tilt_from_particle_defocus
double project_tilt_from_particle_defocus(Bproject *project)
Finds the tilt axis from refined particle defocus values.
Definition: mg_particles.cpp:709
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
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:432
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
main
int main(int argc, char **argv)
Definition: bpart.cpp:55
Bimage
General image parameter class.
Definition: Bimage.h:163
M_PI
#define M_PI
Definition: utilities.h:59
mg_particles.h
Manipulates single particle images.
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
use
const char * use[]
Definition: bpart.cpp:22
part_reset_selection
long part_reset_selection(Bproject *project)
Resets selection to all particles.
Definition: mg_particle_select.cpp:131
Boption::next
Boption * next
Definition: options.h:28
project_center_particles
int project_center_particles(Bproject *project, int part_select, double nuavg, double nustd)
Centers single particle images based on the parametric center.
Definition: mg_particles.cpp:135
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
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
project_align_particles
int project_align_particles(Bproject *project, int part_select, double nuavg, double nustd)
Aligns single particle images based on orientation parameters.
Definition: mg_particles.cpp:33
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
project_set_particle_defocus_from_tilt
long project_set_particle_defocus_from_tilt(Bproject *project, double axis, double tilt)
Finds the tilt axis from refined particle defocus values.
Definition: mg_particles.cpp:802
mg_processing.h
Header file for micrograph processing.
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
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
project_mask_particles
long project_mask_particles(Bproject *project, Bimage *pmask, Bstring &partpath)
Calculates centers of single particle images.
Definition: mg_particles.cpp:579
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
Bproject
Definition: mg_processing.h:333
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
verbose
int verbose