001/* 002 * Copyright 2019 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V.. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.isas.mztab2.io.validators; 017 018import de.isas.mztab2.model.Metadata; 019import de.isas.mztab2.model.MsRun; 020import de.isas.mztab2.model.Parameter; 021import java.util.LinkedList; 022import java.util.List; 023import java.util.SortedMap; 024import uk.ac.ebi.pride.jmztab2.utils.errors.LogicalErrorType; 025import uk.ac.ebi.pride.jmztab2.utils.errors.MZTabError; 026import uk.ac.ebi.pride.jmztab2.utils.parser.MZTabParserContext; 027 028/** 029 * Validates that the ms run section is present in metadata. 030 * 031 * @author nilshoffmann 032 */ 033public class MsRunValidator implements RefiningValidator<Metadata> { 034 035 @Override 036 public List<MZTabError> validateRefine(Metadata metadata, MZTabParserContext parserContext) { 037 SortedMap<Integer, MsRun> runMap = parserContext.getMsRunMap(); 038 List<MZTabError> errorList = new LinkedList<>(); 039 for (Integer id : runMap.keySet()) { 040 if (runMap.get(id). 041 getLocation() == null) { 042 errorList.add(new MZTabError( 043 LogicalErrorType.NotDefineInMetadata, -1, 044 Metadata.Properties.msRun + "[" + id + "]-" + MsRun.Properties.location)); 045 } 046 List<Parameter> scanPolarity = runMap.get(id). 047 getScanPolarity(); 048 if (scanPolarity == null || scanPolarity.isEmpty()) { 049 errorList.add(new MZTabError( 050 LogicalErrorType.NotDefineInMetadata, -1, 051 Metadata.Properties.msRun + "[" + id + "]-" + MsRun.Properties.scanPolarity)); 052 } 053 054 } 055 return errorList; 056 } 057 058}