-
Notifications
You must be signed in to change notification settings - Fork 12
/
core.clj
34 lines (29 loc) · 1023 Bytes
/
core.clj
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
(ns cljam.io.dict.core
"The core of dictionary features."
(:require [clojure.java.io :as cio]
[clojure.tools.logging :as logging]
[cljam.io.dict.writer :as writer]
[cljam.util :as util])
(:import cljam.io.dict.writer.DICTWriter))
;; Reading
;; -------
;; TODO
;; Writing
;; -------
(defn ^DICTWriter writer
"Opens f, returning a `cljam.dict.writer.DICTWriter`. Should be used inside
`with-open` to ensure the writer is properly closed."
[f]
(DICTWriter. (cio/writer f)
(util/as-url f)))
(defn create-dict
"Creates a FASTA sequence dictionary file (.dict) from the specified FASTA
file. The unfinished file will be deleted when failing."
[f headers sequences ur]
(with-open [w (writer f)]
(try
(writer/write-dict! w headers sequences ur)
(catch Exception e (do
(cio/delete-file (.url w))
(logging/error "Failed to create dictionary")
(throw e))))))