mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 12:13:33 +08:00
Make datatype H5_Model for machine leaning models
This commit is contained in:
@@ -170,6 +170,7 @@
|
||||
<datatype extension="hivtrace" type="galaxy.datatypes.text:Json" mimetype="application/json" subclass="true" display_in_upload="false"/>
|
||||
<datatype extension="cool" type="galaxy.datatypes.binary:Cool" mimetype="application/octet-stream" display_in_upload="true"/>
|
||||
<datatype extension="mcool" type="galaxy.datatypes.binary:MCool" mimetype="application/octet-stream" display_in_upload="true"/>
|
||||
<datatype extension="h5_model" type="galaxy.datatypes.binary:H5_Model" mimetype="application/octet-stream" display_in_upload="true"/>
|
||||
<datatype extension="html" type="galaxy.datatypes.text:Html" mimetype="text/html"/>
|
||||
<datatype extension="interval" type="galaxy.datatypes.interval:Interval" display_in_upload="true" description="File must start with definition line in the following format (columns may be in any order).">
|
||||
<converter file="interval_to_bed_converter.xml" target_datatype="bed"/>
|
||||
@@ -907,6 +908,7 @@
|
||||
<sniffer type="galaxy.datatypes.binary:NcbiTaxonomySQlite"/>
|
||||
<sniffer type="galaxy.datatypes.binary:SQlite"/>
|
||||
<sniffer type="galaxy.datatypes.binary:Cool"/>
|
||||
<sniffer type="galaxy.datatypes.binary:H5_Model"/>
|
||||
<sniffer type="galaxy.datatypes.binary:MCool"/>
|
||||
<sniffer type="galaxy.datatypes.binary:Loom"/>
|
||||
<sniffer type="galaxy.datatypes.binary:Anndata"/>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import binascii
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
@@ -26,7 +27,13 @@ from galaxy.datatypes.data import (
|
||||
DatatypeValidation,
|
||||
get_file_peek,
|
||||
)
|
||||
from galaxy.datatypes.metadata import DictParameter, ListParameter, MetadataElement, MetadataParameter
|
||||
from galaxy.datatypes.metadata import (
|
||||
DictParameter,
|
||||
FileParameter,
|
||||
ListParameter,
|
||||
MetadataElement,
|
||||
MetadataParameter,
|
||||
)
|
||||
from galaxy.datatypes.sniff import build_sniff_from_prefix
|
||||
from galaxy.util import nice_size, sqlite
|
||||
from galaxy.util.checkers import is_bz2, is_gzip
|
||||
@@ -1452,6 +1459,71 @@ class MCool(H5):
|
||||
return "MCool (HDF5) file (%s)." % (nice_size(dataset.get_size()))
|
||||
|
||||
|
||||
class H5_Model(H5):
|
||||
"""
|
||||
Machine learning models generated by Galaxy-ML.
|
||||
"""
|
||||
file_ext = "h5_model"
|
||||
|
||||
MetadataElement(name="params", desc="Hyperparameter File", param=FileParameter, file_ext="tabular", readonly=True, no_value=None, visible=False, optional=True)
|
||||
|
||||
def set_meta(self, dataset, overwrite=True, **kwd):
|
||||
try:
|
||||
spec_key = "params"
|
||||
params_file = dataset.metadata.params
|
||||
if not params_file:
|
||||
params_file = dataset.metadata.spec[spec_key].param.new_file(dataset=dataset)
|
||||
with h5py.File(dataset.file_name, "r") as handle:
|
||||
params = handle["-model_hyperparameters-"][()]
|
||||
params = json.loads(params.decode('utf-8'))
|
||||
with open(params_file.file_name, "w") as f:
|
||||
f.write("\tParameter\tValue\n")
|
||||
for p in params:
|
||||
f.write("\t".json(p) + "\n")
|
||||
dataset.metadata.params_file = params_file
|
||||
except Exception as e:
|
||||
log.warning('%s, set_meta Exception: %s', self, e)
|
||||
|
||||
def sniff(self, filename):
|
||||
URL = "https://github.com/goeckslab/Galaxy-ML"
|
||||
|
||||
if super().sniff(filename):
|
||||
keys = ["-model_config-"]
|
||||
with h5py.File(filename, "r") as handle:
|
||||
if not all(name in handle.keys() for name in keys):
|
||||
return False
|
||||
url = util.unicodify(handle.attrs.get("-URL-"))
|
||||
if url == URL:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_config(self, filename):
|
||||
try:
|
||||
with h5py.File(filename, "r") as handle:
|
||||
config = util.unicodify(handle["-model_config-"][()])
|
||||
return config
|
||||
except Exception as e:
|
||||
log.warning('%s, get model configuration Except: %s', self, e)
|
||||
return ""
|
||||
|
||||
def set_peek(self, dataset, is_multi_byte=False):
|
||||
if not dataset.dataset.purged:
|
||||
config = self.get_config(dataset.file_name)
|
||||
if len(config) > 100:
|
||||
config = config[:100]
|
||||
dataset.peek = config
|
||||
dataset.blurb = nice_size(dataset.get_size())
|
||||
else:
|
||||
dataset.peek = 'file does not exist'
|
||||
dataset.blurb = 'file purged from disk'
|
||||
|
||||
def display_peek(self, dataset):
|
||||
try:
|
||||
return dataset.peek
|
||||
except Exception:
|
||||
return "HDF5 Model (%s)" % (nice_size(dataset.get_size()))
|
||||
|
||||
|
||||
class Scf(Binary):
|
||||
"""Class describing an scf binary sequence file"""
|
||||
edam_format = "format_1632"
|
||||
|
||||
Reference in New Issue
Block a user