     (repeat (count positions) (PileupStatus. 0 nil nil))))
 
 (defn- pickup-ref
-  [ref-line pos]
-  (if (nil? ref-line)
+  [ref-seq pos]
+  (if (nil? ref-seq)
     \N
     (let [idx (dec pos)]
       (if (neg? idx)
         \N
-        (if-let [ref (nth (:seq ref-line) idx)]
+        (if-let [ref (nth ref-seq idx)]
           ref
           \N)))))
 
 (defn- count-for-positions
   [alns ref-line rname positions]
   (if (pos? (count alns))
-    (let [cfas (map #(count-for-alignment % rname positions) alns)
+    (let [cfas (map #(count-for-alignment % (:seq ref-line) rname positions) alns)
           plp1 (apply map (fn [& a]
                             {:rname rname
                              :count (reduce + (map :count a))
                              :seq   (str/join (map :seq a))
                              :qual  (str/join (map :qual a))}) cfas)]
-      (map #(assoc %2 :pos %1 :ref (pickup-ref ref-line %2))
+      (map #(assoc %2 :pos %1 :ref (pickup-ref (:seq ref-line) %1))
            positions plp1))
     (let [plp1 (repeat (count positions) {:rname rname
                                           :count 0
                                           :seq   nil
                                           :qual  nil})]
-      (map #(assoc %2 :pos %1 :ref (pickup-ref ref-line %2))
+      (map #(assoc %2 :pos %1 :ref (pickup-ref (:seq ref-line) %1))
            positions plp1))))
 
 (defn- read-alignments

            [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]])
  (:import cljam.fasta.FASTAReader))

(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]
