示例#1
0
    def test_get_table(self):
        """Test get_table method."""

        # Negative tests:
        for table_id in [-1, "hello"]:
            self.assertIsNone(table.get_table(table_id))

        # Positive tests:
        for table_id, dna in itertools.product([45372, "45372", "Abies alba"],
                                               [True, False]):
            self.__test_table(table.get_table(table_id, dna=dna), dna=dna)
示例#2
0
    def test_sample(self):
        """Test sample method."""
        codon_table = table.get_table("Escherichia coli")
        amino_acid = "L"

        # Get codon usage for amino acid:
        aa_codons = codon_table[amino_acid]

        # Apply sample a number of times:
        sampled = [utils.sample(codon_table, amino_acid) for _ in range(10000)]

        # Test:
        self._test(sampled, aa_codons)
示例#3
0
    def test_codon_optimise(self):
        """Test codon optimise method."""
        # TODO: update in future to codon optimise random amino acid sequence,
        # then translate back to original amino acid sequence.
        # (Will need Biopython, but don't want to add extra dependency.
        codon_table = table.get_table(9606)
        amino_acid = "S"

        # Get codon usage for amino acid:
        aa_codons = codon_table[amino_acid]

        # Generate amino acid sequence and codon optimise:
        aa_seq = "".join([amino_acid] * 100000)
        dna_seq = utils.optimise(codon_table, aa_seq)

        # Extract codons from DNA sequence:
        codons = [dna_seq[i : i + 3] for i in range(0, len(dna_seq), 3)]

        # Test:
        self._test(codons, aa_codons)