diff --git a/src/include/pair_score.hpp b/src/include/pair_score.hpp index 5017a51..1d04708 100644 --- a/src/include/pair_score.hpp +++ b/src/include/pair_score.hpp @@ -16,5 +16,6 @@ class PairScore{ void init_blosum50(); void init_blosum62(); + void init_blastn(); int query(char res1, char res2); }; diff --git a/src/include/pairwise_aligner.hpp b/src/include/pairwise_aligner.hpp index 9d4c0f2..6e66467 100644 --- a/src/include/pairwise_aligner.hpp +++ b/src/include/pairwise_aligner.hpp @@ -23,6 +23,7 @@ class PairwiseAligner{ PairScore* ps; public: PairwiseAligner(); + PairwiseAligner(std::string scoring); void set_algorithm(std::string alg); std::string get_algorithm(); void set_query(std::string query_); diff --git a/src/pair_score.cpp b/src/pair_score.cpp index 9a831e1..901c7df 100644 --- a/src/pair_score.cpp +++ b/src/pair_score.cpp @@ -6,9 +6,29 @@ PairScore::PairScore(std::string name_) std::cout << name << std::endl; if (name.compare("blosum50") == 0) init_blosum50(); else if (name.compare("blosum62") == 0) init_blosum62(); + else if (name.compare("blastn") == 0) init_blastn(); else throw "unrecognized name"; } +void PairScore::init_blastn(){ + scores.clear(); + std::string letters = "ACGTU"; + + for(auto let1 : letters){ + for (auto let2 : letters){ + std::string pair; + pair.push_back(let1); + pair.push_back(let2); + if (let1 == let2){ + scores[pair] = 1; + } + else{ + scores[pair] = -2; + } + } + } +} + void PairScore::init_blosum50(){ scores.clear(); // load data and populate map diff --git a/src/pairwise_aligner.cpp b/src/pairwise_aligner.cpp index 6e6a2c5..ad3dc69 100644 --- a/src/pairwise_aligner.cpp +++ b/src/pairwise_aligner.cpp @@ -14,11 +14,13 @@ namespace py = pybind11; -enum algorithms {local, global}; - PairwiseAligner::PairwiseAligner(){ ps = new PairScore("blosum50"); }; +PairwiseAligner::PairwiseAligner(std::string scoring){ + set_gap_penalty(-2); + ps = new PairScore(scoring); +} void PairwiseAligner::set_algorithm(std::string alg) {algorithm = alg;} std::string PairwiseAligner::get_algorithm() {return algorithm;} void PairwiseAligner::set_query(std::string query_) {query = query_;} diff --git a/tests/test_pairwise_aligner.py b/tests/test_pairwise_aligner.py index 125510b..1cd8345 100644 --- a/tests/test_pairwise_aligner.py +++ b/tests/test_pairwise_aligner.py @@ -38,4 +38,11 @@ def test_align_2(self): pa.align() - pdb.set_trace() \ No newline at end of file + def test_align_blastn(self): + pa = PairwiseAligner("blastn") + pa.algorithm = "local" + + pa.target = "GGTACGTACG" + pa.query = "ACCT" + + pa.align() \ No newline at end of file