| Bsoft 2.0.5 Bernard's software package

dcount.cpp
Go to the documentation of this file.
1
12 #include "rwimg.h"
13 #include "rwmodel.h"
14 #include "model_occupancy.h"
15 #include "model_select.h"
16 #include "model_util.h"
17 #include "ps_model.h"
18 #include "timer.h"
19 #include "options.h"
20 #include "utilities.h"
21
22
23 // Declaration of global variables
24 extern int verbose; // Level of output to the screen
25
26 // Usage assistance
27 const char* use[] = {
28 " ",
29 "Usage: dcount [options] input.star [input2.star...]",
30 "---------------------------------------------------",
31 "Determines the occupancy of components in the maps associated with models.",
32 "The maps must have positive density for occupancy determination (use -invert option).",
33 " ",
34 "Actions:",
35 "-invert Invert density for determination of the threshold.",
36 " ",
37 "Parameters:",
38 "-verbose 7 Verbosity of output.",
39 "-componentradius 8.4 Set radius for all components.",
40 "-shift 40 Maximum shift allowed (angstrom, default infinite).",
41 "-resolution 50,500 Resolution range for cross-correlation (default 0 - 1e6 angstrom).",
42 "-rho 0.8 Protein density (default 0.81 Da/A3, use with -mass).",
43 "-mass 12.645M Molecular mass of the particle (determines the threshold.",
44 "-cutoff 0.3 Cutoff for voxels above threshold for determining occupancy (default 0.5),",
45 "-bins 50 Number of bins for histogram of average intensities at the marker locations in all images.",
46 "-fit 2 Number of fitted binomial distributions to the distribution of occupancy.",
47 " ",
48 "Input:",
49 "-model model.star Input reference model of expected locations in the particle.",
50 "-template templ.pif Template map for cross-correlation refinement of component locations.",
51 "-Mask shell.map Binary mask to hide denisity in some regions of the map before determination of occupancy.",
52 " ",
53 "Output:",
54 "-output model.star Model output file.",
55 "-split 3 Split models into individual files:",
56 " Argument: 1-6: number of digits inserted before extension",
57 " Argument: \"id\": model ID's are used as file names.",
58 "-Postscript plots.ps Postscript output file.",
59 " ",
60 "Examples:",
61 "dcount -v 7 -model model_template.star -comp 15.6 -template map_template.pif -shift 55 ",
62 " -resol 50,500 -invert -mass 12.645M -cutoff 50 -bins 20 -fit 2 ",
63 " -output model_occ.star -Postscript model_occ.ps model.star",
64 " ",
65 NULL
66 };
67
68
69 int main(int argc, char **argv)
70 {
71 // Initialize variables
72 double comprad(0); // Component radius
73 int bins(256); // Number of bins in output histogram of average intensities
74 int invert_flag(0); // Invertion of intensity for threshold determination
75 int nfit(1); // Number of fitted binomial distributions
76 double mol_weight(0); // Molecular weight for threshold finding
77 double hires(0); // Limiting resolution range (hires must be > 0 to be set)
78 double lores(1e6); // Limiting resolution range (hires must be > 0 to be set)
79 double max_shift(0); // Maximum shift allowed, default infinite
80 double cutoff(0.5); // Limits for cutoff determination
81 double rho(RHO); // Protein density in Da/A3
82 Bstring modelin; // Input STAR file with a model of expected locations
83 Bstring templfile; // Filename of the template file for cross correlation
84 Bstring maskfile; // Filename of the input mask
85 Bstring PSname; // Name of the output PostScript file
86 Bstring outmod; // Rootname of output generized models
87 int split(0); // Sets output of multiple single-model files
88
89 int i, optind;
90 Boption* option = get_option_list(use, argc, argv, optind);
91 Boption* curropt;
92
93 for ( curropt = option; curropt; curropt = curropt->next ) {
94 if ( curropt->tag == "invert" ) invert_flag = 1;
95 if ( curropt->tag == "fit" )
96 if ( ( nfit = curropt->value.integer() ) < 1 )
97 cerr << "-fit: Number of fitted distributions must be specified!" << endl;
98 if ( curropt->tag == "componentradius" )
99 if ( ( comprad = curropt->value.real() ) < 1 )
100 cerr << "-componentradius: A display radius must be specified!" << endl;
101 if ( curropt->tag == "model" )
102 modelin = curropt->filename();
103 if ( curropt->tag == "Mask" )
104 maskfile = curropt->filename();
105 if ( curropt->tag == "template" )
106 templfile = curropt->filename();
107 if ( curropt->tag == "shift" )
108 if ( ( max_shift = curropt->value.real() ) < 1 )
109 cerr << "-shift: A maximum shift distance must be specified" << endl;
110 if ( curropt->tag == "resolution" )
111 if ( curropt->values(hires, lores) < 1 )
112 cerr << "-resolution: A high resolution limit must be specified" << endl;
113 if ( curropt->tag == "rho" )
114 if ( ( rho = curropt->value.real() ) < 1 )
115 cerr << "-rho: A protein density value must be specified!" << endl;
116 if ( curropt->tag == "mass" ) {
117 if ( ( mol_weight = curropt->value.real() ) < 1 )
118 cerr << "-mass: A molecular weight must be specified!" << endl;
119 else {
120 if ( curropt->value.contains("k") || curropt->value.contains("K") ) mol_weight *= 1e3;
121 if ( curropt->value.contains("m") || curropt->value.contains("M") ) mol_weight *= 1e6;
122 if ( curropt->value.contains("g") || curropt->value.contains("G") ) mol_weight *= 1e9;
123 }
124 }
125 if ( curropt->tag == "cutoff" ) {
126 if ( ( cutoff = curropt->value.real() ) < 1 )
127 cerr << "-cuttof: A cutoff fraction must be specified!" << endl;
128 else
129 if ( cutoff >= 1 ) cutoff /= 100;
130 }
131 if ( curropt->tag == "bins" )
132 if ( ( bins = curropt->value.integer() ) < 1 )
133 cerr << "-bins: Number of bins must be specified!" << endl;
134 if ( curropt->tag == "output" ) {
135 outmod = curropt->value;
136 if ( outmod.length() < 1 )
137 cerr << "-output: A filename must be specified!" << endl;
138 }
139 if ( curropt->tag == "split" ) {
140 if ( curropt->value.contains("id") || curropt->value.contains("ID") ) split = 9;
141 else if ( ( split = curropt->value.integer() ) < 1 )
142 cerr << "-split: An integer must be specified!" << endl;
143 else
144 if ( split > 6 ) split = 6;
145 }
146 if ( curropt->tag == "Postscript" ) {
147 PSname = curropt->value;
148 if ( PSname.length() < 1 )
149 cerr << "-Postscript: A filename for the output PostScript file must be specified!" << endl;
150 }
151 }
152 option_kill(option);
153
154 double ti = timer_start();
155
156 // Read the input models
157 Bstring* file_list = NULL;
158
159 while ( optind < argc ) string_add(&file_list, argv[optind++]);
160 if ( !file_list ) {
161 cerr << "Error: No model or image files specified!" << endl;
162 bexit(-1);
163 }
164
165 Bmodel* model = read_model(file_list);
166 string_kill(file_list);
167
168 if ( !model ) {
169 cerr << "Error: Input file not read!" << endl;
170 bexit(-1);
171 }
172
173 Bmodel* modref = NULL;
174
175 // Read a reference model and replace all components in the input models
176 if ( modelin.length() ) {
177 modref = read_model(modelin);
178 if ( !modref ) {
179 cerr << "Error: No model was read!\n" << endl;
180 bexit(-1);
181 }
182 model_replace_components(model, modref);
183 model_kill(modref);
184 }
185
186 if ( comprad > 0 ) models_process(model, comprad, model_set_component_radius);
187
188 // Bimage* p = NULL;
189 Bimage* pt = NULL;
190 Bimage* pmask = NULL;
191 Bmodel* mp;
192
193 // Read a common mask for individual images
194 if ( maskfile.length() ) {
195 pmask = read_img(maskfile, 1, -1);
196 if ( pmask == NULL ) {
197 cerr << "Error: No mask image was read!\n" << endl;
198 bexit(-1);
199 }
200 }
201
202 // Refine component locations if the template map is defined
203 if ( templfile.length() ) {
204 pt = read_img(templfile, 1, -1);
205 if ( pt == NULL ) {
206 cerr << "Error: No template image was read!\n" << endl;
207 bexit(-1);
208 }
209 for ( i=0, mp=model; mp; mp = mp->next, i++ )
210 model_refine_comp_for_occupancy(mp, pmask, pt, NULL, hires, lores, max_shift);
211 }
212
213 model_occupancy(model, pmask, mol_weight, rho, cutoff, invert_flag);
214
215 // Occupancy analysis and binomial fit
216 long ncomp;
217 double R(0);
218 vector<double> prob(2*nfit); // array for parameters of fitted B(n,p)
219
220 vector<double> distrib = model_occupancy_distribution(model, cutoff, nfit, ncomp, prob, R);
221
222 if ( PSname.length() )
223 ps_model_occupancy(model, cutoff, bins, nfit, distrib, prob, R, PSname);
224
225 model_selection_stats(model);
226
227 // Write the model
228 if ( model && ( outmod.length() || split == 9 ) ) {
229 model->split = split;
230 model_update_comment(model, argc, argv);
231 write_model(outmod, model);
232 }
233
234 delete pt;
235 delete pmask;
236 model_kill(model);
237
238 if ( verbose & VERB_TIME )
239 timer_report(ti);
240
241 bexit(0);
242 }
243
model_occupancy
int model_occupancy(Bmodel *model, Bimage *pmask, double mol_weight, double rho, double cutoff, int invert_flag)
Calculates the occupancy of components in a map.
Definition: model_occupancy.cpp:45
Bstring::real
double real()
Definition: Bstring.cpp:545
model_set_component_radius
long model_set_component_radius(Bmodel *model, double comprad)
Set the display radius for all components to a specific value.
Definition: rwmodel.cpp:1264
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
model_occupancy_distribution
vector< double > model_occupancy_distribution(Bmodel *model, double cutoff, int nfit, long &ncomp, vector< double > &prob, double &R)
Calculates the occupancy distribution of models.
Definition: model_occupancy.cpp:126
model_occupancy.h
Library routines to count components in maps.
utilities.h
Header file for general utilities.
model_util.h
Library routines used for model processing.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
verbose
int verbose
Bmodel::split
int split
Definition: rwmodel.h:130
Bstring::length
long length() const
Definition: Bstring.cpp:263
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
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
model_kill
int model_kill(Bmodel *model)
Deallocates all memory in the list.
Definition: rwmodel.cpp:1124
Boption
A class for a command line input option.
Definition: options.h:26
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
model_update_comment
int model_update_comment(Bmodel *model, int n, char **strings)
Puts a set of strings and time in the comment of a model.
Definition: rwmodel.cpp:1158
use
const char * use[]
Definition: dcount.cpp:27
Bmodel::next
Bmodel * next
Definition: rwmodel.h:120
model_selection_stats
long model_selection_stats(Bmodel *model)
Calculates selection statistics.
Definition: model_select.cpp:870
model
Bmodel * model
Definition: bshow.cpp:32
read_model
Bmodel * read_model(Bstring &filename)
Definition: rwmodel.cpp:28
write_model
int write_model(Bstring &filename, Bmodel *model)
Writes model parameters.
Definition: rwmodel.cpp:91
Boption::next
Boption * next
Definition: options.h:28
ps_model_occupancy
int ps_model_occupancy(Bmodel *model, double cutoff, int bins, int nfit, vector< double > &distrib, vector< double > &prob, double R, Bstring &filename)
Generates a postscript plot for a model occupancy analysis.
Definition: ps_model.cpp:220
Bstring
Definition: Bstring.h:29
rwmodel.h
Header file for reading and writing atomic model files.
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
ps_model.h
Header file for postscript tools dealing with models.
RHO
#define RHO
Definition: utilities.h:91
main
int main(int argc, char **argv)
Definition: dcount.cpp:69
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Bmodel
Definition: rwmodel.h:119
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
model_replace_components
long model_replace_components(Bmodel *model, Bmodel *modref)
Replaces all components in a model with reference components.
Definition: model_util.cpp:227
models_process
long models_process(Bmodel *model, long(modfunc)(Bmodel *))
Process a list of models using the specified function.
Definition: model_util.cpp:36
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
model_select.h
Header file for reading and writing atomic model files.
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
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760
model_refine_comp_for_occupancy
int model_refine_comp_for_occupancy(Bmodel *model, Bimage *pmask2, Bimage *ptemp, Bimage *pmask, double hires, double lores, double max_shift)
Refines component views and positions by cross-correlation.
Definition: model_occupancy.cpp:237