This is a test version of Biostars. For the public version, visit https://www.biostars.org.
separating dataset by a specific character

I downloaded a .bed file and converted it using this https://genome.ucsc.edu/cgi-bin/hgLiftOver now I want to load the converted file "datahg38.bed" in R using this code

   library(rtracklayer)
dataset<-import.bed("datahg38.bed")

and I get this error

error : $ operator is invalid for atomic vectors

any ideas how to fix this ?

so I found out that the output format is a list of 300,000 by 1 which should be a table of 300,000 of 3 variables

the format is something like this

chr1:10142-10351
chr1:10453-10563
chr1:13044-13104
.
.
.

so basically I need to read it as a table with read.table and then convert it to a matrix of 300,000 of 3 . and character : , - should be used to split data. I'm looking for an output like this

 chr1  10142  10351
 chr1  10453  10563
 chr1  13044  13104
 ...

so can anyone please suggest an efficient way to separate this data?

r

Why not convert the bed file to a more suitable format using linux? Something like

cat datahg38.bed | tr "\:" "\t" | tr "-" "\t" > datahg38_format.bed

1 answer

Basically your BED file is not a BED file, so you need to convert it:

perl -pe 's/:/\t/; s/-/\t/' < datahg38.bed > datahg38_realBED.bed

Log in to answer this question.