Skip to content

Commit

Permalink
unit tests for new plots in consensusSeq.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KatyBrown committed May 22, 2024
1 parent 3a1325f commit f2513df
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
46 changes: 46 additions & 0 deletions tests/consensusSeqTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import numpy as np
import os
import matplotlib.pyplot as plt
from matplotlib import image

import CIAlign
import CIAlign.consensusSeq as consensusSeq
import CIAlign.utilityFunctions as utilityFunctions
from tests.helperFunctions import readMSA
import shutil
import skimage.metrics

class ConsensusSeqTests(unittest.TestCase):

Expand Down Expand Up @@ -171,6 +174,49 @@ def testMakeLinePlot(self):
consensusSeq.makeLinePlot([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.03, 0.03, 0.03, 0.03, 0.03], self.dest, "x")
self.assertTrue(os.path.isfile(self.dest))

class ConsensusSeqPlotResidueFrequenciesTest(unittest.TestCase):

def setUp(self):
self.dest = 'resfreq_test.png'

def tearDown(self):
os.remove(self.dest)

@parameterized.expand([['tests/test_files/example1.fasta', 'nt'],
['tests/test_files/example2.fasta', 'aa']])
def testPlotResidueFrequencies(self, fasta, typ):
alignment, names = readMSA(fasta)
expected = image.imread("tests/test_files/expected_resfreq_%s.png" % typ)
consensusSeq.plotResidueFrequencies(alignment, typ, self.dest)
imi = image.imread(self.dest)
simi = skimage.metrics.structural_similarity(expected,
imi,
channel_axis=-1,
data_range=1)
self.assertTrue(simi > 0.85)


class ConsensusSeqResidueChangeCountTest(unittest.TestCase):

def setUp(self):
self.dest = 'changecount_test.png'

def tearDown(self):
os.remove(self.dest)

@parameterized.expand([['tests/test_files/example1.fasta']])
def testResidueChangeCount(self, fasta):
alignment, names = readMSA(fasta)
expected = image.imread("tests/test_files/expected_changecount.png")
consensusSeq.residueChangeCount(alignment, 'nt', self.dest)
imi = image.imread(self.dest)
simi = skimage.metrics.structural_similarity(expected,
imi,
channel_axis=-1,
data_range=1)
self.assertTrue(simi > 0.85)


class ConsensusSeqSequenceLogoTest(unittest.TestCase):

def setUp(self):
Expand Down
1 change: 0 additions & 1 deletion tests/miniAlignmentsTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def testDrawMiniAlignment(self, input, expected, type, keep_numbers, plot_type,
mini_alignment,
channel_axis=-1,
data_range=1)
print ("%s %s %s %s %s" % (type, plot_type, pal, gapcol, simi))
self.assertTrue(simi > 0.85)


Expand Down
Binary file added tests/test_files/expected_changecount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_files/expected_resfreq_aa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_files/expected_resfreq_nt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2513df

Please sign in to comment.