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

Fix warnings and errors reported by clj-kondo #192

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{:linters
{:type-mismatch
{:namespaces
{clojure.core
{long {:arities {1 {:args [#{:byte :number :char}],
:ret :int}}}},
cljam.algo.pileup
{unzip-2 {:arities {1 {:args [:fn],
:ret :transducer}}}}}},
:unresolved-symbol
{:exclude [(cljam.io.pileup-test/with-string-writer [w])
;; cljam.algo.depth
(com.climate.claypoole/pdoseq [s e])
;; cljam.algo.level
(com.climate.claypoole/pfor [i])]}},
:lint-as {cljam.test-common/deftest-slow clojure.test/deftest,
cljam.test-common/deftest-remote clojure.test/deftest,
cljam.util/with-temp-dir clojure.core/with-open,
cavia.core/defprofile clojure.core/def,
libra.bench/defbench clojure.test/deftest,
libra.bench/is clojure.test/is,
libra.bench/are clojure.test/are,
com.climate.claypoole/with-shutdown! clojure.core/with-open}}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pom.xml.asc
.nrepl-port
/.cavia
/docs
.clj-kondo/.cache
2 changes: 1 addition & 1 deletion bench/cljam/algo/bam_indexer_bench.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljam.algo.bam-indexer-bench
(:require [libra.bench :refer :all]
(:require [libra.bench :refer [defbench are dur]]
[libra.criterium :as c]
[cljam.test-common :as tcommon]
[cljam.algo.bam-indexer :as bai]))
Expand Down
2 changes: 1 addition & 1 deletion bench/cljam/algo/convert_bench.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljam.algo.convert-bench
(:require [libra.bench :refer :all]
(:require [libra.bench :refer [defbench are]]
[libra.criterium :as c]
[cljam.test-common :as tcommon]
[cljam.algo.convert :as convert]))
Expand Down
2 changes: 1 addition & 1 deletion bench/cljam/algo/depth_bench.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljam.algo.depth-bench
(:require [libra.bench :refer :all]
(:require [libra.bench :refer [defbench are dur]]
[libra.criterium :as c]
[cljam.test-common :as tcommon]
[cljam.algo.depth :as depth]
Expand Down
3 changes: 1 addition & 2 deletions bench/cljam/algo/pileup_bench.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljam.algo.pileup-bench
(:require [libra.bench :refer :all]
(:require [libra.bench :refer [defbench is]]
[libra.criterium :as c]
[criterium.core :as criterium]
[cljam.test-common :as tcommon]
Expand All @@ -15,4 +15,3 @@
(is
(c/quick-bench
(dorun (pileup/pileup r region)))))))))

2 changes: 1 addition & 1 deletion bench/cljam/io/sequence_bench.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns cljam.io.sequence-bench
(:require [libra.bench :refer :all]
(:require [libra.bench :refer [defbench are]]
[libra.criterium :as c]
[cljam.test-common :as tcommon]
[cljam.io.sequence :as cseq]))
Expand Down
5 changes: 2 additions & 3 deletions src/cljam/algo/sorter.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
(ns cljam.algo.sorter
"Sorter of the SAM/BAM format alignments."
(:refer-clojure :exclude [sorted?])
(:require [clojure.java.io :as cio]
[clojure.tools.logging :as logging]
(:require [clojure.tools.logging :as logging]
[com.climate.claypoole :as cp]
[cljam.io.protocols :as protocols]
[cljam.io.sam :as sam]
[cljam.io.util :as io-util]
[cljam.util :as util]
[cljam.io.sam.util.header :as header])
(:import [java.io Closeable File]
(:import [java.io Closeable]
[java.util PriorityQueue]))

(def ^:const default-chunk-size 1500000)
Expand Down
3 changes: 1 addition & 2 deletions src/cljam/io/bam/reader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
[cljam.io.bam-index.core :as bai]
[cljam.io.bam.decoder :as decoder]
[cljam.io.util.lsb :as lsb])
(:import [java.io Closeable EOFException IOException FileNotFoundException]
(:import [java.io Closeable FileNotFoundException]
[cljam.io.bam.decoder BAMRawBlock]
[java.nio ByteBuffer]
[bgzf4j BGZFInputStream]))

(declare read-blocks-sequentially*
Expand Down
8 changes: 4 additions & 4 deletions src/cljam/io/bam_index/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
(with-open [w (writer f refs)]
(try
(writer/write-index! w alns)
(catch Exception e (do
(cio/delete-file (.url w))
(logging/error "Failed to create BAM index")
(throw e))))))
(catch Exception e
(cio/delete-file (.url w))
(logging/error "Failed to create BAM index")
(throw e)))))
6 changes: 4 additions & 2 deletions src/cljam/io/bam_index/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
[cljam.io.util.bgzf :as bgzf]
[cljam.io.util.lsb :as lsb]
[cljam.io.util.bin :as util-bin]
[cljam.io.bam-index.common :refer :all]
[cljam.io.bam-index.common :refer [linear-index-shift
linear-index-depth
max-bins
bai-magic]]
[cljam.io.util.chunk :as chunk]
[cljam.io.bam.decoder :as bam-decoder])
(:import [java.io DataOutputStream Closeable]
[java.nio ByteBuffer ByteOrder]
[cljam.io.bam.decoder BAMPointerBlock]
[cljam.io.util.chunk Chunk]))

Expand Down
3 changes: 1 addition & 2 deletions src/cljam/io/bcf/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[cljam.io.vcf.writer :as vw]
[cljam.io.vcf.util :as vcf-util]
[cljam.util :as util])
(:import [java.io Closeable IOException DataOutputStream]
(:import [java.io Closeable DataOutputStream]
[java.net URL]
[java.nio ByteBuffer ByteOrder]))

Expand All @@ -27,7 +27,6 @@
[:fileformat :file-date :source :reference :contig :phasing :info :filter
:format :alt :sample :pedigree])
(def ^:private ^:const meta-info-prefix "##")
(def ^:private ^:const header-prefix "#")
(def ^:private ^:const type-kws
{"String" :str, "Character" :char,
"Integer" :int, "Float" :float, "Flag" :flag})
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/io/bed.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
http://genome.ucsc.edu/FAQ/FAQformat#format1 for the detail BED specifications."
(:require [clojure.java.io :as cio]
[clojure.string :as cstr]
[proton.core :refer [as-int as-long]]
[proton.core :refer [as-long]]
[cljam.io.protocols :as protocols]
[cljam.util :as util]
[cljam.util.chromosome :as chr]
Expand Down
5 changes: 3 additions & 2 deletions src/cljam/io/bigwig.clj
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@
end-base (lsb/read-uint r)
offset (lsb/read-long r)
size (lsb/read-long r)]
(if (cir-tree-overlaps? id start end start-chrom-ix
start-base end-chrom-ix end-base)
(when (cir-tree-overlaps?
id start end start-chrom-ix
start-base end-chrom-ix end-base)
{:offset offset, :size size}))))
(remove nil?)))

Expand Down
8 changes: 4 additions & 4 deletions src/cljam/io/dict/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(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))))))
(catch Exception e
(cio/delete-file (.url w))
(logging/error "Failed to create dictionary")
(throw e)))))
2 changes: 1 addition & 1 deletion src/cljam/io/dict/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
(defn make-dict
"Calculates sequence dictionary from the headers and sequences, returning it
as a map."
[headers sequences ur]
[_headers sequences ur]
(loop [[seq* & rest] sequences
name (:name seq*)
dict-status (init-dict-status)
Expand Down
8 changes: 4 additions & 4 deletions src/cljam/io/fasta_index/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
w ^FAIWriter (writer out-fai)]
(try
(writer/write-index! r w)
(catch Exception e (do
(cio/delete-file (.url w))
(logging/error "Failed to create FASTA index")
(throw e))))))
(catch Exception e
(cio/delete-file (.url w))
(logging/error "Failed to create FASTA index")
(throw e)))))

;;;; Reading

Expand Down
24 changes: 12 additions & 12 deletions src/cljam/io/pileup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@
(.append w (if reverse? \, \.))
(.append w (unchecked-char (case-base-fn base))))
(when deletion
(do (.append w \-)
(.append w (String/valueOf ^int deletion))
(.append w ^String (case-fn
(if ref-reader
(->> {:chr rname
:start (inc ref-pos)
:end (+ ref-pos deletion)}
(cseq/read-sequence ref-reader))
(apply str (repeat deletion \N)))))))
(.append w \-)
(.append w (String/valueOf ^int deletion))
(.append w ^String (case-fn
(if ref-reader
(->> {:chr rname
:start (inc ref-pos)
:end (+ ref-pos deletion)}
(cseq/read-sequence ref-reader))
(apply str (repeat deletion \N))))))
(when insertion
(do (.append w \+)
(.append w (String/valueOf (count insertion)))
(.append w ^String (case-fn insertion))))
(.append w \+)
(.append w (String/valueOf (count insertion)))
(.append w ^String (case-fn insertion)))
(when end?
(.append w \$))))

Expand Down
4 changes: 1 addition & 3 deletions src/cljam/io/sam/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
[cljam.io.sam.util.cigar :as cigar]
[cljam.io.util.bin :as util-bin]
[cljam.io.sam.util.option :as opt])
(:import [java.nio CharBuffer ByteBuffer]
[java.nio.charset StandardCharsets]
[cljam.io.protocols SAMAlignment]))
(:import [cljam.io.protocols SAMAlignment]))

(def ^:const linear-index-shift 14)
(def ^:const linear-index-depth 5)
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/io/sam/util/refs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
(defn ref-by-name
"Returns the first reference which has the specified name."
[refs name]
(some #(if (= (:name %) name) %) refs))
(some #(when (= (:name %) name) %) refs))
2 changes: 1 addition & 1 deletion src/cljam/io/sam/util/sequence.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
result-len (quot (inc length) 2)
in-bb (ByteBuffer/wrap b)
out-bb (ByteBuffer/allocate result-len)]
(dotimes [i result-len]
(dotimes [_ result-len]
(let [u (.get in-bb)
l (byte (if (.hasRemaining in-bb) (.get in-bb) \=))]
(->> (bit-and 0x7F l)
Expand Down
10 changes: 1 addition & 9 deletions src/cljam/io/twobit/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@
(recur (conj! r [p l]) nil nil (inc i))
(recur r nil nil (inc i))))))))

(defn- index-size
"Number of bytes required for index."
[seqs]
(-> (fn [{:keys [name]}]
(+ 1 (count name) 4))
map
(transduce + 0 seqs)))

(defn- write-index!
[w idx]
(loop [offset (+ (* 4 4) (reduce + (map #(+ 1 (count (:name %)) 4) idx)))
Expand Down Expand Up @@ -173,7 +165,7 @@
seq-data (or (:seq sequence) (:sequence sequence))
masks (mask-regions seq-data)
ambs (amb-regions seq-data)
i (first (keep-indexed #(if (= (:name %2) name) %1) @idx-atom))]
i (first (keep-indexed #(when (= (:name %2) name) %1) @idx-atom))]
(swap! idx-atom update i assoc :masks masks :ambs ambs))
(write-sequence! (.writer wtr) sequence @idx-atom))
;; finalize
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/io/util/lsb.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns cljam.io.util.lsb
"Reading/writing functions of stream and buffer for little-endian data."
(:refer-clojure :exclude [read-string])
(:require [cljam.util :refer [string->bytes bytes->string]])
(:require [cljam.util :refer [string->bytes]])
(:import [java.io DataInput InputStream DataOutputStream EOFException ByteArrayOutputStream]
[java.nio Buffer ByteBuffer ByteOrder]))

Expand Down
5 changes: 2 additions & 3 deletions src/cljam/io/vcf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
cljam.io.vcf.reader.VCFReader
cljam.io.vcf.writer.VCFWriter
cljam.io.bcf.reader.BCFReader
cljam.io.bcf.writer.BCFWriter
bgzf4j.BGZFInputStream))
cljam.io.bcf.writer.BCFWriter))

;; Reading
;; -------
Expand All @@ -37,7 +36,7 @@
(bgzf/bgzf-input-stream f)
(cio/reader (util/compressor-input-stream f)))
(delay (try (csi/read-index (str f ".csi"))
(catch FileNotFoundException e
(catch FileNotFoundException _
(tabix/read-index (str f ".tbi"))))))))

(defn ^BCFReader bcf-reader
Expand Down
6 changes: 3 additions & 3 deletions src/cljam/io/vcf/writer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

(defn- write-meta-info1
[^VCFWriter wtr k v]
(if-not (nil? v)
(when-not (nil? v)
(if (sequential? v)
(doseq [x v]
(write-line (.writer wtr) (str meta-info-prefix
Expand Down Expand Up @@ -182,12 +182,12 @@

(defn- stringify-data-line-alt
[v]
(if v
(when v
(cstr/join \, v)))

(defn- stringify-data-line-qual
[x]
(if x
(when x
(if (zero? (mod x 1))
(str (int x))
(str x))))
Expand Down
4 changes: 1 addition & 3 deletions src/cljam/io/wig.clj
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@
#(- (:end %) (:start %))))
(map
(fn [[{{:keys [line format span step]} :track
chr :chr
start :start
end :end} :as xs]]
chr :chr start :start} :as xs]]
(case format
:variable-step
(let [declaration-line (->> (cond-> ["variableStep"
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/tools/cli.clj
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@

;; ### version command

(defn version [args]
(defn version [_]
(let [ver (with-open [r (-> "META-INF/maven/cljam/cljam/pom.properties"
(clojure.java.io/resource)
(clojure.java.io/reader))]
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/util.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cljam.util
"General utilities."
(:require [clojure.java.io :refer [file] :as cio])
(:require [clojure.java.io :as cio])
(:import [java.net MalformedURLException URL]
[java.nio.file Files FileVisitor FileVisitResult]
[java.nio.file.attribute FileAttribute]
Expand Down
2 changes: 1 addition & 1 deletion src/cljam/util/chromosome.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
normalize-name
prepend-chromosome-prefix
normalize-chromosome-prefix)
(if version-suffix (cstr/lower-case version-suffix)))))
(when version-suffix (cstr/lower-case version-suffix)))))

(defn is-primary-chromosome?
[s]
Expand Down
Loading