|
30 | 30 | (some? (re-matches #"(NM_|ENST)\d+(\.\d+)?" (:name rg))))
|
31 | 31 |
|
32 | 32 | (defn select-variant
|
33 |
| - [var seq-rdr rg] |
| 33 | + [var seq-rdr rg & {:keys [three-prime-rule]}] |
34 | 34 | (if-let [nvar (normalize-variant var seq-rdr rg)]
|
35 | 35 | (let [var-start-cds-coord (rg/cds-coord (:pos var) rg)
|
36 | 36 | var-end-cds-coord (rg/cds-coord (+ (:pos var) (max (count (:ref var)) (count (:alt var)))) rg)
|
37 | 37 | nvar-start-cds-coord (rg/cds-coord (:pos nvar) rg)
|
38 |
| - nvar-end-cds-coord (rg/cds-coord (+ (:pos nvar) (max (count (:ref nvar)) (count (:alt nvar)))) rg)] |
39 |
| - (if (= (:region var-start-cds-coord) (:region nvar-start-cds-coord) |
40 |
| - (:region var-end-cds-coord) (:region nvar-end-cds-coord)) |
| 38 | + nvar-end-cds-coord (rg/cds-coord (+ (:pos nvar) (max (count (:ref nvar)) (count (:alt nvar)))) rg) |
| 39 | + restrict-cds (get three-prime-rule :restrict-cds true)] |
| 40 | + (if (or (= (:region var-start-cds-coord) (:region nvar-start-cds-coord) |
| 41 | + (:region var-end-cds-coord) (:region nvar-end-cds-coord)) |
| 42 | + (not restrict-cds)) |
41 | 43 | nvar
|
42 | 44 | var))
|
43 | 45 | var))
|
|
119 | 121 | (filter coding-dna-ref-gene?)
|
120 | 122 | (map (fn [rg]
|
121 | 123 | (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt}
|
122 |
| - seq-rdr rg) |
| 124 | + seq-rdr rg |
| 125 | + :three-prime-rule (:three-prime-rule options)) |
123 | 126 | :rg rg)))
|
124 | 127 | (map (fn [{:keys [rg] :as m}]
|
125 | 128 | (when (:verbose? options)
|
|
135 | 138 | (let [options (merge default-options options)]
|
136 | 139 | (if (valid-ref? seq-rdr chr pos ref)
|
137 | 140 | (let [nv (select-variant {:chr chr, :pos pos, :ref ref, :alt alt}
|
138 |
| - seq-rdr rg)] |
| 141 | + seq-rdr rg |
| 142 | + :three-prime-rule (:three-prime-rule options))] |
139 | 143 | (when (:verbose? options)
|
140 | 144 | (print-debug-info nv seq-rdr rg))
|
141 | 145 | (coding-dna/->hgvs (assoc nv :rg rg) seq-rdr rg options))
|
|
189 | 193 | (filter coding-dna-ref-gene?)
|
190 | 194 | (map (fn [rg]
|
191 | 195 | (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt}
|
192 |
| - seq-rdr rg) |
| 196 | + seq-rdr rg |
| 197 | + :three-prime-rule (:three-prime-rule options)) |
193 | 198 | :rg rg)))
|
194 | 199 | (filter #(cds-affected? % (:rg %)))
|
195 | 200 | (keep (fn [{:keys [rg] :as m}]
|
|
206 | 211 | (let [options (merge default-options options)]
|
207 | 212 | (if (valid-ref? seq-rdr chr pos ref)
|
208 | 213 | (let [nv (select-variant {:chr chr, :pos pos, :ref ref, :alt alt}
|
209 |
| - seq-rdr rg)] |
| 214 | + seq-rdr rg |
| 215 | + :three-prime-rule (:three-prime-rule options))] |
210 | 216 | (when (cds-affected? nv rg)
|
211 | 217 | (when (:verbose? options)
|
212 | 218 | (print-debug-info nv seq-rdr rg))
|
|
264 | 270 | (->> (rg/ref-genes chr pos rgidx (:tx-margin options))
|
265 | 271 | (filter coding-dna-ref-gene?)
|
266 | 272 | (map (fn [rg]
|
267 |
| - (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
268 |
| - seq-rdr rg) |
269 |
| - :rg rg))) |
270 |
| - (map (fn [{:keys [rg] :as m}] |
| 273 | + {:coding-dna (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
| 274 | + seq-rdr rg |
| 275 | + :three-prime-rule (get-in options [:three-prime-rule :coding-dna])) |
| 276 | + :rg rg |
| 277 | + :type :coding-dna) |
| 278 | + :protein (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
| 279 | + seq-rdr rg |
| 280 | + :three-prime-rule (get-in options [:three-prime-rule :protein])) |
| 281 | + :rg rg |
| 282 | + :type :protein)})) |
| 283 | + (map (fn [{:keys [coding-dna protein]}] |
271 | 284 | (when (:verbose? options)
|
272 |
| - (print-debug-info m seq-rdr rg)) |
273 |
| - {:coding-dna (coding-dna/->hgvs m seq-rdr rg options) |
274 |
| - :protein (if (cds-affected? m rg) |
275 |
| - (prot/->hgvs m seq-rdr rg options))})) |
| 285 | + (print-debug-info coding-dna seq-rdr (:rg coding-dna)) |
| 286 | + (print-debug-info protein seq-rdr (:rg protein))) |
| 287 | + {:coding-dna (coding-dna/->hgvs coding-dna seq-rdr (:rg coding-dna) options) |
| 288 | + :protein (when (cds-affected? coding-dna (:rg coding-dna)) |
| 289 | + (prot/->hgvs protein seq-rdr (:rg protein) options))})) |
276 | 290 | distinct)
|
277 | 291 | (throw (ex-info "ref is not found on the position."
|
278 | 292 | {:type ::invalid-ref
|
|
282 | 296 | [{:keys [pos ref alt]} seq-rdr {:keys [chr] :as rg} & [options]]
|
283 | 297 | (let [options (merge default-options options)]
|
284 | 298 | (if (valid-ref? seq-rdr chr pos ref)
|
285 |
| - (let [nv (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
286 |
| - seq-rdr rg)] |
| 299 | + (let [nv (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
| 300 | + seq-rdr rg |
| 301 | + :three-prime-rule (get-in options [:three-prime-rule :coding-dna])) |
| 302 | + :type :coding-dna) |
| 303 | + pnv (assoc (select-variant {:chr chr, :pos pos, :ref ref, :alt alt} |
| 304 | + seq-rdr rg |
| 305 | + :three-prime-rule (get-in options [:three-prime-rule :protein])) |
| 306 | + :type :protein)] |
287 | 307 | (when (:verbose? options)
|
288 |
| - (print-debug-info nv seq-rdr rg)) |
289 |
| - |
| 308 | + (print-debug-info nv seq-rdr rg) |
| 309 | + (print-debug-info pnv seq-rdr rg)) |
| 310 | + (println (:three-prime-rule options)) |
290 | 311 | {:coding-dna (coding-dna/->hgvs nv seq-rdr rg options)
|
291 |
| - :protein (if (cds-affected? nv rg) |
292 |
| - (prot/->hgvs nv seq-rdr rg options))}) |
| 312 | + :protein (when (cds-affected? nv rg) |
| 313 | + (prot/->hgvs pnv seq-rdr rg options))}) |
293 | 314 | (throw (ex-info "ref is not found on the position."
|
294 | 315 | {:type ::invalid-ref
|
295 | 316 | :variant {:chr chr, :pos pos, :ref ref, :alt alt}})))))
|
0 commit comments