| Bsoft 2.0.5 Bernard's software package

bzfft.cpp
Go to the documentation of this file.
1
9 #include "rwmg.h"
10 #include "mg_tomo_rec.h"
11 #include "file_util.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: bzfft [options] input.img/input.star [input2.img/input2.star...]",
23 "-----------------------------------------------------------------------",
24 "Assembles slabs and back-transform z-lines for tomogram reconstruction.",
25 " ",
26 "Actions:",
27 "-ytile 50,25 Tile start and size along y dimension (default 0 and y size).",
28 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
29 "-truncate -0.5,1.2 Truncate data to minimum and maximum after rescaling.",
30 " ",
31 "Parameters:",
32 "-verbose 7 Verbosity of output.",
33 "-datatype u Force writing of a new data type.",
34 "-sampling 1.5,1.5,1.5 Sampling of input images (A/pixel; a single value can be given).",
35 " ",
36 "Output:",
37 "-output new.star Output parameter file name.",
38 "-reconstruction new.map Output image file name.",
39 " ",
40 NULL
41 };
42
43 int main(int argc, char **argv)
44 {
45 DataType nudatatype(Unknown_Type); // Conversion to new type
46 double avg(0), std(0); // Values for rescaling
47 double cutmin(0), cutmax(0); // Truncation
48 Vector3<double> sam; // Units for the three axes (A/pixel)
49 int ystart(0), ysize(0); // Y tile start and size
50 Bstring recfile; // Output image file
51 Bstring outfile; // Output parameter file
52
53 int optind;
54 Boption* option = get_option_list(use, argc, argv, optind);
55 Boption* curropt;
56 for ( curropt = option; curropt; curropt = curropt->next ) {
57 if ( curropt->tag == "rescale" ) {
58 if ( curropt->values(avg, std) < 2 )
59 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
60 if ( std <= 0 )
61 cerr << "-rescale: A positive standard deviation must be specified!" << endl;
62 }
63 if ( curropt->tag == "truncate" ) {
64 if ( curropt->values(cutmin, cutmax) < 2 )
65 cerr << "-truncate: Both min and max must be specified!" << endl;
66 if ( cutmin > cutmax ) swap(cutmin, cutmax);
67 }
68 if ( curropt->tag == "datatype" )
69 nudatatype = curropt->datatype();
70 if ( curropt->tag == "sampling" )
71 sam = curropt->sampling();
72 if ( curropt->tag == "ytile" )
73 if ( curropt->values(ystart, ysize) < 2 )
74 cerr << "-ytile: Both start and size must be specified!" << endl;
75 if ( curropt->tag == "output" )
76 outfile = curropt->filename();
77 if ( curropt->tag == "reconstruction" )
78 recfile = curropt->filename();
79 }
80 option_kill(option);
81
82 if ( verbose && argc < 3 ) {
83 cerr << "Error: No input files given!" << endl;
84 bexit(-1);
85 }
86
87 double ti = timer_start();
88
89 Bstring* file_list = NULL;
90 while ( optind < argc ) string_add(&file_list, argv[optind++]);
91 Bstring paramfile(*file_list);
92 Bproject* project = NULL;
93 Breconstruction* rec;
94
95 if ( file_type(paramfile) == Micrograph ) {
96 project = read_project(file_list);
97 string_kill(file_list);
98 file_list = NULL;
99 for ( rec = project->rec; rec; rec = rec->next )
100 string_add(&file_list, rec->frec);
101 project_kill(project);
102 }
103
104 Bimage* pmap = NULL;
105 string label = get_cmd_line(argc, argv);
106 Bstring blabel(label);
107
108 if ( ysize > 0 ) {
109 pmap = img_extract_ytile(file_list, ystart, ysize);
110 if ( !pmap ) bexit(-1);
111 img_backtransform_z_lines(pmap);
112 if ( std > 0 ) pmap->rescale_to_avg_std(avg, std);
113 if ( cutmin < cutmax ) pmap->truncate_to_min_max(cutmin, cutmax);
114 pmap->change_type(nudatatype);
115 if ( sam.volume() > 0 ) pmap->sampling(sam);
116 pmap->label(label);
117 write_img(recfile, pmap, 0);
118 } else {
119 pmap = img_backtransform_z_on_disk(file_list, recfile, nudatatype,
120 blabel, avg, std, cutmin, cutmax);
121 if ( !pmap ) bexit(-1);
122 if ( sam.volume() > 0 ) pmap->sampling(sam);
123 }
124
125 Bstring id("1");
126 if ( outfile.length() ) {
127 project = read_project(paramfile);
128 if ( !project->rec ) rec = reconstruction_add(&project->rec, id);
129 else rec = project->rec;
130 rec->frec = recfile;
131 project_update_comment(project, argc, argv);
132 write_project(outfile, project, 0, 0);
133 project_kill(project);
134 }
135
136 delete pmap;
137 string_kill(file_list);
138
139 if ( verbose & VERB_TIME )
140 timer_report(ti);
141
142 bexit(0);
143 }
144
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
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.
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
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
utilities.h
Header file for general utilities.
img_backtransform_z_lines
int img_backtransform_z_lines(Bimage *p)
The lines along the z-dimensions of a disk-based block is Fourier back-transformed.
Definition: mg_tomo_rec.cpp:1334
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
img_backtransform_z_on_disk
Bimage * img_backtransform_z_on_disk(Bstring *file_list, Bstring &recfile, DataType datatype, Bstring &label, double avg, double std, double cutmin, double cutmax)
The lines along the z-dimensions of a disk-based block is Fourier back-transformed.
Definition: mg_tomo_rec.cpp:1184
Breconstruction
Definition: mg_processing.h:280
Boption::tag
Bstring tag
Definition: options.h:29
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
Bimage::truncate_to_min_max
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Definition: Bimage_rescale.cpp:331
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
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Micrograph
Definition: file_util.h:23
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
main
int main(int argc, char **argv)
Definition: bzfft.cpp:43
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
file_util.h
Header file for file checking functions.
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
img_extract_ytile
Bimage * img_extract_ytile(Bstring *file_list, int ystart, int ysize)
Extracts a tile from the image with limits in y.
Definition: mg_tomo_rec.cpp:1082
Vector3< double >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Unknown_Type
Definition: utilities.h:147
verbose
int verbose
options.h
Header file for option handlers.
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
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
use
const char * use[]
Definition: bzfft.cpp:20
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