44 "Usage: jsubtomo [options] input.star/input.img [input.star/input.img]",
45 "---------------------------------------------------------------------",
46 "Finds particles (subtomograms) in a tomographic reconstruction and refines their orientations and origins.",
47 "Extracts particles from the tomograms and transforms them for averaging,",
48 "or applies the inverse transformations on the template to position it in the original tomogram.",
51 "-mode refine Search, Refine or Extract.",
53 " Search: Searches the particles in the input.image.",
54 " Refine: Refines the orientations of the particles in the input.star.",
55 " Extract: Writes selected particles to image files.",
58 "-transform Transform the particle before extraction (use only in Extract mode).",
59 "-inverse Transform the template instead of the particle (use only in Extract mode).",
60 "-star Output a star file for each extracted particle (use only in Extract mode).",
61 "-wedges Output rotated missing wedge masks for each particle (use only in Extract mode).",
62 "-iterate 2 Iterate angular refinement (default 1 iteration).",
63 " The original step sizes and limits are halved after every iteration (use only in Refine mode with angle limits).",
66 "-verbose 7 Verbosity of output.",
67 "-datatype u Force writing of a new data type (default is float).",
68 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
69 "-origin 110,50,44 Origin for rotations of the template (default taken from template image).",
70 "-convert Convert the first particle in the star-file into a reconstruction.",
72 "Parameters for search and refinement:",
73 "-angles 8.8,2.5,5.2 Step size for alpha, theta and phi, one value sets all (default 45 degrees).",
74 "-alphalimit 30 Angular limit for alpha (default: 180 degrees).",
75 "-thetaphilimit 5 Angular limit for theta & phi (default: 180 degrees, cannot be used with option symmetry).",
76 "-shiftlimit 5 Radial limit to search for shift in cross-correlation map, around the location given in input.star.",
77 " (pixels; default: whole map in Search mode, 1/2 template in Refine mode).",
78 "-resolution 15.6,200 Resolution limits for cross-correlation (default 0).",
79 "-symmetry I Symmetry of the template (default: no symmetry, thetaphilimit used instead).",
80 "-bin 3 Binning of input, template and mask by given kernel size,",
81 " output image remains same size as input.",
82 "-refinepeaks Refine peaks from cc search to subpixel accuracy.",
84 "Parameters for search:",
85 "-threshold 0.5 Report only particles above the ccc threshold.",
86 "-maxhits 10 Maximum number of particles to report for each orientation (default: all).",
88 "Parameters for refinement:",
89 "-zshiftlimit 10 Shift allowed in addition to 'shiftlimit' in the direction of the view vector (Use only in Refine mode, no xyshiftlimit).",
90 "-xyshiftlimit 10 Shift allowed in addition to 'shiftlimit' in the orthogonal to the view vector (Use only in Refine mode, no zshiftlimit).",
92 "Parameters for particle selection:",
93 "-all Reset selection to all particles before other selections.",
94 "-mindist 64 Discard overlapping particles (default: size of the template in Search, selection number set to zero).",
95 "-minangledif 50 Discard particles with too similar orientations (selection number set to zero).",
96 "-fom 0.3 Discard particles below the threshold (selection number set to zero).",
97 "-spheremindist 5 Discard particles too far from a sphere that best fits all the particles (selection number set to zero).",
98 "-topp 75.0 Select only the best percentage of particles (default 100%).",
99 "-topn 100 Select only a number of best particles from each reconstruction (default all).",
100 "-withindist 100,100,100,45 Select only particles within a set distance from a point.",
101 "-remove Remove all particles with selection number 0 after other selections.",
102 "-renumber Renumber particles.",
104 "Parameters for particle extraction:",
105 "-select 1 Extract particles with this selection number (default: all > 0).",
106 "-size 50,50,50 New size for transformed particles (use only in Extract mode. one value sets all).",
107 "-partpath dir/subdir Set the particle file paths (use only in Extract mode).",
108 "-partextension pif Set the particle image file format (dafault: map. use only in Extract mode).",
111 "-Template image.map Template to search for or to refine.",
112 "-mask mask_1.map Mask in real space to apply on template. Use a soft edged mask.",
113 "-Mask mask_2.map Mask in reciprocal space to apply during cross-correlation and for CCC normalization.",
116 "-output file.star Output parameter file with orientations.",
117 "-ccmax ccmax.img Output image with maximum cross-correlation coefficient value for each position (use only in Search mode).",
122 int main(
int argc,
char **argv)
134 double alpha_step(
M_PI_4);
135 double theta_step(
M_PI_4);
137 double alpha_limit(
M_PI);
138 double thetaphi_limit(
M_PI);
139 double hires(0), lores(0);
140 double shiftlimit(-1);
141 double shiftlimitz(0);
142 double shiftlimitxy(0);
145 int applytransform(0);
146 int extractparticle(1);
155 double threshold(0.005);
161 double randomlocations(0);
162 double randomviews(0);
167 double minangledif(-1);
168 double spheremindist(-1);
170 double fom_cutoff(-1);
171 double fom_percentage(-1);
172 int num_to_select(-1);
173 double withindist_x(0);
174 double withindist_y(0);
175 double withindist_z(0);
177 double withindist_d(-1);
184 int extractwedges(0);
192 for ( curropt = option; curropt; curropt = curropt->
next ) {
193 if ( curropt->
tag ==
"datatype" )
195 if ( curropt->
tag ==
"mode" ) {
197 if ( mode.
length() < 1 ) {
198 cerr <<
"-mode: A mode must be specified" << endl;
202 if ( curropt->
tag ==
"inverse" )
204 if ( curropt->
tag ==
"transform")
206 if ( curropt->
tag ==
"star")
208 if ( curropt->
tag ==
"wedges")
210 if ( curropt->
tag ==
"sampling") {
211 sam = curropt->
scale();
214 if ( curropt->
tag ==
"origin") {
215 origin = curropt->
origin();
218 if ( curropt->
tag ==
"angles") {
219 if ( ( i = curropt->
values(alpha_step, theta_step, phi_step) ) < 1 ) {
220 cerr <<
"-angles: An angle step size must be specified" << endl;
224 if ( i < 2 ) phi_step = theta_step = alpha_step;
225 else if ( i < 3 ) phi_step = theta_step;
227 if ( alpha_step < 0.01 ) { alpha_step=1; }
228 if ( theta_step < 0.01 ) { theta_step=1; }
229 if ( phi_step < 0.01 ) { phi_step=1; }
231 alpha_step *=
M_PI/180.0;
232 theta_step *=
M_PI/180.0;
233 phi_step *=
M_PI/180.0;
236 if ( curropt->
tag ==
"alphalimit" ) {
237 if ( ( alpha_limit = curropt->
value.
real() ) < 0.001 ) {
238 cerr <<
"-alphalimit: An angular limit for alpha must be specified!" << endl;
242 alpha_limit *=
M_PI/180.0;
245 if ( curropt->
tag ==
"thetaphilimit" ) {
246 if ( ( thetaphi_limit = curropt->
value.
real() ) < 0.001 ) {
247 cerr <<
"-thetaphilimit: An angular limit for theta & phi must be specified!" << endl;
251 thetaphi_limit *=
M_PI/180.0;
254 if ( curropt->
tag ==
"resolution" ) {
255 if ( curropt->
values(hires, lores) < 1 ) {
256 cerr <<
"-resolution: A resolution must be specified!" << endl;
260 if ( curropt->
tag ==
"shiftlimit" ) {
261 if ( ( shiftlimit = curropt->
value.
real() ) < 0.001 ) {
262 cerr <<
"-shiftlimit: A shift search radius must be specified!" << endl;
266 if ( shiftlimit < 0 ) { shiftlimit = 0; }
269 if ( curropt->
tag ==
"zshiftlimit") {
270 if ( ( shiftlimitz = curropt->
value.
real() ) < 0.001 ) {
271 cerr <<
"-zshiftlimit: A maximum shift in the direction of the view vector must be specified!" << endl;
275 if ( shiftlimitz < 0 ) { shiftlimitz = 0; }
278 if ( curropt->
tag ==
"xyshiftlimit") {
279 if ( ( shiftlimitxy = curropt->
value.
real() ) < 0.001 ) {
280 cerr <<
"-xyshiftlimit: A maximum shift orthogonal to the view vector must be specified!" << endl;
284 if ( shiftlimitxy < 0 ) { shiftlimitxy = 0; }
287 if ( curropt->
tag ==
"mindist") {
288 if ( ( mindist = curropt->
value.
real() ) < 0.001 ) {
289 cerr <<
"-mindist: A minimum distance between particles must be specified!" << endl;
293 if ( curropt->
tag ==
"spheremindist") {
294 if ( ( spheremindist = curropt->
value.
real() ) < 0.001 ) {
295 cerr <<
"-spheremindist: A minimum distance between particles and a fitted sphere!" << endl;
299 if ( curropt->
tag ==
"minangledif") {
300 if ( ( minangledif = curropt->
value.
real() ) < 0.001 ) {
301 cerr <<
"-minangledif: A minimum difference in the orientations between particles must be specified!" << endl;
305 minangledif *=
M_PI/180.0;
309 if ( curropt->
tag ==
"symmetry" )
311 if ( curropt->
tag ==
"bin" ) {
313 cerr <<
"-bin: A bin size must be specified!" << endl;
316 bin[2] = bin[1] = bin[0];
319 if ( curropt->
tag ==
"refinepeaks" ) {
322 if ( curropt->
tag ==
"threshold" ) {
323 if ( ( threshold = curropt->
value.
real() ) < 0.001 ) {
324 cerr <<
"-threshold: A threshold must be specified!" << endl;
328 if ( curropt->
tag ==
"topp" ) {
329 if ( ( fom_percentage = curropt->
value.
real() ) < 0.001 ) {
330 cerr <<
"-topp: A percentage must be specified!" << endl;
334 if ( curropt->
tag ==
"topn" ) {
335 if ( ( num_to_select = curropt->
value.
integer() ) < 1 ) {
336 cerr <<
"-topn: A number must be specified!" << endl;
340 if ( curropt->
tag ==
"withindist" ) {
341 if ( ( i = curropt->
values(withindist_x, withindist_y, withindist_z, withindist_d) ) < 4 ) {
342 cerr <<
"-withindist: Three coordinates and a maximum distance (in pixels) must be specified" << endl;
345 withindist_point =
Vector3<double>(withindist_x, withindist_y, withindist_z);
348 if ( curropt->
tag ==
"maxhits" ) {
350 cerr <<
"-maxhits: The maximum number of hits must be specified!" << endl;
354 if ( curropt->
tag ==
"Template" ) {
355 template_file = curropt->
filename();
357 if ( curropt->
tag ==
"mask" ) {
360 if ( curropt->
tag ==
"Mask" ) {
363 if ( curropt->
tag ==
"output" ) {
366 if ( curropt->
tag ==
"ccmax" ) {
370 if ( curropt->
tag ==
"size" ) {
371 size = curropt->
size();
372 if ( size.
volume() < 1 ) {
373 cerr <<
"-size: A box size must be specified." << endl;
377 if ( curropt->
tag ==
"partpath" ) {
378 partpath = curropt->
value;
379 if ( partpath.
length() < 1 )
380 cerr <<
"-partpath: The particle file path must be specified!" << endl;
382 if ( partpath[-1] !=
'/' ) partpath +=
"/";
385 if ( curropt->
tag ==
"partextension" ) {
386 part_ext = curropt->
value;
387 if ( part_ext.
length() < 1 ) {
388 cerr <<
"-partextension: The particle file extension must be specified!" << endl;
392 if ( curropt->
tag ==
"randomlocations" ) {
393 if ( ( randomlocations = curropt->
value.
real() ) < 0.001 ) {
394 cerr <<
"-randomlocations: A standard deviation must be specified!" << endl;
397 else if ( randomlocations < 0 ) randomlocations = 0;
399 if ( curropt->
tag ==
"randomviews" ) {
400 if ( ( randomviews = curropt->
value.
real() ) < 0.001 )
401 cerr <<
"-randomviews: A standard deviation must be specified!" << endl;
403 randomviews *=
M_PI/180.0;
404 if ( randomviews < 0 ) randomviews = 0;
407 if ( curropt->
tag ==
"randommag" ) {
408 if ( ( randommag = curropt->
value.
real() ) < 0.00001 ) {
409 cerr <<
"-randommag: A standard deviation must be specified!" << endl;
413 if ( randommag < 0 ) randommag = 0;
416 if ( curropt->
tag ==
"iterate" ) {
418 cerr <<
"-iterate: The number of iterations must be specified!" << endl;
422 if ( iters < 1 ) { iters = 1; }
426 if ( curropt->
tag ==
"renumber" )
428 if ( curropt->
tag ==
"fom" ) {
429 if ( ( fom_cutoff = curropt->
value.
real() ) < 0.001 ) {
430 cerr <<
"-fom: A threshold value must be specified!" << endl;
434 if ( curropt->
tag ==
"all" ) {
437 if ( curropt->
tag ==
"remove" ) {
440 if ( curropt->
tag ==
"select" ) {
442 cerr <<
"-select: A selection number must be specified!" << endl;
446 if ( curropt->
tag ==
"convert" ) {
481 if ( template_file.
length() ) {
483 ptemp =
read_img(template_file, 1, 0);
485 ptempsize = ptemp->
size();
489 if ( ( (mode ==
"search") || (mode ==
"refine") ) && ptemp == NULL ) {
490 cerr <<
"Error: No template file specified!" << endl << endl;
495 if ( (mode ==
"extract") && ( extractparticle == 0) && ptemp == NULL ) {
496 cerr <<
"Error: No template file specified!" << endl << endl;
503 while ( optind < argc )
string_add(&file_list, argv[optind++]);
505 cerr <<
"Error: No parameter files specified!" << endl << endl;
539 if ( mask_file.
length() ) {
540 if (
verbose &
VERB_PROCESS ) { cout <<
"Reading the reciprocal space mask." << endl << endl; }
543 cerr <<
"Error: No mask found!" << endl;
547 if ( (mode ==
"extract") && ( extractwedges == 1 ) && pmask == NULL ) {
548 cerr <<
"Error: No reciprocal space mask file specified!" << endl << endl;
553 if ( mask_file2.
length() ) {
555 pmask2 =
read_img(mask_file2, 1, 0);
557 cerr <<
"Error: No mask found!" << endl;
564 if ( set_origin ) { ptemp->
origin(origin); }
565 if ( set_sampling ) { ptemp->
sampling(sam); }
570 ptempsize = ptemp->
size();
575 if ( set_origin ) { pmask2->
origin(origin); }
576 if ( set_sampling ) { pmask2->
sampling(sam); }
584 if ( pmask2 && ptemp ) {
585 if (ptemp->
size() != pmask2->
size()) {
586 cerr <<
"Error: Real space mask and template must be of the same size!" << endl << endl;
591 if ( mode !=
"refine" ) {
596 if ( shiftlimitz && shiftlimitxy ) {
597 cerr <<
"Error: Both zshiftlimit and xyshiftlimit specified!" << endl << endl;
603 shiftlimit /= bin[0];
604 shiftlimitz /= bin[0];
605 shiftlimitxy /= bin[0];
614 if ( set_origin == 1 ) {
616 cout << endl <<
"Setting particle origins." << endl;
617 for (part = rec->
part; part; part=part->
next ) { part->
ori = origin; }
621 if ( (mode ==
"search") || (mode ==
"refine") || ( (mode ==
"extract") && (extractparticle == 1)) ) {
623 cout << endl <<
"Reading the reconstruction." << endl << endl;
626 cerr <<
"Error: No reconstruction found!" << endl;
629 if ( set_sampling ) { p->
sampling(sam); }
630 if ( bin[0] > 1 ) { p->bin(bin); }
636 if ( mode ==
"search" ) {
638 alpha_step, theta_step, phi_step, alpha_limit, thetaphi_limit,
639 hires, lores, shiftlimit, mindist,
640 threshold, maxhits, bin, sym, refinepeaks, ccmax_file);
644 cout << endl <<
"Found " << npart <<
" particle(s), some of which maybe overlapping each other." << endl;
646 cout << endl <<
"No particles found." << endl;
652 if ( mode ==
"refine" ) {
654 alpha_step, theta_step, phi_step, alpha_limit, thetaphi_limit,
655 hires, lores, shiftlimit, shiftlimitz, shiftlimitxy,
656 mindist, bin, sym, iters, refinepeaks, ccmax_file);
659 cout <<
"Refined " << npart <<
" particle(s)." << endl;
665 cout << endl <<
"Normalizing particle views." << endl;
673 cout << endl <<
"Resetting particle selections." << endl;
674 for ( part = rec->
part; part; part=part->
next ) part->
sel = 1;
678 if ( (fom_percentage >= 0) || (num_to_select >= 0) ) {
681 if (fom_percentage >= 0) { num_to_select = (int) (npart*fom_percentage/100.0); }
682 if (num_to_select > npart) { num_to_select = npart; }
684 fom_cutoff = rank[num_to_select].
f;
690 if ( fom_cutoff > 0 ) {
691 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Discarding particles below threshold." << endl; }
692 for (part = rec->
part; part; part=part->
next ) {
693 if ( part->
fom[0] <= fom_cutoff ) { part->
sel = 0; }
700 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Selecting the best particle for each position." << endl; }
705 if ( part->
sel != 0 ) {
708 if ( part2->
sel != 0 ) {
711 if ( peakdist < mindist * bin[0] ) {
712 if ( part2->
fom[0] > part->
fom[0] ) {
724 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Minimum distance between particles: " << mindist * bin[0] << endl; }
733 if ( minangledif > 0 ) {
735 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Selecting the best particle for each view." << endl; }
740 if ( part->
sel != 0 ) {
743 if ( part2->
sel != 0 ) {
750 angledif = part_view.
angle(part2_view);
753 if ( angledif < minangledif ) {
754 if ( part2->
fom[0] > part->
fom[0] ) {
756 cout <<
"unselected part: " << part->
id;
759 cout <<
"unselected part: " << part2->
id;
769 cout << endl <<
"Minimum difference in the view angles between particles: " << (minangledif*180/
M_PI) << endl;
774 if ( withindist_d > 0 ) {
775 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Discarding particles further than " << withindist_d <<
" from the given point." << endl; }
776 for (part = rec->
part; part; part=part->
next ) {
777 cout <<
"ID " << part->
id <<
": distance: " << (part->
loc-withindist_point).
length() << endl;
778 if ( ((part->
loc-withindist_point).length()) > withindist_d ) { part->
sel = 0; }
783 if ( spheremindist > 0 ) {
786 double sumdistances2(0);
787 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Fitting a sphere to particles locations" << endl; }
790 if (
verbose &
VERB_PROCESS ) { cout <<
"Discarding particles further than " << spheremindist <<
" pix from the surface of the sphere." << endl; }
791 for (part = rec->
part; part; part=part->
next ) {
795 if ( fabs(
distance) > spheremindist ) { part->
sel = 0; }
805 if ( part2->
sel == 0 ) {
807 cout <<
"Removing particle: " << part2->
id << endl;
826 for (part = rec->
part, ipart=1; part; part=part->
next, ipart++) {
835 if ( mode ==
"extract" ) {
840 if ( part_ext.
length() < 1 ) { part_ext =
"map"; }
842 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Extracting " << npart <<
" particle(s)." << endl; }
844 if ( !applytransform ) { cerr <<
"Warning: -transform option not give given, particles will not be rotated, only shifted." << endl; }
849 if ( extractwedges ) {
850 if ( size.
volume() == 0 ) {
852 if ( ptemp ) { size = ptemp->
size(); }
853 else { size = p->
size(); }
857 if ( pmask->
size() != size ) {
858 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Scaling the reciprocal space mask to the size of the extracted particle." << endl; }
866 filename = rec->
fpart;
867 if ( filename.
length() < 3 )
868 filename = rec->
frec.
pre_rev(
'.') +
"_part." + part_ext;
872 for ( part = rec->
part; part; part = part-> next ) {
874 if ( ((select < 0) && (part->
sel > 0)) || (part->
sel == select) ) {
879 if ( extractparticle == 1 ) {
882 if ( ( size.
volume() == 0 ) ) {
884 if ( ptemp ) { size = ptemp->
size(); }
885 else { size = p->
size(); }
889 origin2 = part->
loc / obin;
894 translate = ( part->
ori - part->
loc ) / obin;
900 if ( applytransform ) {
910 if (
verbose &
VERB_PROCESS ) { cout << endl <<
"Masking the extracted particle." << endl; }
914 if ( extractwedges ) {
919 origin3 = pmask->
size()/2;
922 wedgefilename = part->
fpart.
pre_rev(
'.') +
"_mask." + part_ext;
931 if ( extractparticle == 0 ) {
932 if ( applytransform ) {
940 origin = part->
ori / obin;
947 if (
verbose &
VERB_PROCESS ) { cout <<
"Masking the template before transformation." << endl; }
956 if ( size.
volume() == 0 ) {
960 origin = -(part->
loc - part->
ori) / obin;
963 translate = (part->
loc - part->
ori) / obin;
969 origin = p2->
size()/2;
982 newrec = partproject->
rec;
989 if ( set_origin == 1 ) {
990 newpart->
loc = origin;
991 newpart->
ori = origin;
993 else if ( size[0] * size[1] * size[2] > 0 ) {
1002 if ( applytransform ) {
1003 newpart->
view = ref_view;
1006 newpart->
view = view;
1009 newpart->
fom[0] = part->
fom[0];
1029 if ( param_file.
length() )