Albluca / rpgraph

An r package to compute princial graphs
GNU General Public License v3.0
2 stars 1 forks source link

Error while following vignette #1

Closed gonzaparra closed 7 years ago

gonzaparra commented 7 years ago

I have followed the vignette. I installed rJava and rgraph. It seems these two libraries were successfully installed, since I don't get any message when loading them.

I have executed the following lines and got the following error (Any help?)

`library(rpgraph) library(rJava)

Data <- simple_circle Results <- computeElasticPrincipalGraph(Data = Data, NumNodes = 40, Method = 'CircleConfiguration') summary(Results)

plotMSDEnergyPlot(Results, Main = "Pincipal Circle", Cex.Main = 1)`

Error in plot(STEP, MSEP, type = "b", col = "blue", ylim = c(0, max(c(MSEP, : object 'STEP' not found

Thanks in advance

Gonzalo

Albluca commented 7 years ago

Many thanks you for interest in the package and for your comment. I've recently introduced a few changes to the package to deal with incremental construction of the principal graphs and unfortunately the vignette is not up to date. Sorry about that. I will fix it later today.

Basically, in the newest version "Results" is a list, which can potentially contain more than one principal graph.

You will be able to reproduce the results by simply selecting the first element of the list, i.e. by replacing "Results" with "Results[[1]]". Another change that I introduced is the requirement for a factor type vector in a couple of functions. The following code should be working in the current version of the package:

library(rpgraph) Data <- simple_circle Results <- computeElasticPrincipalGraph(Data = Data, NumNodes = 40, Method = 'CircleConfiguration') plotMSDEnergyPlot(Results[[1]], Main = "Pincipal Circle", Cex.Main = 1) accuracyComplexityPlot(Results[[1]], Main = "Pincipal Circle", Cex.Main = 1, Mode = 5) accuracyComplexityPlot(Results[[1]], Main = "Pincipal Circle", Cex.Main = 1, Xlims = c(.97, .98)) plotData2D(Data = simple_circle, PrintGraph = Results[[1]], GroupsLab = rep(1, nrow(simple_circle)), Xlab = "Dimension 1", Ylab = "Dimension 2")

plotData2D(Data = simple_circle, PrintGraph = Results[[1]], Plot.ly = TRUE, GroupsLab = rep(1, nrow(simple_circle)))

plotData3D(Data = simple_circle, PrintGraph = Results[[1]], Plot.ly = TRUE, GroupsLab = rep(1, nrow(simple_circle)), NodeSizeMult = 0.05, Xlab = "Dimension 1", Ylab = "Dimension 2", Zlab = "Dimension 3")

Net <- ConstructGraph(Results = Results[[1]], DirectionMat = NULL, Thr = 0.05) TaxonList <- getTaxonMap(Results = Results[[1]], Data = Data)

InfoData <- plotPieNet(Results = Results[[1]], Data = simple_circle, NodeSizeMult = 4, Categories = factor(sample(1:3, nrow(simple_circle), replace = TRUE)), Graph = Net, TaxonList = TaxonList, LayOut = 'circle', Main = "Pincipal Circle")

gonzaparra commented 7 years ago

Many thanks @Albluca !!! :)

All the code works perfectly, except for the 3Dplot.

This line: plotData3D(Data = simple_circle, PrintGraph = Results[[1]], Plot.ly = TRUE, GroupsLab = rep(1, nrow(simple_circle)), NodeSizeMult = 0.05, Xlab = "Dimension 1", Ylab = "Dimension 2", Zlab = "Dimension 3")

gives me the following error:

Error in PrintGraph[[1]]$Edges : $ operator is invalid for atomic vectors

Sorry if this is too basic, but I am not that proficient with R.

Thanks again!

Gonzalo

gonzaparra commented 7 years ago

In addition to the last question, I have the following one.

In the other repository, with the matlab implementation, the wiki says that it is possible to give an initialization topology G for the calculations.

Is it possible to give as an input a precomputed tree that I already calculate by other method, that I can then optimize using RGraph?

The specific need I have is that given a topology, with let's say 5 final nodes, and 5 branches, I want to prevent the creation of new branches in the optimization. If that is not possible, is it possible to limitate the number of resulting branches?

Best and thanks again!

Gonzalo

Albluca commented 7 years ago

Hi Gonzalo,

don't worry, I'm glad to get a feedback! I'm a bit puzzled by the plotting error, do you have plotly installed? Also could you please type "Results[[1]]$Edges" at the R console? It should give you a matrix containing information on the edges. I will have a closer look at the code tomorrow in reach of potential issues.

As for your other question, the answer is yes. You can provide an initial topology. The feature was not documented, but it is there. I included a simple example in the context of the circle. Basically you need the coordinate of the points and the edges between them. The coordinates have to be encoded in a matrix where each row represents a point and each column represents a dimension (See Results[[1]]$Nodes for an example). The Edges are encoded by 2 column matrix: the first column indicate the index of the node at one end of the edge and the second column indicate other one (See Results[[1]]$Edges for an example).

You will have to update the package though for this to work, as I noticed that I had the wrong library on github. You will get a warning when you first call the java function, but you can ignore it.

As for your specific need, if you use a tree as an initial topology and then use 'CurveConfiguration' as a method in the principal graph computation function it should give you exactly what you want as the grammar associated with a principal curve will not create any new branching point. This is an example:

Data <- simple_tree

Results <- computeElasticPrincipalGraph(Data = Data, NumNodes = 20, Method = 'DefaultPrincipalTreeConfiguration')

plotData2D(Data = simple_tree, PrintGraph = Results[[1]], GroupsLab = rep(1, nrow(simple_circle)), Xlab = "Dimension 1", Ylab = "Dimension 2")

ResultsExt <- computeElasticPrincipalGraph(Data = Data, NumNodes = 50, NodesPositions = Results[[1]]$Nodes, Edges = Results[[1]]$Edges, Method = 'CurveConfiguration')

plotData2D(Data = simple_tree, PrintGraph = ResultsExt[[1]], GroupsLab = rep(1, nrow(simple_circle)), Xlab = "Dimension 1", Ylab = "Dimension 2")

Controlling the number of branching points is a bit more complex to do and would require you to write some additional code. Basically you should use the tree configuration a node at the time, until you have the required number of branches and then use the curve configuration.

BW, Luca

gonzaparra commented 7 years ago

Hi Luca,

Thanks again for your answer!

I have installed the plotly library, both for python2 and python3.

When I load the library I get the following:

Loading required package: ggplot2 Attaching package: ‘plotly’ The following object is masked from ‘package:ggplot2’:

last_plot

The following object is masked from ‘package:stats’:

filter

The following object is masked from ‘package:graphics’:

layout

This is the first part for the Results[[1]]$Edges:

Results[[1]]$Edges [,1] [,2] [1,] 8 12 [2,] 13 6 [3,] 7 14 [4,] 18 19 [5,] 11 22 [6,] 14 24 [7,] 15 5 [8,] 15 9 [9,] 15 21 [10,] 26 27

I will try now your advices about the topology initialization.

Thanks again!

Gonzalo


R. Gonzalo Parra, PhD EMBO Postdoctoral Fellow Quantitative and Computational Biology Group http://www.mpibpc.mpg.de/de/soeding Max Planck Institute for Biophysical Chemistry Am Fassberg 11 37077, Göttingen, Germany

2016-12-05 22:39 GMT+01:00 Luca Albergante notifications@github.com:

Hi Gonzalo,

don't worry, I'm glad to get a feedback! I'm a bit puzzled by the plotting error, do you have plotly installed? Also could you please type "Results[[1]]$Edges" at the R console? It should give you a matrix containing information on the edges. I will have a closer look at the code tomorrow in reach of potential issues.

As for your other question, the answer is yes. You can provide an initial topology. The feature was not documented, but it is there. I included a simple example in the context of the circle. Basically you need the coordinate of the points and the edges between them. The coordinates have to be encoded in a matrix where each row represents a point and each column represents a dimension (See Results[[1]]$Nodes for an example). The Edges are encoded by 2 column matrix: the first column indicate the index of the node at one end of the edge and the second column indicate other one (See Results[[1]]$Edges for an example).

You will have to update the package though for this to work, as I noticed that I had the wrong library on github. You will get a warning when you first call the java function, but you can ignore it.

As for your specific need, if you use a tree as an initial topology and then use 'CurveConfiguration' as a method in the principal graph computation function it should give you exactly what you want as the grammar associated with a principal curve will not create any new branching point. This is an example:

Data <- simple_tree

Results <- computeElasticPrincipalGraph(Data = Data, NumNodes = 20, Method = 'DefaultPrincipalTreeConfiguration')

plotData2D(Data = simple_tree, PrintGraph = Results[[1]], GroupsLab = rep(1, nrow(simple_circle)), Xlab = "Dimension 1", Ylab = "Dimension 2")

ResultsExt <- computeElasticPrincipalGraph(Data = Data, NumNodes = 50, NodesPositions = Results[[1]]$Nodes, Edges = Results[[1]]$Edges, Method = 'CurveConfiguration')

plotData2D(Data = simple_tree, PrintGraph = ResultsExt[[1]], GroupsLab = rep(1, nrow(simple_circle)), Xlab = "Dimension 1", Ylab = "Dimension 2")

Controlling the number of branching points is a bit more complex to do and would require you to write some additional code. Basically you should use the tree configuration a node at the time, until you have the required number of branches and then use the curve configuration.

BW, Luca

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Albluca/rpgraph/issues/1#issuecomment-264985715, or mute the thread https://github.com/notifications/unsubscribe-auth/AGDtRGXtZX8kbvMSiLKgiWkCtlP-4uasks5rFISqgaJpZM4LEYcW .

gonzaparra commented 7 years ago

Dear Luca,

The problem with the 3Dplot was solved when I updated the library from the github.

However, for the topology initialization I use the following line: ResultsExt <- computeElasticPrincipalGraph(Data = Data, NumNodes = length(SkeletonNodes), NodesPositions = SkeletonCoords, Edges = SkeletonEdges, Method = 'CurveConfiguration')

Data has the coordinates for the points in my data. SkeletonNodes is a subset of n points from Data that I will give as a topology initialization. SkeletonCoords in a matrix (nx3) that for each element in SkeletonNodes has the 3D coordinates. SkeletonEdged, has the connectivity for the TopologyInitialization. I initialize NumNodes with length(SkeletonNodes)

I get the following error: Configuring engine ......[1] "Data-dependent initialization" Error in cpg$setPrimitiveGraphByNodesAndEdges : no field, method or inner class called 'setPrimitiveGraphByNodesAndEdges'

Maybe some function was not correctly updated?

Best

Gonzalo

Albluca commented 7 years ago

Dear Gonzalo,

I'm glad that the 3d functions are working now. BTW I also updated the readme file and now it contains more information on combining topologies. I also included an example with trees containing a fixed number of branches.

In the function "NumNodes" represents the number of the nodes that will be present in the final principal graph. If I understand correctly, this number will be the same as the the nodes already present and therefore no operation will be performed as the algorithm optimizes the position of the points only when new nodes are being added. Basically you want NumNodes to be larger than the number of rows of NodesPositions if you want the algorithm to do anything.

The error sounds like a Java problem and seems to suggests that the VDAOEngine was not updated. It's kind of annoying and appended to me before. Basically, I think that when you updated the package, the old VDAOEngine.jar file was not updated due to a compilation issue.

One way to fix the problem would be to replace the file manually. If you type "library()" in the R prompt you will get the list of packages installed with their installation directory. If you go into the library directory containing rpgraph and open the rpgraph directory. You will see a number of files and directories that constitute the package. A this point if you open the "java" directory, you should see a single file named "VDAOEngine.jar". Just delete it and replace it with this one: https://github.com/Albluca/rpgraph/blob/master/inst/java/VDAOEngine.jar (note that you have to open the link and then push the download button, save as does not work on github).

Alternatively, if you uninstall the package and then reinstall it should work.

Let me know if this works and thanks for testing the package :)

Best wishes, Luca

gonzaparra commented 7 years ago

Dear Luca,

I reinstalled the package and updated the libraries and everything works perfectly. I tried the calculations using an initial topology from my own and it works really nice!

Thank you very much for your assistance and for setting such a nice R package. I hope I can do something useful out of it, soon!

Best regards,

Gonzalo

gonzaparra commented 7 years ago

Dear Luca,

I have been using the rpgraph package really nicely. Unfortunately, I had to update my R version. I installed everything again, and now I got the java error again:

Error in cpg$setPrimitiveGraphByNodesAndEdges : no field, method or inner class called 'setPrimitiveGraphByNodesAndEdges'

Was maybe something updated in the code or something? The code I tried to execute was:

EmbeddedTree <- computeElasticPrincipalGraph(Data = Matrix, NumNodes = 100, NodesPositions = NodesCoordinates, Edges = NodesEdges, Method = 'CurveConfiguration')

I tried to do the same you suggested me last time about updating the VDAOEngine.jar file and reinstalling but it still does not work.

Any suggestion? might it be related to the R version?

thanks!

Gonzalo

gonzaparra commented 7 years ago

Dear Luca,

I have fixed this by using the package version I have saved when I downloaded it for the first time. It seems some update is producing this error.

Albluca commented 7 years ago

Hi Gonzalo,

thank you for your comment and sorry for not replying before, I had to change my computer and I am a bit behind with some stuff. I was trying to slim down the jar file containing the java functions, but ended up including the wrong version of some library unfortunately ...

I will fix the problem very soon (probably in a couple of hours).

BW, Luca