Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fitzpatrick committed Jan 5, 2015
1 parent 512f467 commit b915437
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 78 deletions.
26 changes: 26 additions & 0 deletions pathomx/Pathomx.py
Expand Up @@ -53,6 +53,7 @@

# Translation (@default context)
from .translate import tr
from .runqueue import ExecuteOnly

from distutils.version import StrictVersion

Expand Down Expand Up @@ -1170,6 +1171,7 @@ def main():
locale = QLocale.system().name()
#locale = 'nl'


# Load base QT translations from the normal place (does not include _nl, or _it)
translator_qt = QTranslator()
if translator_qt.load("qt_%s" % locale, QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
Expand All @@ -1191,6 +1193,30 @@ def main():
notebook_queue.create_user_kernel()
notebook_queue.create_runners()
notebook_queue.start_timers()
'''
exc = ExecuteOnly("""
import pip
for pkg in [
'numpy',ls
'scipy',
'pandas',
'matplotlib',
'requests',
'nmrglue',
'gpml2svg',
'icoshift',
'mplstyler',
'pyqtconfig',
"pygments",
'pydot',
'jinja2']:
pip.main(['install', pkg, '--upgrade'])
""")
notebook_queue.add_job(exc, {})
'''


MainWindow()
logging.info('Ready.')
Expand Down
76 changes: 41 additions & 35 deletions pathomx/kernel_helpers.py
Expand Up @@ -48,48 +48,54 @@ def pathomx_notebook_start(varsi, vars):
for k, v in varsi.items():
vars[k] = v

# _keep_input_vars = ['styles']
# vars['_pathomx_exclude_input_vars'] = [x for x in varsi.keys() if x not in _keep_input_vars]

# Handle IO magic
for k, v in vars['_io']['input'].items():
if v in vars:
vars[k] = deepcopy(vars[v])
else:
vars[k] = None
if '_io' in vars:
for k, v in vars['_io']['input'].items():
if v in vars:
vars[k] = deepcopy(vars[v])
else:
vars[k] = None

global rcParams
from matplotlib import rcParams
if 'rcParams' in vars:
global rcParams
from matplotlib import rcParams

# Block warnings from deprecated rcParams here
with warnings.catch_warnings():
warnings.simplefilter("ignore")
for k, v in vars['rcParams'].items():
rcParams[k] = v
# Block warnings from deprecated rcParams here
with warnings.catch_warnings():
warnings.simplefilter("ignore")
for k, v in vars['rcParams'].items():
rcParams[k] = v


def pathomx_notebook_stop(vars):
# Handle IO magic
for k, v in vars['_io']['output'].items():
if k in vars:
vars[v] = vars[k]
else:
vars[v] = None

varso = {}
for k, v in vars.items():
# Check it's an accepted type for passing; and not private (starts with _)
if not k.startswith('_') and \
not k in vars['_io']['input'].keys():

if type(v) in MAGIC_TYPES or k in vars['_pathomx_expected_output_vars']:
varso[k] = v

elif hasattr(v, '_repr_html_'):
try:
# Check if it is a bound method (not a class definition)
v._repr_html_()
except:
pass
else:
varso[k] = displayobjects.Html(v)
if '_id' in vars:
# Handle IO magic
for k, v in vars['_io']['output'].items():
if k in vars:
vars[v] = vars[k]
else:
vars[v] = None

for k, v in vars.items():
# Check it's an accepted type for passing; and not private (starts with _)
if not k.startswith('_') and \
not k in vars['_io']['input'].keys():

if type(v) in MAGIC_TYPES or k in vars['_pathomx_expected_output_vars']:
varso[k] = v

elif hasattr(v, '_repr_html_'):
try:
# Check if it is a bound method (not a class definition)
v._repr_html_()
except:
pass
else:
varso[k] = displayobjects.Html(v)

vars['varso'] = varso

Expand Down
18 changes: 18 additions & 0 deletions pathomx/plugins.py
Expand Up @@ -23,6 +23,8 @@
from .globals import settings, app_launchers, file_handlers, url_handlers, available_tools_by_category, \
plugin_categories, plugin_manager, plugin_objects, plugin_metadata, installed_plugin_names

import pip

# Translation (@default context)
from .translate import tr

Expand Down Expand Up @@ -64,6 +66,10 @@ def get_available_plugins(plugin_places=None, include_deactivated=False):

available_tools_by_category = defaultdict(list)

# A list of the packages required for all found plugins (when to install?; via pip)
# pip is available since 2.7.9 via ensurepip (and/or we can package)
required_packages_all = set()

# Loop round the plugins and print their names.
for plugin in plugin_manager.getAllPlugins():
plugin_image = os.path.join(os.path.dirname(plugin.path), 'icon.png')
Expand All @@ -76,6 +82,11 @@ def get_available_plugins(plugin_places=None, include_deactivated=False):
except:
resource_list = []

try:
required_packages = plugin.details.get('Documentation','Packages').split(',')
except:
required_packages = []

metadata = {
'id': type(plugin.plugin_object).__name__, # __module__,
'image': plugin_image,
Expand All @@ -89,13 +100,20 @@ def get_available_plugins(plugin_places=None, include_deactivated=False):
'path': os.path.dirname(plugin.path),
'module': os.path.basename(plugin.path),
'shortname': os.path.basename(os.path.dirname(plugin.path)),
'required_packages': required_packages,
}

required_packages_all |= set(required_packages)

plugin_metadata[metadata['shortname']] = metadata
installed_plugin_names[id(plugin.plugin_object)] = plugin.name

plugin.plugin_object.post_setup(path=os.path.dirname(plugin.path), name=plugin.name, metadata=metadata)

# Check and import all packages
# for pkg_ver in required_packages_all:
# pip.main(['install', pkg_ver, '--upgrade'])


class pluginListDelegate(QAbstractItemDelegate):

Expand Down
4 changes: 3 additions & 1 deletion pathomx/plugins/maxquant/maxquant.md
@@ -1,7 +1,7 @@
MaxQuant
=======

Import protein quantification from the MaxQuant software.
Import labelled protein quantification from the MaxQuant software.
[Martin A. Fitzpatrick][]

Introduction
Expand All @@ -13,5 +13,7 @@ are supported. MaxQuant is freely available and can be downloaded from [the webs
engine Andromeda which is integrated into MaxQuant as well as the Viewer application for inspection of raw data and
identification and quantification results.

This tool is a first implementation of MaxQuant support, and imports labelled data only.

[Martin A. Fitzpatrick]: http://martinfitzpatrick.name/
[MaxQuant]: http://www.maxquant.org/
1 change: 1 addition & 0 deletions pathomx/plugins/maxquant/maxquant.py
Expand Up @@ -45,6 +45,7 @@

output_data = df
df = None
ds = None

from pathomx.figures import histogram
Histogram = histogram(output_data)
1 change: 1 addition & 0 deletions pathomx/plugins/multivariate/.pathomx-plugin
Expand Up @@ -7,3 +7,4 @@ Author = Martin Fitzpatrick
Version = 1.0
Website = http://martinfitzpatrick.name/
Description = Multivariate analysis plugins
Packages = scikit-learn>=0.15, pandas>=0.15, numpy>=1.9
2 changes: 1 addition & 1 deletion pathomx/plugins/volcano/volcano.py
@@ -1,4 +1,4 @@
iimport pandas as pd
import pandas as pd
import scipy as sp
import scipy.stats
import numpy as np
Expand Down
78 changes: 44 additions & 34 deletions pathomx/runqueue.py
Expand Up @@ -104,7 +104,7 @@ def run(self, tool, varsi, progress_callback=None, result_callback=None):
setup_languages(self.e.execute, tool.language)

self.ar = self.e.execute(code)
self.e.execute(r'''pathomx_notebook_stop(vars());''') # This will queue directly above the main code block
self.e.execute(r'''pathomx_notebook_stop(vars());''') # This will queue directly after the main code block

def check_status(self):
result = {}
Expand All @@ -121,7 +121,9 @@ def check_status(self):
result['status'] = -1
result['traceback'] = '\n'.join(e.render_traceback())
result['stdout'] = self.stdout
self._result_callback(result)
if self._result_callback:
self._result_callback(result)

self.ar = None
self._is_active = False # Release this kernel
self._status = STATUS_ERROR
Expand All @@ -141,7 +143,9 @@ def check_status(self):
result['traceback'] = '\n'.join(e.render_traceback())
result['stdout'] = self.stdout
result['varso'] = []
self._result_callback(result)
if self._result_callback:
self._result_callback(result)

self.aro = None
self._is_active = False # Release this kernel
self._status = STATUS_ERROR
Expand All @@ -151,7 +155,9 @@ def check_status(self):
result['status'] = 0
result['varso'] = varso
result['stdout'] = self.stdout
self._result_callback(result)
if self._result_callback:
self._result_callback(result)

self._is_active = False # Release this kernel
self._status = STATUS_READY

Expand Down Expand Up @@ -557,35 +563,37 @@ def run(self):
self.jobs.insert(0, (tool, varsi, progress_callback, result_callback))
return False

varsi['_pathomx_expected_output_vars'] = tool.data.o.keys()
if hasattr(tool, 'data'):
# We can run code without an associated tool (e.g. for central-setup)
varsi['_pathomx_expected_output_vars'] = tool.data.o.keys()

# Build the IO magic
# - if the source did not run on the current runner we'll need to push the data over
io = {'input': {}, 'output': {}, }
for i, sm in tool.data.i.items():
if sm:
mo, mi = sm
io['input'][i] = "_%s_%s" % (mi, id(mo.v))
# Build the IO magic
# - if the source did not run on the current runner we'll need to push the data over
io = {'input': {}, 'output': {}, }
for i, sm in tool.data.i.items():
if sm:
mo, mi = sm
io['input'][i] = "_%s_%s" % (mi, id(mo.v))

# Check if the last run of this occurred on the selected runner
if id(mo.v) in self.run_metadata and \
self.run_metadata[id(mo.v)]['last_runner'] != id(runner):
# Check if the last run of this occurred on the selected runner
if id(mo.v) in self.run_metadata and \
self.run_metadata[id(mo.v)]['last_runner'] != id(runner):

# We need to push the actual data; this should do it?
varsi['_%s_%s' % (mi, id(mo.v))] = tool.data.get(i)
else:
io['input'][i] = None
# We need to push the actual data; this should do it?
varsi['_%s_%s' % (mi, id(mo.v))] = tool.data.get(i)
else:
io['input'][i] = None

for o in tool.data.o.keys():
io['output'][o] = "_%s_%s" % (o, id(tool))
for o in tool.data.o.keys():
io['output'][o] = "_%s_%s" % (o, id(tool))

varsi['_io'] = io
varsi['_io'] = io

self.run_metadata[id(tool)] = {
'last_runner': id(runner)
}
self.run_metadata[id(tool)] = {
'last_runner': id(runner)
}

tool.logger.info("Starting job....")
tool.logger.info("Starting job....")

# Result callback gets the varso dict
runner.run(tool, varsi, progress_callback=progress_callback, result_callback=result_callback)
Expand Down Expand Up @@ -625,7 +633,7 @@ def create_runners(self):

if self.p is None:
# Use the in-process runner for now
self.runners = [self.in_process_runner]
# self.runners = [self.in_process_runner]
self.start_cluster()

elif self.p.poll() is None:
Expand All @@ -640,7 +648,7 @@ def create_runners(self):
for e in self.client:
found = False
for r in self.runners:
if r is not self.in_process_runner and e.targets == r.e.targets:
if e.targets == r.e.targets:
found = True

if not found:
Expand All @@ -649,12 +657,6 @@ def create_runners(self):
runner.e.execute('%matplotlib inline')
self.runners.append(runner)

if len(self.runners) > 1:
# We've got a running cluster
# remove the in-process kernel from the queue
if self.in_process_runner in self.runners:
self.runners.remove(self.in_process_runner)

else:
# We've got a -value for poll; it's terminated this will trigger restart on next poll
self.stop_cluster()
Expand All @@ -665,3 +667,11 @@ def create_user_kernel(self):
self.in_process_runner = InProcessRunner()
self.in_process_runner.kernel_client.execute('%reset -f')
#self.in_process_runner.kernel_client.execute('%matplotlib inline')


class ExecuteOnly(object):
language = 'python'

def __init__(self, code):
self.code = code

0 comments on commit b915437

Please sign in to comment.