Skip to content

Commit

Permalink
set number of maximal number threads by the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
julianu committed Jul 16, 2024
1 parent 5b143e2 commit d7b183a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
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
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);
}
}

0 comments on commit d7b183a

Please sign in to comment.