%\VignetteIndexEntry{segmentSeq} %\VignettePackage{segmentSeq} \documentclass[a4paper]{article} \usepackage{rotating} \title{segmentSeq: methods for identifying small RNA loci from high-throughput sequencing data} \author{Thomas J. Hardcastle} \begin{document} \maketitle \section{Introduction} High-throughput sequencing technologies allow the production of large volumes of short sequences, which can be aligned to the genome to create a set of \textsl{matches} to the genome. By looking for regions of the genome which to which there are high densities of matches, we can infer a segmentation of the genome into regions of biological significance. The methods we propose allows the simultaneous segmentation of data from multiple samples, taking into account replicate data, in order to create a consensus segmentation. This has obvious applications in a number of classes of sequencing experiments, particularly in the discovery of small RNA loci and novel mRNA transcriptome discovery. We approach the problem by considering a large set of potential \textsl{segments} upon the genome and counting the number of tags that match to that segment in multiple sequencing experiments (that may or may not contain replication). We then adapt the empirical Bayesian methods based on the Poisson-Gamma conjugacy and implemented in the \verb'baySeq' package \cite{Hardcastle:2010} to establish, for a given segment, the likelihood that the count data in that segment is similar to background levels, or that it is similar to the regions to the left or right of that segment. We then rank all the potential segments in order of increasing likelihood of similarity and reject those segments for which there is a high likelihood of similarity with the background or the regions to the left or right of the segment. This gives us a large list of overlapping segments. We reduce this list to identify non-overlapping loci by choosing, for a set of overlapping segments, the segment which has the lowest likelihood of similarity with either background or the regions to the left or right of that segment and rejecting all other segments that overlap with this segment. For fuller details of the method, see Hardcastle (2010) \cite{Hardcastle:2010a}. \section{Preparation} We begin by loading the \verb'segmentSeq' package. <<>>= library(segmentSeq) @ Note that because the experiments that \verb'segmentSeq' is designed to analyse are usually massive, we should use (if possible) parallel processing as implemented by the \verb'snow' package. We therefore need to load the \verb'snow' package (if it exists) and define a \textsl{cluster}. <>= library(snow) cl <- makeCluster(7, "MPI") @ If \verb'snow' is not present, we can proceed anyway with a \verb'NULL' cluster. Results may be slightly different depending on whether or not a cluster is used owing to the non-deterministic elements of the method. <>= cl <- NULL @ There is a convenience function, \verb'processTags' which is able to read in tab-delimited files which have appropriate column names, and create an \verb'alignmentData' object. Alternatively, if the appropriate column names are not present, we can specify which columns to use for the data. In either case, we pass a character vector of files, together with information on which data are to be treated as replicates to the function. We also need to define the lengths of the chromosome and specifiy the chromosome names as a character. The data here, drawn from text files in the 'data' directory of the \verb'segmentSeq' package are taken from the first million bases of an alignment to chromosome 1 and the first five hundred thousand bases of an alignment to chromosome 2 of \textsl{Arabidopsis thaliana} in a sequencing experiment where libraries 'SL9' and 'SL10' are replicates, as are 'SL26' and 'SL32'. <<>>= chrlens <- c(1e6, 5e5) datadir <- system.file("extdata", package = "segmentSeq") libfiles <- c("SL9.txt", "SL10.txt", "SL26.txt", "SL32.txt") libnames <- c("SL9", "SL10", "SL26", "SL32") replicates <- c(1,1,2,2) aD <- processTags(libfiles, dir = datadir, replicates, libnames, chrlens, chrs = c(">Chr1", ">Chr2"), header = TRUE, gap = 200) aD @ Next, we process this \verb'alignmentData' object to produce a \verb'segData' object. This \verb'segData' object contains a set of potential segments on the genome defined by the start and end points of regions of overlapping alignments in the \verb'alignmentData' object. It then evaluates the number of tags that hit in each of these segments. <<>>= sD <- processAD(aD, cl = cl) sD @ We can now construct a segment map from these potential segments. \subsection*{Segmentation by Clustering} A fast method of segmentation can be achieved by exploiting the bimodality of the densities of small RNAs in the potential segments. In this approach, we assign each potential segment to one of two clusters for each replicate group, either as a segment or a null based on the density of sequence tags within that segment. We then combine these clusterings for each replicate group to gain a consensus segmentation map. <<>>= clustSegs <- heuristicSeg(sD = sD, aD = aD, bimodality = TRUE, getLikes = TRUE, cl = cl) clustSegs @ \subsection*{Segmentation by Classification} A more refined approach to the problem uses an existing segment map (or, if not provided, a segment map defined by the \verb'clustSegs' function) to acquire empirical distributions on the density of sequence tags within a segment. We can then estimate posterior likelihoods for each potential segment as being either a true segment or a null. We then identifying all potential segments in the with a posterior likelihood of being a segment greater than some value 'locsens' and containing no subregion with a posterior likelihood of being a null greater than 'nulsens'. We then greedily select the longest segments satisfying these criteria that do not overlap with any other such segments in defining our segmentation map. <<>>= classSegs <- classifySeg(sD = sD, aD = aD, cD = clustSegs, subRegion = NULL, getLikes = TRUE, cl = cl, lociCutoff = 0.9, nullCutoff = 0.9) classSegs @ By one of these methods, we finally acquire an annotated \verb'countData' object, with the annotations describing the co-ordinates of each segment. We can use this \verb'countData' object, in combination with the \verb'alignmentData' object, to plot the segmented genome. <>= par(mfrow = c(2,1), mar = c(2,2,2,2)) plotGenome(aD, clustSegs, chr = ">Chr1", limits = c(1, 3e5)) plotGenome(aD, classSegs, chr = ">Chr1", limits = c(1, 3e5)) @ \begin{sidewaysfigure}[!ht] \begin{center} <>= <> @ \caption{The segmented genome (first $10^5$ bases of chromosome 1.} \label{fig:Seg} \end{center} \end{sidewaysfigure} This \verb'countData' object can now be examined for differential expression with the \verb'baySeq' package. \begin{thebibliography}{99} \bibitem{Hardcastle:2010} Thomas J. Hardcastle and Krystyna A. Kelly. \textsl{Empirical Bayesian Methods For Identifying Patterns of Differential Expression in Count Data}. In submission. 2010. \bibitem{Hardcastle:2010a} Thomas J. Hardcastle and Krystyna A. Kelly. \textsl{Genome Segmentation From High-Throughput Sequencing Data.}. In preparation. 2010. \end{thebibliography} \end{document}