Pairwise whole genome alignment

code <- function(...) {
    cat(paste(..., sep = "\n"))

date = "`r doc_date()`"
pkg = "`r pkg_ver('BiocStyle')`"


r Biocpkg("CNEr") identifies conserved noncoding elments (CNEs) from pairwise whole genome alignment (net.axt files) of two species. UCSC has provided alignments between many species on the downloads, hence it is highly recommended to use their alignments when available. When the alignments of some new assemblies/species are not availble from UCSC yet, this vignette describes the pipeline of generating the alignments merely from soft-masked 2bit files or fasta files. This vignette is based on the genomewiki from UCSC.



List of external softwares have to be installed on the machine: * The sequence alignment program LASTZ * Kent Utilities. In this pipeline, lavToPsl, axtChain, chainMergeSort, chainPreNet, chainNet, netSyntenic, netToAxt, axtSort are essential. netClass is optional.


Here, as an example, we will get the pairwise alignment only on "chr1", "chr2" and "chr3" between zebrafish(danRer10) and human(hg38).

LASTZ aligner

First we need to download the 2bit files from UCSC, and set the appropriate paths of assemblyTarget, assemblyQuery and intermediate files. Then we can run lastz function to generate the lav files.

## lastz aligner
assemblyDir <- "/Users/gtan/OneDrive/Project/CSC/CNEr/2bit"
axtDir <- "/Users/gtan/OneDrive/Project/CSC/CNEr/axt"
assemblyTarget <- file.path(system.file("extdata",
assemblyQuery <- file.path(system.file("extdata",
lavs <- lastz(assemblyTarget, assemblyQuery, 
              chrsTarget=c("chr1", "chr2", "chr3"),
              chrsQuery=c("chr1", "chr2", "chr3"),
              distance="far", mc.cores=4)

## lav files to psl files conversion
psls <- lavToPsl(lavs, removeLav=FALSE, binary="lavToPsl")

One essential argument here is the distance. It determines the scoring matrix to use in lastz aligner. See ?scoringMatrix for more details.

Note: This step may encounter difficulties if the two assemblies are too fragmented, because there can be millions of combinations of the chromosomes/scaffolds. The lastz is overwhelmed with reading small pieces from assembly for each combination, rather than doing actual alignment. In this case, another aligner last is recommended and introduced in nex section.

last aligner

last aligner is considered faster and memory efficient. It creates maf file, which can converted to psl files. Then the same following processes can be used on psl files.

Different from lastz, last aligner starts with fasta files. The target genome sequence has to build the index file first, and then align with the query genome sequence.

## Build the lastdb index
system2(command="lastdb", args=c("-c", file.path(assemblyDir, "danRer10"),
                                 file.path(assemblyDir, "danRer10.fa")))

## Run last aligner
lastal(db=file.path(assemblyDir, "danRer10"),
       queryFn=file.path(assemblyDir, "hg38.fa"),
       outputFn=file.path(axtDir, "danRer10.hg38.maf"),
       distance="far", binary="lastal", mc.cores=4L)

## maf to psl 
psls <- file.path(axtDir, "danRer10.hg38.psl")
system2(command="maf-convert", args=c("psl", 
                                      file.path(axtDir, "danRer10.hg38.maf"),
                                      ">", psls))

YASS aligner

Another alternative of alignment software is YASS. It may be added into this pipeline after we test the performance.


If two matching alignments next to each other are close enough, they are joined into one fragment. Then these chain files are sorted and combined into one big file.

## Join close alignments
chains <- axtChain(psls, assemblyTarget=assemblyTarget,
                   assemblyQuery=assemblyQuery, distance="far",
                   removePsl=FALSE, binary="axtChain")

## Sort and combine
allChain <- chainMergeSort(chains, assemblyTarget, assemblyQuery,
                         paste0(sub("\\.2bit$", "", basename(assemblyTarget),
                          , ".", 
                                sub("\\.2bit$", "", basename(assemblyQuery), 
                          , ".all.chain")),
                           removeChains=FALSE, binary="chainMergeSort")


In this step, first we filter out chains that are unlikely to be netted by chainPreNet. During the alignment, every genomic fragment can match with several others, and certainly we want to keep the best one. This is done by chainNet. Then we add the synteny information with netSyntenic.

## Filtering out chains
allPreChain <- chainPreNet(allChain, assemblyTarget, assemblyQuery,
                                      paste0(sub("\\.2bit$", "", 
                                        = TRUE), ".", 
                                             sub("\\.2bit$", "",
                                        = TRUE),
                           removeAllChain=FALSE, binary="chainPreNet")

## Keep the best chain and add synteny information
netSyntenicFile <- chainNetSyntenic(allPreChain, assemblyTarget, assemblyQuery,
                                               paste0(sub("\\.2bit$", "",
                                             = TRUE), ".",
                                                      sub("\\.2bit$", "",
                                             = TRUE),
                     binaryChainNet="chainNet", binaryNetSyntenic="netSyntenic")


As the last step, we create the .net.axt file from the previous net and chain files.

netToAxt(netSyntenicFile, allPreChain, assemblyTarget, assemblyQuery,
                           paste0(sub("\\.2bit$", "",
                             = TRUE), ".",
                                  sub("\\.2bit$", "",
                             = TRUE),
             binaryNetToAxt="netToAxt", binaryAxtSort="axtSort")

Session info

Here is the output of sessionInfo() on the system on which this document was compiled:


Try the CNEr package in your browser

Any scripts or data that you put into this service are public.

CNEr documentation built on Nov. 8, 2020, 5:36 p.m.