def test_calculate_percent_identity(self):
        """
        Test the calculate percent identity function
        """

        cigar_string = "100S84M16S"
        md_field = "MD:Z:27A5G2T6G4T1A6T2C0A7A1A0A0C0G1G1A5"

        expected_identity = 100.0 * (68 / 84.0)

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_two_match_mismatch_identifiers(self):
        """
        Test the calculate percent identity function
        Test cigar string with the two match and mistmatch identifiers (X and =)
        """

        cigar_string = "100I84M1X2=2D"
        md_field = "MD:Z:27A5G2T6G4T1A6T2C0A7A1A0A0C0G1G1A5"

        expected_identity = 100.0 * (68 / 189.0)

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_insert_delete(self):
        """
        Test the calculate percent identity function
        Test cigar string with insert and deletes
        """

        cigar_string = "100I84M2D"
        md_field = "MD:Z:27A5G2T6G4T1A6T2C0A7A1A0A0C0G1G1A5"

        expected_identity = 100.0 * (68 / 186.0)

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_missing_md_field(self):
        """
        Test the calculate percent identity function
        Test with an empty md field
        """

        cigar_string = "100S84M16S"
        md_field = ""

        expected_identity = 0.0

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_missing_cigar_identifier(self):
        """
        Test the calculate percent identity function
        Test with a cigar string that does not have the match/mismatch identifier
        """

        cigar_string = "*"
        md_field = "MD:Z:84"

        expected_identity = 0.0

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_simple_md_field(self):
        """
        Test the calculate percent identity function
        Test with a simple md field where all bases match
        """

        cigar_string = "100S84M16S"
        md_field = "MD:Z:84"

        expected_identity = 100.0 * (84 / 84.0)

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(identity, expected_identity)
    def test_calculate_percent_identity_multiple_M_cigar_fields_reference_length(
            self):
        """
        Test the calculate percent identity function
        Test with multiple M fields to compute reference length
        """

        cigar_string = "100S84M16S10M5D2N3S4I3=3X"
        md_field = "MD:Z:27A5G2T6G4T1A6T2C0A7A1A0A0C0G1G1A5"

        expected_length = 84 + 10 + 5 + 2 + 3 + 3

        identity, alignment_length, reference_length = nucleotide.calculate_percent_identity(
            cigar_string, md_field)

        self.assertEqual(reference_length, expected_length)