 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
25 #define DATLINELENGTH 120
42 "Usage: bmgconvert [options] input.star [input2.star]",
43 "----------------------------------------------------",
44 "Converts micrograph parameter files.",
49 "DAT and CRD files only hold one micrograph per file:",
50 " multiple micrographs are written as numbered DAT or CRD files.",
51 " use -mgselect to select only one micrograph.",
54 "-verbose 7 Verbosity of output.",
55 "-sampling 1.5,1.5,1 Sampling (A/pixel, one value sets all).",
56 "-mgselect 5 Selected micrograph (default all, first micrograph = 1).",
57 "-recselect 5 Selected reconstruction (default all, first reconstruction = 1).",
58 "-euler Convert views to Euler angles.",
59 "-omega Add or subtract 90 degrees to or from the OMEGA angle.",
60 "-magnification Invert the magnification factor: 1/mag.",
61 "-path part Path for new particles file (default current directory).",
62 "-extension pif Set the particle image file format.",
65 "-particles part.mrcs Input file with a stack of particles (Relion).",
68 "-output file.star Output parameter file.",
73 int main(
int argc,
char** argv)
89 for ( curropt = option; curropt; curropt = curropt->
next ) {
90 if ( curropt->
tag ==
"sampling" )
91 sam = curropt->
scale();
94 if ( curropt->
tag ==
"mgselect" )
96 cerr <<
"-mgselect: A number must be specified" << endl;
97 if ( curropt->
tag ==
"recselect" )
99 cerr <<
"-recselect: A number must be specified" << endl;
100 if ( curropt->
tag ==
"euler" )
102 if ( curropt->
tag ==
"magnification" )
104 if ( curropt->
tag ==
"omega" )
106 if ( curropt->
tag ==
"path" )
107 path = curropt->
value;
108 if ( curropt->
tag ==
"extension" ) {
109 partext = curropt->
value;
110 if ( partext.
length() < 1 )
111 cerr <<
"-extension: The particle file extension must be specified!" << endl;
113 if ( curropt->
tag ==
"particles" )
115 if ( curropt->
tag ==
"output" )
124 while ( optind < argc )
string_add(&file_list, argv[optind++]);
126 cerr <<
"Error: No parameter files specified!" << endl;
135 cerr <<
"Error: No project generated!" << endl;
166 cerr <<
"Error: No micrograph parameter filename!" << endl;
174 cout <<
"Parameter filenames:";
175 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next )
176 cout <<
" " << *thisfile;
188 for ( thisfile = file_list; thisfile; thisfile = thisfile->
next ) {
190 if ( field )
for ( mg = field->
mg; mg && mg->
next; mg = mg->
next ) ;
201 cerr <<
"Error: The STAR file is not a valid form Bsoft can read!" << endl;
209 cerr <<
"Error: Extension " << ext <<
" not valid for parameter files!" << endl;
213 else field = field->
next;
215 if ( !mg ) mg = field->
mg;
220 else rec = rec->
next;
223 cerr <<
" Parameter file " << *thisfile <<
" not read." << endl;
247 if ( filename.
empty() ) {
248 cerr <<
"Error: No micrograph parameter filename!" << endl;
267 cout <<
"Parameter filename: " << filename << endl;
278 cerr <<
"Error: Extension " << ext <<
" not valid for parameter files!" << endl;
279 cerr <<
" Parameter file " << filename <<
" not written." << endl;
298 int err(0), nx(0), ny(0), n(0);
299 char inputLine[1024];
301 char unitsInHeaderC[10];
302 double px, volt, amp, def, dev, ast, cs;
311 if (
verbose ) cout <<
"Reading a DAT file: " << filename << endl;
316 ifstream fdat(filename.
c_str());
318 cerr <<
"File " << filename <<
" does not exist!. Exit program." << endl;
322 fdat.getline(inputLine, 1023);
323 mg->
fpart = inputLine;
328 cerr <<
"ERROR reading line 1 of PFT-format DAT file. Exit program" << endl;
333 sscanf(strchr(inputLine+mg->
fpart.
length(),
' '),
" %d %d %d", &nx, &ny, &n);
336 fdat.getline(inputLine, 1023);
337 if ( !fdat.good() ) {
338 cout <<
"ERROR reading line 2 of PFT-format DAT file. Exit program" << endl;
341 if ( sscanf(inputLine,
"%lf,%d,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &unitsInHeaderI,
342 &volt, &, &def, &dev, &ast, &cs) == 8) {
343 switch(unitsInHeaderI) {
345 strcpy(unitsInHeaderC,
"pixels");
348 strcpy(unitsInHeaderC,
"angstroms");
351 strcpy(unitsInHeaderC,
"nm");
355 }
else if ( sscanf(inputLine,
"%lf,%lf,%lf,%lf,%lf,%lf,%lf\n", &px, &volt,
356 &, &def, &dev, &ast, &cs) == 7) {
358 cout <<
"ERROR interpreting line 2 of PFT-format DAT file. Exit program" << endl;
362 if ( volt < 1000.0 ) volt *= 1000;
364 if ( def < 100 ) def *= 1e4;
365 if ( dev < 100 ) dev *= 1e4;
368 if ( dev < 0 ) dev = -dev;
381 float theta, phi, omega, ox, oy, mag, fom1, fom2, fom3;
384 if ( sscanf(line,
"%d,%f,%f,%f,%f,%f,%f,%f,%f,%f", &pid, &theta, &phi, &omega, &ox, &oy, &mag, &fom1, &fom2, &fom3) > 6 ) {
401 if ( n && numpart != n )
402 cerr <<
"Warning: The number of particles (" << numpart <<
403 ") does not agree with the number in the header (" << n <<
")" << endl;
406 cout <<
"Number of particles read: " << numpart << endl << endl;
422 int i, f, numpart(0);
423 double def_min, def_max, omega;
432 if (
verbose ) cout <<
"Writing a DAT file: " << filename << endl;
437 for ( mg = field->
mg; mg; mg = mg->
next, i++ )
if ( mg_select < 1 || mg_select == i ) {
439 for ( part = mg->
part; part; part = part->
next ) numpart++;
444 fdat.open(outname.
c_str());
446 cerr <<
"Unable to create file " << filename <<
"!. Exit program." << endl;
450 fdat << fixed << right << setprecision(4) << setw(9) << mg->
pixel_size[0] <<
", "
452 << setprecision(1) << setw(8) << ctf->
volt() <<
", "
453 << setprecision(4) << setw(10) << sin(ctf->
amp_shift()) <<
", "
454 << setprecision(4) << setw(9) << def_max/1e4 <<
", "
455 << setprecision(4) << setw(9) << def_min/1e4 <<
", "
457 << setprecision(2) << setw(7) << ctf->
Cs()/1e7 << endl;
458 for ( part = mg->
part; part; part = part->
next ) {
460 omega = -euler.
psi()*180.0/
M_PI;
461 if ( omega < 0 ) omega += 360;
462 fdat << setw(7) << part->
id <<
", "
463 << setprecision(3) << setw(7) << euler.
theta()*180.0/
M_PI <<
", "
464 << setprecision(3) << setw(7) << euler.
phi()*180.0/
M_PI <<
", "
465 << setprecision(3) << setw(7) << omega <<
", "
466 << setprecision(3) << setw(7) << part->
ori[0] <<
", "
467 << setprecision(3) << setw(7) << part->
ori[1] <<
", "
468 << setprecision(3) << setw(5) << part->
mag;
469 for ( f=0; f<3; f++ ) fdat <<
", " << setprecision(3) << setw(5) << part->
fom[f];
477 cout <<
"Number of particles written: " << numpart << endl << endl;
504 if (
verbose ) cout <<
"Reading a CRD file: " << filename << endl;
509 ifstream fcrd(filename.
c_str());
511 cerr <<
"File " << filename <<
" does not exist!. Exit program." << endl;
518 while ( fcrd.getline(line,
DATLINELENGTH) && !strstr(line,
"$END") ) {
519 value = strchr(line,
'=') + 1;
520 while ( isspace(value[0]) ) value++;
521 if ( strstr(line,
"PIC_FILENAME") ) {
526 }
else if ( strstr(line,
"OUTFILE_PREFIX") ) {
528 part_prefix = part_prefix.
remove(
'\n');
529 part_prefix = part_prefix.
remove(
',');
530 part_prefix = part_prefix.
remove(
'\'');
531 }
else if ( strstr(line,
"OUTFILE_TYPE") ) {
533 part_ext = part_ext.
remove(
'\n');
534 part_ext = part_ext.
remove(
',');
535 part_ext = part_ext.
remove(
'\'');
536 }
else if ( strstr(line,
"ANGSTROMS") ) {
537 sscanf(value,
"%lf", &d);
539 }
else if ( strstr(line,
"RADIUS_PICK") ) {
540 sscanf(value,
"%lf", &d);
543 }
else if ( strstr(line,
"RADIUS_BAD") ) {
548 if ( part_prefix.
length() )
549 mg->
fpart = part_prefix +
"." + part_ext;
551 int numpart(0), numbad(0), pid;
555 if ( sscanf(line,
"%d %f %f", &pid, &x, &y) > 2 ) {
564 if ( !mg->
bad ) mg->
bad = bad;
575 cout <<
"Number of particles written: " << numpart <<
" (" << numbad <<
")" << endl << endl;
591 int i, numpart(0), numbad(0);
600 if (
verbose ) cout <<
"Writing a CRD file: " << filename << endl;
605 for ( mg = field->
mg; mg; mg = mg->
next, i++ )
if ( mg_select < 1 || mg_select == i ) {
611 fcrd.open(outname.
c_str());
613 cerr <<
"Unable to create file " << filename <<
"!. Exit program." << endl;
616 fcrd <<
" $TRIMNEWPARAMETERS" << endl;
617 fcrd <<
" CRD_VERSION = 3," << endl;
618 fcrd <<
" PIC_FILENAME = '" << mg->
fmg <<
"'," << endl;
619 fcrd <<
" PIC_FLIPFLAG = F," << endl;
620 fcrd <<
" FLIPALLROWSFLAG = F," << endl;
621 fcrd <<
" FLIPALLCOLSFLAG = F," << endl;
622 fcrd <<
" INVERT_INTENSTY = F," << endl;
623 fcrd <<
" ANGSTROMS = " << mg->
pixel_size[0] <<
"," << endl;
624 fcrd <<
" CONTRAST = 1.380000" << endl;
625 fcrd <<
" BRIGHTNESS = 0.120000" << endl;
626 fcrd <<
" OUTFILE_PREFIX = '" << prefix <<
"'," << endl;
627 fcrd <<
" OUTFILE_START = 1," << endl;
628 fcrd <<
" OUTFILE_WIDTH = 3," << endl;
629 fcrd <<
" OUTFILE_TYPE = '" << type <<
"'," << endl;
630 fcrd <<
" OD_CONVERT = F," << endl;
631 fcrd <<
" RADIUS = 50," << endl;
632 fcrd <<
" RADIUS_BAD = " << mg->
bad_radius <<
"," << endl;
633 fcrd <<
" RADIUS_PICK = " << mg->
box_size[0]/2.0 <<
"," << endl;
634 fcrd <<
" FADE = 9," << endl;
635 fcrd <<
" EXTRACT_DX = 501," << endl;
636 fcrd <<
" EXTRACT_DY = 501," << endl;
637 fcrd <<
" FINAL_DX = 401," << endl;
638 fcrd <<
" FINAL_DY = 401," << endl;
639 fcrd <<
" FINAL_MEAN = 127," << endl;
640 fcrd <<
" FINAL_STDDEV = 40," << endl;
641 fcrd <<
" SKIPMASKFLAG = F," << endl;
642 fcrd <<
" SKIPGRADIENTFLAG= T" << endl;
643 fcrd <<
" SELECTEXTENDED = T" << endl;
644 fcrd <<
" SELECTEXTLENMODE= FIXED" << endl;
645 fcrd <<
" SELECTEXTFLENGTH= 40" << endl;
646 fcrd <<
" $END" << endl;
647 for ( part = mg->
part; part; part = part->
next, numpart++ )
648 fcrd << right << setw(6) << part->
id << setw(8) << part->
loc[0] << setw(8) << part->
loc[1] << endl;
649 for ( bad = mg->
bad; bad; bad = bad->
next, numbad++ )
650 fcrd << right << setw(6) << -numbad-1 << setw(8) << bad->
loc[0] << setw(8) << bad->
loc[1] << endl;
656 cout <<
"Number of particles written: " << numpart <<
" (" << numbad <<
")" << endl << endl;
676 for ( mg = field->
mg; mg; mg = mg->
next ) {
677 for ( part = mg->
part; part; part = part->
next ) {
678 if ( flags & 1 ) part->
mag = 1.0/part->
mag;
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
Reads and writes micrograph XML files.
Bstring remove(const char c)
Vector3< double > scale()
int string_kill(Bstring *list)
Kills a string linked list.
Header file for file checking functions.
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
int write_project_conv(Bstring &filename, Bproject *project, int mg_select, int rec_select)
int project_update_first_zero(Bproject *project)
Updates the first zero from the defocus average for all the micrographs.
double astigmatism_angle()
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.
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.
int write_project_crd(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a CRD file.
int read_project_xml(Bstring &filename, Bproject *project)
Reading micrograph parameters from XML files.
Header file for option handlers.
int write_project_star(const char *filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a STAR file.
int project_split_particles(Bproject *project, Bstring partfile, Bstring path, Bstring partext)
Modifies some micrograph parameters.
int read_project_relion(Bstring &filename, Bproject *project)
Reading micrograph parameters from a Relion file.
int read_project_dat(Bstring &filename, Bproject *project)
Reading micrograph parameters from a DAT file.
Header file for reading and writing micrograph parameters.
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
int main(int argc, char **argv)
Functions for CTF (contrast transfer function) processing.
FileType
File type enumeration.
Utilities for timing functions.
int write_project_dat(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a DAT file.
double defocus_deviation()
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Header file for reading and writing micrograph parameters from and to the STAR format.
Header file for micrograph processing.
Header file for reading and writing micrograph parameters from and to the RELION STAR format.
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Header file for generalized linked list functions.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Vector3< double > pixel_size
int project_modify_parameters(Bproject *project, char flags)
Modifies some micrograph parameters.
bool contains(const Bstring &s)
Bproject * read_project_conv(Bstring *file_list)
int read_project_crd(Bstring &filename, Bproject *project)
Reading micrograph parameters from a CRD file.
int read_project_star(Bstring &filename, Bproject *project)
Reading micrograph parameters from STAR files.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
int write_project_xml(Bstring &filename, Bproject *project, int mg_select, int rec_select)
Writing micrograph parameters to a XML file.
FileType file_type(const char *filename)
Checks the file type using the extension and contents.