IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

144 řádky
4.1KB

  1. #
  2. # Copyright (C) Stanislaw Adaszewski, 2020
  3. # License: GPLv3
  4. #
  5. from icosagon.data import Data, \
  6. _equal, \
  7. RelationFamily
  8. from icosagon.decode import DEDICOMDecoder
  9. import torch
  10. import pytest
  11. def test_equal_01():
  12. x = torch.rand((10, 10))
  13. y = torch.rand((10, 10)).round().to_sparse()
  14. print('x == x ?')
  15. assert torch.all(_equal(x, x))
  16. print('y == y ?')
  17. assert torch.all(_equal(y, y))
  18. print('x == y ?')
  19. with pytest.raises(ValueError):
  20. _equal(x, y)
  21. print('y == z ?')
  22. z = torch.rand((10, 10)).round().to_sparse()
  23. assert not torch.all(_equal(y, z))
  24. def test_relation_family_01():
  25. d = Data()
  26. d.add_node_type('Whatever', 10)
  27. fam = RelationFamily(d, 'Dummy-Dummy', 0, 0, True, DEDICOMDecoder)
  28. with pytest.raises(ValueError):
  29. fam.add_relation_type('Dummy-Dummy', None, None)
  30. with pytest.raises(ValueError):
  31. fam.add_relation_type('Dummy-Dummy', 'bad-value', None)
  32. with pytest.raises(ValueError):
  33. fam.add_relation_type('Dummy-Dummy', None, 'bad-value')
  34. with pytest.raises(ValueError):
  35. fam.add_relation_type('Dummy-Dummy', torch.rand((5, 5)), None)
  36. with pytest.raises(ValueError):
  37. fam.add_relation_type('Dummy-Dummy', None, torch.rand((5, 5)))
  38. with pytest.raises(ValueError):
  39. fam.add_relation_type('Dummy-Dummy', torch.rand((10, 10)), torch.rand((10, 10)))
  40. with pytest.raises(ValueError):
  41. fam.add_relation_type('Dummy-Dummy', torch.rand((10, 10)), None)
  42. def test_relation_family_02():
  43. d = Data()
  44. d.add_node_type('A', 10)
  45. d.add_node_type('B', 5)
  46. fam = RelationFamily(d, 'A-B', 0, 1, True, DEDICOMDecoder)
  47. with pytest.raises(ValueError):
  48. fam.add_relation_type('A-B', torch.rand((10, 5)).round(),
  49. torch.rand((5, 10)).round())
  50. def test_relation_family_03():
  51. d = Data()
  52. d.add_node_type('A', 10)
  53. d.add_node_type('B', 5)
  54. fam = RelationFamily(d, 'A-B', 0, 1, True, DEDICOMDecoder)
  55. fam.add_relation_type('A-B', torch.rand((10, 5)).round())
  56. assert torch.all(fam.relation_types[0].adjacency_matrix.transpose(0, 1) == \
  57. fam.relation_types[0].adjacency_matrix_backward)
  58. def test_data_01():
  59. d = Data()
  60. d.add_node_type('Gene', 1000)
  61. d.add_node_type('Drug', 100)
  62. dummy_0 = torch.zeros((100, 1000))
  63. dummy_1 = torch.zeros((1000, 100))
  64. dummy_2 = torch.zeros((100, 100))
  65. dummy_3 = torch.zeros((1000, 1000))
  66. fam = d.add_relation_family('Drug-Gene', 1, 0, True)
  67. fam.add_relation_type('Target', dummy_0)
  68. fam = d.add_relation_family('Gene-Gene', 0, 0, True)
  69. fam.add_relation_type('Interaction', dummy_3)
  70. fam = d.add_relation_family('Drug-Drug', 1, 1, True)
  71. fam.add_relation_type('Side Effect: Nausea', dummy_2)
  72. fam.add_relation_type('Side Effect: Infertility', dummy_2)
  73. fam.add_relation_type('Side Effect: Death', dummy_2)
  74. print(d)
  75. def test_data_02():
  76. d = Data()
  77. d.add_node_type('Gene', 1000)
  78. d.add_node_type('Drug', 100)
  79. dummy_0 = torch.zeros((100, 1000))
  80. dummy_1 = torch.zeros((1000, 100))
  81. dummy_2 = torch.zeros((100, 100))
  82. dummy_3 = torch.zeros((1000, 1000))
  83. fam = d.add_relation_family('Drug-Gene', 1, 0, True)
  84. with pytest.raises(ValueError):
  85. fam.add_relation_type('Target', dummy_1)
  86. fam = d.add_relation_family('Gene-Gene', 0, 0, True)
  87. with pytest.raises(ValueError):
  88. fam.add_relation_type('Interaction', dummy_2)
  89. fam = d.add_relation_family('Drug-Drug', 1, 1, True)
  90. with pytest.raises(ValueError):
  91. fam.add_relation_type('Side Effect: Nausea', dummy_3)
  92. with pytest.raises(ValueError):
  93. fam.add_relation_type('Side Effect: Infertility', dummy_3)
  94. with pytest.raises(ValueError):
  95. fam.add_relation_type('Side Effect: Death', dummy_3)
  96. print(d)
  97. def test_data_03():
  98. d = Data()
  99. d.add_node_type('Gene', 1000)
  100. d.add_node_type('Drug', 100)
  101. fam = d.add_relation_family('Drug-Gene', 1, 0, True)
  102. with pytest.raises(ValueError):
  103. fam.add_relation_type('Target', None)
  104. print(d)