Skip to content

Commit 520bcfa

Browse files
committed
removing conn_handler from def and calls - 1
1 parent e311fb7 commit 520bcfa

File tree

14 files changed

+60
-90
lines changed

14 files changed

+60
-90
lines changed

qiita_db/analysis.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,12 @@ def build_files(self, rarefaction_depth=None):
656656
raise ValueError("rarefaction_depth must be greater than 0")
657657

658658
conn_handler = SQLConnectionHandler()
659-
samples = self._get_samples(conn_handler=conn_handler)
660-
self._build_mapping_file(samples, conn_handler=conn_handler)
659+
samples = self._get_samples()
660+
self._build_mapping_file(samples)
661661
self._build_biom_tables(samples, rarefaction_depth,
662662
conn_handler=conn_handler)
663663

664-
def _get_samples(self, conn_handler=None):
664+
def _get_samples(self):
665665
"""Retrieves dict of samples to proc_data_id for the analysis"""
666666
conn_handler = SQLConnectionHandler()
667667
sql = ("SELECT processed_data_id, array_agg(sample_id ORDER BY "
@@ -714,7 +714,7 @@ def _build_biom_tables(self, samples, rarefaction_depth,
714714
self._add_file("%d_analysis_%s.biom" % (self._id, dt),
715715
"biom", data_type=dt, conn_handler=conn_handler)
716716

717-
def _build_mapping_file(self, samples, conn_handler=None):
717+
def _build_mapping_file(self, samples):
718718
"""Builds the combined mapping file for all samples
719719
Code modified slightly from qiime.util.MetadataMap.__add__"""
720720
conn_handler = SQLConnectionHandler()
@@ -787,11 +787,10 @@ def _add_file(self, filename, filetype, data_type=None, conn_handler=None):
787787
data_type : str, optional
788788
conn_handler : SQLConnectionHandler object, optional
789789
"""
790-
conn_handler = SQLConnectionHandler() \
791-
790+
conn_handler = SQLConnectionHandler()
792791

793-
filetype_id = convert_to_id(filetype, 'filepath_type', conn_handler)
794-
_, mp = get_mountpoint('analysis', conn_handler)[0]
792+
filetype_id = convert_to_id(filetype, 'filepath_type')
793+
_, mp = get_mountpoint('analysis')[0]
795794
fpid = insert_filepaths([
796795
(join(mp, filename), filetype_id)], -1, 'analysis', 'filepath',
797796
conn_handler, move_files=False)[0]

qiita_db/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,13 @@ def _check_subclass(cls):
113113
raise IncompetentQiitaDeveloperError(
114114
"Could not instantiate an object of the base class")
115115

116-
def _check_id(self, id_, conn_handler=None):
116+
def _check_id(self, id_):
117117
r"""Check that the provided ID actually exists on the database
118118
119119
Parameters
120120
----------
121121
id_ : object
122122
The ID to test
123-
conn_handler : SQLConnectionHandler
124-
The connection handler object connected to the DB
125123
126124
Notes
127125
-----

qiita_db/data.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ def get_filepaths(self):
193193
self._data_filepath_table,
194194
self._data_filepath_column), {'id': self.id})
195195

196-
_, fb = get_mountpoint(self._table, conn_handler)[0]
196+
_, fb = get_mountpoint(self._table)[0]
197197
base_fp = partial(join, fb)
198198

199-
return [(fpid, base_fp(fp), convert_from_id(fid, "filepath_type",
200-
conn_handler)) for fpid, fp, fid in db_paths]
199+
return [(fpid, base_fp(fp), convert_from_id(fid, "filepath_type"))
200+
for fpid, fp, fid in db_paths]
201201

202202
def get_filepath_ids(self):
203203
self._check_subclass()
@@ -579,8 +579,7 @@ def clear_filepaths(self):
579579

580580
# Move the files, if they are not used, if you get to this point
581581
# self.studies should only have one element, thus self.studies[0]
582-
move_filepaths_to_upload_folder(self.studies[0], filepaths,
583-
conn_handler=conn_handler)
582+
move_filepaths_to_upload_folder(self.studies[0], filepaths)
584583

585584
def remove_filepath(self, fp):
586585
"""Removes the filepath from the RawData
@@ -614,7 +613,7 @@ def remove_filepath(self, fp):
614613
self._set_link_filepaths_status("idle")
615614

616615
# Delete the files, if they are not used anywhere
617-
purge_filepaths(conn_handler)
616+
purge_filepaths()
618617

619618
def status(self, study):
620619
"""The status of the raw data within the given study
@@ -753,7 +752,7 @@ def create(cls, study, preprocessed_params_table, preprocessed_params_id,
753752
data_type = prep_template.data_type(ret_id=True)
754753
else:
755754
# only data_type, so need id from the text
756-
data_type = convert_to_id(data_type, "data_type", conn_handler)
755+
data_type = convert_to_id(data_type, "data_type")
757756

758757
# Check that the preprocessed_params_table exists
759758
if not exists_dynamic_table(preprocessed_params_table, "preprocessed_",
@@ -1278,7 +1277,7 @@ def create(cls, processed_params_table, processed_params_id, filepaths,
12781277
"You must provide either a preprocessed_data, a "
12791278
"data_type, or both")
12801279
else:
1281-
data_type = convert_to_id(data_type, "data_type", conn_handler)
1280+
data_type = convert_to_id(data_type, "data_type")
12821281

12831282
# We first check that the processed_params_table exists
12841283
if not exists_dynamic_table(processed_params_table,
@@ -1524,8 +1523,7 @@ def status(self, status):
15241523

15251524
conn_handler = SQLConnectionHandler()
15261525

1527-
status_id = convert_to_id(status, 'processed_data_status',
1528-
conn_handler=conn_handler)
1526+
status_id = convert_to_id(status, 'processed_data_status')
15291527

15301528
sql = """UPDATE qiita.{0} SET processed_data_status_id = %s
15311529
WHERE processed_data_id=%s""".format(self._table)

qiita_db/job.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def exists(cls, datatype, command, options, analysis,
110110
"""
111111
conn_handler = SQLConnectionHandler()
112112
# check passed arguments and grab analyses for matching jobs
113-
datatype_id = convert_to_id(datatype, "data_type", conn_handler)
113+
datatype_id = convert_to_id(datatype, "data_type")
114114
sql = "SELECT command_id FROM qiita.command WHERE name = %s"
115115
command_id = conn_handler.execute_fetchone(sql, (command, ))[0]
116116
opts_json = params_dict_to_json(options)
@@ -238,7 +238,7 @@ def create(cls, datatype, command, options, analysis,
238238
"analysis: %s" % (datatype, command, options, analysis.id))
239239

240240
# Get the datatype and command ids from the strings
241-
datatype_id = convert_to_id(datatype, "data_type", conn_handler)
241+
datatype_id = convert_to_id(datatype, "data_type")
242242
sql = "SELECT command_id FROM qiita.command WHERE name = %s"
243243
command_id = conn_handler.execute_fetchone(sql, (command, ))[0]
244244
opts_json = params_dict_to_json(options)
@@ -297,7 +297,7 @@ def options(self):
297297
"job_id = %s)".format(self._table))
298298
db_comm = conn_handler.execute_fetchone(sql, (self._id, ))
299299
out_opt = loads(db_comm[1])
300-
basedir = get_db_files_base_dir(conn_handler)
300+
basedir = get_db_files_base_dir()
301301
join_f = partial(join, join(basedir, "job"))
302302
for k in out_opt:
303303
opts[k] = join_f("%s_%s_%s" % (self._id, db_comm[0], k.strip("-")))
@@ -422,7 +422,7 @@ def add_results(self, results):
422422
conn_handler = SQLConnectionHandler()
423423
self._lock_job(conn_handler)
424424
# convert all file type text to file type ids
425-
res_ids = [(fp, convert_to_id(fptype, "filepath_type", conn_handler))
425+
res_ids = [(fp, convert_to_id(fptype, "filepath_type"))
426426
for fp, fptype in results]
427427
file_ids = insert_filepaths(res_ids, self._id, self._table,
428428
"filepath", conn_handler, move_files=False)
@@ -485,7 +485,7 @@ def get_commands_by_datatype(cls, datatypes=None):
485485
conn_handler = SQLConnectionHandler()
486486
# get the ids of the datatypes to get commands for
487487
if datatypes is not None:
488-
datatype_info = [(convert_to_id(dt, "data_type", conn_handler), dt)
488+
datatype_info = [(convert_to_id(dt, "data_type"), dt)
489489
for dt in datatypes]
490490
else:
491491
datatype_info = conn_handler.execute_fetchall(

qiita_db/metadata_template/base_metadata_template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _get_categories(self, conn_handler):
195195
The set of all available metadata categories
196196
"""
197197
# Get all the columns
198-
cols = get_table_cols(self._dynamic_table, conn_handler)
198+
cols = get_table_cols(self._dynamic_table)
199199
# Remove the sample_id column as this column is used internally for
200200
# data storage and it doesn't actually belong to the metadata
201201
cols.remove('sample_id')
@@ -489,7 +489,7 @@ class MetadataTemplate(QiitaObject):
489489
_id_column = None
490490
_sample_cls = None
491491

492-
def _check_id(self, id_, conn_handler=None):
492+
def _check_id(self, id_):
493493
r"""Checks that the MetadataTemplate id_ exists on the database"""
494494
self._check_subclass()
495495

@@ -1013,7 +1013,7 @@ def to_dataframe(self):
10131013
The metadata in the template,indexed on sample id
10141014
"""
10151015
conn_handler = SQLConnectionHandler()
1016-
cols = sorted(get_table_cols(self._table_name(self._id), conn_handler))
1016+
cols = sorted(get_table_cols(self._table_name(self._id)))
10171017
# Get all metadata for the template
10181018
sql = "SELECT {0} FROM qiita.{1}".format(", ".join(cols),
10191019
self._table_name(self.id))
@@ -1071,7 +1071,7 @@ def get_filepaths(self, conn_handler=None):
10711071
info={self.__class__.__name__: self.id})
10721072
raise e
10731073

1074-
_, fb = get_mountpoint('templates', conn_handler)[0]
1074+
_, fb = get_mountpoint('templates')[0]
10751075
base_fp = partial(join, fb)
10761076

10771077
return [(fpid, base_fp(fp)) for fpid, fp in filepath_ids]

qiita_db/metadata_template/prep_template.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ def create(cls, md_template, raw_data, study, data_type,
117117
# Check if the data_type is the id or the string
118118
if isinstance(data_type, (int, long)):
119119
data_type_id = data_type
120-
data_type_str = convert_from_id(data_type, "data_type",
121-
conn_handler)
120+
data_type_str = convert_from_id(data_type, "data_type")
122121
else:
123-
data_type_id = convert_to_id(data_type, "data_type", conn_handler)
122+
data_type_id = convert_to_id(data_type, "data_type")
124123
data_type_str = data_type
125124

126125
pt_cols = PREP_TEMPLATE_COLUMNS

qiita_db/parameters.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,13 @@ def values(self):
116116
del result['param_set_name']
117117
return result
118118

119-
def _check_id(self, id_, conn_handler=None):
119+
def _check_id(self, id_):
120120
r"""Check that the provided ID actually exists in the database
121121
122122
Parameters
123123
----------
124124
id_ : object
125125
The ID to test
126-
conn_handler : SQLConnectionHandler
127-
The connection handler object connected to the DB
128126
129127
Notes
130128
-----

qiita_db/reference.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,21 @@ def create(cls, name, version, seqs_fp, tax_fp=None, tree_fp=None):
7070
conn_handler = SQLConnectionHandler()
7171

7272
seq_id = insert_filepaths([(seqs_fp, convert_to_id("reference_seqs",
73-
"filepath_type",
74-
conn_handler))],
73+
"filepath_type"))],
7574
"%s_%s" % (name, version), "reference",
7675
"filepath", conn_handler)[0]
7776

7877
# Check if the database has taxonomy file
7978
tax_id = None
8079
if tax_fp:
81-
fps = [(tax_fp, convert_to_id("reference_tax", "filepath_type",
82-
conn_handler))]
80+
fps = [(tax_fp, convert_to_id("reference_tax", "filepath_type"))]
8381
tax_id = insert_filepaths(fps, "%s_%s" % (name, version),
8482
"reference", "filepath", conn_handler)[0]
8583

8684
# Check if the database has tree file
8785
tree_id = None
8886
if tree_fp:
89-
fps = [(tree_fp, convert_to_id("reference_tree", "filepath_type",
90-
conn_handler))]
87+
fps = [(tree_fp, convert_to_id("reference_tree", "filepath_type"))]
9188
tree_id = insert_filepaths(fps, "%s_%s" % (name, version),
9289
"reference", "filepath",
9390
conn_handler)[0]
@@ -129,15 +126,15 @@ def name(self):
129126
return conn_handler.execute_fetchone(
130127
"SELECT reference_name FROM qiita.{0} WHERE "
131128
"reference_id = %s".format(self._table), (self._id,))[0]
132-
_, basefp = get_mountpoint('reference', conn_handler=conn_handler)[0]
129+
_, basefp = get_mountpoint('reference')[0]
133130

134131
@property
135132
def version(self):
136133
conn_handler = SQLConnectionHandler()
137134
return conn_handler.execute_fetchone(
138135
"SELECT reference_version FROM qiita.{0} WHERE "
139136
"reference_id = %s".format(self._table), (self._id,))[0]
140-
_, basefp = get_mountpoint('reference', conn_handler=conn_handler)[0]
137+
_, basefp = get_mountpoint('reference')[0]
141138

142139
@property
143140
def sequence_fp(self):
@@ -146,7 +143,7 @@ def sequence_fp(self):
146143
"SELECT f.filepath FROM qiita.filepath f JOIN qiita.{0} r ON "
147144
"r.sequence_filepath=f.filepath_id WHERE "
148145
"r.reference_id=%s".format(self._table), (self._id,))[0]
149-
_, basefp = get_mountpoint('reference', conn_handler=conn_handler)[0]
146+
_, basefp = get_mountpoint('reference')[0]
150147
return join(basefp, rel_path)
151148

152149
@property
@@ -156,7 +153,7 @@ def taxonomy_fp(self):
156153
"SELECT f.filepath FROM qiita.filepath f JOIN qiita.{0} r ON "
157154
"r.taxonomy_filepath=f.filepath_id WHERE "
158155
"r.reference_id=%s".format(self._table), (self._id,))[0]
159-
_, basefp = get_mountpoint('reference', conn_handler=conn_handler)[0]
156+
_, basefp = get_mountpoint('reference')[0]
160157
return join(basefp, rel_path)
161158

162159
@property
@@ -166,5 +163,5 @@ def tree_fp(self):
166163
"SELECT f.filepath FROM qiita.filepath f JOIN qiita.{0} r ON "
167164
"r.tree_filepath=f.filepath_id WHERE "
168165
"r.reference_id=%s".format(self._table), (self._id,))[0]
169-
_, basefp = get_mountpoint('reference', conn_handler=conn_handler)[0]
166+
_, basefp = get_mountpoint('reference')[0]
170167
return join(basefp, rel_path)

qiita_db/study.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ def environmental_packages(self, values):
707707
raise TypeError('Environmental packages should be a list')
708708

709709
# Get all the environmental packages
710-
env_pkgs = [pkg[0] for pkg in get_environmental_packages(
711-
conn_handler=conn_handler)]
710+
env_pkgs = [pkg[0] for pkg in get_environmental_packages()]
712711

713712
# Check that all the passed values are valid environmental packages
714713
missing = set(values).difference(env_pkgs)

qiita_db/support_files/patches/python_patches/15.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# retrieve relative filepaths as dictionary for matching
1616
mountpoints = {m[1].rstrip('/\\'): m[0] for m in get_mountpoint(
17-
'analysis', conn_handler=conn_handler, retrieve_all=True)}
17+
'analysis', retrieve_all=True)}
1818

1919
for filepath in filepaths:
2020
filename = basename(filepath['filepath'])

0 commit comments

Comments
 (0)