From a4a76d268f94b21715cf064bc3d7513be2af75b6 Mon Sep 17 00:00:00 2001 From: Suresh Hewapathirana Date: Mon, 4 Jan 2021 09:45:00 +0000 Subject: [PATCH 1/4] save output as a file & multiple peakfile check --- pom.xml | 1 + .../px_validator/SubmissionToolValidator.java | 11 +++- .../toolsuite/px_validator/Validator.java | 2 +- .../toolsuite/px_validator/utils/Report.java | 2 +- .../px_validator/utils/ResultReport.java | 12 +++- .../toolsuite/px_validator/utils/Utility.java | 25 ++++++++ .../validators/MzIdValidator.java | 60 +++++++++++++++++++ 7 files changed, 106 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 2821011..7ff2064 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ UTF-8 1.0.2 2.0.28 + 2.0.31-SNAPSHOT 1.2.0 2.3.1 1.3.15 diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/SubmissionToolValidator.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/SubmissionToolValidator.java index 4f346a7..28c419f 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/SubmissionToolValidator.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/SubmissionToolValidator.java @@ -4,6 +4,7 @@ import org.apache.log4j.Logger; import uk.ac.ebi.pride.toolsuite.px_validator.utils.IReport; +import java.io.File; import java.util.*; import static uk.ac.ebi.pride.toolsuite.px_validator.utils.Utility.*; @@ -30,8 +31,14 @@ public static void main(String[] args) { if (args.length > 0) { if (cmd.hasOption(ARG_VALIDATION)) { IReport report = Validator.startValidation(cmd); - if (report != null) - log.info(report.toString()); + if (report != null) { + if(cmd.hasOption(ARG_REPORTFILE)){ + File outputFile = cmd.hasOption(ARG_REPORTFILE) ? new File(cmd.getOptionValue(ARG_REPORTFILE)) : null; + outputReport(report, outputFile); + }else { + log.info(report.toString()); + } + } } else { log.error("Did not find validation command from arguments "); Arrays.stream(args).forEach(log::error); diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/Validator.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/Validator.java index 7964292..18a15d4 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/Validator.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/Validator.java @@ -84,7 +84,7 @@ private static List getFilesToValidate(File file) { * @param cmd the command line arguments. * @return List of peak files. */ - private static List getPeakFiles(CommandLine cmd) { + public static List getPeakFiles(CommandLine cmd) { List peakFiles = new ArrayList<>(); if (cmd.hasOption(ARG_PEAK) || cmd.hasOption(ARG_PEAKS)) { String[] peakFilesString = cmd.hasOption(ARG_PEAK) ? cmd.getOptionValues(ARG_PEAK) diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Report.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Report.java index 0a0bb3f..c6ac77e 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Report.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Report.java @@ -34,7 +34,7 @@ public String toString() { for(Map.Entry er: errors) error.append(er.getKey().toString()).append(" == Level Error: ").append(er.getValue()).append(" ==\n"); if(errors.isEmpty()){ - error.append("No errors found -- OK").append("\n"); + error.append("Errors found: None").append("\n"); } return error.toString(); } diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/ResultReport.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/ResultReport.java index b86f0a2..b5c6214 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/ResultReport.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/ResultReport.java @@ -8,6 +8,7 @@ public class ResultReport extends Report { private int numberOfProteins; private int numberOfPeptides; private int numberOfPSMs; + private int numberOfPeakFiles; public ResultReport() { @@ -25,10 +26,15 @@ public void setNumberOfPSMs(int numberOfPSMs) { this.numberOfPSMs = numberOfPSMs; } + public void setNumberOfPeakFiles(int numberOfPeakFiles) { + this.numberOfPeakFiles = numberOfPeakFiles; + } + @Override public String toString() { - return super.toString() + "\nIdentification results Report: \nNumber of reported proteins -- " + numberOfProteins + "\n" + - "Number of reported peptides -- " + numberOfPeptides + "\n" + - "Number of reported PSMs -- " + numberOfPSMs + "\n"; + return super.toString() + "Number of reported proteins : " + numberOfProteins + "\n" + + "Number of reported peptides : " + numberOfPeptides + "\n" + + "Number of reported PSMs : " + numberOfPSMs + "\n" + + "Number of peak files : " + numberOfPeakFiles + "\n"; } } diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Utility.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Utility.java index 52c4b55..31b91cb 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Utility.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/utils/Utility.java @@ -104,4 +104,29 @@ public static File createNewTempFile(File file) { } return tempFile; } + + public static void outputReport(IReport report, File reportFile){ + log.info(report.toString()); + if (reportFile!=null) { + try { + log.info("Writing report to: " + reportFile.getAbsolutePath()); + java.nio.file.Files.write(reportFile.toPath(), report.toString().getBytes()); + } catch (IOException ioe) { + log.error("Problem when writing report file: ", ioe); + } + } + } + + public static String getRealFileName(String fileName) { + String name = fileName; + + if (name.contains("/") || name.contains("\\")) { + String[] parts = name.split("/"); + name = parts[parts.length - 1]; + parts = name.split("\\\\"); + name = parts[parts.length - 1]; + } + + return name; + } } diff --git a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/validators/MzIdValidator.java b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/validators/MzIdValidator.java index 80b2ee0..4122598 100644 --- a/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/validators/MzIdValidator.java +++ b/src/main/java/uk/ac/ebi/pride/toolsuite/px_validator/validators/MzIdValidator.java @@ -2,8 +2,10 @@ import de.mpc.pia.intermediate.compiler.PIASimpleCompiler; import de.mpc.pia.intermediate.compiler.parser.InputFileParserFactory; +import de.mpc.pia.modeller.PIAModeller; import org.apache.commons.cli.CommandLine; import org.xml.sax.SAXException; +import uk.ac.ebi.jmzidml.model.mzidml.SpectraData; import uk.ac.ebi.pride.data.validation.ValidationMessage; import uk.ac.ebi.pride.tools.ErrorHandlerIface; import uk.ac.ebi.pride.tools.GenericSchemaValidator; @@ -13,11 +15,15 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; public class MzIdValidator implements Validator{ private File file; + private List peakFiles; private static final String MZID_SCHEMA = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/psi-pi/mzIdentML1.1.0.xsd"; public static Validator getInstance(CommandLine cmd) throws Exception { @@ -35,6 +41,7 @@ private MzIdValidator(CommandLine cmd) throws Exception{ }else{ throw new IOException("In order to validate a mzid file the argument -mzid should be provided"); } + peakFiles = uk.ac.ebi.pride.toolsuite.px_validator.Validator.getPeakFiles(cmd); } @Override @@ -50,13 +57,23 @@ public IReport validate() { piaCompiler.buildClusterList(); piaCompiler.buildIntermediateStructure(); + List spectrumFiles = getPeakFiles(piaCompiler); + List peakFilesError = validatePeakFiles(spectrumFiles); + if(peakFilesError.size() > 0){ + for(String error: peakFilesError){ + report.addException(new IOException(error), ValidationMessage.Type.ERROR); + } + } + int numProteins = piaCompiler.getNrAccessions(); int numPeptides = piaCompiler.getNrPeptides(); int numPSMs = piaCompiler.getNrPeptideSpectrumMatches(); + int numPeakFiles = spectrumFiles.size(); ((ResultReport) report).setNumberOfPeptides(numPeptides); ((ResultReport) report).setNumberOfProteins(numProteins); ((ResultReport) report).setNumberOfPSMs(numPSMs); + ((ResultReport) report).setNumberOfPeakFiles(numPeakFiles); return report; } @@ -77,4 +94,47 @@ private static IReport validateMzidSchema(File mzIdentML) { } return report; } + + private List getPeakFiles(PIASimpleCompiler piaCompiler){ + PIAModeller piaModeller = null; + try { + if (piaCompiler.getAllPeptideSpectrumMatcheIDs() != null + && !piaCompiler.getAllPeptideSpectrumMatcheIDs().isEmpty()) { + File inferenceTempFile = File.createTempFile("assay", ".tmp"); + piaCompiler.writeOutXML(inferenceTempFile); + piaCompiler.finish(); + piaModeller = new PIAModeller(inferenceTempFile.getAbsolutePath()); + + if (inferenceTempFile.exists()) { + inferenceTempFile.deleteOnExit(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + piaModeller.getSpectraData(); + + return piaModeller.getSpectraData() + .entrySet().stream().map(Map.Entry::getValue) + .collect(Collectors.toList()); + } + + private List validatePeakFiles(List spectraDataFiles){ + List peakFileErrors = new ArrayList<>(); + + for(File peakFile: this.peakFiles){ + boolean isFound = false; + for (SpectraData spectraData : spectraDataFiles) { + String filename = Utility.getRealFileName(spectraData.getLocation()); + if(filename.equals(peakFile.getName())){ + isFound = true; + break; + } + } + if(!isFound){ + peakFileErrors.add(peakFile.getName() + " does not found as a reference in MzIdentML"); + } + } + return peakFileErrors; + } } From b553b10205f5567b61ac760a7ed2b9edbe563a88 Mon Sep 17 00:00:00 2001 From: Suresh Hewapathirana Date: Mon, 4 Jan 2021 12:41:12 +0000 Subject: [PATCH 2/4] added repo --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 7ff2064..8be2cf9 100644 --- a/pom.xml +++ b/pom.xml @@ -271,6 +271,13 @@ nexus-ebi-snapshot-repo http://www.ebi.ac.uk/Tools/maven/repos/content/groups/ebi-snapshots/ + + + genesis-maven2-repository + Genesis maven2 repository + http://genesis.ugent.be/maven2 + default + pst-release EBI Nexus Repository From bd7f86cfe33ddae459d903784c6d45b068ce07ab Mon Sep 17 00:00:00 2001 From: Suresh Hewapathirana Date: Mon, 4 Jan 2021 13:00:26 +0000 Subject: [PATCH 3/4] added repo --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 8be2cf9..3a20583 100644 --- a/pom.xml +++ b/pom.xml @@ -271,6 +271,10 @@ nexus-ebi-snapshot-repo http://www.ebi.ac.uk/Tools/maven/repos/content/groups/ebi-snapshots/ + + nexus-ebi-intact-repo + https://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/ + genesis-maven2-repository From 11b352b9744cff47dbb1bbccfdd2791faf46ddec Mon Sep 17 00:00:00 2001 From: Suresh Hewapathirana Date: Mon, 4 Jan 2021 14:58:05 +0000 Subject: [PATCH 4/4] cpdetector dependency resolve --- pom.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3a20583..b72b514 100644 --- a/pom.xml +++ b/pom.xml @@ -16,9 +16,15 @@ 1.2.0 2.3.1 1.3.15 + 1.0.7 + + cpdetector + cpdetector + ${cpdetector} + de.mpc.pia pia @@ -56,7 +62,11 @@ com.sun.xml.bind jaxb-xjc - + + + net.sourceforge.cpdetector + cpdetector +