Contents

1 Introduction

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.

Note:

2 Prerequisite

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.

3 Aligning

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

3.1 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",
                            package="BSgenome.Drerio.UCSC.danRer10"),
                            "single_sequences.2bit")
assemblyQuery <- file.path(system.file("extdata",
                                       package="BSgenome.Hsapiens.UCSC.hg38"),
                           "single_sequences.2bit")
lavs <- lastz(assemblyTarget, assemblyQuery, 
              outputDir=axtDir,
              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.

3.2 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))

3.3 YASS aligner

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

4 Chaining:

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,
              allChain=file.path(axtDir,
                         paste0(sub("\\.2bit$", "", basename(assemblyTarget),
                                    ignore.case=TRUE), ".", 
                                sub("\\.2bit$", "", basename(assemblyQuery), 
                                    ignore.case=TRUE), ".all.chain")),
                           removeChains=FALSE, binary="chainMergeSort")

5 Netting:

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,
                           allPreChain=file.path(axtDir,
                                      paste0(sub("\\.2bit$", "", 
                                                 basename(assemblyTarget),
                                                 ignore.case = TRUE), ".", 
                                             sub("\\.2bit$", "",
                                                 basename(assemblyQuery),
                                                 ignore.case = TRUE),
                                                 ".all.pre.chain")),
                           removeAllChain=FALSE, binary="chainPreNet")

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

6 axtNet

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

netToAxt(netSyntenicFile, allPreChain, assemblyTarget, assemblyQuery,
         axtFile=file.path(axtDir,
                           paste0(sub("\\.2bit$", "",
                                      basename(assemblyTarget),
                                      ignore.case = TRUE), ".",
                                  sub("\\.2bit$", "",
                                      basename(assemblyQuery),
                                      ignore.case = TRUE),
                                  ".net.axt")),
             removeFiles=FALSE,
             binaryNetToAxt="netToAxt", binaryAxtSort="axtSort")

7 Session info

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

## R version 4.0.0 RC (2020-04-19 r78255)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 18.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.12-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.12-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
##  [1] grid      stats4    parallel  stats     graphics  grDevices utils    
##  [8] datasets  methods   base     
## 
## other attached packages:
##  [1] Gviz_1.33.0                         BSgenome.Ggallus.UCSC.galGal3_1.4.0
##  [3] BSgenome.Hsapiens.UCSC.hg19_1.4.3   BSgenome_1.57.0                    
##  [5] rtracklayer_1.49.0                  Biostrings_2.57.0                  
##  [7] XVector_0.29.0                      GenomicRanges_1.41.0               
##  [9] GenomeInfoDb_1.25.0                 IRanges_2.23.0                     
## [11] S4Vectors_0.27.0                    BiocGenerics_0.35.0                
## [13] CNEr_1.25.0                         BiocStyle_2.17.0                   
## 
## loaded via a namespace (and not attached):
##   [1] colorspace_1.4-1            ellipsis_0.3.0             
##   [3] biovizBase_1.37.0           htmlTable_1.13.3           
##   [5] base64enc_0.1-3             dichromat_2.0-0            
##   [7] rstudioapi_0.11             farver_2.0.3               
##   [9] bit64_0.9-7                 AnnotationDbi_1.51.0       
##  [11] splines_4.0.0               R.methodsS3_1.8.0          
##  [13] knitr_1.28                  Formula_1.2-3              
##  [15] Rsamtools_2.5.0             annotate_1.67.0            
##  [17] cluster_2.1.0               GO.db_3.10.0               
##  [19] dbplyr_1.4.3                png_0.1-7                  
##  [21] R.oo_1.23.0                 BiocManager_1.30.10        
##  [23] readr_1.3.1                 compiler_4.0.0             
##  [25] httr_1.4.1                  backports_1.1.6            
##  [27] lazyeval_0.2.2              assertthat_0.2.1           
##  [29] Matrix_1.2-18               acepack_1.4.1              
##  [31] htmltools_0.4.0             prettyunits_1.1.1          
##  [33] tools_4.0.0                 gtable_0.3.0               
##  [35] glue_1.4.0                  GenomeInfoDbData_1.2.3     
##  [37] reshape2_1.4.4              dplyr_0.8.5                
##  [39] rappdirs_0.3.1              Rcpp_1.0.4.6               
##  [41] Biobase_2.49.0              vctrs_0.2.4                
##  [43] xfun_0.13                   stringr_1.4.0              
##  [45] lifecycle_0.2.0             ensembldb_2.13.0           
##  [47] poweRlaw_0.70.6             XML_3.99-0.3               
##  [49] zlibbioc_1.35.0             scales_1.1.0               
##  [51] VariantAnnotation_1.35.0    ProtGenerics_1.21.0        
##  [53] hms_0.5.3                   SummarizedExperiment_1.19.0
##  [55] AnnotationFilter_1.13.0     RColorBrewer_1.1-2         
##  [57] yaml_2.2.1                  curl_4.3                   
##  [59] memoise_1.1.0               gridExtra_2.3              
##  [61] ggplot2_3.3.0               biomaRt_2.45.0             
##  [63] rpart_4.1-15                latticeExtra_0.6-29        
##  [65] stringi_1.4.6               RSQLite_2.2.0              
##  [67] checkmate_2.0.0             GenomicFeatures_1.41.0     
##  [69] BiocParallel_1.23.0         rlang_0.4.5                
##  [71] pkgconfig_2.0.3             matrixStats_0.56.0         
##  [73] bitops_1.0-6                pracma_2.2.9               
##  [75] evaluate_0.14               lattice_0.20-41            
##  [77] purrr_0.3.4                 htmlwidgets_1.5.1          
##  [79] GenomicAlignments_1.25.0    labeling_0.3               
##  [81] bit_1.1-15.2                tidyselect_1.0.0           
##  [83] plyr_1.8.6                  magrittr_1.5               
##  [85] bookdown_0.18               R6_2.4.1                   
##  [87] magick_2.3                  Hmisc_4.4-0                
##  [89] DelayedArray_0.15.0         DBI_1.1.0                  
##  [91] pillar_1.4.3                foreign_0.8-79             
##  [93] survival_3.1-12             KEGGREST_1.29.0            
##  [95] RCurl_1.98-1.2              nnet_7.3-14                
##  [97] tibble_3.0.1                crayon_1.3.4               
##  [99] BiocFileCache_1.13.0        rmarkdown_2.1              
## [101] jpeg_0.1-8.1                progress_1.2.2             
## [103] data.table_1.12.8           blob_1.2.1                 
## [105] digest_0.6.25               xtable_1.8-4               
## [107] R.utils_2.9.2               openssl_1.4.1              
## [109] munsell_0.5.0               askpass_1.1