                   (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

  *test-runs*
  (prop/for-all
    [tsv gen-tsv
     id (gen/such-that not-empty gen/string-alpha-numeric)]
    (genomic-matrix-loader-run tsv id)))

(defn matrix2 [db]
  (ct/testing "tsv matrix from file"


(defmacro with-file
  "Execute body, ensuring that file is always deleted before returning."
  [bindings & body]
  (if (= (count bindings) 0)
    `(do ~@body)
    `(let ~(subvec bindings 0 2)
       (try
         (with-file ~(subvec bindings 2) ~@body)
         (finally (when *delete-tmp-files*
                    (io/delete-file (io/file ~(bindings 0)) true)))))))

(defn write-clinical-meta [file]
  (spit (io/file file)
        "{\"type\": \"clinicalMatrix\"}"))

(defn transpose [m]
  (apply map vector m))

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

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