Skip to content

Commit

Permalink
refactor: refactor and generalize overlap-exon-intron-boundary? using…
Browse files Browse the repository at this point in the history
… diff-bases
  • Loading branch information
federkasten committed Feb 1, 2024
1 parent 0587070 commit 7e227e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/varity/vcf_to_hgvs/protein.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
[varity.ref-gene :as rg]
[varity.vcf-to-hgvs.common :refer [diff-bases] :as common]))

(defn- overlap-exon-intron-boundary?
(defn- overlap-exon-intron-boundary?*
[exon-ranges pos ref alt]
(let [nref (count ref)
nalt (count alt)]
(and (not (= 1 nref nalt))
(not= 1 (count exon-ranges))
(let [[pos nref] (if (= (first ref) (first alt))
[(inc pos) (dec nref)]
[pos nref])]
(some (fn [[s e]]
(and (not= s e)
(or (and (< pos s) (<= s (+ pos nref -1)))
(and (<= pos e) (< e (+ pos nref -1))))))
exon-ranges)))))
nalt (count alt)
[_ _ d _] (diff-bases ref alt)
pos (+ pos d)
nref (- nref d)]
(boolean
(and (not (= 1 nref nalt))
(not= 1 (count exon-ranges))
(some (fn [[s e]]
(and (not= s e)
(or (and (< pos s) (<= s (+ pos nref -1)))
(and (<= pos e) (< e (+ pos nref -1))))))
exon-ranges)))))

(def ^:private overlap-exon-intron-boundary? (memoize overlap-exon-intron-boundary?*))

(defn alt-exon-ranges
"Returns exon ranges a variant applied."
Expand Down
15 changes: 13 additions & 2 deletions test/varity/vcf_to_hgvs/protein_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
[varity.t-common :refer [test-ref-seq-file
defslowtest]]))

(deftest overlap-exon-intron-boundary?-test
(let [exon-ranges [[123 321] [456 654] [789 987]]]
(are [p pos ref alt] (p (#'prot/overlap-exon-intron-boundary? exon-ranges pos ref alt))
false? 454 "X" "Y"
true? 454 "XXX" "X"
false? 455 "XX" "X"
false? 456 "XX" "X"
false? 654 "XX" "X"
true? 653 "XXX" "X"
false? 653 "XX" "X")))

(deftest alt-exon-ranges-test
;; 1 [2 3 4] 5 6 7 [8 9 10 11] 12 13 14 15
(are [p r a e] (= (#'prot/alt-exon-ranges [[2 4] [8 11]] p r a) e)
Expand All @@ -15,10 +26,10 @@
2 "XX" "X" [[2 3] [7 10]]
3 "XX" "X" [[2 3] [7 10]]
6 "XX" "X" [[2 4] [7 10]]
9 "XXX" "XXX" [[2 4] [8 11]])
9 "XXX" "YYY" [[2 4] [8 11]])
;; Variants overlapping a boundary of exon/intron
(are [p r a] (nil? (#'prot/alt-exon-ranges [[2 4] [8 11]] p r a))
3 "XXX" "XXX"
3 "XXX" "YYY"
6 "XXX" "X"
3 "XXX" "X"
1 "XXXXX" "X"))
Expand Down

0 comments on commit 7e227e8

Please sign in to comment.