def test_transformNonesToHalfwayPositions_allNonesButOneReturnsTransformedArray( self ): array = [None, None, 0, None, None] actual = AlignedPairs.transform_Nones_to_halfway_positions(array) expected = [-0.5, -0.5, 0, 0.5, 0.5] assert actual == expected
def test_getPairsInQueryInterval_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_pairs_in_query_interval(interval) expected = aligned_pairs 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_initAlignedPairsEmptyList(self): actual = AlignedPairs([]) expected = [] assert actual == expected
def test_initAlignedPairsNoArguments(self): actual = AlignedPairs() expected = [] assert actual == expected
def test_transformNonesToHalfwayPositions_allNonesRaisesException(self): with pytest.raises(ValueError): AlignedPairs.transform_Nones_to_halfway_positions([None, None])
def test_transformNonesToHalfwayPositions_severalNonesReturnsTransformedArray(self): array = [None, 5, None, None, 6, None, None] actual = AlignedPairs.transform_Nones_to_halfway_positions(array) expected = [4.5, 5, 5.5, 5.5, 6, 6.5, 6.5] assert actual == expected
def test_transformNonesToHalfwayPositions_noNonesReturnsInput(self): array = [1, 2] actual = AlignedPairs.transform_Nones_to_halfway_positions(array) expected = array assert actual == expected
def test_transformNonesToHalfwayPositions_emptyReturnsEmpty(self): actual = AlignedPairs.transform_Nones_to_halfway_positions([]) expected = [] assert actual == expected
def test_getRefPositions_allAlignedPairsAreNoneAndTransformRaisesException( self, *mocks ): aligned_pairs = AlignedPairs([AlignedPair(10, None, None)]) with pytest.raises(ValueError): aligned_pairs.get_ref_positions(transform_Nones_into_halfway_positions=True)
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 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))