Skip to content

Commit d0b9ef6

Browse files
committed
Refactor preferred visualization logic
to eliminate circular import between datatypes registry and managers. Move get_preferred_visualization from registry to datatypes manager module where the class hierarchy mapping logic already exists.
1 parent 5fb725a commit d0b9ef6

File tree

3 files changed

+48
-51
lines changed

3 files changed

+48
-51
lines changed

lib/galaxy/datatypes/registry.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -516,56 +516,6 @@ def get_legacy_sites_by_build(self, site_type, build):
516516
def get_display_sites(self, site_type):
517517
return self.display_sites.get(site_type, [])
518518

519-
def get_preferred_visualization(self, datatype_extension):
520-
"""
521-
Get the preferred visualization mapping for a specific datatype extension.
522-
Returns a dictionary with 'visualization' and 'default_params' keys, or None if no mapping exists.
523-
524-
Preferred visualizations are defined inline within each datatype definition in the
525-
datatypes_conf.xml configuration file. These mappings determine which visualization plugin
526-
should be used by default when viewing datasets of a specific type.
527-
528-
If no direct mapping exists for the extension, this method will walk up the inheritance
529-
chain to find a preferred visualization from a parent datatype class.
530-
531-
Example configuration:
532-
<datatype extension="bam" type="galaxy.datatypes.binary:Bam" mimetype="application/octet-stream" display_in_upload="true">
533-
<visualization plugin="igv" />
534-
</datatype>
535-
"""
536-
direct_mapping = self.visualization_mappings.get(datatype_extension)
537-
if direct_mapping:
538-
return direct_mapping
539-
540-
current_datatype = self.get_datatype_by_extension(datatype_extension)
541-
if not current_datatype:
542-
return None
543-
544-
# Use the same mapping approach as the datatypes API for consistency
545-
from galaxy.managers.datatypes import view_mapping
546-
547-
mapping_data = view_mapping(self)
548-
549-
current_class_name = mapping_data.ext_to_class_name.get(datatype_extension)
550-
if not current_class_name:
551-
return None
552-
553-
current_class_mappings = mapping_data.class_to_classes.get(current_class_name, {})
554-
555-
# Find parent extensions that have preferred visualizations
556-
for ext, visualization_mapping in self.visualization_mappings.items():
557-
if ext == datatype_extension:
558-
continue
559-
560-
parent_class_name = mapping_data.ext_to_class_name.get(ext)
561-
if parent_class_name and parent_class_name in current_class_mappings:
562-
self.log.debug(
563-
f"Found inherited preferred visualization '{visualization_mapping['visualization']}' for datatype '{datatype_extension}' from parent '{ext}'"
564-
)
565-
return visualization_mapping
566-
567-
return None
568-
569519
def get_all_visualization_mappings(self):
570520
"""
571521
Get all datatype to visualization mappings.

lib/galaxy/managers/datatypes.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,51 @@ def view_visualization_mappings(
163163
return parse_obj_as(DatatypeVisualizationMappingsList, mappings)
164164

165165

166+
def get_preferred_visualization(datatypes_registry: Registry, datatype_extension: str) -> Optional[Dict[str, str]]:
167+
"""
168+
Get the preferred visualization mapping for a specific datatype extension.
169+
Returns a dictionary with 'visualization' and 'default_params' keys, or None if no mapping exists.
170+
171+
Preferred visualizations are defined inline within each datatype definition in the
172+
datatypes_conf.xml configuration file. These mappings determine which visualization plugin
173+
should be used by default when viewing datasets of a specific type.
174+
175+
If no direct mapping exists for the extension, this method will walk up the inheritance
176+
chain to find a preferred visualization from a parent datatype class.
177+
178+
Example configuration:
179+
<datatype extension="bam" type="galaxy.datatypes.binary:Bam" mimetype="application/octet-stream" display_in_upload="true">
180+
<visualization plugin="igv" />
181+
</datatype>
182+
"""
183+
direct_mapping = datatypes_registry.visualization_mappings.get(datatype_extension)
184+
if direct_mapping:
185+
return direct_mapping
186+
187+
current_datatype = datatypes_registry.get_datatype_by_extension(datatype_extension)
188+
if not current_datatype:
189+
return None
190+
191+
# Use the same mapping approach as the datatypes API for consistency
192+
mapping_data = view_mapping(datatypes_registry)
193+
194+
current_class_name = mapping_data.ext_to_class_name.get(datatype_extension)
195+
if not current_class_name:
196+
return None
197+
198+
current_class_mappings = mapping_data.class_to_classes.get(current_class_name, {})
199+
200+
for ext, visualization_mapping in datatypes_registry.visualization_mappings.items():
201+
if ext == datatype_extension:
202+
continue
203+
204+
parent_class_name = mapping_data.ext_to_class_name.get(ext)
205+
if parent_class_name and parent_class_name in current_class_mappings:
206+
return visualization_mapping
207+
208+
return None
209+
210+
166211
__all__ = (
167212
"DatatypeConverterList",
168213
"DatatypeDetails",
@@ -179,4 +224,5 @@ def view_visualization_mappings(
179224
"view_edam_formats",
180225
"view_edam_data",
181226
"view_visualization_mappings",
227+
"get_preferred_visualization",
182228
)

lib/galaxy/webapps/galaxy/api/datatypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
DatatypesEDAMDetailsDict,
2727
DatatypesMap,
2828
DatatypeVisualizationMappingsList,
29+
get_preferred_visualization,
2930
view_converters,
3031
view_edam_data,
3132
view_edam_formats,
@@ -258,7 +259,7 @@ async def show(
258259
result["converters"] = list(converters.keys())
259260

260261
# Add preferred visualization if any and if the plugin is available
261-
preferred_viz = self.datatypes_registry.get_preferred_visualization(datatype)
262+
preferred_viz = get_preferred_visualization(self.datatypes_registry, datatype)
262263
if preferred_viz:
263264
plugin_name = preferred_viz["visualization"]
264265

0 commit comments

Comments
 (0)