53 bool ee_error_flag=
false;
76 throw error(
"Unexpected error\n",4);
93 _CrtMemCheckpoint( &
d_s1 );
97 Int4 number_of_AA_RR1;
98 Int4 number_of_AA_RR2;
107 throw error(
"Error - number of letters in the scoring matrix file must be greater than 0\n",3);
146 throw error(
"Number of letters is different for the scoring matrix and probabilities array\n",3);
151 throw error(
"Number of letters is different for the scoring matrix and probabilities array\n",3);
176 Uint4 random_factor = 0;
181 if(AdvancedParams_tmp.
Empty())
184 #ifndef NCBI_OS_MSWIN
187 gettimeofday(&tv, &tz);
188 random_factor+=tv.tv_usec*10000000;
190 struct _timeb timebuffer;
192 _ftime( &timebuffer );
193 timeline = ctime( & ( timebuffer.time ) );
194 random_factor+=timebuffer.millitm*10000000;
305 double tmp_size=
Tmin((
double)(tmp_size1),
311 (
double)(
sizeof(
double)*12)+(
double)(
sizeof(
Int4)*17)
327 ee_error=
error(
"Internal error in the program\n",4);
343 string smatr_file_name_,
344 string RR1_file_name_,
345 string RR2_file_name_,
350 string out_file_name_)
354 bool ee_error_flag=
false;
355 error ee_error(
"",0);
383 #ifndef NCBI_OS_MSWIN
386 _CrtMemCheckpoint( &
d_s1 );
390 Int4 number_of_AA_RR1;
391 Int4 number_of_AA_RR2;
422 throw error(
"Number of letters is different in the files "+smatr_file_name_+
" and "+RR1_file_name_+
"\n",3);
427 throw error(
"Number of letters is different in the files "+smatr_file_name_+
" and "+RR2_file_name_+
"\n",3);
431 for(
t=0;
t<number_of_AA_RR1;
t++)
457 Uint4 random_factor=rand_;
460 if((
Int4)random_factor<0)
463 #ifndef NCBI_OS_MSWIN
466 gettimeofday(&tv, &tz);
467 random_factor+=tv.tv_usec*10000000;
469 struct _timeb timebuffer;
471 _ftime( &timebuffer );
472 timeline = ctime( & ( timebuffer.time ) );
473 random_factor+=timebuffer.millitm*10000000;
485 frand.open(rand_st.data(),
ios::in);
502 throw error(
"Unexpected error in randomization seed\n",3);
604 double tmp_size=
Tmin((
double)(tmp_size1),
610 (
double)(
sizeof(
double)*12)+(
double)(
sizeof(
Int4)*17)
626 ee_error=
error(
"Internal error in the program\n",4);
646 if(value_<0||value_>1.0||dim_<=0)
648 throw error(
"Unexpected error",4);
694 string out_file_name_)
696 bool ee_error_flag=
false;
697 error ee_error(
"",0);
705 f.open(out_file_name_.data(),
ios::in);
711 bool symmetric_case_flag;
715 str_ch=
new char[
str.length()+1];
718 throw error(
"Memory allocation error\n",41);
722 for(k=0;k<(
Int4)
str.length();k++)
726 str_ch[
str.length()]=
'\0';
729 char str_for_test0[]=
"number of realizations with killing";
730 char *test_flag0= strstr(str_ch,str_for_test0);
734 throw error(
"The output file "+out_file_name_+
" exists and does not have correct format;\nplease delete the file and rerun the program\n",3);
737 char str_for_test[]=
"0.5*";
739 char*test_flag= strstr(str_ch,str_for_test);
742 symmetric_case_flag=
true;
746 symmetric_case_flag=
false;
752 if(symmetric_case_flag)
756 throw error(
"The output file "+out_file_name_+
" exists and corresponds to symmetric case; \ncurrent calculation uses non-symmetric parameters;\nplease define another output file name\n",3);
760 if(!symmetric_case_flag)
764 throw error(
"The output file "+out_file_name_+
" exists and corresponds to non-symmetric case; \ncurrent calculation uses symmetric parameters;\nplease define another output file name\n",3);
779 ee_error=
error(
"Internal error in the program\n",4);
782 delete[]str_ch;str_ch=
NULL;
800 #ifndef NCBI_OS_MSWIN
805 _CrtMemCheckpoint( &
d_s2 );
811 for (use = 0; use < _MAX_BLOCKS; use++)
813 total+=
d_s3.lSizes[use];
816 total/=(double)1048576;
825 #if defined(NCBI_COMPILER_ICC) && defined(__OPTIMIZE__) \
826 && NCBI_COMPILER_VERSION >= 1000 && NCBI_COMPILER_VERSION < 1100
827 # pragma optimization_level 1
832 Int4 d_number_of_AA=
data->d_number_of_AA;
834 double *d_RR1=
data->d_RR1;
835 double *d_RR2=
data->d_RR2;
840 for(
i=0;
i<d_number_of_AA;
i++)
842 for(j=0;j<d_number_of_AA;j++)
844 res+=d_RR1[
i]*d_RR2[j]*exp(x_*d_smatr[
i][j]);
852 string smatr_file_name_,
854 Int4 &number_of_AA_smatr_)
856 bool ee_error_flag=
false;
857 error ee_error(
"",0);
866 f.open(smatr_file_name_.data(),
ios::in);
869 throw error(
"Error - file "+smatr_file_name_+
" is not found\n",3);
872 f>>number_of_AA_smatr_;
874 if(number_of_AA_smatr_<=0)
876 throw error(
"Error - number of letters in the scoring matrix file must be greater than 0\n",3);
882 for(
i=0;
i<number_of_AA_smatr_;
i++)
884 for(j=0;j<number_of_AA_smatr_;j++)
893 for(
i=0;
i<number_of_AA_smatr_;
i++)
897 if(smatr_[
i][j]!=smatr_[j][
i])
918 ee_error=
error(
"Internal error in the program\n",4);
935 string RR_file_name_,
938 Int4 *&RR_sum_elements_,
939 Int4 &number_of_AA_RR_)
941 bool ee_error_flag=
false;
942 error ee_error(
"",0);
951 f.open(RR_file_name_.data(),
ios::in);
954 throw error(
"Error - file "+RR_file_name_+
" is not found\n",3);
959 if(number_of_AA_RR_<=0)
961 throw error(
"Error - number of letters in the probabilities file must be greater than 0\n",3);
964 RR_=
new double[number_of_AA_RR_];
967 RR_sum_=
new double[number_of_AA_RR_];
970 RR_sum_elements_=
new Int4 [number_of_AA_RR_];
976 for(
i=0;
i<number_of_AA_RR_;
i++)
982 throw error(
"Error - input letter's probability number "+
long_to_string(
i+1)+
" is negative\n",3);
987 throw error(
"Error - input letter's probability number "+
long_to_string(
i+1)+
" is greater than 1.0\n",3);
993 RR_sum_[
i]=RR_sum_[
i-1]+RR_[
i];
999 RR_sum_elements_[
i]=
i;
1002 if(
fabs(RR_sum_[number_of_AA_RR_-1]-1.0)>0.000000000001)
1019 ee_error=
error(
"Internal error in the program\n",4);
1036 const vector<double> &vector_,
1039 Int4 *&RR_sum_elements_,
1040 Int4 &number_of_AA_RR_)
1042 bool ee_error_flag=
false;
1043 error ee_error(
"",0);
1052 number_of_AA_RR_=vector_.size();
1054 if(number_of_AA_RR_<=0)
1056 throw error(
"Error - number of letters in the probabilities file must be greater than 0\n",3);
1059 RR_=
new double[number_of_AA_RR_];
1062 RR_sum_=
new double[number_of_AA_RR_];
1065 RR_sum_elements_=
new Int4 [number_of_AA_RR_];
1071 for(
i=0;
i<number_of_AA_RR_;
i++)
1077 throw error(
"Error - input letter's probability number "+
long_to_string(
i+1)+
" is negative\n",3);
1082 throw error(
"Error - input letter's probability number "+
long_to_string(
i+1)+
" is greater than 1.0\n",3);
1088 RR_sum_[
i]=RR_sum_[
i-1]+RR_[
i];
1094 RR_sum_elements_[
i]=
i;
1097 if(
fabs(RR_sum_[number_of_AA_RR_-1]-1.0)>0.000000000001)
1113 ee_error=
error(
"Internal error in the program\n",4);
1144 number_=
abs(number_);
1146 Int4 reminder=number_%10;
1147 number_=(number_-reminder)/10;
1156 return tmp_string+res_;
1185 throw error(
"Memory allocation error\n",41);
1192 double x_floor=floor(x_);
1193 double x_ceil=ceil(x_);
1194 if(
fabs(x_-x_floor)<0.5)
1221 throw error(
"Unexpected error",4);
1224 bool ee_error_flag=
false;
1225 error ee_error(
"",0);
1245 Int4 smatr_max=smatr_[0][0];
1248 Int4 smatr_min=smatr_[0][0];
1254 double threshold=DBL_MIN*10.0;
1256 double aver_score=0;
1258 for(
i=0;
i<number_of_AA_;
i++)
1260 for(j=0;j<number_of_AA_;j++)
1262 if(RR1_[j]*RR2_[
i]<=threshold)
1267 aver_score+=RR1_[
i]*RR2_[j]*smatr_[
i][j];
1269 if(smatr_max<smatr_[
i][j])
1271 smatr_max=smatr_[
i][j];
1291 if(aver_score>=-threshold)
1293 throw error(
"Error - sum[i,j] RR1[i]*RR2[j]*smatr[i][j]>=0; the program cannot continue the calculation\n",3);
1298 throw error(
"Error - at least one element of the scoring matrix must be positive\n",3);
1309 if(
a<threshold*100.0)
1311 throw error(
"Error - the input parameters correspond to non-logarithmic regime\n",3);
1315 if(
a<threshold*100.0)
1317 throw error(
"Error - the input parameters define the regime which is too close to the critical regime\n",3);
1323 double tmp_pr=RR1_[smatr_max_i]*RR2_[smatr_max_j];
1324 double b=(
log(1+10*eps)-
log(tmp_pr))/(
double)smatr_max;
1328 std::vector<double> res_lambda;
1340 sort(res_lambda.begin(),res_lambda.end());
1342 if(res_lambda.size()==0)
1344 throw error(
"Error - the program is not able to find the ungapped lambda\n",3);
1347 d_lambda=res_lambda[res_lambda.size()-1];
1372 for(
a=0;
a<number_of_AA_;
a++)
1374 for(
b=0;
b<number_of_AA_;
b++)
1384 for(
a=0;
a<number_of_AA_;
a++)
1386 for(
b=0;
b<number_of_AA_;
b++)
1393 for(ind=0;ind<number_of_AA_*number_of_AA_;ind++)
1399 for(ind=1;ind<number_of_AA_*number_of_AA_;ind++)
1406 for(
a=0;
a<number_of_AA_;
a++)
1408 for(
b=0;
b<number_of_AA_;
b++)
1461 ee_error=
error(
"Internal error in the program\n",4);
1491 #ifndef NCBI_OS_MSWIN
1496 gettimeofday(&tv, &tz);
1500 seconds_=(double)(
t)+(double)(tv.tv_usec) * 0.000001;
1504 struct _timeb timebuffer;
1506 _ftime( &timebuffer );
1508 seconds_=timebuffer.time+(double)(timebuffer.millitm)/1000.0;
const TFrequencies & GetSeq2ResidueProbs(void) const
Get sequence 2 residue probabilities.
const TFrequencies & GetSeq1ResidueProbs(void) const
Get sequence 1 residue probabilities.
double GetMaxCalcMemory(void) const
Get maximum memory allowed for computation.
double GetMaxCalcTime(void) const
Get maximum calculation time allowed.
Int4 GetGapOpening(void) const
Get gap opening penalty.
double GetKAccuracy(void) const
Get relative error threshold for K parameter calculation for gapped alignment.
Int4 GetNumResidues(void) const
Get number of residues in utilized alphabet.
const Int4 ** GetScoreMatrix(void) const
Get score matrix.
double GetLambdaAccuracy(void) const
Get relative error threshold for lambda parameter calculation for gapped aligmment.
Int4 GetGapExtension(void) const
Get gap extention penalty.
Int4 GetTotalReNumber(void) const
Get total realizations number.
const vector< Int4 > & GetPrelimReNumbersKilling(void) const
Get perliminary realizations numbers killing array.
const vector< Int4 > & GetFirstStagePrelimReNumbers(void) const
Get first stage preliminary realizations numbers.
Int4 GetTotalReNumberKilling(void) const
Get total realizations number killing.
Uint4 GetRandomSeed(void) const
Get random seed.
const vector< Int4 > & GetPrelimReNumbers(void) const
Get preliminary realizations numbers.
bool d_smatr_symmetric_flag
importance_sampling * d_is
struct_for_randomization * d_rand_all
void get_memory_for_matrix(Int4 dim_, T **&matr_)
static double round(const double &x_)
alp_data(Int4 rand_, Int4 open_, Int4 epen_, string smatr_file_name_, string RR1_file_name_, string RR2_file_name_, double max_time_, double max_mem_, double eps_lambda_, double eps_K_, string out_file_name_)
Int4 * d_RR2_sum_elements
static T Tmax(T i_, T j_)
static void get_current_time(double &seconds_)
void read_smatr(string smatr_file_name_, Int4 **&smatr_, Int4 &number_of_AA_smatr_)
static T Tmin(T i_, T j_)
Int4 d_minimum_realizations_number
static Int4 random_long(double value_, Int4 dim_)
Int4 d_number_of_AA_smatr
double get_allocated_memory_in_MB()
void delete_memory_for_matrix(Int4 dim_, T **&matr_)
Int4 * d_RR1_sum_elements
static void assert_mem(void *pointer_)
static char digit_to_string(Int4 digit_)
void check_out_file(string out_file_name_)
double d_memory_size_in_MB
void read_RR(string RR_file_name_, double *&RR_, double *&RR_sum_, Int4 *&RR_sum_elements_, Int4 &number_of_AA_RR_)
static string long_to_string(Int4 number_)
static void find_tetta_general(function_type *func_, void *func_pointer_, double a_, double b_, Int4 n_partition_, double eps_, std::vector< double > &res_)
importance_sampling(alp_data *alp_data_, Int4 open_, Int4 epen_, Int4 number_of_AA_, Int4 **smatr_, double *RR1_, double *RR2_)
double * d_elements_values
static double lambda_equation(double x_, void *func_number_)
static const char * str(char *buf, int n)
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
void SetSeed(TValue seed)
Seed the random number generator with "seed".
constexpr auto sort(_Init &&init)
const struct ncbi::grid::netcache::search::fields::SIZE size
std::istream & in(std::istream &in_, double &x_)
Int4 d_total_realizations_number_with_ALP
vector< Int4 > d_preliminary_realizations_numbers_ALP
Int4 d_total_realizations_number_with_killing
vector< Int4 > d_preliminary_realizations_numbers_killing
vector< Int4 > d_first_stage_preliminary_realizations_numbers_ALP