| Bsoft 2.0.5 Bernard's software package

bspr.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_reconstruct.h"
11 #include "rwmg.h"
12 #include "mg_particle_select.h"
13 #include "utilities.h"
14 #include "options.h"
15 #include "timer.h"
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
20
21 // Usage assistance
22 const char* use[] = {
23 " ",
24 "Usage: bspr [options] input.star [input.star]",
25 "---------------------------------------------",
26 "Analyzing single particle reconstructions.",
27 "The mask should have 4 levels.",
28 "The relative density is calculated as (level1 - level3)/(level2 - level3).",
29 " ",
30 "Actions:",
31 "-all Reset selection to all particles.",
32 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
33 "-postsymmetrize Symmetrization after reconstruction (default during).",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbosity of output.",
37 "-datatype u Force writing of a new data type.",
38 "-select 3 Selection number from STAR file selection column (default 1).",
39 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
40 "-resolution 20 Resolution limit (angstrom, default Nyquist).",
41 "-scale 1.2 Scale or magnification of reconstruction compared to original images (default 1).",
42 "-size 100,120,90 Size of reconstruction (default from images).",
43 "-interpolation weighted Interpolation type: nearest (default), weighted, trilinear.",
44 "-pad 3 Image padding factor (default 2).",
45 "-symmetry D6 Symmetry: Point group identifier",
46 "-CTF flip Apply CTF correction to images before reconstruction (default not).",
47 "-wiener 0.15 Wiener factor for CTF correction (default 0.2).",
48 " ",
49 "Input:",
50 "-Mask mask.pif Mask with 4 levels: 0=ignore, 1=analyze, 2=reference density, 3=background.",
51 " ",
52 "Output:",
53 "-output file.star Output parameter file name.",
54 "-ppx Write temporary particle parameter files to directory \"ppx\".",
55 " ",
56 NULL
57 };
58
59
60 int main(int argc, char** argv)
61 {
62 // Initializing variables
63 // DataType nudatatype(Unknown_Type); // Conversion to new type
64 double nuavg, nustd(0); // Values for rescaling
65 Vector3<double> sam; // Units for the three axes (A/pixel)
66 Vector3<long> map_size; // Size of reconstruction
67 int reset(0); // Keep selection as read from file
68 int interp_type(0); // Interpolation type
69 double scale(1); // Scale or magnification of reconstruction compared to original images
70 int ctf_action(0); // Default no CTF operation
71 double wiener(0.2); // Wiener for CTF correction
72 int pad_factor(2); // Image padding factor
73 double resolution(0); // Must be set > 0 to limit resolution
74 Bsymmetry* sym = NULL; // No symmetry specified
75 // int sym_mode(0); // Symmetrization during reconstruction
76 int part_select(-1000); // Selection number from parameter file selection column
77 int flags(0); // Flags for processing options
78 Bstring maskfile; // Mask file
79 Bstring outfile; // Output parameter file
80
81 int optind;
82 Boption* option = get_option_list(use, argc, argv, optind);
83 Boption* curropt;
84 for ( curropt = option; curropt; curropt = curropt->next ) {
85 if ( curropt->tag == "all" )
86 reset = 1;
87 if ( curropt->tag == "interpolation" ) {
88 if ( curropt->value[0] == 'n' ) interp_type = 0;
89 if ( curropt->value[0] == 't' ) interp_type = 1;
90 if ( curropt->value[0] == 'k' ) interp_type = 2;
91 }
92 // if ( curropt->tag == "datatype" )
93 // nudatatype = curropt->datatype();
94 if ( curropt->tag == "sampling" )
95 sam = curropt->sampling();
96 if ( curropt->tag == "rescale" ) {
97 if ( curropt->values(nuavg, nustd) < 2 )
98 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
99 if ( nustd <= 0 )
100 cerr << "-rescale: A positive standard deviation must be specified!" << endl;
101 }
102 if ( curropt->tag == "select" )
103 if ( ( part_select = curropt->value.integer() ) < 1 )
104 cerr << "-select: A selection number must be specified!" << endl;
105 if ( curropt->tag == "CTF" )
106 ctf_action = curropt->ctf_action();
107 if ( curropt->tag == "wiener" ) {
108 if ( ( wiener = curropt->value.real() ) < 0.000001 )
109 cerr << "-wiener: A Wiener factor must be specified!" << endl;
110 else {
111 if ( wiener < 0.01 ) wiener = 0.01;
112 // if ( wiener > 1 ) wiener = 1;
113 }
114 }
115 if ( curropt->tag == "resolution" )
116 if ( ( resolution = curropt->value.real() ) < 0.001 )
117 cerr << "-resolution: A resolution limit must be specified!" << endl;
118 if ( curropt->tag == "size" )
119 map_size = curropt->size();
120 if ( curropt->tag == "scale" )
121 if ( ( scale = curropt->value.real() ) < 0.0001 )
122 cerr << "-scale: A scale must be specified!" << endl;
123 if ( curropt->tag == "interpolation" ) {
124 if ( curropt->value[0] == 'n' ) interp_type = 0;
125 if ( curropt->value[0] == 'w' ) interp_type = 1;
126 if ( curropt->value[0] == 't' ) interp_type = 2;
127 }
128 if ( curropt->tag == "pad" )
129 if ( ( pad_factor = curropt->value.integer() ) < 0 )
130 cerr << "-pad: An integer factor must be specified!" << endl;
131 if ( curropt->tag == "symmetry" )
132 sym = curropt->symmetry();
133 // if ( curropt->tag == "postsymmetrize" )
134 // sym_mode = 1;
135 if ( curropt->tag == "ppx" ) flags |= WRITE_PPX | CHECK_PPX;
136 if ( curropt->tag == "Mask" )
137 maskfile = curropt->filename();
138 if ( curropt->tag == "output" )
139 outfile = curropt->filename();
140 }
141 option_kill(option);
142
143 double ti = timer_start();
144
145 // Read all the parameter files
146 Bstring* file_list = NULL;
147 while ( optind < argc ) string_add(&file_list, argv[optind++]);
148 if ( !file_list ) {
149 cerr << "Error: No parameter files specified!" << endl;
150 bexit(-1);
151 }
152
153 Bproject* project = read_project(file_list);
154 string_kill(file_list);
155
156 if ( project == NULL ) {
157 cerr << "Error: No input file read!" << endl;
158 bexit(-1);
159 }
160
161 if ( reset ) part_reset_selection(project);
162
163 if ( sam[0] > 0 ) {
164 if ( sam[0] < 0.1 ) sam[0] = 1;
165 project_set_pixel_size(project, sam[0]);
166 }
167
168 if ( !sym ) sym = init_point_group_symmetry("C1");
169
170 View ref_view;
171 Bstring id;
172
173 if ( maskfile.length() )
174 project_single_particle_reconstruction(project, maskfile, sym, part_select,
175 resolution, scale, map_size, pad_factor,
176 interp_type, ctf_action, wiener, flags);
177
178 if ( project && outfile.length() ) {
179 project_update_comment(project, argc, argv);
180 write_project(outfile, project, 0, 0);
181 }
182
183 kill_symmetry(sym);
184 project_kill(project);
185
186 if ( verbose & VERB_TIME )
187 timer_report(ti);
188
189 bexit(0);
190 }
191
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
mg_particle_select.h
Select particles.
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
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
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:432
main
int main(int argc, char **argv)
Definition: bspr.cpp:60
CHECK_PPX
#define CHECK_PPX
Definition: mg_processing.h:27
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Boption::size
Vector3< long > size()
Definition: options.h:163
verbose
int verbose
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
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
project_single_particle_reconstruction
long project_single_particle_reconstruction(Bproject *project, Bstring &maskfile, Bsymmetry *sym, int num_select, double hi_res, double scale, Vector3< long > size, int pad_factor, int interp_type, int ctf_action, double wiener, int flags)
Reciprocal space reconstruction from the images in a multi-image file.
Definition: mg_reconstruct.cpp:489
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
part_reset_selection
long part_reset_selection(Bproject *project)
Resets selection to all particles.
Definition: mg_particle_select.cpp:131
Bsymmetry
Definition: symmetry.h:38
Boption::next
Boption * next
Definition: options.h:28
use
const char * use[]
Definition: bspr.cpp:22
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
project_set_pixel_size
int project_set_pixel_size(Bproject *project, double pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:3398
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
View
Definition: View.h:26
Boption::ctf_action
int ctf_action()
Definition: options.h:303
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.
mg_reconstruct.h
Functions for reconstruction.
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
Bproject
Definition: mg_processing.h:333
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760