                   (doseq [f# ["test.h2.db" "test.lock.db" "test.trace.db"]]
                     (io/delete-file f# true)))))))
 
-(def ^:dynamic *test-runs* 100)
+(def ^:dynamic *test-runs* 40)
 
 (defn check-matrix [db id tsv]
   (let [{:keys [probes samples matrix]} tsv


(defmacro with-file
  "Execute body, ensuring that file is always deleted before returning."
  [[bindvar file] & body]
  `(let [~bindvar ~file]
     (try
       ~@body
       (finally (when *delete-tmp-files*
                  (io/delete-file (io/file ~bindvar) true))))))

(defn write-genomic-matrix
  "Write a genomic matrix to a file."
  [file {:keys [matrix probes samples]}]
  (let [header (cons "sampleID" samples)
        rows (map (fn [probe row] (cons probe row)) probes matrix)]
    (spit (io/file file)
          (s/join "\n"
                  (map #(s/join "\t" (map str-nan %)) (cons header rows))))))

(defn trim-tsv
  "Rewrite tsv with probes and samples trimmed of leading and trailing

(defn genomic-matrix-loader-run
  "Run a generated genomic-matrix-loader test case. Useful for repeated failed
  cases. Run with *verbose* to print detailed test failures"
  [tsv id clinical]
  (with-file [file (str (io/file docroot "generated" id))
              meta-file (str file ".json")]
    (write-genomic-matrix file tsv clinical meta-file)
    (db-disk-fixture
      db
      (loader db detector docroot file)
