Skip to content
30 changes: 19 additions & 11 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,20 +987,23 @@ def test_get_artifacts_information(self):

exp = [
{'files': ['1_study_1001_closed_reference_otu_table.biom'],
'target_subfragment': ['V4'], 'artifact_id': 4,
'algorithm': (
'Pick closed-reference OTUs | Split libraries FASTQ'),
'data_type': '18S', 'prep_samples': 27,
'artifact_id': 4, 'data_type': '18S', 'target_gene': '16S rRNA',
'name': 'BIOM', 'target_subfragment': ['V4'],
'parameters': {
'reference': '1', 'similarity': '0.97',
'sortmerna_e_value': '1', 'sortmerna_max_pos': '10000',
'threads': '1', 'sortmerna_coverage': '0.97'}, 'name': 'BIOM'},
{'files': [], 'target_subfragment': ['V4'], 'algorithm': '',
'artifact_id': 7, 'data_type': '16S', 'prep_samples': 27,
'parameters': {}, 'name': 'BIOM'},
{'files': ['biom_table.biom'], 'target_subfragment': [],
'algorithm': '', 'artifact_id': 8, 'data_type': '18S',
'prep_samples': 0, 'parameters': {}, 'name': 'noname'}]
'threads': '1', 'sortmerna_coverage': '0.97'},
'algorithm': 'Pick closed-reference OTUs | Split libraries FASTQ',
'algorithm_az': 'PickclosedreferenceOTUsSplitlibrariesFASTQ',
'platform': 'Illumina', 'prep_samples': 27},
{'files': [], 'artifact_id': 7, 'data_type': '16S',
'target_gene': '16S rRNA', 'name': 'BIOM',
'target_subfragment': ['V4'], 'parameters': {}, 'algorithm': '',
'algorithm_az': '', 'platform': 'Illumina', 'prep_samples': 27},
{'files': ['biom_table.biom'], 'artifact_id': 8,
'data_type': '18S', 'target_gene': '', 'name': 'noname',
'target_subfragment': [], 'parameters': {}, 'algorithm': '',
'algorithm_az': '', 'platform': '', 'prep_samples': 0}]
self.assertItemsEqual(obs, exp)

# now let's test that the order given by the commands actually give the
Expand All @@ -1019,6 +1022,8 @@ def test_get_artifacts_information(self):
del obs[i]['timestamp']
exp[0]['algorithm'] = ('Pick closed-reference OTUs (reference: 1) '
'| Split libraries FASTQ')
exp[0]['algorithm_az'] = (
'PickclosedreferenceOTUsreferenceSplitlibrariesFASTQ')
self.assertItemsEqual(obs, exp)

# setting up database changes for also command output
Expand All @@ -1032,6 +1037,9 @@ def test_get_artifacts_information(self):
exp[0]['algorithm'] = ('Pick closed-reference OTUs (reference: 1, '
'BIOM: 1_study_1001_closed_reference_'
'otu_table.biom) | Split libraries FASTQ')
exp[0]['algorithm_az'] = (
'PickclosedreferenceOTUsreferenceBIOMstudyclosedreference'
'otutablebiomSplitlibrariesFASTQ')
self.assertItemsEqual(obs, exp)

# returning database as it was
Expand Down
31 changes: 25 additions & 6 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from contextlib import contextmanager
from future.builtins import bytes, str
import h5py
import re

from qiita_core.exceptions import IncompetentQiitaDeveloperError
import qiita_db as qdb
Expand Down Expand Up @@ -1605,6 +1606,8 @@ def get_artifacts_information(artifact_ids, only_biom=True):
# now let's get the actual artifacts
ts = {}
ps = {}
algorithm_az = {'': ''}
regex = re.compile('[^a-zA-Z]')
PT = qdb.metadata_template.prep_template.PrepTemplate
qdb.sql_connection.TRN.add(sql, [tuple(artifact_ids)])
for row in qdb.sql_connection.TRN.execute_fetchindex():
Expand Down Expand Up @@ -1655,6 +1658,8 @@ def get_artifacts_information(artifact_ids, only_biom=True):
palgorithm = "%s (%s)" % (palgorithm, params)

algorithm = '%s | %s' % (cname, palgorithm)
if algorithm not in algorithm_az:
algorithm_az[algorithm] = regex.sub('', algorithm)

if target is None:
target = []
Expand All @@ -1665,23 +1670,37 @@ def get_artifacts_information(artifact_ids, only_biom=True):
qdb.sql_connection.TRN.execute_fetchflatten()
target = ts[target]

if prep_template_id is None:
prep_samples = 0
else:
prep_samples = 0
platform = ''
target_gene = ''
if prep_template_id is not None:
if prep_template_id not in ps:
ps[prep_template_id] = len(list(
PT(prep_template_id).keys()))
prep_samples = ps[prep_template_id]
pt = PT(prep_template_id)
categories = pt.categories()
if 'platform' in categories:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defer on this to @wasade, but I think instead of an empty string for platform and target_gene, it would likely be better to return "Not Available" or something along those lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, i thought it was "not available" lowercase. Best to ask Gail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EBI is "null values: not applicable, missing: not collected, missing: not provided, missing: restricted access.". However, this is different and the current use case is redbiom, so whatever you prefer @wasade .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing offline with @wasade we are going with: 'not provided'

platform = ', '.join(
set(pt.get_category('platform').values()))
if 'target_gene' in categories:
target_gene = ', '.join(
set(pt.get_category('target_gene').values()))

ps[prep_template_id] = [
len(list(pt.keys())), platform, target_gene]

prep_samples, patform, target_gene = ps[prep_template_id]

results.append({
'artifact_id': aid,
'target_subfragment': target,
'prep_samples': prep_samples,
'platform': platform,
'target_gene': target_gene,
'name': name,
'data_type': dt,
'timestamp': str(gt),
'parameters': aparams,
'algorithm': algorithm,
'algorithm_az': algorithm_az[algorithm],
'files': filepaths})

return results
Expand Down
33 changes: 19 additions & 14 deletions qiita_pet/handlers/api_proxy/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,29 +227,34 @@ def test_artifact_get_info(self):
obs = artifact_get_info('test@foo.bar', [5, 6, 7])
data = [
{'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'],
'target_subfragment': ['V4'],
'algorithm': (
'Pick closed-reference OTUs | Split libraries FASTQ'),
'artifact_id': 6, 'data_type': '16S',
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
'timestamp': '2012-10-02 17:30:00', 'target_gene': '16S rRNA',
'name': 'BIOM', 'target_subfragment': ['V4'],
'parameters': {
'reference': '2', 'similarity': '0.97',
'sortmerna_e_value': '1', 'sortmerna_max_pos': '10000',
'threads': '1', 'sortmerna_coverage': '0.97'}, 'name': 'BIOM'},
'threads': '1', 'sortmerna_coverage': '0.97'},
'algorithm': 'Pick closed-reference OTUs | Split libraries FASTQ',
'platform': 'Illumina',
'algorithm_az': 'PickclosedreferenceOTUsSplitlibrariesFASTQ',
'prep_samples': 27},
{'files': ['1_study_1001_closed_reference_otu_table.biom'],
'target_subfragment': ['V4'],
'algorithm': (
'Pick closed-reference OTUs | Split libraries FASTQ'),
'artifact_id': 5, 'data_type': '18S',
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
'timestamp': '2012-10-02 17:30:00', 'target_gene': '16S rRNA',
'name': 'BIOM', 'target_subfragment': ['V4'],
'parameters': {
'reference': '1', 'similarity': '0.97',
'sortmerna_e_value': '1', 'sortmerna_max_pos': '10000',
'threads': '1', 'sortmerna_coverage': '0.97'}, 'name': 'BIOM'},
{'files': [], 'target_subfragment': ['V4'], 'algorithm': '',
'artifact_id': 7, 'data_type': '16S',
'timestamp': '2012-10-02 17:30:00', 'prep_samples': 27,
'parameters': {}, 'name': 'BIOM'}]
'threads': '1', 'sortmerna_coverage': '0.97'},
'algorithm': 'Pick closed-reference OTUs | Split libraries FASTQ',
'platform': '',
'algorithm_az': 'PickclosedreferenceOTUsSplitlibrariesFASTQ',
'prep_samples': 27},
{'files': [], 'artifact_id': 7, 'data_type': '16S',
'timestamp': '2012-10-02 17:30:00', 'target_gene': '16S rRNA',
'name': 'BIOM', 'target_subfragment': ['V4'], 'parameters': {},
'algorithm': '', 'platform': 'Illumina', 'algorithm_az': '',
'prep_samples': 27}]
exp = {'status': 'success', 'msg': '', 'data': data}
self.assertItemsEqual(obs.keys(), exp.keys())
self.assertEqual(obs['status'], exp['status'])
Expand Down
14 changes: 9 additions & 5 deletions qiita_pet/handlers/study_handlers/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,20 @@ def test_get(self):
data = [
{'files': ['1_study_1001_closed_reference_otu_table_Silva.biom'],
'target_subfragment': ['V4'], 'artifact_id': 6,
'data_type': '16S', 'timestamp': '2012-10-02 17:30:00',
'data_type': '16S', 'timestamp': u'2012-10-02 17:30:00',
'platform': 'Illumina',
'algorithm_az': 'PickclosedreferenceOTUsSplitlibrariesFASTQ',
'prep_samples': 27,
'algorithm': 'Pick closed-reference OTUs | Split libraries FASTQ',
'parameters': {
'reference': '2', 'similarity': '0.97',
'sortmerna_e_value': '1', 'sortmerna_max_pos': '10000',
'threads': '1', 'sortmerna_coverage': '0.97'}, 'name': 'BIOM'},
'reference': u'2', 'similarity': '0.97',
'sortmerna_e_value': '1', 'sortmerna_max_pos': '10000',
'threads': '1', 'sortmerna_coverage': '0.97'},
'target_gene': '16S rRNA', 'name': 'BIOM'},
{'files': [], 'target_subfragment': ['V4'], 'artifact_id': 7,
'data_type': '16S', 'timestamp': '2012-10-02 17:30:00',
'prep_samples': 27, 'algorithm': '', 'parameters': {},
'platform': 'Illumina', 'algorithm_az': '', 'prep_samples': 27,
'algorithm': '', 'parameters': {}, 'target_gene': '16S rRNA',
'name': 'BIOM'}]
exp = {'status': 'success', 'msg': '', 'data': data}
obs = loads(response.body)
Expand Down