               (io/write-alignments wtr alns hdr)))))))
   nil)
 
+;;; normalize command
+
+(def ^:private normalize-cli-options
+  [["-h" "--help"]])
+
+(defn- normalize-usage [options-summary]
+  (->> ["Normalize references of alignments"
+        ""
+        "Usage: cljam normalize <in.bam|sam> <out.bam|sam>"
+        ""
+        "Options:"
+        options-summary]
+       (str/join \newline)))
+
+(defn normalize [args]
+  (let [{:keys [options arguments errors summary]} (parse-opts args normalize-cli-options)]
+    (cond
+     (:help options) (exit 0 (normalize-usage summary))
+     (not= (count arguments) 2) (exit 1 (normalize-usage summary))
+     errors (exit 1 (error-msg errors)))
+    (let [[in out] arguments
+          r (reader in)
+          w (writer out)]
+      (normal/normalize r w)))
+  nil)
+
 ;;; sort command
 
 (def ^:private sort-cli-options

                   [io :as io]
                   [bam :as bam]
                   [bam-indexer :as bai]
                   [sorter :as sorter]
                   [fasta :as fa]
                   [fasta-indexer :as fai]

                                          :options  [["-h" "--help" "Show help" :default false :flag true]]
                                          :commands [["view"    "Extract/print all or sub alignments in SAM or BAM format."]
                                                     ["convert" "Convert SAM to BAM or BAM to SAM."]
                                                     ["normalize" "Normalize references of alignments"]
                                                     ["sort"    "Sort alignments by leftmost coordinates."]
                                                     ["index"   "Index sorted alignment for fast random access."]
                                                     ["pileup"  "Generate pileup for the BAM file."]
