Repository: chrovis/cljam (clojure)

Issue:
QUAL value overflows when writing VCF
VCF QUAL values may contain huge numbers that are out of the Integer range.
Attempts to write such data to a file will fail.

### Example[^1]
```tsv
chr1	143214613	rs1483186290	T	A	5.60878e+09	VQSRTrancheSNP99.95to100.00;PlatformBiasObserved	...
```
[^1]: [tommo-38kjpn-20220630-GRCh38-af-autosome.vcf.gz](https://jmorp.megabank.tohoku.ac.jp/datasets/tommo-38kjpn-20220630-af_snvindelall/files/tommo-38kjpn-20220630-GRCh38-af-autosome.vcf.gz)

Pull request description:
Use `format` instead of `int` to solve the problem of stringifying huge QUAL values.

- According to hts-specs, the value of the QUAL field in the VCF is only considered to be a float, and there is no mention of an upper limit.
- The old implementation of cljam was limited to the Integer range.

Fixes #267

Patch:
diff --git a/src/cljam/io/vcf/writer.clj b/src/cljam/io/vcf/writer.clj
index 461470ce..480ec7d5 100644
--- a/src/cljam/io/vcf/writer.clj
+++ b/src/cljam/io/vcf/writer.clj
@@ -185,10 +185,13 @@
   (when v
     (cstr/join \, v)))
 
+(def ^:private ^:const precise-integer-limit 0x800000)
+
 (defn- stringify-data-line-qual
   [x]
   (when x
-    (if (zero? (mod x 1))
+    (if (and (zero? (mod x 1))
+             (< x precise-integer-limit))
       (str (int x))
       (str x))))
 


Test patch:
diff --git a/test/cljam/io/vcf/writer_test.clj b/test/cljam/io/vcf/writer_test.clj
index ed06fe2b..85bab7ae 100644
--- a/test/cljam/io/vcf/writer_test.clj
+++ b/test/cljam/io/vcf/writer_test.clj
@@ -18,6 +18,11 @@
 
 (deftest stringify-data-line-qual
   (is (= (#'vcf-writer/stringify-data-line-qual 10.0) "10"))
+  (is (= (#'vcf-writer/stringify-data-line-qual 6e+9) "6.0E9"))
+  (is (= (#'vcf-writer/stringify-data-line-qual 1.0E7) "1.0E7"))
+  (is (= (#'vcf-writer/stringify-data-line-qual 9.999999E6) "9999999.0"))
+  (is (= (#'vcf-writer/stringify-data-line-qual (Float/intBitsToFloat 0x4b000000)) "8388608.0"))
+  (is (= (#'vcf-writer/stringify-data-line-qual (Float/intBitsToFloat 0x4afffffe)) "8388607"))
   (is (= (#'vcf-writer/stringify-data-line-qual 9.6) "9.6"))
   (is (= (#'vcf-writer/stringify-data-line-qual nil) nil)))