Last active
November 23, 2023 13:21
-
-
Save epaule/338be9381de1eb01c771eabd90b38ce1 to your computer and use it in GitHub Desktop.
get taxonomic lineage from ENA for a species name
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
#!/usr/bin/env crystal | |
require "http/client" | |
require "json" | |
species = ARGV[0] | |
species = species.gsub(/\s/, "%20") | |
r = HTTP::Client.get("https://www.ebi.ac.uk/ena/taxonomy/rest/scientific-name/#{species}", headers: HTTP::Headers{"Accept" => "application/json"}) | |
raise "cannot get the taxonomy" unless r.success? | |
json = JSON.parse(r.body) | |
if json.as_a.size < 1 | |
r = HTTP::Client.get("https://www.ebi.ac.uk/ena/taxonomy/rest/any-name/#{species}", headers: HTTP::Headers{"Accept" => "application/json"}) | |
raise "cannot get the taxonomy" unless r.success? | |
json = JSON.parse(r.body) | |
end | |
raise "cannot get the taxonomy" if json.as_a.size < 1 | |
puts "#{json[0]["lineage"]}#{ARGV[0]}" |
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
#!/nfs/users/nfs_m/mh6/.linuxbrew/homebrew/bin/ruby | |
require "net/http" | |
require "uri" | |
require "json" | |
require "cgi" | |
species = ARGV[0] | |
species = CGI.escapeURIComponent(species) | |
uri = URI("https://www.ebi.ac.uk/ena/taxonomy/rest/scientific-name/#{species}") | |
r = Net::HTTP.get_response(uri, {"Accept" => "application/json"}) | |
raise "cannot get the taxonomy" unless r.is_a?(Net::HTTPSuccess) | |
json = JSON.parse(r.body) | |
if json.size < 1 | |
uri =URI("https://www.ebi.ac.uk/ena/taxonomy/rest/any-name/#{species}") | |
r = Net::HTTP.get_response(uri,{"Accept" => "application/json"}) | |
raise "cannot get the taxonomy" unless r.is_a?(Net::HTTPSuccess) | |
json = JSON.parse(r.body) | |
end | |
raise "cannot get the taxonomy" if json.size < 1 | |
print "#{json[0]["lineage"]}#{ARGV[0]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment