Skip to content

Commit c34121e

Browse files
authored
Merge pull request #135 from CGru21/main
Add functionality to generate Snakemake files.
2 parents 4d70717 + d2e3951 commit c34121e

File tree

6 files changed

+354
-2
lines changed

6 files changed

+354
-2
lines changed

CITATION.cff

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ authors:
2424
family-names: Haverkort
2525
affiliation: Utrecht University, Netherlands
2626
orcid: 'https://orcid.org/0009-0005-4904-0868'
27-
- given-names: Maurin
28-
family-names: Voshol
27+
- family-names: Maurin
28+
given-names: Voshol
29+
- given-names: Charlotte
30+
family-names: Grunert
31+
32+
affiliation: University of Potsdam, Germany
33+
orcid: 'https://orcid.org/0009-0007-1871-5409'
2934
identifiers:
3035
- type: doi
3136
value: 10.5281/zenodo.5638988

src/main/java/nl/uu/cs/ape/APE.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow;
3232
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;
3333
import nl.uu.cs.ape.solver.solutionStructure.cwl.DefaultCWLCreator;
34+
import nl.uu.cs.ape.solver.solutionStructure.snakemake.SnakemakeCreator;
3435
import nl.uu.cs.ape.utils.APEFiles;
3536
import nl.uu.cs.ape.utils.APEUtils;
3637

@@ -666,6 +667,47 @@ public static boolean writeCWLWorkflows(SolutionsList allSolutions) {
666667
return true;
667668
}
668669

670+
public static boolean writeSnakemakeWorkflows(SolutionsList allSolutions) {
671+
if (allSolutions.isEmpty()) {
672+
return false;
673+
}
674+
Path snakemakeFolder = allSolutions.getRunConfiguration().getSolutionDirPath2Snakemake();
675+
int noSnakemakeFiles = allSolutions.getRunConfiguration().getNoSnakemake();
676+
if (snakemakeFolder == null || noSnakemakeFiles == 0) {
677+
return false;
678+
}
679+
680+
final String timerID = "writingSnakemake";
681+
APEUtils.printHeader(null, String.format("Writing the first %d solution(s) to Snakemake files", noSnakemakeFiles));
682+
APEUtils.timerStart(timerID, true);
683+
684+
final File snakemakeDir = snakemakeFolder.toFile();
685+
if (snakemakeDir.isDirectory()) {
686+
// If the directory already exists, empty it first
687+
deleteExistingFiles(snakemakeDir, SolutionWorkflow.getFileNamePrefix(), "snakefile");
688+
} else {
689+
// Create the Snakemake directory if it does not already exist
690+
snakemakeDir.mkdir();
691+
}
692+
log.debug("Generating Snakemake files.");
693+
694+
allSolutions.getParallelStream().filter(solution -> solution.getIndex() < noSnakemakeFiles).forEach(solution -> {
695+
try {
696+
String titleSnakefile= solution.getFileName() + "_snakefile";
697+
File script = snakemakeFolder.resolve(titleSnakefile).toFile();
698+
SnakemakeCreator snakemakeCreator = new SnakemakeCreator(solution);
699+
APEFiles.write2file(snakemakeCreator.generateSnakemakeRepresentation(), script, false);
700+
701+
} catch (IOException e) {
702+
log.error("Error occurred while writing a Snakemake file to the file system.");
703+
e.printStackTrace();
704+
}
705+
});
706+
707+
APEUtils.timerPrintText(timerID, "Snakemake files have been generated.");
708+
return true;
709+
}
710+
669711
/**
670712
* Delete all files in the given directory that start with the given prefix and
671713
* have the given extension.

src/main/java/nl/uu/cs/ape/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public static void executeSynthesis(String[] args) {
238238
APE.writeTavernaDesignGraphs(solutions);
239239
APE.writeExecutableWorkflows(solutions);
240240
APE.writeCWLWorkflows(solutions);
241+
APE.writeSnakemakeWorkflows(solutions);
241242
} catch (IOException e) {
242243
log.error("Error in writing the solutions. to the file system.");
243244
e.printStackTrace();

src/main/java/nl/uu/cs/ape/configuration/APERunConfig.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public class APERunConfig {
6666
* Default is 0.
6767
*/
6868
private final APEConfigTag<Integer> NO_CWL = new APEConfigTagFactory.TAGS.NO_CWL();
69+
/**
70+
* Number of Snakemake files that should be generated from candidate workflows.
71+
* Default is 0.
72+
*/
73+
private final APEConfigTag<Integer> NO_SNAKEMAKE = new APEConfigTagFactory.TAGS.NO_SNAKEMAKE();
6974
/**
7075
* Determines the required usage for the data instances that are given as
7176
* workflow input:<br>
@@ -119,6 +124,7 @@ public class APERunConfig {
119124
this.NO_EXECUTIONS,
120125
this.NO_GRAPHS,
121126
this.NO_CWL,
127+
this.NO_SNAKEMAKE,
122128
this.USE_WORKFLOW_INPUT,
123129
this.USE_ALL_GENERATED_DATA,
124130
this.DEBUG_MODE,
@@ -141,6 +147,7 @@ public class APERunConfig {
141147
new NO_EXECUTIONS(),
142148
new NO_GRAPHS(),
143149
new NO_CWL(),
150+
new NO_SNAKEMAKE(),
144151
new USE_WORKFLOW_INPUT(),
145152
new USE_ALL_GENERATED_DATA(),
146153
new DEBUG_MODE(),
@@ -366,6 +373,20 @@ public Path getSolutionDirPath2CWL() {
366373
return getSolutionDirPath2(CWL_FOLDER_NAME);
367374
}
368375

376+
/** Tag value. */
377+
public static final String SNAKEMAKE_FOLDER_NAME = "Snakemake";
378+
379+
/**
380+
* Get the path to the directory where the snakemake scripts corresponding the given
381+
* solutions should be stored.
382+
*
383+
* @return the path to the directory where the snakemake scripts corresponding to the
384+
* given solutions should be stored
385+
*/
386+
public Path getSolutionDirPath2Snakemake() {
387+
return getSolutionDirPath2(SNAKEMAKE_FOLDER_NAME);
388+
}
389+
369390
/** Tag value. */
370391
public static final String EXECUTABLE_CWL_FOLDER_NAME = "CWL_executables";
371392

@@ -462,6 +483,24 @@ public void setNoCWL(int noCWL) {
462483
NO_CWL.setValue(noCWL);
463484
}
464485

486+
/**
487+
* Gets number of Snakemake files.
488+
*
489+
* @return The value of {@link #NO_SNAKEMAKE}
490+
*/
491+
public int getNoSnakemake() {
492+
return NO_SNAKEMAKE.getValue();
493+
}
494+
495+
/**
496+
* Set the number of Snakemake files.
497+
*
498+
* @param noSnakemake The number to set.
499+
*/
500+
public void setNoSnakemake(int noSnakemake) {
501+
NO_SNAKEMAKE.setValue(noSnakemake);
502+
}
503+
465504
/**
466505
* Gets program inputs.
467506
*

src/main/java/nl/uu/cs/ape/configuration/tags/APEConfigTagFactory.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,40 @@ protected ValidationResults validate(Integer value, ValidationResults results) {
919919
}
920920
}
921921

922+
/**
923+
* Configuration field.
924+
*/
925+
public static class NO_SNAKEMAKE extends TYPES.Int {
926+
public NO_SNAKEMAKE() {
927+
super(Range.of(0, Integer.MAX_VALUE));
928+
}
929+
930+
@Override
931+
public APEConfigDefaultValue<Integer> getDefault() {
932+
return APEConfigDefaultValue.withDefault(0);
933+
}
934+
935+
@Override
936+
public String getTagName() {
937+
return "number_of_snakemake_files";
938+
}
939+
940+
@Override
941+
public String getLabel() {
942+
return "Number of Snakemake files";
943+
}
944+
945+
@Override
946+
public String getDescription() {
947+
return "The number of Snakemake representations of solutions that should be generated.";
948+
}
949+
950+
@Override
951+
protected ValidationResults validate(Integer value, ValidationResults results) {
952+
return results;
953+
}
954+
}
955+
922956
/**
923957
* Configuration field.
924958
*/

0 commit comments

Comments
 (0)