comparison load_db.py @ 10:dfe38b7c34ed draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/query_tabular commit 67db58361546009a77b2cbd140967fbc634d425b"
author iuc
date Thu, 24 Sep 2020 11:27:11 +0000
parents 4678715f7147
children c4d18aa4ec4a
comparison
equal deleted inserted replaced
9:4678715f7147 10:dfe38b7c34ed
187 col_idx=None, filters=filters) 187 col_idx=None, filters=filters)
188 for linenum, fields in enumerate(tr): 188 for linenum, fields in enumerate(tr):
189 if linenum == 0 and firstlinenames: 189 if linenum == 0 and firstlinenames:
190 col_names = [get_valid_column_name(name) or 'c%d' % (i + 1) 190 col_names = [get_valid_column_name(name) or 'c%d' % (i + 1)
191 for i, name in enumerate(fields)] 191 for i, name in enumerate(fields)]
192 # guarantee col_types in case of empty data
193 while len(col_types) < len(fields):
194 col_types.append(None)
192 continue 195 continue
193 if linenum > max_lines: 196 if linenum > max_lines:
194 break 197 break
195 try: 198 try:
196 while len(col_types) < len(fields): 199 while len(col_types) < len(fields):
208 if not col_type: 211 if not col_type:
209 col_types[i] = 'TEXT' 212 col_types[i] = 'TEXT'
210 if not col_names: 213 if not col_names:
211 col_names = ['c%d' % i for i in range(1, len(col_types) + 1)] 214 col_names = ['c%d' % i for i in range(1, len(col_types) + 1)]
212 if column_names: 215 if column_names:
216 cnames = [cn.strip() for cn in column_names.split(',')]
213 if load_named_columns: 217 if load_named_columns:
214 col_idx = [] 218 col_idx = []
215 cnames = [] 219 colnames = []
216 for i, cname in enumerate( 220 for i, cname in enumerate(cnames):
217 [cn.strip() for cn in column_names.split(',')]): 221 # guarantee col_types in case of empty data
222 if i >= len(col_types):
223 col_types.append('TEXT')
218 if cname != '': 224 if cname != '':
219 col_idx.append(i) 225 col_idx.append(i)
220 cnames.append(cname) 226 colnames.append(cname)
221 col_types = [col_types[i] for i in col_idx] 227 col_types = [col_types[i] for i in col_idx]
222 col_names = cnames 228 col_names = colnames
223 else: 229 else:
224 for i, cname in enumerate( 230 if col_names:
225 [cn.strip() for cn in column_names.split(',')]): 231 for i, cname in enumerate(cnames):
226 if cname and i < len(col_names): 232 if cname and i < len(col_names):
227 col_names[i] = cname 233 col_names[i] = cname
234 else:
235 col_names = [x if x else 'c%d' % (i) for i, x in enumerate(cnames)]
228 col_def = [] 236 col_def = []
229 for i, col_name in enumerate(col_names): 237 for i, col_name in enumerate(col_names):
238 if i >= len(col_types):
239 col_types.append('TEXT')
230 col_def.append('%s %s' % (col_names[i], col_types[i])) 240 col_def.append('%s %s' % (col_names[i], col_types[i]))
231 return col_names, col_types, col_def, col_idx 241 return col_names, col_types, col_def, col_idx
232 242
233 243
234 def create_table(conn, file_path, table_name, skip=0, comment_char='#', 244 def create_table(conn, file_path, table_name, skip=0, comment_char='#',