{"_id":"58459a87ba4f1c0f00969336","__v":0,"project":"55faf11ba62ba1170021a9a7","version":{"_id":"55faf11ba62ba1170021a9aa","project":"55faf11ba62ba1170021a9a7","__v":37,"createdAt":"2015-09-17T16:58:03.490Z","releaseDate":"2015-09-17T16:58:03.490Z","categories":["55faf11ca62ba1170021a9ab","55faf8f4d0e22017005b8272","55faf91aa62ba1170021a9b5","55faf929a8a7770d00c2c0bd","55faf932a8a7770d00c2c0bf","55faf94b17b9d00d00969f47","55faf958d0e22017005b8274","55faf95fa8a7770d00c2c0c0","55faf96917b9d00d00969f48","55faf970a8a7770d00c2c0c1","55faf98c825d5f19001fa3a6","55faf99aa62ba1170021a9b8","55faf99fa62ba1170021a9b9","55faf9aa17b9d00d00969f49","55faf9b6a8a7770d00c2c0c3","55faf9bda62ba1170021a9ba","5604570090ee490d00440551","5637e8b2fbe1c50d008cb078","5649bb624fa1460d00780add","5671974d1b6b730d008b4823","5671979d60c8e70d006c9760","568e8eef70ca1f0d0035808e","56d0a2081ecc471500f1795e","56d4a0adde40c70b00823ea3","56d96b03dd90610b00270849","56fbb83d8f21c817002af880","573c811bee2b3b2200422be1","576bc92afb62dd20001cda85","5771811e27a5c20e00030dcd","5785191af3a10c0e009b75b0","57bdf84d5d48411900cd8dc0","57ff5c5dc135231700aed806","5804caf792398f0f00e77521","58458b4fba4f1c0f009692bb","586d3c287c6b5b2300c05055","58ef66d88646742f009a0216","58f5d52d7891630f00fe4e77"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"58458b4fba4f1c0f009692bb","project":"55faf11ba62ba1170021a9a7","version":"55faf11ba62ba1170021a9aa","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-12-05T15:44:15.650Z","from_sync":false,"order":6,"slug":"datasets-hub","title":"DATASETS HUB"},"user":"5613e4f8fdd08f2b00437620","parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-05T16:49:11.459Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":26,"body":"[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"On this page:\",\n  \"body\": \"* [Overview](#section-overview)\\n* [Use the Seven Bridges Query Console](#section-use-the-seven-bridges-query-console)\\n* [Example SPARQL queries](#section-example-sparql-queries)\\n* [Adjust sample queries for other available datasets](#section-adjust-sample-queries-for-other-available-datasets)\"\n}\n[/block]\n##Overview\n\nIssue SPARQL queries via the interactive Seven Bridges Query Console or programmatically through the SPARQL endpoint, `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`. For instance, you can programmatically query the endpoint using the SPARQLWrapper in a Python script as in this [example](https://github.com/sbg/docs/blob/master/cgc/SPARQL/SPARQL_download_notebook.ipynb).\n\nOn this page, learn to issue a query in the console and consult example queries to get started.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Use the Seven Bridges Query Console\n\nThe Seven Bridges Query Console is available at https://opensparql.sbgenomics.com/#/. This is an interactive shell that runs in your web browser. You can use the console to write SPARQL queries, issue them, and immediately see a list of results matching the query criteria.\n\nTo issue a SPARQL query using the Seven Bridges Query Console:\n1. Go to https://opensparql.sbgenomics.com/#\n2. Click the tab marked **Console**.\n3. Select a **Namespace**. Details about namespaces are located below the image.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9dd62bc-Screen_Shot_2016-09-08_at_11.52.29_AM.jpeg\",\n        \"Screen Shot 2016-09-08 at 11.52.29 AM.jpeg\",\n        2656,\n        1526,\n        \"#0b2e4d\"\n      ]\n    }\n  ]\n}\n[/block]\nThere are two **namespaces** for each dataset on the console, formatted as follows:\n\n* `{dataset}_metadata_ontology`: This namespace contains URIs for a dataset's ontology and is used to issue queries into a dataset's metadata. It includes the URIs for entities, such as `tcga:Case` and `tcga:File`, as well as properties like `tcga:Gender`. The [example queries](doc:example-sparql-queries) provided use the `tcga_metadata_ontology` namespace to issue queries into TCGA metadata.\n* `{dataset}_metadata_kb`: This namespace contains URIs for concrete data within a dataset, such as its files. This namespace is used to issue queries into specific pieces of data in a dataset. For instance, use the namespace `ccle_metadata_kb` to query specific pieces of CCLE data.\n\n4. Enter your query in the text field.\n5. Click **Execute query**. Your results are listed below the console.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Click **Choose query template **at the top of the console to select a pre-written SPARQL query. These have been selected to demonstrate different methods.\",\n  \"title\": \"Use a query template\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example SPARQL queries\nUse the sample SPARQL queries in this section to get started on your own queries. Each query is accompanied by a link to run it in realtime using the interactive query console. Note that you can also embed the query in a script for use elsewhere.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Adjust sample queries for other available datasets\n\nThe sample queries all use TCGA but can be used to model similar queries for any dataset by making the following adjustments:\n  * Substitute the appropriate [prefix](sparql-basics#section-abbreviating-uris). For instance, use the following prefix for CCLE, `PREFIX ccle: <https://www.sbgenomics.com/ontologies/2014/11/ccle#>`.\n  * Modify queries to reflect the metadata ontology for the queried datasets. For instance, `case` is a TCGA entity but is not a CCLE entity. Using `case` in a CCLE query results in an error. Learn more about the [metadata ontology for each dataset](about-metadata-for-datasets) available on the CGC.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Example SPARQL queries\",\n  \"body\": \"* [Example 1: List all investigations in TCGA](example-sparql-queries#section-example-1-list-all-investigations-in-tcga)\\n* [Example 2: Show the number of cases for every disease type studied in the investigation](example-sparql-queries#section-example-2-show-the-number-of-cases-for-every-disease-type-studied-in-the-investigation)\\n* [Example 3: List all the properties linked to the case entity](example-sparql-queries#section-example-3-list-all-the-properties-linked-to-the-case-entity)\\n* [Example 4: List cases with Lung Adenocarcinoma](example-sparql-queries#section-example-4-list-cases-with-lung-adenocarcinoma)\\n* [Example 5: Count the number of cases with the selected histologic diagnosis](example-sparql-queries#section-example-5-count-the-number-of-cases-with-the-selected-histologic-diagnosis)\\n* [Example 6: Count the number of males and females in the selected data](example-sparql-queries#section-example-6-count-the-number-of-males-and-females-in-the-selected-data)\\n* [Example 7: List cases in the selected data that are male and limit the results to 150](example-sparql-queries#section-example-7-list-cases-in-the-selected-data-that-are-male-and-limit-the-results-to-150)\\n* [Example 8: List the age at diagnosis for the selected cases that are male](example-sparql-queries#section-example-8-list-the-age-at-diagnosis-for-the-selected-cases-that-are-male)\\n* [Example 9: Choose cases with age at diagnosis in the range 60-80](example-sparql-queries#section-example-9-choose-cases-with-age-at-diagnosis-in-the-range-60-80)\\n* [Example 10: Given a selected subset of cases, return those with follow-up information](example-sparql-queries#section-example-10-given-a-selected-subset-of-cases-return-those-with-follow-up-information)\\n* [Example 11: Given a subset of cases, return those with follow-up data more than 550 days after treatment](example-sparql-queries#section-example-11-given-a-subset-of-cases-return-those-with-follow-up-data-more-than-550-days-after-treatment)\\n* [Example 12: Given a subset of cases, return those that are alive more than 550 days after treatment](example-sparql-queries#section-example-12-given-a-subset-of-cases-return-those-that-are-alive-more-than-550-days-after-treatment)\\n* [Example 13: Given a subset of cases, return those with a pharmaceutical therapy type of chemotherapy](example-sparql-queries#section-example-13-given-a-subset-of-cases-return-those-with-a-pharmaceutical-therapy-type-of-chemotherapy)\\n* [Example 14: List the properties of each sample](example-sparql-queries#section-example-14-list-the-properties-of-each-sample)\\n* [Example 15: For selected cases, list the sample types of their samples](example-sparql-queries#section-example-15-for-selected-cases-list-the-sample-types-of-their-samples)\\n* [Example 16: Given the selected cases, return those with a sample type of Primary tumor](example-sparql-queries#section-example-16-given-the-selected-cases-return-those-with-a-sample-type-of-primary-tumor)\\n* [Example 17: Given the selected files, return those with an RNA-Seq experimental strategy and a data format of BAM](example-sparql-queries#section-example-17-given-the-selected-files-return-those-with-an-rna-seq-experimental-strategy-and-a-data-format-of-bam)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>","excerpt":"<a href=\"query-datasets\" style=\"color:#132c56\">QUERY DATASETS</a> > <a href=\"about-sparql\" style=\"color:#132c56\">About SPARQL</a> > Query via SPARQL","slug":"query-via-sparql","type":"basic","title":"↳ Query via SPARQL"}

↳ Query via SPARQL

<a href="query-datasets" style="color:#132c56">QUERY DATASETS</a> > <a href="about-sparql" style="color:#132c56">About SPARQL</a> > Query via SPARQL

[block:callout] { "type": "warning", "title": "On this page:", "body": "* [Overview](#section-overview)\n* [Use the Seven Bridges Query Console](#section-use-the-seven-bridges-query-console)\n* [Example SPARQL queries](#section-example-sparql-queries)\n* [Adjust sample queries for other available datasets](#section-adjust-sample-queries-for-other-available-datasets)" } [/block] ##Overview Issue SPARQL queries via the interactive Seven Bridges Query Console or programmatically through the SPARQL endpoint, `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`. For instance, you can programmatically query the endpoint using the SPARQLWrapper in a Python script as in this [example](https://github.com/sbg/docs/blob/master/cgc/SPARQL/SPARQL_download_notebook.ipynb). On this page, learn to issue a query in the console and consult example queries to get started. <div align="right"><a href="#top">top</a></div> ##Use the Seven Bridges Query Console The Seven Bridges Query Console is available at https://opensparql.sbgenomics.com/#/. This is an interactive shell that runs in your web browser. You can use the console to write SPARQL queries, issue them, and immediately see a list of results matching the query criteria. To issue a SPARQL query using the Seven Bridges Query Console: 1. Go to https://opensparql.sbgenomics.com/# 2. Click the tab marked **Console**. 3. Select a **Namespace**. Details about namespaces are located below the image. [block:image] { "images": [ { "image": [ "https://files.readme.io/9dd62bc-Screen_Shot_2016-09-08_at_11.52.29_AM.jpeg", "Screen Shot 2016-09-08 at 11.52.29 AM.jpeg", 2656, 1526, "#0b2e4d" ] } ] } [/block] There are two **namespaces** for each dataset on the console, formatted as follows: * `{dataset}_metadata_ontology`: This namespace contains URIs for a dataset's ontology and is used to issue queries into a dataset's metadata. It includes the URIs for entities, such as `tcga:Case` and `tcga:File`, as well as properties like `tcga:Gender`. The [example queries](doc:example-sparql-queries) provided use the `tcga_metadata_ontology` namespace to issue queries into TCGA metadata. * `{dataset}_metadata_kb`: This namespace contains URIs for concrete data within a dataset, such as its files. This namespace is used to issue queries into specific pieces of data in a dataset. For instance, use the namespace `ccle_metadata_kb` to query specific pieces of CCLE data. 4. Enter your query in the text field. 5. Click **Execute query**. Your results are listed below the console. [block:callout] { "type": "info", "body": "Click **Choose query template **at the top of the console to select a pre-written SPARQL query. These have been selected to demonstrate different methods.", "title": "Use a query template" } [/block] <div align="right"><a href="#top">top</a></div> ##Example SPARQL queries Use the sample SPARQL queries in this section to get started on your own queries. Each query is accompanied by a link to run it in realtime using the interactive query console. Note that you can also embed the query in a script for use elsewhere. <div align="right"><a href="#top">top</a></div> ##Adjust sample queries for other available datasets The sample queries all use TCGA but can be used to model similar queries for any dataset by making the following adjustments: * Substitute the appropriate [prefix](sparql-basics#section-abbreviating-uris). For instance, use the following prefix for CCLE, `PREFIX ccle: <https://www.sbgenomics.com/ontologies/2014/11/ccle#>`. * Modify queries to reflect the metadata ontology for the queried datasets. For instance, `case` is a TCGA entity but is not a CCLE entity. Using `case` in a CCLE query results in an error. Learn more about the [metadata ontology for each dataset](about-metadata-for-datasets) available on the CGC. <div align="right"><a href="#top">top</a></div> [block:callout] { "type": "info", "title": "Example SPARQL queries", "body": "* [Example 1: List all investigations in TCGA](example-sparql-queries#section-example-1-list-all-investigations-in-tcga)\n* [Example 2: Show the number of cases for every disease type studied in the investigation](example-sparql-queries#section-example-2-show-the-number-of-cases-for-every-disease-type-studied-in-the-investigation)\n* [Example 3: List all the properties linked to the case entity](example-sparql-queries#section-example-3-list-all-the-properties-linked-to-the-case-entity)\n* [Example 4: List cases with Lung Adenocarcinoma](example-sparql-queries#section-example-4-list-cases-with-lung-adenocarcinoma)\n* [Example 5: Count the number of cases with the selected histologic diagnosis](example-sparql-queries#section-example-5-count-the-number-of-cases-with-the-selected-histologic-diagnosis)\n* [Example 6: Count the number of males and females in the selected data](example-sparql-queries#section-example-6-count-the-number-of-males-and-females-in-the-selected-data)\n* [Example 7: List cases in the selected data that are male and limit the results to 150](example-sparql-queries#section-example-7-list-cases-in-the-selected-data-that-are-male-and-limit-the-results-to-150)\n* [Example 8: List the age at diagnosis for the selected cases that are male](example-sparql-queries#section-example-8-list-the-age-at-diagnosis-for-the-selected-cases-that-are-male)\n* [Example 9: Choose cases with age at diagnosis in the range 60-80](example-sparql-queries#section-example-9-choose-cases-with-age-at-diagnosis-in-the-range-60-80)\n* [Example 10: Given a selected subset of cases, return those with follow-up information](example-sparql-queries#section-example-10-given-a-selected-subset-of-cases-return-those-with-follow-up-information)\n* [Example 11: Given a subset of cases, return those with follow-up data more than 550 days after treatment](example-sparql-queries#section-example-11-given-a-subset-of-cases-return-those-with-follow-up-data-more-than-550-days-after-treatment)\n* [Example 12: Given a subset of cases, return those that are alive more than 550 days after treatment](example-sparql-queries#section-example-12-given-a-subset-of-cases-return-those-that-are-alive-more-than-550-days-after-treatment)\n* [Example 13: Given a subset of cases, return those with a pharmaceutical therapy type of chemotherapy](example-sparql-queries#section-example-13-given-a-subset-of-cases-return-those-with-a-pharmaceutical-therapy-type-of-chemotherapy)\n* [Example 14: List the properties of each sample](example-sparql-queries#section-example-14-list-the-properties-of-each-sample)\n* [Example 15: For selected cases, list the sample types of their samples](example-sparql-queries#section-example-15-for-selected-cases-list-the-sample-types-of-their-samples)\n* [Example 16: Given the selected cases, return those with a sample type of Primary tumor](example-sparql-queries#section-example-16-given-the-selected-cases-return-those-with-a-sample-type-of-primary-tumor)\n* [Example 17: Given the selected files, return those with an RNA-Seq experimental strategy and a data format of BAM](example-sparql-queries#section-example-17-given-the-selected-files-return-those-with-an-rna-seq-experimental-strategy-and-a-data-format-of-bam)" } [/block] <div align="right"><a href="#top">top</a></div>