Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a problem with annotations in the PSI OBO for PSM scores #209

Merged
merged 5 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>de.mpc.pia</groupId>
<artifactId>pia</artifactId>
<version>1.5.3</version>
<version>1.5.4</version>
<name>PIA - Protein Inference Algorithms</name>
<url>https://github.com/mpc-bioinformatics/pia</url>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.mpc.pia.intermediate.PeptideSpectrumMatch;
import de.mpc.pia.intermediate.compiler.PIACompiler;
import de.mpc.pia.modeller.score.ScoreModel;
import de.mpc.pia.modeller.score.ScoreModelEnum;
import de.mpc.pia.tools.MzIdentMLTools;
import de.mpc.pia.tools.OntologyConstants;
import de.mpc.pia.tools.obo.AbstractOBOMapper;
Expand Down Expand Up @@ -854,17 +855,24 @@ private ScoreModel parseOBOTermAsScore(Term oboTerm, String value) {
ScoreModel score = null;

if (oboTerm != null) {
// the score is in the OBO file, get the relations etc.
Set<Triple> tripleSet = compiler.getOBOMapper().getTriples(oboTerm, null, null);

for (Triple triple : tripleSet) {
if (triple.getPredicate().getName().equals(AbstractOBOMapper.OBO_IS_A) &&
triple.getObject().getName().equals(OntologyConstants.SEARCH_ENGINE_PSM_SCORE.getPsiAccession())) {
// subject is a "search engine specific score for PSM"
double doubleValue = Double.parseDouble(value);
score = new ScoreModel(doubleValue,
StringEscapeUtils.unescapeJava(oboTerm.getName()),
StringEscapeUtils.unescapeJava(oboTerm.getDescription()));
ScoreModelEnum scEnum = ScoreModelEnum.getModelByAccession(oboTerm.getName());
if ((scEnum != null) && !scEnum.equals(ScoreModelEnum.UNKNOWN_SCORE)) {
// the term is a recognized / hard coded score
double doubleValue = Double.parseDouble(value);
score = new ScoreModel(doubleValue, scEnum);
} else {
// the score is in the OBO file, try to get the relations etc.
Set<Triple> tripleSet = compiler.getOBOMapper().getTriples(oboTerm, null, null);

for (Triple triple : tripleSet) {
if (triple.getPredicate().getName().equals(AbstractOBOMapper.OBO_IS_A) &&
triple.getObject().getName().equals(OntologyConstants.SEARCH_ENGINE_PSM_SCORE.getPsiAccession())) {
// subject is a "search engine specific score for PSM"
double doubleValue = Double.parseDouble(value);
score = new ScoreModel(doubleValue,
StringEscapeUtils.unescapeJava(oboTerm.getName()),
StringEscapeUtils.unescapeJava(oboTerm.getDescription()));
}
}
}
}
Expand Down
59 changes: 15 additions & 44 deletions src/test/java/de/mpc/pia/intermediate/IntermediateJAXBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,30 @@
import java.io.File;
import java.io.IOException;

import org.apache.log4j.Logger;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import de.mpc.pia.intermediate.xmlhandler.PIAIntermediateJAXBHandler;
import de.mpc.pia.modeller.PIAModellerTest;

public class IntermediateJAXBTest {

/** logger for this class */
private static final Logger LOGGER = Logger.getLogger(IntermediateJAXBTest.class);

private static File piaFile;


@BeforeClass
public static void setUpBeforeClass() {
piaFile = new File(PIAModellerTest.class.getResource("/55merge_mascot_tandem.pia.xml").getPath());
}


@Test
public void testIntermediateJAXB() {
@Ignore("Unfortunately, loading Unmarshaller for mzid 1.1 and mzid 1.2 in same test suite breaks everything")
public void testIntermediateJAXB() throws IOException{
PIAIntermediateJAXBHandler intermediateHandler;
intermediateHandler = new PIAIntermediateJAXBHandler();

Runtime runtime = Runtime.getRuntime();
double mb = 1024*1024;
final long startTime = System.nanoTime();
final long endTime;

try {
intermediateHandler.parse(piaFile.getAbsolutePath(), null);
} catch (IOException e) {
LOGGER.error(e);
}

endTime = System.nanoTime();

assertEquals(2, intermediateHandler.getFiles().size());
assertEquals(2, intermediateHandler.getSpectraData().size());
assertEquals(2, intermediateHandler.getSearchDatabase().size());
assertEquals(2, intermediateHandler.getAnalysisSoftware().size());
assertEquals(1941, intermediateHandler.getGroups().size());
assertEquals(2131, intermediateHandler.getAccessions().size());
assertEquals(2113, intermediateHandler.getPeptides().size());
assertEquals(2478, intermediateHandler.getPSMs().size());
assertEquals(1856, intermediateHandler.getNrTrees());

LOGGER.info("Total Memory: " + runtime.totalMemory() / mb + " MB");
LOGGER.info("Used Memory: " + (runtime.totalMemory() - runtime.freeMemory()) / mb + " MB");
LOGGER.info("Free Memory: " + runtime.freeMemory() / mb + " MB");
LOGGER.info("Max Memory: " + runtime.maxMemory() / mb + " MB");
LOGGER.info("Execution time: " + ((endTime - startTime) / 1000000000.0) + " s");
File piaFile = new File(IntermediateJAXBTest.class.getResource("/55merge_mascot_tandem.pia.xml").getPath());
intermediateHandler.parse(piaFile.getAbsolutePath(), null);

assertEquals("Number of Files differ", 2, intermediateHandler.getFiles().size());
assertEquals("Number of SpectraData differ", 2, intermediateHandler.getSpectraData().size());
assertEquals("Number of SearchDatabases differ", 2, intermediateHandler.getSearchDatabase().size());
assertEquals("Number of AnalysisSoftware differ", 2, intermediateHandler.getAnalysisSoftware().size());
assertEquals("Number of Groups differ", 1941, intermediateHandler.getGroups().size());
assertEquals("Number of Accessions differ", 2131, intermediateHandler.getAccessions().size());
assertEquals("Number of Peptides differ", 2113, intermediateHandler.getPeptides().size());
assertEquals("Number of PSMs differ", 2478, intermediateHandler.getPSMs().size());
assertEquals("Number of NrTrees differ", 1856, intermediateHandler.getNrTrees());
}
}
35 changes: 35 additions & 0 deletions src/test/java/de/mpc/pia/modeller/exporter/MzIdentML12Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.mpc.pia.modeller.exporter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import de.mpc.pia.intermediate.compiler.PIACompiler;
import de.mpc.pia.intermediate.compiler.PIASimpleCompiler;


public class MzIdentML12Test {

@Test
@Ignore("Unfortunately, loading Unmarshaller for mzid 1.1 and mzid 1.2 in same test suite breaks everything")
public void testMzIdentMLv1_2_0Import() {
PIACompiler piaCompiler = new PIASimpleCompiler();

File cometMzid12Results = new File(MzIdentML12Test.class.getResource("/comet_mzid12.mzid").getPath());
assertTrue(piaCompiler.getDataFromFile("mzid", cometMzid12Results.getAbsolutePath(), null, null));

piaCompiler.buildClusterList();
piaCompiler.buildIntermediateStructure();

piaCompiler.setName("testFile");

assertEquals("Wrong number of PIA Input files", 1, piaCompiler.getAllFileIDs().size());
assertEquals("Wrong number of imported peptides", 600, piaCompiler.getNrPeptides());
assertEquals("Wrong number of imported PSMs", 610, piaCompiler.getNrPeptideSpectrumMatches());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
import java.io.IOException;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;

import de.mpc.pia.intermediate.compiler.PIACompiler;
import de.mpc.pia.intermediate.compiler.PIACompilerTest;
import de.mpc.pia.intermediate.compiler.PIASimpleCompiler;
import de.mpc.pia.modeller.PIAModeller;
import de.mpc.pia.modeller.protein.inference.SpectrumExtractorInference;
Expand All @@ -26,41 +24,28 @@

public class MzIdentMLExportAndImportTest {

private File tandemIdXMLResults;
private File tandemMzidResults;
private String piaIntermediateFileName;
/** logger for this class */
private static final Logger LOGGER = Logger.getLogger(PIACompiler.class);

@Before
public void setUp() {
piaIntermediateFileName = "PIACompilerTest.pia.xml";

tandemIdXMLResults = new File(PIACompilerTest.class.getResource("/merge1-tandem-fdr_filtered-015.idXML").getPath());
tandemMzidResults = new File(PIACompilerTest.class.getResource("/55merge_tandem.mzid").getPath());
}


@Test
public void testMzIdentMLv1_1_0Import() throws IOException {
public void testMzIdentMLv1_1_0Import() {
PIACompiler piaCompiler = new PIASimpleCompiler();


File tandemMzidResults = new File(MzIdentMLExportAndImportTest.class.getResource("/55merge_tandem.mzid").getPath());
assertTrue(piaCompiler.getDataFromFile("mzid", tandemMzidResults.getAbsolutePath(), null, null));

piaCompiler.buildClusterList();
piaCompiler.buildIntermediateStructure();

piaCompiler.setName("testFile");

assertEquals("Wrong number of PIA Input files", 1, piaCompiler.getAllFileIDs().size());
assertEquals("Wrong number of imported peptides", 153, piaCompiler.getNrPeptides());
assertEquals("Wrong number of imported PSMs", 170, piaCompiler.getNrPeptideSpectrumMatches());
}


@Test
public void testMzIdentMLExportAndImport() throws IOException {
PIACompiler piaCompiler = new PIASimpleCompiler();

File tandemIdXMLResults = new File(MzIdentMLExportAndImportTest.class.getResource("/merge1-tandem-fdr_filtered-015.idXML").getPath());
assertTrue(piaCompiler.getDataFromFile("tandem", tandemIdXMLResults.getAbsolutePath(), null, null));

piaCompiler.buildClusterList();
Expand All @@ -73,6 +58,7 @@ public void testMzIdentMLExportAndImport() throws IOException {


// write out the file
String piaIntermediateFileName = "testMzIdentMLExportAndImport.pia.xml";
File piaIntermediateFile = File.createTempFile(piaIntermediateFileName, null);
piaCompiler.writeOutXML(piaIntermediateFile);
piaCompiler.finish();
Expand Down Expand Up @@ -110,7 +96,6 @@ public void testMzIdentMLExportAndImport() throws IOException {


// try to read it back in PIA compiler
LOGGER.info("Try to read back the mzIdentML previously compiled");
piaCompiler = new PIASimpleCompiler();

assertTrue(piaCompiler.getDataFromFile("mzIdentMLfile", exportFile.getAbsolutePath(), null, null));
Expand Down
Loading
Loading