 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
25 double hires,
double lores,
Bimage* pmask);
51 "Usage: bmapdist [options] input.star/input.img [input.star/input.img]",
52 "---------------------------------------------------------------------",
53 "Calculates distance criterions between a set of 2D images or 3D maps.",
54 "CC: Correlation coefficient.",
55 "R: R factor (Euclidean distance).",
56 "FSC: Resolution based on Fourier shell correlation.",
57 "DPR: Resolution based on differential phase residual.",
58 "Clustering: The preference value should be set to the approximate average in the",
59 " similarity matrix. The damping factor should be ~0.5, or between 0.1 and 0.9.",
62 "-type fsc Output type of criterion: cc (default), r, fsc, dpr.",
63 "-preference -10 Homogenous preference value for clustering.",
64 "-TwoD Compare 2D images rather than 3D maps.",
67 "-verbose 7 Verbosity of output.",
68 "-resolution 15.3 Resolution limit (angstrom).",
69 "-cutoff 0.5,45 Resolution cutoffs for FSC and DPR.",
70 "-lambda 0.6 Damping factor for clustering (default 0.5).",
73 "-mask mask.tif Real space mask (same size as input maps).",
76 "-output file.star Output parameter file.",
77 "-matrix mat.dat Output comparison matrix file.",
82 int main(
int argc,
char **argv)
89 double cutoff[4] = {0.5,45,1,0.5};
99 for ( curropt = option; curropt; curropt = curropt->
next ) {
100 if ( curropt->
tag ==
"type" ) {
101 if ( curropt->
value[0] ==
'r' ) type = 1;
102 if ( curropt->
value[0] ==
'f' ) type = 2;
103 if ( curropt->
value[0] ==
'd' ) type = 3;
105 if ( curropt->
tag ==
"preference" )
106 if ( ( pref = curropt->
value.
real() ) < -1e36 )
107 cerr <<
"-preference: A preference value must be specified!" << endl;
108 if ( curropt->
tag ==
"TwoD" ) flag = 1;
109 if ( curropt->
tag ==
"resolution" )
110 if ( curropt->
values(hires, lores) < 1 )
111 cerr <<
"-resolution: A resolution limit must be specified!" << endl;
112 if ( curropt->
tag ==
"cutoff" )
113 if ( curropt->
values(cutoff[0], cutoff[1], cutoff[2], cutoff[3]) < 1 )
114 cerr <<
"-cutoff: A cuttoff must be specified!" << endl;
115 if ( curropt->
tag ==
"lambda" )
116 if ( ( lambda = curropt->
value.
real() ) < 0.001 )
117 cerr <<
"-lambda: A damping factor must be specified!" << endl;
118 if ( curropt->
tag ==
"mask" )
119 real_mask_file = curropt->
filename();
120 if ( curropt->
tag ==
"output" )
122 if ( curropt->
tag ==
"matrix" )
131 while ( optind < argc )
string_add(&file_list, argv[optind++]);
133 cerr <<
"Error: No image or parameter files specified!" << endl;
146 cerr <<
"Error: No image file names found!" << endl;
151 if ( real_mask_file.
length() )
152 pmask =
read_img(real_mask_file, 1, 0);
156 long i, *idx, ncluster(0);
157 if ( matrix.
rows() ) {
158 if ( pref > -1e30 ) {
159 for ( i=0; i<matrix.
rows(); i++ )
172 matrix.
write(matfile);
191 double hires,
double lores,
Bimage* pmask)
193 if ( type < 0 || type > 3 ) type = 0;
195 if ( hires < 0.01 ) hires = 0.01;
199 long i, j, ii, jj, n1, n2, nmap(0);
205 for ( fn1 = file_list; fn1; fn1 = fn1->
next ) {
212 cout <<
"Calculating the similarities and differences between " << nmap <<
" images:" << endl;
213 cout <<
"Resolution limit: " << hires << endl;
215 cout <<
"Mask: " << pmask->
file_name() << endl;
220 if ( nmap < 2 )
return matrix;
223 double* CC =
new double[nmap*nmap];
224 double* R =
new double[nmap*nmap];
225 double* FSC =
new double[nmap*nmap];
226 double* DPR =
new double[nmap*nmap];
229 cout <<
"Map1\tMap2\tCC\tR\tFSC\tDPR" << endl;
230 for ( i=0, fn1 = file_list; fn1; fn1 = fn1->
next ) {
232 if ( !p1 )
bexit(-1);
235 for ( ii=0; ii<n1; ++ii, ++i ) {
240 for ( j=0, fn2 = file_list; j<i && fn2; fn2 = fn2->
next ) {
242 if ( !p2 )
bexit(-1);
245 for ( jj=0; j<i && jj<n2; ++jj, ++j ) {
250 CC[i*nmap+j] = CC[j*nmap+i] = p1->
correlate(p2);
251 R[i*nmap+j] = R[j*nmap+i] = p1->
R_factor(p2);
256 FSC[i*nmap+j] = FSC[j*nmap+i] = 1/plot->
cut(1, cutoff[0], -1);
257 DPR[i*nmap+j] = DPR[j*nmap+i] = 1/plot->
cut(2, cutoff[1], 1);
259 cout << *fn1 <<
"(" << i <<
")" <<
tab << *fn2 <<
"(" << j <<
")" <<
tab <<
260 CC[i*nmap+j] <<
tab << R[i*nmap+j] <<
tab <<
261 FSC[i*nmap+j] <<
tab << DPR[i*nmap+j] << endl;
269 cout << endl <<
"Correlation coefficients:" << endl;
270 for ( i=0; i<nmap; i++ ) {
275 for ( i=0; i<nmap; i++ ) {
277 for ( j=0; j<nmap; j++ )
278 cout <<
tab << CC[i*nmap+j];
284 cout <<
"-log(Correlation coefficients):" << endl;
285 for ( i=0; i<nmap; i++ )
288 for ( i=0; i<nmap; i++ ) {
290 for ( j=0; j<nmap; j++ )
291 cout <<
tab << -log(CC[i*nmap+j]);
297 cout <<
"R factors:" << endl;
298 for ( i=0; i<nmap; i++ ) {
303 for ( i=0; i<nmap; i++ ) {
305 for ( j=0; j<nmap; j++ )
306 cout <<
tab << R[i*nmap+j];
312 cout <<
"Resolution based on Fourier shell correlation:" << endl;
313 cout <<
"Cutoff: " << cutoff[0] << endl;
314 for ( i=0; i<nmap; i++ ) {
316 FSC[i*nmap+i] = hires;
319 for ( i=0; i<nmap; i++ ) {
321 for ( j=0; j<nmap; j++ )
322 cout <<
tab << FSC[i*nmap+j];
328 cout <<
"Resolution based on differential phase residuals:" << endl;
329 cout <<
"Cutoff: " << cutoff[1] << endl;
330 for ( i=0; i<nmap; i++ ) {
332 DPR[i*nmap+i] = hires;
335 for ( i=0; i<nmap; i++ ) {
337 for ( j=0; j<nmap; j++ )
338 cout <<
tab << DPR[i*nmap+j];
343 matrix =
Matrix(nmap, nmap);
346 for ( i=0; i<nmap; i++ ) {
349 for ( j=0; j<nmap; j++ ) matrix[i][j] = CC[i*nmap+j];
352 for ( j=0; j<nmap; j++ ) matrix[i][j] = R[i*nmap+j];
355 for ( j=0; j<nmap; j++ ) matrix[i][j] = FSC[i*nmap+j];
358 for ( j=0; j<nmap; j++ ) matrix[i][j] = DPR[i*nmap+j];
379 cerr <<
"Error: No class averages!" << endl;
384 filename = filename.
pre_rev(
'.') +
"_cluster." + filename.
post_rev(
'.');
387 cout <<
"Replacing class averages:" << endl;
388 cout <<
"Old number: " << p->
images() << endl;
389 cout <<
"New number: " << n << endl;
390 cout <<
"New file name: " << filename << endl;
398 for ( mg = field->
mg; mg; mg = mg->
next )
399 for ( part = mg->
part; part; part = part->
next )
401 part->
sel = idx[part->
sel-1] + 1;
412 nupart->
fpart = filename;
420 for ( j=0, nupart = partlist; nupart; ++j, nupart = nupart->
next )
421 if ( nupart->group == idx[i] )
break;
422 nupart->sel += part->sel;
430 for ( j=0; j<pnu->
images(); ++j )
double R_factor(Bimage *p)
Calculates an R factor between two images.
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
Matrix img_map_distance(Bstring *file_list, int type, double *cutoff, double hires, double lores, Bimage *pmask)
Header file for clustering functions.
int string_kill(Bstring *list)
Kills a string linked list.
Bplot * fsc_dpr(double hi_res, double sampling_ratio=1, int flag=0)
Calculates an FSC and DPR curves from two images.
Header file for file checking functions.
int bexit(int value)
Exit function for cleanup and debugging.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Header file for option handlers.
int project_set_selection(Bproject *project, long n, long *idx)
long * affin_prop_clustering(Matrix s, long maxit, long convit, double lambda, long &ncluster)
Generate clusters from a similarity matrix using affinity propagation.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for reading and writing micrograph parameters.
void multiply(long j, Complex< double > cv)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
void add(long j, double v)
double correlate(Bimage *p)
Calculates correlation coefficient between two images.
General image parameter class.
Utilities for timing functions.
double cut(long icol, double threshold, int dir=1)
Bimage * resolution_prepare(Bimage *p)
Header file for image processing from micrograph structures.
int main(int argc, char **argv)
unsigned char * data_alloc_and_clear()
double timer_start()
Starts timer and prints the time.
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Bstring * project_get_filenames(Bproject *project, int flag)
Header file for general utilities.
ostream & tab(ostream &out)
int project_rec_select(Bproject *project, long *idx)
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Generalized matrix class.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Header file for generalized linked list functions.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
void write(Bstring &filename)
int particle_kill(Bparticle *part)
Frees a list of particles.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
long statistics()
Calculates the statistics for an image.
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.