To find more information please see our docs or our public service schema explorer.
Created
November 8, 2024 15:39
-
-
Save andrewyatz/e457d42b4bb05b346cd17a87474fe8da to your computer and use it in GitHub Desktop.
Collection of utilities to work with Ensembl's GraphQL service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires you to install gql | |
from gql import gql, Client | |
from gql.transport.aiohttp import AIOHTTPTransport | |
from pprint import pp | |
server="https://beta.ensembl.org/data/graphql" | |
transport = AIOHTTPTransport(url=server) | |
# Create a GraphQL client using the defined transport | |
async with Client( | |
transport=transport, | |
fetch_schema_from_transport=True, | |
) as session: | |
# Provide a GraphQL query | |
query = gql( | |
""" | |
query getAssembly($accession: String!) { | |
genomes(by_keyword: { assembly_accession_id: $accession}) { | |
genome_id | |
assembly_accession | |
scientific_name | |
release_number | |
release_date | |
taxon_id | |
parlance_name | |
is_reference | |
assembly { | |
name | |
accession_id | |
regions { | |
name | |
length | |
sequence { | |
checksum | |
} | |
} | |
} | |
} | |
} | |
""" | |
) | |
params = { "accession" : "GCA_000001405.29" } | |
# Execute the query on the transport | |
result = await session.execute(query, variable_values=params) | |
pp(result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment