Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement nicer categories for toolshed install instructions #4515

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ annotate: ## annotate the tutorials with usable Galaxy instances
wget https://github.com/hexylena/toolshed-version-database/raw/main/guid-rev.json -O metadata/toolshed-revisions.json && \
python bin/supported-fetch.py
bin/workflows-fetch.rb
bin/fetch-categories.rb
.PHONY: annotate

rebuild-search-index: ## Rebuild search index
Expand Down
12 changes: 12 additions & 0 deletions _plugins/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ def generate(site)
page2.data['layout'] = nil
site.pages << page2

# Tool Categories
page2 = PageWithoutAFile.new(site, '', 'api/', 'toolcats.json')
page2.content = JSON.generate(site.data['toolcats'])
page2.data['layout'] = nil
site.pages << page2

# Tool Categories
page2 = PageWithoutAFile.new(site, '', 'api/', 'toolshed-revisions.json')
page2.content = JSON.generate(site.data['toolshed-revisions'])
page2.data['layout'] = nil
site.pages << page2

# Contributors
puts '[GTN/API] Contributors, Funders, Organisations'
%w[contributors funders organisations].each do |type|
Expand Down
4 changes: 2 additions & 2 deletions _plugins/gtn/toolshed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Toolshed
# +topic+:: The topic to install the tools under
# Returns:
# +supported+:: A string of the admin install, ready for ephemeris
def self.format_admin_install(data, tool_list, topic)
def self.format_admin_install(data, tool_list, topic, tool_cats)
# p "Calculating supported servers for this tool list"
return {} if data.nil? || data.empty?

Expand All @@ -23,7 +23,7 @@ def self.format_admin_install(data, tool_list, topic)
'name' => tool_info[1],
'owner' => tool_info[0],
'revisions' => tool_info[2],
'tool_panel_section_label' => topic,
'tool_panel_section_label' => tool_cats["#{tool_info[0]}/#{tool_info[1]}"] || topic,
'tool_shed_url' => 'https://toolshed.g2.bx.psu.edu/',
}
end
Expand Down
2 changes: 1 addition & 1 deletion _plugins/jekyll-topic-filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def self.resolve_material(site, material)
topic_name_human = site.data[page_obj['topic_name']]['title']
page_obj['topic_name_human'] = topic_name_human # TODO: rename 'topic_name' and 'topic_name' to 'topic_id'
admin_install = Gtn::Toolshed.format_admin_install(site.data['toolshed-revisions'], page_obj['tools'],
topic_name_human)
topic_name_human, site.data['toolcats'])
page_obj['admin_install'] = admin_install
page_obj['admin_install_yaml'] = admin_install.to_yaml

Expand Down
61 changes: 61 additions & 0 deletions bin/fetch-categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env ruby
require 'json'
require 'net/http'
require 'uri'
require 'yaml'

# Get the list of toolcats
def fetch_toolcats(server)
uri = URI.parse("#{server}")
request = Net::HTTP::Get.new(uri)
req_options = {
use_ssl: uri.scheme == 'https',
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end

begin
JSON.parse(response.body) do |w|
w
end
rescue StandardError
{}
end
end

# Parse the response
toolcats_eu = fetch_toolcats('https://usegalaxy-eu.github.io/usegalaxy-eu-tools/api/labels.json')
# toolcats_eu = File.open('/tmp/tmp.ccFYsrbAa5/usegalaxy-eu-tools/api/labels.json') { |f| YAML.safe_load(f) }
toolcats_org = fetch_toolcats('https://galaxyproject.github.io/usegalaxy-tools/api/labels.json')
toolcats_aus = fetch_toolcats('https://usegalaxy-au.github.io/usegalaxy-au-tools/api/labels.json')
# toolcats_aus = File.open('/tmp/tmp.ccFYsrbAa5/usegalaxy-au-tools/api/labels.json') { |f| YAML.safe_load(f) }
tool_ids = (toolcats_org.keys + toolcats_eu.keys + toolcats_aus.keys).uniq
# tool_ids = toolcats_org.keys
tool_ids.sort!

toolcats = {}
# Cleanup the list
tool_ids.each do |k|
eu = toolcats_eu[k] || nil
org = toolcats_org[k] || nil
aus = toolcats_aus[k] || nil

# We get N 'votes' for the categories
values = [eu, org, aus].compact
# values = [org].compact


# Majority answer wins
# set that value to toolcats[k]
# If there is no majority, pick one.
# print("#{k} - #{values.length} => #{values.uniq.compact.length}\n")
if values.length.positive?
toolcats[k] = values.max_by { |v| v['count'] }
else
toolcats[k] = nil
end
end

# Write the list to a file
File.write('metadata/toolcats.yml', toolcats.to_yaml)
Loading