提取给定节点的所有父代 [英] Extract all parents of a given node

查看:81
本文介绍了提取给定节点的所有父代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 两个类似的问题来阐述查询,下面是两个说明问题的示例:

I'm trying to extract all parents of a each given GO Id (a node) using EBI-RDF sparql endpoint, I was based on this two similar questions to formulate the query, here're two examples illustrating the problem:

示例1 (在此示例中,使用以下查询:

In this example, using the following query:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

PREFIX obo: <http://purl.obolibrary.org/obo/>

SELECT (count(?mid) as ?depth)
       (group_concat(distinct ?midId ; separator = " / ") AS ?treePath) 
FROM <http://rdf.ebi.ac.uk/dataset/go> 
WHERE {
    obo:GO_0032259 rdfs:subClassOf* ?mid .
    ?mid rdfs:subClassOf* ?class .
    ?mid <http://www.geneontology.org/formats/oboInOwl#id> ?midId.
}
GROUP BY ?treePath
ORDER BY ?depth

我获得了预期的结果,没有任何问题:

I got the desired results without problems:

c |              treePath
--|-------------------------------------
6 | GO:0008150 / GO:0008152 / GO:0032259

但是当该术语存在于多个分支(例如GO:0007267)中时(如下例所示),前一种方法就行不通了:

But when the term exists in multiple branches (e.g GO:0007267) as in the case below, the previous approach didn't work:

示例2 (结果:

c |                            treePath
--|---------------------------------------------------------------
15| GO:0007154 / GO:0007267 / GO:0008150 / GO:0009987 / GO:0023052

我想要得到的是以下内容:

What I wanted to get is the following:

GO:0008150 / GO:0009987 / GO:0007154 / GO:0007267
GO:0008150 / GO:0023052 / GO:0007267


我了解到,在幕后,我正在计算每个级别的深度并使用它来构造路径,当我们有一个仅属于一个分支的元素时,这种方法就可以正常工作.


What I understood is that under the hood I'm calculating the depth of each level and using it to construct the path, this works fine when we have an element that belongs only to one branch.

SELECT (count(?mid) as ?depth) ?midId
FROM <http://rdf.ebi.ac.uk/dataset/go> 
WHERE {
    obo:GO_0032259 rdfs:subClassOf* ?mid .
    ?mid rdfs:subClassOf* ?class .
    ?mid <http://www.geneontology.org/formats/oboInOwl#id> ?midId.
}
GROUP BY ?midId
ORDER BY ?depth

结果:

depth |   midId
------|------------
1     | GO:0008150
2     | GO:0008152
3     | GO:0032259

在第二个示例中,一切都错了,我不知道为什么,无论如何,我确定问题的一部分是具有相同深度/级别的术语,但我不知道该怎么做我解决了.

In the second example, things are missed up and I didn't get why, in any ways I'm sure that part of the problem are terms that have the same depth/level, but I don't know how can I solve this.

depth |   midId
------|------------
2     | GO:0008150
2     | GO:0009987
2     | GO:0023052
3     | GO:0007154
6     | GO:0007267

推荐答案

感谢@AKSW,我使用找到了不错的解决方案HyperGraphQL (用于在网络上查询和提供链接数据的 GraphQL 界面).

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. 我下载并设置了HyperGraphQL 下载页面
  2. 本教程

我使用的config.json文件:

{
    "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": ""
        }
    ]
}

这是我的ebischema.graphql文件的外观(因为我只需要ClassidlabelsubClassOf):

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")
}

  • 我开始测试一些简单的查询,但是不断得到空的响应. 此问题的答案解决了我的问题.

  • I started testing some simple query, but constantly getting an empty response; the answer to this issue solved my problem.

    最后我构造了查询以获取树

    Finally I constructed the query to get the tree

    使用此查询:

    {
      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": []
    }
    

  • 编辑

    这正是我想要的,但是我注意到我无法添加这样的另一个子级别:

    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

    这篇关于提取给定节点的所有父代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆