Skip to content

Instantly share code, notes, and snippets.

@traversc
Created July 17, 2025 23:21
Show Gist options
  • Select an option

  • Save traversc/d8a9314e9103306dd265c51484ab1bf9 to your computer and use it in GitHub Desktop.

Select an option

Save traversc/d8a9314e9103306dd265c51484ab1bf9 to your computer and use it in GitHub Desktop.
edlibR Rcpp script example
#include <Rcpp.h>
#include "edlib_external.h"
// [[Rcpp::depends(edlibR)]]
using namespace Rcpp;
// [[Rcpp::export]]
List edlib_test_basic() {
// simple example
std::string query = "GATTACA";
std::string target = "GCATGCU";
// build a NW global distance-only config
EdlibAlignConfig cfg = edlib_new_align_config(
-1, EDLIB_MODE_NW, EDLIB_TASK_DISTANCE, nullptr, 0
);
// run alignment
EdlibAlignResult res = edlib_align(
query.c_str(), query.size(),
target.c_str(), target.size(),
cfg
);
// extract distance
int dist = res.editDistance;
// build an extended CIGAR
char* cig_c = edlib_alignment_to_cigar(
res.alignment, res.alignmentLength,
EDLIB_CIGAR_EXTENDED
);
std::string cigar = cig_c ? std::string(cig_c) : "";
free(cig_c);
// free edlib result
edlib_free_align_result(res);
return List::create(
_["query"] = query,
_["target"] = target,
_["distance"] = dist,
_["cigar"] = cigar
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment