Skip to content

fix generate_biom_and_metadata_release #2072

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

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
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