{"__v":0,"_id":"5845ae5eba4f1c0f00969346","category":{"project":"55faf11ba62ba1170021a9a7","version":"55faf11ba62ba1170021a9aa","_id":"58458b4fba4f1c0f009692bb","__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"},"parentDoc":null,"project":"55faf11ba62ba1170021a9a7","user":"5613e4f8fdd08f2b00437620","version":{"__v":37,"_id":"55faf11ba62ba1170021a9aa","project":"55faf11ba62ba1170021a9a7","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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-05T18:13:50.773Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":42,"body":"The Datasets API can be linked to the [CGC API](the-cgc-api). This means that file IDs returned by queries in Datasets API can be used in the CGC API to operate on the corresponding files. \n\nAccess data from a Datasets API query via the following steps.\n\n##Step 1: Get the file id of each file you wish to access via the Datasets API\n\nIssue a query to the Datasets API, such as the one shown below. Learn more about querying datasets via the Datasets API.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /datasets/tcga/v0/query HTTP/1.1\\nHost: cgc-datasets-api.sbgenomics.com\\nX-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96\",\n      \"language\": \"http\",\n      \"name\": \"Request\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"entity\\\":\\\"files\\\",\\n    \\\"hasCase\\\":{\\n        \\\"hasDiseaseType\\\":\\\"Breast Invasive Carcinoma\\\",\\n        \\\"hasSample\\\":{\\n            \\\"hasSampleType\\\":\\\"Primary Tumor\\\"\\n          }\\n        },\\n    \\\"hasDataFormat\\\":\\\"BAM\\\"\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Request body\"\n    }\n  ]\n}\n[/block]\nThis returns the following response body:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"count\\\": 100,\\n  \\\"_embedded\\\": {\\n    \\\"files\\\": [\\n      {\\n        \\\"hasIndex\\\": \\\"564a31aae4b093830b662920\\\",\\n        \\\"_links\\\": {\\n          \\\"self\\\": {\\n            \\\"href\\\": \\\"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b662924\\\"\\n          }\\n        },\\n        \\\"label\\\": \\\"4f40538e4124d6847dda7318200960d7.bam\\\",\\n        \\\"id\\\": \\\"564a31aae4b093830b662924\\\"\\n      },\\n      {\\n        \\\"hasIndex\\\": \\\"564a31aae4b0ef1218175260\\\",\\n        \\\"_links\\\": {\\n          \\\"self\\\": {\\n            \\\"href\\\": \\\"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b66294a\\\"\\n          }\\n        },\\n        \\\"label\\\": \\\"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam\\\",\\n        \\\"id\\\": \\\"564a31aae4b093830b66294a\\\"\\n      },\\n       \\n      <snip>\\n       \\n    ]\\n  },\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Response body\"\n    }\n  ]\n}\n[/block]\nCopy the values for `id` and `hasIndex` for each file you wish to copy. We will use these in Step 2 to copy the files.\n\nThe `hasIndex` key contains the IDs of associated index files (*.BAI) which are required for analysis alongside of BAM files on the CGC. If `hasIndex` displays as `null`, there are no associated index files.\n\n##Step 2: Make a CGC API request to copy a file\n\nUse the values for `id` and `hasIndex` obtained from the Datasets API query above to make the CGC API request to [copy a file](copy-files-between-projects-1), as shown below. Note that if `hasIndex` has a value other than `null`, you need to copy the file IDs for the index files specified in `hasIndex` for your analysis to run properly.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /v2/action/files/copy HTTP/1.1\\nHost: cgc-api.sbgenomics.com\\nX-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96\",\n      \"language\": \"http\",\n      \"name\": \"Request\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"project\\\": \\\"RFranklin/my-project\\\",\\n  \\\"file_ids\\\": [\\\"564a31aae4b093830b662924\\\", \\\"564a31aae4b093830b662920\\\", \\\"564a31aae4b093830b66294a\\\", \\\"564a31aae4b0ef1218175260\\\"]\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Request body\"\n    }\n  ]\n}\n[/block]\nThis returns the following response:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"564a31aae4b093830b662924\\\": {\\n    \\\"status\\\": \\\"OK\\\",\\n    \\\"new_file_id\\\": \\\"583f568fe4b038da1d96a513\\\",\\n    \\\"new_file_name\\\": \\\"4f40538e4124d6847dda7318200960d7.bam\\\"\\n  },\\n  \\\"564a31aae4b093830b66294a\\\": {\\n    \\\"status\\\": \\\"OK\\\",\\n    \\\"new_file_id\\\": \\\"583f568fe4b038da1d96a517\\\",\\n    \\\"new_file_name\\\": \\\"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam\\\"\\n  },\\n  \\\"564a31aae4b093830b662920\\\": {\\n    \\\"status\\\": \\\"OK\\\",\\n    \\\"new_file_id\\\": \\\"583f568fe4b038da1d96a515\\\",\\n    \\\"new_file_name\\\": \\\"4f40538e4124d6847dda7318200960d7.bam.bai\\\"\\n  },\\n  \\\"564a31aae4b0ef1218175260\\\": {\\n    \\\"status\\\": \\\"OK\\\",\\n    \\\"new_file_id\\\": \\\"583f568fe4b038da1d96a519\\\",\\n    \\\"new_file_name\\\": \\\"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam.bai\\\"\\n  }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Response body\"\n    }\n  ]\n}\n[/block]","excerpt":"<a href=\"access-data-from-datasets\" style=\"color:#132c56\">ACCESS DATA FROM DATASETS</a> > Access data from the Datasets API","slug":"access-data-from-the-datasets-api","type":"basic","title":"Access data from the Datasets API"}

Access data from the Datasets API

<a href="access-data-from-datasets" style="color:#132c56">ACCESS DATA FROM DATASETS</a> > Access data from the Datasets API

The Datasets API can be linked to the [CGC API](the-cgc-api). This means that file IDs returned by queries in Datasets API can be used in the CGC API to operate on the corresponding files. Access data from a Datasets API query via the following steps. ##Step 1: Get the file id of each file you wish to access via the Datasets API Issue a query to the Datasets API, such as the one shown below. Learn more about querying datasets via the Datasets API. [block:code] { "codes": [ { "code": "POST /datasets/tcga/v0/query HTTP/1.1\nHost: cgc-datasets-api.sbgenomics.com\nX-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96", "language": "http", "name": "Request" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"entity\":\"files\",\n \"hasCase\":{\n \"hasDiseaseType\":\"Breast Invasive Carcinoma\",\n \"hasSample\":{\n \"hasSampleType\":\"Primary Tumor\"\n }\n },\n \"hasDataFormat\":\"BAM\"\n}", "language": "json", "name": "Request body" } ] } [/block] This returns the following response body: [block:code] { "codes": [ { "code": "{\n \"count\": 100,\n \"_embedded\": {\n \"files\": [\n {\n \"hasIndex\": \"564a31aae4b093830b662920\",\n \"_links\": {\n \"self\": {\n \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b662924\"\n }\n },\n \"label\": \"4f40538e4124d6847dda7318200960d7.bam\",\n \"id\": \"564a31aae4b093830b662924\"\n },\n {\n \"hasIndex\": \"564a31aae4b0ef1218175260\",\n \"_links\": {\n \"self\": {\n \"href\": \"https://cgc-datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b66294a\"\n }\n },\n \"label\": \"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam\",\n \"id\": \"564a31aae4b093830b66294a\"\n },\n \n <snip>\n \n ]\n },\n}", "language": "json", "name": "Response body" } ] } [/block] Copy the values for `id` and `hasIndex` for each file you wish to copy. We will use these in Step 2 to copy the files. The `hasIndex` key contains the IDs of associated index files (*.BAI) which are required for analysis alongside of BAM files on the CGC. If `hasIndex` displays as `null`, there are no associated index files. ##Step 2: Make a CGC API request to copy a file Use the values for `id` and `hasIndex` obtained from the Datasets API query above to make the CGC API request to [copy a file](copy-files-between-projects-1), as shown below. Note that if `hasIndex` has a value other than `null`, you need to copy the file IDs for the index files specified in `hasIndex` for your analysis to run properly. [block:code] { "codes": [ { "code": "POST /v2/action/files/copy HTTP/1.1\nHost: cgc-api.sbgenomics.com\nX-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96", "language": "http", "name": "Request" } ] } [/block] [block:code] { "codes": [ { "code": "{\n \"project\": \"RFranklin/my-project\",\n \"file_ids\": [\"564a31aae4b093830b662924\", \"564a31aae4b093830b662920\", \"564a31aae4b093830b66294a\", \"564a31aae4b0ef1218175260\"]\n}", "language": "json", "name": "Request body" } ] } [/block] This returns the following response: [block:code] { "codes": [ { "code": "{\n \"564a31aae4b093830b662924\": {\n \"status\": \"OK\",\n \"new_file_id\": \"583f568fe4b038da1d96a513\",\n \"new_file_name\": \"4f40538e4124d6847dda7318200960d7.bam\"\n },\n \"564a31aae4b093830b66294a\": {\n \"status\": \"OK\",\n \"new_file_id\": \"583f568fe4b038da1d96a517\",\n \"new_file_name\": \"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam\"\n },\n \"564a31aae4b093830b662920\": {\n \"status\": \"OK\",\n \"new_file_id\": \"583f568fe4b038da1d96a515\",\n \"new_file_name\": \"4f40538e4124d6847dda7318200960d7.bam.bai\"\n },\n \"564a31aae4b0ef1218175260\": {\n \"status\": \"OK\",\n \"new_file_id\": \"583f568fe4b038da1d96a519\",\n \"new_file_name\": \"TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam.bai\"\n }\n}", "language": "json", "name": "Response body" } ] } [/block]