mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 02:04:04 +08:00
Adjust datatypes preferred viz API /datatypes/{type}/visualizations
This commit is contained in:
@@ -24,35 +24,13 @@ export async function fetchDatatypeVisualizations(): Promise<DatatypeVisualizati
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a datatype visualization mapping
|
||||
*/
|
||||
export async function updateDatatypeVisualization(mapping: DatatypeVisualization): Promise<DatatypeVisualization> {
|
||||
try {
|
||||
const { data } = await axios.put(withPrefix(`/api/datatypes/visualizations/${mapping.datatype}`), mapping);
|
||||
return data;
|
||||
} catch (error) {
|
||||
rethrowSimple(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a datatype visualization mapping
|
||||
*/
|
||||
export async function deleteDatatypeVisualization(datatype: string): Promise<void> {
|
||||
try {
|
||||
await axios.delete(withPrefix(`/api/datatypes/visualizations/${datatype}`));
|
||||
} catch (error) {
|
||||
rethrowSimple(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the preferred visualization for a specific datatype
|
||||
*/
|
||||
export async function getPreferredVisualization(datatype: string): Promise<DatatypeVisualization | null> {
|
||||
try {
|
||||
const url = withPrefix(`/api/datatypes/visualizations/${datatype}`);
|
||||
const url = withPrefix(`/api/datatypes/${datatype}/visualizations`);
|
||||
const { data } = await axios.get(url);
|
||||
|
||||
// If the API returns an array with one item, return that item
|
||||
|
||||
@@ -419,7 +419,7 @@ class Registry:
|
||||
# Load build sites
|
||||
if use_build_sites:
|
||||
self._load_build_sites(root)
|
||||
|
||||
|
||||
# Load visualization mappings
|
||||
self._load_visualization_mappings(root)
|
||||
self.set_default_values()
|
||||
@@ -444,57 +444,55 @@ class Registry:
|
||||
def _load_visualization_mappings(self, root):
|
||||
"""
|
||||
Load datatype to visualization mappings from the datatypes_conf.xml file.
|
||||
|
||||
Administrators can define preferred visualizations for datatypes in the
|
||||
|
||||
Administrators can define preferred visualizations for datatypes in the
|
||||
datatypes_conf.xml configuration file using the visualization_mappings section.
|
||||
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
<visualization_mappings>
|
||||
<visualization_mapping datatype="bam" visualization="igv" />
|
||||
<visualization_mapping datatype="vcf" visualization="jbrowse" />
|
||||
<visualization_mapping datatype="h5" visualization="vitessce" default_params='{"layer":"primary"}' />
|
||||
</visualization_mappings>
|
||||
|
||||
|
||||
These mappings are read-only and must be manually edited in the configuration file.
|
||||
"""
|
||||
# Clear existing mappings
|
||||
self.visualization_mappings = {}
|
||||
|
||||
|
||||
# Find the visualization_mappings element
|
||||
mappings_elem = root.find("visualization_mappings")
|
||||
if mappings_elem is None:
|
||||
# No mappings defined, that's okay
|
||||
return
|
||||
|
||||
|
||||
for mapping_elem in mappings_elem.findall("visualization_mapping"):
|
||||
datatype = mapping_elem.get("datatype", None)
|
||||
visualization = mapping_elem.get("visualization", None)
|
||||
default_params_str = mapping_elem.get("default_params", None)
|
||||
|
||||
|
||||
# Skip incomplete mappings
|
||||
if not datatype or not visualization:
|
||||
self.log.warning("Incomplete visualization mapping (missing datatype or visualization)")
|
||||
continue
|
||||
|
||||
|
||||
# Parse default parameters if provided
|
||||
default_params = None
|
||||
if default_params_str:
|
||||
try:
|
||||
default_params = galaxy.util.safe_loads(default_params_str)
|
||||
except Exception:
|
||||
self.log.exception("Error parsing default_params for visualization mapping: %s -> %s",
|
||||
datatype, visualization)
|
||||
self.log.exception(
|
||||
"Error parsing default_params for visualization mapping: %s -> %s", datatype, visualization
|
||||
)
|
||||
continue
|
||||
|
||||
|
||||
# Store the mapping
|
||||
self.visualization_mappings[datatype] = {
|
||||
"visualization": visualization,
|
||||
"default_params": default_params
|
||||
}
|
||||
|
||||
self.visualization_mappings[datatype] = {"visualization": visualization, "default_params": default_params}
|
||||
|
||||
self.log.debug("Loaded visualization mapping: %s -> %s", datatype, visualization)
|
||||
|
||||
|
||||
def _load_build_sites(self, root):
|
||||
def load_build_site(build_site_config):
|
||||
# Take in either an XML element or simple dictionary from YAML and add build site for this.
|
||||
@@ -548,28 +546,28 @@ class Registry:
|
||||
|
||||
def get_display_sites(self, site_type):
|
||||
return self.display_sites.get(site_type, [])
|
||||
|
||||
|
||||
def get_preferred_visualization(self, datatype_extension):
|
||||
"""
|
||||
Get the preferred visualization mapping for a specific datatype extension.
|
||||
Returns a dictionary with 'visualization' and 'default_params' keys, or None if no mapping exists.
|
||||
|
||||
Preferred visualizations are defined in the datatypes_conf.xml configuration file using
|
||||
the visualization_mappings section. These mappings determine which visualization plugin
|
||||
|
||||
Preferred visualizations are defined in the datatypes_conf.xml configuration file using
|
||||
the visualization_mappings section. These mappings determine which visualization plugin
|
||||
should be used by default when viewing datasets of a specific type.
|
||||
|
||||
|
||||
Example configuration:
|
||||
<visualization_mappings>
|
||||
<visualization_mapping datatype="bam" visualization="igv" />
|
||||
</visualization_mappings>
|
||||
"""
|
||||
return self.visualization_mappings.get(datatype_extension)
|
||||
|
||||
|
||||
def get_all_visualization_mappings(self):
|
||||
"""
|
||||
Get all datatype to visualization mappings.
|
||||
Returns a dictionary where keys are datatype extensions and values are mapping configurations.
|
||||
|
||||
|
||||
Mappings are defined in the datatypes_conf.xml configuration file and are read-only.
|
||||
"""
|
||||
return self.visualization_mappings
|
||||
|
||||
@@ -11,7 +11,7 @@ from galaxy.datatypes._schema import (
|
||||
DatatypeConverterList,
|
||||
DatatypeDetails,
|
||||
DatatypesCombinedMap,
|
||||
DatatypesEDAMDetailsDict,
|
||||
DatatypesEDAMDetailsDict,
|
||||
DatatypesMap,
|
||||
DatatypeVisualizationMapping,
|
||||
DatatypeVisualizationMappingsList,
|
||||
@@ -124,43 +124,47 @@ def view_edam_data(
|
||||
return datatypes_registry.edam_data
|
||||
|
||||
|
||||
def view_visualization_mappings(datatypes_registry: Registry, datatype: Optional[str] = None) -> DatatypeVisualizationMappingsList:
|
||||
def view_visualization_mappings(
|
||||
datatypes_registry: Registry, datatype: Optional[str] = None
|
||||
) -> DatatypeVisualizationMappingsList:
|
||||
"""
|
||||
Get datatype visualization mappings from the registry.
|
||||
|
||||
|
||||
Args:
|
||||
datatypes_registry: The datatypes registry
|
||||
datatype: If provided, return only the mapping for this datatype extension
|
||||
|
||||
|
||||
Returns:
|
||||
A list of datatype visualization mappings
|
||||
"""
|
||||
mappings = []
|
||||
|
||||
|
||||
# Get all mappings
|
||||
all_mappings = datatypes_registry.get_all_visualization_mappings()
|
||||
|
||||
|
||||
# Filter for a specific datatype if requested
|
||||
if datatype and datatype in all_mappings:
|
||||
mapping_info = all_mappings[datatype]
|
||||
mappings.append({
|
||||
"datatype": datatype,
|
||||
"visualization": mapping_info["visualization"],
|
||||
"default_params": mapping_info.get("default_params")
|
||||
})
|
||||
mappings.append(
|
||||
{
|
||||
"datatype": datatype,
|
||||
"visualization": mapping_info["visualization"],
|
||||
"default_params": mapping_info.get("default_params"),
|
||||
}
|
||||
)
|
||||
elif not datatype:
|
||||
for dt, mapping_info in all_mappings.items():
|
||||
mappings.append({
|
||||
"datatype": dt,
|
||||
"visualization": mapping_info["visualization"],
|
||||
"default_params": mapping_info.get("default_params")
|
||||
})
|
||||
|
||||
mappings.append(
|
||||
{
|
||||
"datatype": dt,
|
||||
"visualization": mapping_info["visualization"],
|
||||
"default_params": mapping_info.get("default_params"),
|
||||
}
|
||||
)
|
||||
|
||||
return parse_obj_as(DatatypeVisualizationMappingsList, mappings)
|
||||
|
||||
|
||||
|
||||
|
||||
__all__ = (
|
||||
"DatatypeConverterList",
|
||||
"DatatypeDetails",
|
||||
|
||||
@@ -11,7 +11,10 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from fastapi import Path, Query
|
||||
from fastapi import (
|
||||
Path,
|
||||
Query,
|
||||
)
|
||||
|
||||
from galaxy.datatypes.registry import Registry
|
||||
from galaxy.managers.datatypes import (
|
||||
@@ -168,7 +171,7 @@ class FastAPIDatatypes:
|
||||
"""Gets a map of datatypes and their corresponding EDAM data.
|
||||
EDAM data contains the EDAM iri, label, and definition."""
|
||||
return view_edam_data(self.datatypes_registry, True)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/api/datatypes/visualizations",
|
||||
public=True,
|
||||
@@ -179,9 +182,9 @@ class FastAPIDatatypes:
|
||||
async def visualizations(self) -> DatatypeVisualizationMappingsList:
|
||||
"""Gets a list of all datatype visualization mappings."""
|
||||
return view_visualization_mappings(self.datatypes_registry)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/api/datatypes/visualizations/{datatype}",
|
||||
"/api/datatypes/{datatype}/visualizations",
|
||||
public=True,
|
||||
summary="Returns the visualization mapping for a specific datatype",
|
||||
response_description="Visualization mapping for the specified datatype",
|
||||
@@ -197,7 +200,7 @@ class FastAPIDatatypes:
|
||||
),
|
||||
) -> DatatypeVisualizationMappingsList:
|
||||
"""Gets the visualization mapping for a specific datatype.
|
||||
|
||||
|
||||
Mappings are defined in the datatypes_conf.xml configuration file.
|
||||
"""
|
||||
return view_visualization_mappings(self.datatypes_registry, datatype)
|
||||
|
||||
Reference in New Issue
Block a user