void model_parameters::output_dat(void) { ofstream afs("lagrangian_est.dat"); afs<<"# syr " << endl << syr <<endl; afs<<"# nyr " << endl << nyr <<endl; afs<<"# sage " << endl << sage <<endl; afs<<"# nage " << endl << nage <<endl; afs<<"# smon " << endl << smon <<endl; afs<<"# nmon " << endl << nmon <<endl; afs<<"# sarea " << endl << sarea <<endl; afs<<"# narea " << endl << narea <<endl; afs<<"# nations " << endl << nations <<endl; afs<<"# border " << endl << border <<endl; afs<<"# Ro " << endl << Ro <<endl; afs<<"# h " << endl << h <<endl; afs<<"# m " << endl << m <<endl; afs<<"# fe " << endl << fe <<endl; afs<<"# q " << endl << q <<endl; afs<<"# sigR " << endl << sigR <<endl; afs<<"# weight at age " << endl << wa <<endl; afs<<"# fecundity at age " << endl << fa <<endl; afs<<"# vulnerability at age " << endl << va <<endl; afs<<"# minPos "<< endl << minPos <<endl; afs<<"# Total effort by country and year " << endl << TotEffyear <<endl; afs<<"# Total effort by country and month " << endl << TotEffmonth <<endl; afs<<"# dMinP " << endl << 0.00001 <<endl; afs<<"# tstp month area catage " << endl << obsCatchNatAge <<endl; afs<<"# eof " << endl << 999 <<endl; }
std::string fuzzy::calc_digest () { fuzzy_state * ctx = fuzzy_new () ; auto_fuzzy_state afs (ctx) ; if (ctx == 0) THROW_XDELTA_EXCEPTION_NO_ERRNO ("Out of memory") ; char_buffer<uchar_t> buff (BUFLEN); reader_.open_file () ; while (true ) { int bytes = reader_.read_file (buff.begin (), (uint32_t)buff.size ()); if (bytes == 0 ) break ; if (0 != fuzzy_update (afs.ctx, buff.begin (), bytes)) THROW_XDELTA_EXCEPTION ("fuzzy update failed.") ; } char result [FUZZY_MAX_RESULT]; if (0 != fuzzy_digest (afs.ctx, result, FUZZY_FLAG_ELIMSEQ)) THROW_XDELTA_EXCEPTION ("fuzzy digest failed."); reader_.close_file () ; return std::string(result) ; }
void rsamplems::readms (string filename){ ifstream inp (filename.c_str()); if (!inp.is_open()){ cerr << "Error reading file "<< filename <<endl; exit(1); } string line; int linenum = 0; int chrindex = 0; int snpindex = 0; int nsnp = 0; double totalw = 0; ofstream snpfs (snpfile.c_str()); int totalsnps = 0; vector<int> nsegsites (nsamples,0); int totalnind = 0 ; vector<int> nind (nsamples,0); for (int i = 0 ; i < nsamples; i++) { nind[i] = samples[i]; totalnind += nind[i]; } char ** snpmat = new char*[totalnind]; int **freq = new int*[nsamples]; double **td = new double *[nsamples]; double **thetaw = new double *[nsamples]; for (int i = 0 ; i < nsamples; i++) { td[i] = new double[reps]; thetaw[i] = new double[reps]; } double abba = 0 ; double baba = 0 ; double abba2 = 0 ; double baba2 = 0 ; double fstnum = 0; double fstdenom = 0; vector<double> chrabba = vector<double>(reps,0); vector<double> chrbaba = vector<double>(reps,0); vector<double> chrsnps = vector<double>(reps,0); vector<double> chrfstnum = vector<double> (reps,0); vector<double> chrfstdenom = vector<double> (reps,0); vector<double> chrw = vector<double> (reps,0); int totalnsnps = 0; int rep = 0 ; int index = 0; string id; double time; int countmatches = 0; while ( std::getline (inp, line)){ linenum ++; io::println ("line = " + line, 2); char c = line[0]; if (c=='#') continue; if (line.empty()) continue; if (line.find ("time:") ==0 ) { vector<string> toks; functions::tokenize (line, toks, " " ); time = atof (toks[1].c_str()); } if ( line.find ("segsites:")==0) { string l1 = line.substr(9,line.length()-9); nsnp = atoi (l1.c_str()); for (int i = 0 ; i < totalnind ; i++) { snpmat[i] = new char[nsnp]; } for (int i = 0 ; i < nsamples; i++){ freq[i] = new int[nsnp]; } io::println ("SNPs = " + tostring(nsnp),2); } if ( line.find ("positions:")==0) { vector<double> genmap ; vector<double> physmap; vector<string> snpids; vector<vector<int> > geno; vector<vector<int> > haplo; vector<int> afs ( samples[0]); chrindex ++; string l1 = line.substr(10,line.length()-10); //cout << "l1 = " << l1 << endl; // io::println ("rep = " + tostring(rep),2); //cout << " rep = " << rep << endl; rep++; istringstream ss (line.substr(10,line.length()-10)); int count = 0 ; while (!ss.eof()){ double pos; ss>>pos; // cout << pos << endl; double ppos = pos * length; double gpos = ppos * rho; if (count >= nsnp ) break; count++; genmap.push_back (gpos); physmap.push_back (ppos); id = "snp" + tostring(index); snpids.push_back (id); index++; } for (int i = 0 ; i < totalnind ; i ++){ string s1, s2; std::getline (inp, s1); for (int j = 0 ; j < nsnp ; j++) { snpmat[i][j] = s1[j]; } } vector<int> nsegsites(nsamples,0); vector<double> pi(nsamples, 0 ); vector<double> h(nsamples,0); vector<double> th(nsamples,0); for (int i = 0, t = 0 ; i < nsamples; i++){ for (int j = 0 ; j < nsnp; j++){ freq[i][j] = frequency('1', j, samples[i], snpmat+t); nsegsites[i] += (freq[i][j] > 0 && freq[i][j] < 1.0); } t += samples[i]; } chrsnps[rep-1] = nsnp; totalnsnps += nsnp; for (int j = 0 ; j < nsnp ; j++) { if (freq[0][j]> 0) afs[freq[0][j]-1]++; } for (int i = 0 ; i < nsamples; i++) delete[] freq[i]; for (int i = 0 ; i < totalnind; i++) delete[] snpmat[i]; if (printsnplist) { for (int j =0 ; j < nsnp; j++){ snpfs << snpids[j] << "\t" << chrindex << "\t" << genmap[j] << "\t" << physmap[j] << endl; } } int dif = 0; int denom = 0 ; for (int j = 0 ; j < afs.size() - 1; j++){ int k = j+1; cout << k << "\t" << afs[j] << endl; dif += abs(afs[j]-oafs[j]); denom += oafs[j]; } countmatches += (dif==0); double fracmatch = 1 - ((double)dif)/denom; cout << "rep = " << rep << "\t" << fracmatch << endl; } // One set of MS sims if (io::debug >= 2) { cout << "Next MS sim " <<endl; } }