Bsoft  2.1.0
Bernard's software package
bclass.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "rwmg.h"
11 #include "mg_class.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: bclass [options] input.star [input.star]",
23 "-----------------------------------------------",
24 "Classifies raw single particle images with respect to multiple reference maps.",
25 "The reference maps can be specified in the parameter file or on the command line.",
26 "FOM choices:",
27 "Correlation coefficient (FOM = CC)",
28 "R-factor (FOM = 1 - R)",
29 "Phase difference (FOM = cos(dPhi))",
30 " ",
31 "Actions:",
32 "-kernel 10,2 Reciprocal space projection: kernel size and power.",
33 "-CTF Apply CTF to projections.",
34 " ",
35 "Parameters:",
36 "-verbose 7 Verbosity of output.",
37 "-resolution 15,200 Resolution limits for comparisons (angstrom).",
38 "-fomtype phase Type FOM to use for classification (default 0=CC=correlation,).",
39 " (other: 1=R=R-factor, 2=PD=phasedifference).",
40 "-cutoff 0.2 FOM cutoff to accept a particle (default 0).",
41 " ",
42 "Input:",
43 "-reference m1.map,m2.map List of reference maps (replaces any in the parameter file).",
44 " ",
45 "Output:",
46 "-output file.star Output parameter file.",
47 "-projections Output projection files (with insertion _map<n>).",
48 "-differences Output difference files (with insertion _map<n>_diff).",
49 " ",
50 NULL
51 };
52 
53 int main(int argc, char **argv)
54 {
55  // Initialize variables
56  int kernel_width(0); // Reciprocal space kernel width
57  int kernel_power(2); // Reciprocal space kernel power
58  double resolution_lo(1e30); // Lower resolution limit (angstrom)
59  double resolution_hi(0); // Upper resolution limit (angstrom)
60  int fom_type(0); // Default correlation coefficient
61  double fom_cut(0); // Classify all particles
62  int ctf_apply(0); // Flag to apply CTF to projections
63  int img_out(0); // Don't output projection or difference images
64  Bstring ref_file; // Comma-delimited list of reference maps
65  Bstring outfile; // Output STAR file name
66 
67  int optind;
68  Boption* option = get_option_list(use, argc, argv, optind);
69  Boption* curropt;
70  for ( curropt = option; curropt; curropt = curropt->next ) {
71  if ( curropt->tag == "kernel" )
72  if ( curropt->values(kernel_width, kernel_power) < 1 )
73  cerr << "-kernel: At least the kernel size must be specified!" << endl;
74  if ( curropt->tag == "CTF" ) ctf_apply = 1;
75  if ( curropt->tag == "resolution" ) {
76  if ( curropt->values(resolution_hi, resolution_lo) < 1 )
77  cerr << "-resolution: At least the high resolution limit must be specified!" << endl;
78  else
79  if ( resolution_hi > resolution_lo )
80  swap(resolution_hi, resolution_lo);
81  }
82  if ( curropt->tag == "fomtype" ) {
83  if ( isdigit(curropt->value[0]) ) {
84  fom_type = curropt->value.integer();
85  } else {
86  curropt->value = curropt->value.lower();
87  if ( curropt->value[0] == 'c' )
88  fom_type = 0;
89  else if ( curropt->value[0] == 'r' || curropt->value.contains("fac") )
90  fom_type = 1;
91  else if ( curropt->value[0] == 'p' )
92  fom_type = 2;
93  }
94  if ( fom_type < 0 || fom_type > 2 ) fom_type = 0;
95  }
96  if ( curropt->tag == "cutoff" )
97  if ( ( fom_cut = curropt->value.real() ) < 0.00001 )
98  cerr << "-cutoff: A FOM cutoff must be specified!" << endl;
99  if ( curropt->tag == "projections" )
100  img_out += 1;
101  if ( curropt->tag == "differences" )
102  img_out += 2;
103  if ( curropt->tag == "reference" )
104  ref_file = curropt->value;
105  if ( curropt->tag == "output" )
106  outfile = 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 ( ref_file.length() ) {
130  project->reference = NULL;
131  project->reference = ref_file.split(",");
132  }
133 
134  if ( !project->reference ) {
135  cerr << "Error: No reference files found!\n" << endl;
136  bexit(-1);
137  }
138 
139  FSI_Kernel* kernel = NULL;
140  if ( kernel_width > 1 )
141  kernel = new FSI_Kernel(kernel_width, kernel_power);
142 
143  mg_classify(project, resolution_hi, resolution_lo, fom_type, fom_cut, kernel, ctf_apply, img_out);
144 
145  // Write an output parameter file if a name is given
146  if ( project && outfile.length() ) {
147  write_project(outfile, project, 0, 0);
148  }
149 
151  if ( kernel ) delete kernel;
152 
153  if ( verbose & VERB_TIME )
154  timer_report(ti);
155 
156  bexit(0);
157 }
158 
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_classify
long mg_classify(Bproject *project, double resolution_hi, double resolution_lo, int fom_type, double fom_cut, FSI_Kernel *kernel, int ctf_apply, int img_out)
Classifies particle images with respect to a series of reference maps.
Definition: mg_class.cpp:39
mg_class.h
Header file for classification of raw single particle images with respect to multiple models.
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::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
main
int main(int argc, char **argv)
Definition: bclass.cpp:53
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
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
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
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
utilities.h
Header file for general utilities.
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
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
Bstring::split
Bstring * split()
Definition: Bstring.cpp:605
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
verbose
int verbose
Bproject::reference
Bstring * reference
Definition: mg_processing.h:341
use
const char * use[]
Definition: bclass.cpp:20
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:316
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
kernel
Definition: kernlut.h:14
FSI_Kernel
Definition: FSI_Kernel.h:14