Skip to content

Commit 24905ff

Browse files
committed
some minor fixes
1 parent 870a04d commit 24905ff

File tree

4 files changed

+16
-68
lines changed

4 files changed

+16
-68
lines changed

qiita_db/support_files/patches/python_patches/54.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ def create_non_rarefied_biom_artifact(analysis, biom_data, rarefied_table):
9696
biom_table = load_table(biom_fp)
9797
samples = set(samples).intersection(biom_table.ids())
9898
biom_table.filter(samples, axis='sample', inplace=True)
99-
new_table = new_table.merge(biom_table)
100-
ids_map.update({sid: "%d.%s" % (a_id, sid)
101-
for sid in biom_table.ids()})
99+
# we need to check if the table has samples left before merging
100+
if biom_table.shape[0] != 0 and biom_table.shape[1] != 0:
101+
new_table = new_table.merge(biom_table)
102+
ids_map.update({sid: "%d.%s" % (a_id, sid)
103+
for sid in biom_table.ids()})
102104

103105
# Check if we need to rename the sample ids in the biom table
104106
new_table_ids = set(new_table.ids())

qiita_db/test/test_util.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,6 @@ def test_move_filepaths_to_upload_folder(self):
446446

447447
self.files_to_remove.append(new_fp)
448448

449-
def test_get_filepath_id(self):
450-
_, base = qdb.util.get_mountpoint("raw_data")[0]
451-
fp = join(base, '1_s_G1_L001_sequences.fastq.gz')
452-
obs = qdb.util.get_filepath_id("raw_data", fp)
453-
self.assertEqual(obs, 1)
454-
455-
def test_get_filepath_id_error(self):
456-
with self.assertRaises(qdb.exceptions.QiitaDBError):
457-
qdb.util.get_filepath_id("raw_data", "Not_a_path")
458-
459449
def test_get_mountpoint(self):
460450
exp = [(5, join(qdb.util.get_db_files_base_dir(), 'raw_data'))]
461451
obs = qdb.util.get_mountpoint("raw_data")

qiita_db/util.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from binascii import crc32
4949
from bcrypt import hashpw, gensalt
5050
from functools import partial
51-
from os.path import join, basename, isdir, relpath, exists
51+
from os.path import join, basename, isdir, exists
5252
from os import walk, remove, listdir, makedirs, rename
5353
from shutil import move, rmtree, copy as shutil_copy
5454
from json import dumps
@@ -841,44 +841,6 @@ def move_filepaths_to_upload_folder(study_id, filepaths):
841841
qdb.sql_connection.TRN.execute()
842842

843843

844-
def get_filepath_id(table, fp):
845-
"""Return the filepath_id of fp
846-
847-
Parameters
848-
----------
849-
table : str
850-
The table type so we can search on this one
851-
fp : str
852-
The full filepath
853-
854-
Returns
855-
-------
856-
int
857-
The filepath id forthe given filepath
858-
859-
Raises
860-
------
861-
QiitaDBError
862-
If fp is not stored in the DB.
863-
"""
864-
with qdb.sql_connection.TRN:
865-
_, mp = get_mountpoint(table)[0]
866-
base_fp = join(get_db_files_base_dir(), mp)
867-
868-
sql = "SELECT filepath_id FROM qiita.filepath WHERE filepath=%s"
869-
qdb.sql_connection.TRN.add(sql, [relpath(fp, base_fp)])
870-
fp_id = qdb.sql_connection.TRN.execute_fetchindex()
871-
872-
# check if the query has actually returned something
873-
if not fp_id:
874-
raise qdb.exceptions.QiitaDBError(
875-
"Filepath not stored in the database")
876-
877-
# If there was a result it was a single row and and single value,
878-
# hence access to [0][0]
879-
return fp_id[0][0]
880-
881-
882844
def filepath_id_to_rel_path(filepath_id):
883845
"""Gets the relative to the base directory of filepath_id
884846

qiita_pet/handlers/analysis_handlers/listing_handlers.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from qiita_pet.handlers.util import download_link_or_path
2020
from qiita_pet.handlers.analysis_handlers import check_analysis_access
2121
from qiita_pet.util import is_localhost
22-
from qiita_db.util import get_filepath_id
22+
from qiita_db.util import retrieve_filepaths
2323
from qiita_db.analysis import Analysis
2424
from qiita_db.logger import LogEntry
2525
from qiita_db.reference import Reference
@@ -37,27 +37,21 @@ def get(self):
3737
analyses = user.shared_analyses | user.private_analyses
3838

3939
is_local_request = is_localhost(self.request.headers['host'])
40-
gfi = partial(get_filepath_id, 'analysis')
4140
dlop = partial(download_link_or_path, is_local_request)
4241
mappings = {}
4342
bioms = {}
4443
tgzs = {}
4544
for analysis in analyses:
4645
_id = analysis.id
47-
# getting mapping file
48-
mapping = analysis.mapping_file
49-
if mapping is not None:
50-
mappings[_id] = dlop(mapping, gfi(mapping), 'mapping file')
51-
else:
52-
mappings[_id] = ''
53-
54-
bioms[_id] = ''
55-
# getting tgz file
56-
tgz = analysis.tgz
57-
if tgz is not None:
58-
tgzs[_id] = dlop(tgz, gfi(tgz), 'tgz file')
59-
else:
60-
tgzs[_id] = ''
46+
mappings[_id], bioms[_id], tgzs[_id] = '', '', ''
47+
for fid, fp, fpt in retrieve_filepaths('analysis_filepath',
48+
'analysis_id', _id):
49+
if fpt == 'plain_text':
50+
mappings[_id] = dlop(fp, fid, 'mapping file')
51+
if fpt == 'biom':
52+
bioms[_id] = dlop(fp, fid, 'biom file')
53+
if fpt == 'tgz':
54+
tgzs[_id] = dlop(fp, fid, 'tgz file')
6155

6256
self.render("list_analyses.html", analyses=analyses, message=message,
6357
level=level, is_local_request=is_local_request,

0 commit comments

Comments
 (0)