Skip to content

Commit 5c02ee7

Browse files
author
Peter Amstutz
committed
Tweak compare_records to handle inexact but compatible matches.
1 parent de6ce38 commit 5c02ee7

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

cwltool/workflow.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def can_assign_src_to_sink(src, sink): # type: (Any, Any) -> bool
110110
return src == sink
111111
return False
112112

113-
def _compare_records(rec1, rec2):
113+
def _compare_records(src, sink):
114114
"""Compare two records, ensuring they have compatible fields.
115115
116116
This handles normalizing record names, which will be relative to workflow
@@ -119,16 +119,17 @@ def _compare_records(rec1, rec2):
119119
def _rec_fields(rec):
120120
out = {}
121121
for field in rec["fields"]:
122-
name = field["name"].replace(rec["name"], "")
122+
name = shortname(field["name"])
123123
out[name] = field["type"]
124124
return out
125-
fields1 = _rec_fields(rec1)
126-
fields2 = _rec_fields(rec2)
127-
for key in set(fields1.keys() + fields2.keys()):
128-
if fields1.get(key) != fields2.get(key):
125+
126+
srcfields = _rec_fields(src)
127+
sinkfields = _rec_fields(sink)
128+
for key in sinkfields.iterkeys():
129+
if not can_assign_src_to_sink(srcfields.get(key, "null"), sinkfields.get(key, "null")) and sinkfields.get(key) is not None:
129130
_logger.info("Record comparison failure for %s and %s\n"
130131
"Did not match fields for %s: %s and %s" %
131-
(rec1["name"], rec2["name"], key, fields1.get(key), fields2.get(key)))
132+
(src["name"], sink["name"], key, srcfields.get(key), sinkfields.get(key)))
132133
return False
133134
return True
134135

tests/test_examples.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,31 @@ def test_typecompare(self):
169169
{'items': ['int'], 'type': 'array'}))
170170

171171
def test_recordcompare(self):
172-
src = {'fields': [{'type': {'items': 'string', 'type': 'array'}, 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/description'}, {'type': {'items': 'File', 'type': 'array'}, 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/vrn_file'}], 'type': 'record', 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec'}
173-
sink = {'fields': [{'type': {'items': 'string', 'type': 'array'}, 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec/description'}, {'type': {'items': 'File', 'type': 'array'}, 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec/vrn_file'}], 'type': 'record', 'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec'}
174-
self.assertTrue(cwltool.workflow.can_assign_src_to_sink(src, sink))
172+
src = {
173+
'fields': [{
174+
'type': { 'items': 'string', 'type': 'array' },
175+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/description'
176+
},
177+
{
178+
'type': { 'items': 'File', 'type': 'array' },
179+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec/vrn_file'
180+
}],
181+
'type': 'record',
182+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/wf-variantcall.cwl#vc_rec/vc_rec'
183+
}
184+
sink = {
185+
'fields': [{
186+
'type': {'items': 'string', 'type': 'array'},
187+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec/description'
188+
},
189+
{
190+
'type': {'items': 'File', 'type': 'array'},
191+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec/vrn_file'
192+
}],
193+
'type': 'record',
194+
'name': u'file:///home/chapmanb/drive/work/cwl/test_bcbio_cwl/run_info-cwl-workflow/steps/vc_output_record.cwl#vc_rec/vc_rec'}
175195

196+
self.assertTrue(cwltool.workflow.can_assign_src_to_sink(src, sink))
176197

177198

178199
if __name__ == '__main__':

0 commit comments

Comments
 (0)