why makeGRangesFromDataFrame don't do the IRange
1
2
Entering edit mode
michela ▴ 20
@216f0d39
Last seen 2.0 years ago
Netherlands

I have a dataframe with 4 columns:

chromosome start end score and for each columns I have multiple rows, like this:

seqnames start end V5 1 chrI 1540683 1540683 6.33554 2 chrI 1838049 1838049 2.81938 3 chrI 2706245 2706245 4.10906

I want to trasform my dataframe in a GRanges object so I try with makeGRangesFromDataFrame


neuron_gr <- makeGRangesFromDataFrame(neuron_df, keep.extra.columns = TRUE)

but my neuron_gr don't have a IRange valid, is like this:

>neuron_gr
GRanges object with 176 ranges and 1 metadata column:
        seqnames    ranges strand |        V5
           <Rle> <IRanges>  <Rle> | <numeric>
    [1]     chrI   1540683      * |   6.33554
    [2]     chrI   1838049      * |   2.81938
    [3]     chrI   2706245      * |   4.10906

I only have the start number and not the range in IRanges.

I also try with this command:

gr <- GRanges(seqnames=neuron_df$seqnames,
              ranges = IRanges(neuron_df$start, end=neuron_df$end),
              strand = Rle(strand(c(rep("*", length(neuron_df$strand))))),
              Conc = neuron_df$V5)

but it dosen't work neither How I can solve this problem? Thank you

HELP HelloRanges • 1.5k views
ADD COMMENT
1
Entering edit mode
@james-w-macdonald-5106
Last seen 6 hours ago
United States

Please remember to put your code between triple backticks. When you start a post it does say this:

Enter the body of text here

Code should be placed in three backticks as shown below


# include your problematic code here with any corresponding output 
# please also include the results of running the following in an R session 

sessionInfo( )

Which seems to be pretty clear? I don't know how we could make it any clearer, but please let us know if there is something confusing about that.

Anyway, your IRanges is perfectly fine. Your positions are all one base, and that is what a one-base GRanges object looks like.

ADD COMMENT
0
Entering edit mode

Yep, like here:

> GRanges("chrI", IRanges(start=11:14, width=c(5,1:3)))
GRanges object with 4 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chrI     11-15      *
  [2]     chrI        12      *
  [3]     chrI     13-14      *
  [4]     chrI     14-16      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

Note that if all your ranges are one-base, then you can coerce the GRanges object to a GPos object:

> gr <- GRanges("chrI", IRanges(start=11:14, width=1))
> gr
GRanges object with 4 ranges and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chrI        11      *
  [2]     chrI        12      *
  [3]     chrI        13      *
  [4]     chrI        14      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

> as(gr, "GPos")
UnstitchedGPos object with 4 positions and 0 metadata columns:
      seqnames       pos strand
         <Rle> <integer>  <Rle>
  [1]     chrI        11      *
  [2]     chrI        12      *
  [3]     chrI        13      *
  [4]     chrI        14      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

See ?GPos for more information.

ADD REPLY
0
Entering edit mode

I do it but the matrix is still empty

ADD REPLY
0
Entering edit mode

What does that mean, exactly? What is 'the matrix' in this context? What do you mean when you say 'I do it'. Do what? It's best to pretend that you are talking to people who know nothing about what you are doing, and you need to supply all necessary information for them to help you.

ADD REPLY

Login before adding your answer.

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