2018-02-03 02:57:08 +08:00
|
|
|
## <a name="started"></a>Getting Started
|
2018-02-03 10:45:46 +08:00
|
|
|
|
2018-02-03 02:57:08 +08:00
|
|
|
```sh
|
|
|
|
|
curl -L https://github.com/attractivechaos/k8/releases/download/v0.2.4/k8-0.2.4.tar.bz2 | tar -jxf -
|
2018-02-03 10:45:46 +08:00
|
|
|
cp k8-0.2.4/k8-`uname -s` $HOME/bin/k8 # assuming $HOME/bin in your $PATH
|
|
|
|
|
gff2bed.js anno.gtf | less -S # convert GTF/GFF3 to BED12 (if k8 installed to $PATH)
|
|
|
|
|
k8 gff2bed.js anno.gtf | less -S # convert GTF/GFF3 to BED12 (if k8 not installed)
|
|
|
|
|
sam2paf.js aln.sam.gz | less -S # convert SAM to PAF
|
|
|
|
|
minimap2 --cs test/MT-*.fa | paf2aln.js - | less # pretty print base alignment
|
2018-02-03 02:57:08 +08:00
|
|
|
minimap2 -cx splice ref.fa rna-seq.fq | splice2bed.js - # convert splice aln to BED12
|
|
|
|
|
```
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 03:07:17 +08:00
|
|
|
## Table of Contents
|
|
|
|
|
|
|
|
|
|
- [Getting Started](#started)
|
|
|
|
|
- [Introduction](#intro)
|
2018-02-03 03:43:58 +08:00
|
|
|
- [Format Conversion](#conv)
|
2018-02-03 10:45:46 +08:00
|
|
|
- [Convert PAF to MAF or BLAST-like format](#paf2aln)
|
2018-02-03 03:12:30 +08:00
|
|
|
- [Convert SAM to PAF](#sam2paf)
|
2018-02-03 10:45:46 +08:00
|
|
|
- [Convert GTF/GFF3 to BED12](#gff2bed)
|
2018-02-03 03:12:30 +08:00
|
|
|
- [Convert spliced alignment to BED12](#splice2bed)
|
2018-02-03 03:43:58 +08:00
|
|
|
- [Evaluation](#eval)
|
2018-02-03 03:18:18 +08:00
|
|
|
- [Evaluating mapping accuracy with simulated reads](#mapeval)
|
|
|
|
|
- [Evaluating read overlap sensitivity](#oveval)
|
2018-02-03 10:45:46 +08:00
|
|
|
- [Calling Variants from Assemblies](#asmvar)
|
2018-02-03 03:07:17 +08:00
|
|
|
|
|
|
|
|
## <a name="intro"></a>Introduction
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 02:57:08 +08:00
|
|
|
This directory contains auxiliary scripts for format conversion, mapping
|
|
|
|
|
accuracy evaluation and miscellaneous purposes. These scripts *require*
|
|
|
|
|
the [k8 Javascript shell][k8] to run. On Linux or Mac, you can download
|
|
|
|
|
the precompiled k8 binary with:
|
2018-02-03 10:45:46 +08:00
|
|
|
|
2018-02-03 02:57:08 +08:00
|
|
|
```sh
|
|
|
|
|
curl -L https://github.com/attractivechaos/k8/releases/download/v0.2.4/k8-0.2.4.tar.bz2 | tar -jxf -
|
2018-02-03 10:45:46 +08:00
|
|
|
cp k8-0.2.4/k8-`uname -s` $HOME/bin/k8 # assuming $HOME/bin in your $PATH
|
2018-02-03 02:57:08 +08:00
|
|
|
```
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
It is highly recommended to copy the executable `k8` to a directory on your
|
|
|
|
|
`$PATH` such as `/usr/bin/env` can find it. Like python or perl scripts, once
|
|
|
|
|
you install `k8`, you can launch these k8 scripts either with
|
2018-02-03 03:43:58 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
```sh
|
|
|
|
|
path/to/gff2bed.js anno.gtf.gz
|
|
|
|
|
```
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
or with
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
```sh
|
|
|
|
|
k8 path/to/gff2bed.js anno.gtf
|
|
|
|
|
```
|
2017-08-05 02:46:31 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
All k8 scripts seamlessly work with both plain text files and gzip'd text files.
|
2018-02-03 03:12:30 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
## <a name="conv"></a>Format Conversion
|
2018-02-03 03:12:30 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
* <a name="paf2aln"></a>Script [paf2aln.js](paf2aln.js) converts PAF with the
|
|
|
|
|
[cs tag][cs] to [MAF][maf] or BLAST-like output. It only works with minimap2
|
|
|
|
|
output generated using the `--cs` tag.
|
2018-02-03 03:07:17 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
* <a name="sam2paf"></a>Script [sam2paf.js](sam2paf.js) converts alignments in
|
|
|
|
|
the SAM format to PAF.
|
2018-02-03 03:07:17 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
* <a name="gff2bed"></a>Script [gff2bed.js](gff2bed.js) converts GFF format to
|
|
|
|
|
12-column BED format. It seamlessly works with both GTF and GFF3.
|
2018-02-03 03:07:17 +08:00
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
* <a name="splice2bed"></a>Script [splice2bed.js](splice2bed.js) converts
|
|
|
|
|
spliced alignment in SAM or PAF to 12-column BED format.
|
2018-02-03 03:07:17 +08:00
|
|
|
|
2018-02-03 03:43:58 +08:00
|
|
|
## <a name="eval"></a>Evaluation
|
|
|
|
|
|
2018-02-03 03:18:18 +08:00
|
|
|
### <a name="mapeval"></a>Evaluating mapping accuracy with simulated reads
|
2018-02-03 02:57:08 +08:00
|
|
|
|
|
|
|
|
Script [sim-pbsim.js](sim-pbsim.js) converts the MAF output of [pbsim][pbsim]
|
|
|
|
|
to FASTQ and encodes the true mapping position in the read name in a format like
|
|
|
|
|
`S1_33!chr1!225258409!225267761!-`. Similarly, script
|
|
|
|
|
[sim-mason2.js](sim-mason2.js) converts [mason2][mason2] simulated SAM to
|
|
|
|
|
FASTQ.
|
|
|
|
|
|
2018-02-03 03:07:17 +08:00
|
|
|
Script [sim-eval.js](sim-eval.js) evaluates mapped SAM/PAF. Here is example output:
|
2018-02-03 02:57:08 +08:00
|
|
|
```
|
|
|
|
|
Q 60 32478 0 0.000000000 32478
|
|
|
|
|
Q 22 16 1 0.000030775 32494
|
|
|
|
|
Q 21 43 1 0.000061468 32537
|
|
|
|
|
Q 19 73 1 0.000091996 32610
|
|
|
|
|
Q 14 66 1 0.000122414 32676
|
|
|
|
|
Q 10 27 3 0.000214048 32703
|
|
|
|
|
Q 8 14 1 0.000244521 32717
|
|
|
|
|
Q 7 13 2 0.000305530 32730
|
|
|
|
|
Q 6 46 1 0.000335611 32776
|
|
|
|
|
Q 3 10 1 0.000366010 32786
|
|
|
|
|
Q 2 20 2 0.000426751 32806
|
|
|
|
|
Q 1 248 94 0.003267381 33054
|
|
|
|
|
Q 0 31 17 0.003778147 33085
|
|
|
|
|
U 3
|
|
|
|
|
```
|
|
|
|
|
where each Q-line gives the quality threshold, the number of reads mapped with
|
|
|
|
|
mapping quality equal to or greater than the threshold, number of wrong
|
|
|
|
|
mappings, accumulative mapping error rate and the accumulative number of
|
|
|
|
|
mapped reads. The U-line gives the number of unmapped reads if they are present
|
|
|
|
|
in the SAM file.
|
|
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
Suppose the reported mapping coordinate overlap with the true coordinate like
|
|
|
|
|
the following:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
truth: --------------------
|
|
|
|
|
mapper: ----------------------
|
|
|
|
|
|<- l1 ->|<-- o -->|<-- l2 -->|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Let `r=o/(l1+o+l2)`. The reported mapping is considered correct if `r>0.1` by
|
|
|
|
|
default.
|
|
|
|
|
|
2018-02-03 03:18:18 +08:00
|
|
|
### <a name="oveval"></a>Evaluating read overlap sensitivity
|
|
|
|
|
|
2018-02-03 10:45:46 +08:00
|
|
|
Script [ov-eval.js](ov-eval.js) takes sorted read-to-reference alignment and
|
|
|
|
|
read overlaps in PAF as input, and evaluates the sensitivity. For example:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
minimap2 -cx map-pb ref.fa reads.fq.gz | sort -k6,6 -k8,8n > reads-to-ref.paf
|
|
|
|
|
minimap2 -x ava-pb reads.fq.gz reads.fq.gz > ovlp.paf
|
|
|
|
|
k8 ov-eval.js reads-to-ref.paf ovlp.paf
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## <a name="asmvar"></a>Calling Variants from Haploid Assemblies
|
|
|
|
|
|
2018-02-09 23:47:12 +08:00
|
|
|
Command `paftools.js call` calls variants from coordinate-sorted
|
2018-02-03 10:45:46 +08:00
|
|
|
assembly-to-reference alignment. It calls variants from the [cs tag][cs] and
|
|
|
|
|
identifies confident/callable regions as those covered by exactly one contig.
|
|
|
|
|
Here are example command lines:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
minimap2 -cx asm5 -t8 --cs ref.fa asm.fa > asm.paf # keeping this file is recommended; --cs required!
|
|
|
|
|
sort -k6,6 -k8,8n asm.paf > asm.srt.paf # sort by reference start coordinate
|
2018-02-09 23:47:12 +08:00
|
|
|
k8 paftools.js call asm.srt.paf > asm.var.txt
|
2018-02-03 10:45:46 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Here is sample output:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
V chr1 3181702 3181703 1 60 c t
|
|
|
|
|
V chr1 3181730 3181768 1 60 gtcttacacacggagtcttacacacggtcttacacaca -
|
|
|
|
|
R chr1 3181796 3260557
|
|
|
|
|
V chr1 3181818 3181822 1 60 tgcg -
|
|
|
|
|
V chr1 3181831 3181832 1 60 a g
|
|
|
|
|
V chr1 3181832 3181833 1 60 t c
|
|
|
|
|
V chr1 3181833 3181834 1 60 t g
|
|
|
|
|
V chr1 3181874 3181874 1 60 - ca
|
|
|
|
|
V chr1 3181879 3181880 1 60 g a
|
|
|
|
|
V chr1 3181886 3181887 1 60 c g
|
|
|
|
|
V chr1 3181911 3181911 1 60 - agtcttacacatgcagtcttacacat
|
|
|
|
|
V chr1 3181924 3181925 1 60 t c
|
|
|
|
|
V chr1 3182079 3182080 1 60 g a
|
|
|
|
|
V chr1 3182150 3182151 1 60 t c
|
|
|
|
|
V chr1 3182336 3182337 1 60 t c
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
where a line starting with `R` gives regions covered by one contig, and a
|
|
|
|
|
V-line encodes a variant in the following format: chr, start, end, contig
|
|
|
|
|
depth, mapping quality, REF allele and ALT allele.
|
|
|
|
|
|
|
|
|
|
By default, when calling variants, this script ignores alignments 50kb or
|
|
|
|
|
shorter; when deriving callable regions, it ignores alignments 10kb or shorter.
|
|
|
|
|
It uses two thresholds to avoid edge effects. These defaults are designed for
|
|
|
|
|
long-read assemblies. For short reads, both should be reduced.
|
|
|
|
|
|
|
|
|
|
|
2018-02-03 03:18:18 +08:00
|
|
|
|
2018-02-03 02:57:08 +08:00
|
|
|
[cs]: https://github.com/lh3/minimap2#cs
|
2017-08-05 02:46:31 +08:00
|
|
|
[k8]: https://github.com/attractivechaos/k8
|
|
|
|
|
[maf]: https://genome.ucsc.edu/FAQ/FAQformat#format5
|
|
|
|
|
[pbsim]: https://github.com/pfaucon/PBSIM-PacBio-Simulator
|
2018-02-03 02:57:08 +08:00
|
|
|
[mason2]: https://github.com/seqan/seqan/tree/master/apps/mason2
|