Skip to content

Instantly share code, notes, and snippets.

@chris-allan
Created June 5, 2018 11:07
Show Gist options
  • Save chris-allan/b361fdff74b49362acbef800f1fb4417 to your computer and use it in GitHub Desktop.
Save chris-allan/b361fdff74b49362acbef800f1fb4417 to your computer and use it in GitHub Desktop.
Print out OMERO binary repository paths for Plate data
#!/bin/bash
# Prints out OMERO binary repository paths for data associated with a Plate
#
# Copyright (C) 2018 Glencoe Software, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
#set -x
# Constants to be changed for your environment; ".pgpass" file is recommended:
# * https://www.postgresql.org/docs/8.4/static/libpq-pgpass.html
DB_HOST="localhost"
DB_USER="omero"
DB_NAME="omero"
# The root of your OMERO binary repository:
# * https://docs.openmicroscopy.org/omero/4.4.10/sysadmins/unix/server-binary-repository.html
DATA_DIR="/OMERO"
if [ "$1" = "" ]; then
echo "Usage: $0 <plate_id>"
exit
fi
# Check that OMERO Python module is on the PYTHONPATH
python -m omero.clients
psql -P 'pager=off' -A -t -f ',' -h "$DB_HOST" -U "$DB_USER" "$DB_NAME" -c "
SELECT pixels.id FROM pixels
JOIN image ON pixels.image = image.id
JOIN wellsample ON image.id = wellsample.image
JOIN well ON wellsample.well = well.id
JOIN plate ON well.plate = plate.id
WHERE plate.id = $1
" | python -c "
import omero.clients
import sys
import os
for pixels_id in sys.stdin.readlines():
print os.path.join(
'$DATA_DIR', 'Pixels', omero.util.long_to_path(int(pixels_id))
)
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment