Skip to content

Commit

Permalink
Merge pull request #11801 from qiagu/ometiff2
Browse files Browse the repository at this point in the history
Make Avivator GEDA and sniffer for ome.tiff datatype
  • Loading branch information
mvdbeek authored Apr 8, 2021
2 parents dec78b7 + 17adb6a commit c87a0dd
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/galaxy/config/sample/datatypes_conf.xml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@
<datatype extension="svs" type="galaxy.datatypes.images:Tiff" subclass="true" display_in_upload="false"/>
<datatype extension="scn" type="galaxy.datatypes.images:Tiff" subclass="true" display_in_upload="false"/>
<datatype extension="bif" type="galaxy.datatypes.images:Tiff" subclass="true" display_in_upload="false"/>
<datatype extension="ome.tiff" type="galaxy.datatypes.images:Tiff" subclass="true" display_in_upload="true"/>
<datatype extension="ome.tiff" type="galaxy.datatypes.images:OMETiff" display_in_upload="true">
<display file="image/avivator.xml"/>
</datatype>
<datatype extension="vms" type="galaxy.datatypes.images:Hamamatsu" mimetype="image/hamamatsu"/>
<datatype extension="vmu" type="galaxy.datatypes.images:Hamamatsu" subclass="true" display_in_upload="false"/>
<datatype extension="ndpi" type="galaxy.datatypes.images:Hamamatsu" subclass="true" display_in_upload="false"/>
Expand Down Expand Up @@ -1055,6 +1057,7 @@
<sniffer type="galaxy.datatypes.images:Mrc2014"/>
<sniffer type="galaxy.datatypes.images:Jpg"/>
<sniffer type="galaxy.datatypes.images:Png"/>
<sniffer type="galaxy.datatypes.images:OMETiff"/>
<sniffer type="galaxy.datatypes.images:Tiff"/>
<sniffer type="galaxy.datatypes.images:Bmp"/>
<sniffer type="galaxy.datatypes.images:Gif"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<display id="avivator" version="1.0.0" name="display at">
<link id="main" name="Avivator">
<url>http://avivator.gehlenborglab.org/?image_url=${qp($tiff_file.url)}</url>
<param type="data" name="tiff_file" url="galaxy_${DATASET_HASH}.ome.tiff" allow_cors="true"/>
<param type="data" name="offsets_file" url="galaxy_${DATASET_HASH}.offsets.json" metadata="offsets" allow_cors="true"/>
</link>
</display>
28 changes: 28 additions & 0 deletions lib/galaxy/datatypes/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
Image classes
"""
import base64
import json
import logging
import zipfile
from io import StringIO
from urllib.parse import quote_plus

import mrcfile
import numpy as np
import tifffile

from galaxy.datatypes.binary import Binary
from galaxy.datatypes.metadata import (
FileParameter,
MetadataElement,
)
from galaxy.datatypes.text import Html as HtmlFromText
from galaxy.util import nice_size
from galaxy.util.image_util import check_image_type
Expand Down Expand Up @@ -80,6 +86,28 @@ class Tiff(Image):
file_ext = "tiff"


class OMETiff(Tiff):
file_ext = "ome.tiff"
MetadataElement(name="offsets", desc="Offsets File", param=FileParameter, file_ext="json", readonly=True, no_value=None, visible=False, optional=True)

def set_meta(self, dataset, overwrite=True, **kwd):
spec_key = 'offsets'
offsets_file = dataset.metadata.offsets
if not offsets_file:
offsets_file = dataset.metadata.spec[spec_key].param.new_file(dataset=dataset)
with tifffile.TiffFile(dataset.file_name) as tif:
offsets = [page.offset for page in tif.pages]
with open(offsets_file.file_name, 'w') as f:
json.dump(offsets, f)
dataset.metadata.offsets = offsets_file

def sniff(self, filename):
with tifffile.TiffFile(filename) as tif:
if tif.is_ome:
return True
return False


class Hamamatsu(Image):
file_ext = "vms"

Expand Down
Binary file added lib/galaxy/datatypes/test/1.ome.tiff
Binary file not shown.
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ svgwrite==1.4.1; python_version >= "3.6"
tempita==0.5.2
tenacity==7.0.0
testfixtures==6.17.1
tifffile==2020.9.3
toml==0.10.2; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.6"
tornado==6.1; python_version >= "3.5"
tqdm==4.59.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0"
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/pinned-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ stevedore==3.3.0; python_version >= "3.6"
svgwrite==1.4.1; python_version >= "3.6"
tempita==0.5.2
tenacity==7.0.0
tifffile==2020.9.3
tornado==6.1; python_version >= "3.5"
tqdm==4.59.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0"
typing-extensions==3.7.4.3; python_version >= "3.6" and python_version < "3.8"
Expand Down
1 change: 1 addition & 0 deletions packages/data/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ social-auth-core[openidconnect]==3.3.0
SQLAlchemy>=1.3.0,<1.4.0 # https://github.com/kvesteri/sqlalchemy-utils/issues/474
sqlalchemy-migrate
sqlalchemy-utils
tifffile<=2020.9.3 # Last version compatible with python 3.6
WebOb
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ sqlparse = "*"
starlette = "*"
starlette-context = {version = "*", python = ">=3.7"}
svgwrite = "*"
tifffile = "<=2020.9.3" # Last version compatible with python 3.6
uvicorn = "*"
WebOb = "*"
Whoosh = "*"
Expand Down

0 comments on commit c87a0dd

Please sign in to comment.