admin管理员组

文章数量:1357082

I am trying to fetch variant details, including population allele frequency (af), from the gnomAD database using the GraphQL API. However, the query does not return allele frequency for populations. When I add af under populations, I get the following error:

GraphQLError: Cannot query field 'af' on type 'VariantPopulation'. Did you mean 'ac' or 'an'?

GraphQL request:10:9
 9 |         populations {
10 |         af
   |         ^
11 |         id

My Query:

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# GraphQL query to fetch variant details
query = gql(
"""
query VariantsInGene {
    gene(gene_symbol: "PTH", reference_genome: GRCh38) {
        variants(dataset: gnomad_r4) {
            variant_id
            pos
            exome {
                af
                populations {
                    id
                    af
                }
            }
        }
    }
}
"""
)

res = await client.execute_async(query)

What I Tried:

  • Fetching allele frequency (af) at the exome level (works fine).
  • Adding af inside populations (causes the error).
  • Checking available fields for VariantPopulation (suggests ac and an, but not af).

Question:

How can I retrieve allele frequency (af) per population in gnomAD GraphQL? If I remove af from query it executes but no af is retrieved for populations:

I am trying to fetch variant details, including population allele frequency (af), from the gnomAD database using the GraphQL API. However, the query does not return allele frequency for populations. When I add af under populations, I get the following error:

GraphQLError: Cannot query field 'af' on type 'VariantPopulation'. Did you mean 'ac' or 'an'?

GraphQL request:10:9
 9 |         populations {
10 |         af
   |         ^
11 |         id

My Query:

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# GraphQL query to fetch variant details
query = gql(
"""
query VariantsInGene {
    gene(gene_symbol: "PTH", reference_genome: GRCh38) {
        variants(dataset: gnomad_r4) {
            variant_id
            pos
            exome {
                af
                populations {
                    id
                    af
                }
            }
        }
    }
}
"""
)

res = await client.execute_async(query)

What I Tried:

  • Fetching allele frequency (af) at the exome level (works fine).
  • Adding af inside populations (causes the error).
  • Checking available fields for VariantPopulation (suggests ac and an, but not af).

Question:

How can I retrieve allele frequency (af) per population in gnomAD GraphQL? If I remove af from query it executes but no af is retrieved for populations:

Share Improve this question edited Mar 28 at 19:01 TylerH 21.1k78 gold badges79 silver badges114 bronze badges asked Mar 28 at 6:11 nicholaspoorannicholaspooran 7271 silver badge11 bronze badges 1
  • 1 There doesn't appear to be a programming problem here, per se. You are asking for something that's not provided through the API. You might be able to get the data you want by downloading a copy of the database and running your own analysis on it (or some variation of that idea), but that's a very different question. – Tangentially Perpendicular Commented Mar 28 at 6:42
Add a comment  | 

1 Answer 1

Reset to default 1
for variant in res['gene']['variants']:
    if 'exome' in variant and 'populations' in variant['exome']
        for pop in variant['exome']['populations']:
            pop['af'] = pop['ac'] / pop['an'] if pop['an'] > 0 else None

You can add ac and an inside population and compute af

The ac (allele count): tells how many times the allele was observed.

The an (allele number): is the total number of alleles sampled.

Compute af = ac / an manually.

本文标签: graphqlHow to fetch population based allelle frequency for variants in a gene using apiStack Overflow