Skip to content

Commit

Permalink
blastn style alignment option
Browse files Browse the repository at this point in the history
  • Loading branch information
sodiumnitrate committed Oct 11, 2023
1 parent 09e6d09 commit 4e72b77
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/include/pair_score.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ class PairScore{

void init_blosum50();
void init_blosum62();
void init_blastn();
int query(char res1, char res2);
};
1 change: 1 addition & 0 deletions src/include/pairwise_aligner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
20 changes: 20 additions & 0 deletions src/pair_score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/pairwise_aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;}
Expand Down
9 changes: 8 additions & 1 deletion tests/test_pairwise_aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ def test_align_2(self):

pa.align()

pdb.set_trace()
def test_align_blastn(self):
pa = PairwiseAligner("blastn")
pa.algorithm = "local"

pa.target = "GGTACGTACG"
pa.query = "ACCT"

pa.align()

0 comments on commit 4e72b77

Please sign in to comment.