Importing a bed file
1
@d27434d9
Last seen 3.6 years ago
United States
fname <- file.choose() #C:\Users\reach\Downloads\CpGislands.Hsapiens.hg38.UCSC.bed.gz
file.exists(fname)
[1] TRUE
cpg <- import(fname)
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
scan() expected 'an integer', got 'chr1'
rtracklayer
• 2.1k views
@james-w-macdonald-5106
Last seen 1 day ago
United States
You need to make one more step, which is to ensure that you change the output format field to Bed format on the UCSC website before you download the table. This will open one more webpage that asks you some questions. After which it works as advertised:
> import("../Downloads/CpGislands.Hsapiens.hg38.UCSC.bed.gz")
UCSC track 'tb_cpgIslandExt'
UCSCData object with 31144 ranges and 1 metadata column:
seqnames ranges strand | name
<Rle> <IRanges> <Rle> | <character>
[1] chr1 155188537-155192004 * | CpG:_361
[2] chr1 2226774-2229734 * | CpG:_366
[3] chr1 36306230-36307408 * | CpG:_110
[4] chr1 47708823-47710847 * | CpG:_164
[5] chr1 53737730-53739637 * | CpG:_221
... ... ... ... . ...
[31140] chr22_KI270734v1_ran.. 131010-132049 * | CpG:_102
[31141] chr22_KI270734v1_ran.. 161257-161626 * | CpG:_55
[31142] chr22_KI270735v1_ran.. 17221-18098 * | CpG:_100
[31143] chr22_KI270738v1_ran.. 4413-5280 * | CpG:_80
[31144] chr22_KI270738v1_ran.. 6226-6467 * | CpG:_34
-------
seqinfo: 332 sequences from an unspecified genome; no seqlengths
Login before adding your answer.
Traffic: 532 users visited in the last hour
An alternative that might be more useful would be to download directly and make a
GRanges
object.Depending on whether or not you care about the extra information you can add.
This worked! Thanks!