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.4.0 beta (2024-04-15 r86425)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [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       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] grid      stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] Gviz_1.48.0                         BSgenome.Ggallus.UCSC.galGal3_1.4.0
##  [3] BSgenome.Hsapiens.UCSC.hg19_1.4.3   BSgenome_1.72.0                    
##  [5] rtracklayer_1.64.0                  BiocIO_1.14.0                      
##  [7] Biostrings_2.72.0                   XVector_0.44.0                     
##  [9] GenomicRanges_1.56.0                GenomeInfoDb_1.40.0                
## [11] IRanges_2.38.0                      S4Vectors_0.42.0                   
## [13] BiocGenerics_0.50.0                 CNEr_1.40.0                        
## [15] BiocStyle_2.32.0                   
## 
## loaded via a namespace (and not attached):
##   [1] RColorBrewer_1.1-3          rstudioapi_0.16.0          
##   [3] jsonlite_1.8.8              magrittr_2.0.3             
##   [5] GenomicFeatures_1.56.0      magick_2.8.3               
##   [7] farver_2.1.1                rmarkdown_2.26             
##   [9] zlibbioc_1.50.0             vctrs_0.6.5                
##  [11] memoise_2.0.1               Rsamtools_2.20.0           
##  [13] RCurl_1.98-1.14             base64enc_0.1-3            
##  [15] tinytex_0.50                htmltools_0.5.8.1          
##  [17] S4Arrays_1.4.0              progress_1.2.3             
##  [19] curl_5.2.1                  SparseArray_1.4.0          
##  [21] Formula_1.2-5               sass_0.4.9                 
##  [23] pracma_2.4.4                bslib_0.7.0                
##  [25] htmlwidgets_1.6.4           plyr_1.8.9                 
##  [27] httr2_1.0.1                 cachem_1.0.8               
##  [29] GenomicAlignments_1.40.0    lifecycle_1.0.4            
##  [31] pkgconfig_2.0.3             Matrix_1.7-0               
##  [33] R6_2.5.1                    fastmap_1.1.1              
##  [35] GenomeInfoDbData_1.2.12     MatrixGenerics_1.16.0      
##  [37] digest_0.6.35               colorspace_2.1-0           
##  [39] AnnotationDbi_1.66.0        Hmisc_5.1-2                
##  [41] RSQLite_2.3.6               filelock_1.0.3             
##  [43] labeling_0.4.3              fansi_1.0.6                
##  [45] httr_1.4.7                  abind_1.4-5                
##  [47] compiler_4.4.0              bit64_4.0.5                
##  [49] withr_3.0.0                 backports_1.4.1            
##  [51] htmlTable_2.4.2             BiocParallel_1.38.0        
##  [53] DBI_1.2.2                   highr_0.10                 
##  [55] R.utils_2.12.3              biomaRt_2.60.0             
##  [57] rappdirs_0.3.3              poweRlaw_0.80.0            
##  [59] DelayedArray_0.30.0         rjson_0.2.21               
##  [61] tools_4.4.0                 foreign_0.8-86             
##  [63] nnet_7.3-19                 R.oo_1.26.0                
##  [65] glue_1.7.0                  restfulr_0.0.15            
##  [67] checkmate_2.3.1             cluster_2.1.6              
##  [69] reshape2_1.4.4              generics_0.1.3             
##  [71] gtable_0.3.5                tzdb_0.4.0                 
##  [73] R.methodsS3_1.8.2           ensembldb_2.28.0           
##  [75] data.table_1.15.4           hms_1.1.3                  
##  [77] xml2_1.3.6                  utf8_1.2.4                 
##  [79] pillar_1.9.0                stringr_1.5.1              
##  [81] vroom_1.6.5                 dplyr_1.1.4                
##  [83] BiocFileCache_2.12.0        lattice_0.22-6             
##  [85] deldir_2.0-4                bit_4.0.5                  
##  [87] annotate_1.82.0             biovizBase_1.52.0          
##  [89] tidyselect_1.2.1            GO.db_3.19.1               
##  [91] knitr_1.46                  gridExtra_2.3              
##  [93] bookdown_0.39               ProtGenerics_1.36.0        
##  [95] SummarizedExperiment_1.34.0 xfun_0.43                  
##  [97] Biobase_2.64.0              matrixStats_1.3.0          
##  [99] stringi_1.8.3               UCSC.utils_1.0.0           
## [101] lazyeval_0.2.2              yaml_2.3.8                 
## [103] evaluate_0.23               codetools_0.2-20           
## [105] interp_1.1-6                archive_1.1.8              
## [107] tibble_3.2.1                BiocManager_1.30.22        
## [109] cli_3.6.2                   rpart_4.1.23               
## [111] xtable_1.8-4                munsell_0.5.1              
## [113] jquerylib_0.1.4             dichromat_2.0-0.1          
## [115] Rcpp_1.0.12                 dbplyr_2.5.0               
## [117] png_0.1-8                   XML_3.99-0.16.1            
## [119] parallel_4.4.0              ggplot2_3.5.1              
## [121] readr_2.1.5                 blob_1.2.4                 
## [123] prettyunits_1.2.0           jpeg_0.1-10                
## [125] latticeExtra_0.6-30         AnnotationFilter_1.28.0    
## [127] bitops_1.0-7                pwalign_1.0.0              
## [129] VariantAnnotation_1.50.0    scales_1.3.0               
## [131] crayon_1.5.2                rlang_1.1.3                
## [133] KEGGREST_1.44.0