Skip to content

Commit e006e20

Browse files
committed
fix errors
1 parent 2e36141 commit e006e20

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

qiita_db/metadata_template/test/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ def test_get_pgsql_reserved_words(self):
780780
'PC.607': 'Fast'},
781781
'DOB': {'PC.354': '20061218',
782782
'PC.607': '20071112'},
783-
'description': {'PC.354': 'Control_mouse_I.D._354',
783+
'Description': {'PC.354': 'Control_mouse_I.D._354',
784784
'PC.607': 'Fasting_mouse_I.D._607'}
785785
}
786786

qiita_db/metadata_template/util.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,6 @@ def load_template_to_dataframe(fn, index='sample_name'):
107107
if not holdfile:
108108
raise ValueError('Empty file passed!')
109109

110-
# Strip all values in the cells in the input file
111-
for pos, line in enumerate(holdfile):
112-
cols = line.split('\t')
113-
if pos == 0:
114-
# get and clean the controlled columns
115-
ccols = {'sample_name'}
116-
ccols.update(qdb.metadata_template.constants.CONTROLLED_COLS)
117-
newcols = [
118-
c.lower().strip() if c.lower().strip() in ccols else c.strip()
119-
for c in cols]
120-
121-
# while we are here, let's check for duplicate columns headers
122-
if len(set(newcols)) != len(newcols):
123-
raise qdb.exceptions.QiitaDBDuplicateHeaderError(
124-
find_duplicates(newcols))
125-
else:
126-
# .strip will remove odd chars, newlines, tabs and multiple spaces
127-
# but we need to read a new line at the end of the line (+ '\n')
128-
newcols = [d.strip(" \r\x0b\x0c\n") for d in cols]
129-
130-
holdfile[pos] = '\t'.join(newcols) + '\n'
131-
132110
if index == "#SampleID":
133111
# We're going to parse a QIIME mapping file. We are going to first
134112
# parse it with the QIIME function so we can remove the comments
@@ -138,6 +116,30 @@ def load_template_to_dataframe(fn, index='sample_name'):
138116
holdfile.insert(0, "%s\n" % '\t'.join(headers))
139117
# The QIIME parser fixes the index and removes the #
140118
index = 'SampleID'
119+
else:
120+
# Strip all values in the cells in the input file
121+
for pos, line in enumerate(holdfile):
122+
cols = line.split('\t')
123+
if pos == 0:
124+
# get and clean the controlled columns
125+
ccols = {'sample_name'}
126+
ccols.update(qdb.metadata_template.constants.CONTROLLED_COLS)
127+
newcols = [
128+
c.lower().strip() if c.lower().strip() in ccols
129+
else c.strip()
130+
for c in cols]
131+
132+
# while we are here, let's check for duplicate columns headers
133+
if len(set(newcols)) != len(newcols):
134+
raise qdb.exceptions.QiitaDBDuplicateHeaderError(
135+
find_duplicates(newcols))
136+
else:
137+
# .strip will remove odd chars, newlines, tabs and multiple
138+
# spaces but we need to read a new line at the end of the
139+
# line (+ '\n')
140+
newcols = [d.strip(" \r\x0b\x0c\n") for d in cols]
141+
142+
holdfile[pos] = '\t'.join(newcols) + '\n'
141143

142144
# index_col:
143145
# is set as False, otherwise it is cast as a float and we want a string

0 commit comments

Comments
 (0)