Skip to content

Commit

Permalink
Merge pull request #455 from ChristopherBradley/454
Browse files Browse the repository at this point in the history
BUG: refactored local function _getaln into class _GetAlign to allow …
  • Loading branch information
GavinHuttley committed Dec 15, 2019
2 parents e6c16e1 + 023b764 commit 94cf953
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/cogent3/align/dp_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,25 @@ def calc(self, edge):
return edge.get_forward_score(use_cost_function=False)


class _GetAlign():
def __init__(self, edge, length1, length2):
try:
ratio = length1 / (length1 + length2)
except (ZeroDivisionError, FloatingPointError):
ratio = 1.0
self.edge = edge
self.ratio = ratio

def __call__(self):
return self.edge.get_viterbi_path().get_alignable(self.ratio)


class EdgeSumAndAlignDefn(CalculationDefn):
name = "pair"

def calc(self, pog1, pog2, length1, length2, bin):
edge = Edge(pog1, pog2, length1 + length2, [bin])

def _getaln():
try:
ratio = length1 / (length1 + length2)
except (ZeroDivisionError, FloatingPointError):
ratio = 1.0
return edge.get_viterbi_path().get_alignable(ratio)

edge.getaln = _getaln
edge.getaln = _GetAlign(edge, length1, length2)
return edge


Expand Down
9 changes: 9 additions & 0 deletions tests/test_app/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ def test_progressive_align_codon(self):
aln = aligner(self.seqs)
self.assertEqual(len(aln), 42)

def test_pickle_progressive_align(self):
"""test progressive_align is picklable"""
from pickle import dumps, loads

aligner = align_app.progressive_align(model="codon")
aln = aligner(self.seqs)
got = loads(dumps(aln))
self.assertTrue(got)

def test_with_genetic_code(self):
"""handles genetic code argument"""
aligner = align_app.progressive_align(model="GY94", gc="2")
Expand Down

0 comments on commit 94cf953

Please sign in to comment.