Skip to content

Commit

Permalink
Merge pull request #3 from sureshhewabi/master
Browse files Browse the repository at this point in the history
save output as a file & multiple peak files check
  • Loading branch information
ypriverol authored Jan 4, 2021
2 parents fe98d34 + 11b352b commit 762a404
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 8 deletions.
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<archive.repo.version>1.0.2</archive.repo.version>
<px.submission.core.version>2.0.28</px.submission.core.version>
<ms.data.core.api.version>2.0.31-SNAPSHOT</ms.data.core.api.version>
<javax.activation.version>1.2.0</javax.activation.version>
<jaxb.api.version>2.3.1</jaxb.api.version>
<pia.version>1.3.15</pia.version>
<cpdetector>1.0.7</cpdetector>
</properties>

<dependencies>
<dependency>
<groupId>cpdetector</groupId>
<artifactId>cpdetector</artifactId>
<version>${cpdetector}</version>
</dependency>
<dependency>
<groupId>de.mpc.pia</groupId>
<artifactId>pia</artifactId>
Expand Down Expand Up @@ -55,7 +62,11 @@
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
</exclusion>

<!-- exclude this as this fails to download from maven a lot. Instead include it separately-->
<exclusion>
<groupId>net.sourceforge.cpdetector</groupId>
<artifactId>cpdetector</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down Expand Up @@ -270,6 +281,17 @@
<id>nexus-ebi-snapshot-repo</id>
<url>http://www.ebi.ac.uk/Tools/maven/repos/content/groups/ebi-snapshots/</url>
</repository>
<repository>
<id>nexus-ebi-intact-repo</id>
<url>https://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/</url>
</repository>
<!-- UGent Genesis repository -->
<repository>
<id>genesis-maven2-repository</id>
<name>Genesis maven2 repository</name>
<url>http://genesis.ugent.be/maven2</url>
<layout>default</layout>
</repository>
<repository>
<id>pst-release</id>
<name>EBI Nexus Repository</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static List<File> getFilesToValidate(File file) {
* @param cmd the command line arguments.
* @return List of peak files.
*/
private static List<File> getPeakFiles(CommandLine cmd) {
public static List<File> getPeakFiles(CommandLine cmd) {
List<File> peakFiles = new ArrayList<>();
if (cmd.hasOption(ARG_PEAK) || cmd.hasOption(ARG_PEAKS)) {
String[] peakFilesString = cmd.hasOption(ARG_PEAK) ? cmd.getOptionValues(ARG_PEAK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ResultReport extends Report {
private int numberOfProteins;
private int numberOfPeptides;
private int numberOfPSMs;
private int numberOfPeakFiles;

public ResultReport() {

Expand All @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<File> 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 {
Expand All @@ -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
Expand All @@ -50,13 +57,23 @@ public IReport validate() {
piaCompiler.buildClusterList();
piaCompiler.buildIntermediateStructure();

List<SpectraData> spectrumFiles = getPeakFiles(piaCompiler);
List<String> 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;
}

Expand All @@ -77,4 +94,47 @@ private static IReport validateMzidSchema(File mzIdentML) {
}
return report;
}

private List<SpectraData> 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<String> validatePeakFiles(List<SpectraData> spectraDataFiles){
List<String> 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;
}
}

0 comments on commit 762a404

Please sign in to comment.