Bsoft  2.1.0
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  if ( use_rec ) project->select = 1;
140 
141  if ( reset ) part_reset_selection(project, 3);
142 
143  Bimage* pref = NULL;
144  Bimage* pmask = NULL;
145 
146  if ( find )
147  pref = project_find_particle_centers(project, find, part_select, hires, lores);
148 
149  if ( align )
151  else if ( shift )
153 
154  if ( maskfile.length() ) {
155  pmask = read_img(maskfile, 1, 0);
156  if ( pmask ) {
157  project_mask_particles(project, pmask, partpath);
158  delete pmask;
159  }
160  }
161 
162  if ( calc_tilt )
164 
165  if ( fabs(tilt) > 0.01 )
167 
168  if ( outfile.length() )
169  write_project(outfile, project, 0, 0);
170 
171  if ( pref && reffile.length() )
172  write_img(reffile, pref, 0);
173 
174  delete pref;
176 
177  if ( verbose & VERB_TIME )
178  timer_report(ti);
179 
180  bexit(0);
181 }
182 
Boption
A class for a command line input option.
Definition: options.h:26
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
mg_particle_select.h
Select particles.
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:411
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:712
mg_particles.h
Manipulates single particle images.
project_mask_particles
long project_mask_particles(Bproject *project, Bimage *pmask, Bstring &partpath)
Calculates centers of single particle images.
Definition: mg_particles.cpp:582
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
Bproject::select
int select
Definition: mg_processing.h:342
Bstring
Definition: Bstring.h:29
verbose
int verbose
Bstring::integer
long integer()
Definition: Bstring.cpp:547
Boption::next
Boption * next
Definition: options.h:28
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
options.h
Header file for option handlers.
use
const char * use[]
Definition: bpart.cpp:22
main
int main(int argc, char **argv)
Definition: bpart.cpp:55
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
rwmg.h
Header file for reading and writing micrograph parameters.
part_reset_selection
long part_reset_selection(Bproject *project, int flag=0)
Resets selection to all particles.
Definition: mg_particle_select.cpp:133
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Boption::value
Bstring value
Definition: options.h:30
Bimage
General image parameter class.
Definition: Bimage.h:177
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
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
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:138
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:36
Bstring::length
long length() const
Definition: Bstring.cpp:263
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
rwimg.h
Header file for 2D and 3D image I/O.
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.
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
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:805
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713