{"_id":"5845a4b2e055290f00c029e0","project":"55faf11ba62ba1170021a9a7","__v":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"},"version":{"_id":"55faf11ba62ba1170021a9aa","project":"55faf11ba62ba1170021a9a7","__v":38,"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","59a555bccdbd85001bfb1442"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"user":"5613e4f8fdd08f2b00437620","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-05T17:32:34.869Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","examples":{"codes":[]},"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":36,"body":"Use the sample SPARQL queries on this page to get started. Follow the link below the query to run it in realtime using the interactive query console. Note that you can also programmatically issue the query to the SPARQL endpoint at `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`.For instance, 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\nThe example queries on this page are for TCGA. Learn how to [modify queries for other datasets](query-via-sparql#section-adjust-sample-queries-for-other-available-datasets).\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"On this page\",\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##Example 1: List all investigations in TCGA\n\nUse the following query to return all investigations in TCGA.\n\nThe sample query below uses TCGA data but can be used to [model similar queries](query-via-sparql#adjust-sample-queries-for-other-available-datasets) for other available datasets. Follow the link below the query to run it in realtime using the interactive query console. Note that you can also programmatically issue the query to the SPARQL endpoint at `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`.For instance, 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[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\n\\nSELECT distinct ?inv_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasInvestigation ?investigation .\\n ?investigation rdfs:label ?inv_label\\n}\",\n      \"language\": \"sql\",\n      \"name\": \"List all investigations studied in the TCGA program\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample1)\"\n}\n[/block]\nNote that in this example, the use of the keyword `distinct` filters out any resources with identical values for `inv_label`.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 2: Show the number of cases for every disease type studied in the investigation\n\nUse the following query to return the number of cases for every disease type studied in the investigation.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n \\n \\nSELECT distinct ?inv_label ?d_type (count(?case) as ?N_cases)\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasInvestigation ?investigation .\\n ?investigation rdfs:label ?inv_label .\\n   \\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label ?d_type .\\n  }\\n \\n \\nGROUP BY ?inv_label ?d_type\",\n      \"language\": \"sql\",\n      \"name\": \"Show the number of cases for every disease type studied in the investigation\\n\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample2)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 3: List all the properties linked to the case entity\n\nUse the following query to return all the properties linked to the Case entity.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\n\\nSELECT distinct ?p\\nWHERE\\n{\\n  ?case a tcga:Case  .\\n  ?case ?p ?o\\n}\",\n      \"language\": \"sql\",\n      \"name\": \" List all the properties linked to the case entity\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample3)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 4: List cases with Lung Adenocarcinoma\n\nUse the following query to return all cases with Lung Adenocarcinoma.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT distinct ?hd_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n\\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label ?hd_label\\n}\",\n      \"language\": \"sql\",\n      \"name\": \"List cases with Lung Adenocarcinoma\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample4)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 5: Count the number of cases with the selected histologic diagnosis\n\nUse the following query to count the number of cases with the selected histologic diagnosis. In this case, we'll count the number of cases with Lung Adenocarcinoma.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT (count(?case) as ?N_cases)\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n\\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\"\\n}\",\n      \"language\": \"sql\",\n      \"name\": \" Count the number of cases with the selected histologic diagnosis\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample5)\",\n  \"title\": \"Try it out!\"\n}\n[/block]\nWe can further explore this data by selecting cases with specified clinical properties, such as in Example 6.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 6: Count the number of males and females in the selected data\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT ?gender_label (count(?case) as ?N_cases)\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n\\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n\\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label ?gender_label\\n}\\n\\nGROUP BY ?gender_label\",\n      \"language\": \"sql\",\n      \"name\": \"Count the number of males and females in the selected data\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample6)\",\n  \"title\": \"Try it out!\"\n}\n[/block]\nUse the `LIMIT` clause to limit results and thus speed up the response from the database when exploring data in the console, as in Example 7.\n\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 7: List cases in the selected data that are male and limit the results to 150\n\nUse the following query to return all cases in the selected data that are male and limit the results to 150. In the query below, we return 150 male cases of Lung Adenocarcinoma Mixed Subtype.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT ?case\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\"\\n}\\n\\nLIMIT 150 \",\n      \"language\": \"sql\",\n      \"name\": \"List all the cases in the selected data that are male\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample7)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 8: List the age at diagnosis for the selected cases that are male\n\nUse the following query to return the age at diagnosis for the selected cases that are males. In the query below, we return the age at diagnosis for 150 male cases of Lung Adenocarcinoma Mixed Subtype.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\n\\nSELECT ?case ?age\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n \\n ?case tcga:hasAgeAtDiagnosis ?age\\n}\\n \\nLIMIT 150\",\n      \"language\": \"sql\",\n      \"name\": \"List age at diagnosis for selected male cases\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample8)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 9: Choose cases with age at diagnosis in the range 60-80\n\nUse the following query to return 150 male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT ?case ?age\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n}\\n \\nLIMIT 150 \",\n      \"language\": \"sql\",\n      \"name\": \"Choose cases with age at diagnosis in the range 60-80\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample9)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 10: Given a selected subset of cases, return those with follow-up information\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT ?case ?age\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n  \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n  \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n  \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n  \\n ?case tcga:hasFollowUp ?follow_up\\n  \\n}\\n \\nLIMIT 150\",\n      \"language\": \"sql\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample10)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 11: Given a subset of cases, return those with follow-up data more than 550 days after treatment\n\nUse the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that have follow-up information more than 550 days after treatment.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT ?case ?age ?days_to_last_follow_up\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n  \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n  \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n  \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n  \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up\\n filter(?days_to_last_follow_up>550)\\n  \\n} \",\n      \"language\": \"text\",\n      \"name\": \"From those cases above, select those with follow up data generated after more than 550 days\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample11)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 12: Given a subset of cases, return those that are alive more than 550 days after treatment\n\nUse the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that were alive more than 550 days after treatment.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT distinct ?case ?age ?vital_status_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\\n filter(?days_to_last_follow_up>550)\\n ?follow_up tcga:hasVitalStatus ?vital_status .\\n ?vital_status rdfs:label ?vital_status_label .\\n filter(?vital_status_label=\\\"Alive\\\")\\n \\n} \",\n      \"language\": \"sql\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample12)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 13: Given a subset of cases, return those with a pharmaceutical therapy type of chemotherapy\n\nUse the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that were alive more than 550 days after a treatment of chemotherapy.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT distinct ?case ?age ?pt_type_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n  \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n  \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n  \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n  \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\\n filter(?days_to_last_follow_up>550)\\n   \\n ?follow_up tcga:hasVitalStatus ?vital_status .\\n ?vital_status rdfs:label ?vital_status_label .\\n filter(?vital_status_label=\\\"Alive\\\")\\n  \\n ?case tcga:hasDrugTherapy ?drug_therapy .\\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\\n ?pt_type rdfs:label ?pt_type_label .\\n filter(?pt_type_label=\\\"Chemotherapy\\\")\\n}\",\n      \"language\": \"sql\",\n      \"name\": \"Given the data selected above, list cases with Pharmaceutical therapy type “Chemotherapy”\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample13)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 14: List the properties of each sample\n\nUse the following query to return the properties of each sample.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\n\\nSELECT distinct ?p\\nWHERE\\n{\\n  ?sample a tcga:Sample  .\\n  ?sample ?p ?o\\n}\",\n      \"language\": \"sql\",\n      \"name\": \"List the properties of each sample\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample14)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 15: For selected cases, list the sample types of their samples\n\nUse the following query to return the sample types of the samples for the selected cases.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT distinct ?case ?sample  ?st_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\\n filter(?days_to_last_follow_up>550)\\n  \\n ?follow_up tcga:hasVitalStatus ?vital_status .\\n ?vital_status rdfs:label ?vital_status_label .\\n filter(?vital_status_label=\\\"Alive\\\")\\n \\n ?case tcga:hasDrugTherapy ?drug_therapy .\\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\\n ?pt_type rdfs:label ?pt_type_label .\\n filter(?pt_type_label=\\\"Chemotherapy\\\")\\n  \\n ?case tcga:hasSample ?sample .\\n ?sample tcga:hasSampleType ?st .\\n ?st rdfs:label ?st_label\\n}\",\n      \"language\": \"sql\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample15)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 16: Given the selected cases, return those with a sample type of Primary tumor\n\nUse the following query to return male cases with Lung Adenocarcinoma Mixed Subtype that were alive 550 days after a treatment of chemotherapy with a sample type of Primary tumor.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\nSELECT distinct ?case ?sample  ?st_label\\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\\n filter(?days_to_last_follow_up>550)\\n  \\n ?follow_up tcga:hasVitalStatus ?vital_status .\\n ?vital_status rdfs:label ?vital_status_label .\\n filter(?vital_status_label=\\\"Alive\\\")\\n \\n ?case tcga:hasDrugTherapy ?drug_therapy .\\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\\n ?pt_type rdfs:label ?pt_type_label .\\n filter(?pt_type_label=\\\"Chemotherapy\\\")\\n  \\n ?case tcga:hasSample ?sample .\\n ?sample tcga:hasSampleType ?st .\\n ?st rdfs:label ?st_label\\n filter(?st_label=\\\"Primary Tumor\\\")\\n} \",\n      \"language\": \"sql\",\n      \"name\": \"Given the selected cases, list those with the Sample type “Primary tumor” \"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample16)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>\n\n##Example 17: Given the selected files, return those with an RNA-Seq experimental strategy and a data format of BAM\n\nUse the following query to return male cases with Lung Adenocarcinoma Mixed Subtype that were alive 550 days after a treatment of chemotherapy with a sample type of Primary tumor, an experimental strategy of RNA-Seq, and a data format of BAM.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\\n\\n\\nSELECT distinct ?case ?st_label ?xs_label  ?file_name \\nWHERE\\n{\\n ?case a tcga:Case .\\n ?case tcga:hasDiseaseType ?disease_type .\\n ?disease_type rdfs:label \\\"Lung Adenocarcinoma\\\" .\\n \\n ?case tcga:hasHistologicalDiagnosis ?hd .\\n ?hd rdfs:label \\\"Lung Adenocarcinoma Mixed Subtype\\\" .\\n \\n ?case tcga:hasGender ?gender .\\n ?gender rdfs:label \\\"MALE\\\" .\\n \\n ?case tcga:hasAgeAtDiagnosis ?age .\\n filter(?age>=60 && ?age<=80)\\n \\n ?case tcga:hasFollowUp ?follow_up .\\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\\n filter(?days_to_last_follow_up>550) \\n  \\n ?follow_up tcga:hasVitalStatus ?vital_status .\\n ?vital_status rdfs:label ?vital_status_label .\\n filter(?vital_status_label=\\\"Alive\\\")\\n \\n ?case tcga:hasDrugTherapy ?drug_therapy .\\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\\n ?pt_type rdfs:label ?pt_type_label .\\n filter(?pt_type_label=\\\"Chemotherapy\\\")\\n  \\n ?case tcga:hasSample ?sample .\\n ?sample tcga:hasSampleType ?st .\\n ?st rdfs:label ?st_label\\n filter(?st_label=\\\"Primary Tumor\\\")\\n     \\n ?sample tcga:hasFile ?file .\\n ?file rdfs:label ?file_name .\\n  \\n ?file tcga:hasExperimentalStrategy ?xs.\\n ?xs rdfs:label ?xs_label .\\n filter(?xs_label=\\\"RNA-Seq\\\")\\n  \\n ?file tcga:hasDataFormat ?data_format .\\n ?data_format rdfs:label ?data_format_label .\\n filter(?data_format_label=\\\"BAM\\\")\\n\\n}\",\n      \"language\": \"sql\",\n      \"name\": \"Given the selected files, list those with the Experimental strategy “RNA-Seq” and the Data format “BAM”\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Try it out!\",\n  \"body\": \"[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample17)\"\n}\n[/block]\n<div align=\"right\"><a href=\"#top\">top</a></div>","excerpt":"<a name=\"top\"></a><a href=\"query-datasets\" style=\"color:#132c56\">QUERY DATASETS</a> > <a href=\"about-sparql\" style=\"color:#132c56\">About SPARQL</a> > Example SPARQL queries","slug":"example-sparql-queries","type":"basic","title":"↳ Example SPARQL queries"}

↳ Example SPARQL queries

<a name="top"></a><a href="query-datasets" style="color:#132c56">QUERY DATASETS</a> > <a href="about-sparql" style="color:#132c56">About SPARQL</a> > Example SPARQL queries

Use the sample SPARQL queries on this page to get started. Follow the link below the query to run it in realtime using the interactive query console. Note that you can also programmatically issue the query to the SPARQL endpoint at `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`.For instance, 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). The example queries on this page are for TCGA. Learn how to [modify queries for other datasets](query-via-sparql#section-adjust-sample-queries-for-other-available-datasets). [block:callout] { "type": "warning", "title": "On this page", "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] ##Example 1: List all investigations in TCGA Use the following query to return all investigations in TCGA. The sample query below uses TCGA data but can be used to [model similar queries](query-via-sparql#adjust-sample-queries-for-other-available-datasets) for other available datasets. Follow the link below the query to run it in realtime using the interactive query console. Note that you can also programmatically issue the query to the SPARQL endpoint at `https://opensparql.sbgenomics.com/blazegraph/namespace/tcga_metadata_kb/sparql`.For instance, 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). [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\n\nSELECT distinct ?inv_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasInvestigation ?investigation .\n ?investigation rdfs:label ?inv_label\n}", "language": "sql", "name": "List all investigations studied in the TCGA program" } ] } [/block] [block:callout] { "type": "success", "title": "Try it!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample1)" } [/block] Note that in this example, the use of the keyword `distinct` filters out any resources with identical values for `inv_label`. <div align="right"><a href="#top">top</a></div> ##Example 2: Show the number of cases for every disease type studied in the investigation Use the following query to return the number of cases for every disease type studied in the investigation. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n \n \nSELECT distinct ?inv_label ?d_type (count(?case) as ?N_cases)\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasInvestigation ?investigation .\n ?investigation rdfs:label ?inv_label .\n \n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label ?d_type .\n }\n \n \nGROUP BY ?inv_label ?d_type", "language": "sql", "name": "Show the number of cases for every disease type studied in the investigation\n" } ] } [/block] [block:callout] { "type": "success", "title": "Try it!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample2)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 3: List all the properties linked to the case entity Use the following query to return all the properties linked to the Case entity. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\n\nSELECT distinct ?p\nWHERE\n{\n ?case a tcga:Case .\n ?case ?p ?o\n}", "language": "sql", "name": " List all the properties linked to the case entity" } ] } [/block] [block:callout] { "type": "success", "title": "Try it!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample3)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 4: List cases with Lung Adenocarcinoma Use the following query to return all cases with Lung Adenocarcinoma. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT distinct ?hd_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n\n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label ?hd_label\n}", "language": "sql", "name": "List cases with Lung Adenocarcinoma" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample4)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 5: Count the number of cases with the selected histologic diagnosis Use the following query to count the number of cases with the selected histologic diagnosis. In this case, we'll count the number of cases with Lung Adenocarcinoma. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT (count(?case) as ?N_cases)\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n\n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\"\n}", "language": "sql", "name": " Count the number of cases with the selected histologic diagnosis" } ] } [/block] [block:callout] { "type": "success", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample5)", "title": "Try it out!" } [/block] We can further explore this data by selecting cases with specified clinical properties, such as in Example 6. <div align="right"><a href="#top">top</a></div> ##Example 6: Count the number of males and females in the selected data [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT ?gender_label (count(?case) as ?N_cases)\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n\n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n\n ?case tcga:hasGender ?gender .\n ?gender rdfs:label ?gender_label\n}\n\nGROUP BY ?gender_label", "language": "sql", "name": "Count the number of males and females in the selected data" } ] } [/block] [block:callout] { "type": "success", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample6)", "title": "Try it out!" } [/block] Use the `LIMIT` clause to limit results and thus speed up the response from the database when exploring data in the console, as in Example 7. <div align="right"><a href="#top">top</a></div> ##Example 7: List cases in the selected data that are male and limit the results to 150 Use the following query to return all cases in the selected data that are male and limit the results to 150. In the query below, we return 150 male cases of Lung Adenocarcinoma Mixed Subtype. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT ?case\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\"\n}\n\nLIMIT 150 ", "language": "sql", "name": "List all the cases in the selected data that are male" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample7)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 8: List the age at diagnosis for the selected cases that are male Use the following query to return the age at diagnosis for the selected cases that are males. In the query below, we return the age at diagnosis for 150 male cases of Lung Adenocarcinoma Mixed Subtype. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\n\nSELECT ?case ?age\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n \n ?case tcga:hasAgeAtDiagnosis ?age\n}\n \nLIMIT 150", "language": "sql", "name": "List age at diagnosis for selected male cases" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample8)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 9: Choose cases with age at diagnosis in the range 60-80 Use the following query to return 150 male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT ?case ?age\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n}\n \nLIMIT 150 ", "language": "sql", "name": "Choose cases with age at diagnosis in the range 60-80" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample9)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 10: Given a selected subset of cases, return those with follow-up information [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT ?case ?age\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up\n \n}\n \nLIMIT 150", "language": "sql", "name": null } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample10)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 11: Given a subset of cases, return those with follow-up data more than 550 days after treatment Use the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that have follow-up information more than 550 days after treatment. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT ?case ?age ?days_to_last_follow_up\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up\n filter(?days_to_last_follow_up>550)\n \n} ", "language": "text", "name": "From those cases above, select those with follow up data generated after more than 550 days" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample11)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 12: Given a subset of cases, return those that are alive more than 550 days after treatment Use the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that were alive more than 550 days after treatment. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT distinct ?case ?age ?vital_status_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\n filter(?days_to_last_follow_up>550)\n ?follow_up tcga:hasVitalStatus ?vital_status .\n ?vital_status rdfs:label ?vital_status_label .\n filter(?vital_status_label=\"Alive\")\n \n} ", "language": "sql", "name": null } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample12)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 13: Given a subset of cases, return those with a pharmaceutical therapy type of chemotherapy Use the following query to return all male cases of Lung Adenocarcinoma Mixed Subtype with an age at diagnosis in the range 60-80 that were alive more than 550 days after a treatment of chemotherapy. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT distinct ?case ?age ?pt_type_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\n filter(?days_to_last_follow_up>550)\n \n ?follow_up tcga:hasVitalStatus ?vital_status .\n ?vital_status rdfs:label ?vital_status_label .\n filter(?vital_status_label=\"Alive\")\n \n ?case tcga:hasDrugTherapy ?drug_therapy .\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\n ?pt_type rdfs:label ?pt_type_label .\n filter(?pt_type_label=\"Chemotherapy\")\n}", "language": "sql", "name": "Given the data selected above, list cases with Pharmaceutical therapy type “Chemotherapy”" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample13)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 14: List the properties of each sample Use the following query to return the properties of each sample. [block:code] { "codes": [ { "code": "PREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\n\nSELECT distinct ?p\nWHERE\n{\n ?sample a tcga:Sample .\n ?sample ?p ?o\n}", "language": "sql", "name": "List the properties of each sample" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample14)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 15: For selected cases, list the sample types of their samples Use the following query to return the sample types of the samples for the selected cases. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT distinct ?case ?sample ?st_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\n filter(?days_to_last_follow_up>550)\n \n ?follow_up tcga:hasVitalStatus ?vital_status .\n ?vital_status rdfs:label ?vital_status_label .\n filter(?vital_status_label=\"Alive\")\n \n ?case tcga:hasDrugTherapy ?drug_therapy .\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\n ?pt_type rdfs:label ?pt_type_label .\n filter(?pt_type_label=\"Chemotherapy\")\n \n ?case tcga:hasSample ?sample .\n ?sample tcga:hasSampleType ?st .\n ?st rdfs:label ?st_label\n}", "language": "sql", "name": null } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample15)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 16: Given the selected cases, return those with a sample type of Primary tumor Use the following query to return male cases with Lung Adenocarcinoma Mixed Subtype that were alive 550 days after a treatment of chemotherapy with a sample type of Primary tumor. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\nSELECT distinct ?case ?sample ?st_label\nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\n filter(?days_to_last_follow_up>550)\n \n ?follow_up tcga:hasVitalStatus ?vital_status .\n ?vital_status rdfs:label ?vital_status_label .\n filter(?vital_status_label=\"Alive\")\n \n ?case tcga:hasDrugTherapy ?drug_therapy .\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\n ?pt_type rdfs:label ?pt_type_label .\n filter(?pt_type_label=\"Chemotherapy\")\n \n ?case tcga:hasSample ?sample .\n ?sample tcga:hasSampleType ?st .\n ?st rdfs:label ?st_label\n filter(?st_label=\"Primary Tumor\")\n} ", "language": "sql", "name": "Given the selected cases, list those with the Sample type “Primary tumor” " } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample16)" } [/block] <div align="right"><a href="#top">top</a></div> ##Example 17: Given the selected files, return those with an RNA-Seq experimental strategy and a data format of BAM Use the following query to return male cases with Lung Adenocarcinoma Mixed Subtype that were alive 550 days after a treatment of chemotherapy with a sample type of Primary tumor, an experimental strategy of RNA-Seq, and a data format of BAM. [block:code] { "codes": [ { "code": "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\nPREFIX tcga: <https://www.sbgenomics.com/ontologies/2014/11/tcga#>\n\n\nSELECT distinct ?case ?st_label ?xs_label ?file_name \nWHERE\n{\n ?case a tcga:Case .\n ?case tcga:hasDiseaseType ?disease_type .\n ?disease_type rdfs:label \"Lung Adenocarcinoma\" .\n \n ?case tcga:hasHistologicalDiagnosis ?hd .\n ?hd rdfs:label \"Lung Adenocarcinoma Mixed Subtype\" .\n \n ?case tcga:hasGender ?gender .\n ?gender rdfs:label \"MALE\" .\n \n ?case tcga:hasAgeAtDiagnosis ?age .\n filter(?age>=60 && ?age<=80)\n \n ?case tcga:hasFollowUp ?follow_up .\n ?follow_up tcga:hasDaysToLastFollowUp ?days_to_last_follow_up .\n filter(?days_to_last_follow_up>550) \n \n ?follow_up tcga:hasVitalStatus ?vital_status .\n ?vital_status rdfs:label ?vital_status_label .\n filter(?vital_status_label=\"Alive\")\n \n ?case tcga:hasDrugTherapy ?drug_therapy .\n ?drug_therapy tcga:hasPharmaceuticalTherapyType ?pt_type .\n ?pt_type rdfs:label ?pt_type_label .\n filter(?pt_type_label=\"Chemotherapy\")\n \n ?case tcga:hasSample ?sample .\n ?sample tcga:hasSampleType ?st .\n ?st rdfs:label ?st_label\n filter(?st_label=\"Primary Tumor\")\n \n ?sample tcga:hasFile ?file .\n ?file rdfs:label ?file_name .\n \n ?file tcga:hasExperimentalStrategy ?xs.\n ?xs rdfs:label ?xs_label .\n filter(?xs_label=\"RNA-Seq\")\n \n ?file tcga:hasDataFormat ?data_format .\n ?data_format rdfs:label ?data_format_label .\n filter(?data_format_label=\"BAM\")\n\n}", "language": "sql", "name": "Given the selected files, list those with the Experimental strategy “RNA-Seq” and the Data format “BAM”" } ] } [/block] [block:callout] { "type": "success", "title": "Try it out!", "body": "[Run this example in the Query Console](https://opensparql.sbgenomics.com/#/console?query=tcgaExample17)" } [/block] <div align="right"><a href="#top">top</a></div>