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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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