diff --git a/qiita_db/job.py b/qiita_db/job.py index fa66d0913..974c0616c 100644 --- a/qiita_db/job.py +++ b/qiita_db/job.py @@ -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} @@ -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] @@ -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=(',', ':')) @@ -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): diff --git a/qiita_db/support_files/initialize.sql b/qiita_db/support_files/initialize.sql index 98ed532ae..3e16ebe37 100644 --- a/qiita_db/support_files/initialize.sql +++ b/qiita_db/support_files/initialize.sql @@ -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'); diff --git a/qiita_db/test/test_job.py b/qiita_db/test/test_job.py index 6cef26815..ea56523ad 100644 --- a/qiita_db/test/test_job.py +++ b/qiita_db/test/test_job.py @@ -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 @@ -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)) @@ -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, @@ -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