Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a default file format version for BCF #170

Merged
merged 4 commits into from Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/cljam/io/bcf/writer.clj
Expand Up @@ -22,6 +22,7 @@
(write-variants [this variants]
(write-variants this variants)))

(def ^:private ^:const default-fileformat "VCFv4.3")
(def ^:private ^:const bcf-meta-keys
[:fileformat :file-date :source :reference :contig :phasing :info :filter
:format :alt :sample :pedigree])
Expand Down Expand Up @@ -86,8 +87,11 @@
(WRITING-BCF))"
[f meta-info header]
(let [bos (bgzf/bgzf-output-stream f)
dos (DataOutputStream. bos)]
(doto (BCFWriter. (util/as-url f) (index-meta meta-info) header dos)
dos (DataOutputStream. bos)
indexed-meta (->> meta-info
(merge {:fileformat default-fileformat})
index-meta)]
(doto (BCFWriter. (util/as-url f) indexed-meta header dos)
(write-file-header))))

(defn- value-type
Expand Down
13 changes: 13 additions & 0 deletions test/cljam/io/bcf/writer_test.clj
Expand Up @@ -267,3 +267,16 @@
0x17 0x43
0x00]
[]]])))

(deftest default-meta-info
(let [tmp (File/createTempFile "default-meta-info" ".bcf")
header ["CHROM" "POS" "ID" "REF" "ALT" "QUAL" "FILTER" "INFO"]
s (->> ["##fileformat=VCFv4.3"
"##FILTER=<ID=PASS,Description=\"All filters passed\",IDX=0>"
(str "#" (cstr/join \tab header) \newline (char 0))]
(cstr/join \newline))
_ (with-open [w (bcf-writer/writer tmp {} header)])
alumi marked this conversation as resolved.
Show resolved Hide resolved
bytes (bb->seq (bgzf->bb tmp))]
(is (= (concat (.getBytes "BCF\2\2") [(.length s) 0 0 0] (.getBytes s))
bytes))
(.delete tmp)))