Untitled
unknown
python
a year ago
1.1 kB
2
Indexable
Never
import requests def get_ena_run_ids(sample_ids): base_url = 'https://www.ebi.ac.uk/ena/browser/api/xml' # Create a comma-separated list of sample IDs sample_ids_str = ','.join(sample_ids) # Prepare the API request URL url = f'{base_url}/runs/{sample_ids_str}' # Send a GET request to the ENA API response = requests.get(url) # Check if the request was successful if response.status_code == 200: # Parse the XML response xml_data = response.text # Extract the Run IDs from the XML response run_ids = [] for line in xml_data.split('\n'): if '<RUN accession="' in line: run_id = line.split('accession="')[1].split('"')[0] run_ids.append(run_id) return run_ids else: # Print an error message if the request failed print(f'Failed to retrieve ENA Run IDs. Error code: {response.status_code}') return [] # Example usage sample_ids = ['SAMPLE_ID_1', 'SAMPLE_ID_2', 'SAMPLE_ID_3'] run_ids = get_ena_run_ids(sample_ids) print(run_ids)