Repository: chrovis/cljam
Pull request #170 (2019-07-01 08:17:37)

Provide a default file format version for BCF
~~**This PR depends on #169**
The actual diff is [94ce1f8...581438a](https://github.com/chrovis/cljam/pull/170/files/94ce1f8de25130bc2a28aa5a03e3fec3e34672f9..581438a1502bf4ab1af0d4b1ea74970b3d876320)~~

Like VCFWriter, this PR provides a default file format version `"VCFv4.3"` for meta-info of BCF.
Though BCF has its version in the magic number `BCF\2\2`, the header string should start with `##fileformat=`.

codecov[bot]: # [Codecov](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=h1) Report
> Merging [#170](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=desc) into [master](https://codecov.io/gh/chrovis/cljam/commit/a3048eaa4859669ba3c55ad0128c0357a9375cd8?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/chrovis/cljam/pull/170/graphs/tree.svg?width=650&token=hrCuiz6NWa&height=150&src=pr)](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #170      +/-   ##
==========================================
+ Coverage   86.87%   86.88%   +<.01%     
==========================================
  Files          73       73              
  Lines        5663     5667       +4     
  Branches      481      481              
==========================================
+ Hits         4920     4924       +4     
  Misses        262      262              
  Partials      481      481
```


| [Impacted Files](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/cljam/io/bcf/writer.clj](https://codecov.io/gh/chrovis/cljam/pull/170/diff?src=pr&el=tree#diff-c3JjL2NsamFtL2lvL2JjZi93cml0ZXIuY2xq) | `90.04% <100%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=footer). Last update [a3048ea...581438a](https://codecov.io/gh/chrovis/cljam/pull/170?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/.travis.yml b/.travis.yml
index ca01d0c..21663db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,10 +4,9 @@ cache:
   directories:
     - $HOME/.m2
 jdk:
+  - openjdk-ea
   - openjdk12
   - openjdk11
-  - openjdk10
-  - openjdk9
   - openjdk8
 env:
 before_install:
diff --git a/src/cljam/io/bcf/writer.clj b/src/cljam/io/bcf/writer.clj
index 7fd993f..e73b28b 100644
--- a/src/cljam/io/bcf/writer.clj
+++ b/src/cljam/io/bcf/writer.clj
@@ -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])
@@ -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


Test patch:
diff --git a/test/cljam/io/bcf/writer_test.clj b/test/cljam/io/bcf/writer_test.clj
index 07a229c..c13ea81 100644
--- a/test/cljam/io/bcf/writer_test.clj
+++ b/test/cljam/io/bcf/writer_test.clj
@@ -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 [_ (bcf-writer/writer tmp {} header)])
+        bytes (bb->seq (bgzf->bb tmp))]
+    (is (= (concat (.getBytes "BCF\2\2") [(.length s) 0 0 0] (.getBytes s))
+           bytes))
+    (.delete tmp)))