# dagLogo Vignette

#### Jianhong Ou, Lihua Julie Zhu

#### 24 April 2017

#### Abstract

A sequence logo has been widely used as a graphical representation of an alignment of multiple amino acid or nucleic acid sequences. dagLogo can visualize significant conserved amio acid sequence patterns in groups, such as charge, chemistry, hydrophobicity and etc.

#### Package version: dagLogo 1.14.0

# Contents

    ## Loading required package: biomaRt

    ## Loading required package: grImport

    ## Loading required package: grid

    ## Loading required package: XML

    ## Loading required package: motifStack

    ## Loading required package: MotIV

    ## Loading required package: BiocGenerics

    ## Loading required package: parallel

    ##
    ## Attaching package: 'BiocGenerics'

    ## The following objects are masked from 'package:parallel':
    ##
    ##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    ##     clusterExport, clusterMap, parApply, parCapply, parLapply,
    ##     parLapplyLB, parRapply, parSapply, parSapplyLB

    ## The following objects are masked from 'package:stats':
    ##
    ##     IQR, mad, sd, var, xtabs

    ## The following objects are masked from 'package:base':
    ##
    ##     Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    ##     as.data.frame, cbind, colMeans, colSums, colnames, do.call,
    ##     duplicated, eval, evalq, get, grep, grepl, intersect,
    ##     is.unsorted, lapply, lengths, mapply, match, mget, order,
    ##     paste, pmax, pmax.int, pmin, pmin.int, rank, rbind, rowMeans,
    ##     rowSums, rownames, sapply, setdiff, sort, table, tapply,
    ##     union, unique, unsplit, which, which.max, which.min

    ##
    ## Attaching package: 'MotIV'

    ## The following object is masked from 'package:stats':
    ##
    ##     filter

    ## Loading required package: ade4

    ##
    ## Attaching package: 'ade4'

    ## The following object is masked from 'package:BiocGenerics':
    ##
    ##     score

    ## Loading required package: Biostrings

    ## Loading required package: S4Vectors

    ## Loading required package: stats4

    ##
    ## Attaching package: 'S4Vectors'

    ## The following object is masked from 'package:base':
    ##
    ##     expand.grid

    ## Loading required package: IRanges

    ## Loading required package: XVector

    ##
    ## Attaching package: 'Biostrings'

    ## The following object is masked from 'package:base':
    ##
    ##     strsplit

# 1 introduction

A sequence logo has been widely used as a graphical representation of an alignment of multiple amino acid or nucleic acid sequences. There is a package seqlogo(Bembom 2006) implemented in R to draw DNA sequence logos. And another package motifStack(Ou 2012) was developed for drawing sequence logos for Amino Acid, DNA and RNA sequences. motifStack also has the capability for graphical representation of multiple motifs.

IceLogo(Colaert et al. 2009) is a tool developed in java to visualize significant conserved sequence patterns in an alignment of multiple peptide sequence against background sequences. Compare to webLogo(Crooks et al. 2004), which relying on information theory, iceLogo builds on probability theory. It is reported that iceLogo has a more dynamic nature and is correcter and completer in the analysis of conserved sequence patterns.

However iceLogo can only compare conserved sequences to reference sequences peptide by peptide. As we know, some conserved sequence patterns are not conserved by peptides but by groups such as charge, chemistry, hydrophobicity and etc.

Here we developed a R package:dagLogo based on iceLogo to visualize significant conserved sequence patterns in groups.

# 2 Prepare environment

You will need ghostscript: the full path to the executable can be set by the environment variable R_GSCMD. If this is unset, a GhostScript executable will be searched by name on your path. For example, on a Unix, linux or Mac “gs” is used for searching, and on Windows the setting of the environment variable GSC is used, otherwise commands “gswi64c.exe” then “gswin32c.exe” are tried.

Example on Windows: assume that the gswin32c.exe is installed at C:\ Program Files\ gs\ gs9.06\ bin, then open R and try:

    Sys.setenv(R_GSCMD=file.path("C:", "Program Files", "gs",
                                 "gs9.06", "bin", "gswin32c.exe"))

# 3 Examples of using dagLogo

## 3.1 Sample 1, start from given peptides positions

## 3.2 Step 1, fetch sequences

You should have interesting peptides position info and the identifiers for fetching sequences via biomaRt.

    library(dagLogo)
    library(biomaRt)
    try({##just in case biomaRt server does not response
        mart <- useMart("ensembl", "dmelanogaster_gene_ensembl")
        dat <- read.csv(system.file("extdata", "dagLogoTestData.csv",
                                    package="dagLogo"))
        dat <- dat[1:5,] ##subset to speed sample
        dat
        seq <- fetchSequence(as.character(dat$entrez_geneid),
                             anchorPos=as.character(dat$NCBI_site),
                             mart=mart,
                             upstreamOffset=7,
                             downstreamOffset=7)
        head(seq@peptides)
    })

    ##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
    ## [1,] "G"  "I"  "A"  "S"  "E"  "A"  "Q"  "K"  "Y"  "Q"   "A"   "K"   "I"
    ## [2,] "A"  "S"  "K"  "V"  "A"  "L"  "S"  "K"  "F"  "D"   "S"   "D"   "V"
    ## [3,] "Q"  "F"  "I"  "S"  "S"  "G"  "L"  "K"  "K"  "V"   "A"   "V"   "P"
    ## [4,] "G"  "R"  "C"  "A"  "S"  "I"  "A"  "K"  "D"  "A"   "M"   "S"   "H"
    ## [5,] "G"  "I"  "S"  "E"  "V"  "F"  "D"  "K"  "F"  "G"   "G"   "T"   "V"
    ##      [,14] [,15]
    ## [1,] "L"   "S"
    ## [2,] "Y"   "L"
    ## [3,] "S"   "T"
    ## [4,] "G"   "L"
    ## [5,] "L"   "A"

Sometimes you don’t have the exactly postions. You have only the interesting peptides and the identifiers.

    try({
        seq <- fetchSequence(as.character(dat$entrez_geneid),
                             anchorAA="*",
                             anchorPos=as.character(dat$peptide),
                             mart=mart,
                             upstreamOffset=7,
                             downstreamOffset=7)
        head(seq@peptides)
    })

    ##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
    ## [1,] "G"  "I"  "A"  "S"  "E"  "A"  "Q"  "K"  "Y"  "Q"   "A"   "K"   "I"
    ## [2,] "A"  "S"  "K"  "V"  "A"  "L"  "S"  "K"  "F"  "D"   "S"   "D"   "V"
    ## [3,] "Q"  "F"  "I"  "S"  "S"  "G"  "L"  "K"  "K"  "V"   "A"   "V"   "P"
    ## [4,] "G"  "R"  "C"  "A"  "S"  "I"  "A"  "K"  "D"  "A"   "M"   "S"   "H"
    ## [5,] "G"  "I"  "S"  "E"  "V"  "F"  "D"  "K"  "F"  "G"   "G"   "T"   "V"
    ##      [,14] [,15]
    ## [1,] "L"   "S"
    ## [2,] "Y"   "L"
    ## [3,] "S"   "T"
    ## [4,] "G"   "L"
    ## [5,] "L"   "A"

In above sample, anchorAA is represented by asterisk. In following sample, anchorAA is represented by lower case of amino acid.

    if(interactive()){
        dat <- read.csv(system.file("extdata", "peptides4dagLogo.csv",
                    package="dagLogo"))

        tail(dat)
        mart <- useMart("ensembl", "hsapiens_gene_ensembl")
        seq <- fetchSequence(toupper(as.character(dat$symbol)),
                             type="hgnc_symbol",
                             anchorAA="s",
                             anchorPos=as.character(dat$peptides),
                             mart=mart,
                             upstreamOffset=7,
                             downstreamOffset=7)
        head(seq@peptides)
    }

Sometimes you may already have the aligned peptides sequences in hand. You will use formatSequence function to prepare an object of dagPeptides for further testing. To use formatSequence, you need prepare the proteome by prepareProteome function.

    dat <- unlist(read.delim(system.file("extdata", "grB.txt", package="dagLogo"),
                             header=F, as.is=TRUE))
    head(dat)

    ##                              V11                              V12
    ## "GHISVKEPTPSIASDISLPIATQELRQRLR" "EREMFDKASLKLGLDKAVLQSMSGRENATN"
    ##                              V13                              V14
    ## "XXXXXXMSDIVVVTDLIAVGLKRGSDELLS" "GQDQEEEEIEDILMDTEEELMRAEDTEQLK"
    ##                              V15                              V16
    ## "ESYATDNEKMTSTPETLLEEIEAKNRELIA" "VENKERTLKRLLLQDQENSLQDNRTSSDSP"

    ##prepare proteome from a fasta file
    proteome <- prepareProteome(fasta=system.file("extdata",
                                                  "HUMAN.fasta",
                                                  package="dagLogo"))
    ##prepare object of dagPeptides
    seq <- formatSequence(seq=dat, proteome=proteome,
                          upstreamOffset=14, downstreamOffset=15)

## 3.3 Step 2, build background model

Once you have an object of dagPeptides in hand, you can start to build background model for DAG test. The background could be random subsequence of whole proteome or your inputs. If the background was built from whole proteome or proteome without your inputs, an object of Proteome is required.

To prepare a proteome, there are two methods, from a fasta file or from UniProt webservice. Last example shows how to prepare proteome from a fasta file. Here we show how to prepare proteome via UniProt webservice.

    if(interactive()){
        library(UniProt.ws)
        UniProt.ws <- UniProt.ws(taxId=9606)
        proteome <- prepareProteome(UniProt.ws=UniProt.ws)
    }

Then the proteome can be used for background model building.

    bg <- buildBackgroundModel(seq, bg="wholeGenome", proteome=proteome)

## 3.4 Step 3, do test

Test can be done without any change of the symbol pattern or with changes of grouped peptides by such as charge, chemistry, hydrophobicity and etc.

    t0 <- testDAU(seq, bg)
    t1 <- testDAU(seq, bg, group="classic")
    t2 <- testDAU(seq, bg, group="charge")
    t3 <- testDAU(seq, bg, group="chemistry")
    t4 <- testDAU(seq, bg, group="hydrophobicity")

## 3.5 Step 4, graphical representation results

We can use heatmap or logo to show the results.

    dagHeatmap(t0) ##Plot a heatmap to show the results

    dagLogo(t0) ##Plot a logo to show the ungrouped results

    ##Plot a logo to show the classic grouped results
    dagLogo(t1, namehash=nameHash(t1@group), legend=TRUE)

    ##Plot a logo to show the charge grouped results
    dagLogo(t2, namehash=nameHash(t2@group), legend=TRUE)

    ##Plot a logo to show the chemistry grouped results
    dagLogo(t3, namehash=nameHash(t3@group), legend=TRUE)

    ##Plot a logo to show the hydrophobicity grouped results
    dagLogo(t4, namehash=nameHash(t4@group), legend=TRUE)

# 4 using dagLogo to analysis Catobolite Activator Protein

CAP (Catabolite Activator Protein, also known as CRP for cAMP Receptor Protein) is a transcription promoter that binds at more than 100 sites within the E. coli genome.

The motif of the DNA-binding helix-turn-helix motif of the CAP family is drawn by motifStack as following figure.

    library(motifStack)
    protein<-read.table(file.path(find.package("motifStack"),"extdata","cap.txt"))
    protein<-t(protein[,1:20])
    motif<-pcm2pfm(protein)
    motif<-new("pfm", mat=motif, name="CAP",
                color=colorset(alphabet="AA",colorScheme="chemistry"))
    ##The DNA-binding helix-turn-helix motif of the CAP family ploted by motifStack
    plot(motif)

If we use dagLogo to plot the motif, it will be shown as following figure. Residues 7-13 form the first helix, 14-17 the turn and 18-26 the DNA recognition helix. The glycine at position 15 appears to be critical in forming the turn.

    library(Biostrings)
    cap <- as.character(readAAStringSet(system.file("extdata",
                                                    "cap.fasta",
                                                    package="dagLogo")))
    data(ecoli.proteome)
    seq <- formatSequence(seq=cap, proteome=ecoli.proteome)
    bg <- buildBackgroundModel(seq, bg="wholeGenome",
                               proteome=ecoli.proteome,
                               permutationSize=10L)
    ##The DNA-binding helix-turn-helix motif of the CAP family ploted by dagLogo
    t0 <- testDAU(seq, bg)
    dagLogo(t0)

If the peptides are grouped by chemistry and then plot, it will be shown as following figure. Positions 10, 14, 16, 21 and 25 are partially or completely buried and therefore tend to be populated by hydrophobic amino acids, which are very clear if we group the peptides by chemistry.

    ## The DNA-binding helix-turn-helix motif of the CAP family grouped by chemistry
    t1 <- testDAU(seq, bg, group="chemistry")
    dagLogo(t1, namehash=nameHash(t1@group), legend=TRUE)

# 5 Session Info

    sessionInfo()

    ## R version 3.4.0 (2017-04-21)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server 2012 R2 x64 (build 9600)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.1252
    ## [3] LC_MONETARY=English_United States.1252
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.1252
    ##
    ## attached base packages:
    ##  [1] stats4    parallel  grid      stats     graphics  grDevices utils
    ##  [8] datasets  methods   base
    ##
    ## other attached packages:
    ##  [1] dagLogo_1.14.0      motifStack_1.20.0   Biostrings_2.44.0
    ##  [4] XVector_0.16.0      IRanges_2.10.0      S4Vectors_0.14.0
    ##  [7] ade4_1.7-6          MotIV_1.32.0        BiocGenerics_0.22.0
    ## [10] grImport_0.9-0      XML_3.98-1.6        biomaRt_2.32.0
    ## [13] BiocStyle_2.4.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] SummarizedExperiment_1.6.0 lattice_0.20-35
    ##  [3] colorspace_1.3-2           htmltools_0.3.5
    ##  [5] rtracklayer_1.36.0         yaml_2.1.14
    ##  [7] DBI_0.6-1                  BiocParallel_1.10.0
    ##  [9] RColorBrewer_1.1-2         matrixStats_0.52.2
    ## [11] GenomeInfoDbData_0.99.0    plyr_1.8.4
    ## [13] stringr_1.2.0              zlibbioc_1.22.0
    ## [15] munsell_0.4.3              gtable_0.2.0
    ## [17] htmlwidgets_0.8            memoise_1.1.0
    ## [19] evaluate_0.10              Biobase_2.36.0
    ## [21] knitr_1.15.1               GenomeInfoDb_1.12.0
    ## [23] AnnotationDbi_1.38.0       highr_0.6
    ## [25] Rcpp_0.12.10               backports_1.0.5
    ## [27] scales_0.4.1               rGADEM_2.24.0
    ## [29] BSgenome_1.44.0            seqLogo_1.42.0
    ## [31] DelayedArray_0.2.0         Rsamtools_1.28.0
    ## [33] digest_0.6.12              stringi_1.1.5
    ## [35] GenomicRanges_1.28.0       rprojroot_1.2
    ## [37] tools_3.4.0                bitops_1.0-6
    ## [39] magrittr_1.5               RCurl_1.95-4.8
    ## [41] RSQLite_1.1-2              pheatmap_1.0.8
    ## [43] Matrix_1.2-9               rmarkdown_1.4
    ## [45] GenomicAlignments_1.12.0   compiler_3.4.0

Bembom, Oliver. 2006. “SeqLogo: Sequence Logos for Dna Sequence Alignments.” R Package Version 1.5.4.

Colaert, Niklaas, Kenny Helsens, Lennart Martens, Joel Vandekerckhove, and Kris Gevaert. 2009. “Improved Visualization of Protein Consensus Sequences by IceLogo.” Nature Methods 6 (11): 786–87.

Crooks, Gavin E., Gary Hon, John-Marc Chandonia, and Steven E. Brenner. 2004. “WebLogo: A Sequence Logo Generator.” Genome Research 14: 1188–90.

Ou, Jianhong. 2012. “MotifStack: Plot Stacked Logos for Single or Multiple Dna, Rna and Amino Acid Sequence.” R Package Version 1.5.4.