def test_bad_partitions(self): with TemporaryDirectory(change=True): for i in [-10, -1, 0]: with self.assertRaisesRegex(ValueError, "Partitions must be greater than 0"): core.write_fastas_with_all_genes(self.clusters, "test", partitions=i) for i in ["str", None, 1.5]: with self.assertRaisesRegex(TypeError, "Partitions must be an int greater than 0"): core.write_fastas_with_all_genes(self.clusters, "test", partitions=i)
def test_single_partition(self): self.dummy_cluster.cds_children = [DummyCDS(1, 3)] * 3 with TemporaryDirectory(change=True): files = core.write_fastas_with_all_genes(self.clusters, "test.fasta", partitions=1) assert files == ["test.fasta"] assert os.path.exists("test.fasta") expected = "".join(">L{0}\nS{0}\n".format(i) for i in range(len(self.clusters)*3)) assert open("test.fasta").read() == expected
def test_single_file(self): self.add_cdses_to_region([DummyCDS(1, i) for i in range(3, 6)]) with TemporaryDirectory(change=True): files = core.write_fastas_with_all_genes(self.regions, "test.fasta") assert files == ["test.fasta"] assert os.path.exists("test.fasta") expected = "".join(">L{0}\nS{0}\n".format(i) for i in range(len(self.regions) * 3)) assert open("test.fasta").read() == expected
def test_multiple_files(self): self.dummy_cluster.cds_children = [DummyCDS(1, 3)] * 3 for partitions in [2, 3]: with TemporaryDirectory(change=True): self.index = 0 chunk_size = (len(self.clusters) * 3) // partitions files = core.write_fastas_with_all_genes(self.clusters, "test.fasta", partitions=partitions) assert files == ["test%d.fasta" % i for i in range(partitions)] for index in range(partitions): assert os.path.exists("test%d.fasta" % index) print(index, chunk_size) contents = open("test%d.fasta" % index).read() assert contents.count(">") == chunk_size expected = "".join(">L{0}\nS{0}\n".format(i + index * chunk_size) for i in range(chunk_size)) assert contents == expected
def test_empty(self): with TemporaryDirectory(change=True): with self.assertRaisesRegex( ValueError, "Diamond search space contains no sequences"): core.write_fastas_with_all_genes(self.regions, "test")