├── DRB-TTseq.html
├── DRB_TT-seq.md
├── LICENSE
├── README.md
├── align.md
├── bigwig.md
├── bigwig_bedtools.md
├── data
├── README.md
└── chrom.sizes.txt
├── metaprofiles.md
└── scripts
├── DRB-TTseq.R
├── DRB-TTseq.Rmd
├── align.sh
├── bigwig.sh
├── bigwig_bedtools.sh
└── metaprofiles.sh
/DRB_TT-seq.md:
--------------------------------------------------------------------------------
1 | This is a companion script to the publication below. It describes a pipeline for calling RNA Pol II transcription wave peak positions and elongation rates from DRB/TT-seq time-series data using R. Instructions are given for calculating wave peaks at both the single-gene and meta-gene level.
2 |
3 |
4 | *Nascent transcriptome profiles and measurement of transcription elongation using TT-seq.*
5 | Lea H. Gregersen1 Richard Mitter2 and Jesper Q. Svejstrup1
6 | 1Mechanisms of Transcription Laboratory, The Francis Crick Institute, 1 Midland Road, London, NW1 1AT, UK
7 | 2Bioinformatics and Biostatistics, The Francis Crick Institute, 1 Midland Road, London NW1 1AT, UK
8 |
9 | ---
10 |
11 |
12 | #### Define genic intervals and calculate coverage directly from BAM files.
13 |
14 | ```bash
15 | library(Rsamtools)
16 | library(GenomicRanges)
17 | library(rtracklayer)
18 | library(GenomicFeatures)
19 | library(bamsignals)
20 | library(reshape2)
21 | library(ggplot2)
22 | library(DT)
23 | ```
24 |
25 |
26 |
27 | ```bash
28 | work.dir <- "/path/to/my/working_directory/"
29 | setwd(work.dir)
30 | ```
31 |
32 |
33 | #### Create a data.frame detailing BAM files and sample names and any pertinent meta-data such as DRB release time.
34 | ```bash
35 | drb.df <- data.frame(
36 | name = c("DRB.10min","DRB.20min","DRB.30min","DRB.40min"),
37 | bam = c("bam/DRB.10min.bam","bam/DRB.20min.bam","bam/DRB.30min.bam","bam/DRB.40min.bam"),
38 | time = c(10,20,30,40),
39 | stringsAsFactors=F)
40 | drb.df <- drb.df[order(drb.df$time),]
41 | ```
42 |
43 |
44 | #### Genome transcriptome GTF files are available for download from [Ensembl](http://www.ensembl.org/index.html). The GTF file may be indexed using [igvtools](https://software.broadinstitute.org/software/igv/igvtools_commandline) *index* command. Make sure that the assembly matches the one used for read alignments.
45 | ```bash
46 | gtf.file <- "data/Homo_sapiens.GRCh38.86.gtf"
47 | ```
48 |
49 |
50 | #### Filters genes to remove any that are overly short, overly long, any non-coding genes any overlapping another gene and any that map to non-standard chromosomes.
51 | ```bash
52 | gtf.dat <- import(gtf.file)
53 | gene.gr <- gtf.dat[gtf.dat$type %in% "gene",]
54 | names(gene.gr) <- gene.gr$gene_id
55 | gene.gr$gene.width <- width(gene.gr)
56 |
57 | gene.gr <- gene.gr[width(gene.gr) >= 60000 & width(gene.gr) < 300000]
58 | gene.gr <- gene.gr[gene.gr$gene_biotype %in% "protein_coding"]
59 | gene.gr <- gene.gr[countOverlaps(gene.gr,gene.gr) == 1]
60 | gene.gr <- keepSeqlevels(gene.gr,c(as.character(1:22),"X","Y"),pruning.mode="coarse")
61 | ```
62 |
63 |
64 | #### Create GRanges object representing filtered genes -2kb:+120kb around their promoters.
65 | ```bash
66 | up.ext <- 2000
67 | dn.ext <- 120000
68 | intervals.gr <- promoters(gene.gr, upstream=up.ext, downstream=dn.ext)
69 | intervals.gr <- trim(intervals.gr)
70 | intervals.gr <- intervals.gr[width(intervals.gr) == (up.ext+dn.ext)]
71 | ```
72 |
73 |
74 | #### Calculate bp-level coverage over the extended gene intervals.
75 | Currently this is not strand-specific as "bamCoverage" doesn't allow it, but filtering out overlapping genes should take care of most of the problems. Alternatively, one could filter the bam file by strand prior to calculating coverage.
76 | ```bash
77 | sigs.list <- list()
78 | for (r in 1:nrow(drb.df)) {
79 | sigs <- bamCoverage(
80 | bampath = drb.df$bam[r],
81 | gr = intervals.gr,
82 | filteredFlag = 1024, # remove duplicates
83 | paired.end = "ignore",
84 | mapq = 20,
85 | verbose = FALSE)
86 | sigs.list[[drb.df$name[r]]] <- t(alignSignals(sigs))
87 | rownames(sigs.list[[drb.df$name[r]]]) <- names(intervals.gr)
88 | }
89 | ```
90 |
91 |
92 | #### Scale to Read counts Per Million (RPM).
93 | ```bash
94 | read.length <- 75
95 | rpm.list <- list()
96 | for (n in 1:length(sigs.list)) {
97 | n.sig <- sigs.list[[n]] / read.length
98 | n.sum <- sum(n.sig)
99 | n.sf <- n.sum / 1000000
100 | rpm.list[[names(sigs.list)[n]]] <- n.sig / n.sf
101 | }
102 | ```
103 |
104 | ***
105 |
106 | ## Meta-gene level wave peak calling.
107 |
108 | #### Create meta-profiles by taking a trimmed mean.
109 | ```bash
110 | meta.dat <- sapply(rpm.list,function(x){ apply(x,2,function(y) { mean(y,na.rm=T,trim=0.01) }) })
111 | ```
112 |
113 |
114 | #### Fit a smoothing spline to each meta-profile.
115 | ```bash
116 | # The spar parameter might need tweaking depending on the fit
117 | spline.dat <- t(apply(meta.dat,2,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
118 | ```
119 |
120 |
121 | #### Plot the meta-profiles.
122 | ```bash
123 | # Coverage
124 | cov.plot <- melt(meta.dat)
125 | colnames(cov.plot) <- c("position","name","RPM")
126 | cov.plot$position <- cov.plot$position-up.ext-1
127 | cov.plot$time <- drb.df$time[match(cov.plot$name,drb.df$name)]
128 |
129 | # Spline
130 | spline.plot <- melt(t(spline.dat))
131 | colnames(spline.plot) <- c("position","name","RPM")
132 | spline.plot$position <- spline.plot$position-up.ext-1
133 | spline.plot$time <- drb.df$time[match(spline.plot$name,drb.df$name)]
134 |
135 | P1 <- ggplot(cov.plot,aes(x=position,y=RPM,colour=name)) + geom_line(alpha=0.4)
136 | P1 <- P1 + geom_line(aes(x=position,y=RPM,colour=name),spline.plot,size=2)
137 | P1 <- P1 + xlab("Position relative to TSS (kb)") + ylab("RPM") + ggtitle("DRB/TT-seq coverage")
138 | P1 <- P1 + scale_x_continuous(breaks=c(0,40000,80000,120000),label=c("TSS","40kb","80kb","120kb"))
139 | #P1 <- P1 + scale_colour_manual(values=c("DRB.10min"="#231F20", "DRB.20min"="#58595B", "DRB.30min"="#A7A9AC", "DRB.40min"="#D1D3D4"))
140 | #ggsave(filename="results/DRB_metaprofile.png",plot=P1,device="png",height=5)
141 | P1
142 | ```
143 |
144 |
145 | #### Calculate wave peaks from meta-profiles as the maximum point on the spline.
146 | Maxima are only called after the preceeding timepoint's maximum position, forcing the wave to advance with time.
147 | ```bash
148 | wf.dat <- drb.df[,c("name","time")]
149 | wf.dat$wave <- 0
150 | for (r in 1:nrow(wf.dat)) {
151 | present.sample <- wf.dat$name[r]
152 | if (r==1) {
153 | previous.wf <- 0
154 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,])
155 | } else {
156 | previous.wf <- wf.dat$wave[r-1]
157 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,-1:-previous.wf])+previous.wf
158 | }
159 | }
160 | wf.dat$wave <- wf.dat$wave - 2001
161 | wf.dat$wave <- wf.dat$wave / 1000
162 |
163 | # Optionally add an additional time=0 datapoint which assumes a wave peak at position=0.
164 | wf.dat <- data.frame(rbind(c("DRB.0min",0,0),wf.dat),stringsAsFactors=F)
165 | wf.dat$time <- as.numeric(wf.dat$time)
166 | wf.dat$wave <- as.numeric(wf.dat$wave)
167 | ```
168 |
169 |
170 | #### Wave peaks calculated from the meta-gene profiles.
171 | ```bash
172 | datatable(wf.dat,rownames=FALSE)
173 | ```
174 |
175 |
176 | #### Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
177 | ```bash
178 | lm.fit <- lm(wf.dat$wave~wf.dat$time)
179 | elongation.rate <- lm.fit$coefficients[2]
180 | P2 <- ggplot(wf.dat,aes(x=time,y=wave)) + geom_point(size=4)
181 | P2 <- P2 + xlab("Time (min)") + ylab("Wave position (kb)")
182 | P2 <- P2 + geom_abline(intercept = lm.fit$coefficients[1], slope = lm.fit$coefficients[2])
183 | P2 <- P2 + annotate(geom="text", x=10, y=75, label=paste("y = ",round(lm.fit$coefficients[2],2),"x",round(lm.fit$coefficients[1],2),sep=''))
184 | #ggsave(filename="results/DRB_metaprofile_elongation_rate.png",plot=P2,device="png")
185 | P2
186 | ```
187 |
188 |
189 | ***
190 |
191 | ## Single gene level wave peak calling
192 |
193 | #### Generate a set of gene ids that pass an arbitrary expression threshold.
194 | ```bash
195 | expr.mat <- sapply(rpm.list,function(x){apply(x,1,function(y){sum(y,na.rm=T)})})
196 | expr.plot <- ggplot(melt(expr.mat),aes(x=log2(value+0.1),fill=Var2)) + geom_histogram(bins=50)
197 | expr.plot <- expr.plot + geom_vline(aes(xintercept=log2(100+1)),colour="darkred") + facet_grid(Var2~.) + xlab("log2(RPM+0.1)") + ylab("frequency") + ggtitle("Expression filter")
198 | expr.gids <- rownames(expr.mat)[rowSums(expr.mat > 100) == ncol(expr.mat)]
199 | #ggsave(filename="results/DRB_expression_filter.png",plot=expr.plot ,device="png")
200 | expr.plot
201 | ```
202 |
203 |
204 | #### Fit a smoothing spline over the RPM data for each gene for each sample.
205 | ```bash
206 | spline.list <- list()
207 | for (n in 1:length(rpm.list)) {
208 | spline.dat <- t(apply(rpm.list[[n]],1,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
209 | spline.list[[names(rpm.list)[n]]] <- spline.dat
210 | }
211 | ```
212 |
213 |
214 | #### Calculate wave peak for each gene as the maximum point on the spline.
215 | ```bash
216 | wf.genes <- sapply(spline.list,function(x){ apply(x,1,function(y){which.max(y)}) })
217 | rownames(wf.genes) <- rownames(spline.list[[1]])
218 | ```
219 |
220 |
221 | #### Filter the gene level wave peak predictions. Remove any genes that are lowly expressed, have missng values, have duplicate values or whose wave doesn't advance with time. Select only genes with a wave-peak after the first 2 kb in the 10min sample.
222 | ```bash
223 | wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min","DRB.40min")]
224 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
225 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
226 | wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:nrow(drb.df))}),]
227 | wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
228 |
229 | ```
230 |
231 |
232 | #### Sometimes it is necessary to disregard the final timepoint when generating the filter as transcription might have already reached the end of the gene at that point. This version only uses the first three timepoints.
233 | ```bash
234 | # wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min")]
235 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
236 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
237 | # wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:3)}),]
238 | # wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
239 |
240 | ```
241 |
242 |
243 | #### Compile results.
244 | ```bash
245 | wf.genes.dBase <- data.frame(
246 | gene_id = rownames(wf.genes),
247 | gene_name = intervals.gr[rownames(wf.genes),]$gene_id,
248 | gene_width = intervals.gr[rownames(wf.genes),]$gene.width,
249 | mean.rpkm = rowMeans(expr.mat[rownames(wf.genes),]),
250 | wf.order = apply(wf.genes[rownames(wf.genes),drb.df$name],1,function(x){paste(order(x),sep='',collapse='')}),
251 | wf.genes,
252 | filter = rownames(wf.genes) %in% rownames(wf.genes.filt),
253 | stringsAsFactors=F,
254 | check.names=F)
255 | ```
256 |
257 |
258 | #### Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
259 | ```bash
260 | lm.dat <- wf.genes.dBase[,drb.df$name]
261 | wf.genes.dBase$elongation.rate <- apply(lm.dat,1,function(x) {
262 | time <- c(0,drb.df$time)
263 | wf <- c(0,x)/1000
264 | lm(wf~time)$coef[2]
265 | })
266 | ```
267 |
268 |
269 | #### Plot a distribution of elongation rates for genes passing the filter.
270 | ```bash
271 | single.elong_rate.dat <- data.frame(wf.genes.dBase[wf.genes.dBase$filter,c("gene_name","elongation.rate")],stringsAsFactors=F)
272 | P3 <- ggplot(single.elong_rate.dat,aes(x=elongation.rate)) + geom_histogram(alpha=0.5,colour="#7CAE00",fill="#7CAE00")
273 | P3 <- P3 + ylab("frequency") + xlab("Elongation rate (kb/min)") + ggtitle(paste("Elongation rate, n=",nrow(single.elong_rate.dat),sep=''))
274 | #ggsave(filename="results/DRB_elongation_rate_distribution.png",plot=P3,device="png")
275 | P3
276 | ```
277 |
278 |
279 | #### Session information
280 | ```bash
281 | sessionInfo()
282 | ```
283 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DRB_TT-seq
2 |
3 | Scripts for the analysis of TT-seq and DRB/TT-seq data.
4 |
5 | This is a companion repository to the publication below.
6 |
7 | *Using TTchem-Seq to Profile Nascent Transcription and Measuring Transcript Elongation.*
8 | *Lea H. Gregersen1 Richard Mitter2 and Jesper Q. Svejstrup1.*
9 | *1Mechanisms of Transcription Laboratory, The Francis Crick Institute, 1 Midland Road, London, NW1 1AT, UK.*
10 | *2Bioinformatics and Biostatistics, The Francis Crick Institute, 1 Midland Road, London NW1 1AT, UK.*
11 |
12 |
13 | ---
14 |
15 | ### [align.md](https://github.com/crickbabs/DRB_TT-seq/blob/master/align.md)
16 | This is a bash markdown document for aligning paired Illumina sequence reads against a reference genome using STAR resulting in a sorted and indexed BAM file.
17 |
18 | ### [bigwig.md](https://github.com/crickbabs/DRB_TT-seq/blob/master/bigwig.md)
19 | This is a bash markdown document for generating scaled strand-specific BIGWIG files from a BAM file containing paired reads.
20 |
21 | ### [bigwig_bedtools.md](https://github.com/crickbabs/DRB_TT-seq/blob/master/bigwig_bedtools.md)
22 | This is a bash markdown document for generating scaled strand-specific BIGWIG files from a BAM file containing paired reads. It is meant as an alternative to **bigwig.md** to be used on large bam files when deeptools struggles.
23 |
24 | ### [metaprofiles.md](https://github.com/crickbabs/DRB_TT-seq/blob/master/metaprofiles.md)
25 | This is a bash markdown document for generating strand-specific metagene, TSS and TES profiles from a BAM file using "ngs.plot".
26 |
27 | ### [DRB-TTseq.md](https://github.com/crickbabs/DRB_TT-seq/blob/master/DRB_TT-seq.md)
28 | This is a markdown document describing a pipeline for calling RNA Pol II transcription wave peak positions and elongation rates from DRB/TT-seq time-series data using R. Instructions are given for calculating wave peaks at both the single-gene and meta-gene level. An Rmarkdown version of the scripts is available in the [scripts](https://github.com/crickbabs/DRB_TT-seq/blob/master/scripts)
29 | An example html output of this script is given in **[DRB-TTseq.html](https://github.com/crickbabs/DRB_TT-seq/blob/master/DRB-TTseq.html)** - view raw, save to your desktop then open with your browser in order to view it.
30 | Users unfamiliar with R markdown are recommended to explore it using [rstudio](https://www.rstudio.com/).
31 |
32 | ### [data](https://github.com/crickbabs/DRB_TT-seq/blob/master/data/README.md)
33 | This directory contains details of demo FASTQ data available from the NCBI's Short Read Archive (SRA).
34 |
35 | ### [scripts](https://github.com/crickbabs/DRB_TT-seq/blob/master/scripts)
36 | This directory contains plain script versions of the markdown documents.
37 |
38 |
39 | ---
40 |
41 | ### Dependencies and requirements
42 |
43 | Scripts were tested using the following software versions:
44 |
45 | * SAMtools v1.3.1
46 | * deepTools v2.5.3
47 | * BEDTools/2.27.1
48 | * kentUtils
49 | * STAR 2.5.2a
50 | * Picard v2.1.1
51 | * R v3.5.1 running Bioconductor version 3.7
52 | * ngsplot v2.63
53 |
54 | Example Bash scripts are written to be executed in a linux environment. Scripts were tested on a linux server equipped with a 8-core Intel E5-2640 Haswell CPU running at 2.6GHz and using 8 processors and 8gb RAM.
55 |
56 | The R script may be run on any machine able to run R v3.5.1 or higher, though for large datasets it is recommended that at least 16gb RAM be made available to the process.
57 |
58 | ---
59 |
60 | ### References
61 |
62 | * Andrews, S. FastQC: a quality control tool for high throughput sequence data. Available online at: http://www.bioinformatics.babraham.ac.uk/projects/fastqc (2010).
63 |
64 | * Dobin, A. et al. STAR: ultrafast universal RNA-seq aligner. Bioinformatics 29, 15-21, doi:10.1093/bioinformatics/bts635 (2013).
65 |
66 | * Hunt, S. E. et al. Ensembl variation resources. Database (Oxford) 2018, doi:10.1093/database/bay119 (2018).
67 |
68 | * Kent WJ, Zweig AS, Barber G, Hinrichs AS, Karolchik D. BigWig and BigBed: enabling browsing of large distributed datasets. Bioinformatics. 2010 Sep 1;26(17):2204-7.
69 |
70 | * Lawrence, M. et al. Software for computing and annotating genomic ranges. PLoS Comput Biol 9, e1003118, doi:10.1371/journal.pcbi.1003118 (2013).
71 |
72 | * Li, H. et al. The Sequence Alignment/Map format and SAMtools. Bioinformatics 25, 2078-2079, doi:10.1093/bioinformatics/btp352 (2009).
73 |
74 | * Mammana, A. H., J. bamsignals: Extract read count signals from bam files. R package version 1.12.11 (2016).
75 |
76 | * Quinlan AR. BEDTools: The Swiss-Army Tool for Genome Feature Analysis. CurrProtoc Bioinformatics. 2014 Sep 8;47:11.12.1-34.
77 |
78 | * Ramirez, F., Dundar, F., Diehl, S., Gruning, B. A. & Manke, T. deepTools: a flexible platform for exploring deep-sequencing data. Nucleic Acids Res 42, W187-191, doi:10.1093/nar/gku365 (2014).
79 |
80 | * Shen, L., Shao, N., Liu, X. and Nestler, E. (2014) ngs.plot: Quick mining and visualization of next-generation sequencing data by integrating genomic databases, BMC Genomics, 15, 284.
81 |
82 | * http://broadinstitute.github.io/picard/.
83 |
--------------------------------------------------------------------------------
/align.md:
--------------------------------------------------------------------------------
1 | ## This bash script provides instruction for aligning paired Illumina sequence reads against a reference genome using STAR.
2 |
3 | In this example a *S. cerevisiae* RNA spike-in was inserted into the human RNA sample prior to sequencing. Spike-in abundance was estimated by a separate mapping of the sequence reads to the yeast genome using STAR. However, creating a composite human/yeast genome and aligning to that or using an alignment free abundance estimator such as [kallisto](https://pachterlab.github.io/kallisto/) are also valid options.
4 |
5 | The purpose of the spike-in is to generate a scale-factor to account for differences in library size between multiple samples. A scale factor may be as simple as a ratio of mapped spike-in reads between two samples. A more robust scale factor may be calculated across multiple samples using the "estimateSizeFactors" function from the [Bioconductor](https://bioconductor.org/) package [DESeq2](https://bioconductor.org/packages/release/bioc/html/DESeq2.html) using sample specific spike-in gene count information.
6 |
7 | ---
8 |
9 | The output of this script are two sorted, duplicate marked and indexed BAM files - one for the target organism and one for the spike-in. There are also gene level counts produced by STAR ("*.ReadsPerGene.out.tab") that may be may used to generate scale factors.
10 |
11 | *It is assumed that the FASTQ reads have been checked for quality and any filtering, adapter trimming etc. that might be required has been done prior to running this script.*
12 |
13 | If there are multiple sets of FASTQ files per sample, i.e. more than 1 set of paired reads, it is recommended to align these separately and merge the resultant BAM files using "samtools merge" before continuing with the downstream analysis.
14 |
15 | Marking duplicate reads isn't strictly necessary but the calculated levels of duplication provide insight into sample quality. Also, counts of unique mapped reads may be useful for scale factor normalisation.
16 |
17 | Dependencies:
18 | SAMtools http://samtools.sourceforge.net/
19 | Picard https://broadinstitute.github.io/picard/
20 | STAR https://github.com/alexdobin/STAR
21 |
22 | ---
23 |
24 | #### Set working, temporary and results directories
25 | ```bash
26 | WORKDIR="/path/to/my/working_directory/"
27 | TMPDIR="${WORKDIR}tmp/"
28 | ALIGNDIR="${WORKDIR}alignments/"
29 | SPIKEDIR="${WORKDIR}alignments_spike/"
30 | mkdir -p $TMPDIR
31 | mkdir -p $ALIGNDIR
32 | mkdir -p $SPIKEDIR
33 | ```
34 |
35 |
36 | #### Sample information: sample name and location of paired FASTQ files.
37 | ```bash
38 | SAMPLE="WT";
39 | FQ1="${WORKDIR}FQ1.fastq.gz"
40 | FQ2="${WORKDIR}FQ2.fastq.gz"
41 | ```
42 |
43 |
44 | #### Threads - set to take advantage of multi-threading and speed things up.
45 | ```bash
46 | THREADS=8
47 | ```
48 |
49 |
50 | #### Path to STAR genome indices
51 | These were created using GRCh38 Ensembl v86 (*Homo sapiens*) and R64-1-1 Ensembl v86 (*Saccharomyces cerevisiae*) genome sequences and GTF files downloaded from the [Ensembl](https://www.ensembl.org/index.html) database. Please refer to the STAR manual for information on how to create your own genomes indices.
52 | ```bash
53 | HUMANIDX="/path/to/my/human_genome_index/"
54 | SPIKEIDX="/path/to/my/yeast_genome_index/"
55 | ```
56 |
57 |
58 | #### Align to the human genome. Sort, mark duplicates and index the genome BAM.
59 | ```bash
60 | cd $ALIGNDIR
61 | STAR --runThreadN ${THREADS} --runMode alignReads --genomeDir ${HUMANIDX} --readFilesIn ${FQ1} ${FQ2} --readFilesCommand zcat --quantMode TranscriptomeSAM GeneCounts --twopassMode Basic --outSAMunmapped None --outSAMattrRGline ID:${SAMPLE} PU:${SAMPLE} SM:${SAMPLE} LB:unknown PL:illumina --outSAMtype BAM Unsorted --outTmpDir ${TMPDIR}${SAMPLE} --outFileNamePrefix ${ALIGNDIR}${SAMPLE}.
62 | samtools sort --threads ${THREADS} -o ${ALIGNDIR}${SAMPLE}.sorted.bam ${ALIGNDIR}${SAMPLE}.Aligned.out.bam
63 | java -jar picard.jar MarkDuplicates INPUT=${ALIGNDIR}${SAMPLE}.sorted.bam OUTPUT=${ALIGNDIR}${SAMPLE}.sorted.marked.bam METRICS_FILE=${ALIGNDIR}${SAMPLE}.sorted.marked.metrics REMOVE_DUPLICATES=false ASSUME_SORTED=true MAX_RECORDS_IN_RAM=2000000 VALIDATION_STRINGENCY=LENIENT TMP_DIR=${TMPDIR}${SAMPLE}
64 | samtools index ${ALIGNDIR}${SAMPLE}.sorted.marked.bam
65 | rm ${ALIGNDIR}${SAMPLE}.sorted.bam
66 | ```
67 |
68 | #### Align to the yeast genome (spike-in). Sort, mark duplicates and index the genome BAM.
69 | ```bash
70 | cd $SPIKEDIR
71 | STAR --runThreadN ${THREADS} --runMode alignReads --genomeDir ${SPIKEIDX} --readFilesIn ${FQ1} ${FQ2} --readFilesCommand zcat --quantMode TranscriptomeSAM GeneCounts --twopassMode Basic --outSAMunmapped None --outSAMattrRGline ID:${SAMPLE} PU:${SAMPLE} SM:${SAMPLE} LB:unknown PL:illumina --outSAMtype BAM Unsorted --outTmpDir ${TMPDIR}${SAMPLE}.spike --outFileNamePrefix ${ALIGNDIR}${SAMPLE}.
72 | samtools sort --threads ${THREADS} -o ${SPIKEDIR}${SAMPLE}.sorted.bam ${SPIKEDIR}${SAMPLE}.Aligned.out.bam
73 | java -jar picard.jar MarkDuplicates INPUT=${SPIKEDIR}${SAMPLE}.sorted.bam OUTPUT=${SPIKEDIR}${SAMPLE}.sorted.marked.bam METRICS_FILE=${SPIKEDIR}${SAMPLE}.sorted.marked.metrics REMOVE_DUPLICATES=false ASSUME_SORTED=true MAX_RECORDS_IN_RAM=2000000 VALIDATION_STRINGENCY=LENIENT TMP_DIR=${TMPDIR}${SAMPLE}
74 | samtools index ${SPIKEDIR}${SAMPLE}.sorted.marked.bam
75 | rm ${SPIKEDIR}${SAMPLE}.sorted.bam
76 | ```
77 |
--------------------------------------------------------------------------------
/bigwig.md:
--------------------------------------------------------------------------------
1 | ## This bash script provides a means of generating scaled strand-specific BIGWIG files from a BAM file containing paired reads.
2 |
3 | Adapted from:
4 | *Ramírez, Fidel, Devon P. Ryan, Björn Grüning, Vivek Bhardwaj, Fabian Kilpert, Andreas S. Richter, Steffen Heyne, Friederike Dündar, and Thomas Manke.*
5 | *deepTools2: A next Generation Web Server for Deep-Sequencing Data Analysis. Nucleic Acids Research (2016). doi:10.1093/nar/gkw257.*
6 | *https://deeptools.readthedocs.io/en/develop/content/tools/bamCoverage.html*
7 |
8 | Dependencies:
9 | SAMtools http://samtools.sourceforge.net/
10 | deepTools https://deeptools.readthedocs.io/en/develop/index.html
11 |
12 | If you experience performance issues using this script it is recommended to try [bigwig_bedtools.sh](https://github.com/crickbabs/DRB_TT-seq/blob/master/bigwig_bedtools.md) as an alternative.
13 |
14 | ---
15 |
16 | #### Set working, temporary and results directories.
17 | ```bash
18 | WORKDIR="/path/to/my/working_directory/"
19 | TMPDIR="${WORKDIR}tmp/"
20 | BIGWIGDIR="${WORKDIR}bigwig/"
21 | mkdir -p $TMPDIR
22 | mkdir -p $BIGWIGDIR
23 | ```
24 |
25 |
26 | #### Sample information: sample name and BAM file location.
27 | ```bash
28 | SAMPLE="WT";
29 | BAM="${WORKDIR}WT.bam"
30 | ```
31 |
32 |
33 | #### Threads - set to take advantage of multi-threading and speed things up.
34 | ```bash
35 | THREADS=1
36 | ```
37 |
38 |
39 | #### Temporaty BAM files.
40 | ```bash
41 | BAMFOR="${TMPDIR}${SAMPLE}.fwd.bam" # BAM file representing reads mapping to forward strand
42 | BAMREV="${TMPDIR}${SAMPLE}.rev.bam" # BAM file representing reads mapping to reverse strand
43 | BAMFOR1="${TMPDIR}${SAMPLE}.fwd1.bam"
44 | BAMFOR2="${TMPDIR}${SAMPLE}.fwd2.bam"
45 | BAMREV1="${TMPDIR}${SAMPLE}.rev1.bam"
46 | BAMREV2="${TMPDIR}${SAMPLE}.rev2.bam"
47 | ```
48 |
49 |
50 | #### bigwig files.
51 | ```bash
52 | BIGWIG="${BIGWIGDIR}${SAMPLE}.bigwig" # BIGWIG file representing all reads
53 | BIGWIGFOR="${BIGWIGDIR}${SAMPLE}.for.bigwig" # BIGWIG file representing reads mapping to forward strand
54 | BIGWIGREV="${BIGWIGDIR}${SAMPLE}.rev.bigwig" # BIGWIG file representing reads mapping to reverse strand
55 | ```
56 |
57 | #### Scale factor.
58 | A scale factor is used to normalise for differences in library sizes across samples. There are many ways to generate such a factor, such as the ratio of reads between two samples of spike-ins. A more robust scale factor may be calculated using the "estimateSizeFactors" function from the Bioconductor package DESeq2 using sample gene count information. Setting this to 1 indicates no scaling. Note that it is necessary to use the recipricol of the the scale factor returned by DESeq2 when passing to the bamCoverage function since coverage will be multiplied by this.
59 | ```bash
60 | SCALEFACTOR=1
61 | ```
62 |
63 |
64 | #### Create bigwig file for all reads.
65 | ```bash
66 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAM -o $BIGWIG
67 | ```
68 |
69 |
70 | #### Create bigwig file for the forward strand.
71 | Get file for transcripts originating on the forward strand.
72 | Include reads that are 2nd in a pair (128). Exclude reads that are mapped to the reverse strand (16)
73 | Exclude reads that are mapped to the reverse strand (16) and first in a pair (64): 64 + 16 = 80
74 | ```bash
75 | samtools view -b -f 128 -F 16 --threads $THREADS $BAM > $BAMFOR1
76 | samtools view -b -f 80 --threads $THREADS $BAM > $BAMFOR2
77 | samtools merge --threads $THREADS -f $BAMFOR $BAMFOR1 $BAMFOR2
78 | samtools index $BAMFOR
79 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAMFOR -o $BIGWIGFOR
80 | ```
81 |
82 |
83 | #### Create bigwig file for the reverse strand.
84 | Get the file for transcripts that originated from the reverse strand:
85 | Include reads that map to the reverse strand (128) and are second in a pair (16): 128 + 16 = 144
86 | Include reads that are first in a pair (64), but exclude those ones that map to the reverse strand (16)
87 | ```bash
88 | samtools view -b -f 144 --threads $THREADS $BAM > $BAMREV1
89 | samtools view -b -f 64 -F 16 --threads $THREADS $BAM > $BAMREV2
90 | samtools merge --threads $THREADS -f $BAMREV $BAMREV1 $BAMREV2
91 | samtools index $BAMREV
92 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAMREV -o $BIGWIGREV
93 | ```
94 |
95 |
96 | #### Remove temporary files.
97 | ```bash
98 | rm $BAMFOR $BAMFFOR1 $BAMFFOR2 $BAMREV $BAMREV1 $BAMREV2
99 | ```
100 |
--------------------------------------------------------------------------------
/bigwig_bedtools.md:
--------------------------------------------------------------------------------
1 | ## This bash script provides a means of generating scaled strand-specific BIGWIG files from a BAM file containing paired reads.
2 |
3 | This alternative to "bigwig.sh" uses bedtools (Quinlan, *et al* 2014) rather than deeptools to generate bedgraph files which are in turn converted to bigwig format via Jim Kent's BigWig and BigBed tools (kent, *et al*, 2010). It is better able to deal with large bam files.
4 |
5 | Dependencies:
6 | SAMtools http://samtools.sourceforge.net/
7 | bedtools https://bedtools.readthedocs.io/en/latest/
8 | kentUtils http://bioinformatics.oxfordjournals.org/content/26/17/2204.long
9 |
10 | ---
11 |
12 |
13 | #### Set working, temporary and results directories.
14 | ```bash
15 | WORKDIR="/path/to/my/working_directory/"
16 | TMPDIR="${WORKDIR}tmp/"
17 | BIGWIGDIR="${WORKDIR}bigwig/"
18 | mkdir -p $TMPDIR
19 | mkdir -p $BIGWIGDIR
20 | ```
21 |
22 | #### Sample information: sample name and BAM file location.
23 | ```bash
24 | SAMPLE="WT";
25 | BAM="${WORKDIR}${SAMPLE}.sorted.marked.bam"
26 | ```
27 |
28 | #### Chromosome size information. An unheadered, two-column tab-delimited text file:
29 | ```bash
30 | CHRSIZE="${WORKDIR}chrom.sizes.txt"
31 | ```
32 |
33 | #### Threads - set to take advantage of multi-threading and speed things up.
34 | ```bash
35 | THREADS=8
36 | ```
37 |
38 | #### Temporaty BAM files.
39 | ```bash
40 | BAMFOR="${TMPDIR}${SAMPLE}.fwd.bam" # BAM file representing reads mapping to forward strand
41 | BAMREV="${TMPDIR}${SAMPLE}.rev.bam" # BAM file representing reads mapping to reverse strand
42 | BAMFOR1="${TMPDIR}${SAMPLE}.fwd1.bam"
43 | BAMFOR2="${TMPDIR}${SAMPLE}.fwd2.bam"
44 | BAMREV1="${TMPDIR}${SAMPLE}.rev1.bam"
45 | BAMREV2="${TMPDIR}${SAMPLE}.rev2.bam"
46 | ```
47 |
48 | #### bedgraph files.
49 | ```bash
50 | BEDGRAPH="${TMPDIR}${SAMPLE}.bedgraph" # BEDGRAPH file representing all reads
51 | BEDGRAPHFOR="${TMPDIR}${SAMPLE}.for.bedgraph" # BEDGRAPH file representing reads mapping to forward strand
52 | BEDGRAPHREV="${TMPDIR}${SAMPLE}.rev.bedgraph" # BEDGRAPH file representing reads mapping to reverse strand
53 | ```
54 |
55 | #### Sorted bedgraph files.
56 | ```bash
57 | BEDGRAPHSORTED="${TMPDIR}${SAMPLE}.sorted.bedgraph" # Sorted BEDGRAPH file representing all reads
58 | BEDGRAPHFORSORTED="${TMPDIR}${SAMPLE}.for.sorted.bedgraph" # Sorted BEDGRAPH file representing reads mapping to forward strand
59 | BEDGRAPHREVSORTED="${TMPDIR}${SAMPLE}.rev.sorted.bedgraph" # Sorted BEDGRAPH file representing reads mapping to reverse strand
60 | ```
61 |
62 | #### bigwig files.
63 | ```bash
64 | BIGWIG="${BIGWIGDIR}${SAMPLE}.bigwig" # BIGWIG file representing all reads
65 | BIGWIGFOR="${BIGWIGDIR}${SAMPLE}.for.bigwig" # BIGWIG file representing reads mapping to forward strand
66 | BIGWIGREV="${BIGWIGDIR}${SAMPLE}.rev.bigwig" # BIGWIG file representing reads mapping to reverse strand
67 | ```
68 |
69 | #### Scale factor.
70 | ```bash
71 | SCALEFACTOR=1
72 | ```
73 |
74 | #### Create bigwig file for all reads.
75 | ```bash
76 | bedtools genomecov -ibam $BAM -bg -split -scale $SCALEFACTOR > $BEDGRAPH
77 | sort -k1,1 -k2,2n $BEDGRAPH > $BEDGRAPHSORTED
78 | bedGraphToBigWig $BEDGRAPHSORTED $CHRSIZE $BIGWIG
79 | ```
80 |
81 | #### Create bigwig file for the forward strand.
82 | ```bash
83 | samtools view -b -f 128 -F 16 --threads $THREADS $BAM > $BAMFOR1
84 | samtools view -b -f 80 --threads $THREADS $BAM > $BAMFOR2
85 | samtools merge --threads $THREADS -f $BAMFOR $BAMFOR1 $BAMFOR2
86 | samtools index $BAMFOR
87 | bedtools genomecov -ibam $BAMFOR -bg -split -strand + -scale $SCALEFACTOR > $BEDGRAPHFOR
88 | sort -k1,1 -k2,2 $BEDGRAPHFOR > $BEDGRAPHFORSORTED
89 | bedGraphToBigWig $BEDGRAPHFORSORTED $CHRSIZE $BIGWIGFOR
90 | ```
91 |
92 | #### Create bigwig file for the reverse strand.
93 | ```bash
94 | samtools view -b -f 144 --threads $THREADS $BAM > $BAMREV1
95 | samtools view -b -f 64 -F 16 --threads $THREADS $BAM > $BAMREV2
96 | samtools merge --threads $THREADS -f $BAMREV $BAMREV1 $BAMREV2
97 | samtools index $BAMREV
98 | bedtools genomecov -ibam $BAMREV -bg -split -strand - -scale $SCALEFACTOR > $BEDGRAPHREV
99 | sort -k1,1 -k2,2 $BEDGRAPHREV > $BEDGRAPHREVSORTED
100 | bedGraphToBigWig $BEDGRAPHREVSORTED $CHRSIZE $BIGWIGREV
101 | ```
102 |
103 | #### Remove temporary files.
104 | ```bash
105 | rm $BAMFOR $BAMFFOR1 $BAMFFOR2 $BAMREV $BAMREV1 $BAMREV2 $BEDGRAPH $BEDGRAPHFOR $BEDGRAPHREV $BEDGRAPHSORTED $BEDGRAPHFORSORTED $BEDGRAPHREVSORTED
106 | ```
107 |
--------------------------------------------------------------------------------
/data/README.md:
--------------------------------------------------------------------------------
1 | Example data for running these scripts are available from the NCBI's Short Read Archive [(SRA)](https://www.ncbi.nlm.nih.gov/sra/) using the accession numbers given below.
2 |
3 | ---
4 |
5 | # DRB_TT-seq
6 |
7 | | accession | description |
8 | | ---------- | ----------- |
9 | | SRR8112728 | DRB_10min |
10 | | SRR8112732 | DRB_20min |
11 | | SRR8112736 | DRB_30min |
12 | | SRR8112740 | DRB_40min |
13 |
14 | The files above represent 4 samples generated at 4 timepoints (10, 20, 30 and 40 mniutes) after DRB release.
15 |
16 | ---
17 |
18 | # TT-seq
19 |
20 | | accession | description |
21 | | ---------- | -------------- |
22 | | SRR8112935 | WT1_replicate1 |
23 | | SRR8112947 | WT1_replicate2 |
24 | | SRR8112941 | WT2_replicate1 |
25 | | SRR8112953 | WT2_replicate2 |
26 |
27 | Note that details of 4 paired-end fastq files are given for the example TT-seq data. These represent two replicates of a single wild-type biological sample, with each replicate being split across 2 sequencing runs. It is recommended to align each separately. For the purposes of visualisation in the manscript, the resulting BAM files were merged prior to downstream analysis. However, this step is not necessary to achieve bigwigs/metaprofiles and analysis of just a single sample should provide reasonable results.
28 |
--------------------------------------------------------------------------------
/data/chrom.sizes.txt:
--------------------------------------------------------------------------------
1 | 1 248956422
2 | 10 133797422
3 | 11 135086622
4 | 12 133275309
5 | 13 114364328
6 | 14 107043718
7 | 15 101991189
8 | 16 90338345
9 | 17 83257441
10 | 18 80373285
11 | 19 58617616
12 | 2 242193529
13 | 20 64444167
14 | 21 46709983
15 | 22 50818468
16 | 3 198295559
17 | 4 190214555
18 | 5 181538259
19 | 6 170805979
20 | 7 159345973
21 | 8 145138636
22 | 9 138394717
23 | MT 16569
24 | X 156040895
25 | Y 57227415
26 | KI270728.1 1872759
27 | KI270727.1 448248
28 | KI270442.1 392061
29 | KI270729.1 280839
30 | GL000225.1 211173
31 | KI270743.1 210658
32 | GL000008.2 209709
33 | GL000009.2 201709
34 | KI270747.1 198735
35 | KI270722.1 194050
36 | GL000194.1 191469
37 | KI270742.1 186739
38 | GL000205.2 185591
39 | GL000195.1 182896
40 | KI270736.1 181920
41 | KI270733.1 179772
42 | GL000224.1 179693
43 | GL000219.1 179198
44 | KI270719.1 176845
45 | GL000216.2 176608
46 | KI270712.1 176043
47 | KI270706.1 175055
48 | KI270725.1 172810
49 | KI270744.1 168472
50 | KI270734.1 165050
51 | GL000213.1 164239
52 | GL000220.1 161802
53 | KI270715.1 161471
54 | GL000218.1 161147
55 | KI270749.1 158759
56 | KI270741.1 157432
57 | GL000221.1 155397
58 | KI270716.1 153799
59 | KI270731.1 150754
60 | KI270751.1 150742
61 | KI270750.1 148850
62 | KI270519.1 138126
63 | GL000214.1 137718
64 | KI270708.1 127682
65 | KI270730.1 112551
66 | KI270438.1 112505
67 | KI270737.1 103838
68 | KI270721.1 100316
69 | KI270738.1 99375
70 | KI270748.1 93321
71 | KI270435.1 92983
72 | GL000208.1 92689
73 | KI270538.1 91309
74 | KI270756.1 79590
75 | KI270739.1 73985
76 | KI270757.1 71251
77 | KI270709.1 66860
78 | KI270746.1 66486
79 | KI270753.1 62944
80 | KI270589.1 44474
81 | KI270726.1 43739
82 | KI270735.1 42811
83 | KI270711.1 42210
84 | KI270745.1 41891
85 | KI270714.1 41717
86 | KI270732.1 41543
87 | KI270713.1 40745
88 | KI270754.1 40191
89 | KI270710.1 40176
90 | KI270717.1 40062
91 | KI270724.1 39555
92 | KI270720.1 39050
93 | KI270723.1 38115
94 | KI270718.1 38054
95 | KI270317.1 37690
96 | KI270740.1 37240
97 | KI270755.1 36723
98 | KI270707.1 32032
99 | KI270579.1 31033
100 | KI270752.1 27745
101 | KI270512.1 22689
102 | KI270322.1 21476
103 | GL000226.1 15008
104 | KI270311.1 12399
105 | KI270366.1 8320
106 | KI270511.1 8127
107 | KI270448.1 7992
108 | KI270521.1 7642
109 | KI270581.1 7046
110 | KI270582.1 6504
111 | KI270515.1 6361
112 | KI270588.1 6158
113 | KI270591.1 5796
114 | KI270522.1 5674
115 | KI270507.1 5353
116 | KI270590.1 4685
117 | KI270584.1 4513
118 | KI270320.1 4416
119 | KI270382.1 4215
120 | KI270468.1 4055
121 | KI270467.1 3920
122 | KI270362.1 3530
123 | KI270517.1 3253
124 | KI270593.1 3041
125 | KI270528.1 2983
126 | KI270587.1 2969
127 | KI270364.1 2855
128 | KI270371.1 2805
129 | KI270333.1 2699
130 | KI270374.1 2656
131 | KI270411.1 2646
132 | KI270414.1 2489
133 | KI270510.1 2415
134 | KI270390.1 2387
135 | KI270375.1 2378
136 | KI270420.1 2321
137 | KI270509.1 2318
138 | KI270315.1 2276
139 | KI270302.1 2274
140 | KI270518.1 2186
141 | KI270530.1 2168
142 | KI270304.1 2165
143 | KI270418.1 2145
144 | KI270424.1 2140
145 | KI270417.1 2043
146 | KI270508.1 1951
147 | KI270303.1 1942
148 | KI270381.1 1930
149 | KI270529.1 1899
150 | KI270425.1 1884
151 | KI270396.1 1880
152 | KI270363.1 1803
153 | KI270386.1 1788
154 | KI270465.1 1774
155 | KI270383.1 1750
156 | KI270384.1 1658
157 | KI270330.1 1652
158 | KI270372.1 1650
159 | KI270548.1 1599
160 | KI270580.1 1553
161 | KI270387.1 1537
162 | KI270391.1 1484
163 | KI270305.1 1472
164 | KI270373.1 1451
165 | KI270422.1 1445
166 | KI270316.1 1444
167 | KI270340.1 1428
168 | KI270338.1 1428
169 | KI270583.1 1400
170 | KI270334.1 1368
171 | KI270429.1 1361
172 | KI270393.1 1308
173 | KI270516.1 1300
174 | KI270389.1 1298
175 | KI270466.1 1233
176 | KI270388.1 1216
177 | KI270544.1 1202
178 | KI270310.1 1201
179 | KI270412.1 1179
180 | KI270395.1 1143
181 | KI270376.1 1136
182 | KI270337.1 1121
183 | KI270335.1 1048
184 | KI270378.1 1048
185 | KI270379.1 1045
186 | KI270329.1 1040
187 | KI270419.1 1029
188 | KI270336.1 1026
189 | KI270312.1 998
190 | KI270539.1 993
191 | KI270385.1 990
192 | KI270423.1 981
193 | KI270392.1 971
194 | KI270394.1 970
195 |
--------------------------------------------------------------------------------
/metaprofiles.md:
--------------------------------------------------------------------------------
1 | ## This bash script provides a means of generating strand-specific metagene, TSS and TES profiles from a BAM file using "ngs.plot".
2 |
3 | *Of course, this will only work if your libraries were created in a strand-specific fashion.*
4 |
5 | Shen, L.*, Shao, N., Liu, X. and Nestler, E. (2014).
6 | ngs.plot: Quick mining and visualization of next-generation sequencing data by integrating genomic databases, BMC Genomics, 15, 284.
7 | https://github.com/shenlab-sinai/ngsplot
8 |
9 | Dependencies:
10 | SAMtools http://samtools.sourceforge.net/
11 | ngs.plot https://github.com/shenlab-sinai/ngsplot
12 |
13 | ---
14 |
15 |
16 | #### Set working, temporary and results directories.
17 | ```bash
18 | WORKDIR="/path/to/my/working_directory/"
19 | TMPDIR="${WORKDIR}tmp/"
20 | PROFDIR="${WORKDIR}metaprofiles/"
21 | mkdir -p $TMPDIR
22 | mkdir -p $PROFDIR
23 | ```
24 |
25 |
26 | #### Sample information: sample name and BAM file location.
27 | ```bash
28 | SAMPLE="WT";
29 | BAM="${WORKDIR}WT.bam"
30 | MATE1="${WORKDIR}WT.mate1.bam"
31 | ```
32 |
33 |
34 | #### Threads - set to take advantage of multi-threading and speed things up.
35 | ```bash
36 | THREADS=1
37 | ```
38 |
39 | #### Restict to first mate reads.
40 | If the BAM file contains paired reads, create a new version containing only the first mate reads.
41 | This step may be skipped if your reads are not paired.
42 | ```bash
43 | samtools view --threads $THREADS -h -b -f 64 $BAM -o $MATE1
44 | samtools index $MATE1
45 | ```
46 |
47 |
48 | #### BAM header compliance.
49 | It might be necessary to re-header the BAM file so that the chromosome names match those in the ngs.plot database, e.g. standard chromosomes preceeded with "chr" for hg38. This is most easily achieved using SAMtools "reheader" function.
50 | For human hg38 Ensembl alignments the following steps should do the job.
51 | This step may be skipped if your header is already compliant.
52 | ```bash
53 | MATE1REHEADER="${WORKDIR}WT.mate1.reheader.bam"
54 | samtools view --threads $THREADS -H ${MATE1} | sed -e 's/SN:\([0-9XY]*\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/' | samtools reheader - ${MATE1} > ${MATE1REHEADER}
55 | samtools index ${MATE1REHEADER}
56 | ```
57 |
58 |
59 | #### Run ngs.plot.
60 | Finally, use ngs.plot to create sense and anti-sense profiles for your regions of interest using the correct BAM file.
61 | Note that if your libraries were produced such that mate2 represents the forward strand the sense/anti-sense profiles will be reversed.
62 | ```bash
63 | ## Genebody
64 | REGION="genebody"
65 | for STRAND in both same opposite
66 | do
67 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
68 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
69 | done
70 |
71 | ## TSS
72 | REGION="tss"
73 | for STRAND in both same opposite
74 | do
75 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
76 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
77 | done
78 |
79 | ## TES
80 | REGION="tes"
81 | for STRAND in both same opposite
82 | do
83 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
84 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
85 | done
86 | ```
87 |
88 |
89 | #### Combining sense and anti-sense profiles
90 | By default ngs.plot produces average profiles in .pdf format. There is also a zip file containing the underlying data, This may be used to combine the sense and anti-sense profiles on a single set of axes. This is best achieved using R.
91 |
92 |
93 | #### Scaling the profiles
94 | A scale factor may be used to normalise for differences in library sizes across samples. There are many ways to generate such a factor, such as the ratio of reads between two samples of spike-ins. A more robust scale factor may be calculated using the "estimateSizeFactors" function from the Bioconductor package DESeq2 using sample gene count information.
95 |
96 | The scale factor may be used to modify the number of valid reads discovered in the BAM file given in the resulting ".cnt" file. Edit this file to multiply read count by your scale factor and re-run ngs.plot using the same parameters.
97 |
98 |
99 | #### Custom genes / intervals
100 | Profiles may be restricted to specific gene sets and also to user-defined intervals. See the ngs.plot documentation for further details.
101 | https://github.com/shenlab-sinai/ngsplot
102 | https://github.com/shenlab-sinai/ngsplot/wiki/ProgramArguments101
103 |
--------------------------------------------------------------------------------
/scripts/DRB-TTseq.R:
--------------------------------------------------------------------------------
1 | #This is a companion script to the publication below. It describes a pipeline for calling RNA Pol II transcription wave peak positions and elongation rates from DRB/TT-seq time-series data using R. Instructions are given for calculating wave peaks at both the single-gene and meta-gene level.
2 |
3 |
4 | # Nascent transcriptome profiles and measurement of transcription elongation using TT-seq.
5 | # Lea H. Gregersen (1) Richard Mitter (2) and Jesper Q. Svejstrup (1)
6 | # (1) Mechanisms of Transcription Laboratory, The Francis Crick Institute, 1 Midland Road, London, NW1 1AT, UK
7 | # (2) Bioinformatics and Biostatistics, The Francis Crick Institute, 1 Midland Road, London NW1 1AT, UK
8 |
9 | ### Define genic intervals and calculate coverage directly from BAM files.
10 |
11 | library(Rsamtools)
12 | library(GenomicRanges)
13 | library(rtracklayer)
14 | library(GenomicFeatures)
15 | library(bamsignals)
16 | library(reshape2)
17 | library(ggplot2)
18 | library(DT)
19 |
20 |
21 |
22 | work.dir <- "/path/to/my/working_directory/"
23 | setwd(work.dir)
24 |
25 |
26 | # Create a data.frame detailing BAM files and sample names and any pertinent meta-data such as DRB release time.
27 | drb.df <- data.frame(
28 | name = c("DRB.10min","DRB.20min","DRB.30min","DRB.40min"),
29 | bam = c("bam/DRB.10min.bam","bam/DRB.20min.bam","bam/DRB.30min.bam","bam/DRB.40min.bam"),
30 | time = c(10,20,30,40),
31 | stringsAsFactors=F)
32 | drb.df <- drb.df[order(drb.df$time),]
33 |
34 |
35 | # Genome transcriptome GTF files are available for download from [Ensembl](http://www.ensembl.org/index.html). The GTF file may be indexed using [igvtools](https://software.broadinstitute.org/software/igv/igvtools_commandline) *index* command. Make sure that the assembly matches the one used for read alignments.
36 | gtf.file <- "data/Homo_sapiens.GRCh38.86.gtf"
37 |
38 |
39 | # Filters genes to remove any that are overly short, overly long, any non-coding genes any overlapping another gene and any that map to non-standard chromosomes.
40 | gtf.dat <- import(gtf.file)
41 | gene.gr <- gtf.dat[gtf.dat$type %in% "gene",]
42 | names(gene.gr) <- gene.gr$gene_id
43 | gene.gr$gene.width <- width(gene.gr)
44 |
45 | gene.gr <- gene.gr[width(gene.gr) >= 60000 & width(gene.gr) < 300000]
46 | gene.gr <- gene.gr[gene.gr$gene_biotype %in% "protein_coding"]
47 | gene.gr <- gene.gr[countOverlaps(gene.gr,gene.gr) == 1]
48 | gene.gr <- keepSeqlevels(gene.gr,c(as.character(1:22),"X","Y"),pruning.mode="coarse")
49 |
50 |
51 | # Create GRanges object representing filtered genes -2kb:+120kb around their promoters.
52 | up.ext <- 2000
53 | dn.ext <- 120000
54 | intervals.gr <- promoters(gene.gr, upstream=up.ext, downstream=dn.ext)
55 | intervals.gr <- trim(intervals.gr)
56 | intervals.gr <- intervals.gr[width(intervals.gr) == (up.ext+dn.ext)]
57 |
58 |
59 | # Calculate bp-level coverage over the extended gene intervals.
60 | # Currently this is not strand-specific as "bamCoverage" doesn't allow it, but filtering out overlapping genes should take care of most of the problems.
61 | # Alternatively, one could filter the bam file by strand prior to calculating coverage.
62 | sigs.list <- list()
63 | for (r in 1:nrow(drb.df)) {
64 | sigs <- bamCoverage(
65 | bampath = drb.df$bam[r],
66 | gr = intervals.gr,
67 | filteredFlag = 1024, # remove duplicates
68 | paired.end = "ignore",
69 | mapq = 20,
70 | verbose = FALSE)
71 | sigs.list[[drb.df$name[r]]] <- t(alignSignals(sigs))
72 | rownames(sigs.list[[drb.df$name[r]]]) <- names(intervals.gr)
73 | }
74 |
75 |
76 | # Scale to Read counts Per Million (RPM).
77 | read.length <- 75
78 | rpm.list <- list()
79 | for (n in 1:length(sigs.list)) {
80 | n.sig <- sigs.list[[n]] / read.length
81 | n.sum <- sum(n.sig)
82 | n.sf <- n.sum / 1000000
83 | rpm.list[[names(sigs.list)[n]]] <- n.sig / n.sf
84 | }
85 |
86 |
87 | ### Meta-gene level wave peak calling.
88 |
89 | # Create meta-profiles by taking a trimmed mean.
90 | meta.dat <- sapply(rpm.list,function(x){ apply(x,2,function(y) { mean(y,na.rm=T,trim=0.01) }) })
91 |
92 |
93 | # Fit a smoothing spline to each meta-profile.
94 | # The spar parameter might need tweaking depending on the fit
95 | spline.dat <- t(apply(meta.dat,2,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
96 |
97 |
98 | # Plot the meta-profiles.
99 |
100 | # Coverage
101 | cov.plot <- melt(meta.dat)
102 | colnames(cov.plot) <- c("position","name","RPM")
103 | cov.plot$position <- cov.plot$position-up.ext-1
104 | cov.plot$time <- drb.df$time[match(cov.plot$name,drb.df$name)]
105 |
106 | # Spline
107 | spline.plot <- melt(t(spline.dat))
108 | colnames(spline.plot) <- c("position","name","RPM")
109 | spline.plot$position <- spline.plot$position-up.ext-1
110 | spline.plot$time <- drb.df$time[match(spline.plot$name,drb.df$name)]
111 |
112 | P1 <- ggplot(cov.plot,aes(x=position,y=RPM,colour=name)) + geom_line(alpha=0.4)
113 | P1 <- P1 + geom_line(aes(x=position,y=RPM,colour=name),spline.plot,size=2)
114 | P1 <- P1 + xlab("Position relative to TSS (kb)") + ylab("RPM") + ggtitle("DRB/TT-seq coverage")
115 | P1 <- P1 + scale_x_continuous(breaks=c(0,40000,80000,120000),label=c("TSS","40kb","80kb","120kb"))
116 | #P1 <- P1 + scale_colour_manual(values=c("DRB.10min"="#231F20", "DRB.20min"="#58595B", "DRB.30min"="#A7A9AC", "DRB.40min"="#D1D3D4"))
117 | #ggsave(filename="results/DRB_metaprofile.png",plot=P1,device="png",height=5)
118 | P1
119 |
120 |
121 | # Calculate wave peaks from meta-profiles as the maximum point on the spline.
122 | # Maxima are only called after the preceeding timepoint's maximum position, forcing the wave to advance with time.
123 | wf.dat <- drb.df[,c("name","time")]
124 | wf.dat$wave <- 0
125 | for (r in 1:nrow(wf.dat)) {
126 | present.sample <- wf.dat$name[r]
127 | if (r==1) {
128 | previous.wf <- 0
129 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,])
130 | } else {
131 | previous.wf <- wf.dat$wave[r-1]
132 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,-1:-previous.wf])+previous.wf
133 | }
134 | }
135 | wf.dat$wave <- wf.dat$wave - 2001
136 | wf.dat$wave <- wf.dat$wave / 1000
137 |
138 | # Optionally add an additional time=0 datapoint which assumes a wave peak at position=0.
139 | wf.dat <- data.frame(rbind(c("DRB.0min",0,0),wf.dat),stringsAsFactors=F)
140 | wf.dat$time <- as.numeric(wf.dat$time)
141 | wf.dat$wave <- as.numeric(wf.dat$wave)
142 |
143 |
144 | # Wave peaks calculated from the meta-gene profiles.
145 | wf.dat
146 | #datatable(wf.dat,rownames=FALSE)
147 |
148 |
149 | # Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
150 | lm.fit <- lm(wf.dat$wave~wf.dat$time)
151 | elongation.rate <- lm.fit$coefficients[2]
152 | P2 <- ggplot(wf.dat,aes(x=time,y=wave)) + geom_point(size=4)
153 | P2 <- P2 + xlab("Time (min)") + ylab("Wave position (kb)")
154 | P2 <- P2 + geom_abline(intercept = lm.fit$coefficients[1], slope = lm.fit$coefficients[2])
155 | P2 <- P2 + annotate(geom="text", x=10, y=75, label=paste("y = ",round(lm.fit$coefficients[2],2),"x",round(lm.fit$coefficients[1],2),sep=''))
156 | #ggsave(filename="results/DRB_metaprofile_elongation_rate.png",plot=P2,device="png")
157 | P2
158 |
159 |
160 | ### Single gene level wave peak calling
161 |
162 | # Generate a set of gene ids that pass an arbitrary expression threshold.
163 | expr.mat <- sapply(rpm.list,function(x){apply(x,1,function(y){sum(y,na.rm=T)})})
164 | expr.plot <- ggplot(melt(expr.mat),aes(x=log2(value+0.1),fill=Var2)) + geom_histogram(bins=50)
165 | expr.plot <- expr.plot + geom_vline(aes(xintercept=log2(100+1)),colour="darkred") + facet_grid(Var2~.) + xlab("log2(RPM+0.1)") + ylab("frequency") + ggtitle("Expression filter")
166 | expr.gids <- rownames(expr.mat)[rowSums(expr.mat > 100) == ncol(expr.mat)]
167 | #ggsave(filename="results/DRB_expression_filter.png",plot=expr.plot ,device="png")
168 | expr.plot
169 |
170 |
171 | # Fit a smoothing spline over the RPM data for each gene for each sample.
172 | spline.list <- list()
173 | for (n in 1:length(rpm.list)) {
174 | spline.dat <- t(apply(rpm.list[[n]],1,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
175 | spline.list[[names(rpm.list)[n]]] <- spline.dat
176 | }
177 |
178 |
179 | # Calculate wave peak for each gene as the maximum point on the spline.
180 | wf.genes <- sapply(spline.list,function(x){ apply(x,1,function(y){which.max(y)}) })
181 | rownames(wf.genes) <- rownames(spline.list[[1]])
182 |
183 |
184 | # Filter the gene level wave peak predictions. Remove any genes that are lowly expressed, have missng values, have duplicate values or whose wave doesn't advance with time. Select only genes with a wave-peak after the first 2 kb in the 10min sample.
185 | wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min","DRB.40min")]
186 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
187 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
188 | wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:nrow(drb.df))}),]
189 | wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
190 |
191 |
192 | # Sometimes it is necessary to disregard the final timepoint when generating the filter as transcription might have already reached the end of the gene at that point. This version only uses the first three timepoints.
193 | # wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min")]
194 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
195 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
196 | # wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:3)}),]
197 | # wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
198 |
199 |
200 | # Compile results.
201 | wf.genes.dBase <- data.frame(
202 | gene_id = rownames(wf.genes),
203 | gene_name = intervals.gr[rownames(wf.genes),]$gene_id,
204 | gene_width = intervals.gr[rownames(wf.genes),]$gene.width,
205 | mean.rpkm = rowMeans(expr.mat[rownames(wf.genes),]),
206 | wf.order = apply(wf.genes[rownames(wf.genes),drb.df$name],1,function(x){paste(order(x),sep='',collapse='')}),
207 | wf.genes,
208 | filter = rownames(wf.genes) %in% rownames(wf.genes.filt),
209 | stringsAsFactors=F,
210 | check.names=F)
211 |
212 |
213 | # Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
214 | lm.dat <- wf.genes.dBase[,drb.df$name]
215 | wf.genes.dBase$elongation.rate <- apply(lm.dat,1,function(x) {
216 | time <- c(0,drb.df$time)
217 | wf <- c(0,x)/1000
218 | lm(wf~time)$coef[2]
219 | })
220 |
221 |
222 | # Plot a distribution of elongation rates for genes passing the filter.
223 | single.elong_rate.dat <- data.frame(wf.genes.dBase[wf.genes.dBase$filter,c("gene_name","elongation.rate")],stringsAsFactors=F)
224 | P3 <- ggplot(single.elong_rate.dat,aes(x=elongation.rate)) + geom_histogram(alpha=0.5,colour="#7CAE00",fill="#7CAE00")
225 | P3 <- P3 + ylab("frequency") + xlab("Elongation rate (kb/min)") + ggtitle(paste("Elongation rate, n=",nrow(single.elong_rate.dat),sep=''))
226 | #ggsave(filename="results/DRB_elongation_rate_distribution.png",plot=P3,device="png")
227 | P3
228 |
--------------------------------------------------------------------------------
/scripts/DRB-TTseq.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "DRB/TT-seq analysis in R."
3 | author: "Richard Mitter"
4 | output:
5 | html_document:
6 | theme: united
7 | date: 'Compiled: `r format(Sys.Date(), "%B %d, %Y")`'
8 | ---
9 |
10 |
14 |
15 |
16 | ```{r, include=FALSE}
17 | knitr::opts_chunk$set(
18 | cache = TRUE,
19 | cache.lazy = FALSE,
20 | tidy = FALSE,
21 | include = TRUE,
22 | fig.width = 7,
23 | fig.height = 7,
24 | fig.align = 'center',
25 | echo = TRUE,
26 | warning = FALSE,
27 | message = FALSE
28 | )
29 | ```
30 |
31 |
32 | ***
33 |
34 | This is a companion script to the publication below. It describes a pipeline for calling RNA Pol II transcription wave peak positions and elongation rates from DRB/TT-seq time-series data using R. Instructions are given for calculating wave peaks at both the single-gene and meta-gene level.
35 |
36 |
37 | *Nascent transcriptome profiles and measurement of transcription elongation using TT-seq.*
38 | *Lea H. Gregersen^1^ Richard Mitter^2^ and Jesper Q. Svejstrup^1^^\*^*
39 | *^1^Mechanisms of Transcription Laboratory, The Francis Crick Institute, 1 Midland Road, London, NW1 1AT, UK *
40 | *^2^Bioinformatics and Biostatistics, The Francis Crick Institute, 1 Midland Road, London NW1 1AT, UK *
41 |
42 | ***
43 |
44 | ### Define genic intervals and calculate coverage directly from BAM files.
45 |
46 | ```{r library}
47 | library(Rsamtools)
48 | library(GenomicRanges)
49 | library(rtracklayer)
50 | library(GenomicFeatures)
51 | library(bamsignals)
52 | library(reshape2)
53 | library(ggplot2)
54 | library(DT)
55 | ```
56 |
57 |
58 |
59 | ```{r work_dir, include=FALSE}
60 | work.dir <- "/path/to/my/working_directory/"
61 | setwd(work.dir)
62 | ```
63 |
64 |
65 | Create a data.frame detailing BAM files and sample names and any pertinent meta-data such as DRB release time.
66 | ```{r, drb.drb.df}
67 | drb.df <- data.frame(
68 | name = c("DRB.10min","DRB.20min","DRB.30min","DRB.40min"),
69 | bam = c("bam/DRB.10min.bam","bam/DRB.20min.bam","bam/DRB.30min.bam","bam/DRB.40min.bam"),
70 | time = c(10,20,30,40),
71 | stringsAsFactors=F)
72 | drb.df <- drb.df[order(drb.df$time),]
73 | ```
74 |
75 |
76 | Genome transcriptome GTF files are available for download from [Ensembl](http://www.ensembl.org/index.html). The GTF file may be indexed using [igvtools](https://software.broadinstitute.org/software/igv/igvtools_commandline) *index* command. Make sure that the assembly matches the one used for read alignments.
77 | ```{r drb.reference_data}
78 | gtf.file <- "data/Homo_sapiens.GRCh38.86.gtf"
79 | ```
80 |
81 |
82 | Filters genes to remove any that are overly short, overly long, any non-coding genes any overlapping another gene and any that map to non-standard chromosomes.
83 | ```{r annotation}
84 | gtf.dat <- import(gtf.file)
85 | gene.gr <- gtf.dat[gtf.dat$type %in% "gene",]
86 | names(gene.gr) <- gene.gr$gene_id
87 | gene.gr$gene.width <- width(gene.gr)
88 |
89 | gene.gr <- gene.gr[width(gene.gr) >= 60000 & width(gene.gr) < 300000]
90 | gene.gr <- gene.gr[gene.gr$gene_biotype %in% "protein_coding"]
91 | gene.gr <- gene.gr[countOverlaps(gene.gr,gene.gr) == 1]
92 | gene.gr <- keepSeqlevels(gene.gr,c(as.character(1:22),"X","Y"),pruning.mode="coarse")
93 | ```
94 |
95 |
96 | Create GRanges object representing filtered genes -2kb:+120kb around their promoters.
97 | ```{r drb.intervals}
98 | up.ext <- 2000
99 | dn.ext <- 120000
100 | intervals.gr <- promoters(gene.gr, upstream=up.ext, downstream=dn.ext)
101 | intervals.gr <- trim(intervals.gr)
102 | intervals.gr <- intervals.gr[width(intervals.gr) == (up.ext+dn.ext)]
103 | ```
104 |
105 |
106 | Calculate bp-level coverage over the extended gene intervals.
107 | ```{r drb.coverage}
108 | # Currently this is not strand-specific as "bamCoverage" doesn't allow it, but filtering out overlapping genes should take care of most of the problems.
109 | # Alternatively, one could filter the bam file by strand prior to calculating coverage.
110 | sigs.list <- list()
111 | for (r in 1:nrow(drb.df)) {
112 | sigs <- bamCoverage(
113 | bampath = drb.df$bam[r],
114 | gr = intervals.gr,
115 | filteredFlag = 1024, # remove duplicates
116 | paired.end = "ignore",
117 | mapq = 20,
118 | verbose = FALSE)
119 | sigs.list[[drb.df$name[r]]] <- t(alignSignals(sigs))
120 | rownames(sigs.list[[drb.df$name[r]]]) <- names(intervals.gr)
121 | }
122 | ```
123 |
124 |
125 | Scale to Read counts Per Million (RPM).
126 | ```{r drb.RPM}
127 | read.length <- 75
128 | rpm.list <- list()
129 | for (n in 1:length(sigs.list)) {
130 | n.sig <- sigs.list[[n]] / read.length
131 | n.sum <- sum(n.sig)
132 | n.sf <- n.sum / 1000000
133 | rpm.list[[names(sigs.list)[n]]] <- n.sig / n.sf
134 | }
135 | ```
136 |
137 | ***
138 |
139 | ### Meta-gene level wave peak calling.
140 |
141 | Create meta-profiles by taking a trimmed mean.
142 | ```{r drb.mean}
143 | meta.dat <- sapply(rpm.list,function(x){ apply(x,2,function(y) { mean(y,na.rm=T,trim=0.01) }) })
144 | ```
145 |
146 |
147 | Fit a smoothing spline to each meta-profile.
148 | ```{r drb.spline}
149 | # The spar parameter might need tweaking depending on the fit
150 | spline.dat <- t(apply(meta.dat,2,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
151 | ```
152 |
153 |
154 | Plot the meta-profiles.
155 | ```{r drb.metaplot, fig.height=5, fig.width=10}
156 | # Coverage
157 | cov.plot <- melt(meta.dat)
158 | colnames(cov.plot) <- c("position","name","RPM")
159 | cov.plot$position <- cov.plot$position-up.ext-1
160 | cov.plot$time <- drb.df$time[match(cov.plot$name,drb.df$name)]
161 |
162 | # Spline
163 | spline.plot <- melt(t(spline.dat))
164 | colnames(spline.plot) <- c("position","name","RPM")
165 | spline.plot$position <- spline.plot$position-up.ext-1
166 | spline.plot$time <- drb.df$time[match(spline.plot$name,drb.df$name)]
167 |
168 | P1 <- ggplot(cov.plot,aes(x=position,y=RPM,colour=name)) + geom_line(alpha=0.4)
169 | P1 <- P1 + geom_line(aes(x=position,y=RPM,colour=name),spline.plot,size=2)
170 | P1 <- P1 + xlab("Position relative to TSS (kb)") + ylab("RPM") + ggtitle("DRB/TT-seq coverage")
171 | P1 <- P1 + scale_x_continuous(breaks=c(0,40000,80000,120000),label=c("TSS","40kb","80kb","120kb"))
172 | #P1 <- P1 + scale_colour_manual(values=c("DRB.10min"="#231F20", "DRB.20min"="#58595B", "DRB.30min"="#A7A9AC", "DRB.40min"="#D1D3D4"))
173 | #ggsave(filename="results/DRB_metaprofile.png",plot=P1,device="png",height=5)
174 | P1
175 | ```
176 |
177 |
178 | Calculate wave peaks from meta-profiles as the maximum point on the spline.
179 | Maxima are only called after the preceeding timepoint's maximum position, forcing the wave to advance with time.
180 | ```{r drb.meta_wave}
181 | wf.dat <- drb.df[,c("name","time")]
182 | wf.dat$wave <- 0
183 | for (r in 1:nrow(wf.dat)) {
184 | present.sample <- wf.dat$name[r]
185 | if (r==1) {
186 | previous.wf <- 0
187 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,])
188 | } else {
189 | previous.wf <- wf.dat$wave[r-1]
190 | wf.dat$wave[r] <- which.max(spline.dat[present.sample,-1:-previous.wf])+previous.wf
191 | }
192 | }
193 | wf.dat$wave <- wf.dat$wave - 2001
194 | wf.dat$wave <- wf.dat$wave / 1000
195 |
196 | # Optionally add an additional time=0 datapoint which assumes a wave peak at position=0.
197 | wf.dat <- data.frame(rbind(c("DRB.0min",0,0),wf.dat),stringsAsFactors=F)
198 | wf.dat$time <- as.numeric(wf.dat$time)
199 | wf.dat$wave <- as.numeric(wf.dat$wave)
200 | ```
201 |
202 |
203 | Wave peaks calculated from the meta-gene profiles.
204 | ```{r, dt}
205 | datatable(wf.dat,rownames=FALSE)
206 | ```
207 |
208 |
209 | Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
210 | ```{r, drb.meta_elongationrate}
211 | lm.fit <- lm(wf.dat$wave~wf.dat$time)
212 | elongation.rate <- lm.fit$coefficients[2]
213 | P2 <- ggplot(wf.dat,aes(x=time,y=wave)) + geom_point(size=4)
214 | P2 <- P2 + xlab("Time (min)") + ylab("Wave position (kb)")
215 | P2 <- P2 + geom_abline(intercept = lm.fit$coefficients[1], slope = lm.fit$coefficients[2])
216 | P2 <- P2 + annotate(geom="text", x=10, y=75, label=paste("y = ",round(lm.fit$coefficients[2],2),"x",round(lm.fit$coefficients[1],2),sep=''))
217 | #ggsave(filename="results/DRB_metaprofile_elongation_rate.png",plot=P2,device="png")
218 | P2
219 | ```
220 |
221 |
222 | ***
223 |
224 | ### Single gene level wave peak calling
225 |
226 | Generate a set of gene ids that pass an arbitrary expression threshold.
227 | ```{r, drb.exprfilt}
228 | expr.mat <- sapply(rpm.list,function(x){apply(x,1,function(y){sum(y,na.rm=T)})})
229 | expr.plot <- ggplot(melt(expr.mat),aes(x=log2(value+0.1),fill=Var2)) + geom_histogram(bins=50)
230 | expr.plot <- expr.plot + geom_vline(aes(xintercept=log2(100+1)),colour="darkred") + facet_grid(Var2~.) + xlab("log2(RPM+0.1)") + ylab("frequency") + ggtitle("Expression filter")
231 | expr.gids <- rownames(expr.mat)[rowSums(expr.mat > 100) == ncol(expr.mat)]
232 | #ggsave(filename="results/DRB_expression_filter.png",plot=expr.plot ,device="png")
233 | expr.plot
234 | ```
235 |
236 |
237 | Fit a smoothing spline over the RPM data for each gene for each sample.
238 | ```{r drb.single_splines}
239 | spline.list <- list()
240 | for (n in 1:length(rpm.list)) {
241 | spline.dat <- t(apply(rpm.list[[n]],1,function(x){smooth.spline(1:length(x),x,spar=0.9)$y }))
242 | spline.list[[names(rpm.list)[n]]] <- spline.dat
243 | }
244 | ```
245 |
246 |
247 | Calculate wave peak for each gene as the maximum point on the spline.
248 | ```{r drb.single_wave}
249 | wf.genes <- sapply(spline.list,function(x){ apply(x,1,function(y){which.max(y)}) })
250 | rownames(wf.genes) <- rownames(spline.list[[1]])
251 | ```
252 |
253 |
254 | Filter the gene level wave peak predictions. Remove any genes that are lowly expressed, have missng values, have duplicate values or whose wave doesn't advance with time. Select only genes with a wave-peak after the first 2 kb in the 10min sample.
255 | ```{r drb.single_filt}
256 | wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min","DRB.40min")]
257 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
258 | wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
259 | wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:nrow(drb.df))}),]
260 | wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
261 |
262 | ```
263 |
264 |
265 | Sometimes it is necessary to disregard the final timepoint when generating the filter as transcription might have already reached the end of the gene at that point. This version only uses the first three timepoints.
266 | ```{r drb.single_filt.alternative}
267 | # wf.genes.filt <- wf.genes[expr.gids,c("DRB.10min","DRB.20min","DRB.30min")]
268 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(is.na(x))}),]
269 | # wf.genes.filt <- wf.genes.filt[!apply(wf.genes.filt,1,function(x){any(duplicated(x))}),]
270 | # wf.genes.filt <- wf.genes.filt[apply(wf.genes.filt,1,function(x){all(order(x)==1:3)}),]
271 | # wf.genes.filt <- wf.genes.filt[wf.genes.filt[,"DRB.10min"]>2000,]
272 |
273 | ```
274 |
275 |
276 | Compile results.
277 | ```{r, spreadsheet}
278 | wf.genes.dBase <- data.frame(
279 | gene_id = rownames(wf.genes),
280 | gene_name = intervals.gr[rownames(wf.genes),]$gene_id,
281 | gene_width = intervals.gr[rownames(wf.genes),]$gene.width,
282 | mean.rpkm = rowMeans(expr.mat[rownames(wf.genes),]),
283 | wf.order = apply(wf.genes[rownames(wf.genes),drb.df$name],1,function(x){paste(order(x),sep='',collapse='')}),
284 | wf.genes,
285 | filter = rownames(wf.genes) %in% rownames(wf.genes.filt),
286 | stringsAsFactors=F,
287 | check.names=F)
288 | ```
289 |
290 |
291 | Fit a linear model to the wave peak positions as a function of time to determine the rate of elongation, kb/min.
292 | ```{r, drb.linfit}
293 | lm.dat <- wf.genes.dBase[,drb.df$name]
294 | wf.genes.dBase$elongation.rate <- apply(lm.dat,1,function(x) {
295 | time <- c(0,drb.df$time)
296 | wf <- c(0,x)/1000
297 | lm(wf~time)$coef[2]
298 | })
299 | ```
300 |
301 |
302 | Plot a distribution of elongation rates for genes passing the filter.
303 | ```{r, drb.single_elongationrate}
304 | single.elong_rate.dat <- data.frame(wf.genes.dBase[wf.genes.dBase$filter,c("gene_name","elongation.rate")],stringsAsFactors=F)
305 | P3 <- ggplot(single.elong_rate.dat,aes(x=elongation.rate)) + geom_histogram(alpha=0.5,colour="#7CAE00",fill="#7CAE00")
306 | P3 <- P3 + ylab("frequency") + xlab("Elongation rate (kb/min)") + ggtitle(paste("Elongation rate, n=",nrow(single.elong_rate.dat),sep=''))
307 | #ggsave(filename="results/DRB_elongation_rate_distribution.png",plot=P3,device="png")
308 | P3
309 | ```
310 |
311 |
312 | ***
313 |
314 | ```{r session.info}
315 | sessionInfo()
316 | ```
317 |
--------------------------------------------------------------------------------
/scripts/align.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | # ## This bash script provides instruction for aligning paired Illumina sequence reads against a reference genome using STAR.
4 | #
5 | # In this example a *S. cerevisiae* RNA spike-in was inserted into the human RNA sample prior to sequencing. Spike-in abundance was estimated by a separate mapping of the sequence reads to the yeast genome using STAR. However, creating a composite human/yeast genome and aligning to that or using an alignment free abundance estimator such as [kallisto](https://pachterlab.github.io/kallisto/) are also valid options.
6 | #
7 | # The purpose of the spike-in is to generate a scale-factor to account for differences in library size between multiple samples. A scale factor may be as simple as a ratio of mapped spike-in reads between two samples. A more robust scale factor may be calculated across multiple samples using the "estimateSizeFactors" function from the [Bioconductor](https://bioconductor.org/) package [DESeq2](https://bioconductor.org/packages/release/bioc/html/DESeq2.html) using sample specific spike-in gene count information.
8 | #
9 | # ---
10 | #
11 | # The output of this script are two sorted, duplicate marked and indexed BAM files - one for the target organism and one for the spike-in. There are also gene level counts produced by STAR ("*.ReadsPerGene.out.tab") that may be may used to generate scale factors.
12 | #
13 | # *It is assumed that the FASTQ reads have been checked for quality and any filtering, adapter trimming etc. that might be required has been done prior to running this script.*
14 | #
15 | # If there are multiple sets of FASTQ files per sample, i.e. more than 1 set of paired reads, it is recommended to align these separately and merge the resultant BAM files using "samtools merge" before continuing with the downstream analysis.
16 | #
17 | # Marking duplicate reads isn't strictly necessary but the calculated levels of duplication provide insight into sample quality. Also, counts of unique mapped reads may be useful for scale factor normalisation.
18 | #
19 | # Dependencies:
20 | # SAMtools http://samtools.sourceforge.net/
21 | # Picard https://broadinstitute.github.io/picard/
22 | # STAR https://github.com/alexdobin/STAR
23 |
24 |
25 | #### Set working, temporary and results directories
26 | WORKDIR="/path/to/my/working_directory/"
27 | TMPDIR="${WORKDIR}tmp/"
28 | ALIGNDIR="${WORKDIR}alignments/"
29 | SPIKEDIR="${WORKDIR}alignments_spike/"
30 | mkdir -p $TMPDIR
31 | mkdir -p $ALIGNDIR
32 | mkdir -p $SPIKEDIR
33 |
34 |
35 | #### Sample information: sample name and location of paired FASTQ files.
36 | SAMPLE="WT";
37 | FQ1="${WORKDIR}FQ1.fastq.gz"
38 | FQ2="${WORKDIR}FQ2.fastq.gz"
39 |
40 |
41 | #### Threads - set to take advantage of multi-threading and speed things up.
42 | THREADS=8
43 |
44 |
45 | #### Path to STAR genome indices
46 | # These were created using GRCh38 Ensembl v86 (*Homo sapiens*) and R64-1-1 Ensembl v86 (*Saccharomyces cerevisiae*) genome sequences and GTF files downloaded from the [Ensembl](https://www.ensembl.org/index.html) database. Please refer to the STAR manual for information on how to create your own genomes indices.
47 | HUMANIDX="/path/to/my/human_genome_index/"
48 | SPIKEIDX="/path/to/my/yeast_genome_index/"
49 |
50 |
51 | #### Align to the human genome. Sort, mark duplicates and index the genome BAM.
52 | cd $ALIGNDIR
53 | STAR --runThreadN ${THREADS} --runMode alignReads --genomeDir ${HUMANIDX} --readFilesIn ${FQ1} ${FQ2} --readFilesCommand zcat --quantMode TranscriptomeSAM GeneCounts --twopassMode Basic --outSAMunmapped None --outSAMattrRGline ID:${SAMPLE} PU:${SAMPLE} SM:${SAMPLE} LB:unknown PL:illumina --outSAMtype BAM Unsorted --outTmpDir ${TMPDIR}${SAMPLE} --outFileNamePrefix ${ALIGNDIR}${SAMPLE}.
54 | samtools sort --threads ${THREADS} -o ${ALIGNDIR}${SAMPLE}.sorted.bam ${ALIGNDIR}${SAMPLE}.Aligned.out.bam
55 | java -jar picard.jar MarkDuplicates INPUT=${ALIGNDIR}${SAMPLE}.sorted.bam OUTPUT=${ALIGNDIR}${SAMPLE}.sorted.marked.bam METRICS_FILE=${ALIGNDIR}${SAMPLE}.sorted.marked.metrics REMOVE_DUPLICATES=false ASSUME_SORTED=true MAX_RECORDS_IN_RAM=2000000 VALIDATION_STRINGENCY=LENIENT TMP_DIR=${TMPDIR}${SAMPLE}
56 | samtools index ${ALIGNDIR}${SAMPLE}.sorted.marked.bam
57 | rm ${ALIGNDIR}${SAMPLE}.sorted.bam
58 |
59 | #### Align to the yeast genome (spike-in). Sort, mark duplicates and index the genome BAM.
60 | cd $SPIKEDIR
61 | STAR --runThreadN ${THREADS} --runMode alignReads --genomeDir ${SPIKEIDX} --readFilesIn ${FQ1} ${FQ2} --readFilesCommand zcat --quantMode TranscriptomeSAM GeneCounts --twopassMode Basic --outSAMunmapped None --outSAMattrRGline ID:${SAMPLE} PU:${SAMPLE} SM:${SAMPLE} LB:unknown PL:illumina --outSAMtype BAM Unsorted --outTmpDir ${TMPDIR}${SAMPLE}.spike --outFileNamePrefix ${ALIGNDIR}${SAMPLE}.
62 | samtools sort --threads ${THREADS} -o ${SPIKEDIR}${SAMPLE}.sorted.bam ${SPIKEDIR}${SAMPLE}.Aligned.out.bam
63 | java -jar picard.jar MarkDuplicates INPUT=${SPIKEDIR}${SAMPLE}.sorted.bam OUTPUT=${SPIKEDIR}${SAMPLE}.sorted.marked.bam METRICS_FILE=${SPIKEDIR}${SAMPLE}.sorted.marked.metrics REMOVE_DUPLICATES=false ASSUME_SORTED=true MAX_RECORDS_IN_RAM=2000000 VALIDATION_STRINGENCY=LENIENT TMP_DIR=${TMPDIR}${SAMPLE}
64 | samtools index ${SPIKEDIR}${SAMPLE}.sorted.marked.bam
65 | rm ${SPIKEDIR}${SAMPLE}.sorted.bam
66 |
--------------------------------------------------------------------------------
/scripts/bigwig.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | ## This bash script provides a means of generating scaled strand-specific BIGWIG files from a BAM file containing paired reads.
4 |
5 | # Adapted from:
6 | # *Ramírez, Fidel, Devon P. Ryan, Björn Grüning, Vivek Bhardwaj, Fabian Kilpert, Andreas S. Richter, Steffen Heyne, Friederike Dündar, and Thomas Manke.*
7 | # *deepTools2: A next Generation Web Server for Deep-Sequencing Data Analysis. Nucleic Acids Research (2016). doi:10.1093/nar/gkw257.*
8 | # *https://deeptools.readthedocs.io/en/develop/content/tools/bamCoverage.html*
9 |
10 | # Dependencies:
11 | # SAMtools http://samtools.sourceforge.net/
12 | # deepTools https://deeptools.readthedocs.io/en/develop/index.html
13 |
14 |
15 | #### Set working, temporary and results directories.
16 | WORKDIR="/path/to/my/working_directory/"
17 | TMPDIR="${WORKDIR}tmp/"
18 | BIGWIGDIR="${WORKDIR}bigwig/"
19 | mkdir -p $TMPDIR
20 | mkdir -p $BIGWIGDIR
21 |
22 |
23 | #### Sample information: sample name and BAM file location.
24 | SAMPLE="WT";
25 | BAM="${WORKDIR}WT.bam"
26 |
27 |
28 | #### Threads - set to take advantage of multi-threading and speed things up.
29 | THREADS=1
30 |
31 |
32 | #### Temporaty BAM files.
33 | BAMFOR="${TMPDIR}${SAMPLE}.fwd.bam" # BAM file representing reads mapping to forward strand
34 | BAMREV="${TMPDIR}${SAMPLE}.rev.bam" # BAM file representing reads mapping to reverse strand
35 | BAMFOR1="${TMPDIR}${SAMPLE}.fwd1.bam"
36 | BAMFOR2="${TMPDIR}${SAMPLE}.fwd2.bam"
37 | BAMREV1="${TMPDIR}${SAMPLE}.rev1.bam"
38 | BAMREV2="${TMPDIR}${SAMPLE}.rev2.bam"
39 |
40 |
41 | #### bigwig files.
42 | BIGWIG="${BIGWIGDIR}${SAMPLE}.bigwig" # BIGWIG file representing all reads
43 | BIGWIGFOR="${BIGWIGDIR}${SAMPLE}.for.bigwig" # BIGWIG file representing reads mapping to forward strand
44 | BIGWIGREV="${BIGWIGDIR}${SAMPLE}.rev.bigwig" # BIGWIG file representing reads mapping to reverse strand
45 |
46 | #### Scale factor.
47 | # A scale factor is used to normalise for differences in library sizes across samples. There are many ways to generate such a factor, such as the ratio of reads between two samples of spike-ins. A more robust scale factor may be calculated using the "estimateSizeFactors" function from the Bioconductor package DESeq2 using sample gene count information. Setting this to 1 indicates no scaling. Note that it is necessary to use the recipricol of the the scale factor returned by DESeq2 when passing to the bamCoverage function since coverage will be multiplied by this.
48 | SCALEFACTOR=1
49 |
50 |
51 | #### Create bigwig file for all reads.
52 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAM -o $BIGWIG
53 |
54 |
55 | #### Create bigwig file for the forward strand.
56 | # Get file for transcripts originating on the forward strand.
57 | # Include reads that are 2nd in a pair (128). Exclude reads that are mapped to the reverse strand (16)
58 | # Exclude reads that are mapped to the reverse strand (16) and first in a pair (64): 64 + 16 = 80
59 | samtools view -b -f 128 -F 16 --threads $THREADS $BAM > $BAMFOR1
60 | samtools view -b -f 80 --threads $THREADS $BAM > $BAMFOR2
61 | samtools merge --threads $THREADS -f $BAMFOR $BAMFOR1 $BAMFOR2
62 | samtools index $BAMFOR
63 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAMFOR -o $BIGWIGFOR
64 |
65 |
66 | #### Create bigwig file for the reverse strand.
67 | # Get the file for transcripts that originated from the reverse strand:
68 | # Include reads that map to the reverse strand (128) and are second in a pair (16): 128 + 16 = 144
69 | # Include reads that are first in a pair (64), but exclude those ones that map to the reverse strand (16)
70 | samtools view -b -f 144 --threads $THREADS $BAM > $BAMREV1
71 | samtools view -b -f 64 -F 16 --threads $THREADS $BAM > $BAMREV2
72 | samtools merge --threads $THREADS -f $BAMREV $BAMREV1 $BAMREV2
73 | samtools index $BAMREV
74 | bamCoverage --scaleFactor $SCALEFACTOR -p $THREADS -b $BAMREV -o $BIGWIGREV
75 |
76 |
77 | #### Remove temporary files.
78 | rm $BAMFOR $BAMFFOR1 $BAMFFOR2 $BAMREV $BAMREV1 $BAMREV2
79 |
--------------------------------------------------------------------------------
/scripts/bigwig_bedtools.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 | ## This bash script provides a means of generating scaled strand-specific BIGWIG files from a BAM file containing paired reads.
4 |
5 | # This alternative to "bigwig.sh" uses bedtools (Quinlan, *et al* 2014) rather than deeptools to generate bedgraph files which are in turn converted to bigwig format via Jim Kent's BigWig and BigBed tools (kent, *et al*, 2010). It is better able to deal with large bam files.
6 |
7 | # Dependencies:
8 | # SAMtools http://samtools.sourceforge.net/
9 | # bedtools https://bedtools.readthedocs.io/en/latest/
10 | # kentUtils http://bioinformatics.oxfordjournals.org/content/26/17/2204.long
11 |
12 |
13 | #### Set working, temporary and results directories.
14 | WORKDIR="/path/to/my/working_directory/"
15 | TMPDIR="${WORKDIR}tmp/"
16 | BIGWIGDIR="${WORKDIR}bigwig/"
17 | mkdir -p $TMPDIR
18 | mkdir -p $BIGWIGDIR
19 |
20 | #### Sample information: sample name and BAM file location.
21 | SAMPLE="WT";
22 | BAM="${WORKDIR}${SAMPLE}.sorted.marked.bam"
23 |
24 | #### Chromosome size information. An unheadered, two-column tab-delimited text file:
25 | CHRSIZE="${WORKDIR}chrom.sizes.txt"
26 |
27 | #### Threads - set to take advantage of multi-threading and speed things up.
28 | THREADS=8
29 |
30 | #### Temporaty BAM files.
31 | BAMFOR="${TMPDIR}${SAMPLE}.fwd.bam" # BAM file representing reads mapping to forward strand
32 | BAMREV="${TMPDIR}${SAMPLE}.rev.bam" # BAM file representing reads mapping to reverse strand
33 | BAMFOR1="${TMPDIR}${SAMPLE}.fwd1.bam"
34 | BAMFOR2="${TMPDIR}${SAMPLE}.fwd2.bam"
35 | BAMREV1="${TMPDIR}${SAMPLE}.rev1.bam"
36 | BAMREV2="${TMPDIR}${SAMPLE}.rev2.bam"
37 |
38 | #### bedgraph files.
39 | BEDGRAPH="${TMPDIR}${SAMPLE}.bedgraph" # BEDGRAPH file representing all reads
40 | BEDGRAPHFOR="${TMPDIR}${SAMPLE}.for.bedgraph" # BEDGRAPH file representing reads mapping to forward strand
41 | BEDGRAPHREV="${TMPDIR}${SAMPLE}.rev.bedgraph" # BEDGRAPH file representing reads mapping to reverse strand
42 |
43 | #### Sorted bedgraph files.
44 | BEDGRAPHSORTED="${TMPDIR}${SAMPLE}.sorted.bedgraph" # Sorted BEDGRAPH file representing all reads
45 | BEDGRAPHFORSORTED="${TMPDIR}${SAMPLE}.for.sorted.bedgraph" # Sorted BEDGRAPH file representing reads mapping to forward strand
46 | BEDGRAPHREVSORTED="${TMPDIR}${SAMPLE}.rev.sorted.bedgraph" # Sorted BEDGRAPH file representing reads mapping to reverse strand
47 |
48 | #### bigwig files.
49 | BIGWIG="${BIGWIGDIR}${SAMPLE}.bigwig" # BIGWIG file representing all reads
50 | BIGWIGFOR="${BIGWIGDIR}${SAMPLE}.for.bigwig" # BIGWIG file representing reads mapping to forward strand
51 | BIGWIGREV="${BIGWIGDIR}${SAMPLE}.rev.bigwig" # BIGWIG file representing reads mapping to reverse strand
52 |
53 | #### Scale factor.
54 | SCALEFACTOR=1
55 |
56 | #### Create bigwig file for all reads.
57 | bedtools genomecov -ibam $BAM -bg -split -scale $SCALEFACTOR > $BEDGRAPH
58 | sort -k1,1 -k2,2 $BEDGRAPH > $BEDGRAPHSORTED
59 | bedGraphToBigWig $BEDGRAPHSORTED $CHRSIZE $BIGWIG
60 |
61 | #### Create bigwig file for the forward strand.
62 | samtools view -b -f 128 -F 16 --threads $THREADS $BAM > $BAMFOR1
63 | samtools view -b -f 80 --threads $THREADS $BAM > $BAMFOR2
64 | samtools merge --threads $THREADS -f $BAMFOR $BAMFOR1 $BAMFOR2
65 | samtools index $BAMFOR
66 | bedtools genomecov -ibam $BAMFOR -bg -split -strand + -scale $SCALEFACTOR > $BEDGRAPHFOR
67 | sort -k1,1 -k2,2 $BEDGRAPHFOR > $BEDGRAPHFORSORTED
68 | bedGraphToBigWig $BEDGRAPHFORSORTED $CHRSIZE $BIGWIGFOR
69 |
70 | #### Create bigwig file for the reverse strand.
71 | samtools view -b -f 144 --threads $THREADS $BAM > $BAMREV1
72 | samtools view -b -f 64 -F 16 --threads $THREADS $BAM > $BAMREV2
73 | samtools merge --threads $THREADS -f $BAMREV $BAMREV1 $BAMREV2
74 | samtools index $BAMREV
75 | bedtools genomecov -ibam $BAMREV -bg -split -strand - -scale $SCALEFACTOR > $BEDGRAPHREV
76 | sort -k1,1 -k2,2 $BEDGRAPHREV > $BEDGRAPHREVSORTED
77 | bedGraphToBigWig $BEDGRAPHREVSORTED $CHRSIZE $BIGWIGREV
78 |
79 | #### Remove temporary files.
80 | rm $BAMFOR $BAMFFOR1 $BAMFFOR2 $BAMREV $BAMREV1 $BAMREV2 $BEDGRAPH $BEDGRAPHFOR $BEDGRAPHREV $BEDGRAPHSORTED $BEDGRAPHFORSORTED $BEDGRAPHREVSORTED
81 |
--------------------------------------------------------------------------------
/scripts/metaprofiles.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 |
3 |
4 | ## This bash script provides a means of generating strand-specific metagene, TSS and TES profiles from a BAM file using "ngs.plot".
5 |
6 | # *Of course, this will only work if your libraries were created in a strand-specific fashion.*
7 |
8 | # Shen, L.*, Shao, N., Liu, X. and Nestler, E. (2014).
9 | # ngs.plot: Quick mining and visualization of next-generation sequencing data by integrating genomic databases, BMC Genomics, 15, 284.
10 | # https://github.com/shenlab-sinai/ngsplot
11 |
12 | # Dependencies:
13 | # SAMtools http://samtools.sourceforge.net/
14 | # ngs.plot https://github.com/shenlab-sinai/ngsplot
15 |
16 |
17 | #### Set working, temporary and results directories.
18 | WORKDIR="/path/to/my/working_directory/"
19 | TMPDIR="${WORKDIR}tmp/"
20 | PROFDIR="${WORKDIR}metaprofiles/"
21 | mkdir -p $TMPDIR
22 | mkdir -p $PROFDIR
23 |
24 |
25 | #### Sample information: sample name and BAM file location.
26 | SAMPLE="WT";
27 | BAM="${WORKDIR}WT.bam"
28 | MATE1="${WORKDIR}WT.mate1.bam"
29 |
30 |
31 | #### Threads - set to take advantage of multi-threading and speed things up.
32 | THREADS=1
33 |
34 | #### Restict to first mate reads.
35 | # If the BAM file contains paired reads, create a new version containing only the first mate reads.
36 | # This step may be skipped if your reads are not paired.
37 | samtools view --threads $THREADS -h -b -f 64 $BAM -o $MATE1
38 | samtools index $MATE1
39 |
40 |
41 | #### BAM header compliance.
42 | # It might be necessary to re-header the BAM file so that the chromosome names match those in the ngs.plot database, e.g. standard chromosomes preceeded with "chr" for hg38. This is most easily achieved using SAMtools "reheader" function.
43 | # For human hg38 Ensembl alignments the following steps should do the job.
44 | # This step may be skipped if your header is already compliant.
45 | MATE1REHEADER="${WORKDIR}WT.mate1.reheader.bam"
46 | samtools view --threads $THREADS -H ${MATE1} | sed -e 's/SN:\([0-9XY]*\)/SN:chr\1/' -e 's/SN:MT/SN:chrM/' | samtools reheader - ${MATE1} > ${MATE1REHEADER}
47 | samtools index ${MATE1REHEADER}
48 |
49 |
50 | #### Run ngs.plot.
51 | # Finally, use ngs.plot to create sense and anti-sense profiles for your regions of interest using the correct BAM file.
52 | # Note that if your libraries were produced such that mate2 represents the forward strand the sense/anti-sense profiles will be reversed.
53 | ## Genebody
54 | REGION="genebody"
55 | for STRAND in both same opposite
56 | do
57 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
58 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
59 | done
60 |
61 | ## TSS
62 | REGION="tss"
63 | for STRAND in both same opposite
64 | do
65 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
66 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
67 | done
68 |
69 | ## TES
70 | REGION="tes"
71 | for STRAND in both same opposite
72 | do
73 | OUTPUT="${PROFDIR}${SAMPLE}.${REGION}.${STRAND}"
74 | ngs.plot.r -G hg38 -R $REGION -C ${MATE1REHEADER} -O $OUTPUT -P $THREADS -SS $STRAND -SE 1 -L 5000 -F chipseq -D ensembl
75 | done
76 |
77 |
78 | #### Combining sense and anti-sense profiles
79 | # By default ngs.plot produces average profiles in .pdf format. There is also a zip file containing the underlying data, This may be used to combine the sense and anti-sense profiles on a single set of axes. This is best achieved using R.
80 |
81 |
82 | #### Scaling the profiles
83 | # A scale factor may be used to normalise for differences in library sizes across samples. There are many ways to generate such a factor, such as the ratio of reads between two samples of spike-ins. A more robust scale factor may be calculated using the "estimateSizeFactors" function from the Bioconductor package DESeq2 using sample gene count information.
84 |
85 | # The scale factor may be used to modify the number of valid reads discovered in the BAM file given in the resulting ".cnt" file. Edit this file to multiply read count by your scale factor and re-run ngs.plot using the same parameters.
86 |
87 |
88 | #### Custom genes / intervals
89 | # Profiles may be restricted to specific gene sets and also to user-defined intervals. See the ngs.plot documentation for further details.
90 | # https://github.com/shenlab-sinai/ngsplot
91 | # https://github.com/shenlab-sinai/ngsplot/wiki/ProgramArguments101
92 |
--------------------------------------------------------------------------------