convert bedgraph to vector file and Granges list
0
0
Entering edit mode
19 months ago
storm1907 ▴ 30

Hello, I have a probem when converting bedgraph files to Granges list

I use this R script:

library("GenomicRanges")
bg_files <- c("file1.bedgraph", "file2.bedgrah")
bgs <- lapply(bg_files, function(x) {
  bg <- read.table(x, sep="\t", skip=1)
  colnames(bg) <- c("seqnames", "start", "end", "value")
  gr <- makeGRangesFromDataFrame(bg, ignore.strand=TRUE, keep.extra.columns=TRUE)
  return(gr)
})
# Convert the list of GRanges into a GRangesList.
gr_list <- GRangesList(bgs)

However, the output is a dataframe. The downstream software does not accept dataframes, only numeric vectors:

if (!(is.numeric(seg) || is.data.frame(seg))) {
    stop("Wrong representation of segments.")
}

if (is.vector(seg))
    seg = t(seg)

How could I get Grange list from bedgraph files in vector format?

Thank you!

vectors Granges R bedgraph • 1.2k views
ADD COMMENT
0
Entering edit mode

What downstream software and function are you trying to use? A GRanges list and a numeric vector are two very different data types.

ADD REPLY
0
Entering edit mode
ADD REPLY
0
Entering edit mode

I am not familiar with the package, but the How to obtain Cytoband and Stain Information and Prepare input data for CINdex documents didn't help?

Have you already tried to replace the convenience function makeGRangesFromDataFrame() with a manually constructed GRanges object?

gr <- GRanges(bg$seqnames, IRanges(bg$start, bg$end), as.numeric(bg$value)) 

Also, it could be related to this statement in the manual?

NOTE: At this time, the CINdex package can only accept segmentation data where probes are in the autosomes (Chromosome 1 - 22). Please remove segment data in the X, Y and mitochondrial chromosomes before input to CINdex.

ADD REPLY
0
Entering edit mode

Thank you for your reply!

in CIndex package, nothing much was told about sample data preparation, only "The result of any segmentation algorithm such as CBS,FMR. Should be a data frame of 3 column-lists or matrix of three-column lists; Grange list"

I have vcf, bam and bedgraph files available. I tried to make grange list from vcf and failed; now I was suggested to use this custom script to make grange list from bedgraph, and result is also not accepted by CINdex

library("GenomicRanges")
bg_files <- c("file1.bedgraph", "file2.bedgrah")
bgs <- lapply(bg_files, function(x) {
  bg <- read.table(x, sep="\t", skip=1)
  colnames(bg) <- c("seqnames", "start", "end", "value")
  gr <- makeGRangesFromDataFrame(bg, ignore.strand=TRUE, keep.extra.columns=TRUE)
  return(gr)
})
# Convert the list of GRanges into a GRangesList.
gr_list <- GRangesList(bgs)
ADD REPLY
0
Entering edit mode

Thank for this function:

gr <- GRanges(bg$seqnames, IRanges(bg$start, bg$end), as.numeric(bg$value)) 

I tried, but keep getting errors, how do I prepare bg variable in this case?

ADD REPLY
0
Entering edit mode

Then please copy and paste the error message(s) here, so we can help. The output or an excerpt of the output from str(bg) might be useful for that as well.

The CIndex package does have info on sample data preparation. I was referring to the documents, that I already linked above: How To Download Cytoband Info and Prepare Input Data.

ADD REPLY
0
Entering edit mode

Hello!

the manual was suitable for preparing probe annotation, reference and clinical data files; However, I could not use it for sample file preparation (2.1. Segment data), as the example only says "The CINdex package can accept output from ANY segmentation alggorithm, as long as the data are in the form of a GRangesList object", but does not demonstrate, how to obtain it from bam or vcf, or bedgraph file, which are available for me

THe error is following:

> bgs <- lapply(bg_files, function(x) {
+     bg <- read.table(x, sep="\t", skip=1)
+     colnames(bg) <- c("seqnames", "start", "end", "value")
+     gr <- makeGRangesFromDataFrame(bg, ignore.strand=TRUE, keep.extra.columns=TRUE)
+     return(gr)
+ })
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'X' in selecting a method for function 'lapply': object 'bg_files' not found
> bg_files <- c("file1.bedgraph", "file2.bedgraph")
> bgs <- lapply(bg_files, function(x) {
+     bg <- read.table(x, sep="\t", skip=1)
+     colnames(bg) <- c("seqnames", "start", "end", "value")
+     gr <- makeGRangesFromDataFrame(bg, ignore.strand=TRUE, keep.extra.columns=TRUE)
+     return(gr)
+ })
> gr <- GRanges(bg$seqnames, IRanges(bg$start, bg$end), as.numeric(bg$value)) 
Error in IRanges(bg$start, bg$end) : object 'bg' not found
> gr <- GRanges(bgs$seqnames, IRanges(bgs$start, bgs$end), as.numeric(bgs$value)) 
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘strand’ for signature ‘"numeric"’
ADD REPLY

Login before adding your answer.

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