Skip to content

Commit 7e227e8

Browse files
committed
refactor: refactor and generalize overlap-exon-intron-boundary? using diff-bases
1 parent 0587070 commit 7e227e8

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/varity/vcf_to_hgvs/protein.clj

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
[varity.ref-gene :as rg]
1515
[varity.vcf-to-hgvs.common :refer [diff-bases] :as common]))
1616

17-
(defn- overlap-exon-intron-boundary?
17+
(defn- overlap-exon-intron-boundary?*
1818
[exon-ranges pos ref alt]
1919
(let [nref (count ref)
20-
nalt (count alt)]
21-
(and (not (= 1 nref nalt))
22-
(not= 1 (count exon-ranges))
23-
(let [[pos nref] (if (= (first ref) (first alt))
24-
[(inc pos) (dec nref)]
25-
[pos nref])]
26-
(some (fn [[s e]]
27-
(and (not= s e)
28-
(or (and (< pos s) (<= s (+ pos nref -1)))
29-
(and (<= pos e) (< e (+ pos nref -1))))))
30-
exon-ranges)))))
20+
nalt (count alt)
21+
[_ _ d _] (diff-bases ref alt)
22+
pos (+ pos d)
23+
nref (- nref d)]
24+
(boolean
25+
(and (not (= 1 nref nalt))
26+
(not= 1 (count exon-ranges))
27+
(some (fn [[s e]]
28+
(and (not= s e)
29+
(or (and (< pos s) (<= s (+ pos nref -1)))
30+
(and (<= pos e) (< e (+ pos nref -1))))))
31+
exon-ranges)))))
32+
33+
(def ^:private overlap-exon-intron-boundary? (memoize overlap-exon-intron-boundary?*))
3134

3235
(defn alt-exon-ranges
3336
"Returns exon ranges a variant applied."

test/varity/vcf_to_hgvs/protein_test.clj

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
[varity.t-common :refer [test-ref-seq-file
88
defslowtest]]))
99

10+
(deftest overlap-exon-intron-boundary?-test
11+
(let [exon-ranges [[123 321] [456 654] [789 987]]]
12+
(are [p pos ref alt] (p (#'prot/overlap-exon-intron-boundary? exon-ranges pos ref alt))
13+
false? 454 "X" "Y"
14+
true? 454 "XXX" "X"
15+
false? 455 "XX" "X"
16+
false? 456 "XX" "X"
17+
false? 654 "XX" "X"
18+
true? 653 "XXX" "X"
19+
false? 653 "XX" "X")))
20+
1021
(deftest alt-exon-ranges-test
1122
;; 1 [2 3 4] 5 6 7 [8 9 10 11] 12 13 14 15
1223
(are [p r a e] (= (#'prot/alt-exon-ranges [[2 4] [8 11]] p r a) e)
@@ -15,10 +26,10 @@
1526
2 "XX" "X" [[2 3] [7 10]]
1627
3 "XX" "X" [[2 3] [7 10]]
1728
6 "XX" "X" [[2 4] [7 10]]
18-
9 "XXX" "XXX" [[2 4] [8 11]])
29+
9 "XXX" "YYY" [[2 4] [8 11]])
1930
;; Variants overlapping a boundary of exon/intron
2031
(are [p r a] (nil? (#'prot/alt-exon-ranges [[2 4] [8 11]] p r a))
21-
3 "XXX" "XXX"
32+
3 "XXX" "YYY"
2233
6 "XXX" "X"
2334
3 "XXX" "X"
2435
1 "XXXXX" "X"))

0 commit comments

Comments
 (0)