Created
September 17, 2022 06:31
-
-
Save kojix2/e3bdbcecf7fc59be449a58a16b978522 to your computer and use it in GitHub Desktop.
Get DDBJ SRA download URLs from BioProject id
This file contains hidden or 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
# DDBJ SRA URL Getter | |
# author: kojix2 | |
require 'net/http' | |
require 'json' | |
require 'tty-spinner' | |
project_id = ARGV[0] | |
if project_id.nil? | |
warn 'Error: No project name.' | |
exit 1 | |
end | |
def json_url(uri) | |
uri = URI.parse(uri) | |
dat = Net::HTTP.get(uri) | |
JSON.parse(dat) | |
end | |
bioproject = json_url("https://ddbj.nig.ac.jp/resource/bioproject/#{project_id}.json") | |
spinner = TTY::Spinner.new('[:spinner] Loading ...', format: :pulse_2) | |
spinner.auto_spin | |
urls = [] | |
bioproject['dbXrefs'].each do |i| | |
next if i['type'] != 'sra-run' | |
sra_run = json_url(i['url'] + '.json') | |
sra_run['downloadUrl'].each do |u| | |
next if u['type'] != 'sra' | |
urls << u['url'] | |
end | |
end | |
spinner.stop('Done!') | |
puts urls |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment