Skip to content

Commit

Permalink
Dom debug (#125)
Browse files Browse the repository at this point in the history
* fixed #117

* fixed #119

* fixed #122

* Fixed #123

* fixed #120
  • Loading branch information
terazus authored Nov 27, 2023
1 parent 1bdc60b commit 2e42e8c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ptmd/database/queries/chemicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ptmd/lib/creator/dataframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion ptmd/lib/validator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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] = {
Expand Down
4 changes: 2 additions & 2 deletions ptmd/lib/validator/validate_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
15 changes: 15 additions & 0 deletions tests/test_lib/test_validator/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lib/test_validator/test_validate_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2e42e8c

Please sign in to comment.