forked from greenelab/Context-Aware-Path-Probability
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data_loading_simple.py
More file actions
73 lines (57 loc) · 2.66 KB
/
test_data_loading_simple.py
File metadata and controls
73 lines (57 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Simple test to verify data_loading module works
"""
import sys
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from dwpc_pvalue_validation import data_loading
def main():
print("Testing data_loading module...")
print("=" * 60)
# Get loader
loader = data_loading.get_loader()
print("✓ Created loader")
# Test loading true Hetionet
print("\n1. Loading true Hetionet HetMat...")
hetmat_true = loader.load_hetmat("true")
print(f" ✓ Loaded: {hetmat_true}")
print(f" Metagraph: {hetmat_true.metagraph}")
# Test loading a specific edge matrix
print("\n2. Loading Compound-binds-Gene edge matrix...")
matrix = loader.load_edge_matrix("CbG", source="true")
print(f" ✓ Shape: {matrix.shape}")
print(f" ✓ Edges: {matrix.nnz}")
# Test getting degrees
print("\n3. Getting node degrees...")
source_degrees = loader.get_node_degrees("CbG", source="true", node_position="source")
target_degrees = loader.get_node_degrees("CbG", source="true", node_position="target")
print(f" ✓ Source (Compound) degrees: min={source_degrees.min()}, max={source_degrees.max()}, mean={source_degrees.mean():.2f}")
print(f" ✓ Target (Gene) degrees: min={target_degrees.min()}, max={target_degrees.max()}, mean={target_degrees.mean():.2f}")
# Test loading permutation 0
print("\n4. Loading permutation 0...")
hetmat_perm0 = loader.load_hetmat(perm_idx=0)
print(f" ✓ Loaded: {hetmat_perm0}")
# Test loading permutation 1
print("\n5. Loading permutation 1...")
matrix_perm1 = loader.load_edge_matrix("CbG", perm_idx=1)
print(f" ✓ Shape: {matrix_perm1.shape}")
print(f" ✓ Edges: {matrix_perm1.nnz}")
# Verify degree preservation
print("\n6. Verifying degree preservation...")
perm_source_degrees = loader.get_node_degrees("CbG", source="perm1", node_position="source")
perm_target_degrees = loader.get_node_degrees("CbG", source="perm1", node_position="target")
assert (source_degrees == perm_source_degrees).all(), "Source degrees should be preserved"
assert (target_degrees == perm_target_degrees).all(), "Target degrees should be preserved"
print(f" ✓ Degrees are preserved in permutation")
# Test metapath parsing
print("\n7. Testing metapath parsing...")
metaedges = data_loading.get_metaedges_for_metapath("CbGpPW")
print(f" CbGpPW -> {metaedges}")
metaedges2 = data_loading.get_metaedges_for_metapath("CbGpPWpG")
print(f" CbGpPWpG -> {metaedges2}")
print("\n" + "=" * 60)
print("✓ All tests passed!")
print("=" * 60)
if __name__ == "__main__":
main()