| Bsoft 2.0.5 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->sampling();
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 )
133 marker_transform(project->rec->mark, t);
134
135 if ( calcplane )
136 marker_plane(project->rec->mark, project->rec->origin);
137
138 if ( fom > 0 )
139 project_mg_marker_select(project, fom);
140
141 if ( verbose )
142 marker_stats(project->rec->mark);
143
144 if ( list ) {
145 project_marker_lists(project);
146 // project_marker_in_particle(project);
147 double marker_radius(10);
148 project_marker_in_particle_image(project, marker_radius);
149 }
150
151 // write an output STAR format file if a name is given
152 if ( output.length() ) {
153 project_update_comment(project, argc, argv);
154 write_project(output, project, 0, 0);
155 }
156
157 project_kill(project);
158
159 if ( verbose & VERB_TIME )
160 timer_report(ti);
161
162 bexit(0);
163 }
164
165
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
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
Vector3::length
double length()
Definition: Vector3.h:222
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
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
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Transform::angle
double angle
Definition: Transform.h:29
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
marker_transform
int marker_transform(Bmarker *markers, Transform t)
Transforming markers.
Definition: marker.cpp:226
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
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
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Transform
Definition: Transform.h:24
M_PI
#define M_PI
Definition: utilities.h:59
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
Transform::scale
Vector3< double > scale
Definition: Transform.h:31
mg_tomography.h
Header file for single particle image processing in Bsoft.
file_util.h
Header file for file checking functions.
Transform::trans
Vector3< double > trans
Definition: Transform.h:30
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Transform::origin
Vector3< double > origin
Definition: Transform.h:27
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
marker_stats
long marker_stats(Bmarker *markers)
Calculating marker statistics.
Definition: marker.cpp:34
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
main
int main(int argc, char **argv)
Definition: bmark.cpp:50
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
Vector3< double >
mg_marker.h
Header file for micrograph marker functions.
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
project_mg_marker_select
int project_mg_marker_select(Bproject *project, double fom)
Selects markers.
Definition: mg_tomography.cpp:1841
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
marker_plane
int marker_plane(Bmarker *markers, Vector3< double > origin)
Fits a plane to a set of markers.
Definition: marker.cpp:1042
mg_processing.h
Header file for micrograph processing.
use
const char * use[]
Definition: bmark.cpp:24
Transform::axis
Vector3< double > axis
Definition: Transform.h:28
options.h
Header file for option handlers.
project_marker_lists
long project_marker_lists(Bproject *project)
Lists micrograph markers.
Definition: mg_marker.cpp:23
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
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
marker.h
Header file for image parameter functions.
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