Counting with summarizeoverlaps

Similar documents
Package roar. August 31, 2018

Practical: Read Counting in RNA-seq

Handling genomic data using Bioconductor II: GenomicRanges and GenomicFeatures

Ranges (and Data Integration)

Package GenomicAlignments

Working with aligned nucleotides (WORK- IN-PROGRESS!)

de.nbi and its Galaxy interface for RNA-Seq

Using the Streamer classes to count genomic overlaps with summarizeoverlaps

A quick introduction to GRanges and GRangesList objects

IRanges and GenomicRanges An introduction

Building and Using Ensembl Based Annotation Packages with ensembldb

10 things (maybe) you didn t know about GenomicRanges, Biostrings, and Rsamtools

Analyzing RNA-seq data for differential exon usage with the DEXSeq package

The QoRTs Analysis Pipeline Example Walkthrough

Range-based containers in Bioconductor

Introduction to GenomicFiles

Useful software utilities for computational genomics. Shamith Samarajiwa CRUK Autumn School in Bioinformatics September 2017

Using the GenomicFeatures package

The software and data for the RNA-Seq exercise are already available on the USB system

Working with ChIP-Seq Data in R/Bioconductor

segmentseq: methods for detecting methylation loci and differential methylation

Introduction to RNA-seq Analysis

Exercise 1 Review. --outfiltermismatchnmax : max number of mismatch (Default 10) --outreadsunmapped fastx: output unmapped reads

m6aviewer Version Documentation

Identify differential APA usage from RNA-seq alignments

TP RNA-seq : Differential expression analysis

segmentseq: methods for detecting methylation loci and differential methylation

Exercise 2: Browser-Based Annotation and RNA-Seq Data

Bioconductor packages for short read analyses

Package easyrnaseq. November 11, 2017

The rtracklayer package

Package customprodb. September 9, 2018

Exercises: Analysing RNA-Seq data

Package GenomicRanges

Generating and using Ensembl based annotation packages

JunctionSeq Package User Manual

Inferring differential exon usage in RNA-Seq data with the DEXSeq package

Package Rsamtools. April 12, 2018

Outline Introduction Sequences Ranges Views Interval Datasets. IRanges. Bioconductor Infrastructure for Sequence Analysis.

RNA-Seq Analysis With the Tuxedo Suite

JunctionSeq Package User Manual

JunctionSeq Package User Manual

Package CAGEr. September 4, 2018

Gene and Genome Annotation Resources in Bioconductor

Managing and analyzing multiple NGS samples with Bioconductor bamviews objects: application to RNA-seq

Annotation resources - ensembldb

Visualisation, transformations and arithmetic operations for grouped genomic intervals

Lecture 12. Short read aligners

Representing sequencing data in Bioconductor

Package DMCHMM. January 19, 2019

featuredb storing and querying genomic annotation

Sequence Analysis Pipeline

An Introduction to VariantTools

Package Rsubread. July 21, 2013

PICS: Probabilistic Inference for ChIP-Seq

ChIP-seq (NGS) Data Formats

Wilson Leung 01/03/2018 An Introduction to NCBI BLAST. Prerequisites: Detecting and Interpreting Genetic Homology: Lecture Notes on Alignment

Package MIRA. October 16, 2018

Package DASiR. R topics documented: October 4, Type Package. Title Distributed Annotation System in R. Version

Package metagene. November 1, 2018

BovineMine Documentation

Standard output. Some of the output files can be redirected into the standard output, which may facilitate in creating the pipelines:

ITMO Ecole de Bioinformatique Hands-on session: smallrna-seq N. Servant 21 rd November 2013

ExomeDepth. Vincent Plagnol. May 15, What is new? 1. 4 Load an example dataset 4. 6 CNV calling 5. 9 Visual display 9

riboseqr Introduction Getting Data Workflow Example Thomas J. Hardcastle, Betty Y.W. Chung October 30, 2017

Rsubread package: high-performance read alignment, quantification and mutation discovery

version /1/2011 Source code Linux x86_64 binary Mac OS X x86_64 binary

Relationship Between BED and WIG Formats

Package HTSeqGenie. April 16, 2019

Prepare input data for CINdex

Wilson Leung 05/27/2008 A Simple Introduction to NCBI BLAST

ChIP-seq hands-on practical using Galaxy

subseq Package Vignette (Version )

Tutorial. RNA-Seq Analysis of Breast Cancer Data. Sample to Insight. November 21, 2017

Package TnT. November 22, 2017

An Introduction to the GenomicRanges Package

High-throughout sequencing and using short-read aligners. Simon Anders

pyensembl Documentation

Miniproject 1. Part 1 Due: 16 February. The coverage problem. Method. Why it is hard. Data. Task1

RNA-Seq data analysis software. User Guide 023UG050V0100

Differential gene expression analysis

Part 1: How to use IGV to visualize variants

Tutorial: RNA-Seq Analysis Part II (Tracks): Non-Specific Matches, Mapping Modes and Expression measures

Package FunciSNP. November 16, 2018

Package ensemblvep. April 5, 2014

High-level S4 containers for HTS data

Package SGSeq. December 31, 2018

Package TxRegInfra. March 17, 2019

ChIP-seq practical: peak detection and peak annotation. Mali Salmon-Divon Remco Loos Myrto Kostadima

Package DNaseR. November 1, 2013

Rsubread package: high-performance read alignment, quantification and mutation discovery

Making and Utilizing TxDb Objects

Package TFutils. October 11, 2018

Package dmrseq. September 14, 2018

Protocol: peak-calling for ChIP-seq data / segmentation analysis for histone modification data

Advanced UCSC Browser Functions

Goal: Learn how to use various tool to extract information from RNAseq reads.

High-throughput sequencing: Alignment and related topic. Simon Anders EMBL Heidelberg

Package seqcat. March 25, 2019

The QoRTs Analysis Pipeline Example Walkthrough

Transcription:

Counting with summarizeoverlaps Valerie Obenchain Edited: August 2012; Compiled: August 23, 2013 Contents 1 Introduction 1 2 A First Example 1 3 Counting Modes 2 4 Counting Features 3 5 pasilla Data 6 5.1 source files............................... 6 5.2 counting................................ 7 6 Refererences 8 1 Introduction This vignette illustrates how s mapped to a genome can be counted with summarizeoverlaps. Different modes of counting are provided to resolve s that overlap multiple features. The built-in count modes are fashioned after the Union, IntersectionStrict, and IntersectionNotEmpty methods found in the HTSeq package by Simon Anders (see references). 2 A First Example In this example s are counted from a list of BAM files and returned in a matrix for use in further analysis such as those offered in DESeq and edger. > library(rsamtools) > library(deseq) > library(edger) > fls <- list.files(system.file("extdata",package="genomicranges"), + recursive=true, pattern="*bam$", full=true) 1

> bfl <- BamFileList(fls, index=character()) > features <- GRanges( + seqnames = c(rep("chr2l", 4), rep("chr2r", 5), rep("chr3l", 2)), + ranges = IRanges(c(1000, 3000, 4000, 7000, 2000, 3000, 3600, 4000, + 7500, 5000, 5400), width=c(rep(500, 3), 600, 900, 500, 300, 900, + 300, 500, 500)), "-", + group_id=c(rep("a", 4), rep("b", 5), rep("c", 2))) > olap <- summarizeoverlaps(features, bfl) > deseq <- newcountdataset(assays(olap)$counts, rownames(coldata(olap))) > edger <- DGEList(assays(olap)$counts, group=rownames(coldata(olap))) 3 Counting Modes The modes of Union, IntersectionStrict and IntersectionNotEmpty provide different approaches to resolving s that overlap multiple features. Figure 1 illustrates how both simple and gapped s are handled by the modes. Note that a is counted a maximum of once; there is no double counting. These methods do not currently handle paired-end s. For additional detail on the counting modes see the summarizeoverlaps man page. 2

Union IntersectionStrict IntersectionNotEmpty Feature I Feature I Feature I Feature I No hit Feature I Feature I No hit Feature I Feature I Feature I Feature I Feature I Feature I Feature I Feature 2 No hit Feature I Feature 2 No hit No hit No hit Feature 2 * Picture reproduced from HTSeq web site : http://www-huber.embl.de/users/anders/htseq/doc/count.html Figure 1: Counting Modes 4 Counting Features Features can be exons, transcripts, genes or any region of interest. The number of ranges that define a single feature is specified in the features argument. When annotation regions of interest are defined by a single range a GRanges should be used as the features argument. With a GRanges it is assumed that each row (i.e., each range) represents a distinct feature. If features was a GRanges of exons, the result would be counts per exon. When the region of interest is defined by one or more ranges the features argument should be a GRangesList. In practice this could be a list of exons by gene or transcripts by gene or other similar relationships. The count result will 3

be the same length as the GRangesList. For a list of exons by genes, the result would be counts per gene. The combination of defining the features as eithergranges or GRangesList and choosing a counting mode controls how summarizeoverlaps assigns hits. Reguardless of the mode chosen, each is assigned to at most a single feature. These options are intended to provide flexibility in defining different biological problems. This next example demonstrates how the same can be counted differently depending on how the features argument is specified. We use a single that overlaps two ranges, gr1 and gr2. > rd <- GappedAlignments("a", seqnames = Rle("chr1"), pos = as.integer(100), + cigar = "300M", strand = strand("+")) > gr1 <- GRanges("chr1", IRanges(start=50, width=150), strand="+") > gr2 <- GRanges("chr1", IRanges(start=350, width=150), strand="+") When provided as a GRanges both gr1 and gr2 are considered distinct features. In this case none of the modes count the as a hit. Mode Union discards the becasue more than 1 feature is overlapped. IntersectionStrict requires the to fall completely within a feature which is not the case for either gr1 or gr2. IntersetctionNotEmpty requires the to overlap a single unique disjoint region of the features. In this case gr1 and gr2 do not overlap so each range is considered a unique disjoint region. However, the overlaps both gr1 and gr2 so a decision cannot be made and the is discarded. > gr <- c(gr1, gr2) > data.frame(union = assays(summarizeoverlaps(gr, rd))$counts, + intstrict = assays(summarizeoverlaps(gr, rd, + mode="intersectionstrict"))$counts, + intnotempty = assays(summarizeoverlaps(gr, rd, + mode="intersectionnotempty"))$counts) union intstrict intnotempty 1 0 0 0 2 0 0 0 Next we count with features as a GRangesList; this is list of length 1 with 2 elements. Modes Union and IntersectionNotEmpty both count the for the single feature. > grl <- GRangesList(c(gr1, gr2)) > data.frame(union = assays(summarizeoverlaps(grl, rd))$counts, + intstrict = assays(summarizeoverlaps(grl, rd, + mode="intersectionstrict"))$counts, + intnotempty = assays(summarizeoverlaps(grl, rd, + mode="intersectionnotempty"))$counts) union intstrict intnotempty 1 1 0 1 4

In this more complicated example we have 7 s, 5 are simple and 2 have gaps in the CIGAR. There are 12 ranges that will serve as the features. > group_id <- c("a", "B", "C", "C", "D", "D", "E", "F", "G", "G", "H", "H") > features <- GRanges( + seqnames = Rle(c("chr1", "chr2", "chr1", "chr1", "chr2", "chr2", + "chr1", "chr1", "chr2", "chr2", "chr1", "chr1")), + strand = strand(rep("+", length(group_id))), + ranges = IRanges( + start=c(1000, 2000, 3000, 3600, 7000, 7500, 4000, 4000, 3000, 3350, 5000, 5400), + width=c(500, 900, 500, 300, 600, 300, 500, 900, 150, 200, 500, 500)), + DataFrame(group_id) + ) > s <- GappedAlignments( + names = c("a","b","c","d","e","f","g"), + seqnames = Rle(c(rep(c("chr1", "chr2"), 3), "chr1")), + pos = as.integer(c(1400, 2700, 3400, 7100, 4000, 3100, 5200)), + cigar = c("500m", "100M", "300M", "500M", "300M", "50M200N50M", "50M150N50M"), + strand = strand(rep.int("+", 7L))) > Using a GRanges as the features all 12 ranges are considered to be different features and counts are produced for each row, > data.frame(union = assays(summarizeoverlaps(features, s))$counts, + intstrict = assays(summarizeoverlaps(features, s, + mode="intersectionstrict"))$counts, + intnotempty = assays(summarizeoverlaps(features, s, + mode="intersectionnotempty"))$counts) union intstrict intnotempty 1 1 0 1 2 1 1 1 3 0 0 0 4 0 0 0 5 0 1 1 6 0 0 0 7 0 0 0 8 0 0 0 9 0 0 0 10 0 0 0 11 0 1 1 12 0 0 0 When the data are split by group to create a GRangesList the highest list-levels are treated as different features and the multiple list elements are considered part of the same features. Counts are returned for each group. 5

> lst <- split(features, mcols(features)[["group_id"]]) > length(lst) [1] 8 > data.frame(union = assays(summarizeoverlaps(lst, s))$counts, + intstrict = assays(summarizeoverlaps(lst, s, + mode="intersectionstrict"))$counts, + intnotempty = assays(summarizeoverlaps(lst, s, + mode="intersectionnotempty"))$counts) union intstrict intnotempty A 1 0 1 B 1 1 1 C 1 0 1 D 1 1 1 E 0 0 0 F 0 0 0 G 1 1 1 H 1 1 1 If desired, users can supply their own counting function as the mode argument and take advantage of the infrastructure for counting over multiple BAM files and parsing the results into a SummarizedExperiment. See? BamViews-class or? BamFile-class in Rsamtools. 5 pasilla Data In this excercise we count the pasilla data by gene and by transcript then create a CountDataSet. This object can be used in differential expression methods offered in the DESeq package. 5.1 source files Files are available through NCBI Gene Expression Omnibus (GEO), accession number GSE18508. http://www.ncbi.nlm.nih.gov/projects/geo/query/acc. cgi?acc=gse18508. SAM files can be converted to BAM with the asbam function in the Rsamtools package. Of the seven files available, 3 are single-s and 4 are paired-end. Smaller versions of untreated1 (single-end) and untreated2 (paired-end) have been made available in the pasillabamsubset package. This subset includes chromosome 4 only. summarizeoverlaps is capable of counting paired-end s in both a Bam- File-method (set argument singleend=true) or a GappedAlignmentPairsmethod. For this example, we use the 3 single-end files, ˆ treated1.bam 6

ˆ untreated1.bam ˆ untreated2.bam Annotations are retrieved as a GTF file from the ENSEMBL web site. We download the file our local disk, then use Rtracklayer s import function to parse the file to a GRanges instance. > library(rtracklayer) > fl <- paste0("ftp://ftp.ensembl.org/pub/release-62/", + "gtf/drosophila_melanogaster/", + "Drosophila_melanogaster.BDGP5.25.62.gtf.gz") > gfffile <- file.path(tempdir(), basename(fl)) > download.file(fl, gfffile) > gff0 <- import(gfffile, asrangeddata=false) Subset on the protein-coding, exon regions of chromosome 4 and split by gene id. > idx <- mcols(gff0)$source == "protein_coding" & + mcols(gff0)$type == "exon" & + seqnames(gff0) == "4" > gff <- gff0[idx] > ## adjust seqnames to match Bam files > seqlevels(gff) <- paste("chr", seqlevels(gff), sep="") > chr4genes <- split(gff, mcols(gff)$gene_id) 5.2 counting The params argument can be used to subset the s in the bam file on characteristics such as position, unmapped or paired-end s. Quality scores or the NH tag, which identifies s with multiple mappings, can be included as metadata columns for further subsetting. See?ScanBamParam for details about specifying the param argument. > param <- ScanBamParam( + what='qual', + which=granges("chr4", IRanges(1, 1e6)), + flag=scanbamflag(isunmappedquery=false, ispaired=na), + tag="nh") We use summarizeoverlaps to count with the default mode of Union. If a param argument is not included all s from the BAM file are counted. > fls <- c("treated1.bam", "untreated1.bam", "untreated2.bam") > path <- "pathtobamfiles" > bamlst <- BamFileList(fls, index=character()) > genehits <- summarizeoverlaps(chr4genes, bamlst, mode="union") A CountDataSet is constructed from the counts and experiment data in pasilla. 7

> expdata = new("miame", + name="pasilla knockdown", + lab="genetics and Developmental Biology, University of + Connecticut Health Center", + contact="dr. Brenton Graveley", + title="modencode Drosophila pasilla RNA Binding Protein RNAi + knockdown RNA-Seq Studies", + url="http://www.ncbi.nlm.nih.gov/projects/geo/query/acc.cgi?acc=gse18508", + abstract="rna-seq of 3 biological replicates of from the Drosophila + melanogaster S2-DRSC cells that have been RNAi depleted of mrnas + encoding pasilla, a mrna binding protein and 4 biological replicates + of the the untreated cell line.") > pubmedids(expdata) <- "20921232" > design <- data.frame( + condition=c("treated", "untreated", "untreated"), + replicate=c(1,1,2), + type=rep("single-", 3), + countfiles=path(coldata(genehits)[,1]), stringsasfactors=true) > genecds <- newcountdataset( + countdata=assays(genehits)$counts, + conditions=design) > experimentdata(genecds) <- expdata > samplenames(genecds) = colnames(genehits) If the primary interest is to count by transcript instead of by gene, the annotation file can be split on transcript id. > chr4tx <- split(gff, mcols(gff)$transcript_id) > txhits <- summarizeoverlaps(chr4tx, bamlst) > txcds <- newcountdataset(assays(txhits)$counts, design) > experimentdata(txcds) <- expdata 6 Refererences http://www-huber.embl.de/users/anders/htseq/doc/overview.html http: //www-huber.embl.de/users/anders/htseq/doc/count.html 8