Skip to content

Commit 1377640

Browse files
josenavasantgonza
authored andcommitted
Sync-ing with master (again) (#2073)
* fix #1505 * improving some GUI stuff * improving some GUI stuff - missing lines * addressing all comments * ready for review * fix #1987 * initial commit * requested changes * fix filter job list * Fixing server cert (#2051) * fix get_studies * flake8 * fix #503 * fix #2010 * fix #1913 * fix errors * addressing @josenavas comment * flake8 * fix #1010 * fix #1066 (#2058) * addressing @josenavas comments * fix #1961 * fix #1837 * Automatic jobs & new stats (#2057) * fix #814, fix #1636 * fixing error in test-env * fixing stats.html call * adding img * addressing @josenavas comments * rm for loops * addresssing @ElDeveloper comments * generalizing this functionality * fix #1816 * fix #1959 * addressing @josenavas comments * addressing @josenavas comments * fixing error * fixed? * addressing @josenavas comments * addressing @wasade comments * fix flake8 * generate biom and metadata release (#2066) * initial commit * adding portal * addressing @josenavas comments * pid -> qiita_artifact_id * addressing @josenavas comments * addressing @ElDeveloper comments * rm 50.sql * database changes to fix 969 * adding delete * addressing @josenavas comments * addressing @ElDeveloper comments * duh! * fix generate_biom_and_metadata_release (#2072) * fix generate_biom_and_metadata_release * addressing @ElDeveloper comment
1 parent 3fdb802 commit 1377640

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

qiita_db/artifact.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def _associate_with_analysis(instance, analysis_id):
429429
instance.visibility = 'private'
430430
else:
431431
instance.visibility = 'public'
432+
432433
elif prep_template:
433434
# This artifact is uploaded by the user in the
434435
# processing pipeline

qiita_db/test/test_meta_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def test_validate_filepath_access_by_user(self):
4747
for i in [1, 2, 3, 4, 5, 9, 12, 17, 18, 19, 20, 21]:
4848
self.assertFalse(qdb.meta_util.validate_filepath_access_by_user(
4949
user, i))
50+
5051
for i in [15, 16]:
5152
self.assertTrue(qdb.meta_util.validate_filepath_access_by_user(
5253
user, i))

qiita_db/test/test_util.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,62 @@ def test_generate_biom_and_metadata_release(self):
777777
'FASTQ\n']
778778
self.assertEqual(txt_obs, txt_exp)
779779

780+
# whatever the configuration was, we will change to settings so we can
781+
# test the other option when dealing with the end '/'
782+
with qdb.sql_connection.TRN:
783+
qdb.sql_connection.TRN.add(
784+
"SELECT base_data_dir FROM settings")
785+
obdr = qdb.sql_connection.TRN.execute_fetchlast()
786+
if obdr[-1] == '/':
787+
bdr = obdr[:-1]
788+
else:
789+
bdr = obdr + '/'
790+
791+
qdb.sql_connection.TRN.add(
792+
"UPDATE settings SET base_data_dir = '%s'" % bdr)
793+
bdr = qdb.sql_connection.TRN.execute()
794+
795+
tgz, txt = qdb.util.generate_biom_and_metadata_release('private')
796+
self.files_to_remove.extend([tgz, txt])
797+
798+
tmp = topen(tgz, "r:gz")
799+
tgz_obs = [ti.name for ti in tmp]
800+
tmp.close()
801+
tgz_exp = [
802+
'processed_data/1_study_1001_closed_reference_otu_table.biom',
803+
'templates/1_19700101-000000.txt',
804+
'templates/1_prep_1_19700101-000000.txt',
805+
'processed_data/1_study_1001_closed_reference_otu_table.biom',
806+
'templates/1_19700101-000000.txt',
807+
'templates/1_prep_1_19700101-000000.txt',
808+
'processed_data/1_study_1001_closed_reference_otu_table_'
809+
'Silva.biom', 'templates/1_19700101-000000.txt',
810+
'templates/1_prep_1_19700101-000000.txt']
811+
self.assertEqual(tgz_obs, tgz_exp)
812+
813+
tmp = open(txt)
814+
txt_obs = tmp.readlines()
815+
tmp.close()
816+
txt_exp = [
817+
'biom_fp\tsample_fp\tprep_fp\tqiita_artifact_id\tcommand\n',
818+
'processed_data/1_study_1001_closed_reference_otu_table.biom\ttem'
819+
'plates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-000000'
820+
'.txt\t4\tPick closed-reference OTUs, Split libraries FASTQ\n',
821+
'processed_data/1_study_1001_closed_reference_otu_table.biom\ttem'
822+
'plates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-000000'
823+
'.txt\t5\tPick closed-reference OTUs, Split libraries FASTQ\n',
824+
'processed_data/1_study_1001_closed_reference_otu_table_Silva.bio'
825+
'm\ttemplates/1_19700101-000000.txt\ttemplates/1_prep_1_19700101-'
826+
'000000.txt\t6\tPick closed-reference OTUs, Split libraries '
827+
'FASTQ\n']
828+
self.assertEqual(txt_obs, txt_exp)
829+
830+
# returning configuration
831+
with qdb.sql_connection.TRN:
832+
qdb.sql_connection.TRN.add(
833+
"UPDATE settings SET base_data_dir = '%s'" % obdr)
834+
bdr = qdb.sql_connection.TRN.execute()
835+
780836

781837
@qiita_test_checker()
782838
class UtilTests(TestCase):

qiita_db/util.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,14 +1531,11 @@ def generate_biom_and_metadata_release(study_status='public'):
15311531
working_dir = qiita_config.working_dir
15321532
portal = qiita_config.portal
15331533
bdir = qdb.util.get_db_files_base_dir()
1534-
bdir_len = len(bdir) + 1
15351534

15361535
data = []
15371536
for s in studies:
15381537
# [0] latest is first, [1] only getting the filepath
1539-
sample_fp = s.sample_template.get_filepaths()[0][1]
1540-
if sample_fp.startswith(bdir):
1541-
sample_fp = sample_fp[bdir_len:]
1538+
sample_fp = relpath(s.sample_template.get_filepaths()[0][1], bdir)
15421539

15431540
for a in s.artifacts(artifact_type='BIOM'):
15441541
if a.processing_parameters is None:
@@ -1562,16 +1559,14 @@ def generate_biom_and_metadata_release(study_status='public'):
15621559
for _, fp, fp_type in a.filepaths:
15631560
if fp_type != 'biom' or 'only-16s' in fp:
15641561
continue
1565-
if fp.startswith(bdir):
1566-
fp = fp[bdir_len:]
1562+
fp = relpath(fp, bdir)
15671563
# format: (biom_fp, sample_fp, prep_fp, qiita_artifact_id,
15681564
# human readable name)
15691565
for pt in a.prep_templates:
15701566
for _, prep_fp in pt.get_filepaths():
15711567
if 'qiime' not in prep_fp:
15721568
break
1573-
if prep_fp.startswith(bdir):
1574-
prep_fp = prep_fp[bdir_len:]
1569+
prep_fp = relpath(prep_fp, bdir)
15751570
data.append((fp, sample_fp, prep_fp, a.id, human_cmd))
15761571

15771572
# writing text and tgz file

0 commit comments

Comments
 (0)