GraphQL query for expression data

Hello,

I am trying to run a GraphQL query to pull expression data for a target. Based on the schema (https://api.platform.opentargets.org/api/v4/graphql/schema), it looks like I should use the term ‘expressions’. However, the below query string appears to fail. If I remove ‘expressions’ from the term list in the string, it works. Am I using the right term to extract expression data? And related, is this just going to be the Expression Atlas data or will it include the GTEx data too?

Failing query:

query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
      expressions
    }
  }
"

Successful query:

query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
    }
  }
"

Thanks!
Michael

Hello Michael,

When using the expressions field you’ll need to specify which fields you’re going to need as it is a structure. So you’ll need to specify if you need protein, tissue or rna or any combination and the same for each field.

The following is the specification for the Expression type and it’s subtypes.

 type Expression {
protein: ProteinExpression!
tissue: Tissue!
rna: RNAExpression!
}
type ProteinExpression {
reliability: Boolean!
level: Int!
cellType: [CellType!]!
}
type Tissue {
label: String!
organs: [String!]!
id: String!
anatomicalSystems: [String!]!
}
type RNAExpression {
zscore: Long!
unit: String!
level: Int!
value: Float!
}

Hi Ricardo,

Great, thanks for these additional details. How would this query look then with these additional details? Should the below query work? I’m finding that it’s still failing.

query_string = "
  query target($ensemblId: String!){
    target(ensemblId: $ensemblId){
      id
      approvedSymbol
      biotype
      expressions {
        ProteinExpression {
          reliability
          level
        }
      }
    }
  }
"

this is because of an incorrect field name. You’re trying to query ProteinExpression which is the type but the field name is protein. The following is an example of the query including all the subtypes you could use it to select the ones you’re interested in

query target($ensemblId: String!) {
  target(ensemblId: $ensemblId) {
    id
    approvedSymbol
    biotype
    expressions {
      protein {
        reliability
        level
        cellType {
          reliability
          level
          name
        }
      }
      tissue {
        label
        organs
        id
        anatomicalSystems
      }
      rna {
        zscore
        unit
        level
        value
      }
    }
  }
}

Ah got it, thanks Ricardo. I think I’m understanding more how the schema works now with the subtypes and how to properly access them.

Hi again Ricardo – have another GraphQL/Schema question. I’m trying to pull L2G information for a credible set. But I’m having troubles following the scheme for L2G specifically. Below is the query I’m trying but it is failing. I think I’m not getting how to cut down on the output of the L2G query using the page specifications. Do you have any suggestions or clarifications? I’m basing this on the example API code you get when you look at a credible set in the platform.

query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page {
            	index
            	size
          		}) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

If I remove the page{} part the query will run but I get the below error:

“message”: “Query is too expensive. The response size is likely to be too large. Try requesting smaller page sizes or fewer items”

So I think I need to use the pagination part to cut down on the size of the output.

Thanks!

Hi again,

Just adding here a partial solution for the page() syntex I found in case anyone else is looking to figure out the same thing. It works but also throws an error/warning at the end:

query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page: [1,1]) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

Hello Michel,

No worries, the issue with the page argument is the format and values. When passing an argument to a query you’ll need to pass the name and value separated by colon <name>: <value>. In the query you sent you’re missing the colon between page and the bracket. Also, you’re missing the values for index and size. The following is an example with hard coded values for them but you can use parameters as well.

query GwasCredibleSetsQuery($ensemblId: String!, $efoId: String!, $size: Int!) {
  target(ensemblId: $ensemblId) {
    approvedSymbol
  }
  disease(efoId: $efoId) {
    id
    name
    gwasCredibleSets: evidences(
      ensemblIds: [$ensemblId]
      enableIndirect: true
      datasourceIds: ["gwas_credible_sets"]
      size: $size
    ) {
      count
      rows {
        disease {
          id
          name
        }
        credibleSet {
          studyLocusId
          study {
            traitFromSource
            id
            projectId
            publicationFirstAuthor
            publicationDate
            pubmedId
            nSamples
          }
          variant {
            id
            chromosome
            position
            referenceAllele
            alternateAllele
          }
          pValueMantissa
          pValueExponent
          beta
          finemappingMethod
          confidence
          l2GPredictions (page: {
            	index: 1
            	size: 1
          		}) {
            rows {
              score
            }
            count
          }
        }
        score
      }
    }
  }
}

The issue with this query is the way you’re passing the arguments. The following is an extract from the graphql js documentation. It’s a different language from the one we use (scala) but it explains the point on names and values. Also worth noting that the page argument is of type Pagination and because it’s a type and not a scalar you’ll need to use brackets (the same way as when asking for a field. An example of a scalar value would be approvedSymbol which is of type String! and an example of type would be disease which is of type Disease, the difference being that in the case of the query you don’t need to use the colon whilst in the arguments you do need them.

When you call this API, you have to pass each argument by name. So for the server above, you could issue this GraphQL query to roll three six-sided dice:

{
  rollDice(numDice: 3, numSides: 6)
}

This is great, thanks for all the additional details and clarifications Ricardo, much appreciated!

1 Like