 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
42 if ( type.
contains(
"micro") ) type =
"mg";
43 else if ( type.
contains(
"frame") ) type =
"frame";
44 else if ( type.
contains(
"rec") ) type =
"rec";
45 else if ( type.
contains(
"part") ) type =
"part";
46 else if ( type.
contains(
"fil") ) type =
"fil";
47 else if ( type.
contains(
"power") ) type =
"ps";
48 else if ( type.
contains(
"trans") ) type =
"ft";
71 long j, k, pid, nid, flen, finc(1);
91 if ( p->
sizeZ() > 1 ) {
106 cout <<
"Creating field \"" << field->
id << endl;
108 if ( type ==
"mg" ) k = p->
images();
109 for ( j=0; j<k; j++ ) {
111 if ( k > 1 )
id +=
Bstring(j+1,
"_%03d");
114 cout <<
"Micrograph \"" << mg->
id << endl;
125 if ( type ==
"frame" ) {
129 for ( j=0; j<k; j++ ) {
137 if ( type ==
"part" ) {
139 partlist = &mg->
part;
142 cout <<
" with " << p->
images() <<
" particles";
143 }
else if ( type ==
"fil" ) {
157 cout <<
" with " << p->
images() <<
" filaments";
164 cout <<
"Creating reconstruction \"" << rec->
id <<
"\"" << endl;
171 if ( type ==
"part" ) partlist = &rec->
part;
172 if ( type ==
"fil" ) {
187 for ( j=pid=0; j<p->
images(); j++ ) {
200 flen = p->
sizeX() - 2*finc;
202 for ( j=0; j<p->
images(); j++ ) {
204 for ( nid = 0, k = 0; k < flen; k += finc ) {
206 fnode->
loc = start + fildir * k;
232 if ( file_list->
empty() ) {
233 error_show(
"Error in project_create_from_images: No filenames given to create a project!", __FILE__, __LINE__);
242 cerr <<
"Error: Input image file " << *file_list <<
" not found!" << endl;
248 if ( type.
length() < 1 ) {
250 if ( p->
sizeZ() > 1 ) type =
"rec";
261 cout <<
"Creating a project from images of type \"" << type <<
"\"" << endl << endl;
264 cout <<
"DEBUG project_create_from_images: type=" << type <<
" multi=" << multi << endl;
266 long i, j, k, pid(0), nid, flen, finc(1);
281 if ( ( type ==
"part" || type ==
"mg" || type ==
"frame" ) && multi ) {
283 if ( p->
sizeZ() == 1 ) {
287 cout <<
"Creating field \"" << field->
id <<
"\", micrograph \"" << mg->
id <<
"\"" << endl;
289 if ( type ==
"part" ) partlist = &mg->
part;
290 if ( type ==
"fil" ) fillist = &mg->
fil;
294 cout <<
"Creating reconstruction \"" << rec->
id <<
"\"" << endl;
296 if ( type ==
"part" ) partlist = &rec->
part;
297 if ( type ==
"fil" ) fillist = &rec->
fil;
303 for ( i=0, thisfile = file_list; thisfile; thisfile = thisfile->
next, i++ ) {
311 if ( p->
sizeZ() == 1 ) {
314 cout <<
"Creating field \"" << field->
id << endl;
316 if ( type ==
"mg" ) k = p->
images();
317 for ( j=0; j<k; j++ ) {
319 if ( k > 1 )
id +=
Bstring(j+1,
"_%03d");
322 cout <<
"Micrograph \"" << mg->
id << endl;
323 if ( type ==
"mg" ) mg->
fmg = *thisfile;
324 else if ( type ==
"frame" ) mg->
fframe = *thisfile;
333 if ( type ==
"frame" ) {
337 for ( j=0; j<k; j++ ) {
345 if ( type ==
"part" ) {
346 mg->
fpart = *thisfile;
347 partlist = &mg->
part;
350 cout <<
" with " << p->
images() <<
" particles";
351 }
else if ( type ==
"fil" ) {
352 mg->
ffil = *thisfile;
356 cout <<
" with " << p->
images() <<
" filaments";
363 cout <<
"Creating reconstruction \"" << rec->
id <<
"\"";
366 if ( type ==
"part" ) {
367 rec->
fpart = *thisfile;
368 partlist = &rec->
part;
371 cout <<
" with " << p->
images() <<
" particles";
372 }
else if ( type ==
"fil" ) {
373 rec->
ffil = *thisfile;
377 cout <<
" with " << p->
images() <<
" filaments";
379 rec->
frec = *thisfile;
388 if ( type ==
"part" ) {
390 }
else if ( type ==
"fil" ) {
400 }
else if ( type ==
"ft" || type ==
"ps" ) {
410 if ( type ==
"part" ) {
412 }
else if ( type ==
"fil" ) {
422 }
else if ( type ==
"ft" || type ==
"ps" ) {
430 for ( j=0; j<p->
images(); j++ ) {
441 if ( multi ) part->
fpart = *thisfile;
445 flen = p->
sizeX() - 2*finc;
447 for ( j=0; j<p->
images(); j++ ) {
449 for ( nid = 0, k = 0; k < flen; k += finc ) {
451 fnode->
loc = start + fildir * k;
454 if ( multi ) fil->
ffil = *thisfile;
484 for ( mg = mg1 = field->
mg; mg; mg = mg->
next )
485 if ( mg->
fmg != mg1->
fmg )
489 cout <<
"Catenating micrographs in field " << field->
id << endl;
491 filename = field->
id;
492 filename +=
"." + file_list->
extension();
493 cout <<
"New file name = " << filename << endl;
497 cout <<
"Writing concatenated file " << filename << endl;
499 for ( i=0, mg = field->
mg; mg; mg = mg->
next, ++i ) {
521 if ( !part )
return NULL;
526 if ( !part->
mg ) cerr <<
"Error: no micrograph for particle " << part->
id << endl;
528 if ( filename.
length() < 2 ) {
531 img_num = part->
id - 1;
532 }
else if ( part->
rec ) {
534 img_num = part->
id - 1;
539 cout <<
"Particle image filename:" <<
tab << filename <<
" (" << img_num <<
")" << endl;
543 if ( filename.
length() ) {
544 p =
read_img(filename, readflag, img_num);
546 error_show(
"Particle file not read", __FILE__, __LINE__);
567 if ( !part )
return 0;
570 long img_num(p->
images());
572 if ( !part->
mg ) cerr <<
"Error: no micrograph for particle " << part->
id << endl;
574 if ( filename.
length() < 2 ) {
577 else if ( part->
rec )
582 cout <<
"Particle image filename:" <<
tab << filename <<
" (" << img_num <<
")" << endl;
584 if ( filename.
length() ) {
587 error_show(
"Particle file not written", __FILE__, __LINE__);
618 cout <<
"Checking particle numbers:" << endl;
624 cout <<
"DEBUG project_check_particles: " << mg->
fpart <<
":" << p->
images() << endl;
627 for ( n=0, part = mg->
part; part; part = part->
next, n++ ) {
634 cerr <<
"Error: Micrograph " << mg->
id <<
" has " << n <<
" particles," << endl;
635 cerr <<
" but particle image file " << p->
file_name() <<
" has " << p->
images() <<
" images!" << endl;
638 cout << mg->
id <<
": " << n <<
" = " << p->
images() << endl;
666 error_show(
"micrograph_intensity", __FILE__, __LINE__);
695 cout <<
"Getting the average micrograph intensities" << endl << endl;
698 for ( mg = field->
mg; mg; mg = mg->
next )
724 error_show(
"micrograph_get_size", __FILE__, __LINE__);
753 error_show(
"micrograph_get_nominal_origin", __FILE__, __LINE__);
776 cout <<
"Setting nominal micrograph origins" << endl << endl;
781 error_show(
"project_set_nominal_mg_origins", __FILE__, __LINE__);
813 cout <<
"Resetting origins" << endl << endl;
816 for ( mg = field->
mg; mg; mg = mg->
next ) {
820 error_show(
"project_reset_origins", __FILE__, __LINE__);
821 for ( part = mg->
part; part; part = part->
next )
849 for ( mg = field->
mg; mg; mg = mg->
next) {
851 for ( part = mg->
part; part; part = part->
next )
879 for ( mg = field->
mg; mg; mg = mg->
next) {
882 max = p->
size() - min;
884 cout <<
"DEBUG project_delesect_edge_particles: limits:" <<
tab << min <<
tab << max << endl;
885 for ( part = mg->
part; part; part = part->
next )
if ( part->
sel ) {
886 if ( part->
loc >= min || part->
loc <= max ) nsel++;
919 for ( part = mg->
part; part; part = part->
next )
972 for ( mg = field->
mg; mg; mg = mg->
next)
973 for ( part = mg->
part; part; part = part->
next )
974 if ( part->
sel > n ) n = part->
sel;
976 long* cn =
new long[n];
980 cout <<
"Writing " << n <<
" particle classes to separate files:" << endl;
983 for ( mg = field->
mg; mg; mg = mg->
next) {
986 for ( i=0; i<n; i++ ) cn[i] = 0;
987 for ( part = mg->
part; part; part = part->
next )
988 if ( part->
sel > 0 ) cn[part->
sel-1]++;
989 for ( i=0; i<n; i++ )
if ( cn[i] ) {
991 cout <<
"Creating image with " << cn[i] <<
" particles" << endl;
995 for ( i=0; i<n; i++ ) cn[i] = 0;
996 for ( part = mg->
part; part; part = part->
next )
997 if ( part->
sel > 0 ) {
1003 for ( i=0; i<n; i++ )
if ( cn[i] ) {
1006 cout <<
"Writing " << filename <<
" with " << cn[i] <<
" particles" << endl;
1032 if ( list.
length() < 1 )
return 0;
1034 long navg(0), i, id;
1054 part_nu->
fpart = filename;
1064 cout <<
"Number of class averages: " <<
id << endl << endl;
1090 int fy = (flip - 4*fz)/2;
1091 int fx = flip - 4*fz - 2*fy;
1094 cout <<
"Flipping locations along ";
1095 if ( fx ) cout <<
"x";
1096 if ( fy ) cout <<
"y";
1097 if ( fz ) cout <<
"z";
1104 for ( part = rec->
part; part; part = part->
next ) {
1105 if ( fx ) part->
loc[0] = p->
sizeX() - part->
loc[0];
1106 if ( fy ) part->
loc[1] = p->
sizeY() - part->
loc[1];
1107 if ( fz ) part->
loc[2] = p->
sizeZ() - part->
loc[2];
1109 for ( bad = rec->
bad; bad; bad = bad->
next ) {
1118 for ( mg = field->
mg; mg; mg = mg->
next ) {
1121 for ( part = mg->
part; part; part = part->
next ) {
1122 if ( fx ) part->
loc[0] = p->
sizeX() - part->
loc[0];
1123 if ( fy ) part->
loc[1] = p->
sizeY() - part->
loc[1];
1124 if ( fz ) part->
loc[2] = p->
sizeZ() - part->
loc[2];
1126 for ( bad=mg->
bad; bad; bad=bad->
next ) {
1155 cout <<
"Getting parameters from picked particle files" << endl << endl;
1158 for ( mg = field->
mg; mg; mg = mg->
next ) {
1161 cout <<
"DEBUG project_set_views_from_images: File=" << mg->
fpart <<
" particles=" << p->
images() << endl;
1167 for ( part = mg->
part; part; part = part->
next ) {
1204 cout <<
"Setting view parameters in picked particle files" << endl << endl;
1207 for ( mg = field->
mg; mg; mg = mg->
next ) {
1211 cout <<
"DEBUG project_set_views_in_images: File=" << mg->
fpart <<
" particles=" << p->
images() << endl;
1216 for ( part = mg->
part; part; part = part->
next ) {
1221 if ( part->
ori[0] < 0 || part->
ori[0] >= p->
sizeX() )
1223 if ( part->
ori[1] < 0 || part->
ori[1] >= p->
sizeY() )
1225 if ( part->
ori[2] < 0 || part->
ori[2] >= p->
sizeZ() )
1243 if ( filename.
length() < 1 )
return filename;
1253 cout <<
"Binning " << filename << endl;
1261 if ( path.
length() ) nufile = path + nufile;
1303 if ( scale <= 0 )
return 0;
1323 cout <<
"Scaling by " << scale << endl;
1325 if ( mgpath ==
"." || mgpath ==
"./" ) mgpath = 0;
1326 if ( partpath ==
"." || partpath ==
"./" ) partpath = 0;
1329 if ( mgpath[-1] !=
'/' ) mgpath +=
"/";
1331 cout <<
"Micrograph path: " << mgpath << endl;
1334 if ( partpath.
length() ) {
1335 if ( partpath[-1] !=
'/' ) partpath +=
"/";
1337 cout <<
"Particle path: " << partpath << endl;
1346 for ( mg = field->
mg; mg; mg = mg->
next ) {
1348 cout <<
"DEBUG project_scale_box: scale=" << scale << endl;
1380 for ( part = mg->
part; part; part = part->
next ) {
1385 part->
ori = (part->
ori * scale) + shift;
1387 for ( fil=mg->
fil; fil; fil=fil->
next ) {
1388 for ( fnode=fil->
node; fnode; fnode=fnode->
next )
1389 fnode->
loc = (fnode->
loc * scale).round(0);
1391 for ( bad=mg->
bad; bad; bad=bad->
next )
1392 bad->
loc = (bad->
loc * scale).round(0);
1393 for ( mark=mg->
mark; mark; mark=mark->
next )
1394 mark->
loc = (mark->
loc * scale).round(0);
1418 cout <<
"DEBUG project_scale_box: scale=" << scale << endl;
1425 newfile = rec->
frec;
1428 if ( mgpath.
length() ) newfile = mgpath + newfile;
1429 rec->
frec = newfile;
1430 size = p->
size() * scale;
1431 translate = (rec->
origin - origin).round(0);
1442 for ( part=rec->
part; part; part=part->
next ) {
1447 part->
ori = (part->
ori * scale) + shift;
1449 for ( fil=rec->
fil; fil; fil=fil->
next ) {
1450 for ( fnode=fil->
node; fnode; fnode=fnode->
next )
1451 fnode->
loc = (fnode->
loc * scale).round(0);
1453 for ( bad=rec->
bad; bad; bad=bad->
next )
1454 bad->
loc = (bad->
loc * scale).round(0);
1455 for ( mark=rec->
mark; mark; mark=mark->
next )
1456 mark->
loc = (mark->
loc * scale).round(0);
1460 newfile = rec->
fpart;
1463 if ( partpath.
length() ) newfile = partpath + newfile;
1464 rec->
fpart = newfile;
1466 translate = rec->
box_size/2 - origin;
1497 if ( bin <= 1 )
return -1;
1500 cout <<
"Binning micrographs by " << bin << endl;
1502 double scale = 1.0/bin;
1532 if ( new_pixel_size[0] <= 0 )
return 0;
Header file for utility functions for use in qsort calls.
Vector3 remainder(int divisor)
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
Vector3< double > voxel_size
string base(string &filename)
Header file for functions for creating random images.
Bfilament * filament_add(Bfilament **fil, int pid)
Adds a filament parameter structure to a linked list.
Vector3< double > micrograph_get_nominal_origin(Bmicrograph *mg)
Gets the nominal origin for a micrograph.
Header file for micrograph processing.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Vector3< long > size() const
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
double micrograph_intensity(Bmicrograph *mg)
Gets the average of a micrograph.
void view(double x, double y, double z, double a)
Bstring mg_img_scale(Bstring &filename, Bstring &path, Bstring &insert, double scale, Vector3< double > origin, Vector3< double > pixel_size)
double standard_deviation()
long delete_images(Bstring list, int retain=0)
Retains or deletes sub-images from a multi-image structure.
int project_set_nominal_mg_origins(Bproject *project)
Sets micrograph origins to the centers of the micrographs.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
Vector3< long > micrograph_get_size(Bmicrograph *mg)
Gets the size of a micrograph.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bstring image_type(Bstring type)
Converts an image type string to a standard form.
string insert(string &filename, string ins)
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
int project_trim_class_averages(Bproject *project, Bstring &list)
Deletes selected class averages from the project..
Functions for CTF (contrast transfer function) processing.
General image parameter class.
unsigned char * data_alloc()
Vector3< double > pixel_size
int replace(Bimage *img)
Replaces the data with that from the given image.
int project_set_views_from_images(Bproject *project)
Gets views from particle images.
int project_catenate_micrographs(Bproject *project)
Concatenates all micrograph image files into one file.
int project_mg_avg_intensities(Bproject *project)
Retrieves the average micrograph intensities.
Bproject * project_create_from_image(Bimage *p, Bstring type)
Creates a project structure using image file names.
Header file for general utilities.
ostream & tab(ostream &out)
Bproject * project_create_from_images(Bstring *file_list, Bstring type)
Creates a project structure using image file names.
int project_reset_origins(Bproject *project)
Resets particle origins to nominal values.
void origin(double ox, double oy, double oz)
int project_set_part_img_origins(Bproject *project)
Writes particle origins into particle image files.
long project_delesect_edge_particles(Bproject *project)
Deselects particles that are too close to the image edges.
Bmicrograph * field_find_zero_tilt_mg(Bfield *field)
Finds the micrograph closest to a zero degree tilt in a series.
Vector3< long > particle_get_box_size(Bparticle *part)
Gets the box size from particle image file.
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Header file for 2D and 3D image I/O.
int project_change_pixel_size(Bproject *project, Vector3< double > new_pixel_size, Bstring mgpath, Bstring partpath)
Changes all the micrograph fields linked to the pixel size.
int project_scale_box(Bproject *project, double scale, Bstring mgpath, Bstring partpath, Bstring insert)
Changes all the micrograph fields linked to the box size and write new particle files.
Vector3 floor(int places)
Header file for micrograph processing.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
void sampling(double x, double y, double z)
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
int project_write_particle_classes(Bproject *project)
Writes particles to different stacks based on class.
Header file for generalized linked list functions.
Header file for general utilities.
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
Bframe * frame_add(Bframe **frame, int pid)
Adds a movie frame parameter structure to a linked list.
Vector3< double > pixel_size
Header file for combining two images in various ways.
int project_bin_micrographs(Bproject *project, int bin, Bstring mgpath, Bstring partpath)
Bins all micrographs a project.
void sampling(long nn, Vector3< double > u)
double bround(double value, int places)
Rounds a value to a specified number of decimal places.
Bimage * particle_read_img(Bparticle *part, int readflag)
Reads a particle image file.
int project_get_part_box_size(Bproject *project)
Gets the box size from particle image files.
bool contains(const Bstring &s)
int particle_kill(Bparticle *part)
Frees a list of particles.
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Bfilnode * filament_node_add(Bfilnode **fnode, int pid)
Adds a filament node parameter structure to a linked list.
int project_flip_particle_coordinates(Bproject *project, int flip)
Reverses one or more particle coordinates.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
int select_numbers(Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
long statistics()
Calculates the statistics for an image.
int project_set_views_in_images(Bproject *project)
Sets views in particle images from the project parameter structure.
int project_check_particles(Bproject *project)
Checks particle numbers and box sizes.
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType newdatatype, Vector3< long > nusize, int setZslices=0, int fill_type=0, double fill=0, double newavg=0, double newstd=0)
Catenates a list of images into a multi-image structure.
int particle_write_img(Bparticle *part, Bimage *p, int compression)
Writes a particle image file.