def test_getPairsInQueryInterval_intervalNotInPairsReturnsEmpty(self):
        interval = Interval(5, 10)

        aligned_pairs = AlignedPairs(
            [AlignedPair(1, 30, "A"), AlignedPair(2, 31, "C"), AlignedPair(3, 32, "T")]
        )
        actual = aligned_pairs.get_pairs_in_query_interval(interval)
        expected = AlignedPairs()

        assert actual == expected
    def test_getQueryPositions_allAlignedPairsAreNoneNoTransformReturnsNone(self):
        aligned_pairs = AlignedPairs([AlignedPair(None, 10, "A")])

        actual = aligned_pairs.get_query_positions()
        expected = [None]

        assert actual == expected
    def test_getRefPositions_allAlignedPairsAreNoneNoTransformReturnsNone(self):
        aligned_pairs = AlignedPairs([AlignedPair(1, None, None)])

        actual = aligned_pairs.get_ref_positions()
        expected = [None]

        assert actual == expected
    def test_getQueryPositions_emptyAlignedPairsReturnsEmptyList(self, *mocks):
        aligned_pairs = AlignedPairs()

        actual = aligned_pairs.get_query_positions()
        expected = []

        assert actual == expected
 def test_getQueryPositions_allAlignedPairsAreNoneAndTransformRaisesException(
     self, *mocks
 ):
     aligned_pairs = AlignedPairs([AlignedPair(None, 10, "A")])
     with pytest.raises(ValueError):
         aligned_pairs.get_query_positions(
             transform_Nones_into_halfway_positions=True
         )
    def test_getRefPositions_twoPairsOneNoneNoTransformReturnsTwoPositionsOneNone(self):
        aligned_pairs = AlignedPairs(
            [AlignedPair(4, None, None), AlignedPair(5, 11, "C")]
        )

        actual = aligned_pairs.get_ref_positions()
        expected = [None, 11]

        assert actual == expected
    def test_getIndexOfQueryInterval_nullIntervalReturnsEmpty(self):
        interval = Interval(2, 2)

        aligned_pairs = AlignedPairs(
            [AlignedPair(1, 30, "A"), AlignedPair(2, 31, "C"), AlignedPair(3, 32, "T")]
        )
        actual = aligned_pairs.get_index_of_query_interval(interval)
        expected = (1, 1)

        assert actual == expected
    def test_getQueryPositions_twoPairsOneNoneNoTransformReturnsTwoPositionsOneNone(
        self
    ):
        aligned_pairs = AlignedPairs(
            [AlignedPair(None, 10, "A"), AlignedPair(5, 11, "C")]
        )

        actual = aligned_pairs.get_query_positions()
        expected = [None, 5]

        assert actual == expected
    def test_getAlignmentTypes(self, alignedPairMocked):
        aligned_pairs = AlignedPairs([AlignedPair()] * 4)

        actual = aligned_pairs.get_alignment_types()
        expected = [
            AlignmentType.MATCH,
            AlignmentType.MISMATCH,
            AlignmentType.DELETION,
            AlignmentType.INSERTION,
        ]

        assert actual == expected
    def test_getRefPositions_twoPairsOneNoneTransformReturnsTwoPositionsOneHalfway(
        self, *mocks
    ):
        aligned_pairs = AlignedPairs(
            [AlignedPair(1, None, None), AlignedPair(2, 5, "C")]
        )

        actual = aligned_pairs.get_ref_positions(
            transform_Nones_into_halfway_positions=True
        )
        expected = [4.5, 5.0]

        assert actual == expected
    def test_getQueryPositions_twoPairsOneNoneTransformReturnsTwoPositionsOneHalfway(
        self, *mocks
    ):
        aligned_pairs = AlignedPairs(
            [AlignedPair(None, 10, "A"), AlignedPair(5, 11, "C")]
        )

        actual = aligned_pairs.get_query_positions(
            transform_Nones_into_halfway_positions=True
        )
        expected = [4.5, 5.0]

        assert actual == expected
    def test_getPairsInQueryInterval_intervalOverlapsRightOfPairs(self):
        interval = Interval(4, 12)

        aligned_pairs = AlignedPairs(
            [
                AlignedPair(3, 30, "A"),
                AlignedPair(4, 31, "C"),
                AlignedPair(None, 32, "T"),
            ]
        )
        actual = aligned_pairs.get_pairs_in_query_interval(interval)
        expected = aligned_pairs[1:]

        assert actual == expected
    def test_getIndexOfQueryInterval_intervalOverlapsRightOfPairs(self):
        interval = Interval(4, 12)

        aligned_pairs = AlignedPairs(
            [
                AlignedPair(3, 30, "A"),
                AlignedPair(4, 31, "C"),
                AlignedPair(None, 32, "T"),
            ]
        )
        actual = aligned_pairs.get_index_of_query_interval(interval)
        expected = (1, 3)

        assert actual == expected
    def test_initAlignedPairsListWith4AlignedPairs(self):
        aligned_pairs_as_tuples = [
            (0, 34, "A"),
            (1, None, None),
            (2, 35, "A"),
            (None, 36, "A"),
        ]

        actual = AlignedPairs(aligned_pairs_as_tuples)
        expected = [
            AlignedPair(*aligned_pair_as_tuple)
            for aligned_pair_as_tuple in aligned_pairs_as_tuples
        ]

        assert actual == expected
    def test_getIndexOfQueryInterval_intervalEnvelopedInPairs(self):
        interval = Interval(5, 7)

        aligned_pairs = AlignedPairs(
            [
                AlignedPair(4, 30, "A"),
                AlignedPair(None, 31, "A"),
                AlignedPair(5, 32, "A"),
                AlignedPair(None, 33, "A"),
                AlignedPair(6, 34, "A"),
                AlignedPair(None, 35, "A"),
            ]
        )
        actual = aligned_pairs.get_index_of_query_interval(interval)
        expected = (2, 5)

        assert actual == expected
    def test_getIndexOfQueryInterval_intervalSpansPairs(self):
        interval = Interval(1, 10)

        aligned_pairs = AlignedPairs(
            [
                AlignedPair(4, 30, "A"),
                AlignedPair(None, 31, "A"),
                AlignedPair(5, 32, "A"),
                AlignedPair(None, 33, "A"),
                AlignedPair(6, 34, "A"),
                AlignedPair(None, 35, "A"),
            ]
        )
        actual = aligned_pairs.get_index_of_query_interval(interval)
        expected = (0, 6)

        assert actual == expected
    def test_getPairsInQueryInterval_intervalEnvelopedInPairs(self):
        interval = Interval(5, 7)

        aligned_pairs = AlignedPairs(
            [
                AlignedPair(4, 30, "A"),
                AlignedPair(None, 31, "A"),
                AlignedPair(5, 32, "A"),
                AlignedPair(None, 33, "A"),
                AlignedPair(6, 34, "A"),
                AlignedPair(None, 35, "A"),
            ]
        )
        actual = aligned_pairs.get_pairs_in_query_interval(interval)
        expected = aligned_pairs[2:5]

        assert actual == expected
 def get_aligned_pairs(self,
                       matches_only: bool = False,
                       with_seq: bool = False) -> AlignedPairs:
     return AlignedPairs(
         self.record.get_aligned_pairs(matches_only=matches_only,
                                       with_seq=with_seq))
예제 #19
0
class TestPrecisionMasker:
    @patch.object(
        Classification, "is_unmapped", return_value=True, new_callable=PropertyMock
    )
    def test_getIntervalWhereProbeAlignsToTruth_ProbeIsUnmappedReturnsNone(self, *mock):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = None

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs(
            [(0, 34, "A"), (1, None, None), (2, 35, "A"), (None, 36, "A")]
        ),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(0, 4))
    def test_getIntervalWhereProbeAlignsToTruth_probeMapsReturnsInterval(self, *mock):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(34, 37, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs(
            [
                (8, 50, "A"),
                (9, None, None),
                (10, None, None),
                (11, None, None),
                (12, 51, "C"),
            ]
        ),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(1, 2))
    def test_getIntervalWhereProbeAlignsToTruth_probeIsInsertionWithTwoNonesAfterReturnsIntervalAroundInsertion(
        self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(50, 52, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs(
            [
                (8, 50, "A"),
                (9, None, None),
                (10, None, None),
                (11, None, None),
                (12, 51, "C"),
            ]
        ),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(2, 3))
    def test_getIntervalWhereProbeAlignsToTruth_probeIsInsertionFlankedByNoneReturnsIntervalAroundInsertion(
        self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(50, 52, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs(
            [
                (8, 50, "A"),
                (9, None, None),
                (10, None, None),
                (11, None, None),
                (12, 51, "C"),
            ]
        ),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(3, 4))
    def test_getIntervalWhereProbeAlignsToTruth_probeIsInsertionWithTwoNonesBeforeReturnsIntervalAroundInsertion(
        self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(50, 52, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs([(5, None, None), (6, 4, "A"), (7, None, None)]),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(0, 3))
    def test_getIntervalWhereProbeAlignsToTruth_refPositionsWhereProbeMapsFlankedByNoneReturnsInterval(
        self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(3, 6, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(Probe, "chrom", return_value="chrom1", new_callable=PropertyMock)
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs([(5, None, None), (6, 0, "A"), (7, None, None)]),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(0, 3))
    def test_getIntervalWhereProbeAlignsToTruth_refPositionsWhereProbeMapsContainsZeroDontReturnNegative(
        self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = Interval(0, 2, "chrom1")

        assert actual == expected

    @patch.object(
        Classification, "is_unmapped", return_value=False, new_callable=PropertyMock
    )
    @patch.object(
        Classification,
        "get_aligned_pairs",
        return_value=AlignedPairs([(5, 0, "A"), (6, 1, "C"), (7, 2, "G"), (8, 3, "G")]),
    )
    @patch.object(AlignedPairs, "get_index_of_query_interval", return_value=(0, 0))
    @patch.object(AlignedPairs, "get_ref_positions", return_value=[])
    def test_getIntervalWhereProbeAlignsToTruth_refPositionsQueryAlignsToIsEmpty_returnsNone(
            self, *mock
    ):
        classification = Classification()

        actual = PrecisionMasker.get_interval_where_probe_aligns_to_truth(
            classification
        )
        expected = None

        assert actual == expected
    def test_initAlignedPairsEmptyList(self):
        actual = AlignedPairs([])
        expected = []

        assert actual == expected
    def test_initAlignedPairsNoArguments(self):
        actual = AlignedPairs()
        expected = []

        assert actual == expected