Skip to content

Commit

Permalink
fix generate_biom_and_metadata_release (#2072)
Browse files Browse the repository at this point in the history
* fix generate_biom_and_metadata_release

* addressing @ElDeveloper comment
  • Loading branch information
antgonza authored and ElDeveloper committed Feb 7, 2017
1 parent 01c656c commit 53188a6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
56 changes: 56 additions & 0 deletions qiita_db/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,62 @@ def test_generate_biom_and_metadata_release(self):
'FASTQ\n']
self.assertEqual(txt_obs, txt_exp)

# whatever the configuration was, we will change to settings so we can
# test the other option when dealing with the end '/'
with qdb.sql_connection.TRN:
qdb.sql_connection.TRN.add(
"SELECT base_data_dir FROM settings")
obdr = qdb.sql_connection.TRN.execute_fetchlast()
if obdr[-1] == '/':
bdr = obdr[:-1]
else:
bdr = obdr + '/'

qdb.sql_connection.TRN.add(
"UPDATE settings SET base_data_dir = '%s'" % bdr)
bdr = qdb.sql_connection.TRN.execute()

tgz, txt = qdb.util.generate_biom_and_metadata_release('private')
self.files_to_remove.extend([tgz, txt])

tmp = topen(tgz, "r:gz")
tgz_obs = [ti.name for ti in tmp]
tmp.close()
tgz_exp = [
'processed_data/1_study_1001_closed_reference_otu_table.biom',
'templates/1_19700101-000000.txt',
'templates/1_prep_1_19700101-000000.txt',
'processed_data/1_study_1001_closed_reference_otu_table.biom',
'templates/1_19700101-000000.txt',
'templates/1_prep_1_19700101-000000.txt',
'processed_data/1_study_1001_closed_reference_otu_table_'
'Silva.biom', 'templates/1_19700101-000000.txt',
'templates/1_prep_1_19700101-000000.txt']
self.assertEqual(tgz_obs, tgz_exp)

tmp = open(txt)
txt_obs = tmp.readlines()
tmp.close()
txt_exp = [
'biom_fp\tsample_fp\tprep_fp\tqiita_artifact_id\tcommand\n',
'processed_data/1_study_1001_closed_reference_otu_table.biom\ttem'
'plates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-000000'
'.txt\t4\tPick closed-reference OTUs, Split libraries FASTQ\n',
'processed_data/1_study_1001_closed_reference_otu_table.biom\ttem'
'plates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-000000'
'.txt\t5\tPick closed-reference OTUs, Split libraries FASTQ\n',
'processed_data/1_study_1001_closed_reference_otu_table_Silva.bio'
'm\ttemplates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-'
'000000.txt\t6\tPick closed-reference OTUs, Split libraries '
'FASTQ\n']
self.assertEqual(txt_obs, txt_exp)

# returning configuration
with qdb.sql_connection.TRN:
qdb.sql_connection.TRN.add(
"UPDATE settings SET base_data_dir = '%s'" % obdr)
bdr = qdb.sql_connection.TRN.execute()


@qiita_test_checker()
class UtilTests(TestCase):
Expand Down
11 changes: 3 additions & 8 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,14 +1574,11 @@ def generate_biom_and_metadata_release(study_status='public'):
working_dir = qiita_config.working_dir
portal = qiita_config.portal
bdir = qdb.util.get_db_files_base_dir()
bdir_len = len(bdir) + 1

data = []
for s in studies:
# [0] latest is first, [1] only getting the filepath
sample_fp = s.sample_template.get_filepaths()[0][1]
if sample_fp.startswith(bdir):
sample_fp = sample_fp[bdir_len:]
sample_fp = relpath(s.sample_template.get_filepaths()[0][1], bdir)

for a in s.artifacts(artifact_type='BIOM'):
if a.processing_parameters is None:
Expand All @@ -1605,16 +1602,14 @@ def generate_biom_and_metadata_release(study_status='public'):
for _, fp, fp_type in a.filepaths:
if fp_type != 'biom' or 'only-16s' in fp:
continue
if fp.startswith(bdir):
fp = fp[bdir_len:]
fp = relpath(fp, bdir)
# format: (biom_fp, sample_fp, prep_fp, qiita_artifact_id,
# human readable name)
for pt in a.prep_templates:
for _, prep_fp in pt.get_filepaths():
if 'qiime' not in prep_fp:
break
if prep_fp.startswith(bdir):
prep_fp = prep_fp[bdir_len:]
prep_fp = relpath(prep_fp, bdir)
data.append((fp, sample_fp, prep_fp, a.id, human_cmd))

# writing text and tgz file
Expand Down

0 comments on commit 53188a6

Please sign in to comment.