Samtools

From wiki
Revision as of 14:27, 9 September 2016 by Rf (talk | contribs)
Jump to: navigation, search

Introduction

Samtools hardly needs an introduction, it is one of the cornerstones of bioinformatics processing and is at the heart of the business of sequence mapping / aligning.

Despite that introduction, note that samtools does not actually carry out alignments itself. Rather it offers utilities attendant on real aligners such as bwa and bowtie.

Primarily this is due to its providing various tools (available as subcommands) centred on a well defined sequence alignment format, sam, and its binary (and therefore compressed) equivalent, bam.

This wiki page just offers some tips on how to use it, as there is plenty documentation elsewhere, some of which is mentioned in the links.

Tips

  1. samtools commands follow the subcommand style: i.e. they always start with a "samtools" followed by subcommand (eg. "sort", "view", etc) which identify the exact operation samtools will perform. This is due to the fact that samtools is a suite of tools for handling alignment files in sam/bam format.
  2. Two input files will commonly be needed, often a sam/bam file and also the reference file.
  3. view is a commonly used subcommand, whose name however refers to internal viewing, because external user visuals is not samtools strong point, though it has some capabilities in this regard ("tview").

Common commands

A bam file is the compressed binary version of a sam file. It exists purely for efficiency purposes and contains the same information. Because it is not human-readable, converting out of, but also back into bam, is very frequent activity. It is ndone via the


Sorting can be as easy as

samtools sort aln.bam aln.sorted


tview

While visualisation is not samtools' strong point, the tview subcommand does provide a raw view of the alignment that a bam files has. Sometimes such raw, and less pretty representations of the alignment can be useful. It is run like so:

samtools tview alignments/sim_reads_aligned.sorted.bam genomes/NC_008253.fna

Explanation: You can see here the point relating to tip no .2 above ... the two arguments are the bam file (first argument) and its associated reference (second argument) with no option switches.

Links

Installation Notes

Since version 1.2, samtools build structure has changed. Before it was monolithic, since 1.2 it is split into a lobrary, htslib and smatools proper. A third package, bcftools, is often mentioned in the same breath, though