             [cljam.cigar :as cgr]
             [cljam.sequence :as cseq]
             [cljam.io :as io]
+            [cljam.fasta :as fa]
             [cljam.util :refer [ubyte]]
             [cljam.util.sam-util :refer [phred->fastq fastq->phred]]
             [cljam.pileup.common :refer [window-width step center]]
-            [cljam.pileup.pileup :refer [rpositions]]))
-
-(defn- wrap
-  [rname positions counts seq qual]
-  (map (fn [{:keys [pos count qual seq]}]
-         {:rname rname
-          :pos pos
-          :ref \N ; FIXME
-          :count count
-          :seq seq
-          :qual qual})
-       (map merge
-            (map (partial hash-map :pos) positions)
-            (map (partial hash-map :count) counts)
-            (map (partial hash-map :qual) qual)
-            (map (partial hash-map :seq) seq))))
+            [cljam.pileup.pileup :refer [rpositions]])
+  (:import cljam.fasta.FASTAReader))
 
 (defn- pickup-qual [aln pos]
   (if (= (:qual aln) "*")

           refs)))

(defn- pileup*
  ([rdr ^String rname ^Long rlength ^Long start ^Long end]
     (flatten
      (let [parts (partition-all step (rpositions start end))]
        (map (fn [positions]
               (let [^Long pos (if (= (count positions) step)
                                 (nth positions center)
                                 (nth positions (quot (count positions) 2)))
                     ^clojure.lang.LazySeq alns (read-alignments rdr rname rlength pos)]
                 (count-for-positions alns rname positions)))
             parts)))))

(defn pileup
  ([rdr ^String rname]
     (pileup rdr rname -1 -1))
  ([rdr ^String rname ^Long start* ^Long end*]
     (let [r (search-ref (.refs rdr) rname)]
       (if (nil? r)
         nil
         (pileup* rdr
                  rname (:len r)
                  (if (neg? start*) 0 start*)
                  (if (neg? end*) (:len r) end*))))))

                             :end right
                             :depth :deep})))

(defn- read-ref-fasta-line
  [fa-rdr rname]
  (if-not (nil? fa-rdr)
   (first
    (filter #(= (:rname %) rname) (fa/read fa-rdr)))))

(defn- search-ref
  [refs rname]
  (first
