| Bsoft 2.0.5 Bernard's software package

brecadd.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "rwmg.h"
11 #include "mg_reconstruct.h"
12 #include "mg_processing.h"
13 #include "mg_particle_select.h"
14 #include "symmetry.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: brecadd [options] input.star [input.star]",
27 "------------------------------------------------",
28 "Averages reconstructions or subvolumes of reconstructions based on",
29 "the selection in parameter files.",
30 " ",
31 "Actions:",
32 "-all Reset selection to all particles before other selections.",
33 "-group 3022 Select particles belonging to this group.",
34 "-setnumber 3 Select given selection number and set others to zero.",
35 "-multiple 2 Generate a number of maps from alternating particle images (default 1).",
36 "-size 50,50,70 Specify a size to extract new particles from a map.",
37 "-resolution 15 Specify a resolution to do a reciprocal space summation.",
38 "-std Output standard deviation image rather than variance image.",
39 "-symmetry C5 Apply point group symmetry after reconstruction.",
40 "-rescale -0.1,5.2 Rescale output images to average and standard deviation.",
41 " ",
42 "Parameters:",
43 "-verbose 7 Verbosity of output.",
44 "-datatype u Force writing of a new data type.",
45 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
46 " ",
47 "Output:",
48 "-output file.star Output parameter file.",
49 "-average output.img Output image (default avg.map).",
50 "-fom fom.img Output variance/standard deviation image (default fom.map).",
51 " ",
52 NULL
53 };
54
55 int main(int argc, char **argv)
56 {
57 // Initialize variables
58 int reset(0); // Flag to reset selection
59 int group(0); // Group to select
60 int set_number(-1); // Selection number to keep
61 int nmaps(1); // Number of maps to reconstruct
62 DataType nudatatype(Unknown_Type); // Conversion to new type
63 double nuavg(0), nustd(0); // Average and standard deviation for rescaling
64 int calcfom(0); // Flag to calculate variance=1, or std=2
65 Vector3<double> sam; // Units for the three axes (A/pixel)
66 Vector3<long> size; // Size to extract new particles
67 double resolution(0); // Resolution for frequency space reconstruction
68 Bsymmetry* sym = NULL; // Point group
69 Bstring outfile; // Output parameter file name
70 Bstring avgfile("avg.map"); // Output image file name
71 Bstring fomfile("fom.map"); // Output FOM file
72
73 int optind;
74 Boption* option = get_option_list(use, argc, argv, optind);
75 Boption* curropt;
76 for ( curropt = option; curropt; curropt = curropt->next ) {
77 if ( curropt->tag == "all" ) reset = 1;
78 if ( curropt->tag == "group" )
79 if ( ( group = curropt->value.integer() ) < 1 )
80 cerr << "-group: A group must be specified!" << endl;
81 if ( curropt->tag == "setnumber" )
82 if ( ( set_number = curropt->value.integer() ) < 1 )
83 cerr << "-setnumber: A selection number must be specified!" << endl;
84 if ( curropt->tag == "multiple" )
85 if ( ( nmaps = curropt->value.integer() ) < 1 )
86 cerr << "-multiple: The number of maps must be specified!" << endl;
87 if ( curropt->tag == "datatype" )
88 nudatatype = curropt->datatype();
89 if ( curropt->tag == "rescale" )
90 if ( curropt->values(nuavg, nustd) < 2 )
91 cerr << "-rescale: Both average and standard deviation must be specified" << endl;
92 if ( curropt->tag == "size" )
93 size = curropt->size();
94 if ( curropt->tag == "resolution" )
95 if ( ( resolution = curropt->value.real() ) < 0.1 )
96 cerr << "-resolution: The resolution must be specified!" << endl;
97 if ( curropt->tag == "std" ) calcfom += 1;
98 if ( curropt->tag == "sampling" )
99 sam = curropt->sampling();
100 if ( curropt->tag == "symmetry" )
101 sym = curropt->symmetry();
102 if ( curropt->tag == "average" )
103 avgfile = curropt->filename();
104 if ( curropt->tag == "output" )
105 outfile = curropt->filename();
106 if ( curropt->tag == "fom" ) {
107 fomfile = curropt->filename();
108 calcfom += 1;
109 }
110 }
111 option_kill(option);
112
113 if ( avgfile.length() < 3 ) {
114 cerr << "Error: No output map file name specified!" << endl;
115 bexit(-1);
116 }
117
118 double ti = timer_start();
119
120 // Read all the parameter files
121 Bstring* file_list = NULL;
122 while ( optind < argc ) string_add(&file_list, argv[optind++]);
123 if ( !file_list ) {
124 cerr << "Error: No parameter files specified!" << endl;
125 bexit(-1);
126 }
127
128 Bproject* project = read_project(file_list);
129 string_kill(file_list);
130
131 if ( !project ) {
132 cerr << "Error: No input file read!" << endl;
133 bexit(-1);
134 }
135
136 project->select = 1;
137
138 if ( reset ) part_reset_selection(project);
139
140 if ( group > 0 ) part_select_group(project, group);
141
142 if ( set_number > 0 ) part_set_selection(project, set_number);
143
144 if ( nmaps > 1 ) part_set_multi_maps(project, set_number, nmaps);
145
146 int n;
147 Bimage* psum = NULL;
148 Bstring id;
149 Bstring filename;
150 Breconstruction* rec;
151
152 for ( n=1; n<=nmaps; n++ ) {
153 if ( nmaps > 1 ) set_number = n;
154 if ( resolution > 0 )
155 psum = project_reconstruct_3D(project, set_number, size, resolution);
156 else
157 psum = project_reconstruct_3D(project, set_number, calcfom, size);
158 if ( !psum ) {
159 cerr << "Error: No average calculated!" << endl;
160 bexit(-1);
161 }
162 if ( sam.volume() > 0 ) psum->sampling(sam);
163 if ( sym && sym->point > 101 ) {
164 if ( verbose )
165 cout << "Applying symmetry " << sym->label << endl;
166 psum->symmetrize(sym, 1);
167 }
168 if ( avgfile.length() ) {
169 if ( nustd > 0 ) psum->rescale_to_avg_std(nuavg, nustd);
170 psum->change_type(nudatatype);
171 psum->label(get_cmd_line(argc, argv));
172 id = avgfile.pre_rev('.');
173 if ( nmaps > 1 ) id += Bstring(n, "_%03d");
174 filename = id + "." + avgfile.post_rev('.');
175 // cout << "writing " << filename << endl;
176 write_img(filename, psum, 0);
177 if ( verbose )
178 cout << "Adding " << id << " to the reconstruction list" << endl;
179 rec = reconstruction_add(&project->rec, id);
180 rec->frec = filename;
181 rec->voxel_size = psum->sampling()[0];
182 rec->origin = psum->image->origin();
183 if ( sym ) rec->symmetry = sym->label;
184 rec->select = 1;
185 }
186 if ( calcfom && psum->next ) {
187 filename = fomfile;
188 if ( nmaps > 1 ) filename = fomfile.pre_rev('.') + Bstring(n, "_%03d.") + fomfile.post_rev('.');
189 write_img(filename, psum->next, 0);
190 }
191 delete psum;
192 }
193
194 if ( outfile.length() ) {
195 project_update_comment(project, argc, argv);
196 write_project(outfile, project, 0, 0);
197 }
198
199 kill_symmetry(sym);
200 project_kill(project);
201
202 if ( verbose & VERB_TIME )
203 timer_report(ti);
204
205 bexit(0);
206 }
207
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
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:318
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
main
int main(int argc, char **argv)
Definition: brecadd.cpp:55
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
mg_particle_select.h
Select particles.
symmetry.h
Header file for general symmetry functions.
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Breconstruction
Definition: mg_processing.h:280
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
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
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:564
project_reconstruct_3D
Bimage * project_reconstruct_3D(Bproject *project, long selnum, int calcfom, Vector3< long > size)
Transforms 3D maps and calculates an average.
Definition: mg_reconstruct.cpp:1235
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
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
part_select_group
long part_select_group(Bproject *project, int group)
Selects particles with a given group identifier.
Definition: mg_particle_select.cpp:1766
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
Bsymmetry::point
int point
Definition: symmetry.h:39
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
Bimage::symmetrize
double symmetrize(Bstring &symmetry_string, int flag)
Definition: Bimage.h:1178
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Breconstruction::symmetry
Bstring symmetry
Definition: mg_processing.h:286
use
const char * use[]
Definition: brecadd.cpp:24
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
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::label
Bstring label
Definition: symmetry.h:41
Bsymmetry
Definition: symmetry.h:38
Bimage::next
Bimage * next
Definition: Bimage.h:165
Boption::datatype
DataType datatype()
Definition: options.h:93
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
verbose
int verbose
Breconstruction::select
long select
Definition: mg_processing.h:283
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
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.
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
mg_reconstruct.h
Functions for reconstruction.
Vector3::volume
double volume()
Definition: Vector3.h:235
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
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760