This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bioconductor R And Input File Issue

I'm using Gviz library from bioconductor. I input a tab delimited file containing CNV position that I need to plot on my chromosome ideogram.

My input file is defined by dat and has 4 columns

  • [1] chromosome
  • [2] start
  • [3] end
  • [4] width (could '+' or '-' depending on the orientation of the Copy Number)

So I did that :

 library(IRanges)
 libraray(Gviz)
 gen <- "mm9"
 chr <- "chr1"

 itrack <- IdeogramTrack(genome = gen, chromosome = chr)
 gtrack <- GenomeAxisTrack()

 dat <- read.delim("C:/R/1ips_chr1.txt", header = FALSE, sep ="\t")
 s <- dat[,2] # need to select col 2 this way
 e <- dat[,3]
 l <- dat[,4]
 s[s>e] <- e # start < end?
 l <- abs(l) # no negative length allowed

It shows an error message when I call the file dat to determine start and width (or end) position of the Copy Number:

 # an annotation is made from a ranges object
 atrack1 <- AnnotationTrack(IRanges( start = s, width = l) , chromosome = chr, genome = gen, name =  "Sample1")
 Error : function (classes, fdef, mtable)  : unable to find an inherited method for function ".buildRange", for signature "NULL", "data.frame", "NULL", "data.frame"

I'm a R newbie, please someone tell me how to use columns within an input file !

Thanks :)

r

1 answer

I have edited your code, you were missing some , in a matrix, columns are selected like this.

Edit to deal with negative width and start>stop issues try to insert this code before making the annotation track:

s[s>e] <- e
e <- abs(e)

Oh thanks! BTW .. We have a lot of negative width .. if I invert the start and end position this is gonna be a pain. Is there a way to pass negative value to IRange ?

You must make sure your width is not negative, and that start < end, otherwise:

IRanges(start=10,width=-3) Error in .Call2("solve_user_SEW0", start, end, width, PACKAGE = "IRanges") : solving row 1: negative widths are not allowed

I inverted start and end whenever we have a negative width, that worked like a charm! Thanks :)

Log in to answer this question.