Skip to content

Commit

Permalink
Merge pull request #16 from josenavas/adding-analysis-only-param
Browse files Browse the repository at this point in the history
Adding analysis only param
  • Loading branch information
antgonza authored May 23, 2017
2 parents 43fbdf4 + 5f536a6 commit 53a7b6a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ install:
pyzmq networkx pyparsing natsort mock future libgfortran
'pandas>=0.18' 'scipy>0.13.0' 'numpy>=1.7' 'h5py>=2.3.1'
- source activate qiita_env
- pip install sphinx sphinx-bootstrap-theme coveralls ipython[all]==2.4.1
- pip install https://github.com/biocore/qiita/archive/master.zip --process-dependency-links
- pip install sphinx==1.5.5 sphinx-bootstrap-theme coveralls ipython[all]==2.4.1
- pip install https://github.com/biocore/qiita/archive/analysis-refactor.zip --process-dependency-links
- export QIITA_SERVER_CERT=$HOME/miniconda3/envs/qiita_env/lib/python2.7/site-packages/qiita_core/support_files/server.crt
- export MOI_CONFIG_FP=$HOME/miniconda3/envs/qiita_env/lib/python2.7/site-packages/qiita_core/support_files/config_test.cfg
- ipython profile create qiita-general --parallel
- qiita-env start_cluster qiita-general
- qiita-env make --no-load-ontologies
- export QIITA_SERVER_CERT=$HOME/miniconda3/envs/qiita_env/lib/python2.7/site-packages/qiita_core/support_files/server.crt
- source deactivate
- travis_retry conda create --yes -n env_name python=$PYTHON_VERSION pip nose flake8 coverage
- source activate env_name
- travis_retry pip install .
before_script:
- source activate qiita_env
- export MOI_CONFIG_FP=$HOME/miniconda3/envs/qiita_env/lib/python2.7/site-packages/qiita_core/support_files/config_test.cfg
- qiita pet webserver start &
script:
- source activate env_name
Expand Down
10 changes: 8 additions & 2 deletions qiita_client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class QiitaCommand(object):
The default parameter sets of the command, keyed by parameter set name.
The values should be a dictionary in which keys are the parameter names
and values are the specific value for each parameter
analysis_only : bool, optional
If true, the command will only be available on the analysis pipeline.
Default: False
Raises
------
Expand All @@ -66,7 +69,8 @@ class QiitaCommand(object):
If `function` does not accept 4 parameters
"""
def __init__(self, name, description, function, required_parameters,
optional_parameters, outputs, default_parameter_sets=None):
optional_parameters, outputs, default_parameter_sets=None,
analysis_only=False):
self.name = name
self.description = description

Expand All @@ -90,6 +94,7 @@ def __init__(self, name, description, function, required_parameters,
self.optional_parameters = optional_parameters
self.default_parameter_sets = default_parameter_sets
self.outputs = outputs
self.analysis_only = analysis_only

def __call__(self, qclient, server_url, job_id, output_dir):
return self.function(qclient, server_url, job_id, output_dir)
Expand Down Expand Up @@ -196,7 +201,8 @@ def _register(self, qclient):
'optional_parameters': dumps(cmd.optional_parameters),
'default_parameter_sets': dumps(
cmd.default_parameter_sets),
'outputs': dumps(cmd.outputs)}
'outputs': dumps(cmd.outputs),
'analysis_only': cmd.analysis_only}
qclient.post('/qiita_db/plugins/%s/%s/commands/'
% (self.name, self.version), data=data)

Expand Down
27 changes: 27 additions & 0 deletions qiita_client/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from unittest import TestCase
from os import environ
from time import sleep

from qiita_client import QiitaClient

Expand All @@ -28,3 +29,29 @@ def setUpClass(cls):
def tearDownClass(cls):
# Reset the test database
cls.qclient.post("/apitest/reset/")

def _wait_for_running_job(self, job_id):
"""Waits until the given job is not in a running status
Parameters
----------
job_id : str
The job it to wait for
Returns
-------
str
The status of the job
Notes
-----
This function only polls for five seconds. After those five seconds,
it returns whatever the last seen status for the given job
"""
for i in range(10):
sleep(0.5)
status = self.qclient.get_job_info(job_id)['status']
if status != 'running':
break

return status
30 changes: 27 additions & 3 deletions qiita_client/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def func(a, b, c, d):
self.assertEqual(obs.optional_parameters, self.exp_opt)
self.assertEqual(obs.outputs, self.exp_out)
self.assertEqual(obs.default_parameter_sets, self.exp_dflt)
self.assertFalse(obs.analysis_only)

obs = QiitaCommand("Test cmd analysis", "Some description", func,
self.exp_req, self.exp_opt, self.exp_out,
self.exp_dflt, analysis_only=True)
self.assertEqual(obs.name, "Test cmd analysis")
self.assertEqual(obs.description, "Some description")
self.assertEqual(obs.function, func)
self.assertEqual(obs.required_parameters, self.exp_req)
self.assertEqual(obs.optional_parameters, self.exp_opt)
self.assertEqual(obs.outputs, self.exp_out)
self.assertEqual(obs.default_parameter_sets, self.exp_dflt)
self.assertTrue(obs.analysis_only)

with self.assertRaises(TypeError):
QiitaCommand("Name", "Desc", "func", self.exp_req, self.exp_opt,
Expand Down Expand Up @@ -193,6 +206,12 @@ def func(qclient, job_id, job_params, working_dir):
{'out1': 'Demultiplexed'})
tester.register_command(cmd)

a_cmd = QiitaCommand("NewCmdAnalysis", "Desc", func,
{'p1': ('artifact', ['FASTQ'])},
{'p2': ('string', 'dflt')},
{'out1': 'Demultiplexed'})
tester.register_command(a_cmd)

tester.generate_config('env_script', 'start_script',
server_cert=self.server_cert)
self.qclient.post('/apitest/reload_plugins/')
Expand All @@ -201,7 +220,10 @@ def func(qclient, job_id, job_params, working_dir):
obs = self.qclient.get('/qiita_db/plugins/NewPlugin/0.0.1/')
self.assertEqual(obs['name'], 'NewPlugin')
self.assertEqual(obs['version'], '0.0.1')
self.assertEqual(obs['commands'], ['NewCmd'])
# I can't use assertItemsEqual because it is not available in py3
# and I can't user assertCountEqual because it is not avaialable in py2
self.assertEqual(sorted(obs['commands']),
sorted(['NewCmd', 'NewCmdAnalysis']))

# Create a new job
data = {'command': dumps(['NewPlugin', '0.0.1', 'NewCmd']),
Expand All @@ -210,8 +232,10 @@ def func(qclient, job_id, job_params, working_dir):
job_id = self.qclient.post('/apitest/processing_job/',
data=data)['job']
tester("https://localhost:21174", job_id, self.outdir)
obs = self.qclient.get_job_info(job_id)
self.assertEqual(obs['status'], 'success')

status = self._wait_for_running_job(job_id)
self.assertEqual(status, 'success')


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion qiita_client/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def test_get(self):
'visibility': 'private',
'ebi_run_accessions': None,
'type': 'FASTQ',
'name': 'Raw data 1'}
'name': 'Raw data 1',
'analysis': None}

# Files contain the full path, which it is hard to test, so get only
# the basename of the files
Expand Down

0 comments on commit 53a7b6a

Please sign in to comment.