Skip to content

Commit

Permalink
Added lipidomics draft semantic validation file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Hoffmann committed Jan 7, 2020
1 parent 1c738ef commit d91a19e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 66 deletions.
19 changes: 14 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.isas.mztab</groupId>
<artifactId>mztab-validator-webapp</artifactId>
<version>1.0.23</version>
<version>1.0.24</version>
<packaging>jar</packaging>
<description>A web-based validator for mzTab format version 1.0 onwards.</description>
<name>MzTab validator webapplication.</name>
Expand Down Expand Up @@ -45,12 +45,12 @@
<maven.compiler.target>1.8</maven.compiler.target>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<jmztab.version>3.0.4</jmztab.version>
<jmztab.version>3.0.9</jmztab.version>
<jmztabm.version>1.0.4</jmztabm.version>
<application.version.number>${project.version}</application.version.number>
<springfox.version>2.9.2</springfox.version>
<guava.version>27.0.1-jre</guava.version>
<spring.boot.version>2.1.7.RELEASE</spring.boot.version>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
<docker.image.prefix>isas</docker.image.prefix>
<dockerfile.plugin.version>1.4.10</dockerfile.plugin.version>
<lombok.version>1.18.4</lombok.version>
Expand All @@ -62,8 +62,8 @@
<junit.platform.version>1.0.3</junit.platform.version>
<swagger.version>1.5.16</swagger.version>
<jersey.version>2.22.2</jersey.version>
<jackson.version>2.9.9</jackson.version>
<jackson.databind.version>2.9.9.2</jackson.databind.version>
<jackson.version>2.10.1</jackson.version>
<jackson.databind.version>2.10.1</jackson.databind.version>
<jodatime.version>2.9.9</jodatime.version>
<hibernate.validator.version>6.0.7.Final</hibernate.validator.version>
<slf4j.version>1.7.25</slf4j.version>
Expand Down Expand Up @@ -269,6 +269,7 @@
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
Expand Down Expand Up @@ -688,6 +689,14 @@
<name>jcenter</name>
<url>http://jcenter.bintray.com</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-lifs-maven</id>
<name>bintray-lifs</name>
<url>https://dl.bintray.com/lifs/maven</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import de.isas.mztab2.model.MzTab;
import de.isas.mztab2.model.ValidationMessage;
import de.isas.mztab2.validation.CvMappingValidator;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
Expand All @@ -37,15 +36,19 @@
import java.util.logging.Logger;
import javax.xml.bind.JAXBException;
import de.isas.mztab2.io.MzTabFileParser;
import java.io.PrintWriter;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import uk.ac.ebi.pride.jmztab2.model.MZTabConstants;
import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorOverflowException;
import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorList;
import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabErrorType;
import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabException;

/**
*
* @author Nils Hoffmann &lt;[email protected]&gt;
*/
@Slf4j
public class IsasValidator implements WebValidator {

private final CvParameterLookupService lookupService;
Expand All @@ -56,51 +59,49 @@ public IsasValidator(CvParameterLookupService lookupService) {

@Override
public List<ValidationMessage> validate(Path filepath,
String validationLevel, int maxErrors, boolean checkCvMapping, Path validationFile) throws IllegalStateException, IOException {
String validationLevel, int maxErrors, boolean checkCvMapping, Path validationFile) throws IllegalStateException, IOException {
MzTabFileParser parser = null;
List<ValidationMessage> validationResults = new ArrayList<>();
try {
parser = new MzTabFileParser(filepath.toFile());
parser.parse(
System.out, MZTabErrorType.findLevel(validationLevel), maxErrors);
} catch (MZTabErrorOverflowException ex) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, ex);
MZTabErrorList errorList = parser.parse(
System.out, MZTabErrorType.findLevel(validationLevel), maxErrors);
errorList.convertToValidationMessages();
} catch (Exception e) {
log.error("Caught Exception in IsasValidator:", e);
ValidationMessage vm = new ValidationMessage();
vm.setCategory(ValidationMessage.CategoryEnum.CROSS_CHECK);
vm.setCategory(
ValidationMessage.CategoryEnum.FORMAT);
vm.setCode("");
vm.setLineNumber(-1l);
vm.setMessageType(
ValidationMessage.MessageTypeEnum.ERROR);
vm.setMessage(ex.getMessage());
ValidationMessage.MessageTypeEnum.ERROR);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
vm.setMessage(e.getMessage()!=null?e.getMessage():"Caught an Exception while parsing '"+filepath.getFileName()+"'. Please check your file's tabular structure and inspect further validation messages!" + "\n" +sw.toString());
validationResults.add(vm);
} finally {
if (parser != null) {
validationResults.addAll(parser.getErrorList().
convertToValidationMessages());
convertToValidationMessages());
if (checkCvMapping) {
try {
CvMappingValidator cvValidator = CvMappingValidator.of(
// IsasValidator.class.getResource(
// "/static/examples/mzTab-M-mapping.xml"),
validationFile.toFile(),
lookupService, checkCvMapping);
validationResults.addAll(cvValidator.validate(parser.
getMZTabFile()));
} catch (JAXBException ex) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, ex);
throw new IOException(ex);
} catch (IllegalArgumentException iae) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, iae);
validationFile.toFile(),
lookupService, checkCvMapping);
List<ValidationMessage> messages = cvValidator.validate(parser.
getMZTabFile());
validationResults.addAll(Optional.ofNullable(messages).orElse(Collections.emptyList()));
} catch (JAXBException | IllegalArgumentException iae) {
log.error("Caught Exception in IsasValidator, semantic validation:", iae);
ValidationMessage vm = new ValidationMessage();
vm.setCategory(
ValidationMessage.CategoryEnum.CROSS_CHECK);
ValidationMessage.CategoryEnum.FORMAT);
vm.setCode("");
vm.setLineNumber(-1l);
vm.setMessageType(
ValidationMessage.MessageTypeEnum.ERROR);
ValidationMessage.MessageTypeEnum.ERROR);
vm.setMessage(iae.getMessage());
validationResults.add(vm);
}
Expand All @@ -112,39 +113,39 @@ public List<ValidationMessage> validate(Path filepath,

@Override
public Map<String, List<Map<String, String>>> parse(Path filepath,
String validationLevel, int maxErrors) throws IOException {
String validationLevel, int maxErrors) throws IOException {
MzTabFileParser parser = new MzTabFileParser(filepath.toFile());
try {
parser.parse(
System.out, MZTabErrorType.findLevel(validationLevel), maxErrors);
System.out, MZTabErrorType.findLevel(validationLevel), maxErrors);
} finally {
MzTab mzTabFile = parser.getMZTabFile();
if (mzTabFile != null) {
MzTabWriterDefaults writerDefaults = new MzTabWriterDefaults();
CsvMapper mapper = writerDefaults.metadataMapper();
CsvSchema schema = writerDefaults.metaDataSchema(mapper);
if (mzTabFile.getMetadata().
getMzTabVersion() == null) {
getMzTabVersion() == null) {
//set default version if not set
mzTabFile.getMetadata().
mzTabVersion(MZTabConstants.VERSION_MZTAB_M);
mzTabVersion(MZTabConstants.VERSION_MZTAB_M);
}
StringWriter writer = new StringWriter();
try {
mapper.writer(schema).
writeValue(writer, mzTabFile.getMetadata());
writeValue(writer, mzTabFile.getMetadata());
} catch (JsonProcessingException ex) {
Logger.getLogger(MzTabNonValidatingWriter.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
}
Map<String, List<Map<String, String>>> mzTabLines = new LinkedHashMap<>();
String[] metaDataLines = writer.toString().
split(MZTabConstants.NEW_LINE);
split(MZTabConstants.NEW_LINE);
List<Map<String, String>> metaData = new ArrayList<>();
int lineNumber = 1;
for (int i = 0; i < metaDataLines.length; i++) {
String[] metaDataLine = metaDataLines[i].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
Map<String, String> lineMap = new LinkedHashMap<>();
lineMap.put("LINE_NUMBER", lineNumber + "");
lineMap.put("PREFIX", metaDataLine[0]);
Expand All @@ -158,29 +159,29 @@ public Map<String, List<Map<String, String>>> parse(Path filepath,
mapper = writerDefaults.smallMoleculeSummaryMapper();
try {
schema = writerDefaults.
smallMoleculeSummarySchema(mapper, mzTabFile);
smallMoleculeSummarySchema(mapper, mzTabFile);
writer = new StringWriter();
mapper.writer(schema).
writeValue(writer, mzTabFile.getSmallMoleculeSummary());
writeValue(writer, mzTabFile.getSmallMoleculeSummary());
} catch (JsonProcessingException ex) {
Logger.getLogger(MzTabNonValidatingWriter.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
} catch (MZTabException ex) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
throw new IOException(ex);
}

String[] summaryDataLines = writer.toString().
split(MZTabConstants.NEW_LINE);
split(MZTabConstants.NEW_LINE);
String[] summaryHeader = summaryDataLines[0].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
List<Map<String, String>> summaryData = new ArrayList<>();
//due to the header
lineNumber++;
for (int i = 1; i < summaryDataLines.length; i++) {
String[] dataLine = summaryDataLines[i].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
Map<String, String> lineMap = new LinkedHashMap<>();
lineMap.put("LINE_NUMBER", lineNumber + "");
for (int j = 0; j < summaryHeader.length; j++) {
Expand All @@ -194,28 +195,28 @@ public Map<String, List<Map<String, String>>> parse(Path filepath,
mapper = writerDefaults.smallMoleculeFeatureMapper();
try {
schema = writerDefaults.
smallMoleculeFeatureSchema(mapper, mzTabFile);
smallMoleculeFeatureSchema(mapper, mzTabFile);
writer = new StringWriter();
mapper.writer(schema).
writeValue(writer, mzTabFile.getSmallMoleculeFeature());
writeValue(writer, mzTabFile.getSmallMoleculeFeature());
} catch (JsonProcessingException ex) {
Logger.getLogger(MzTabNonValidatingWriter.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
} catch (MZTabException ex) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
throw new IOException(ex);
}
String[] featureDataLines = writer.toString().
split(MZTabConstants.NEW_LINE);
split(MZTabConstants.NEW_LINE);
String[] featureHeader = featureDataLines[0].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
List<Map<String, String>> featureData = new ArrayList<>();
//due to the header
lineNumber++;
for (int i = 1; i < featureDataLines.length; i++) {
String[] dataLine = featureDataLines[i].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
Map<String, String> lineMap = new LinkedHashMap<>();
lineMap.put("LINE_NUMBER", lineNumber + "");
for (int j = 0; j < featureHeader.length; j++) {
Expand All @@ -229,28 +230,28 @@ public Map<String, List<Map<String, String>>> parse(Path filepath,
mapper = writerDefaults.smallMoleculeEvidenceMapper();
try {
schema = writerDefaults.smallMoleculeEvidenceSchema(mapper,
mzTabFile);
mzTabFile);
writer = new StringWriter();
mapper.writer(schema).
writeValue(writer, mzTabFile.getSmallMoleculeEvidence());
writeValue(writer, mzTabFile.getSmallMoleculeEvidence());
} catch (JsonProcessingException ex) {
Logger.getLogger(MzTabNonValidatingWriter.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
} catch (MZTabException ex) {
Logger.getLogger(IsasValidator.class.getName()).
log(Level.SEVERE, null, ex);
log(Level.SEVERE, null, ex);
throw new IOException(ex);
}
String[] evidenceDataLines = writer.toString().
split(MZTabConstants.NEW_LINE);
split(MZTabConstants.NEW_LINE);
String[] evidenceHeader = evidenceDataLines[0].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
List<Map<String, String>> evidenceData = new ArrayList<>();
//due to the header
lineNumber++;
for (int i = 1; i < evidenceDataLines.length; i++) {
String[] dataLine = evidenceDataLines[i].split(
MZTabConstants.TAB_STRING);
MZTabConstants.TAB_STRING);
Map<String, String> lineMap = new LinkedHashMap<>();
lineMap.put("LINE_NUMBER", lineNumber + "");
for (int j = 0; j < evidenceHeader.length; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,13 @@ public CompletableFuture<ToolResult> runValidation(MzTabVersion mzTabVersion,
try {
List<ValidationMessage> validationResults = new ArrayList<>();
status.setStatus(Status.RUNNING);
validationResults.addAll(
validate(mzTabVersion, filepath, validationLevel,
maxErrors, checkCvMapping, storageService.load(
mappingFile, StorageService.SLOT.MAPPINGFILE)));
Path mappingFilePath = storageService.load(mappingFile, StorageService.SLOT.MAPPINGFILE);
if (!mappingFilePath.toFile().exists()) {
throw new IOException("Semantic validation file "+mappingFilePath+" does not exist!");
}
List<ValidationMessage> messages = validate(mzTabVersion, filepath, validationLevel,
maxErrors, checkCvMapping, mappingFilePath);
validationResults.addAll(messages);
tracker.stopped(userSessionFile.getSessionId(), "validation",
"success");
status.setMessages(validationResults);
Expand All @@ -287,7 +290,15 @@ public CompletableFuture<ToolResult> runValidation(MzTabVersion mzTabVersion,
status.setMessages(Arrays.asList(mex.getError().
toValidationMessage()));
} else {
throw new RuntimeException(ex);
ValidationMessage vm = new ValidationMessage();
vm.setCategory(
ValidationMessage.CategoryEnum.CROSS_CHECK);
vm.setCode("");
vm.setLineNumber(-1l);
vm.setMessageType(
ValidationMessage.MessageTypeEnum.ERROR);
vm.setMessage(ex.getMessage());
status.setMessages(Arrays.asList(vm));
}
resultService.addResultFor(userSessionId, status);
tracker.
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/examples.properties
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ example.exampleFile[8].description=default CV term mapping file
example.exampleFile[8].version=2.0
example.exampleFile[8].focus=mzTab-M
example.exampleFile[8].createdBy=Manual

example.exampleFile[9].section=mapping
example.exampleFile[9].name=mzTab_2_0-M-lipidomics_mapping.xml
example.exampleFile[9].uri=https://raw.githubusercontent.com/lipidomics-standards-initiative/mzTab-L/master/drafts/1_0-Lipidomics/mzTab_2_0-M-lipidomics_mapping.xml
example.exampleFile[9].description=draft mzTab-L CV term mapping file
example.exampleFile[9].version=DRAFT
example.exampleFile[9].focus=mzTab-L
example.exampleFile[9].createdBy=Manual

0 comments on commit d91a19e

Please sign in to comment.