Skip to content

Commit

Permalink
Handle missing columns in SDS to SFL conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctberthiaume committed Jan 6, 2017
1 parent 22438e5 commit 40f2c34
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion seaflowpy/sds2sfl_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def main(cli_args=None):

f2.write("\t".join(FILE_COLUMNS) + "\n")

missing_fields = dict();

file_duration_field = "180"
for line in f:
file_field = create_file_field(line, header)
Expand Down Expand Up @@ -180,8 +182,17 @@ def main(cli_args=None):
# Write SFL subset of fields in correct order
outfields = []
for col in FILE_COLUMNS:
outfields.append(fields[d[col]])
try:
outfields.append(fields[d[col]])
except KeyError as e:
# If column is missing, just output NA and note for later
outfields.append("NA")
missing_fields[str(e)] = True

f2.write("\t".join(outfields) + "\n")

f.close()
f2.close()

if missing_fields:
print "Some fields were missing from input file: %s" % " ".join(missing_fields.keys())

0 comments on commit 40f2c34

Please sign in to comment.