Closed thomaskelder closed 10 years ago
I read up a bit more about the options here, and I can't find a way to force any R json library to always print digits for a double (even if it's a round number). Both RJSONIO, rjson and jsonlite do not have an option for this. Besides, JSON doesn't distinguish between integers and doubles, the output is valid json. So I would argue to fix this on the Cytoscape part, e.g. by always treating numeric attributes as double in json (since JavaScript also only has doubles as number type, not integers). Alternatively, there could a an additional "type" option in the json format to force the type of the attribute?
Confirmed the bug. I think this can be resolved in Cytoscape side.
The actual parser is in the core, and need to be fixed in the next version (which will be released next month):
https://code.cytoscape.org/redmine/issues/2808
Also, an alternative is supporting GraphSON in addition to Cytoscape.js format.
https://github.com/tinkerpop/blueprints/wiki/GraphSON-Reader-and-Writer-Library
Is there any reason not to support GraphSON?? … at least via a format parameter on the REST request?
If this is the right approach, it can be implemented later.
From: Keiichiro Ono [mailto:notifications@github.com] Sent: Wednesday, August 27, 2014 7:23 PM To: idekerlab/cy-rest-R Subject: Re: [cy-rest-R] doubles printed as integers in JSON makes network upload fail (#3)
The actual parser is in the core, and need to be fixed in the next version (which will be released next month):
https://code.cytoscape.org/redmine/issues/2808
Also, an alternative is supporting GraphSON in addition to Cytoscape.js format.
https://github.com/tinkerpop/blueprints/wiki/GraphSON-Reader-and-Writer-Library
— Reply to this email directly or view it on GitHub https://github.com/idekerlab/cy-rest-R/issues/3#issuecomment-53666215 . https://github.com/notifications/beacon/3696094__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNDgxMTc1NSwiZGF0YSI6eyJpZCI6NDAxNjE0MDd9fQ==--377584332c79fca6b8618717c45ac967fe355d54.gif
There are two approaches for this problem:
Since there is no side-effect adding more information to the data object in Cytoscape.js JSON, we can add Cytoscape-dependent data in the JSON file like:
{
"data": {
"dataTables":[
"nodeDefault": [
{ "columnName": "SUID", "type": "Long"}, ...
]
]
},
"elements": {
"nodes":[...],
"edges":[...]
}
}
Also, there is no side effect for this solution, although the data is a bit redundant (all entries have its own data type tag). But I have no objection to adding support.
https://github.com/keiono/cy-rest/issues/17 https://github.com/keiono/cy-rest/issues/18
As a reasonably OK solution for now, I'll update the core code to handle numbers as double if no data type is available. This change is for the core (3.2.0).
By the way, this is not the complete solution, but even for current version, here is a workaround for R users:
In R, it is this simple:
write.graph(test, "test.graphml", "graphml")
file.url <- paste(base.url, "networks?source=url", sep="/")
fullpath <- normalizePath("test.graphml")
file.list = paste("[\"file://", fullpath, "\"]", sep="")
res <- POST(url=file.url, body=file.list, encode="json")
result <- unname(fromJSON(rawToChar(res$content)))
Of course, you can send multiple files at once. This POST method DOES NOT send actual file contents. Just send a list of resources (URLs) and Cytoscape read the files from that resources.
Fixed in the core. By default, all numbers will be handed as Double. If optional columnTypes object is available as a network property, it will be used to set the data type.
See https://code.cytoscape.org/redmine/issues/2808
This fix will be available from Cytoscape 3.2.0.
Uploading a network to Cytoscape fails when there is a node/edge attribute with doubles, but the first occurence(s) are whole numbers (even when their storage mode is not "integer").
Here is a short R script to reproduce:
It gives me the following error on the final line:
When looking at the JSON output, is seems that the problem is that whole numbers are printed without decimals and hence parsed as integer by Cytoscape. Subsequent values that do have decimals, will then trigger an error (since the attribute type has been fixed as integer at that point).
I tried forcing the toJSON function to add decimals always in case of a numerical attribute, but couldn't find a way to do this.