如何将 .sif 文件转换为 json 以便在 Cytoscape JS 中使用

How to convert .sif file to json to be used in Cytoscape JS

我有一个这样的 .sif 文件

NodeA   "phosphorylation"   NodeB
NodeA   "binding"       NodeC
NodeB   "phosphorylation"   NodeC
NodeD   "binding"       NodeC

我需要将其转换为 JSON,Cytoscape JS 可以使用它来使用节点及其关系生成图表。

我需要的格式是这样的

[
    {"data":{"id":"n40","weight":53},"position":     
    {"x":50,"y":45},"group":"nodes","removed":false,"selected":false,
    "selectable":true,"locked":false,"grabbable":true,"classes":""},

    {"data":{"id":"n41","weight":23},"position":     
    {"x":150,"y":45},"group":"nodes","removed":false,
    "selected":false,"selectable":true,"locked":false,
    "grabbable":true,"classes":""},

    ..........................

    {"data":{"id":"e129","weight":31,"source":"n65","target":"n58"},
    "position":{},"group":"edges","removed":false,"selected":false,
    "selectable":true,"locked":false,"grabbable":true,"classes":""},

    {"data":{"id":"e131","weight":90,"source":"n53","target":"n43"},
    "position:{},"group":"edges","removed":false,"selected":false,
    "selectable":true,"locked":false,"grabbable":true,"classes":""},
]

你试过SIF.js了吗?我在 npm 上找到了它:https://www.npmjs.com/package/sif.js

它与 Cytoscape 的 JSON 格式不完全相同,但您可以使用它和 .map() the entries just a bit so that they match. Or you could use the code in the repo to build your own parsing function that directly outputs the Cytoscape format

您也可以使用 Cytoscape desktop software 将 SIF 转换为 JSON,但这不能作为 JS 应用程序的一部分自动完成。