annotate primsfilters.py @ 24:2ab40f9266e4 draft

An update to the core of galaxy prevents the way the code is trying to write files. This patch fixes this.
author linda-bakker
date Tue, 20 Feb 2018 07:59:47 -0500
parents dffc38727496
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
1 import logging
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
2 log = logging.getLogger( __name__ )
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
3
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
4
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
5 def restrict_prims_metabolomics( context, tool ):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
6 """
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
7 This tool filter will hide prims_metabolomics tools for non-metabolomics users.
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
8 This can be enabled by adding the following to the
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
9 ``app:main`` section of ``universe_wsgi.ini``::
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
10
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
11 tool_filters = primsfilters:restrict_prims_metabolomics
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
12
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
13 and by adding this file to the folder:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
14
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
15 <galaxy-dist>/lib/galaxy/tools/filters
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
16
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
17 This is optional and can be used in case some control is desired on whom
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
18 gets to see the prims_metabolomics tools. When not using this file and the
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
19 settings mentioned above, all prims_metabolomics tools will be visible to
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
20 all users.
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
21 """
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
22 # for debugging: import pydevd;pydevd.settrace("L0136815.wurnet.nl")
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
23 user = context.trans.user
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
24 metabolomics_tools = [ "msclust2", "combine_output", "create_poly_model", "lookup_library",
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
25 "NDIStext2tabular", "rankfilterGCMS_tabular", "filter_on_rank",
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
26 "export_to_metexp_tabular", "query_metexp" ]
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
27 found_match = False
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
28 # iterate over the tool (partial)ids and look for a match (this is compatible with tool shed given ids):
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
29 for partial_id in metabolomics_tools:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
30 if tool.id.find("/"+ partial_id + "/") >= 0:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
31 found_match = True
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
32 break
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
33 # the second part of this if is compatible with the ids when NOT using tool shed:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
34 if found_match or tool.id in metabolomics_tools:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
35 # logging.warn( 'FILTER MATCHED: %s' %(tool.name))
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
36
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
37 for user_role in user.roles:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
38 if user_role.role.name == "PRIMS_METABOLOMICS":
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
39 return True
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
40 # not found to have the role, return false:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
41 return False
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
42 else:
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
43 # return true for any other tool
dffc38727496 initial commit
pieter.lukasse@wur.nl
parents:
diff changeset
44 return True