// pairwiseDist // [[Rcpp::export]] NumericMatrix pairwiseDistRcpp (StringVector seq, NumericMatrix dist_mat) { // allocate the matrix we will return NumericMatrix rmat(seq.length(), seq.length()); for (int i = 0; i < rmat.nrow(); i++) { for (int j = 0; j < i; j++) { // check seq equal std::string row_seq = as<std::string>(seq[i]); std::string col_seq = as<std::string>(seq[j]); double distance = seqDistRcpp(row_seq, col_seq, dist_mat); // write to output matrix rmat(i,j) = distance; rmat(j,i) = distance; } } // Add row and column names Rcpp::List dimnames = Rcpp::List::create(seq.attr("names"), seq.attr("names")); rmat.attr("dimnames") = dimnames; return rmat; }
//' Calculate pairwise equivalence between sequences //' //' \code{pairwiseEqual} determined pairwise equivalence between a pairs in a //' set of sequences, excluding ambiguous positions (Ns and gaps). //' //' @param seq character vector containing a DNA sequences. //' //' @return A logical matrix of equivalence between each entry in \code{seq}. //' Values are \code{TRUE} when sequences are equivalent and \code{FALSE} //' when they are not. //' //' @seealso Uses \link{seqEqual} for testing equivalence between pairs. //' See \link{pairwiseDist} for generating a sequence distance matrix. //' //' @examples //' # Gaps and Ns will match any character //' seq <- c(A="ATGGC", B="ATGGG", C="ATGGG", D="AT--C", E="NTGGG") //' d <- pairwiseEqual(seq) //' rownames(d) <- colnames(d) <- seq //' d //' //' @export // [[Rcpp::export]] LogicalMatrix pairwiseEqual (StringVector seq) { // allocate the matrix we will return LogicalMatrix rmat(seq.length(), seq.length()); for (int i = 0; i < rmat.nrow(); i++) { for (int j = 0; j <= i; j++) { // check seq equal std::string row_seq = as<std::string>(seq[i]); std::string col_seq = as<std::string>(seq[j]); bool is_equal = seqEqual(row_seq, col_seq); // write to output matrix rmat(i,j) = is_equal; rmat(j,i) = is_equal; } } // Add row and column names Rcpp::List dimnames = Rcpp::List::create(seq.attr("names"), seq.attr("names")); rmat.attr("dimnames") = dimnames; return rmat; }