Bsoft  2.1.0
Bernard's software package
bmark.cpp
Go to the documentation of this file.
1 
9 #include "rwmg.h"
10 #include "mg_processing.h"
11 #include "mg_tomography.h"
12 #include "mg_marker.h"
13 #include "marker.h"
14 #include "file_util.h"
15 #include "utilities.h"
16 #include "options.h"
17 #include "timer.h"
18 
19 // Declaration of global variables
20 extern int verbose; // Level of output to the screen
21 
22 
23 // Usage assistance
24 const char* use[] = {
25 " ",
26 "Usage: bmark [options] in.star [in2.star...]",
27 "--------------------------------------------",
28 "Operates on sets of micrograph markers.",
29 " ",
30 "Actions:",
31 "-reconstructions Operate on reconstruction parameters rather than micrographs.",
32 "-list List all micrograph and reconstruction markers.",
33 "-rotate 0.3,0.1,-0.5,81 Rotate around an axis by an angle.",
34 "-scale 0.5,3,1 Scale.",
35 "-translate 12.2,0.5,-50 Shift after rotation and scaling.",
36 "-plane Calculate a plane through the markers.",
37 "-fom 0.55 Select markers with a figure-of-merit above this cutoff.",
38 " ",
39 "Parameters:",
40 "-verbose 7 Verbosity of output.",
41 "-origin 0,22.5,30 Set the origin for rotation.",
42 //"-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
43 " ",
44 "Output:",
45 "-output out.star Output micrograph parameter file.",
46 " ",
47 NULL
48 };
49 
50 int main(int argc, char **argv)
51 {
52  // Initialize variables
53  int use_rec(0); // Flag to process reconstructions
54  int list(0);
55  int settransform(0);
56  int setorigin(0);
57  int calcplane(0); // Flag to calculate a plane
58  double fom(0); // FOM cutoff to select markers
59  Transform t; // All transformation parameters
60 // Vector3<double> samp = {1,1,1}; // Pixel size
61  Bstring output; // Output micrograph parameter file name
62 
63  int optind;
64  Boption* option = get_option_list(use, argc, argv, optind);
65  Boption* curropt;
66  for ( curropt = option; curropt; curropt = curropt->next ) {
67  if ( curropt->tag == "reconstructions" ) use_rec = 1;
68  if ( curropt->tag == "list" ) list = 1;
69  if ( curropt->tag == "rotate" ) {
70  vector<double> d = curropt->value.split_into_doubles(",");
71  if ( d.size() < 4 )
72  cerr << "-rotate: All three vector elements and an angle must be specified!" << endl;
73  else {
74  t.axis = Vector3<double>(d[0], d[1], d[2]);
75  t.angle = d[3] * M_PI/180.0;
76  settransform = 1;
77  }
78  }
79  if ( curropt->tag == "scale" ) {
80  t.scale = curropt->vector3();
81  if ( t.scale.volume() < 1 )
82  cerr << "-scale: At least one value must be specified!" << endl;
83  else {
84  if ( t.scale[1] <= 0 ) t.scale[2] = t.scale[1] = t.scale[0];
85  settransform = 1;
86  }
87  }
88  if ( curropt->tag == "translate" ) {
89  t.trans = curropt->vector3();
90  if ( t.trans.length() < 0.1 )
91  cerr << "-translate: At least one translation value must be specified!" << endl;
92  else
93  settransform = 1;
94  }
95  if ( curropt->tag == "plane" ) calcplane = 1;
96  if ( curropt->tag == "fom" )
97  if ( ( fom = curropt->value.real() ) < 0.0001 )
98  cerr << "-fom: A figure-of-merit must be specified!" << endl;
99  if ( curropt->tag == "origin" ) {
100  t.origin = curropt->origin();
101  setorigin = 1;
102  }
103 // if ( curropt->tag == "sampling" )
104 // sam = curropt->scale();
105  if ( curropt->tag == "output" )
106  output = curropt->filename();
107  }
108  option_kill(option);
109 
110  double ti = timer_start();
111 
112  // Read all the parameter files
113  Bstring* file_list = NULL;
114  while ( optind < argc ) string_add(&file_list, argv[optind++]);
115  if ( !file_list ) {
116  cerr << "Error: No parameter files specified!" << endl;
117  bexit(-1);
118  }
119 
120  Bproject* project = read_project(file_list);
121  string_kill(file_list);
122 
123  if ( project == NULL ) {
124  cerr << "Error: No input file read!" << endl;
125  bexit(-1);
126  }
127 
128  if ( use_rec ) project->select = 1;
129 
130  if ( setorigin ) project->rec->origin = t.origin;
131 
132  if ( settransform )
134 
135  if ( calcplane )
137 
138  if ( fom > 0 )
140 
141  if ( verbose )
143 
144  if ( list ) {
146 // project_marker_in_particle(project);
147  double marker_radius(10);
149  }
150 
151  // write an output STAR format file if a name is given
152  if ( output.length() ) {
153  write_project(output, project, 0, 0);
154  }
155 
157 
158  if ( verbose & VERB_TIME )
159  timer_report(ti);
160 
161  bexit(0);
162 }
163 
164 
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
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:310
marker_transform
int marker_transform(Bmarker *markers, Transform t)
Transforming markers.
Definition: marker.cpp:276
project_mg_marker_select
int project_mg_marker_select(Bproject *project, double fom)
Selects markers.
Definition: mg_tomography.cpp:2058
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
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
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Transform::origin
Vector3< double > origin
Definition: Transform.h:27
marker_stats
long marker_stats(Bmarker *markers)
Calculating marker statistics.
Definition: marker.cpp:34
marker.h
Header file for image parameter functions.
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:296
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
rwmg.h
Header file for reading and writing micrograph parameters.
Boption::value
Bstring value
Definition: options.h:30
timer.h
Utilities for timing functions.
verbose
int verbose
Bproject
Definition: mg_processing.h:336
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:673
main
int main(int argc, char **argv)
Definition: bmark.cpp:50
Transform::scale
Vector3< double > scale
Definition: Transform.h:31
marker_plane
int marker_plane(Bmarker *markers, Vector3< double > origin)
Fits a plane to a set of markers.
Definition: marker.cpp:1092
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_marker_in_particle_image
long project_marker_in_particle_image(Bproject *project, double marker_radius)
Enumerates markers within particles.
Definition: mg_marker.cpp:135
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
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
Vector3::volume
double volume()
Definition: Vector3.h:237
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
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
Transform::axis
Vector3< double > axis
Definition: Transform.h:28
Transform::angle
double angle
Definition: Transform.h:29
Transform
Definition: Transform.h:24
Vector3::length
double length()
Definition: Vector3.h:222
mg_marker.h
Header file for micrograph marker functions.
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
project_marker_lists
long project_marker_lists(Bproject *project)
Lists micrograph markers.
Definition: mg_marker.cpp:23
mg_tomography.h
Header file for single particle image processing in Bsoft.
use
const char * use[]
Definition: bmark.cpp:24