From afd74afaa817d91c3a8204a94eab4111aff0f639 Mon Sep 17 00:00:00 2001 From: Nils Hoffmann <3309580+nilshoffmann@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:03:26 +0200 Subject: [PATCH] Updated Metadata Assay name and Study name validation. --- .../mztab2/io/validators/AssayValidator.java | 7 ++++++- .../io/validators/StudyVariableValidator.java | 9 +++++---- .../mztab2/io/validators/AssayValidatorTest.java | 14 ++++++++++++++ .../io/validators/StudyVariableValidatorTest.java | 8 ++++---- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/io/src/main/java/org/lifstools/mztab2/io/validators/AssayValidator.java b/io/src/main/java/org/lifstools/mztab2/io/validators/AssayValidator.java index 9e10adc2..726fa1a0 100644 --- a/io/src/main/java/org/lifstools/mztab2/io/validators/AssayValidator.java +++ b/io/src/main/java/org/lifstools/mztab2/io/validators/AssayValidator.java @@ -25,7 +25,7 @@ import uk.ac.ebi.pride.jmztab2.utils.parser.MZTabParserContext; /** - * Validates that the quantification method section is present in metadata. + * Validates that the assay section is present in metadata. * * @author nilshoffmann */ @@ -42,6 +42,11 @@ public List validateRefine(Metadata metadata, MZTabParserContext par } for (Integer id : assayMap.keySet()) { + if (assayMap.get(id).getName() == null || assayMap.get(id).getName().isBlank()) { + errorList.add(new MZTabError( + LogicalErrorType.NotDefineInMetadata, -1, + Metadata.Properties.assay + "[" + id + "]" + "\t<" + Assay.Properties.name + ">")); + } if (assayMap.get(id). getMsRunRef() == null || assayMap.get(id). getMsRunRef().isEmpty()) { diff --git a/io/src/main/java/org/lifstools/mztab2/io/validators/StudyVariableValidator.java b/io/src/main/java/org/lifstools/mztab2/io/validators/StudyVariableValidator.java index 56dd5e54..e639b0e0 100644 --- a/io/src/main/java/org/lifstools/mztab2/io/validators/StudyVariableValidator.java +++ b/io/src/main/java/org/lifstools/mztab2/io/validators/StudyVariableValidator.java @@ -55,18 +55,19 @@ public List validateRefine(Metadata metadata, MZTabParserContext par if (sv == null) { errorList.add(new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + id + "]" + "\t" + "")); + Metadata.Properties.studyVariable + "[" + id + "]" + "\t<" + StudyVariable.Properties.name + ">")); } else { if (sv.getName() == null) { errorList.add(new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + id + "]" + "\t" + "")); + Metadata.Properties.studyVariable + "[" + id + "]" + "\t<" + StudyVariable.Properties.name + ">")); } else { if (sv.getName().equals("undefined")) { if (undefinedDefined) { errorList.add(new MZTabError( LogicalErrorType.UndefinedStudyVariableNameOnceOnly, -1, - Metadata.Properties.studyVariable + "[" + id + "]" + "\t" + "")); + Metadata.Properties.studyVariable + "[" + id + "]" + "\t<" + StudyVariable.Properties.name + + ">")); } else { undefinedDefined = true; } @@ -76,7 +77,7 @@ public List validateRefine(Metadata metadata, MZTabParserContext par getDescription() == null) { errorList.add(new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + id + "]-" + StudyVariable.Properties.description + "\t" + "")); + Metadata.Properties.studyVariable + "[" + id + "]-" + StudyVariable.Properties.description)); } if (sv. getAssayRefs() == null || sv.getAssayRefs(). diff --git a/io/src/test/java/org/lifstools/mztab2/io/validators/AssayValidatorTest.java b/io/src/test/java/org/lifstools/mztab2/io/validators/AssayValidatorTest.java index f2a0dc7f..832e429e 100644 --- a/io/src/test/java/org/lifstools/mztab2/io/validators/AssayValidatorTest.java +++ b/io/src/test/java/org/lifstools/mztab2/io/validators/AssayValidatorTest.java @@ -47,6 +47,20 @@ public void testValidateRefineNullAssay() { assertEquals(expResult.size(), result.size()); assertEquals(expResult.get(0).toString(), result.get(0).toString()); } + + @Test + public void testValidateMissingName() { + Metadata metadata = new Metadata(); + metadata.addAssayItem(new Assay().id(1)); + MZTabParserContext parserContext = new MZTabParserContext(); + AssayValidator instance = new AssayValidator(); + List expResult = Arrays.asList(new MZTabError( + LogicalErrorType.NotDefineInMetadata, -1, + Metadata.Properties.assay + "")); + List result = instance.validateRefine(metadata, parserContext); + assertEquals(expResult.size(), result.size()); + assertEquals(expResult.get(0).toString(), result.get(0).toString()); + } /** * Test of validateRefine method for assay requiring a linked ms run, of diff --git a/io/src/test/java/org/lifstools/mztab2/io/validators/StudyVariableValidatorTest.java b/io/src/test/java/org/lifstools/mztab2/io/validators/StudyVariableValidatorTest.java index 461acf52..f693948c 100644 --- a/io/src/test/java/org/lifstools/mztab2/io/validators/StudyVariableValidatorTest.java +++ b/io/src/test/java/org/lifstools/mztab2/io/validators/StudyVariableValidatorTest.java @@ -95,13 +95,13 @@ public void testTwoStudyVariableMultipleAssaysMissingNamesAndMissingDescription( List expResult = Arrays.asList( new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + 1 + "]" + "\t" + ""), + Metadata.Properties.studyVariable + "[" + 1 + "]" + "\t<" + StudyVariable.Properties.name+">"), new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t" + ""), + Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t<" + StudyVariable.Properties.name+">"), new MZTabError( LogicalErrorType.NotDefineInMetadata, -1, - Metadata.Properties.studyVariable + "[" + 2 + "]-" + StudyVariable.Properties.description + "\t" + "") + Metadata.Properties.studyVariable + "[" + 2 + "]-" + StudyVariable.Properties.description) ); List result = instance.validateRefine(metadata, parserContext); assertEquals(expResult.size(), result.size()); @@ -134,7 +134,7 @@ public void testTwoStudyVariableMultipleAssaysMultipleUndefinedStudyVariables() List expResult = Arrays.asList( new MZTabError( LogicalErrorType.UndefinedStudyVariableNameOnceOnly, -1, - Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t" + "") + Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t<" + StudyVariable.Properties.name+">") ); List result = instance.validateRefine(metadata, parserContext); assertEquals(expResult.size(), result.size());