Skip to content

Commit 38cd6af

Browse files
authored
Change WDL annotation names, add new WDL attributes, add requiredOutputs, separate required/optional companions. (#165)
1 parent 3f10e49 commit 38cd6af

21 files changed

+1962
-337
lines changed

src/main/java/org/broadinstitute/barclay/argparser/CommandLineArgumentParser.java

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public final class CommandLineArgumentParser implements CommandLineParser {
5555
protected static final Set<String> EXPANSION_FILE_EXTENSIONS = new HashSet<>(
5656
Arrays.asList(EXPANSION_FILE_EXTENSION_LIST, EXPANSION_FILE_EXTENSIONS_ARGS));
5757

58+
// Prefixes used by the opt parser for short/long prefixes
59+
public static final String SHORT_OPTION_PREFIX = "-";
60+
public static final String LONG_OPTION_PREFIX = "--";
61+
5862
// This is the object that the caller has provided that contains annotations,
5963
// and into which the values will be assigned.
6064
private final Object callerArguments;

src/main/java/org/broadinstitute/barclay/argparser/TaggedArgumentParser.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public final class TaggedArgumentParser {
6060
// Map of surrogate keys to Pair(tag_string, raw_argument_value)
6161
private Map<String, Pair<String, String>> tagSurrogates = new HashMap<>();
6262

63-
// Prefixes used by the opt parser for short/long prefixes
64-
private static final String SHORT_OPTION_PREFIX = "-";
65-
private static final String LONG_OPTION_PREFIX = "--";
66-
6763
/**
6864
* Given an array of raw arguments provided by the user, return an array of args where tagged arguments
6965
* have been replaced with curated arguments containing a key to be used by the parser to retrieve the actual
@@ -78,9 +74,9 @@ public String[] preprocessTaggedOptions(final String[] argArray) {
7874
while (argIt.hasNext()) {
7975
final String arg = argIt.next();
8076
if (isShortOptionToken(arg)) {
81-
replaceTaggedOption(SHORT_OPTION_PREFIX, arg.substring(SHORT_OPTION_PREFIX.length()), argIt, finalArgs);
77+
replaceTaggedOption(CommandLineArgumentParser.SHORT_OPTION_PREFIX, arg.substring(CommandLineArgumentParser.SHORT_OPTION_PREFIX.length()), argIt, finalArgs);
8278
} else if (isLongOptionToken(arg)) {
83-
replaceTaggedOption(LONG_OPTION_PREFIX, arg.substring(LONG_OPTION_PREFIX.length()), argIt, finalArgs);
79+
replaceTaggedOption(CommandLineArgumentParser.LONG_OPTION_PREFIX, arg.substring(CommandLineArgumentParser.LONG_OPTION_PREFIX.length()), argIt, finalArgs);
8480
} else { // Positional arg, etc., just add it
8581
finalArgs.add(arg);
8682
}
@@ -173,14 +169,14 @@ public Pair<String, String> getTaggedOptionForSurrogate(final String putativeSur
173169

174170
// See if the opt parser would think this is a short option ("-")
175171
private static boolean isShortOptionToken(final String argument) {
176-
return argument.startsWith( SHORT_OPTION_PREFIX )
177-
&& !SHORT_OPTION_PREFIX.equals( argument )
172+
return argument.startsWith( CommandLineArgumentParser.SHORT_OPTION_PREFIX )
173+
&& !CommandLineArgumentParser.SHORT_OPTION_PREFIX.equals( argument )
178174
&& !isLongOptionToken( argument );
179175
}
180176

181177
// See if the opt parser would think this is a long option ("--")
182178
private static boolean isLongOptionToken(final String argument) {
183-
return argument.startsWith( LONG_OPTION_PREFIX );
179+
return argument.startsWith( CommandLineArgumentParser.LONG_OPTION_PREFIX );
184180
}
185181

186182
// Stores the option string and value in the tagSurrogates hash map and returns a surrogate key.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.broadinstitute.barclay.argparser;
2+
3+
import java.lang.annotation.*;
4+
5+
/**
6+
* Used to annotate @Arguments of a CommandLineProgram that are a workflow input, used by auto WDL generation.
7+
*/
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.FIELD)
10+
@Documented
11+
public @interface WorkflowInput {
12+
/**
13+
* @return array of names of required companion files that should travel with this resource. For example,
14+
* a (Genomic Reference) FASTA file might have two associated companion files that must be supplied as
15+
* arguments to the workflow, so the WorkflowInput would use the attribute values:
16+
*
17+
* @WorkflowInput(requiredCompanions = {"referenceDictionary", "referenceIndex" }
18+
*
19+
* The associated workflow and workflow input JSON (but not the task) generated by Barclay will contain two
20+
* additional required parameters with these names, allowing callers to optionally provide name values for
21+
* the companion files.
22+
*/
23+
String[] requiredCompanions() default {};
24+
25+
/**
26+
* @return array of names of optional companion files that should travel with this resource. For example,
27+
* a (Genomic Reference) FASTA file might have two associated companion files that can optionally be supplied as
28+
* arguments to the workflow, so the WorkflowOutput would use the attribute values:
29+
*
30+
* @WorkflowInput(optionalCompanions = {"referenceDictionary", "referenceIndex" }
31+
*
32+
* The associated workflow and workflow input JSON (but not the task) generated by Barclay will contain two
33+
* additional optional parameters with these names, allowing callers to optionally provide name values for
34+
* the companion files.
35+
*/
36+
String[] optionalCompanions() default {};
37+
38+
/**
39+
* Return a boolean specifying whether this input should have the "localization optional" attribute set.
40+
* Defaults to false. A value of true should only be used for input arguments on tools that can handle
41+
* inputs on non-local/remote file systems. This attribute is propagated to this input's companion files.
42+
*/
43+
boolean localizationOptional() default false;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.broadinstitute.barclay.argparser;
2+
3+
import java.lang.annotation.*;
4+
5+
/**
6+
* Used to annotate @Arguments of a CommandLineProgram that are a workflow output, used by auto WDL generation.
7+
*/
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.FIELD)
10+
@Documented
11+
public @interface WorkflowOutput {
12+
/**
13+
* @return array of names of required companion files that should travel with this resource. For example,
14+
* a (Genomic Reference) FASTA file might have two associated companion files that must be supplied as
15+
* arguments to the workflow, so the WorkflowOutput would use the attribute values:
16+
*
17+
* @WorkflowOutput(requiredCompanions = {"referenceDictionary", "referenceIndex" }
18+
*
19+
* The associated workflow and workflow input JSON (but not the task) generated by Barclay will contain two
20+
* additional parameters with these names (the parameters will only be required if the source of the companions
21+
* is required, otherwise they will be optional), allowing callers to optionally provide name values for
22+
* the companion files.
23+
*
24+
* The additional companion arguments will be included in the workflow output section of the associated WDL.
25+
*/
26+
String[] requiredCompanions() default {};
27+
28+
/**
29+
* @return array of names of optional companion files that should travel with this resource. For example,
30+
* a (Genomic Reference) FASTA file might have two associated companion files that can optionally be supplied as
31+
* arguments to the workflow, so the WorkflowOutput would use the attribute values:
32+
*
33+
* @WorkflowOutput(optionalCompanions = {"referenceDictionary", "referenceIndex" }
34+
*
35+
* The associated workflow and workflow input JSON (but not the task) generated by Barclay will contain two
36+
* additional optional parameters with these names, allowing callers to optionally provide name values for
37+
* the companion files.
38+
*
39+
* The additional companion arguments will be included in the workflow output section of the associated WDL.
40+
*/
41+
String[] optionalCompanions() default {};
42+
}

src/main/java/org/broadinstitute/barclay/argparser/RuntimeProperties.java src/main/java/org/broadinstitute/barclay/argparser/WorkflowProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
@Target(ElementType.TYPE)
1414
@Retention(RetentionPolicy.RUNTIME)
15-
public @interface RuntimeProperties {
15+
public @interface WorkflowProperties {
1616

1717
// NOTE: When a new attribute is added here, code should also be added to WDLWorkUnitHandler.addCustomBindings
1818
// to propagate the value to the freemarker map, and the corresponding expansion of the value should be
@@ -26,7 +26,7 @@
2626
/**
2727
* @return number of CPUs to use for this tool
2828
*/
29-
int cpu() default 1;
29+
int cpu() default 2;
3030

3131
/**
3232
* @return maximum number of times the workflow execution engine should request a preemptible machine for this

src/main/java/org/broadinstitute/barclay/argparser/WorkflowResource.java

-38
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.broadinstitute.barclay.help;
2+
3+
/**
4+
* String constants for properties used in the various freemarker templates.
5+
*/
6+
public class TemplateProperties {
7+
8+
// Properties used by the base doc gen system
9+
public final static String ARGUMENTS_POSITIONAL = "positional";
10+
11+
// Single argument map properties
12+
public final static String ARGUMENT_NAME = "name";
13+
public final static String ARGUMENT_TYPE = "type";
14+
public final static String ARGUMENT_SUMMARY = "summary";
15+
public final static String ARGUMENT_REQUIRED = "required";
16+
public final static String ARGUMENT_DEFAULT_VALUE = "defaultValue";
17+
18+
// Properties specific to WDL generation
19+
20+
// workflow/task argument names need to be wdl-conforming, but we need to preserve the actual arg name
21+
// for use in the command block
22+
public final static String WDL_ARGUMENT_ACTUAL_NAME = "actualArgName";
23+
24+
// The WDL input type (as opposed to the acutal/output type; these differ when an input is the name of
25+
// an output file. The input type is (String) but the output type is File.
26+
public final static String WDL_ARGUMENT_INPUT_TYPE = "wdlinputtype";
27+
28+
/**
29+
* Name of the top level freemarker map entry for runtime properties.
30+
*
31+
* Note that the property names used in this map will appear as workflow and task argument names in the
32+
* generated WDL, and should therefore not collide with any WDL reserved words.
33+
*/
34+
public static final String WDL_WORKFLOW_PROPERTIES = "workflowProperties";
35+
/**
36+
* runtime memory property (stored in "workflowProperties", used to initialize arg value in JSON)
37+
*/
38+
public static final String WDL_WORKFLOW_MEMORY = "memoryRequirements";
39+
/**
40+
* runtime disks property (stored in "workflowProperties", used to initialize arg value in JSON)
41+
*/
42+
public static final String WDL_WORKFLOW_DISKS = "diskRequirements";
43+
/**
44+
* cpu property
45+
*/
46+
public static final String WDL_WORKFLOW_CPU = "cpuRequirements";
47+
/**
48+
* bootDiskSizeGb property
49+
*/
50+
public static final String WDL_WORKFLOW_BOOT_DISK_SIZE_GB = "bootdisksizegbRequirements";
51+
/**
52+
* preemptible property
53+
*/
54+
public static final String WDL_WORKFLOW_PREEMPTIBLE = "preemptibleRequirements";
55+
56+
/**
57+
* name of the top level freemarker map entry for runtime outputs
58+
*/
59+
public static final String WDL_RUNTIME_OUTPUTS = "runtimeOutputs";
60+
/**
61+
* name of the top level freemarker map entry for required runtime outputs
62+
*/
63+
public static final String WDL_REQUIRED_OUTPUTS = "requiredOutputs";
64+
/**
65+
* name of the top level freemarker map entry for required companion resources
66+
*/
67+
public static final String WDL_REQUIRED_COMPANIONS = "requiredCompanions";
68+
/**
69+
* name of the top level freemarker map entry for optional companion resources
70+
*/
71+
public static final String WDL_OPTIONAL_COMPANIONS = "optionalCompanions";
72+
73+
/**
74+
* localization optional inputs
75+
*/
76+
public static final String WDL_LOCALIZATION_OPTIONAL = "localizationOptional";
77+
78+
}

src/main/java/org/broadinstitute/barclay/help/WDLDoclet.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import freemarker.template.Template;
66
import freemarker.template.TemplateException;
77
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties;
8-
import org.broadinstitute.barclay.argparser.RuntimeProperties;
8+
import org.broadinstitute.barclay.argparser.WorkflowProperties;
99

1010
import java.io.*;
1111
import java.util.List;
@@ -28,12 +28,12 @@ public static boolean start(final com.sun.javadoc.RootDoc rootDoc) throws IOExce
2828
@Override
2929
public boolean includeInDocs(final DocumentedFeature documentedFeature, final ClassDoc classDoc, final Class<?> clazz) {
3030
if (super.includeInDocs(documentedFeature, classDoc, clazz)) {
31-
boolean hasRuntimeProperties = clazz.getAnnotation(RuntimeProperties.class) != null;
31+
boolean hasWorkflowProperties = clazz.getAnnotation(WorkflowProperties.class) != null;
3232
boolean isCommandLineProgram = clazz.getAnnotation(CommandLineProgramProperties.class) != null;
33-
if (hasRuntimeProperties) {
33+
if (hasWorkflowProperties) {
3434
if (!isCommandLineProgram) {
3535
throw new DocException(String.format(
36-
"RuntimeProperties can only be applied to classes that are annotated with CommandLineProgramProperties (%s)",
36+
"WorkflowProperties can only be applied to classes that are annotated with CommandLineProgramProperties (%s)",
3737
clazz));
3838
}
3939
return true;

0 commit comments

Comments
 (0)