Genomic Ranges: Convert from 0-base to 1-base
1
0
Entering edit mode
Zach Roe ▴ 10
@zach-roe-11189
Last seen 4.0 years ago

I have bed files that are 0-based. Before I do a mergeOverlaps with another granges object that is 1-based, I need to convert the first to 1-base. The shift command moves the whole range by a specific number of base pairs, but I only want to add 1 to the start.

Is there an one line command in GenomicRanges to do this?

library(GenomicRanges)
library(rtracklayer)

# 0-based
bed <- import(file.path(bed.dir, bed.filename), format="bed")

# shift
bed1 <- shift(bed, 1)

bed
> GRanges object with 454075 ranges and 1 metadata column:
>            seqnames            ranges strand |        name
>               <Rle>         <IRanges>  <Rle> | <character>
>        [1]    chr10           1-94200      * |    15_Quies
>        [2]    chr10       94201-96600      * |       9_Het
>        [3]    chr10      96601-119800      * |    15_Quies
>        [4]    chr10     119801-120400      * |      1_TssA
>        [5]    chr10     120401-122000      * |      5_TxWk
>        ...      ...               ...    ... .         ...   [454071]     chrY 58993401-58997200      * |  8_ZNF/Rpts   [454072]     chrY
> 58997201-59001800      * |       9_Het   [454073]     chrY
> 59001801-59002400      * |  8_ZNF/Rpts   [454074]     chrY
> 59002401-59033400      * |       9_Het   [454075]     chrY
> 59033401-59373400      * |    15_Quies   -------   seqinfo: 25
> sequences from an unspecified genome; no seqlengths

bed1
> GRanges object with 454075 ranges and 1 metadata column:
>            seqnames            ranges strand |        name
>               <Rle>         <IRanges>  <Rle> | <character>
>        [1]    chr10           2-94201      * |    15_Quies
>        [2]    chr10       94202-96601      * |       9_Het
>        [3]    chr10      96602-119801      * |    15_Quies
>        [4]    chr10     119802-120401      * |      1_TssA
>        [5]    chr10     120402-122001      * |      5_TxWk
>        ...      ...               ...    ... .         ...   [454071]     chrY 58993402-58997201      * |  8_ZNF/Rpts   [454072]     chrY
> 58997202-59001801      * |       9_Het   [454073]     chrY
> 59001802-59002401      * |  8_ZNF/Rpts   [454074]     chrY
> 59002402-59033401      * |       9_Het   [454075]     chrY
> 59033402-59373401      * |    15_Quies
GenomicRanges • 1.4k views
ADD COMMENT
2
Entering edit mode
@michael-lawrence-3846
Last seen 2.4 years ago
United States

If you are using rtracklayer::import(), then it has already done this for you. Just look at your data; the first range already starts with 1.

But in case you need to do this in the future, just set the start:

start(bed) <- start(bed) + 1L

Btw, the above transformation only makes sense if the data are 0-based and half open.

ADD COMMENT
0
Entering edit mode

Thanks! I missed that, I only checked that my bed files started at 0 and assumed rtracklayer imports as is.

ADD REPLY

Login before adding your answer.

Traffic: 769 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6