Provide optional value to date_submitted field
This was causing a local build to error out because by supplemental metadata did not have submission date as an available field., resulting in:
KeyError: 'date_submitted'
Providing a default value fixes this key error
@@ -132,7 +132,7 @@ if __name__ == '__main__':
with open(args.output_flagged, 'w') as flag:
flag.write(f'strain\tcollection_date\tsubmission_date\tflagging_reason\n')
for s, msg, reasons, meta in sorted(flagged_sequences, key=lambda x:x[3].get('date_submitted', 'XX'), reverse=True):
- flag.write(f"{s}\t{metadata[s]['date'] if s in metadata else 'XXXX-XX-XX'}\t{metadata[s]['date_submitted'] if s in metadata else 'XXXX-XX-XX'}\t{msg}\n")
+ flag.write(f"{s}\t{metadata[s]['date'] if s in metadata else 'XXXX-XX-XX'}\t{metadata[s].get('date_submitted', 'XXXX-XX-XX') if s in metadata else 'XXXX-XX-XX'}\t{msg}\n")
to_exclude_by_reason[reasons].append(s)
# write out file with sequences flagged for exclusion sorted by date
@@ -140,4 +140,3 @@ if __name__ == '__main__':
for reason in to_exclude_by_reason:
excl.write(f'\n# {"&".join(reason)}\n')
excl.write('\n'.join(to_exclude_by_reason[reason])+'\n')
-
