phasing: Count the number of aligned reads per read length per frame

Description Usage Arguments Value Author(s) Examples

Description

This function counts the number of reads in the [[ribo]] list for all genes and returns a data frame with the number of reads per read length per frame.

Usage

1
phasing(data, genedf, cores = 1, plot = F)

Arguments

data

object returned by read_profiling_data

genedf

data frame with the start and stop coordinated of the ORFs in the transcriptome.

cores

integer, how many threads to use. See details.

plot

logical whether to plot the results, defaults to F.

Value

Returns a molten data frame that has the number of reads per read length per frame.

Currently PSOCK multithreadding is not supported. For Windows set cores to 1. For operating systems that support forking the number of threads that are used can be set by the cores argument. If the cores>1 then the data is processed by mclapply instead of lapply.

Author(s)

Alper Celik

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, genedf, cores = 1, plot = F)
{
    genes <- genedf$gene
    ribo <- data[["ribo"]]
    get_phasing <- function(gene) {
        orf <- ribo[[gene]]
        if (is.null(orf)) {
            orf <- NULL
            orf
        }
        else {
            features <- genedf[genedf$gene == gene, ]
            orf <- orf[orf$codon > 0 & orf$codon < features$ncodon,
                c(1, 2, 4)]
            orf
        }
    }
    if (cores > 1) {
        orfs <- do.call("rbind", mclapply(genes, get_phasing,
            mc.cores = cores))
    }
    else {
        orfs <- do.call("rbind", lapply(genes, get_phasing))
    }
    phasing <- reshape2::dcast(data = orfs, width ~ frame, fun.aggregate = sum)
    colnames(phasing) <- c("read_length", "frame_0", "frame_1",
        "frame_2")
    phasing$read_length <- as.factor(phasing$read_length)
    phasing <- reshape2::melt(phasing)
    colnames(phasing) <- c("read_length", "frame", "number_of_reads")
    if (plot) {
        print(ggplot(phasing, aes(x = read_length, y = number_of_reads,
            fill = frame)) + geom_bar(stat = "identity", position = "dodge"))
    }
    invisible(phasing)
  }

celalp/ribofootprintR documentation built on May 12, 2019, 12:04 p.m.