Question: IRanges object from count matrix
gravatar for Assa Yeroslaviz
2.8 years ago by
Assa Yeroslaviz1.4k
Munich, Germany
Assa Yeroslaviz1.4k wrote:


is there a way to automatically convert the featureCounts result matrix into a GRanges (IRanges) object? by feeding it into GRanges?

I ran featureCounts for the data set and have this matrix (first 5 columns):

              Chr      Start        End  Strand Length
ENSMUSG00000102693    1    3073253    3074322    +   1070
ENSMUSG00000064842    1    3102016    3102125    +    110
ENSMUSG00000102851    1    3252757    3253236    +    480
ENSMUSG00000103377    1    3365731    3368549    -   2819
ENSMUSG00000104017    1    3375556    3377788    -   2233

When I am trying to do it, I get the following error, that GRanges can't understand negative values. I guess the problem occurs with the reverse strand where the start position is smaller than the end position of the gene. 

countsTable <- read.delim2(file = "../featureCounts/featureCounts.geneLevel.txt", 
                           header = TRUE, sep = "\t", quote = "", skip = 1, 
                           row.names = 1 )
geneRanges <- GRanges(seqnames = countsTable$Chr,
                      ranges = IRanges(start = as.numeric(countsTable$Start), 
                                       end = as.numeric(countsTable$End)),
                      strand = countsTable$Strand

Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : 
  solving row 2: negative widths are not allowed

thanks in advance for any suggestions



ADD COMMENTlink modified 2.8 years ago by Hervé Pagès ♦♦ 14k • written 2.8 years ago by Assa Yeroslaviz1.4k
Answer: IRanges object from count matrix
gravatar for Hervé Pagès
2.8 years ago by
Hervé Pagès ♦♦ 14k
United States
Hervé Pagès ♦♦ 14k wrote:

Hi Assa,

Looks like you have a data.frame, not a matrix. You can call makeGRangesFromDataFrame() on it to turn it into a GRanges object. You might want to call the function with keep.extra.columns=TRUE to preserve the Length column. See ?makeGRangesFromDataFrame for the details.

Note that the start/end of a genomic feature are always its 5' and 3' ends with respect to the plus strand, even for a feature that belongs to the minus strand. That means that the start position should always be smaller than the end position, whatever the strand is. The only exception to this is for a zero-length feature where end = start - 1.


ADD COMMENTlink written 2.8 years ago by Hervé Pagès ♦♦ 14k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 290 users visited in the last hour