499 |
499 |
|
delete [] G; |
500 |
500 |
|
return(out); |
501 |
501 |
|
} |
|
502 |
+ |
RcppExport SEXP pairwise_given_0rf(SEXP m_R, |
|
503 |
+ |
SEXP mrk_pairs_R, |
|
504 |
+ |
SEXP geno_R, |
|
505 |
+ |
SEXP dP_R, |
|
506 |
+ |
SEXP dQ_R, |
|
507 |
+ |
SEXP count_cache_R) |
|
508 |
+ |
{ |
|
509 |
+ |
Rcpp::NumericMatrix mrk_pairs = Rcpp::as<Rcpp::NumericMatrix>(mrk_pairs_R); |
|
510 |
+ |
Rcpp::NumericMatrix geno = Rcpp::as<Rcpp::NumericMatrix>(geno_R); |
|
511 |
+ |
Rcpp::NumericVector dP = Rcpp::as<Rcpp::NumericVector>(dP_R); |
|
512 |
+ |
Rcpp::NumericVector dQ = Rcpp::as<Rcpp::NumericVector>(dQ_R); |
|
513 |
+ |
Rcpp::List count_cache = Rcpp::as<Rcpp::List>(count_cache_R); |
|
514 |
+ |
Rcpp::NumericVector d_pair(4); |
|
515 |
+ |
Rcpp::List out(mrk_pairs.ncol()); |
|
516 |
+ |
int m = Rcpp::as<int>(m_R); |
|
517 |
+ |
int n_ind = geno.ncol(); |
|
518 |
+ |
for(int k=0; k < mrk_pairs.ncol(); k++) |
|
519 |
+ |
{ |
|
520 |
+ |
//Rcpp::Rcout << mrk_pairs(0,k) << " - " << mrk_pairs(1,k) << std::endl; |
|
521 |
+ |
int id = (m+1)*(m+1)*(m+1)*dQ[mrk_pairs(1,k)]+(m+1)*(m+1)*dQ[mrk_pairs(0,k)]+(m+1)*dP[mrk_pairs(1,k)]+dP[mrk_pairs(0,k)]+1; |
|
522 |
+ |
//Rcpp::Rcout << "id: " << id << std::endl; |
|
523 |
+ |
Rcpp::List temp_list = count_cache[(id-1)]; |
|
524 |
+ |
//Rcpp::List temp_list = count_cache[k]; |
|
525 |
+ |
if(temp_list.size() > 1) |
|
526 |
+ |
{ |
|
527 |
+ |
NumericVector gen_1 = geno( mrk_pairs(0,k), _); |
|
528 |
+ |
NumericVector gen_2 = geno( mrk_pairs(1,k), _); |
|
529 |
+ |
Rcpp::NumericMatrix res(3, temp_list.size()); |
|
530 |
+ |
Rcpp::CharacterVector zn = temp_list.attr( "names" ) ; |
|
531 |
+ |
colnames(res)=zn; |
|
532 |
+ |
for(int i=0; i < temp_list.size(); i++) |
|
533 |
+ |
{ |
|
534 |
+ |
Rcpp::NumericMatrix count_mat = temp_list[i] ; |
|
535 |
+ |
Rcpp::List dimnames = count_mat.attr( "dimnames" ) ; |
|
536 |
+ |
Rcpp::CharacterVector z = dimnames[0]; |
|
537 |
+ |
Rcpp::NumericVector dk(z.size()), dk1(z.size()); |
|
538 |
+ |
std::string delimiter = " "; |
|
539 |
+ |
for(int j=0; j < z.size(); j++) |
|
540 |
+ |
{ |
|
541 |
+ |
std::string lnames = Rcpp::as<std::string>(z(j)); |
|
542 |
+ |
dk(j) = std::stoi(lnames.substr(0,lnames.find(delimiter))); |
|
543 |
+ |
dk1(j) = std::stoi(lnames.substr(lnames.find(delimiter)+1, lnames.length())); |
|
544 |
+ |
} |
|
545 |
+ |
vector<double> x{0.0, 0.2, 0.5}; |
|
546 |
+ |
double lltemp, ll, curx; |
|
547 |
+ |
ll = twopt_likelihood_dosage(x[0], m, n_ind, dP[mrk_pairs(0,k)], dQ[mrk_pairs(0,k)], dk, dk1, gen_1, gen_2, count_mat); |
|
548 |
+ |
curx = x[0]; |
|
549 |
+ |
for(int j=1; j < x.size(); j++) |
|
550 |
+ |
{ |
|
551 |
+ |
lltemp = twopt_likelihood_dosage(x[j], m, n_ind, dP[mrk_pairs(0,k)], dQ[mrk_pairs(0,k)], dk, dk1, gen_1, gen_2, count_mat); |
|
552 |
+ |
if(ll - lltemp < 0.0) break; |
|
553 |
+ |
else{ |
|
554 |
+ |
curx = x[j]; |
|
555 |
+ |
ll = lltemp; |
|
556 |
+ |
} |
|
557 |
+ |
} |
|
558 |
+ |
res(0,i) = curx; |
|
559 |
+ |
res(1,i) = ll; |
|
560 |
+ |
res(2,i) = ll; |
|
561 |
+ |
} |
|
562 |
+ |
out(k)=res; |
|
563 |
+ |
} |
|
564 |
+ |
else |
|
565 |
+ |
{ |
|
566 |
+ |
Rcpp::NumericVector d_out(4); |
|
567 |
+ |
d_out(0)=dP[mrk_pairs(0,k)]; |
|
568 |
+ |
d_out(1)=dP[mrk_pairs(1,k)]; |
|
569 |
+ |
d_out(2)=dQ[mrk_pairs(0,k)]; |
|
570 |
+ |
d_out(3)=dQ[mrk_pairs(1,k)]; |
|
571 |
+ |
out(k)=d_out; |
|
572 |
+ |
} |
|
573 |
+ |
} |
|
574 |
+ |
return(out); |
|
575 |
+ |
} |
502 |
576 |
|
//end of file two_pts_est.cpp |