Skip to content

Commit

Permalink
WIP - IDR add option to connect to private omero instance (#3278)
Browse files Browse the repository at this point in the history
* option connect to private omero instance

* increase version number

* fix flake8 error

* bump omero version, changed -s argument

* fix flake8 error again L134

* add readme, validate username, and host

* host validator

* various fixes; updated channel in tests

* error out if username/password is empty; various spelling fixes

Co-authored-by: galaxy <[email protected]>
  • Loading branch information
sunyi000 and galaxy authored Nov 5, 2020
1 parent e30be19 commit 6b9df5f
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 14 deletions.
18 changes: 18 additions & 0 deletions tools/idr_download/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Set up user credentials on Galaxy to connect to other omero instance

To enable users to set their credentials for this tool,
make sure the file `config/user_preferences_extra.yml` has the following section:

```
omero_account:
description: Your OMERO instance connection credentials
inputs:
- name: username
label: Username
type: text
required: False
- name: password
label: Password
type: password
required: False
```
22 changes: 16 additions & 6 deletions tools/idr_download/idr_download_by_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def download_image_data(
image_ids,
channel=None, z_stack=0, frame=0,
coord=(0, 0), width=0, height=0, region_spec='rectangle',
skip_failed=False, download_tar=False
skip_failed=False, download_tar=False, omero_host='idr.openmicroscopy.org', omero_secured=True, omero_username='public', omero_password='public'
):
# basic argument sanity checks and adjustments
prefix = 'image-'
Expand All @@ -127,14 +127,12 @@ def download_image_data(
'Got unknown value "{0}" as region_spec argument'
.format(region_spec)
)

with ExitStack() as exit_stack:
# connect to idr
conn = exit_stack.enter_context(
BlitzGateway(
'public', 'public',
host='idr.openmicroscopy.org',
secure=True
omero_username, omero_password,
host=omero_host,
secure=omero_secured
)
)
# exit_stack.callback(conn.connect().close)
Expand Down Expand Up @@ -356,6 +354,18 @@ def _center_to_ul(center_x, center_y, width, height):
p.add_argument(
'--download-tar', action='store_true'
)
p.add_argument(
'-oh', '--omero-host', type=str, default="idr.openmicroscopy.org"
)
p.add_argument(
'--omero-secured', action='store_false'
)
p.add_argument(
'-u', '--omero-username', type=str, default="public"
)
p.add_argument(
'-p', '--omero-password', type=str, default="public"
)
args = p.parse_args()
if not args.image_ids:
args.image_ids = sys.stdin.read().split()
Expand Down
73 changes: 65 additions & 8 deletions tools/idr_download/idr_download_by_ids.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<tool id="idr_download_by_ids" name="IDR Download" version="0.42" profile="18.09">
<tool id="idr_download_by_ids" name="IDR Download" version="0.43" profile="18.09">
<description>- download images from the Image Data Resource using image IDs</description>
<macros>
<xml name="region_spec" token_pos="upper-left corner">
Expand All @@ -16,10 +16,21 @@
</xml>
</macros>
<requirements>
<requirement type="package" version="5.6.0">python-omero</requirement>
<requirement type="package" version="5.7.1">python-omero</requirement>
<requirement type="package" version="0.4.2">pylibtiff</requirement>
</requirements>
<command detect_errors="exit_code"><![CDATA[
#if $omero_instance_type.omero_instance == "priv":
#set $username = $__user__.extra_preferences.get('omero_account|username', "")
#set $password = $__user__.extra_preferences.get('omero_account|password', "")
#if $username == "" or $password =="":
echo "OMERO connection credentials are empty. Set your credentials via: User -> Preferences -> Manage Information" &&
exit 1
#end if
#end if
mkdir downloads && cd downloads &&
#if str($image_ids.source) == 'link':
python -c 'print("${image_ids.id_spec}".replace(",", "|").split("?show=")[-1].replace("|", "\n"))'
Expand All @@ -39,10 +50,35 @@
#end if
$skip_failed
$download_tar
#if $omero_instance_type.omero_instance =='priv':
-h '$omero_host'
$omero_secured
-u '$username'
-p '$password'
#end if
2> >(tee -a $out_log >&2)
]]></command>
<inputs>
<conditional name="omero_instance_type">
<param name="omero_instance" type="select" label="Which OMERO instance to connect?"
help="By default, the tool will download a tarball containing individual images from IDR into your Galaxy history. If you
need to connect to your own instance, set your connection username and password from User->Preference->Manage Information" >
<option value="idr">IDR</option>
<option value="priv">other OMERO instance</option>
</param>
<when value="priv">
<param name="omero_host" type="text" label="OMERO host URL">
<validator type="regex" message="Enter a valid host location, for example, your.omero.server">
[.A-Za-z0-9_-]
</validator>
</param>
<param name="omero_secured" type="boolean" label="Seured connection?" checked="true" truevalue="--omero-secured" falsevalue=""
help="Select Yes if your OMERO instance is running with SSL, otherwise select No">
</param>
</when>
<when value="idr" />
</conditional>

<conditional name="image_ids">
<param name="source" type="select" label="How would you like to specify the IDs of images to download?">
<option value="link">As text (comma-separated list of IDs or a valid IDR link)</option>
Expand Down Expand Up @@ -104,26 +140,32 @@
</outputs>
<tests>
<test>
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<param name="source" value="dataset" />
<param name="id_spec" value="ids.txt" />
<param name="channel" value="615.0" />
<param name="channel" value="PCNT" />
<conditional name="clip_image">
<param name="select" value="--rectangle" />
<param name="x_coord" value="3" />
<param name="y_coord" value="3" />
<param name="width" value="5" />
<param name="height" value="5" />
</conditional>
<param name="frame" value="2" />
<param name="frame" value="0" />
<param name="download_tar" value="false" />
<output_collection name="output_file" type="list">
<element name="Centrin_PCNT_Cep215_20110506_Fri-1545_0_SIR_PRJ__1884807__3__3__5__5" file="test1.tiff"/>
<element name="Centrin_PCNT_Cep215_20110506_Fri-1545_0_SIR_PRJ__1884807__3__3__5__5" file="test0.tiff"/>
</output_collection>
</test>
<test>
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<param name="source" value="link" />
<param name="id_spec" value="1884807" />
<param name="channel" value="615.0" />
<param name="channel" value="PCNT" />
<conditional name="clip_image">
<param name="select" value="--rectangle" />
<param name="x_coord" value="3" />
Expand All @@ -138,9 +180,12 @@
</output_collection>
</test>
<test>
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<param name="source" value="link" />
<param name="id_spec" value="1884807" />
<param name="channel" value="615.0" />
<param name="channel" value="PCNT" />
<conditional name="clip_image">
<param name="select" value="--center" />
<param name="x_coord" value="5" />
Expand All @@ -155,6 +200,9 @@
</output_collection>
</test>
<test>
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<param name="source" value="link" />
<param name="id_spec" value="https://idr.openmicroscopy.org/webclient/?show=image-9036708|image-9036710|image-9036711" />
<param name="channel" value="Spo20(51-91)" />
Expand All @@ -179,6 +227,9 @@
</output>
</test>
<test expect_failure="true">
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<!-- Test behavior with non-existing image-ID 9036708999 -->
<param name="source" value="link" />
<param name="id_spec" value="https://idr.openmicroscopy.org/webclient/?show=image-9036708999|image-9036710|image-9036711" />
Expand All @@ -193,6 +244,9 @@
<test>
<!-- Repeat test with non-existing image-ID 9036708999,
but use skip-failed option -->
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<param name="source" value="link" />
<param name="id_spec" value="https://idr.openmicroscopy.org/webclient/?show=image-9036708999|image-9036710|image-9036711" />
<param name="channel" value="Spo20(51-91)" />
Expand All @@ -219,6 +273,9 @@
</output>
</test>
<test>
<conditional name="omero_instance_type">
<param name="omero_instance" value="idr" />
</conditional>
<!-- Test for download images in a tarball -->
<param name="source" value="dataset" />
<param name="id_spec" value="ids_tar.txt" />
Expand Down
Binary file added tools/idr_download/test-data/test0.tiff
Binary file not shown.

0 comments on commit 6b9df5f

Please sign in to comment.