def test_compute_distances12(adata_cdr3, adata_cdr3_mock_distance_calculator): """Test for #174. Gracefully handle the case when there are no distances. """ adata_cdr3.obs["IR_VJ_1_cdr3"] = np.nan adata_cdr3.obs["IR_VDJ_1_cdr3"] = np.nan # test both receptor arms, primary chain only tn = IrNeighbors( adata_cdr3, metric=adata_cdr3_mock_distance_calculator, receptor_arms="all", dual_ir="primary_only", sequence="aa", cutoff=0, ) tn.compute_distances() print(tn.dist.toarray()) npt.assert_equal(tn.dist.toarray(), np.zeros((5, 5)))
def test_compute_distances11(adata_cdr3, adata_cdr3_mock_distance_calculator): tn = IrNeighbors( adata_cdr3, metric=adata_cdr3_mock_distance_calculator, receptor_arms="all", dual_ir="all", sequence="aa", ) tn.compute_distances() print(tn.dist.toarray()) npt.assert_equal( tn.dist.toarray(), np.array( [ [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], ] ), )
def test_compute_distances6(adata_cdr3, adata_cdr3_mock_distance_calculator): # test both receptor arms, primary chain only tn = IrNeighbors( adata_cdr3, metric=adata_cdr3_mock_distance_calculator, receptor_arms="all", dual_ir="primary_only", sequence="aa", ) tn.compute_distances() print(tn.dist.toarray()) npt.assert_equal( tn.dist.toarray(), np.array( [ [1, 13, 0, 0, 0], [13, 1, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], ] ), )
def test_compute_distances3(adata_cdr3, adata_cdr3_mock_distance_calculator): # test single chain with custom distance tn = IrNeighbors( adata_cdr3, metric=adata_cdr3_mock_distance_calculator, receptor_arms="VJ", dual_ir="primary_only", sequence="aa", ) tn.compute_distances() assert tn.dist.nnz == 9 npt.assert_equal( tn.dist.toarray(), np.array( [ [1, 4, 0, 1, 0], [4, 1, 0, 4, 0], [0] * 5, [1, 4, 0, 1, 0], [0] * 5, ] ), )
def test_compute_distances2(adata_cdr3, adata_cdr3_mock_distance_calculator): # test single receptor arm with multiple chains and identity distance tn = IrNeighbors( adata_cdr3, metric="identity", cutoff=0, receptor_arms="VJ", dual_ir="any", sequence="aa", ) tn.compute_distances() npt.assert_equal( tn.dist.toarray(), np.array( [ [1, 1, 0, 1, 1], [1, 1, 0, 0, 0], [0] * 5, [1, 0, 0, 1, 1], [1, 0, 0, 1, 1], ] ), )
def test_compute_distances5(adata_cdr3, adata_cdr3_mock_distance_calculator): # test single receptor arm with multiple chains and custom distance tn = IrNeighbors( adata_cdr3, metric=adata_cdr3_mock_distance_calculator, receptor_arms="VJ", dual_ir="all", sequence="aa", ) tn.compute_distances() print(tn.dist.toarray()) npt.assert_equal( tn.dist.toarray(), np.array( [ [1, 0, 0, 4, 0], [0, 1, 0, 0, 4], [0, 0, 0, 0, 0], [4, 0, 0, 1, 0], [0, 4, 0, 0, 1], ] ), )