                                             (bam/writer sorted-f))))
                        (after :facts (clean-cache!))]
     (fact "about BAM indexer (for incomplete alignments)"
-          ;; generate incomplete bam file on the fly
           (bai/create-index sorted-f (str sorted-f ".bai")) => anything
+          (.exists (file (str sorted-f ".bai"))) => truthy
           (with-open [r (bam/reader sorted-f)]
             (io/read-alignments r {:chr "ref" :start 0 :end 1000})
             ) => (filter #(= "ref" (:rname %))

                     (after :facts (clean-cache!))]
  (fact "about BAM indexer (large file)" :slow
        (bai/create-index
          temp-file-sorted (str temp-file-sorted ".bai")) => anything))


  (fact "about BAM indexer"
        (bai/create-index
          temp-file-sorted (str temp-file-sorted ".bai")) => anything
        (.exists (file (str temp-file-sorted ".bai"))) => truthy
        (with-open [r (bam/reader temp-file-sorted)]
          (io/read-alignments r {:chr "ref" :start 0 :end 1000})
          ) => (filter #(= "ref" (:rname %))
                       (:alignments test-sam-sorted-by-pos))))

(let [f (str temp-dir "/test.incomplete.bam")
      sorted-f (str temp-dir "/test.incomplete.sorted.bam")]
  (with-state-changes [(before :facts (do (prepare-cache!)
                                          ;; generate incomplete bam on the fly
                                          (spit-bam-for-test
                                            f test-sam-incomplete-alignments)
                                          ;; TODO: go independent from sorter
