Access data from the Datasets API

The Datasets API can be linked to the Seven Bridges API. This means that file IDs returned by queries in Datasets API can be used in the Seven Bridges 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.

POST /datasets/tcga/v0/query HTTP/1.1
Host: datasets-api.sbgenomics.com
X-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96
{
    "entity":"files",
    "hasCase":{
        "hasDiseaseType":"Breast Invasive Carcinoma",
        "hasSample":{
            "hasSampleType":"Primary Tumor"
          }
        },
    "hasDataFormat":"BAM"
}

This returns the following response body:

{
  "count": 100,
  "_embedded": {
    "files": [
      {
        "hasIndex": "564a31aae4b093830b662920",
        "_links": {
          "self": {
            "href": "https://datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b662924"
          }
        },
        "label": "4f40538e4124d6847dda7318200960d7.bam",
        "id": "564a31aae4b093830b662924"
      },
      {
        "hasIndex": "564a31aae4b0ef1218175260",
        "_links": {
          "self": {
            "href": "https://datasets-api.sbgenomics.com/datasets/tcga/v0/files/564a31aae4b093830b66294a"
          }
        },
        "label": "TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam",
        "id": "564a31aae4b093830b66294a"
      },
       
      <snip>
       
    ]
  },
}

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 Seven Bridges Platform. If hasIndex displays as null, there are no associated index files.

Step 2: Make an API request to copy a file

Use the values for id and hasIndex obtained from the Datasets API query above to make the API request to copy a file, 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.

POST /v2/action/files/copy HTTP/1.1
Host: api.sbgenomics.com
X-SBG-Auth-Token: 7942f56901534434a054dafc3813bc96
{
  "project": "RFranklin/my-project",
  "file_ids": ["564a31aae4b093830b662924", "564a31aae4b093830b662920", "564a31aae4b093830b66294a", "564a31aae4b0ef1218175260"]
}

This returns the following response:

{
  "564a31aae4b093830b662924": {
    "status": "OK",
    "new_file_id": "583f568fe4b038da1d96a513",
    "new_file_name": "4f40538e4124d6847dda7318200960d7.bam"
  },
  "564a31aae4b093830b66294a": {
    "status": "OK",
    "new_file_id": "583f568fe4b038da1d96a517",
    "new_file_name": "TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam"
  },
  "564a31aae4b093830b662920": {
    "status": "OK",
    "new_file_id": "583f568fe4b038da1d96a515",
    "new_file_name": "4f40538e4124d6847dda7318200960d7.bam.bai"
  },
  "564a31aae4b0ef1218175260": {
    "status": "OK",
    "new_file_id": "583f568fe4b038da1d96a519",
    "new_file_name": "TCGA-GM-A5PV-01A-11R-A28I-13_mirna.bam.bai"
  }
}