Skip to content

Instantly share code, notes, and snippets.

@ksuderman
Created November 6, 2022 00:02
Show Gist options
  • Save ksuderman/5a48f970cabc2bf62a882b9829835efa to your computer and use it in GitHub Desktop.
Save ksuderman/5a48f970cabc2bf62a882b9829835efa to your computer and use it in GitHub Desktop.
Python script to query the AskGalaxy service to generate CSV data for Observable.
#!/usr/bin/env python3
import os
import sys
import json
import requests
KB = 1024
MB = KB * KB
GB = MB * KB
service = 'https://ask.galaxyproject.org'
tools = ['bowtie2', 'bwa_mem', 'minimap2' ]
metric = sys.argv[1]
def get_url(tool, metric, input_size):
size = input_size * GB
params = ''
if tool == 'bowtie2':
params = f'fastqsanger_file_size_bytes_1={size}&fastqsanger_file_size_bytes_2={size}&fasta_file_size_bytes=1000000&format_output=false'
elif tool == 'bwa_mem' or tool == 'minimap2':
p = []
for x in [1,2,11,12]:
p.append(f"fastq_input{x}={size}")
params = '&'.join(p) + "&ref_file=1000000"
elif tool == 'featurecounts':
params = f'alignment_file_size_bytes={size}'
else:
raise Exception(f'Unsupported tool type {tool}')
return f'{service}/{tool}/{metric}/?{params}'
headers = { 'Accept': 'application/json' }
print(f"GB,Tool,Value")
for i in range(30):
size = i+1
for tool in tools:
url = get_url(tool, metric, size)
#print(url)
response = requests.get(url, headers=headers)
data = response.json()
if 'memory' == metric:
print(f"{size},{tool},{(data['Required memory']/GB):02.2f}")
else:
print(f"{size},{tool},{(data['Required CPU']):02.2f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment