            refs)))
 
 (defn- pileup*
-  ([rdr ^String rname ^Long rlength ^Long start ^Long end]
+  ([rdr ^FASTAReader fa-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)))
+                     ^clojure.lang.LazySeq alns (read-alignments rdr rname rlength pos)
+                     ref-line (read-ref-fasta-line fa-rdr rname)]
+                 (count-for-positions alns ref-line rname positions)))
              parts)))))
 
 (defn pileup
   ([rdr ^String rname]
      (pileup rdr rname -1 -1))
-  ([rdr ^String rname ^Long start* ^Long end*]
+  ([rdr ^String rname ^Long start* ^Long end* & {:keys [ref-fasta] :or {ref-fasta nil}}]
      (let [r (search-ref (.refs rdr) rname)]
        (if (nil? r)
          nil
          (pileup* rdr
+                  ref-fasta
                   rname (:len r)
                   (if (neg? start*) 0 start*)
                   (if (neg? end*) (:len r) end*))))))

                             :end right
                             :depth :deep})))

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

               (PileupStatus. 0 nil nil))) positions))
    (repeat (count positions) (PileupStatus. 0 nil nil))))

(defn- pickup-ref
  [ref-line pos]
  (let [idx (- pos (:offset ref-line))]
    (if (neg? idx)
      \N
      (if-let [ref (nth (:seq ref-line) idx)]
        ref
        \N))))

(defn- wrap
  [rname ref-line positions counts seq qual]
  (map (fn [{:keys [pos count qual seq]}]
         {:rname rname
          :pos   pos
          :ref   (if (nil? ref-line)
                   \N
                   (pickup-ref ref-line pos))
          :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))))

(defn- count-for-positions
  [alns ref-line rname positions]
  (if (pos? (count alns))
    (let [cfas (map #(count-for-alignment % rname positions) alns)]
      (wrap rname ref-line positions
            (apply map (fn [& args]
                         (reduce + (map :count args))) cfas)
            (apply map (fn [& args]
