nx_align_chain_stranded_test.nx source
↩ module page · 136 lines · 5076 B
1// nx_align_chain_stranded_test.nx -- KAT for strand-partitioned chain.
2//
3// expect_exit: 0
4//
5// license_tier: ORIGINAL
6
7import "nx_syscalls.nx"
8import "nx_const.nx"
9import "nx_align_chain_stranded.nx"
10
11func main() -> i64 {
12
13 let q: *i64 = sys_mmap(256) as *i64
14 let r: *i64 = sys_mmap(256) as *i64
15 let ch: *i64 = sys_mmap(128) as *i64
16 let st: *i64 = sys_mmap(16) as *i64
17
18 // ============================================================
19 // Section A -- forward-only (n_rev = 0): picks fwd chain.
20 // Forward partition (4 seeds, co-linear): (q=0,r=0)(q=1,r=1)(q=2,r=2)(q=3,r=3)
21 // Reverse partition: empty.
22 // Expected: chain length 4, indices [0,1,2,3], strand = FWD.
23 // ============================================================
24
25 q[0]=0; r[0]=0
26 q[1]=1; r[1]=1
27 q[2]=2; r[2]=2
28 q[3]=3; r[3]=3
29 let l1: i64 = chain_pick_best_strand(q, r, 4, 4, ch, st, 16)
30 if l1 != 4 { return 1 }
31 if st[0] != NX_STRAND_FWD { return 2 }
32 if ch[0] != 0 { return 3 }
33 if ch[1] != 1 { return 4 }
34 if ch[2] != 2 { return 5 }
35 if ch[3] != 3 { return 6 }
36
37 // ============================================================
38 // Section B -- reverse-only (n_fwd = 0): picks rev chain.
39 // Reverse partition (3 seeds, co-linear): (q=5,r=0)(q=7,r=1)(q=9,r=2)
40 // Expected: chain length 3, indices [0,1,2] (offset by n_fwd=0 stays same),
41 // strand = REV.
42 // ============================================================
43
44 q[0]=5; r[0]=0
45 q[1]=7; r[1]=1
46 q[2]=9; r[2]=2
47 let l2: i64 = chain_pick_best_strand(q, r, 0, 3, ch, st, 16)
48 if l2 != 3 { return 10 }
49 if st[0] != NX_STRAND_REV { return 11 }
50 if ch[0] != 0 { return 12 }
51 if ch[1] != 1 { return 13 }
52 if ch[2] != 2 { return 14 }
53
54 // ============================================================
55 // Section C -- mixed, forward wins.
56 // Forward partition (4 co-linear): (q=0,r=0)(q=1,r=1)(q=2,r=2)(q=3,r=3)
57 // Reverse partition (2 co-linear): (q=5,r=10)(q=8,r=20)
58 // n_fwd=4, n_total=6.
59 // Expected: chain length 4 fwd, indices [0,1,2,3], strand = FWD.
60 // ============================================================
61
62 q[0]=0; r[0]=0
63 q[1]=1; r[1]=1
64 q[2]=2; r[2]=2
65 q[3]=3; r[3]=3
66 q[4]=5; r[4]=10
67 q[5]=8; r[5]=20
68 let l3: i64 = chain_pick_best_strand(q, r, 4, 6, ch, st, 16)
69 if l3 != 4 { return 20 }
70 if st[0] != NX_STRAND_FWD { return 21 }
71 if ch[0] != 0 { return 22 }
72 if ch[3] != 3 { return 23 }
73
74 // ============================================================
75 // Section D -- mixed, reverse wins.
76 // Forward partition (2 seeds): (q=0,r=0)(q=1,r=1) length 2
77 // Reverse partition (5 co-linear): (q=0,r=0)(q=1,r=1)(q=2,r=2)(q=3,r=3)(q=4,r=4) length 5
78 // n_fwd=2, n_total=7.
79 // Expected: chain length 5 rev, indices [2,3,4,5,6] (offset by n_fwd=2),
80 // strand = REV.
81 // ============================================================
82
83 q[0]=0; r[0]=0
84 q[1]=1; r[1]=1
85 q[2]=0; r[2]=0
86 q[3]=1; r[3]=1
87 q[4]=2; r[4]=2
88 q[5]=3; r[5]=3
89 q[6]=4; r[6]=4
90 let l4: i64 = chain_pick_best_strand(q, r, 2, 7, ch, st, 16)
91 if l4 != 5 { return 30 }
92 if st[0] != NX_STRAND_REV { return 31 }
93 if ch[0] != 2 { return 32 }
94 if ch[1] != 3 { return 33 }
95 if ch[2] != 4 { return 34 }
96 if ch[3] != 5 { return 35 }
97 if ch[4] != 6 { return 36 }
98
99 // ============================================================
100 // Section E -- tie at length 3: FORWARD wins (spec).
101 // Forward partition (3 co-linear): (q=0,r=0)(q=1,r=1)(q=2,r=2)
102 // Reverse partition (3 co-linear): (q=0,r=0)(q=1,r=1)(q=2,r=2)
103 // n_fwd=3, n_total=6.
104 // Expected: chain length 3, strand = FWD (tie-break), indices [0,1,2].
105 // ============================================================
106
107 q[0]=0; r[0]=0
108 q[1]=1; r[1]=1
109 q[2]=2; r[2]=2
110 q[3]=0; r[3]=0
111 q[4]=1; r[4]=1
112 q[5]=2; r[5]=2
113 let l5: i64 = chain_pick_best_strand(q, r, 3, 6, ch, st, 16)
114 if l5 != 3 { return 40 }
115 if st[0] != NX_STRAND_FWD { return 41 }
116 if ch[0] != 0 { return 42 }
117
118 // ============================================================
119 // Section F -- both partitions empty: length 0, strand = UNKNOWN.
120 // ============================================================
121
122 let l6: i64 = chain_pick_best_strand(q, r, 0, 0, ch, st, 16)
123 if l6 != 0 { return 50 }
124 if st[0] != NX_STRAND_UNKNOWN { return 51 }
125
126 // ============================================================
127 // Section G -- bad-input rejection.
128 // ============================================================
129
130 if chain_pick_best_strand(q, r, 5, 3, ch, st, 16) != -1 { return 60 } // n_fwd > n_total
131 if chain_pick_best_strand(q, r, -1, 3, ch, st, 16) != -1 { return 61 } // negative n_fwd
132 if chain_pick_best_strand(q, r, 0, -1, ch, st, 16) != -1 { return 62 } // negative n_total
133 if chain_pick_best_strand(q, r, 0, 3, ch, st, 0) != -1 { return 63 } // zero capacity
134
135 return 0
136}