Bowtie2で許容編集距離を設定する

Bowtie2のoptionは複雑で、とりあえずデフォルトで回してからSAMをパースしている人は多いかもしれない。
マニュアルを良く読むとスコアをきちんと設定すれば色々設定できる。

Bowtie 2: Manual
特に以下の部分。

Scoring options

--mp MX,MN
Sets the maximum (MX) and minimum (MN) mismatch penalties, both integers. A number less than or equal to MX and greater than or equal to MN is subtracted from the alignment score for each position where a read character aligns to a reference character, the characters do not match, and neither is an N. If --ignore-quals is specified, the number subtracted quals MX. Otherwise, the number subtracted is MN + floor( (MX-MN)(MIN(Q, 40.0)/40.0) ) where Q is the Phred quality value. Default: MX = 6, MN = 2.

--np
Sets penalty for positions where the read, reference, or both, contain an ambiguous character such as N. Default: 1.

--rdg ,
Sets the read gap open () and extend () penalties. A read gap of length N gets a penalty of + N * . Default: 5, 3.

--rfg ,
Sets the reference gap open () and extend () penalties. A reference gap of length N gets a penalty of + N * . Default: 5, 3.

--score-min
Sets a function governing the minimum alignment score needed for an alignment to be considered "valid" (i.e. good enough to report). This is a function of read length. For instance, specifying L,0,-0.6 sets the minimum-score function f to f(x) = 0 + -0.6 * x, where x is the read length. See also: setting function options. The default in --end-to-end mode is L,-0.6,-0.6 and the default in --local mode is G,20,8.

日本語で要約すると
--mp: ミスマッチペナルティ(最大,最小)、リードのクオリティでスコアがバラける。
--np: N(曖昧塩基)のペナルティ、Bowtie2では他の縮退塩基もNとして扱われる。
--rdg: リードのギャップペナルティ(開始,延長それぞれについて規定)
--rfg: 参照配列のギャップペナルティ(開始,延長それぞれについて規定)
これを編集距離へを変化させるには、それぞれを1に設定すれば良い(ギャップ開始は0)。

最も煩雑なのは
--score-min
であり、これは以下のように書いてあるが、要約するとリードの長さを変数としたときの "式のタイプ, y切片,傾き" である。

Setting function options

Some Bowtie 2 options specify a function rather than an individual number or setting. In these cases the user specifies three parameters: (a) a function type F, (b) a constant term B, and (c) a coefficient A. The available function types are constant (C), linear (L), square-root (S), and natural log (G). The parameters are specified as F,B,A - that is, the function type, the constant term, and the coefficient are separated by commas with no whitespace. The constant term and coefficient may be negative and/or floating-point numbers.

For example, if the function specification is L,-0.4,-0.6, then the function defined is:

f(x) = -0.4 + -0.6 * x
If the function specification is G,1,5.4, then the function defined is:

f(x) = 1.0 + 5.4 * ln(x)
See the documentation for the option in question to learn what the parameter x is for. For example, in the case if the --score-min option, the function f(x) sets the minimum alignment score necessary for an alignment to be considered valid, and x is the read length.

よって、編集距離1以内のものだけを出力するオプションは以下のようになる。

--mp "1,1" --rdg "0,1" --rfg "0,1" --score-min "C,-1,0"

”C”については例示すら無いが一応これでちゃんと動くのは確認した。(SAMファイル内で "XM:i:" が1を超えるものがなかった。)