Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoffmann committed Jan 30, 2025
2 parents 5eb36b2 + a6bebdb commit 124245b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
6 changes: 3 additions & 3 deletions api/src/main/resources/mzTab_m_openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ components:
SMH SML_ID … adduct_ions …
SML 1 … [M+H]1+ | [M+Na]1+ …
default: []
pattern: ^\[\d*M([+-][\w]*)\]\d*[+-]$
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
items:
type: string
reliability:
Expand Down Expand Up @@ -1292,7 +1292,7 @@ components:
SFH SMF_ID … adduct_ion …
SMF 1 … [M+H]+ …
SMF 2 … [M+2Na]2+ …
pattern: ^\[\d*M([+-][\w]*)\]\d*[+-]$
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
isotopomer:
$ref: "#/components/schemas/Parameter"
exp_mass_to_charge:
Expand Down Expand Up @@ -1547,7 +1547,7 @@ components:
OR (for negative mode):
SME 1 … [M-H]- …
SME 2 … [M+Cl]- …
pattern: ^\[\d*M([-][\w]*)\]\d*[+-]$
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
exp_mass_to_charge:
type: number
description: The experimental mass/charge value for the precursor ion. If
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/resources/mzTab_m_swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ definitions:
SMH SML_ID … adduct_ions …
SML 1 … [M+H]1+ | [M+Na]1+ …
default: []
pattern: '^\[\d*M([+-][\w]*)\]\d*[+-]$'
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
items:
type: string
reliability:
Expand Down Expand Up @@ -1022,7 +1022,7 @@ definitions:
SFH SMF_ID … adduct_ion …
SMF 1 … [M+H]+ …
SMF 2 … [M+2Na]2+ …
pattern: '^\[\d*M([+-][\w]*)\]\d*[+-]$'
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
isotopomer:
$ref: '#/definitions/Parameter'
description: If de-isotoping has not been performed, then the isotopomer quantified MUST be reported here e.g. “+1”, “+2”, “13C peak” using CV terms, otherwise (i.e. for approaches where SMF rows are de-isotoped features) this MUST be null.
Expand Down Expand Up @@ -1211,7 +1211,7 @@ definitions:
OR (for negative mode):
SME 1 … [M-H]- …
SME 2 … [M+Cl]- …
pattern: '^\[\d*M([+-][\w]*)\]\d*[+-]$'
pattern: '^\[\d*M([+-][\w\d]+)*\]\d*[+-]$'
exp_mass_to_charge:
type: number
description: The experimental mass/charge value for the precursor ion. If multiple adduct forms have been combined into a single identification event/search, then a single value e.g. for the protonated form SHOULD be reported here.
Expand Down
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 124245b

Please sign in to comment.