本文整理汇总了Python中omero.gateway.BlitzGateway.setGroupForSession方法的典型用法代码示例。如果您正苦于以下问题:Python BlitzGateway.setGroupForSession方法的具体用法?Python BlitzGateway.setGroupForSession怎么用?Python BlitzGateway.setGroupForSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类omero.gateway.BlitzGateway
的用法示例。
在下文中一共展示了BlitzGateway.setGroupForSession方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Omg
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import setGroupForSession [as 别名]
class Omg(object):
"""
OMERO gateway that wraps Blitz gateway and CLI, intended for
scripting and interactive work.
Attributes
----------
conn : Blitz gateway connection
"""
def __init__(self, conn=None, user=None, passwd=None,
server=SERVER, port=PORT, skey=None):
"""
Requires active Blitz connection OR username plus password or sesskey
"""
if conn is None and (user is None or (passwd is None and skey is None)):
raise ValueError("Bad parameters," + self.__init__.__doc__)
if conn is not None:
if conn.isConnected():
self.conn = conn
else:
raise ValueError("Cannot initialize with closed connection!")
else:
if passwd is not None:
self.conn = BlitzGateway(user, passwd, host=server, port=port)
self.conn.connect()
else:
self.conn = BlitzGateway(user, host=server, port=port)
self.conn.connect(skey)
if self.conn.isConnected():
self._server = self.conn.host
self._port = self.conn.port
self._user = self.conn.getUser().getName()
self._key = self.conn.getSession().getUuid().getValue()
print("Connected to {0} (port {1}) as {2}, session key={3}".format(
self._server, self._port, self._user, self._key))
else:
print("Failed to open connection :-(")
def ls(self):
"""
Print groups, then projects/datasets/images for current group.
"""
print("Groups for {0}:-".format(self.conn.getUser().getName()))
for gid, gname in self._ls_groups():
print(" {0} ({1})".format(gname, str(gid)))
curr_grp = self.conn.getGroupFromContext()
gid, gname = curr_grp.getId(), curr_grp.getName()
print("\nData for current group, {0} ({1}):-".format(gname, gid))
for pid, pname in self._ls_projects():
print(" Project: {0} ({1})".format(pname, str(pid)))
for did, dname in self._ls_datasets(pid):
print(" Dataset: {0} ({1})".format(dname, str(did)))
for iid, iname in self._ls_images(did):
print(" Image: {0} ({1})".format(iname, str(iid)))
# TODO, list orphaned Datasets and Images
def _ls_groups(self):
"""list groups (id, name) this session is a member of"""
groups = self.conn.getGroupsMemberOf()
return [(group.getId(), group.getName()) for group in groups]
def _ls_projects(self):
"""list projects (id, name) in the current session group"""
projs = self.conn.listProjects(self.conn.getUserId())
return [(proj.getId(), proj.getName()) for proj in projs]
def _ls_datasets(self, proj_id):
"""list datasets (id, name) within the project id given"""
dsets = self.conn.getObject("Project", proj_id).listChildren()
return [(dset.getId(), dset.getName()) for dset in dsets]
def _ls_images(self, dset_id):
"""list images (id, name) within the dataset id given"""
imgs = self.conn.getObject("Dataset", dset_id).listChildren()
return [(img.getId(), img.getName()) for img in imgs]
def chgrp(self, group_id):
"""
Change group for this session to the group_id given.
"""
self.conn.setGroupForSession(group_id)
def get(self, im_id, get_att=True):
"""
Download the specified image as an OME-TIFF to current directory,
with attachments also downloaded to folder: img_path + '_attachments'
Return : path to downloaded image
"""
img = self.conn.getObject("Image", oid=im_id)
img_name = self._unique_name(img.getName(), im_id)
img_path = os.path.join(os.getcwd(), img_name)
img_file = open(str(img_path + ".ome.tiff"), "wb")
fsize, blockgen = img.exportOmeTiff(bufsize=65536)
for block in blockgen:
img_file.write(block)
img_file.close()
fa_type = omero.model.FileAnnotationI
attachments = [ann for ann in img.listAnnotations()
#.........这里部分代码省略.........
示例2: BlitzGateway
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import setGroupForSession [as 别名]
conn = BlitzGateway(username, password, host=HOST, port=PORT)
connected = conn.connect()
if not connected:
print >> sys.stderr, ("Error: Connection not available, please check your " "username and password.")
sys.exit(1)
else:
print "Login successful.\n"
# Set our default group so we can see the data.
# (I thought I had to do this, but now I am not sure it's needed.
# -JLM 2013/12/04)
try:
group = next(g for g in conn.listGroups() if g.getName() == GROUP)
except StopIteration:
print >> sys.stderr, "Error: could not find group '%s'" % GROUP
conn.setGroupForSession(group.getId())
# Get plate of interest.
# (ID 1552 is "RTK ligands induce differing FOXO3a translocation dynamics")
plate = conn.getObject("Plate", 1552)
# Get list of lists of well objects from the plate.
well_grid = plate.getWellGrid()
# Loop over all wells in the plate.
for (raw_row_num, row) in enumerate(well_grid):
for (raw_col_num, well) in enumerate(row):
# Fix up row and column numbers to match Pat's nomenclature.
row_num = raw_row_num + 1
col_num = raw_col_num + 2
# Construct paths and create output directory. (I dislike this naming
# format but it's what Pat has chosen. -JLM)
示例3: BlitzGateway
# 需要导入模块: from omero.gateway import BlitzGateway [as 别名]
# 或者: from omero.gateway.BlitzGateway import setGroupForSession [as 别名]
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Suggests OMERO.cli commands to fix the idr0004 field-image mapping.
# author: [email protected]
from omero.gateway import BlitzGateway
from omero.rtypes import wrap
from omero.sys import ParametersI
import os
conn = BlitzGateway(
os.environ.get('IDR_USER', 'root'),
os.environ.get('IDR_PASSWORD', 'omero'),
host=os.environ.get('IDR_HOST', 'localhost'))
conn.connect()
conn.setGroupForSession(3) # Public
query_service = conn.getQueryService()
# Find the plates of idr0004.
query = """
SELECT child.id
FROM ScreenPlateLink
WHERE parent.name LIKE :name
"""
params = ParametersI()
params.add('name', wrap('idr0004-%'))
rows = query_service.projection(query, params)