Skip to content

Commit

Permalink
added functionality to query the range of alignment for target and qu…
Browse files Browse the repository at this point in the history
…ery separately
  • Loading branch information
sodiumnitrate committed Nov 6, 2024
1 parent 0f30fdc commit e0d8716
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sequence_analysis/pairwise_aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ def print(self, char_per_line=80):
print(query_aligned[i*char_per_line:(i+1)*char_per_line])
print(match[i*char_per_line:(i+1)*char_per_line])
print(target_aligned[i*char_per_line:(i+1)*char_per_line])


# TODO: refactor below.
def get_query_range(self):
"""
Function to get the range of the query that aligns with the target.
"""
query_aligned = self.get_query_aligned().replace('-','')
start = self.query.find(query_aligned)
end = self.query[::-1].find(query_aligned[::-1])
end = len(self.query) - end - 1
return start, end

def get_target_range(self):
"""
Function to get the range of the target that aligns with the query.
"""
target_aligned = self.get_target_aligned().replace('-','')
start= self.target.find(target_aligned)
end = self.target[::-1].find(target_aligned[::-1])
end = len(self.target) - end - 1
return start, end
15 changes: 15 additions & 0 deletions tests/test_pairwise_aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ def test_align_3(self):
pa.target = "MKA"
pa.align()

def test_get_alignment_range(self):
pa = PairwiseAligner()
pa.algorithm = "local"
pa.query = "MCDDVAALVVD"
pa.target = "DVAALV"
pa.align()

qs, qe = pa.get_query_range()
assert qs == 3
assert qe == 8

ts, te = pa.get_target_range()
assert ts == 0
assert te == len(pa.target)-1

def test_align_blastn(self):
pa = PairwiseAligner("blastn", -2)
pa.algorithm = "local"
Expand Down

0 comments on commit e0d8716

Please sign in to comment.