Skip to content

Commit

Permalink
Merge pull request #87 from lifs-tools/fix-metadata-objects-validation
Browse files Browse the repository at this point in the history
Updated Metadata Assay name and Study name validation.
  • Loading branch information
nilshoffmann authored Jul 26, 2024
2 parents 506d5b3 + afd74af commit a6bebdb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -42,6 +42,11 @@ public List<MZTabError> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ public List<MZTabError> validateRefine(Metadata metadata, MZTabParserContext par
if (sv == null) {
errorList.add(new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.studyVariable + "[" + id + "]" + "\t" + "<NAME>"));
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" + "<NAME>"));
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" + "<NAME>"));
Metadata.Properties.studyVariable + "[" + id + "]" + "\t<" + StudyVariable.Properties.name
+ ">"));
} else {
undefinedDefined = true;
}
Expand All @@ -76,7 +77,7 @@ public List<MZTabError> validateRefine(Metadata metadata, MZTabParserContext par
getDescription() == null) {
errorList.add(new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.studyVariable + "[" + id + "]-" + StudyVariable.Properties.description + "\t" + "<DESCRIPTION>"));
Metadata.Properties.studyVariable + "[" + id + "]-" + StudyVariable.Properties.description));
}
if (sv.
getAssayRefs() == null || sv.getAssayRefs().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MZTabError> expResult = Arrays.asList(new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.assay + ""));
List<MZTabError> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public void testTwoStudyVariableMultipleAssaysMissingNamesAndMissingDescription(
List<MZTabError> expResult = Arrays.asList(
new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.studyVariable + "[" + 1 + "]" + "\t" + "<NAME>"),
Metadata.Properties.studyVariable + "[" + 1 + "]" + "\t<" + StudyVariable.Properties.name+">"),
new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t" + "<NAME>"),
Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t<" + StudyVariable.Properties.name+">"),
new MZTabError(
LogicalErrorType.NotDefineInMetadata, -1,
Metadata.Properties.studyVariable + "[" + 2 + "]-" + StudyVariable.Properties.description + "\t" + "<DESCRIPTION>")
Metadata.Properties.studyVariable + "[" + 2 + "]-" + StudyVariable.Properties.description)
);
List<MZTabError> result = instance.validateRefine(metadata, parserContext);
assertEquals(expResult.size(), result.size());
Expand Down Expand Up @@ -134,7 +134,7 @@ public void testTwoStudyVariableMultipleAssaysMultipleUndefinedStudyVariables()
List<MZTabError> expResult = Arrays.asList(
new MZTabError(
LogicalErrorType.UndefinedStudyVariableNameOnceOnly, -1,
Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t" + "<NAME>")
Metadata.Properties.studyVariable + "[" + 2 + "]" + "\t<" + StudyVariable.Properties.name+">")
);
List<MZTabError> result = instance.validateRefine(metadata, parserContext);
assertEquals(expResult.size(), result.size());
Expand Down

0 comments on commit a6bebdb

Please sign in to comment.