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

Adjusting threads via CLI and fixing RT problems in mzid #210

Merged
merged 2 commits into from
Jul 16, 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.4</version>
<version>1.5.5</version>
<name>PIA - Protein Inference Algorithms</name>
<url>https://github.com/mpc-bioinformatics/pia</url>

Expand Down
48 changes: 44 additions & 4 deletions src/main/java/de/mpc/pia/PIACli.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class PIACli implements Runnable{
@Option(names = { "-o", "--outfile" },
description = "output file name (e.g. intermediate PIA file)")
private String outfile;

@Option(names = { "-t", "--threads" },
description = "maximum number of used threads for compilation (0 for use all)",
defaultValue = "0")
private String threads;

@Option(names = { "-n", "--name" },
description = "name of the compilation",
Expand Down Expand Up @@ -89,12 +94,16 @@ public static void main(String[] args) {
private void processCompile() {
PIACompiler piaCompiler = new PIASimpleCompiler();

int iThreads = parseThreads();
LOGGER.debug("Compiler uses {} CPUs", iThreads);
piaCompiler.setNrThreads(iThreads);

// parse the command line arguments
try {
if (!parseCommandLineInfiles(piaCompiler)) {
return;
}

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

Expand All @@ -108,6 +117,24 @@ private void processCompile() {
}
}

/**
* Parses the threads from the CLI into an integer value.
*
* @return integer value of CLI argument threads, 0 if errored (stands for use all CPUs)
*/
private int parseThreads() {
int iThreads = 0;
if (!threads.equals("0")) {
try {
iThreads = Integer.parseInt(threads);
} catch (NumberFormatException e) {
LOGGER.error("Could not parse the maximal number of threads, using all available CPUs");
iThreads = 0;
}
}
return iThreads;
}

/**
* Parses the files given from the command line in the String array into the
* given {@link PIACompiler}. The files may also contain the name and
Expand Down Expand Up @@ -193,7 +220,8 @@ private void processAnalysis() {
}

if (filesExist) {
processPIAAnalysis(infiles[0], infiles[1]);
int iThreads = parseThreads();
processPIAAnalysis(infiles[0], infiles[1], iThreads);
}
}
}
Expand All @@ -205,7 +233,7 @@ private void processAnalysis() {
* @param jsonFileName
* @param piaFileName
*/
public static boolean processPIAAnalysis(String jsonFileName, String piaFileName) {
public static boolean processPIAAnalysis(String jsonFileName, String piaFileName, int threads) {
PIAModeller modeller = new PIAModeller(piaFileName);
JsonAnalysis json = JsonAnalysis.readFromFile(new File(jsonFileName));

Expand Down Expand Up @@ -234,7 +262,7 @@ public static boolean processPIAAnalysis(String jsonFileName, String piaFileName

if (processOK && json.isInfereProteins()) {
// protein level
processOK = modeller.getProteinModeller().executeProteinOperations(json);
processOK = modeller.getProteinModeller().executeProteinOperations(json, threads);
}

if (processOK && (json.getProteinExportFile() != null)) {
Expand All @@ -257,6 +285,18 @@ public static boolean processPIAAnalysis(String jsonFileName, String piaFileName
return processOK;
}


/**
* Performs the actual PIA analysis parsing the JSON file for the PIA
* intermediate file.
*
* @param jsonFileName
* @param piaFileName
*/
public static boolean processPIAAnalysis(String jsonFileName, String piaFileName) {
return processPIAAnalysis(jsonFileName, piaFileName, 0);
}

/**
* {@link IVersionProvider} implementation that returns version information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,33 @@ private static Double parseRetentionTime(SpectrumIdentificationResult specIdResu
Double rt = null;

// get the "scan start time" cvParams
List<CvParam> scanStartCvParams = specIdResult.getCvParam().stream()
List<CvParam> rtCvParams = specIdResult.getCvParam().stream()
.filter(cvParam -> cvParam.getAccession().equals(OntologyConstants.SCAN_START_TIME.getPsiAccession()))
.toList();
rt = extractRTfromCVs(rtCvParams);

if (rt == null) {
// did not find the RT with this param, try "retention time"
rtCvParams = specIdResult.getCvParam().stream()
.filter(cvParam -> cvParam.getAccession().equals(OntologyConstants.RETENTION_TIME.getPsiAccession()))
.toList();
rt = extractRTfromCVs(rtCvParams);
}

return rt;
}


/**
* Extract scan time in seconds from the the retention time / scan start time CV params.
*
* @param scanTimeCvParams
* @return
*/
private static Double extractRTfromCVs(List<CvParam> scanTimeCvParams) {
Double rt = null;

for (CvParam cvParam : scanStartCvParams) {
for (CvParam cvParam : scanTimeCvParams) {
try {
rt = Double.parseDouble(cvParam.getValue());

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/de/mpc/pia/modeller/ProteinModeller.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,19 @@ public boolean addInferenceFilter(AbstractFilter newFilter) {
* <p>
* If a required setting is not given, the default value is used.
*/
public boolean executeProteinOperations(JsonAnalysis json) {
public boolean executeProteinOperations(JsonAnalysis json, int threads) {
boolean allOk = true;

AbstractProteinInference proteinInference =
ProteinInferenceFactory.createInstanceOf(json.getInferenceMethod());
if (proteinInference == null) {
LOGGER.error("Could not create inference method '{}'", json.getInferenceMethod());
allOk = false;
} else {
LOGGER.info("selected inference method: {}", proteinInference.getName());
proteinInference.setAllowedThreads(threads);
LOGGER.debug("Protein inference using {} threads (0=all available)", proteinInference.getAllowedThreads());
}

if (allOk) {
Expand Down Expand Up @@ -558,4 +560,14 @@ public boolean executeProteinOperations(JsonAnalysis json) {

return allOk;
}


/**
* Execute analysis on protein level, getting the settings from JSON, using all available CPUs
* <p>
* If a required setting is not given, the default value is used.
*/
public boolean executeProteinOperations(JsonAnalysis json) {
return executeProteinOperations(json, 0);
}
}
1 change: 1 addition & 0 deletions src/main/java/de/mpc/pia/tools/OntologyConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum OntologyConstants {
SEARCH_ENGINE_PSM_SCORE("search engine specific score for PSMs", "MS:1001143"),
SPECTRUM_TITLE("spectrum title", "MS:1000796"),
SCAN_START_TIME("scan start time", "MS:1000016"),
RETENTION_TIME("retention time", "MS:1000894"),
SCAN_NUMBERS("scan number(s)", "MS:1001115"),
DELTA_MZ("delta m/z", "MS:1001975"),
CLEAVAGE_AGENT_NAME("cleavage agent name", "MS:1001045"),
Expand Down
Loading