Bsoft  2.1.0
Bernard's software package
bmgft.cpp
Go to the documentation of this file.
1 
9 #include "mg_tomo_rec.h"
10 #include "mg_tomography.h"
11 #include "rwmg.h"
12 #include "utilities.h"
13 #include "options.h"
14 #include "timer.h"
15 
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18 
19 // Usage assistance
20 const char* use[] = {
21 " ",
22 "Usage: bmgft [options] input.star [input2.star]",
23 "-----------------------------------------------",
24 "Fourier transforms micrographs from a tomographic tilt series.",
25 " ",
26 "Actions:",
27 "-removemarkers 14 Mask out markers with this radius (pixels) before transformation.",
28 " ",
29 "Parameters:",
30 "-verbose 7 Verbosity of output.",
31 "-datatype u Force writing of a new data type.",
32 "-select 23,45,66 Micrograph selection (default all).",
33 "-size 1024,1024,200 Intended reconstruction size (default from micrograph).",
34 "-scale 0.5 Scale of intended reconstruction (default 1).",
35 "-pad 3 Image padding factor (default 2).",
36 "-fill 127 Fill value for erasing/painting markers (default average).",
37 " ",
38 "Output:",
39 "-output file.star Output STAR file name.",
40 " ",
41 NULL
42 };
43 
44 int main(int argc, char **argv)
45 {
46  double marker_radius(0); // Radius to mask out markers
47  DataType nudatatype(Unknown_Type); // Conversion to new type
48  Bstring mg_select; // Micrograph selection, default all
49  Vector3<long> size; // Default use micrograph dimension
50  double scale(1); // Intended reconstruction scale
51  int pad_factor(2); // Image padding factor
52  int fill_type(FILL_AVERAGE); // Type of fill value
53  double fill(0); // Fill value for new areas
54  Bstring outfile; // Output STAR file
55 
56  int optind;
57  Boption* option = get_option_list(use, argc, argv, optind);
58  Boption* curropt;
59  for ( curropt = option; curropt; curropt = curropt->next ) {
60  if ( curropt->tag == "removemarkers" )
61  if ( ( marker_radius = curropt->value.real() ) < 1 )
62  cerr << "-removemarkers: A marker radius must be specified!" << endl;
63  if ( curropt->tag == "datatype" )
64  nudatatype = curropt->datatype();
65  if ( curropt->tag == "select" )
66  mg_select = curropt->value;
67  if ( curropt->tag == "size" )
68  size = curropt->size();
69  if ( curropt->tag == "scale" )
70  if ( ( scale = curropt->value.real() ) < 0.0001 )
71  cerr << "-scale: A scale must be specified!" << endl;
72  if ( curropt->tag == "pad" )
73  if ( ( pad_factor = curropt->value.integer() ) < 0 )
74  cerr << "-pad: An integer factor must be specified!" << endl;
75  if ( curropt->tag == "fill" )
76  fill = curropt->fill(fill_type);
77  if ( curropt->tag == "output" )
78  outfile = curropt->filename();
79  }
80  option_kill(option);
81 
82  double ti = timer_start();
83 
84  // Read all the parameter files
85  Bstring* file_list = NULL;
86  while ( optind < argc ) string_add(&file_list, argv[optind++]);
87  if ( !file_list ) {
88  cerr << "Error: No parameter files specified!" << endl;
89  bexit(-1);
90  }
91 
92  Bproject* project = read_project(file_list);
93  string_kill(file_list);
94 
95  if ( project == NULL ) {
96  cerr << "Error: No input file read!" << endl;
97  bexit(-1);
98  }
99 
100  if ( mg_select.length() ) project_mg_select(project, mg_select);
101 
102  int n = mg_fft_write(project, size, scale, pad_factor,
103  nudatatype, marker_radius, fill_type, fill);
104 
105  if ( n && project && outfile.length() ) {
106  write_project(outfile, project, 0, 0);
107  }
108 
110 
111  if ( verbose & VERB_TIME )
112  timer_report(ti);
113 
114  bexit(0);
115 }
116 
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
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::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Vector3< long >
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
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:177
options.h
Header file for option handlers.
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.
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
main
int main(int argc, char **argv)
Definition: bmgft.cpp:44
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
project_mg_select
long project_mg_select(Bproject *project, Bstring &mg_select)
Selects micrographs in a project hierarchy.
Definition: mg_tomography.cpp:1801
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
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
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
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
verbose
int verbose
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
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
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
use
const char * use[]
Definition: bmgft.cpp:20
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
mg_tomography.h
Header file for single particle image processing in Bsoft.
mg_fft_write
int mg_fft_write(Bproject *project, Vector3< int > size, double scale, int pad_factor, DataType datatype, double marker_radius, int fill_type, double fill)
Fourier transform micrographs and write to disk.
Definition: mg_tomo_rec.cpp:1012