Extract all parents of a given node

拈花ヽ惹草 提交于 2019-12-02 10:07:58
Bilal

Thanks to @AKSW I found a decent solution using HyperGraphQL (a GraphQL interface for querying and serving linked data on the Web).

I'll leave the detailed answer here, it may help someone.

  1. I downloaded and set up HyperGraphQL download page
  2. Linked it to EBI Sparql endpoint as described in this tutorial

    The config.json file I used:

    {
        "name": "ebi-hgql",
        "schema": "ebischema.graphql",
        "server": {
            "port": 8081,
            "graphql": "/graphql",
            "graphiql": "/graphiql"
        },
        "services": [
            {
                "id": "ebi-sparql",
                "type": "SPARQLEndpointService",
                "url": "http://www.ebi.ac.uk/rdf/services/sparql",
                "graph": "http://rdf.ebi.ac.uk/dataset/go",
                "user": "",
                "password": ""
            }
        ]
    }
    

    Here's how my ebischema.graphql file looks like (Since I needed only the Class, id, label and subClassOf):

    type __Context {
        Class:          _@href(iri: "http://www.w3.org/2002/07/owl#Class")
        id:             _@href(iri: "http://www.geneontology.org/formats/oboInOwl#id")
        label:          _@href(iri: "http://www.w3.org/2000/01/rdf-schema#label")
        subClassOf:     _@href(iri: "http://www.w3.org/2000/01/rdf-schema#subClassOf")
    }
    
    type Class @service(id:"ebi-sparql") {
        id: [String] @service(id:"ebi-sparql")
        label: [String] @service(id:"ebi-sparql")
        subClassOf: [Class] @service(id:"ebi-sparql")
    }
    
  3. I started testing some simple query, but constantly getting an empty response; the answer to this issue solved my problem.

  4. Finally I constructed the query to get the tree

    Using this query:

    {
      Class_GET_BY_ID(uris:[
        "http://purl.obolibrary.org/obo/GO_0032259",
        "http://purl.obolibrary.org/obo/GO_0007267"]) {
        id
        label
        subClassOf {
          id
          label
          subClassOf {
            id
            label
          }
        }
      }
    }
    

    I got some interesting results:

    {
      "extensions": {},
      "data": {
        "@context": {
          "_type": "@type",
          "_id": "@id",
          "id": "http://www.geneontology.org/formats/oboInOwl#id",
          "label": "http://www.w3.org/2000/01/rdf-schema#label",
          "Class_GET_BY_ID": "http://hypergraphql.org/query/Class_GET_BY_ID",
          "subClassOf": "http://www.w3.org/2000/01/rdf-schema#subClassOf"
        },
        "Class_GET_BY_ID": [
          {
            "id": [
              "GO:0032259"
            ],
            "label": [
              "methylation"
            ],
            "subClassOf": [
              {
                "id": [
                  "GO:0008152"
                ],
                "label": [
                  "metabolic process"
                ],
                "subClassOf": [
                  {
                    "id": [
                      "GO:0008150"
                    ],
                    "label": [
                      "biological_process"
                    ]
                  }
                ]
              }
            ]
          },
          {
            "id": [
              "GO:0007267"
            ],
            "label": [
              "cell-cell signaling"
            ],
            "subClassOf": [
              {
                "id": [
                  "GO:0007154"
                ],
                "label": [
                  "cell communication"
                ],
                "subClassOf": [
                  {
                    "id": [
                      "GO:0009987"
                    ],
                    "label": [
                      "cellular process"
                    ]
                  }
                ]
              },
              {
                "id": [
                  "GO:0023052"
                ],
                "label": [
                  "signaling"
                ],
                "subClassOf": [
                  {
                    "id": [
                      "GO:0008150"
                    ],
                    "label": [
                      "biological_process"
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "errors": []
    }
    

EDIT

This was exactly what I wanted, but I noticed that I can't add another sublevel like this:

{
  Class_GET_BY_ID(uris:[
    "http://purl.obolibrary.org/obo/GO_0032259",
    "http://purl.obolibrary.org/obo/GO_0007267"]) {
    id
    label
    subClassOf {
      id
      label
      subClassOf {
        id
        label
        subClassOf {  # <--- 4th sublevel
          id
          label
        }
      }
    }
  }
}

I created a new question: Endpoint returned Content-Type: text/html which is not recognized for SELECT queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!