Bsoft  2.1.0
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  Vector3<double> scale(1,1,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->scale();
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  scale = curropt->scale();
122  if ( curropt->tag == "interpolation" ) {
123  if ( curropt->value[0] == 'n' ) interp_type = 0;
124  if ( curropt->value[0] == 'w' ) interp_type = 1;
125  if ( curropt->value[0] == 't' ) interp_type = 2;
126  }
127  if ( curropt->tag == "pad" )
128  if ( ( pad_factor = curropt->value.integer() ) < 0 )
129  cerr << "-pad: An integer factor must be specified!" << endl;
130  if ( curropt->tag == "symmetry" )
131  sym = curropt->symmetry();
132 // if ( curropt->tag == "postsymmetrize" )
133 // sym_mode = 1;
134  if ( curropt->tag == "ppx" ) flags |= WRITE_PPX | CHECK_PPX;
135  if ( curropt->tag == "Mask" )
136  maskfile = curropt->filename();
137  if ( curropt->tag == "output" )
138  outfile = curropt->filename();
139  }
140  option_kill(option);
141 
142  double ti = timer_start();
143 
144  // Read all the parameter files
145  Bstring* file_list = NULL;
146  while ( optind < argc ) string_add(&file_list, argv[optind++]);
147  if ( !file_list ) {
148  cerr << "Error: No parameter files specified!" << endl;
149  bexit(-1);
150  }
151 
152  Bproject* project = read_project(file_list);
153  string_kill(file_list);
154 
155  if ( project == NULL ) {
156  cerr << "Error: No input file read!" << endl;
157  bexit(-1);
158  }
159 
160  if ( reset ) part_reset_selection(project, 3);
161 
162  if ( sam[0] > 0 ) {
163  if ( sam[0] < 0.1 ) sam[0] = 1;
165  }
166 
167  if ( !sym ) sym = init_point_group_symmetry("C1");
168 
169  View ref_view;
170  Bstring id;
171 
172  if ( maskfile.length() )
174  resolution, scale, map_size, pad_factor,
175  interp_type, ctf_action, wiener, flags);
176 
177  if ( project && outfile.length() ) {
178  write_project(outfile, project, 0, 0);
179  }
180 
181  kill_symmetry(sym);
183 
184  if ( verbose & VERB_TIME )
185  timer_report(ti);
186 
187  bexit(0);
188 }
189 
Boption
A class for a command line input option.
Definition: options.h:26
CHECK_PPX
#define CHECK_PPX
Definition: mg_processing.h:27
mg_reconstruct.h
Functions for reconstruction.
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
mg_particle_select.h
Select particles.
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
Boption::scale
Vector3< double > scale()
Definition: options.h:190
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Bstring
Definition: Bstring.h:29
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
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
verbose
int verbose
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
View
Definition: View.h:26
Bsymmetry
Definition: symmetry.h:38
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:240
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_set_mg_pixel_size
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:1997
part_reset_selection
long part_reset_selection(Bproject *project, int flag=0)
Resets selection to all particles.
Definition: mg_particle_select.cpp:133
Boption::ctf_action
int ctf_action()
Definition: options.h:291
Boption::value
Bstring value
Definition: options.h:30
timer.h
Utilities for timing functions.
Bproject
Definition: mg_processing.h:336
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:563
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
utilities.h
Header file for general utilities.
Boption::size
Vector3< long > size()
Definition: options.h:163
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
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
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
project_single_particle_reconstruction
long project_single_particle_reconstruction(Bproject *project, Bstring &maskfile, Bsymmetry *sym, int num_select, double hi_res, Vector3< 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:519
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
use
const char * use[]
Definition: bspr.cpp:22
main
int main(int argc, char **argv)
Definition: bspr.cpp:60
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713