diff --git a/ptmd/database/queries/chemicals.py b/ptmd/database/queries/chemicals.py index 722c6bc..1770047 100644 --- a/ptmd/database/queries/chemicals.py +++ b/ptmd/database/queries/chemicals.py @@ -36,7 +36,7 @@ def create_chemicals(chemicals: list[dict]) -> dict[str, Chemical]: """ LOGGER.info('Creating Chemicals') chemicals_in_database = {} - water: Chemical = Chemical(common_name='Water', ptx_code=997, cas='7732-18-5', formula='H2O') + water: Chemical = Chemical(common_name='Water', ptx_code=000, cas='7732-18-5', formula='H2O') dmso: Chemical = Chemical(common_name='DMSO', ptx_code=998, cas='67-68-5', formula='C2H6OS') session.add_all([water, dmso]) session.commit() diff --git a/ptmd/lib/creator/dataframes.py b/ptmd/lib/creator/dataframes.py index 48f0cde..5c32767 100644 --- a/ptmd/lib/creator/dataframes.py +++ b/ptmd/lib/creator/dataframes.py @@ -79,7 +79,7 @@ def build_sample_dataframe(harvester: Any, chemicals_mapping: dict[str, str], or timepoint_key = f'TP{tp}' timepoint = TIME_POINT_MAPPING[timepoint_key] if timepoint_key in TIME_POINT_MAPPING else 'X' timepoint_value = harvester.timepoints[tp - 1] - control_code = '999' if harvester.vehicle == 'DMSO' else '997' + control_code = '999' if harvester.vehicle == 'DMSO' else '000' for replicate in range(1, harvester.replicates4control + 1): hash_id = '%s%s%sZ%s%s' % (organism_code, harvester.exposure_batch, control_code, timepoint, replicate) series = Series([hash_id, BASE_IDENTIFIER + control_code, *EMPTY_FIELDS_VALUES, diff --git a/ptmd/lib/validator/core.py b/ptmd/lib/validator/core.py index e5d7050..37ec967 100644 --- a/ptmd/lib/validator/core.py +++ b/ptmd/lib/validator/core.py @@ -214,7 +214,7 @@ def add_node(self, node: dict) -> None: else: self.collection_order.append(collection_order) - if replicate > self.replicates: + if compound_name not in self.controls_keys and replicate > self.replicates: message = f"Replicate {replicate} is greater than the number of replicates {self.replicates}." self.validator.add_error(label, message, 'replicate') @@ -232,6 +232,9 @@ def add_node(self, node: dict) -> None: if dose != 0: message = "Controls must have a dose of 0." self.validator.add_error(label, message, 'dose_code') + if replicate > self.controls: + message = f"Control {replicate} is greater than the number of controls {self.controls}." + self.validator.add_error(label, message, 'replicate') if compound_name not in self.compounds: self.compounds[compound_name] = { diff --git a/ptmd/lib/validator/validate_identifier.py b/ptmd/lib/validator/validate_identifier.py index 29bcb64..f27ece5 100644 --- a/ptmd/lib/validator/validate_identifier.py +++ b/ptmd/lib/validator/validate_identifier.py @@ -164,9 +164,9 @@ def validate_controls_compound(validator: Any, compound_name: str, code: int) -> validator.add_error(validator.current_record['label'], f"The identifier compound should be 999 but got {code}.", PTX_ID_LABEL) - elif 'WATER' in compound_name and code != 997: + elif 'WATER' in compound_name and code != 000: validator.add_error(validator.current_record['label'], - f"The identifier compound should be 997 but got {code}.", + f"The identifier compound should be 000 but got {code}.", PTX_ID_LABEL) diff --git a/tests/test_lib/test_validator/test_core.py b/tests/test_lib/test_validator/test_core.py index 70d447a..2944d9c 100644 --- a/tests/test_lib/test_validator/test_core.py +++ b/tests/test_lib/test_validator/test_core.py @@ -230,6 +230,21 @@ def test_validate_replicate_too_many(self): self.assertEqual(validator.report['errors'][self.organism][0]['message'], "Replicate 1 has too many timepoints.") + def test_validate_controls_too_many(self): + validator = MockValidator() + extra_node: dict = {**self.default_node} + self.general_information['control'] = 8 + extra_node['data']['replicate'] = 12 + extra_node['data']['compound_name'] = "CONTROL (DMSO)" + extra_node['data']['dose_code'] = 0 + graph = VerticalValidator(self.general_information, validator) + graph.add_node(self.default_node) + graph.add_node(extra_node) + graph.validate() + self.assertFalse(validator.report['valid']) + self.assertEqual(validator.report['errors']['CP1'][0]['message'], + "Control 12 is greater than the number of controls 8.") + def test_validate_controls_dose_not_zero(self): validator = MockValidator() self.general_information['control'] = 1 diff --git a/tests/test_lib/test_validator/test_validate_identifier.py b/tests/test_lib/test_validator/test_validate_identifier.py index e2ad169..08d6533 100644 --- a/tests/test_lib/test_validator/test_validate_identifier.py +++ b/tests/test_lib/test_validator/test_validate_identifier.py @@ -181,7 +181,7 @@ def test_validate_compound_controls(self, mock_chemical): validate_compound(validator) self.assertFalse(validator.report['valid']) self.assertEqual(validator.report['errors']['test'][0]['message'], - "The identifier compound should be 997 but got 2.") + "The identifier compound should be 000 but got 2.") def test_validate_compound_blanks(self): validator = ExcelValidatorMock()