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

Show tool with the latest version #9828

Draft
wants to merge 3 commits into
base: release_20.05
Choose a base branch
from
Draft
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion lib/galaxy/tools/recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,32 @@ def __set_model(self, trans, remote_model_url):
for k in tool_pos_sorted:
self.tool_weights_sorted[k] = tool_weights[str(k)]
# collect ids and names of all the installed tools
all_t = dict()
for tool_id, tool in trans.app.toolbox.tools():
t_id_renamed = tool_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use if tool.is_latest_version and then drop the other changes

if t_id_renamed.find("/") > -1:
t_id_renamed = t_id_renamed.split("/")[-2]
self.all_tools[t_id_renamed] = (tool_id, tool.name)
if t_id_renamed not in all_t:
all_t[t_id_renamed] = list()
all_t[t_id_renamed].append((tool_id, tool.version_object, tool.name))
self.all_tools = self.__get_latest_tool(all_t)
return True

def __get_latest_tool(self, a_tools):
"""
Sort tool versions and take the latest one
"""
all_tools = dict()
for t in a_tools:
t_versions = list()
for t_v in a_tools[t]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to get the index without sorting.

Something along the lines of:

max_index, max_value = max(enumerate(values), key=operator.itemgetter(1))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, will test it and update

t_versions.append(t_v[1])
s_t_v = sorted(t_versions)
# get tool with the latest version
latest_t = a_tools[t][t_versions.index(s_t_v[-1])]
all_tools[t] = (latest_t[0], latest_t[2])
return all_tools

def __collect_admin_preferences(self, admin_path):
"""
Collect preferences for recommendations of tools
Expand Down