Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON file not opening in Cystoscape desktop #1018

Closed
nandankita opened this issue Jul 24, 2015 · 20 comments
Closed

JSON file not opening in Cystoscape desktop #1018

nandankita opened this issue Jul 24, 2015 · 20 comments
Assignees

Comments

@nandankita
Copy link

Hi,
I have generated the JSON of my image by calling,
cy.json()

It returns the JSON, which I am saving in a file. I tried to open my JSON file, which has "preset layout" and "compound nodes"; in Cytoscape(Version: 3.2.1) Desktop version, but it doesn't open. I suppose the user who is generating the JSON, will want to open the JSON file in Cytoscape and try to render it there.
It doesn't even show any error while trying to open in cytoscape(Version: 3.2.1). Please refer the attachment for details. Please let me know if you need any more clarifications on this or if I need to change anything in my code.

Thanks,
Ankita

screen shot 2015-07-24 at 2 12 26 pm

screen shot 2015-07-24 at 2 21 41 pm

@maxkfranz
Copy link
Member

@keiono Could you take a look at this? The user might not be generating the JSON your plugin expects, but there should probably be an error message either way.

Maybe it makes sense to move this ticket to Cytoscape desktop.

@keiono
Copy link
Member

keiono commented Jul 24, 2015

I'll try and see what happens. The output JSON file looks fine to me, so it can be an Cytoscape Desktop issue.

@keiono
Copy link
Member

keiono commented Jul 24, 2015

What happens if you manually add "data" element in the JSON?

{
data: {name: 'foo'},
elements: [],
.
.
.
}

@nandankita
Copy link
Author

I tried manually adding the data in JSON as follow:

{"elements": {
"nodes": [
{ "data": { "id": "a"} },
{ "data": { "id": "b" } },
{ "data": { "id": "c"} },
{ "data": { "id": "d" } },
{ "data": { "id": "e" } },
{ "data": { "id": "f"} }
],
"edges": [
{ "data": { "id": "ad", "source": "a", "target": "d" } },
{ "data": { "id": "eb", "source": "e", "target": "b" } }

]

}
}

And tried opening it in Cytoscape desktop, but the same thing happens, an error dialogue box without any error message. Does Cytoscape desktop need different parameters? or anything else needs to be included in this JSON?

@keiono
Copy link
Member

keiono commented Jul 24, 2015

Oh, sorry. I mean adding data:{} for network, not nodes/edges.

{
"data": {"name": "my network name" },
elements:[ . . .]
}

This defines name of the network, etc. Cytoscape Desktop depends on that network-level information, and it maybe the cause of this issue.

@nandankita
Copy link
Author

Okay sorry, I misunderstood it. So I generated a JSON from Cytoscape desktop as follow:
{
"format_version" : "1.0",
"generated_by" : "cytoscape-3.2.1",
"target_cytoscapejs_version" : "~2.1",
"data" : {
"shared_name" : "My Network",
"name" : "My Network",
"SUID" : 104,
"__Annotations" : [ ],
"selected" : true
},
"elements" : {
"nodes" : [ {
"data" : {
"id" : "114",
"shared_name" : "Node1",
"name" : "a",
"SUID" : 114,
"selected" : false
},
"position" : {
"x" : 0.0,
"y" : 0.0
},
"selected" : false
} ],
"edges" : [ ]
}
}

I manually edited it to as follow:
{
"data" : {
"name" : "My Network",
},
"elements" : {
"nodes" : [ {
"data" : {
"id" : "1",
"name" : "a",
},
} ],
"edges" : [ ]
}
}

But the edited version doesn't work. I think that a manual version of JSON won't work with Cytoscape desktop, since it needs all those parameters. But on the other hand if I am generating a JSON from Cytoscape.js that should be supported in desktop version as well. Or I would request a feature in Cytoscape.js to have a function which can generate the JSON, exactly as supported by the desktop version.

@maxkfranz
Copy link
Member

Firstly: @nandankita I think you're running into a separate bug, that Cytoscape desktop errors out if you give it a graph with only one node (or just several nodes). This happens for sure with JSON import, but possibly other formats as well. Try adding two nodes and an edge.

Secondly: @keiono Is it not possible to support import/export of vanilla JSON in Cy desktop, e.g. cy.json() and cy.elements().jsons()? All that desktop metadata, like SUID could be automatically generated for the user.

@maxkfranz
Copy link
Member

@keiono This may mean that an extra check may be needed in the importer. elements may be a map of arrays of elements: { nodes: [ ... ], edges: [ ... ] } or one array elements: [ { group: 'nodes', ... }, { group: 'edges', ... }, ... ]. The export can use either style.

@keiono
Copy link
Member

keiono commented Jul 27, 2015

@maxkfranz

Yes, I think the JSON reader in Cytoscape desktop should seamlessly work with Cytoscape.js outputs. I've just added new ticket:

https://code.cytoscape.org/redmine/issues/3213

Will be fixed in the next release.

@keiono
Copy link
Member

keiono commented Jul 27, 2015

OK, I think I found the issue.

CYtoscape JSON reader is very strict because it uses default settings for Jackson JSON library for Java, and it does not allow comma at the end of elements in array. for example, this does NOT work:

[
    "name": "foo",
]

but this does:

[
    "name": "foo"
]

And here is the fixed JSON:

https://gist.github.com/b96057b9ea11c2602317

Hope this helps.

@nandankita
Copy link
Author

Thank you @keiono & @maxkfranz. This is a great help! This new JSON file works perfectly fine with Cytoscape desktop.

Thanks a lot for responding so quickly on this!

@nandankita
Copy link
Author

I tried with the JSON file generated by cy.json(). If we manually add the data, i.e.
{
"data": {"name": "My Network"},
"elements":{}
}
we can open the file in Cytoscape desktop, but only the issue is that it doesn't import the exact layout and colors which is there with cytoscape.js.

Hope the next version will address this issue.

Thanks!

@keiono
Copy link
Member

keiono commented Jul 27, 2015

The cy.json() exports both Style and network topology in a single JSON. Instead, Cytoscape Desktop handle those as two separate files. Also, Cytoscape desktop can export both Styles and networks, but cannot read Cytoscape.js CSS-like styles because it is VERY different from Styles for Cytoscape desktop. This is a current limitation in this feature.

@maxkfranz
Copy link
Member

@nandankita To clarify: Importing styles into Cy desktop will probably not be possible in the general case. The model of Cy desktop for style is analogous to a very simple stylesheet:

node {
  ...
}

edge {
  ...
}

Since Cy.js can support stylesheets with an arbitrary number of selector blocks and Cy desktop has no notion of selectors, compatibility for styles from Cy.js-to-Cy3 is not really possible.

You could try making your stylesheet very, very simple and putting cy.style().json() into a style JSON exported by Cy3. No guarantees, though.

As for separation of JSONs from Cy.js, it's all in what you call:

  • cy.json() : whole graph state
  • cy.style().json() : stylesheet only
  • cy.elements().jsons() : graph elements only

@maxkfranz
Copy link
Member

Closing for now as this seems to be OK for @nandankita

@nandankita
Copy link
Author

Yeah it's good for me. Thank you so much for your help and explanation.

@keiono
Copy link
Member

keiono commented Sep 3, 2015

I've pushed changes for Cytoscape 3.3.0 development branch. I confirmed that new version reads both outputs from:

  • cy.json()
  • cy.elements().jsons()

Style conversion from Cytoscape.js to Cytoscape 3.x is way too complicated and not implemented (yet?).

You can try the nightly build if you try this new feature before 3.3.0 release:

@bramson
Copy link

bramson commented Mar 4, 2019

I know it's a few years later, but I tried loading a JSON that was generated by NetworkX and I got the same blank error message shown in the first screenshot. Is there still no way to get Cytoscape to open my standard JSON file?

@maxkfranz
Copy link
Member

maxkfranz commented Mar 4, 2019

@bramson Would you please post the problematic JSON file in the Cytoscape desktop issue tracker in order to help reproduce the issue? What version of the Cytoscape desktop app are you using?

@maxkfranz
Copy link
Member

@bramson Here's the link to report a bug in the Cytoscape desktop issue tracker: https://cytoscape.org/bug-report.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants