error with RBGL package in R - r

I want to install the RGBL package in bioconductor to perform some graph algorithms.
I updated R to the latest version 3.2.0, and installed the package as instructed on http://www.bioconductor.org/
source("http://bioconductor.org/biocLite.R")
biocLite("RBGL")
It was installed successfully, then I tried to run
library(graph)
library(RBGL)
x<- strongComp(graph)
and returns this error
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘isDirected’ for signature ‘"igraph"’
Here's the traceback
> traceback()
4: stop(gettextf("unable to find an inherited method for function %s for signature %s",
sQuote(fdef#generic), sQuote(cnames)), domain = NA)
3: (function (classes, fdef, mtable)
{
methods <- .findInheritedMethods(classes, fdef, mtable)
if (length(methods) == 1L)
return(methods[[1L]])
else if (length(methods) == 0L) {
cnames <- paste0("\"", vapply(classes, as.character,
""), "\"", collapse = ", ")
stop(gettextf("unable to find an inherited method for function %s for signature %s",
sQuote(fdef#generic), sQuote(cnames)), domain = NA)
}
else stop("Internal error in finding inherited methods; didn't return a unique method",
domain = NA)
})(list("igraph"), function (object)
standardGeneric("isDirected"), <environment>)
2: isDirected(g)
1: strongComp(graph)
My system is Windows 32-bit.
I'm not sure if this is enough information. Please let me know if any other information needed.
Any ideas are appreciated, thanks!
EDIT:
I used the igraph packaged to create the graph object from an edge list with weight
library(igraph)
graph<- graph.data.frame(edge.list[,c(2:4)],directed=TRUE)
I'm not very good with generating random number, here's a reproducible example for my graph
set.seed(123)
edge.list<-cbind(seq(10),c(1,1,2,3,3,4,5,5,5,5),c(2,2,3,5,4,3,4,4,4,2),
runif(10, 1, 30))
colnames(edge.list) <-c("ID","V1","V2","weight")

As pointed out in the comments, you need to make a graph object, not an igraph object.
Here's how I might transform your edge.list into the form that graph expects.
rawEL <- data.frame(source = as.character(edge.list[,1]),
edges = as.character(edge.list[,2]),
weights = edge.list[,3], stringsAsFactors=F
)
V <- unique(c(rawEL$source, rawEL$edges))
edL <- lapply(
split(
rawEL[,-1],
factor(edge.list[,1], levels=V)
), as.list
)
gr <- graphNEL(V, edL, "directed")
plot(gr)

Related

Normalization of cel. files after filtering of non-expressed genes in R

Before normalizing my data, I want to perform a filtering where genes that are not expressed are deleted. For this purpose I have specified a threshold value. I would like to do this filtering before normalizing and then normalize it.
library(limma)
library(hgu133plus2cdf)
library(affy)
library(dplyr)
library(oligo)
setwd("C:/A549_ALI/4_tert-Butanol (22)/")
data=read.celfiles(list.celfiles())
eset <- rma(data, normalize=FALSE, background=FALSE)
not_expressed_threshold <- quantile(exprs(eset),0.1)
not_expressed <- exprs(eset) < not_expressed_threshold
not_expressed_2 <- rownames(exprs(eset))[not_expressed]
celfiles_filtered <- eset[!rownames(eset) %in% not_expressed_2, ]
cat("Dimensions of celfiles:", dim(eset), "\n")
cat("Dimensions of celfiles_filtered:", dim(celfiles_filtered), "\n")
eset_ <- rma(celfiles_filtered, normalize=FALSE, background=FALSE)
I get this error message:
Error in (function (classes, fdef, mtable) :
cannot find inherited method for function 'rma' for signature '"ExpressionSet"'.
I tried to filter data directly and then normalize it, but it didn't work either. Thanks for any reply.

unable to find an inherited method for function 'distance' for signature '"matrix", "character"', but it's a df?

Here is all my code leading up to the function as per #Till request!
library("phyloseq")
library("qiime2R")
library("vegan")
# read in phyloseq objects from qiime
physeq<-qza_to_phyloseq(
features="~/Documents/qiime2-analyses/CRD/fresh_run/table.qza",
tree="~/Documents/qiime2-analyses/CRD/fresh_run/rooted-tree.qza",
"~/Documents/qiime2-analyses/CRD/fresh_run/taxonomy.qza",
metadata = "crd-metadata.txt")
# Clean out unwanted taxa annotations. Base script removes endozoicimonaceae, escherischia,
# and shigella contaminates
physeq <- subset_taxa(physeq, Family!="f__Endozoicimonaceae")
physeq <- subset_taxa(physeq, Family!="f__Enterobacteriaceae")
physeq <- subset_taxa(physeq, Family!="f__mitochondria")
physeq <- subset_taxa(physeq, Class!="c__Chloroplast")
#pull out otu table
otu_table <- (as.data.frame(otu_table(physeq)))
# rotate otu matrix layout
rownames(otu_table) <- factor(rownames(otu_table), levels = rownames(otu_table))
otu_ord <- as.data.frame(t(otu_table[rowSums(otu_table)!=0, ]))
# remove any rows or columns with only 0s
otu_ord <- otu_ord[, colSums(otu_ord !=0)>0]
otu_ord <- otu_ord[rowSums(otu_ord[])>0,]
#edits from observations of this StO chat
rownames(otu_ord) <- gsub("sample-", "", rownames(otu_ord))
rownames(otu_ord) <- as.numeric(rownames(otu_ord))
otu_ord <- as.matrix(otu_ord)
#the args of the function
raup_crick_abundance = function(spXsite=otu_ord, plot_names_in_col1=TRUE,
classic_metric=FALSE, split_ties=TRUE,
reps=9999, set_all_species_equal=FALSE,
as.distance.matrix=TRUE, report_similarity=FALSE){
Please note the whole function is verbatim from Stegen_etal_ISME_2013 github linked below and here.
I am receiving the error
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘distance’ for signature ‘"matrix", "character"’
Called from: (function (classes, fdef, mtable)
{
methods <- .findInheritedMethods(classes, fdef, mtable)
if (length(methods) == 1L)
return(methods[[1L]])
else if (length(methods) == 0L) {
cnames <- paste0("\"", vapply(classes, as.character,
""), "\"", collapse = ", ")
stop(gettextf("unable to find an inherited method for function %s for signature %s",
sQuote(fdef#generic), sQuote(cnames)), domain = NA)
}
else stop("Internal error in finding inherited methods; didn't return a unique method",
domain = NA)
})(list("matrix", "character"), new("nonstandardGenericFunction",
.Data = function (physeq, method, type = "samples", ...)
{
standardGeneric("distance")
}, generic = "distance", package = "phyloseq", group = list(),
valueClass = character(0), signature = c("physeq", "method",
"type"), default = NULL, skeleton = (function (physeq, method,
type = "samples", ...)
stop("invalid call in method dispatch to 'distance' (no default method)",
domain = NA))(physeq, method, type, ...)), <environment>)
Browse[1]> traceback()
No traceback available
within this function linked here.
My argument is a data.frame (dput() below) with no character strings? As I understand it, the error is saying the function distance () can't be calculated with matrix or character strings, which I agree with...
Therefore, I am unsure why distance () cannot operate with my arg, if I am interpreting the error correctly.
Thank you.
Here is my Qiime2 OTU table.qza linked to this Dropbox file, my rooted tree linked here, and my taxonomy linked here to recreate my phyloseq object.
What the error message is actually trying to get across is that your matrix has character values and the function you called can not handle it. The first column in data.frame is a character column.
If your data frame is called ex_otu_ord, try this:
ex_otu_ord <- ex_otu_ord[-1]
ex_otu_ord <- as.matrix(ex_otu_ord)
Then try again to call the function on ex_otu_ord.

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘values’ for signature ‘"hash"’

I'm looking to create keys and then pull all the values onto one list, however, when I try to pull the values I'm getting this error:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘values’ for signature ‘"hash"’
Not sure if its a formatting issue or something. Here's my current code:
myMarkersList <- hash("Neuron", c("Snap25","Meg3"))
myMarkersList$GABAergic <- c("Ndnf","Vip")
myMarkersList$Microglia <- c("Ctss","Csf1r")
myMarkersList$Astrocytes <- c("Gfap","Aqp4")
myMarkersList$Endothelial <- c("Xdh","Flt1")
myMarkersList$OPC <- c("Pdgfra")
myMarkersList$Oligodendrocyte <- c("Opalin","Olig1")
myMarkersList$Glutamatergic <- c("Ptgs2", "Ngb")
myGenesList <- values(myMarkersList)
myMarkers <-c()
I get the error in trying to create myGenesList

unable to find an inherited method for function 'saveXML' for signature '"XMLDocument"'

Can anywone tell me why this code:
filename3 = "restaurants.xml"
if (!file.exists(filename3)) csv <- download.file("https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml", filename3, "curl")
if (!exists("data3")) data3 <- xmlRoot(xmlTreeParse(filename3, useInternalNodes = TRUE))
zips <- xpathSApply(data3, "//zipcode", xmlValue)
is giving me the error:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'saveXML' for signature '"XMLDocument"'
Thank you.

Use of xpathSApply function in R

I am learning R now and faced these errors while using xpathSApply().
doc=xmlTreeParse("http://www.w3schools.com/xml/simple.xml")
xpathSApply(node,"//name",xmlValue)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘saveXML’ for signature ‘"character"’
and
doc2=htmlTreeParse("http://espn.go.com/nfl/team/_/name/bal/baltimore-ravens")
scores=xpathSApply(doc2,"//li[#class='score]",xmlValue)
Error in UseMethod("xpathApply") :
no applicable method for 'xpathApply' applied to an object of class "XMLDocumentContent"
How to resolve it.
Please refer to the xmlParse and htmlParse functions. Description:
‘xmlParse’ and ‘htmlParse’ are equivalent to the ‘xmlTreeParse’
and ‘htmlTreeParse’ respectively, except they both use a default
value for the ‘useInternalNodes’ parameter of ‘TRUE’, i.e. they
working with and return internal nodes/C-level nodes. These can
then be searched using XPath expressions via ‘xpathApply’ and
‘getNodeSet’.
My solution:
xml.file <- xmlParse( file = "http://www.w3schools.com/xml/simple.xml")
names <- xpathSApply( doc = xml.file
, path = "//name"
, fun = xmlValue
)
[1] "Belgian Waffles" "Strawberry Belgian Waffles" "Berry-Berry Belgian Waffles" "French Toast" "Homestyle Breakfast"
Then, for the ESPN page:
html.file <- htmlParse( file = "http://espn.go.com/nfl/team/_/name/bal/baltimore-ravens")
scores <- xpathSApply( doc = html.file
, path = "//li[#class='score']"
, fun = xmlValue
)
list()
There must be something wrong with your xpath expression since it is not returning anything :).
Below code worked for me:
URL<-"https://www.w3schools.com/xml/simple.xml"
response<-GET(URL)
doc=xmlTreeParse(response,useInternalNodes = TRUE)
root<-xmlRoot(doc)
xml_names<-xpathSApply(root,"//name",xmlValue)
you probably missed to set useInternalNodes option to TRUE, when using xmlTreeParse

Resources