IRanges output length not equal to input

23 views Asked by At

I want create a IRanges with a exists data.table

ranges <- IRanges::IRanges(
        start = x$position,
        wdith = 1
    )

length(ranges)
[1] 31253

However, My data.table is a table with 31548 line

> dim(x)
[1] 31548     8

also x$position length is

> length(x$position)
[1] 31548
1

There are 1 answers

0
zhang On

I found that this is because of many duplicated value in x$position

sum(duplicated(x$position))
[1] 13998

But I am trying to create a GRanges by:

GenomicRanges::GRanges(
    seqnames = x$contig,
    ranges = IRanges::IRanges(
        start = x$position,
        wdith = 1
    )

In fact each duplicated x$position have different x$chrom value, but IRanges::IRanges remove them, so its not work.

My bypass solution is use makeGRangesFromDataFrame instead