Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak job commands #108

Merged
merged 2 commits into from
Jun 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions qiita_db/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def exists(cls, datatype, command, options):
datatype : str
Datatype the job is operating on
command : str
The command run on the data
The name of the command run on the data
options : dict
Options for the command in the format {option: value}

Expand All @@ -67,12 +67,13 @@ def exists(cls, datatype, command, options):
bool
Whether the job exists or not
"""
sql = ("SELECT EXISTS(SELECT * FROM qiita.{0} WHERE data_type_id = %s"
" AND command_id = %s AND options = %s)".format(cls._table))
conn_handler = SQLConnectionHandler()
datatype_id = convert_to_id(datatype, "data_type", conn_handler)
command_id = convert_to_id(command, "command", conn_handler)
sql = "SELECT command_id FROM qiita.command WHERE name = %s"
command_id = conn_handler.execute_fetchone(sql, (command, ))[0]
opts_json = dumps(options, sort_keys=True, separators=(',', ':'))
sql = ("SELECT EXISTS(SELECT * FROM qiita.{0} WHERE data_type_id = %s"
" AND command_id = %s AND options = %s)".format(cls._table))
return conn_handler.execute_fetchone(
sql, (datatype_id, command_id, opts_json))[0]

Expand Down Expand Up @@ -104,7 +105,8 @@ def create(cls, datatype, command, options, analysis):
# Get the datatype and command ids from the strings
conn_handler = SQLConnectionHandler()
datatype_id = convert_to_id(datatype, "data_type", conn_handler)
command_id = convert_to_id(command, "command", conn_handler)
sql = "SELECT command_id FROM qiita.command WHERE name = %s"
command_id = conn_handler.execute_fetchone(sql, (command, ))[0]

# JSON the options dictionary
opts_json = dumps(options, sort_keys=True, separators=(',', ':'))
Expand Down Expand Up @@ -139,18 +141,18 @@ def datatype(self):

@property
def command(self):
"""Returns the command of the job
"""Returns the command of the job as (name, command)

Returns
-------
str
command run by the job
"""
sql = ("SELECT command from qiita.command WHERE command_id = "
sql = ("SELECT name, command from qiita.command WHERE command_id = "
"(SELECT command_id from qiita.{0} WHERE "
"job_id = %s)".format(self._table))
conn_handler = SQLConnectionHandler()
return conn_handler.execute_fetchone(sql, (self._id, ))[0]
return conn_handler.execute_fetchone(sql, (self._id, ))

@property
def options(self):
Expand Down
2 changes: 1 addition & 1 deletion qiita_db/support_files/initialize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ INSERT INTO qiita.filepath_type (filepath_type) VALUES ('raw_sequences'), ('raw_
INSERT INTO qiita.checksum_algorithm (name) VALUES ('crc32');

-- Populate commands available
INSERT INTO qiita.command (name, command) VALUES ('Summarize taxa through plots', 'summarize_taxa_through_plots.py'), ('Beta diversity through plots', 'beta_diversity_through_plots.py');
INSERT INTO qiita.command (name, command) VALUES ('Summarize Taxa', 'summarize_taxa_through_plots.py'), ('Beta Diversity', 'beta_diversity_through_plots.py'), ('Alpha Diversity', 'alpha_diversity_through_plots.py');
13 changes: 7 additions & 6 deletions qiita_db/test/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ def tearDown(self):

def test_exists(self):
"""tests that existing job returns true"""
self.assertTrue(Job.exists("16S", "summarize_taxa_through_plots.py",
self.assertTrue(Job.exists("16S", "Summarize Taxa",
{'option1': True, 'option2': 12,
'option3': 'FCM'}))

def test_exists_not_there(self):
"""tests that non-existant job returns false"""
self.assertFalse(Job.exists("Metabolomic",
"summarize_taxa_through_plots.py",
"Summarize Taxa",
{'option1': "Nope", 'option2': 10,
'option3': 'FCM'}))

def test_create(self):
"""Makes sure creation works as expected"""
new = Job.create("18S", "beta_diversity_through_plots.py",
new = Job.create("18S", "Beta Diversity",
self.options, Analysis(1))
self.assertEqual(new.id, 3)
# make sure job inserted correctly
Expand All @@ -71,7 +71,7 @@ def test_create(self):
def test_create_exists(self):
"""Makes sure creation doesn't duplicate a job"""
with self.assertRaises(QiitaDBDuplicateError):
Job.create("16S", "summarize_taxa_through_plots.py",
Job.create("16S", "Summarize Taxa",
{'option1': True, 'option2': 12, 'option3': 'FCM'},
Analysis(1))

Expand All @@ -81,7 +81,8 @@ def test_retrieve_datatype(self):

def test_retrieve_command(self):
"""Makes sure command retriveal is correct"""
self.assertEqual(self.job.command, 'summarize_taxa_through_plots.py')
self.assertEqual(self.job.command, ['Summarize Taxa',
'summarize_taxa_through_plots.py'])

def test_retrieve_options(self):
self.assertEqual(self.job.options, {'option1': True, 'option2': 12,
Expand All @@ -97,7 +98,7 @@ def test_retrieve_results(self):
self.assertTrue(exists(join(get_work_base_dir(), "job1result.txt")))

def test_retrieve_results_blank(self):
new = Job.create("18S", "beta_diversity_through_plots.py",
new = Job.create("18S", "Beta Diversity",
self.options, Analysis(1))
obs = new.results
self._delete_path = obs
Expand Down