Permalink
Browse files

bugfix - if a keycol was blank, you'd get an error - now append blank…

…s to all rows, if they are missing values
  • Loading branch information...
1 parent 23a253d commit 0014cde119c02dd229f9b723d56255eaaca9385f @mbreese committed Mar 7, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 tab_utils/tab_merge.py
View
@@ -12,6 +12,7 @@ class MergeException(Exception):
def merge_files(fnames,common_cols,uncommon_cols, keycols, noheader=False,collate=True,headercomment=False,keydesc=False):
names = filenames_to_uniq([os.path.basename(x) for x in fnames])
files = []
+ file_col_count = 0
for fname in fnames:
files.append(open(fname))
@@ -126,6 +127,9 @@ def merge_files(fnames,common_cols,uncommon_cols, keycols, noheader=False,collat
cols = line.rstrip().split('\t')
if not cols:
values.append(['',] * num_of_columns)
+
+ while len(cols) < file_col_count:
+ cols.append('')
values.append(cols)
@@ -156,6 +160,8 @@ def merge_files(fnames,common_cols,uncommon_cols, keycols, noheader=False,collat
# first line is header
if headers:
headers = False
+ if not file_col_count:
+ file_col_count = len(values[0])
if not collate:
for j in uncommon_cols:
for name in names:

0 comments on commit 0014cde

Please sign in to comment.