53 addUsageLine(
"MONORES: This algorithm estimates the local resolution map from a single reconstruction");
55 addUsageLine(
"Reference: J.L. Vilas et al, MonoRes: Automatic and Accurate Estimation of ");
56 addUsageLine(
"Local Resolution for Electron Microscopy Maps, Structure, 26, 337-344, (2018).");
59 addParamsLine(
" --vol <vol_file=\"\"> : Input map to estimate its local resolution map.");
60 addParamsLine(
" : If you want to estimate the local resolution map");
61 addParamsLine(
" : by using two half maps, then --vol represents the");
62 addParamsLine(
" : first half map, while the second is given by the ");
64 addParamsLine(
" --mask <vol_file=\"\"> : Mask defining the region where the protein is.");
65 addParamsLine(
" --minRes <s=30> : Lowest resolution in (A) for the resolution range");
67 addParamsLine(
" --maxRes <s=1> : Highest resolution in (A) for the resolution range");
69 addParamsLine(
" --sampling_rate <s=1> : Sampling rate (A/px)");
70 addParamsLine(
" -o <output_folder=\"\"> : Folder where the results will be stored.");
71 addParamsLine(
" [--vol2 <vol_file=\"\">] : (Optional but recommended) Second half map to estimate its");
72 addParamsLine(
" : local resolution map. The first one will be the --vol label.");
73 addParamsLine(
" [--maskExcl <vol_file=\"\">] : (Optional) This mask excludes the masked region in the ");
76 addParamsLine(
" [--step <s=0.25>] : (Optional) The resolution is computed from low to high frequency");
78 addParamsLine(
" [--significance <s=0.95>] : (Optional) The level of confidence for the hypothesis test between");
80 addParamsLine(
" [--threads <s=4>] : (Optional) Number of threads to parallelize the algorithm.");
81 addParamsLine(
" [--noiseonlyinhalves] : (Optional) The noise estimation is only performed inside the mask.");
82 addParamsLine(
" : This feature only works when two half maps are provided as input.");
83 addParamsLine(
" [--gaussian] : (Optional) This flag assumes than the noise is gaussian.");
84 addParamsLine(
" : Usually there are no difference between this assumption and the ");
85 addParamsLine(
" : exact noise distribution. If this flag is not provided, the exact");
86 addParamsLine(
" : distribution is estimated. It is also a faster option than the exact one");
92 std::cout <<
"Starting..." << std::endl;
109 halfMapsGiven =
true;
113 halfMapsGiven =
false;
116 V().setXmippOrigin();
124 mask().setXmippOrigin();}
126 std::cout <<
"Error: a mask ought to be provided" << std::endl;
129 double smoothparam = 0;
130 int radiuslimit, radius;
134 mono.
findCliffValue(inputVol, radius, radiuslimit, pMask, smoothparam);
138 maskExcl().setXmippOrigin();
160 iu = mono.
fourierFreqs_3D(fftV, inputVol, freq_fourier_x, freq_fourier_y, freq_fourier_z);
215 double sumS=0, sumN=0, NN = 0, NS = 0;
216 std::vector<double> noiseValues;
224 sumS += amplitudeValue;
229 noiseValues.push_back(amplitudeValue);
230 sumN += amplitudeValue;
234 std::sort(noiseValues.begin(),noiseValues.end());
236 double mean_Signal = sumS/NS;
237 double mean_noise = sumN/NN;
239 double thresholdFirstEstimation = noiseValues[size_t(noiseValues.size()*0.95)];
264 double last_res = list[(list.size()-1)];
265 last_res = last_res - 0.001;
286 double filling_value =
A1D_ELEM(resolutions, (
int)(0.5*N));
288 last_res = list[(list.size()-1)];
324 outputResolutionImage() = FilteredMap;
325 outputResolutionImage.
write(
fnOut+
"/monoresResolutionChimera.mrc");
333 outputResolutionImage() = FilteredMap;
334 outputResolutionImage.
write(
fnOut+
"/monoresResolutionMap.mrc");
343 outputResolution().resizeNoCopy(VRiesz);
351 double resolution, resolution_2, last_resolution =
maxRes;
352 double meanS, sdS2, meanN, sdN2, thr95;
353 double freq, freqH, freqL;
354 double max_meanS = -
DBL_MIN, cut_value = 0.025;
355 double mean_Signal, mean_noise, thresholdFirstEstimation;
357 bool doNextIteration=
true, lefttrimming =
false;
359 int fourier_idx, last_fourier_idx = -1;
380 volsize =
XSIZE(pMask);
382 std::vector<double> list;
384 std::cout <<
"Analyzing frequencies" << std::endl;
385 std::vector<double> noiseValues;
390 pOutputResolution.
initZeros(amplitudeMN);
394 bool continueIter =
false;
395 bool breakIter =
false;
398 resolution, last_resolution,
400 last_fourier_idx, volsize,
401 continueIter, breakIter,
410 std::cout <<
"resolution = " << resolution << std::endl;
412 list.push_back(resolution);
415 resolution_2 = list[0];
417 resolution_2 = list[iter - 2];
432 fftVRiesz, fftVRiesz_aux, VRiesz,
433 freq, freqH, freqL, iu,
434 freq_fourier_x, freq_fourier_y, freq_fourier_z,
435 amplitudeMS, iter, fnDebug);
440 fftVRiesz, fftVRiesz_aux, VRiesz,
441 freq, freqH, freqL, iu,
442 freq_fourier_x, freq_fourier_y, freq_fourier_z,
443 amplitudeMN, iter, fnDebug);
446 double sumS=0, sumS2=0, sumN=0, sumN2=0, NN = 0, NS = 0;
452 pMask, meanS, sdS2, meanN, sdN2,
significance, thr95, NS, NN);
457 pMask, meanS, sdS2, meanN, sdN2,
significance, thr95, NS, NN);
462 std::cout <<
"Search of resolutions stopped due to mask has been completed" << std::endl;
463 doNextIteration =
false;
483 std::cout <<
"There are no points to compute inside the mask" << std::endl;
484 std::cout <<
"If the number of computed frequencies is low, perhaps the provided" 485 "mask is not enough tight to the volume, in that case please try another mask" << std::endl;
490 double thresholdNoise;
492 thresholdNoise = meanN+criticalZ*
sqrt(sdN2);
494 thresholdNoise = thr95;
499 if (meanS<0.001*max_meanS){
500 std::cout <<
"Search of resolutions stopped due to too low signal" << std::endl;
506 thresholdNoise, resolution, resolution_2);
511 thresholdNoise, resolution, resolution_2);
516 double z=(meanS-meanN)/
sqrt(sdS2/NS+sdN2/NN);
519 std::cout <<
"thresholdNoise = " << thresholdNoise << std::endl;
520 std::cout <<
" meanS= " << meanS <<
" sigma2S= " << sdS2 <<
" NS= " << NS << std::endl;
521 std::cout <<
" meanN= " << meanN <<
" sigma2N= " << sdN2 <<
" NN= " << NN << std::endl;
522 std::cout <<
" z=" << z <<
" (" << criticalZ <<
")" << std::endl;
527 std::cout <<
"Search stopped due to z>Z (hypothesis test)" << std::endl;
528 doNextIteration=
false;}
530 if (doNextIteration){
532 doNextIteration =
false;}
535 last_resolution = resolution;
536 }
while (doNextIteration);
538 if (lefttrimming ==
false)
double getDoubleParam(const char *param, int arg=0)
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
double icdf_gauss(double p)
void statisticsInOutBinaryMask2(const MultidimArray< double > &volS, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void findCliffValue(MultidimArray< double > &inputmap, int &radius, int &radiuslimit, MultidimArray< int > &mask, double rsmooth)
void statisticsInBinaryMask2(const MultidimArray< double > &volS, const MultidimArray< double > &volN, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void resolution2eval(int &count_res, double step, double &resolution, double &last_resolution, double &freq, double &freqL, int &last_fourier_idx, int &volsize, bool &continueIter, bool &breakIter, double &sampling, double &maxRes)
#define DIGFREQ2FFT_IDX(freq, size, idx)
void excludeArea(MultidimArray< int > &pMask, MultidimArray< int > &pMaskExcl)
const char * getParam(const char *param, int arg=0)
void setLocalResolutionHalfMaps(const MultidimArray< double > &litudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
MultidimArray< double > fourierFreqs_3D(const MultidimArray< std::complex< double > > &myfftV, const MultidimArray< double > &inputVol, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z)
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
void amplitudeMonoSig3D_LPF(const MultidimArray< std::complex< double > > &myfftV, FourierTransformer &transformer_inv, MultidimArray< std::complex< double > > &fftVRiesz, MultidimArray< std::complex< double > > &fftVRiesz_aux, MultidimArray< double > &VRiesz, double freq, double freqH, double freqL, MultidimArray< double > &iu, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z, MultidimArray< double > &litude, int count, FileName fnDebug)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
void monogenicAmplitude_3D_Fourier(const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, MultidimArray< double > &litude, int numberOfThreads)
void proteinRadiusVolumeAndShellStatistics(const MultidimArray< int > &mask, int &radius, long &vol)
void realGaussianFilter(MultidimArray< double > &img, double sigma)
bool checkParam(const char *param)
void setLocalResolutionMap(const MultidimArray< double > &litudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
void postProcessingLocalResolutions(MultidimArray< double > &FilteredMap, MultidimArray< double > &resolutionVol, std::vector< double > &list, double &cut_value, MultidimArray< int > &pMask)
int getIntParam(const char *param, int arg=0)
void refiningMask(const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, int thrs, MultidimArray< int > &pMask)
void addParamsLine(const String &line)