Skip to content

Instantly share code, notes, and snippets.

@clintval
Created August 19, 2024 22:09
Show Gist options
  • Save clintval/6a55969f8fa689197dd0cdb7e11366ee to your computer and use it in GitHub Desktop.
Save clintval/6a55969f8fa689197dd0cdb7e11366ee to your computer and use it in GitHub Desktop.
Fetch a DNA sequence from the UCSC Das web server
def dna_sequence_from_DAS(build: str, chrom: str, start: int, end: int) -> str:
"""
Return the DNA sequence along an interval for a reference sequence build.
Uses the DAS web server.
Args:
build: The UCSC genome build.
chrom: The reference sequence name.
start: The 1-based start locus.
end: The inclusive end locus.
Returns:
seq: The DNA sequence in the specified interval of the genome build.
"""
host = f'http://genome.ucsc.edu/cgi-bin/das/{build}/dna'
response = requests.get(host, params={'segment': f'{chrom}:{start},{end}'})
return ElementTree.fromstring(response.content).find('.//DNA').text.replace('\n', '')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment