Omero-pychrm

From Colettapedia
Jump to: navigation, search

General

BlitzGateway

  • blitz_gateway - python bindings and wrappers to access an OMERO blitz server
  • script location in $OMERO_HOME/lib/python/omero/gateway/

__init__.py

  • where all the magic happens
  • BlitzGateway = _BlitzGateway

OmeroPychrm scripts

__init__.py

  • empty

TableConnection.py

class PychrmStorageError(Exception):
  pass

class Connection(object):
  def __init__(self, user = None, passwd = None, host = None, client = None):
    """A wrapper for omero.client."""
    self.log = logging.getLogger(__name__)
    self.conn = BlitzGateway(client_obj = client)
    self.res = omero.client.getSession().sharedResources()
  def __enter__(self):
    return self.log.debug('Entering Connection')
  def __exit__(self):
    self.log.debug('Exiting Connection')
    self.conn._closeSession()

class TableConnection(Connection):
  """A basic client-side wrapper for OMERO.tables which handles opening and closing tables."""
  def __init__(self, user = None, passwd = None, host = None, client = None, tableName = None):
    """Create a new table handler, either by specifying user and passwd or by providing a client object (for scripts)."""
    # call base class constructor
    self.rid = self.res.repositories().descriptions[0].id.val
    self.tableName = tableName
    self.tableId = None
    self.table = None
  def close(self, parent=True):
    """standard cleanup stuff"""
    pass
  def openTable(self, tableId):
    """Opens an existing table by ID"""
    ofile = self.conn.getObject("OriginalFile", attributes = {'id': long(tableId)})
    if not ofile:
      raise TableConnectionError('No table found with id:%s' % tableId)
  def findByName(self):
    """Searches for OriginalFile objects by name, does not check whether file is a table"""
    return self.conn.getObjects("OriginalFile", attributes = {'name': self.tableName} )
  def deleteAllTables(self):
    """Delete all tables with tableName. Will fail if there are any annotation links."""
    ofiles = self.conn.getObjects("OriginalFile", attributes = {'name': self.tableName})
    ids = [f.getId() for f in ofiles]
    elf.conn.deleteObjects('OriginalFile', ids)

PychrmStorage.py

class PychrmStorageError(Exception):
  pass

def parseFeatureName( name ):
  """Separate bin number and feature group name"""
  pass

def createFeatureName(ft, idx):
  """Concatenate feature group name and feature bin number"""
  pass

def featureSizes(names):
  """Return a dictionary of feature groups and corresponding numbers of features in them"""
  pass

Serverside UI scripts

Pychrm_build_clasifier.py

def runScript():
  client = omero.scripts.client(
    name="Pychrm_build_clasifier.py",
    description="blahblah",
    # Plus some JobParams )

    try:
      session = client.getSession()
      client.enableKeepAlive(60)
      scriptParams = {}

      # Pull the input from the UI
      for key in client.getInputKeys():
        if client.getInput(key):
          scriptParams[key] = client.getInput(key, unwrap=True)
      message = str(scriptParams) + '\n'

      # Run the script
      message += trainClassifier(client, scriptParams) + '\n'
    
      print message
      client.setOutput('Message', rstring(message))
    finally:
      client.closeSession()

def trainClassifier(client, scriptParams):

def createWeights(ftb, ctb, project, featureThreshold, imagesOnly):

def reduceFeatures(fts, weights):

Native OMERO python scripts

omero.scripts.client()