[Bioc-devel] GenomicRanges: Concatenation of GRanges with matrices in mcols
Hervé Pagès
hpages at fhcrc.org
Tue May 20 21:52:43 CEST 2014
On 05/20/2014 12:49 PM, Hervé Pagès wrote:
> Hi Julian,
>
> At the root of the problem is what rbind() does on DataFrames containing
> matrices:
>
> m <- matrix(1:4, nrow=2)
> df <- DataFrame(m=I(m))
> df2 <- rbind(df, df)
>
> Then:
>
> > df2
> DataFrame with 8 rows and 1 column
> m
> <matrix>
> 1 1 3
> 2 2 4
> 3 1 3
> 4 2 4
>
> > nrow(df2)
> [1] 8
>
> Too many rows!
>
> > str(df2)
> Formal class 'DataFrame' [package "IRanges"] with 6 slots
> ..@ rownames : NULL
> ..@ nrows : int 12
> ..@ listData :List of 1
> .. ..$ m: int [1:6, 1:2] 1 2 3 1 2 3 4 5 6 4 ...
> ..@ elementType : chr "ANY"
> ..@ elementMetadata: NULL
> ..@ metadata : list()
Sorry, I mixed up outputs from different sessions. Correct str() output:
> str(df2)
Formal class 'DataFrame' [package "IRanges"] with 6 slots
..@ rownames : NULL
..@ nrows : int 8
..@ listData :List of 1
.. ..$ m: int [1:4, 1:2] 1 2 1 2 3 4 3 4
..@ elementType : chr "ANY"
..@ elementMetadata: NULL
..@ metadata : list()
H.
>
> > validObject(df2)
> [1] TRUE
>
> I'll leave this to Michael.
>
> Thanks,
> H.
>
>
> On 05/20/2014 01:22 AM, Julian Gehring wrote:
>> Hi,
>>
>> If I want to bind two GRanges object with a matrix in the meta columns,
>> the concatenation of the two fails in bioc-stable (GenomicRanges 1.16.3)
>> and bioc-devel (GenomicRanges 1.17.13) with:
>>
>> '''
>> Error in validObject(.Object) :
>> invalid class “GRanges” object: number of rows in DataTable
>> 'mcols(x)' must match length of 'x'
>> '''
>>
>> If multiple columns are used, the class of of the first column seem to
>> determine the behavior:
>>
>> #+BEGIN_SRC R
>> library(GenomicRanges)
>>
>> ## sample data, two identical GRanges
>> gr1 = gr2 = GRanges(1, IRanges(1:2, width = 1))
>> m = matrix(1:4, 2)
>>
>> ## the vector alone works
>> mcols(gr1) = mcols(gr2) = DataFrame(x = 1)
>> c(gr1, gr2) ## works
>>
>> ## vector first, matrix second works
>> mcols(gr1) = mcols(gr2) = DataFrame(x = 1, m = I(m))
>> c(gr1, gr2) ## works
>>
>> ## the matrix alone fails
>> mcols(gr1) = mcols(gr2) = DataFrame(m = I(m))
>> c(gr1, gr2) ## fails
>>
>> ## matrix first, vector second fails
>> mcols(gr1) = mcols(gr2) = DataFrame(m = I(m), x = 1)
>> c(gr1, gr2) ## fails
>> #+END_SRC
>>
>> Best wishes
>> Julian
>>
>> _______________________________________________
>> Bioc-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
--
Hervé Pagès
Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024
E-mail: hpages at fhcrc.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioc-devel
mailing list