vsearch

Versatile open-source tool for microbiome analysis

View on GitHub

NAME

cigar — a compact text-based format for representing pairwise alignments

DESCRIPTION

CIGAR (Compact Idiosyncratic Gapped Alignment Report) is a text-based format that encodes a pairwise alignment as a sequence of run-length encoded operations. Each operation describes a column of the alignment, or a run of identical consecutive columns, as seen from the query viewpoint. Hence, a cigar string encodes query modifications needed to equal the target. However, beware that cigar strings in the SAM format adopt the target viewpoint: they encode target modifications needed to equal the query (see vsearch-sam(5)). vsearch emits CIGAR strings in several search, clustering, and pairwise alignment outputs (see SEE ALSO).

A CIGAR string is an ASCII string consisting of one or more operations. Each operation is written as an optional non-negative integer run-length immediately followed by a single uppercase letter indicating the operation type:

[run-length] operation [run-length] operation ...

For example, 3M2I3MD describes an alignment that starts with three matches or mismatches, followed by two insertions (residues present only in the target), three matches or mismatches, and a single deletion (a residue present only in the query).

Operations

vsearch recognizes three operation types, corresponding to the three possible column types in a gapped pairwise alignment (see vsearch-pairwise_alignment_parameters(7)):

M
Match or mismatch. The column aligns one query residue with one target residue. vsearch does not distinguish matches from mismatches in its CIGAR strings.

I
Insertion. A residue is present in the target but absent from the query (a gap in the query); it must be inserted into the query to equal the target.

D
Deletion. A residue is present in the query but absent from the target (a gap in the target); it must be deleted from the query to equal the target.

Other operation letters defined by the SAM specification (X, =, N, S, H, P) are never produced by vsearch.

Run-length encoding

Consecutive columns of the same operation type are grouped into a single run. The number of columns in a run is written as a decimal integer immediately before the operation letter, without leading zeros. A run-length of 1 is implicit and omitted: vsearch writes M, not 1M, and MID rather than 1M1I1D. Run-lengths are positive and bounded by the alignment length; there is no maximum total length for a CIGAR string.

Empty and missing alignments

An empty CIGAR string is valid and represents an empty alignment.

When a command reports that a query has no alignment to a target, the CIGAR field is replaced with a placeholder whose value depends on the output format:

(The --blast6out tabular output contains no CIGAR field at all.)

Exact-match shorthand

As a vsearch-specific convention, a CIGAR string consisting of the single character = is emitted in the --uc output (and only there) when the query and the target sequences are strictly identical; with --cluster_fast, terminal gaps are ignored when deciding identity. This shorthand is not part of the SAM specification; --samout and the caln userfield always emit explicit operations.

Ill-formed strings

vsearch never reads CIGAR strings from its input files: the strings it writes are always well-formed as described above, and there is no user-facing path that parses one back.

EXAMPLES

The following alignment of an 8-nt query against a 9-nt target

query:     ACGT--TACG
target:    AC-TGGTTCG
alignment: MMDMIIMMMM
cigar:     2M1D1M2I4M

contains, from left to right:

Without run-length encoding, the alignment reads MMDMIIMMMM, after encoding it reads 2M1D1M2I4M. Note that M does not distinguish matches from mismatches; a mismatching column is encoded with the same operation letter.

SEE ALSO

vsearch-allpairs_global(1), vsearch-cluster_fast(1), vsearch-cluster_size(1), vsearch-cluster_smallmem(1), vsearch-cluster_unoise(1), vsearch-search_exact(1), vsearch-usearch_global(1), vsearch-sam(5), vsearch-pairwise_alignment_parameters(7), vsearch-userfields(7)

CITATION

Rognes T, Flouri T, Nichols B, Quince C, Mahé F. (2016) VSEARCH: a versatile open source tool for metagenomics. PeerJ 4:e2584 doi: 10.7717/peerj.2584

REPORTING BUGS

Submit suggestions and bug-reports at https://github.com/torognes/vsearch/issues, send a pull request on https://github.com/torognes/vsearch, or compose a friendly or curmudgeont e-mail to Torbjørn Rognes (torognes@ifi.uio.no).

AVAILABILITY

Source code and binaries are available at https://github.com/torognes/vsearch.

COPYRIGHT

Copyright (C) 2014-2026, Torbjørn Rognes, Frédéric Mahé and Tomás Flouri

All rights reserved.

Contact: Torbjørn Rognes torognes@ifi.uio.no, Department of Informatics, University of Oslo, PO Box 1080 Blindern, NO-0316 Oslo, Norway

This software is dual-licensed and available under a choice of one of two licenses, either under the terms of the GNU General Public License version 3 or the BSD 2-Clause License.

GNU General Public License version 3

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

The BSD 2-Clause License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ACKNOWLEDGMENTS

We would like to thank the authors of the following projects for making their source code available: