unexpected error when creating GRanges object by calling makeGRangesFromDataFrame()
1
0
Entering edit mode
@jurat-shahidin-9488
Last seen 4.7 years ago
Chicago, IL, USA

Hi,

Regarding bed files, peaks were called using MASC2 peak caller, and data were come from Myc transcription factor ChIP seq dataset in K562 cell available in ENCODE projects. 

first, I read bed files as data.frame object by using read.delim(), and I got this data.frame:

 df <- df <- read.delim("data/wgEncodeSydhTfbsK562CmycStdAlnRep1.bed")

I execute the above code, and I got this: 

  track.type.narrowPeak.nextItemButton.on     X   X.1         X.2  X.3
1                                    chr1 11381 11441 MACS_peak_1  3.4
2                                    chr1 11553 11612 MACS_peak_2 2.06
3                                    chr1 13055 13114 MACS_peak_3 2.06
4                                    chr1 26952 27011 MACS_peak_4 2.06
5                                    chr1 29338 29445 MACS_peak_5 9.77
6                                    chr1 32374 32450 MACS_peak_6  3.4

the text of yellow mark is not correct. how can I rename it as desired.format of data.frame object such as below :

 chrom start end strand score
1  chr1    11  12      +     1
2  chr1    12  13      -     2
3  chr1    13  14      +     3
4  chr1    14  15      *     4
5  chr1    15  16      .     5

then, I ran into strange error when I am gonna create GRanges object from makeGRangesFromDataFrame():

makeGRangesFromDataFrame(f1, TRUE)
Error in .find_start_end_cols(df_colnames0, start.field0, end.field0) : 
  cannnot determine start/end columns

how can I fix this issue? regarding my bed files, how can I get desired format of GRanges object? Thanks a lot

 

Best regards

Julaiti

 

 

r error handling granges • 4.6k views
ADD COMMENT
1
Entering edit mode

Please UPDATE YOUR QUESTION to indicate how you obtained your BED file. Usually, the way to import BED files is to use rtracklayer::import.bed().

ADD REPLY
0
Entering edit mode

Dear Mr Martin Morgan:

I have updated my questions. I want to enable user can read bed files as data.frame then make GRanges objects after all, and this is what I want to do.  Thanks a lot !!

Best regards:

Julaiti

 

ADD REPLY
0
Entering edit mode

Can you please provide a specific URL for the file that you are trying to import?

ADD REPLY
2
Entering edit mode

If you really want to use read.delim, then you're going to have to skip the UCSC track line. rtracklayer already knows how to do that and even formally represents the information from the track line. Why not just use rtracklayer?

ADD REPLY
0
Entering edit mode

Dear Mr Martin Morgan:

bed files can be available: 

 http://www.bioinformatics.deib.polimi.it/genomic_computing/MSPC/packages/ENCODE_Samples.zip

Thanks a lot

ADD REPLY
3
Entering edit mode
@herve-pages-1542
Last seen 3 days ago
Seattle, WA, United States

Hi,

The easiest way to import a BED file as a data.frame is really to import it first as a GRanges object with rtracklayer::import() and to then call as.data.frame() on the GRanges object:

library(rtracklayer)
df <- as.data.frame(import("wgEncodeSydhTfbsK562CmycStdAlnRep1.bed"))
head(df)
##   seqnames start   end width strand        name score
## 1     chr1 10000 10039    40      * MACS_peak_1  2.42
## 2     chr1 10102 10190    89      * MACS_peak_2  3.23
## 3     chr1 29304 29382    79      * MACS_peak_3  2.44
## 4     chr1 32601 32680    80      * MACS_peak_4  4.08
## 5     chr1 32727 32936   210      * MACS_peak_5 17.50
## 6     chr1 34690 34797   108      * MACS_peak_6  5.82

But that's really if you insist you want the data.frame representation. The GRanges representation is almost always a better choice.

H.

ADD COMMENT
0
Entering edit mode

Thank you very much !

ADD REPLY

Login before adding your answer.

Traffic: 503 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