Skip to content

Commit 080be0f

Browse files
josenavasantgonza
authored andcommitted
Fix artifact type creation (#2158)
* Changing the HTML setter to add support dirs * Extending the patch operation * Fixing remaining calls to html_summary_fp set * Fixing test * Deleting unused function * Removing unused import * Fixing tests * Fixing failing test * Creating the mountpoint of the new type * Cleaning up patch and fixing bug * Fixing tests * Adding analysis to the list of acceptable parameter types * Adding the provenance parameter automatically
1 parent a7e3d8b commit 080be0f

File tree

7 files changed

+55
-84
lines changed

7 files changed

+55
-84
lines changed

qiita_db/artifact.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from future.utils import viewitems
1111
from itertools import chain
1212
from datetime import datetime
13-
from os import remove
14-
from os.path import isfile
13+
from os import remove, makedirs
14+
from os.path import isfile, exists
1515
from shutil import rmtree
1616
from functools import partial
1717

@@ -152,6 +152,19 @@ def create_type(name, description, can_be_submitted_to_ebi,
152152
[at_id, qdb.util.convert_to_id(fpt, 'filepath_type'), req]
153153
for fpt, req in filepath_types]
154154
qdb.sql_connection.TRN.add(sql, sql_args, many=True)
155+
156+
# When creating a type is expected that a new mountpoint is created
157+
# for that type
158+
sql = """INSERT INTO qiita.data_directory
159+
(data_type, mountpoint, subdirectory, active)
160+
VALUES (%s, %s, %s, %s)"""
161+
qdb.sql_connection.TRN.add(sql, [name, name, True, True])
162+
163+
# We are intersted in the dirpath
164+
dp = qdb.util.get_mountpoint(name)[0][1]
165+
if not exists(dp):
166+
makedirs(dp)
167+
155168
qdb.sql_connection.TRN.execute()
156169

157170
@classmethod

qiita_db/software.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def create(cls, software, name, description, parameters, outputs=None,
272272
ptype, dflt = vals
273273
# Check that the type is one of the supported types
274274
supported_types = ['string', 'integer', 'float', 'reference',
275-
'boolean', 'prep_template']
275+
'boolean', 'prep_template', 'analysis']
276276
if ptype not in supported_types and not ptype.startswith(
277277
('choice', 'mchoice', 'artifact')):
278278
supported_types.extend(['choice', 'mchoice', 'artifact'])
@@ -337,6 +337,7 @@ def create(cls, software, name, description, parameters, outputs=None,
337337
sql_type = """INSERT INTO qiita.parameter_artifact_type
338338
(command_parameter_id, artifact_type_id)
339339
VALUES (%s, %s)"""
340+
supported_types = []
340341
for pname, p_type, atypes in sql_artifact_params:
341342
sql_params = [c_id, pname, p_type, True, None]
342343
qdb.sql_connection.TRN.add(sql, sql_params)
@@ -345,6 +346,30 @@ def create(cls, software, name, description, parameters, outputs=None,
345346
[pid, qdb.util.convert_to_id(at, 'artifact_type')]
346347
for at in atypes]
347348
qdb.sql_connection.TRN.add(sql_type, sql_params, many=True)
349+
supported_types.extend([atid for _, atid in sql_params])
350+
351+
# If the software type is 'artifact definition', there are a couple
352+
# of extra steps
353+
if software.type == 'artifact definition':
354+
# If supported types is not empty, link the software with these
355+
# types
356+
if supported_types:
357+
sql = """INSERT INTO qiita.software_artifact_type
358+
(software_id, artifact_type_id)
359+
VALUES (%s, %s)"""
360+
sql_params = [[software.id, atid]
361+
for atid in supported_types]
362+
qdb.sql_connection.TRN.add(sql, sql_params, many=True)
363+
# If this is the validate command, we need to add the
364+
# provenance parameter. This is used internally, that's why
365+
# we are adding it here
366+
if name == 'Validate':
367+
sql = """INSERT INTO qiita.command_parameter
368+
(command_id, parameter_name, parameter_type,
369+
required, default_value)
370+
VALUES (%s, 'provenance', 'string', 'False', NULL)
371+
"""
372+
qdb.sql_connection.TRN.add(sql, [c_id])
348373

349374
# Add the outputs to the command
350375
if outputs:

qiita_db/support_files/patches/python_patches/54.py

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -392,57 +392,22 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data,
392392
# and (3) taxonomy summary, which will include all the files generated
393393
# by summarize_taxa_through_plots.py
394394

395-
# Step 1: Create the new type
396395
with TRN:
397-
# Magic number 2 -> The "artifact definition" software type
398-
sql = """INSERT INTO qiita.software
399-
(name, version, description, environment_script, start_script,
400-
software_type_id)
401-
VALUES ('Diversity types', '0.1.0',
402-
'Diversity artifacts type plugin',
403-
'source activate qiita', 'start_diversity_types', 2)
404-
RETURNING software_id"""
405-
TRN.add(sql)
406-
divtype_id = TRN.execute_fetchlast()
407-
408-
# Step 2: Create the validate and HTML generator commands
409-
sql = """INSERT INTO qiita.software_command (software_id, name, description)
410-
VALUES (%s, %s, %s)
411-
RETURNING command_id"""
412-
TRN.add(sql, [divtype_id, 'Validate',
413-
'Validates a new artifact of the given diversity type'])
414-
validate_cmd_id = TRN.execute_fetchlast()
415-
TRN.add(sql, [divtype_id, 'Generate HTML summary',
416-
'Generates the HTML summary of a given diversity type'])
417-
html_summary_cmd_id = TRN.execute_fetchlast()
418-
419-
# Step 3: Add the parameters for the previous commands
420-
sql = """INSERT INTO qiita.command_parameter
421-
(command_id, parameter_name, parameter_type, required)
422-
VALUES (%s, %s, %s, %s)"""
423-
sql_args = [(validate_cmd_id, 'files', 'string', True),
424-
(validate_cmd_id, 'artifact_type', 'string', True),
425-
(validate_cmd_id, 'template', 'prep_template', False),
426-
(validate_cmd_id, 'analysis', 'analysis', False),
427-
(validate_cmd_id, 'provenance', 'string', False),
428-
(html_summary_cmd_id, 'input_data', 'artifact', True)]
429-
TRN.add(sql, sql_args, many=True)
430-
431-
# Step 4: Add the new artifact types
396+
# Add the new artifact types
432397
sql = """INSERT INTO qiita.artifact_type (
433398
artifact_type, description, can_be_submitted_to_ebi,
434399
can_be_submitted_to_vamps)
435400
VALUES (%s, %s, %s, %s)
436401
RETURNING artifact_type_id"""
437-
TRN.add(sql, ['distance_matrix', 'Distance matrix holding pairwise '
438-
'distance between samples', False, False])
402+
TRN.add(sql, ['beta_div_plots', 'Qiime 1 beta diversity results',
403+
False, False])
439404
dm_atype_id = TRN.execute_fetchlast()
440405
TRN.add(sql, ['rarefaction_curves', 'Rarefaction curves', False, False])
441406
rc_atype_id = TRN.execute_fetchlast()
442407
TRN.add(sql, ['taxa_summary', 'Taxa summary plots', False, False])
443408
ts_atype_id = TRN.execute_fetchlast()
444409

445-
# Step 5: Associate each artifact with the filetypes that it accepts
410+
# Associate each artifact with the filetypes that it accepts
446411
# At this time we are going to add them as directories, just as it is done
447412
# right now. We can make it fancier with the new type system.
448413
# Magic number 8: the filepath_type_id for the directory
@@ -454,36 +419,6 @@ def transfer_job(analysis, command_id, params, input_artifact_id, job_data,
454419
[ts_atype_id, 8, True]]
455420
TRN.add(sql, sql_args, many=True)
456421

457-
# Step 6: Associate the plugin with the types that it defines
458-
sql = """INSERT INTO qiita.software_artifact_type
459-
(software_id, artifact_type_id)
460-
VALUES (%s, %s)"""
461-
sql_args = [[divtype_id, dm_atype_id],
462-
[divtype_id, rc_atype_id],
463-
[divtype_id, ts_atype_id]]
464-
TRN.add(sql, sql_args, many=True)
465-
466-
# Step 7: Create the new entries for the data directory
467-
sql = """INSERT INTO qiita.data_directory
468-
(data_type, mountpoint, subdirectory, active)
469-
VALUES (%s, %s, %s, %s)"""
470-
sql_args = [['distance_matrix', 'distance_matrix', True, True],
471-
['rarefaction_curves', 'rarefaction_curves', True, True],
472-
['taxa_summary', 'taxa_summary', True, True]]
473-
TRN.add(sql, sql_args, many=True)
474-
475-
# Step 8: Give a new client id/client secret pair to the plugins
476-
sql = """INSERT INTO qiita.oauth_identifiers (client_id, client_secret)
477-
VALUES (%s, %s)"""
478-
# Each plugin needs a client id/secret pair, so we are generating it here
479-
# at random
480-
client_id = get_random_string(50)
481-
client_secret = get_random_string(255)
482-
TRN.add(sql, [client_id, client_secret])
483-
sql = """INSERT INTO qiita.oauth_software (client_id, software_id)
484-
VALUES (%s, %s)"""
485-
TRN.add(sql, [client_id, divtype_id])
486-
487422
# Create the new commands that execute the current analyses. In qiita,
488423
# the only commands that where available are Summarize Taxa, Beta
489424
# Diversity and Alpha Rarefaction. The system was executing rarefaction

qiita_db/test/test_artifact.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def test_create_type(self):
4949
['Demultiplexed', 'Demultiplexed and QC sequences'],
5050
['FASTA', None], ['FASTA_Sanger', None], ['FASTQ', None],
5151
['SFF', None], ['per_sample_FASTQ', None],
52-
['distance_matrix', 'Distance matrix holding pairwise '
53-
'distance between samples'],
52+
['beta_div_plots', 'Qiime 1 beta diversity results'],
5453
['rarefaction_curves', 'Rarefaction curves'],
5554
['taxa_summary', 'Taxa summary plots']]
5655
self.assertItemsEqual(obs, exp)
@@ -64,12 +63,12 @@ def test_create_type(self):
6463
['Demultiplexed', 'Demultiplexed and QC sequences'],
6564
['FASTA', None], ['FASTA_Sanger', None], ['FASTQ', None],
6665
['SFF', None], ['per_sample_FASTQ', None],
67-
['distance_matrix', 'Distance matrix holding pairwise '
68-
'distance between samples'],
66+
['beta_div_plots', 'Qiime 1 beta diversity results'],
6967
['rarefaction_curves', 'Rarefaction curves'],
7068
['taxa_summary', 'Taxa summary plots'],
7169
['NewType', 'NewTypeDesc']]
7270
self.assertItemsEqual(obs, exp)
71+
self.assertTrue(exists(qdb.util.get_mountpoint('NewType')[0][1]))
7372

7473
with self.assertRaises(qdb.exceptions.QiitaDBDuplicateError):
7574
qdb.artifact.Artifact.create_type(

qiita_db/test/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_get_artifact_types(self):
100100
obs = qdb.util.get_artifact_types()
101101
exp = {'SFF': 1, 'FASTA_Sanger': 2, 'FASTQ': 3, 'FASTA': 4,
102102
'per_sample_FASTQ': 5, 'Demultiplexed': 6, 'BIOM': 7,
103-
'distance_matrix': 8L, 'rarefaction_curves': 9L,
103+
'beta_div_plots': 8L, 'rarefaction_curves': 9L,
104104
'taxa_summary': 10L}
105105
self.assertEqual(obs, exp)
106106

qiita_pet/handlers/api_proxy/tests/test_artifact.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ def test_artifact_types_get_req(self):
108108
['FASTQ', None],
109109
['SFF', None],
110110
['per_sample_FASTQ', None],
111-
['distance_matrix', 'Distance matrix holding pairwise'
112-
' distance between samples'],
111+
['beta_div_plots', 'Qiime 1 beta diversity results'],
113112
['rarefaction_curves', 'Rarefaction curves'],
114113
['taxa_summary', 'Taxa summary plots']]}
115114

qiita_pet/handlers/api_proxy/tests/test_processing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def test_list_commands_handler_get_req(self):
5555
exp = {'status': 'success',
5656
'message': '',
5757
'commands': [
58-
{'command': 'Summarize Taxa', 'id': 11,
58+
{'command': 'Summarize Taxa', 'id': 9,
5959
'output': [['taxa_summary', 'taxa_summary']]},
60-
{'command': 'Beta Diversity', 'id': 12,
61-
'output': [['distance_matrix', 'distance_matrix']]},
62-
{'command': 'Alpha Rarefaction', 'id': 13,
60+
{'command': 'Beta Diversity', 'id': 10,
61+
'output': [['distance_matrix', 'beta_div_plots']]},
62+
{'command': 'Alpha Rarefaction', 'id': 11,
6363
'output': [['rarefaction_curves', 'rarefaction_curves']]},
64-
{'command': 'Single Rarefaction', 'id': 14,
64+
{'command': 'Single Rarefaction', 'id': 12,
6565
'output': [['rarefied_table', 'BIOM']]}]}
6666
# since the order of the commands can change, test them separately
6767
self.assertItemsEqual(obs.pop('commands'), exp.pop('commands'))

0 commit comments

Comments
 (0)