Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed missing required properties to error #532

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions isatools/isatab/validate/rules/rules_40xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ def check_investigation_against_config(i_df, configs):
code = 4003
message = "A required property is missing"

def add_warning(index, column, value_index):
def add_error(index, column, value_index):
if index > 0:
spl = "A property value in {}.{} of investigation file at column {} is required"
spl = spl.format(column, index + 1, value_index + 1)
validator.add_warning(message=message, supplemental=spl, code=code)
log.warning("(W) {}".format(spl))
else:
spl = "A property value in {} of investigation file at column {} is required"
spl = spl.format(column, value_index + 1)
validator.add_warning(message=message, supplemental=spl, code=code)
log.warning("(W) {}".format(spl))
validator.add_error(message=message, supplemental=spl, code=code)
log.error("(E) {}".format(spl))

def check_section_against_required_fields_one_value(section, required, i=0):
fields_required = [i for i in section.columns if i in required]
Expand All @@ -45,10 +43,10 @@ def check_section_against_required_fields_one_value(section, required, i=0):
required_value = required_values.iloc[x]
if isinstance(required_value, float):
if isnan(required_value):
add_warning(i, col, x)
add_error(i, col, x)
else:
if required_value == '' or 'Unnamed: ' in required_value:
add_warning(i, col, x)
add_error(i, col, x)

config_fields = configs[('[investigation]', '')].get_isatab_configuration()[0].get_field()
required_fields = [i.header for i in config_fields if i.is_required]
Expand Down
4 changes: 2 additions & 2 deletions isatools/resources/config/xml/investigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<default-value><![CDATA[]]></default-value>
</field>
<field header="Investigation Person Mid Initials" data-type="String" is-file-field="false"
is-multiple-value="false" is-required="true" is-hidden="false"
is-multiple-value="false" is-required="false" is-hidden="false"
is-forced-ontology="false" section="INVESTIGATION CONTACTS">
<description><![CDATA[The mid initial of the contact.]]></description>
<default-value><![CDATA[]]></default-value>
Expand Down Expand Up @@ -231,7 +231,7 @@
<default-value><![CDATA[]]></default-value>
</field>
<field header="Study Person Mid Initials" data-type="String" is-file-field="false"
is-multiple-value="false" is-required="true" is-hidden="false"
is-multiple-value="false" is-required="false" is-hidden="false"
is-forced-ontology="false" section="STUDY CONTACTS">
<description><![CDATA[The mid initial of the contact.]]></description>
<default-value><![CDATA[]]></default-value>
Expand Down
6 changes: 3 additions & 3 deletions tests/convert/test_mzml2isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_mzml2isa_convert_investigation(self):
report = mzml2isa.convert(os.path.join(self._mzml_data_dir, study_id + '-partial'), self._tmp_dir, study_id,
validate_output=True)
self.assertTrue(report['validation_finished'])
self.assertEqual(len(report['errors']), 0)
self.assertEqual(len(report['errors']), 4)
# Strip out the line with Comment[Created With Tool] to avoid changes in version number generated by mzml2isa
with open(os.path.join(self._tmp_dir, 'i_Investigation.txt')) as in_fp, StringIO() as stripped_actual_file:
stripped_actual_file.name = 'i_Investigation.txt'
Expand All @@ -42,7 +42,7 @@ def test_mzml2isa_convert_study_table(self):
report = mzml2isa.convert(os.path.join(self._mzml_data_dir, study_id + '-partial'), self._tmp_dir, study_id,
validate_output=True)
self.assertTrue(report['validation_finished'])
self.assertEqual(len(report['errors']), 0)
self.assertEqual(len(report['errors']), 4)
with open(os.path.join(self._tmp_dir, 's_{}.txt'.format(study_id))) as out_fp:
with open(os.path.join(self._tab_data_dir, study_id + '-partial', 's_{}.txt'.format(study_id))) as reference_fp:
self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
Expand All @@ -52,7 +52,7 @@ def test_mzml2isa_convert_assay_table(self):
report = mzml2isa.convert(os.path.join(self._mzml_data_dir, study_id + '-partial'), self._tmp_dir, study_id,
validate_output=True)
self.assertTrue(report['validation_finished'])
self.assertEqual(len(report['errors']), 0)
self.assertEqual(len(report['errors']), 4)
with open(os.path.join(self._tmp_dir, 'a_{}_metabolite_profiling_mass_spectrometry.txt'.format(study_id))) as out_fp:
with open(os.path.join(self._tab_data_dir, study_id + '-partial', 'a_{}_metabolite_profiling_mass_spectrometry.txt'.format(study_id))) as reference_fp:
self.assertTrue(assert_tab_content_equal(out_fp, reference_fp))
10 changes: 5 additions & 5 deletions tests/isatab/validate/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_b_ii_s_3(self):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'tab', 'BII-S-3')
with open(path.join(data_path, 'i_gilbert.txt'), 'r') as data_file:
r = validate(fp=data_file, config_dir=self.default_conf, origin="")
self.assertEqual(len(r['warnings']), 12)
self.assertEqual(len(r['warnings']), 4)

def test_mtbls267(self):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'tab', 'MTBLS267-partial')
Expand All @@ -30,19 +30,19 @@ def test_mtbls_1846(self):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'mtbls', 'MTBLS1846')
with open(path.join(data_path, 'i_Investigation.txt'), 'r') as data_file:
r = validate(fp=data_file, config_dir=self.default_conf)
self.assertEqual(len(r['errors']), 10)
self.assertEqual(len(r['errors']), 23)

def test_bii_i_1(self):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'tab', 'BII-I-1')
with open(path.join(data_path, 'i_investigation.txt'), 'r') as data_file:
report = validate(fp=data_file, config_dir=self.default_conf)
self.assertEqual(len(report['warnings']), 40)
self.assertEqual(len(report['warnings']), 38)

def test_bii_s_7(self):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'tab', 'BII-S-7')
with open(path.join(data_path, 'i_matteo.txt'), 'r') as data_file:
report = validate(fp=data_file, config_dir=self.default_conf)
self.assertEqual(len(report['warnings']), 14)
self.assertEqual(len(report['warnings']), 1)

def test_print_rule(self):
raw_rule = INVESTIGATION_RULES_MAPPING[0]
Expand Down Expand Up @@ -82,7 +82,7 @@ def is_investigation(investigation_df):
data_path = path.join(path.dirname(path.abspath(__file__)), '..', '..', 'data', 'tab', 'BII-S-3')
with open(path.join(data_path, 'i_gilbert.txt'), 'r') as data_file:
r = validate(data_file, rules=rules)
self.assertEqual(len(r['warnings']), 12)
self.assertEqual(len(r['warnings']), 4)

rule = '12000'
expected_error = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_clients/test_mw2isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_conversion_ms(self):
with open(os.path.join(self._tmp_dir, study_id, 'i_investigation.txt')) as fp:
report = isatab.validate(fp)
for error in report['errors']:
self.assertEqual(error['code'], 4014)
self.assertIn(error['code'], [4014, 4003])
else:
self.fail("conversion failed, validation was not invoked")

Expand Down
Loading
Loading