def testDrawMiniAlignmentMarkUp(self): self.alignment, self.names = readMSA("./tests/test_files/example1.fasta") self.dest = "./tests/test_files/test_mini_markup.png" self.legend = "./tests/test_files/test_mini_markup_legend.png" expected = image.imread('./tests/test_files/expected_mini_ali_markup.png') markup_dict = {'remove_divergent': {'Seq1'}, 'remove_gaponly': {89, 90, 91, 92, 93, 94, 95}, 'remove_insertions': {22, 23, 24, 25, 26, 27}, 'crop_ends': {'Seq5': ((np.array([]), np.array([92, 93, 94, 95])))}, 'remove_short': {'Seq6'}} logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: miniAlignments.drawMiniAlignment(self.alignment, self.names, logger, self.dest, 'nt', 300, None, 5, 3, True, markup_dict, False) mini_alignment = image.imread(self.dest) # added a bit of leeway to allow for images created on different # machines - they are visually identical but have minor differences # in rendering - look for 95% structural similarity simi = skimage.metrics.structural_similarity(expected, mini_alignment, multichannel=True) self.assertTrue(simi > 0.9)
def testRemoveShort(self, min_length, expected): exp_array, names = readMSA(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: result_ali, r = parsingFunctions.removeTooShort(self.in_array, self.nams, self.rm_file, mock_debug, min_length) self.assertTrue((result_ali == exp_array).all()) self.assertGreaterEqual(len(self.in_array), len(result_ali))
def testRemoveGapOnly(self): expected = "./tests/test_files/remove_gaponly_cleaned.fasta" exp_array, names = readMSA(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: result_ali, r, self.relativePositions = parsingFunctions.removeGapOnly(self.in_array, self.relativePositions, self.rm_file, mock_debug) self.assertTrue((result_ali == exp_array).all()) self.assertEqual(len(self.in_array), len(result_ali))
def testCropEnds(self, mingap, redefine_perc, expected): exp_array, names = readMSA(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: result_ali, names = parsingFunctions.cropEnds(self.in_array, self.nams, self.relativePositions, self.rm_file, mock_debug, mingap, redefine_perc) self.assertEqual(result_ali[0,:].size, exp_array[0,:].size) self.assertEqual(len(self.in_array), len(result_ali)) self.assertTrue((result_ali == exp_array).all())
def testRemoveInsertions(self, min_size, max_size, min_flank, expected): exp_array, names = readMSA(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: result_ali, r, self.relativePositions = parsingFunctions.removeInsertions(self.in_array, self.relativePositions, self.rm_file, mock_debug, min_size, max_size, min_flank) # check if dimensions are equal first self.assertEqual(result_ali[0,:].size, exp_array[0,:].size) self.assertEqual(len(self.in_array), len(result_ali)) self.assertTrue((result_ali == exp_array).all())
def testFindConsensus(self, MSA, type, expected_consensus, expected_coverage): alignment, names = readMSA(MSA) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: consensus, coverage = consensusSeq.findConsensus( alignment, logger, type) coverage_rounded = [round(num, 2) for num in coverage] self.assertEqual(consensus, expected_consensus) self.assertEqual(coverage_rounded, expected_coverage)
def testRemoveDivergent(self, percidentity, expected): exp_array, names = readMSA(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: result_ali, r = parsingFunctions.removeDivergent(self.in_array, self.nams, self.rm_file, mock_debug, percidentity) self.assertEqual(result_ali[0,:].size, exp_array[0,:].size) self.assertEqual(result_ali[:,0].size, exp_array[:,0].size) self.assertGreaterEqual(len(self.in_array), len(result_ali)) self.assertTrue((result_ali == exp_array).all())
def testArrNumeric(self): alignment, names = readMSA("./tests/test_files/consensus_example_nt.fasta") arr_expected = [[1, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 0, 4, 2, 4, 3], [1, 1, 1, 3, 3, 3, 3, 3, 3, 4, 4, 0, 4, 2, 4, 2], [1, 1, 1, 3, 3, 3, 3, 3, 3, 4, 4, 0, 0, 1, 2, 4], [1, 1, 1, 2, 4, 2, 4, 4, 0, 4, 4, 0, 4, 2, 4, 2], [4, 2, 1, 3, 3, 3, 3, 3, 3, 4, 4, 0, 4, 2, 4, 2], [2, 4, 0, 3, 3, 3, 3, 3, 3, 4, 2, 1, 2, 4, 0, 2],] arr_int, colour_map = miniAlignments.arrNumeric(alignment,'nt') self.assertTrue((arr_int == arr_expected).all())
def setUp(self): self.dest = "./tests/test_files/test_mini.png" self.alignment, self.names = readMSA("./tests/test_files/example1.fasta") self.ali_width = len(self.alignment[0]) self.ali_height = len(self.alignment) self.markup_dict = {'remove_divergent': {'Seq1'}, 'remove_gaponly': {89, 90, 91, 92, 93, 94, 95}, 'remove_insertions': {22, 23, 24, 25, 26, 27}, 'crop_ends': {'Seq5': ((np.array([]), np.array([92, 93, 94, 95])))}, 'remove_short': {'Seq6'}} logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: # make mini plot without markup self.mini_plot = miniAlignments.drawMiniAlignment(self.alignment, self.names, logger, self.dest, 'nt', 300, None, 5, 3, False, None, True) # make mini plot with markup self.mini_plot_expected = miniAlignments.drawMiniAlignment(self.alignment, self.names, logger, self.dest, 'nt', 300, None, 5, 3, True, self.markup_dict, True)
def testDrawMiniAlignment(self, input, expected, type): self.alignment, self.names = readMSA(input) self.dest = "./tests/test_files/test_mini.png" self.legend = "" expected = image.imread(expected) logger = logging.getLogger('path.to.module.under.test') with mock.patch.object(logger, 'debug') as mock_debug: miniAlignments.drawMiniAlignment(self.alignment, self.names, logger, self.dest, type, 300, None, 5, 3, False, None, False) mini_alignment = image.imread(self.dest) # added a bit of leeway to allow for images created on different # machines - they are visually identical but have minor differences # in rendering - look for 95% structural similarity simi = skimage.metrics.structural_similarity(expected, mini_alignment, multichannel=True) self.assertTrue(simi > 0.9)
def testMakeCoveragePlot(self): alignment, names = readMSA( "./tests/test_files/consensus_example_aa.fasta") consensusSeq.sequence_bar_logo(alignment, self.dest, 'aa') self.assertTrue(os.path.isfile(self.dest))
def setUp(self): self.in_array, self.nams = readMSA("./tests/test_files/example1.fasta") self.relativePositions = list(range(0, len(self.in_array[0]))) self.rm_file = 'mock_rmfile.txt'
def testSeqType(self, input, expected): in_array, names = readMSA(input) type = utilityFunctions.seqType(in_array) self.assertEqual(type, expected)
def setUp(self): self.input = "./tests/test_files/example1.fasta" self.in_array, self.nams = readMSA(self.input) self.removed = set() self.outfile = "writeOutfile_test.txt"
def setUp(self): self.input = "./tests/test_files/example1.fasta" self.in_array, self.nams = readMSA(self.input)
def setUp(self): self.in_array, self.nams = readMSA( "./tests/test_files/remove_gaponly_cleaned.fasta")