Skip to content

Commit

Permalink
Merge pull request galaxyproject#18892 from jmchilton/axe_drill_down_…
Browse files Browse the repository at this point in the history
…filters

Remove some unused dynamic drill down options.
  • Loading branch information
martenson authored Oct 2, 2024
2 parents a4c640e + cee6a76 commit 2e9ca39
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 74 deletions.
7 changes: 0 additions & 7 deletions lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,12 @@ def get_index_file_name(self) -> Optional[str]:
"""If dynamic options are loaded from an index file, return the name."""


DrillDownDynamicFilters = Dict[str, Dict[str, dict]] # {input key: {metadata_key: metadata values}}


class DrillDownDynamicOptions(metaclass=ABCMeta):

@abstractmethod
def from_code_block(self) -> Optional[str]:
"""Get a code block to do an eval on."""

@abstractmethod
def from_filters(self) -> Optional[DrillDownDynamicFilters]:
"""Get filters to apply to target datasets."""


class InputSource(metaclass=ABCMeta):
default_optional = False
Expand Down
50 changes: 4 additions & 46 deletions lib/galaxy/tool_util/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from .interface import (
AssertionList,
Citation,
DrillDownDynamicFilters,
DrillDownDynamicOptions,
DrillDownOptionsDict,
DynamicOptions,
Expand Down Expand Up @@ -1374,50 +1373,13 @@ def parse_static_options(self) -> List[Tuple[str, str, bool]]:
def parse_drill_down_dynamic_options(
self, tool_data_path: Optional[str] = None
) -> Optional[DrillDownDynamicOptions]:
from_file = self.input_elem.get("from_file", None)
if from_file:
if not os.path.isabs(from_file):
assert tool_data_path, "This tool cannot be parsed outside of a Galaxy context"
from_file = os.path.join(tool_data_path, from_file)
elem = XML(f"<root>{open(from_file).read()}</root>")
else:
elem = self.input_elem

elem = self.input_elem
dynamic_options_raw = elem.get("dynamic_options", None)
dynamic_options: Optional[str] = str(dynamic_options_raw) if dynamic_options_raw else None
filters: Optional[DrillDownDynamicFilters] = None
if elem.find("filter"):
_filters: DrillDownDynamicFilters = {}
for filter in elem.findall("filter"):
# currently only filtering by metadata key matching input file is allowed
filter_type = filter.get("type")
if filter_type == "data_meta":
data_ref = filter.get("data_ref")
assert data_ref
if data_ref not in _filters:
_filters[data_ref] = {}
meta_key = filter.get("meta_key")
assert meta_key
if meta_key not in _filters[data_ref]:
_filters[data_ref][meta_key] = {}
meta_value = filter.get("value")
if meta_value not in _filters[data_ref][meta_key]:
_filters[data_ref][meta_key][meta_value] = []
assert meta_value
options_elem = filter.find("options")
assert options_elem
_recurse_drill_down_elems(
_filters[data_ref][meta_key][meta_value],
options_elem.findall("option"),
)
filters = _filters
if filters is None and dynamic_options is None:
if dynamic_options is None:
return None
else:
return XmlDrillDownDynamicOptions(
code_block=dynamic_options,
filters=filters,
)
return XmlDrillDownDynamicOptions(code_block=dynamic_options)

def parse_drill_down_static_options(
self, tool_data_path: Optional[str] = None
Expand Down Expand Up @@ -1575,17 +1537,13 @@ def parse_citation_elem(citation_elem: Element) -> Optional[Citation]:

class XmlDrillDownDynamicOptions(DrillDownDynamicOptions):

def __init__(self, code_block: Optional[str], filters: Optional[DrillDownDynamicFilters]):
def __init__(self, code_block: Optional[str]):
self._code_block = code_block
self._filters = filters

def from_code_block(self) -> Optional[str]:
"""Get a code block to do an eval on."""
return self._code_block

def from_filters(self) -> Optional[DrillDownDynamicFilters]:
return self._filters


def _element_to_dict(elem: Element) -> Dict[str, Any]:
# every call to this function needs to be replaced with something more type safe and with
Expand Down
23 changes: 2 additions & 21 deletions lib/galaxy/tools/parameters/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1646,13 +1646,11 @@ def __init__(self, tool, input_source, context=None):
drill_down_dynamic_options = input_source.parse_drill_down_dynamic_options(tool_data_path)
if drill_down_dynamic_options is not None:
self.is_dynamic = True
self.dynamic_options = drill_down_dynamic_options.code_block
self.filtered = drill_down_dynamic_options.filters
self.dynamic_options = drill_down_dynamic_options.from_code_block()
self.options = []
else:
self.is_dynamic = False
self.dynamic_options = None
self.filtered = {}
self.options = input_source.parse_drill_down_static_options(tool_data_path)

def _get_options_from_code(self, trans=None, other_values=None):
Expand All @@ -1673,20 +1671,6 @@ def get_options(self, trans=None, other_values=None):
options = self._get_options_from_code(trans=trans, other_values=other_values)
else:
options = []
for filter_key, filter_value in self.filtered.items():
dataset = other_values.get(filter_key)
if dataset.__class__.__name__.endswith(
"DatasetFilenameWrapper"
): # this is a bad way to check for this, but problems importing class (due to circular imports?)
dataset = dataset.dataset
if dataset:
for meta_key, meta_dict in filter_value.items():
if hasattr(dataset, "metadata") and hasattr(dataset.metadata, "spec"):
check_meta_val = dataset.metadata.spec[meta_key].param.to_string(
dataset.metadata.get(meta_key)
)
if check_meta_val in meta_dict:
options.extend(meta_dict[check_meta_val])
return options
return self.options

Expand Down Expand Up @@ -1830,10 +1814,7 @@ def get_option_display(value, options):
return "Nothing selected."

def get_dependencies(self):
"""
Get the *names* of the other params this param depends on.
"""
return list(self.filtered.keys())
return []

def to_dict(self, trans, other_values=None):
other_values = other_values or {}
Expand Down

0 comments on commit 2e9ca39

Please sign in to comment.