   (update m :chr chr/normalize-chromosome-key))
 
 (defn- fields->map
-  "Convert vector [\"key1=value1\" \"key2=value2\" ...] to map {:key1 \"value1\" :key2 \"value2\" ...}."
+  "Convert vector [\"key1=value1\" \"key2=value2\" ...] to map
+  {:key1 \"value1\" :key2 \"value2\" ...}."
   [fields]
   (into {}
         (map (fn [field]

          (serialize [wigs]
            (lazy-seq
             (when (some? (first wigs))
               (let [[track rest-wigs] (split-with (partial same-track? (first wigs)) wigs)
                     track (case (-> track first :format)
                             :variable-step
                             (let [{:keys [chr start end]} (first track)
                                   span (inc (- end start))
                                   declaration-line (->> (cond-> ["variableStep" (str "chrom=" chr)]
                                                           (not= span 1) (conj (str "span=" span)))
                                                         (cstr/join \space))
                                   data-lines (->> track
                                                   (map (fn [{:keys [start value]}] (cstr/join \space [start value])))
                                                   (cstr/join \newline))]
                               (cstr/join \newline [declaration-line data-lines]))

                             :fixed-step
                             (let [{:keys [chr start end]} (first track)
                                   step (- (-> track rest first :start) start)
                                   span (inc (- end start))
                                   declaration-line (->> (cond-> ["fixedStep" (str "chrom=" chr) (str "start=" start)]
                                                           (not= step 1) (conj (str "step=" step))
                                                           (not= span 1) (conj (str "span=" span)))
                                                         (cstr/join \space))
                                   data-lines (->> track
                                                   (map (fn [{:keys [value]}] value))
                                                   (cstr/join \newline))]
                               (cstr/join \newline [declaration-line data-lines])))]
                 (cons track (serialize rest-wigs))))))]
    (serialize wigs)))


                 (case (first fields)
                   ; declaration line of variableStep
                   "variableStep"
                   (let [{:keys [chrom span]
                          :or {span 1}} (->> fields rest fields->map)
                         span (as-long span)]
                     (deserialize (rest lines)
                                  {:format :variable-step
                                   :chr chrom
                                   :pre-start nil
                                   :span span
                                   :step nil}))

                   ; declaration line of fixedStep
                   "fixedStep"
                   (let [{:keys [chrom start span step]
                          :or {span 1, step 1}} (->> fields rest fields->map)
                         step (as-long step)
                         pre-start (- (as-long start) step)
                         span (as-long span)]
                     (deserialize (rest lines)
                                  {:format :fixed-step
                                   :chr chrom
                                   :pre-start pre-start
                                   :span span
                                   :step step}))

                   ; data line
                   (let [m (case (:format current-track)
