rtracklayer::import for signature "GFFFile,ANY,ANY" has an argument text, the help page says:
## S4 method for signature 'GFFFile,ANY,ANY'
import(con, format, text,
version = c("", "1", "2", "3"),
genome = NA, colnames = NULL, which = NULL,
feature.type = NULL, sequenceRegionsAsSeqinfo = FALSE)
text: If con is missing, a character vector to use as the input.
But the argument does not seem to work, in fact I have looked into the source https://github.com/Bioconductor-mirror/rtracklayer/blob/1d5b9b3979d277b1dfd5642fd714d7c7bc75ca84/R/gff.R#L233-L296 , it does not seem to support that argument. In my case, I have already read the file using readLines to check the hash, and I do not want to re-read file again or write it to a temporary file then import it. Is there any way to import gff from a character vector?
For a reproducible example I went to ?import and found a gff3 file. I read it in using readLines, and then read the date using the text connection
> test_path <- system.file("tests", package = "rtracklayer")
> test_gff3 <- file.path(test_path, "genes.gff3")
> gff = readLines(test_gff3)
> gr = import(format="gff3", text=gff)
Warning in readGFF(filepath, version = version, filter = filter) :
connection is not positioned at the start of the file, rewinding it
The warning seems harmless. Here's my sessionInfo()
Sorry, Martin, it was my fault, I was using
import.gff
and thought the arguments are passed toimport
, your example works for me. Thanks!