A DNA Sequence Alignment/Map (SAM) library for Clojure
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
bench/cljam Remove namespace cljam.algo.pileup.mpileup Aug 10, 2018
bin-resources Add a logging configuration for cli Aug 22, 2017
.gitignore Use Marginalia for generating documents Mar 4, 2014
LICENSE Modify the license to Apache License, Version 2.0 Apr 2, 2014
README.md Release 0.6.0 Jun 22, 2018
deploy-snapshot.sh Use clojure 1.9 for the dev profile Jun 22, 2018
project.clj Upgrade lein-cloverage to 1.0.13 Aug 27, 2018



A DNA Sequence Alignment/Map (SAM) library for Clojure. [API Reference] [Annotated Source]

Clojars Project

Build Status



cljam is available as a Maven artifact from Clojars.

To use with Leiningen/Boot, add the following dependency.

[cljam "0.6.0"]

To use with Maven, add the following dependency.


Breaking changes in 0.6.0

  • N padding for out-of-range bases is not appended. See #120 comment and #121 for more information.
  • cljam.io.protocols/{reader,writer}-path were renamed to cljam.io.protocols/{reader,writer}-url. Their return values are java.net.URL.

Getting started

To read a SAM/BAM format file,

(require '[cljam.io.sam :as sam])

;; Open a file
(with-open [r (sam/reader "path/to/file.bam")]
  ;; Retrieve header
  (sam/read-header r)
  ;; Retrieve alignments
  (doall (take 5 (sam/read-alignments r))))

To create a sorted file,

(require '[cljam.io.sam :as sam]
         '[cljam.algo.sorter :as sorter])

(with-open [r (sam/reader "path/to/file.bam")
            w (sam/writer "path/to/sorted.bam")]
  ;; Sort by chromosomal coordinates
  (sorter/sort-by-pos r w))

To create a BAM index file,

(require '[cljam.algo.bam-indexer :as bai])

;; Create a new BAM index file
(bai/create-index "path/to/sorted.bam" "path/to/sorted.bam.bai")

To calculate coverage depth for a BAM file,

(require '[cljam.io.sam :as sam]
         '[cljam.algo.depth :as depth])

(with-open [r (sam/reader "path/to/sorted.bam")]
  ;; Pileup "chr1" alignments
  (depth/depth r {:chr "chr1", :start 1, :end 10}))
;;=> (0 0 0 0 0 0 1 1 3 3)

If you are Clojure beginner, read Getting Started for Clojure Beginners.

Command-line tool

cljam provides a command-line tool to use the features easily.

Executable installation

lein bin creates standalone console executable into target directory.

$ lein bin
Creating standalone executable: /path/to/cljam/target/cljam

Copy the executable cljam somewhere in your $PATH.


All commands are displayed by cljam -h, and detailed help for each command are displayed by cljam [cmd] -h.

$ cljam view -h

For example, to display contents of a SAM file including the header,

$ cljam view --header path/to/file.sam

See command-line tool manual for more information.



To run tests,

  • lein test for basic tests,
  • lein test :slow for slow tests with local resources,
  • lein test :remote for tests with remote resources.

To get coverage

$ lein cloverage

And open target/coverage/index.html.

Generating document

cljam uses Codox for API reference and Marginalia for annotated source code.

$ lein docs

generates these documents in target/docs and target/literate directories.

Citing cljam

T. Takeuchi, A. Yamada, T. Aoki, and K. Nishimura. cljam: a library for handling DNA sequence alignment/map (SAM) with parallel processing. Source Code for Biology and Medicine, Vol. 11, No. 1, pp. 1-4, 2016.


Sorted by first commit.


Copyright 2013-2018 Xcoo, Inc.

Licensed under the Apache License, Version 2.0.