                                  V v)))
                       (fn[V fqrec]
                         (let [[id sq aux qc] (sqxform-fn fqrec)
-                              bc (get-sq-bc sq barcodes-map other-barcodes)]
+                              bc (get-sq-bc sq bclen
+                                            barcodes-map
+                                            other-barcodes)]
                           (if bc
                             (if (pass-qcscore qc qc-ctpt sqc%)
                               (let [len (count sq)

               ibcs))))


(defn get-sq-bc [sq barcodes-map other-barcodes]
  (let [bc (str/substring sq 0 7)]
    (or (barcodes-map bc) (other-barcodes bc))))

(defn pass-qcscore [qc qc-ctpt sqc%]
  (> (fil/percent-pass-qscore qc qc-ctpt) (double sqc%)))


(defn write-chunk-to-files [ot-fd-map recs]
  (let [file-groups (->> recs (group-by (fn[[bc fqrec]] (ot-fd-map bc)))
                         (mapv (fn[[fd rec]] [fd (mapv second rec)])))]
    (dorun
     (mapv (fn[fut] (deref fut))
           (mapv (fn[[fd recs]]


(defn split-barcodes
  [in-fq sqxform-fn ot-fq-map barcodes-map other-barcodes qc-ctpt sqc%]

  (letio [bclen (->> ot-fq-map keys first count long)
          inf (io/open-streaming-gzip in-fq :in)
          lines (io/read-lines inf)
