                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 get-sq-bc [sq bclen barcodes-map other-barcodes]
+  (when sq
+    (let [bc (str/substring sq 0 bclen)]
+      (or (barcodes-map bc) (other-barcodes bc)))))
 
 (defn pass-qcscore [qc qc-ctpt sqc%]
   (> (fil/percent-pass-qscore qc qc-ctpt) (double sqc%)))
 
 
+(def SDBG (atom #{}))
+;;;#{"GGATGG" "CTTAAC" "TAATTA" "ATGGAT" "AATTGC" "TGCTTA"}
 (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)])))]
+  (let [file-groups (->> recs (group-by
+                               (fn[[bc fqrec]]
+                                 (let [fd (ot-fd-map bc)]
+                                   (if fd fd
+                                       (when (not (@SDBG bc))
+                                         (swap! SDBG #(conj % bc))
+                                         (prn :BAD-BC?! bc))))))
+                         (mapv (fn[[fd rec]] [fd (mapv second rec)])))
+
+        file-groups (filter (fn[[fd recs]] fd) file-groups)]
     (dorun
      (mapv (fn[fut] (deref fut))
            (mapv (fn[[fd recs]]

                            (fs/directory-files (m :stats) ".clj"))))))
      ((fn[m]
         (assoc m :ed1codes
                (let [bcmaps (m :bcmaps)]
                  (into {} (map #(vector % (barcodes-edist-1-seqs
                                            (bcM bcmaps %)
                                            (m :barcodes)))
                                (keys bcmaps)))))))
      ((fn[m]
         (assoc m :red1codes

(comment
  (def eid "160930_161002_AHK72HBGXY_AHK7YKBGXY")
  (def neid "161108_161109_AH2WWGBGX2_AH2WLJBGX2")
  (def teid "160804_NS500751_0017_AHF2KLBGXY")

  (set-exp "160307_NS500751_0013_AHL7L3BGXX")
  (set-exp "160930_161002_AHK72HBGXY_AHK7YKBGXY")
  (set-exp "161108_161109_AH2WWGBGX2_AH2WLJBGX2")
  (set-exp teid)

  (get-exp "160307_NS500751_0013_AHL7L3BGXX")
  ((get-exp "160307_NS500751_0013_AHL7L3BGXX") :base)
