     (->> #(<= min-base-quality (.qual ^PileupBase %))
          (partial filterv)
          (update p 1))))
+
+(defn- unzip-2
+  [transform-fn]
+  (fn [rf]
+    (let [va (volatile! (transient []))
+          vb (volatile! (transient []))]
+      (fn
+        ([] (rf))
+        ([acc]
+         (-> acc
+             (rf (persistent! @va))
+             (rf (persistent! @vb))))
+        ([acc x]
+         (let [[a b] (transform-fn x)]
+           (vswap! va conj! a)
+           (vswap! vb conj! b)
+           acc))))))
 
 (defn- merge-corrected-quals
   "Merge corrected quals with the uncorrected part."

    (when (and (pos? (.pnext a1))
               (<= correct-start (.end a1)))
      (let [[quals1 quals2] (into []
                                  (two-vec-transducer
                                   (correct-pair-qual a1 a2))
                                  (range correct-start (inc correct-end)))
            new-quals1 (merge-corrected-quals a1
                                              correct-start

  [^long start ^long end alns]
  (seq-step start end 0 alns))

(defn- quals-at-ref
  [idx ^String qual]
  (let [empty-qual? (and (= (.length qual) 1)
                         (= (.charAt qual 0) \*))]
    (if empty-qual?
      (vec (repeat (count idx) 93)) ;; \~
      (mapv (fn [[_ x]]
              (if (number? x)
                (qual/fastq-char->phred-byte (.charAt qual x))
                93))
            idx))))

(defn- seqs-at-ref
  [idx ^String s]
  (mapv (fn [[op x xs]]
          (let [c (if (number? x) (.charAt s x) x)]
            (case op
              :m [c]
              :d [c xs]
              :i [c (subs s (first xs) (last xs))]))) idx))

(defn index-cigar
  "Align bases and base quality scores with the reference coordinate."
  [^SAMAlignment aln]
  (let [idx (cigar/to-index (.cigar aln))]
    (assoc aln
           :seqs-at-ref (seqs-at-ref idx (:seq aln))
           :quals-at-ref (quals-at-ref idx (.qual aln)))))

(defn basic-mpileup-pred
  "Basic predicate function for filtering alignments for mpileup."
