Created
August 19, 2024 22:09
-
-
Save clintval/6a55969f8fa689197dd0cdb7e11366ee to your computer and use it in GitHub Desktop.
Fetch a DNA sequence from the UCSC Das web server
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
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