Skip to content

Commit d45ac4d

Browse files
committed
bump to v1.0.3
1 parent ac8b31d commit d45ac4d

File tree

7 files changed

+218
-115
lines changed

7 files changed

+218
-115
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# bactopia/nf-bactopia: Changelog
22

3+
## v1.0.3
4+
5+
- Expose the config options
6+
37
## v1.0.2
48

59
- bump to latest nextflow gradle plugin version

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
implementation 'com.sanctionco.jmail:jmail:1.6.3' // Needed for e-mail format validation
1010
}
1111

12-
version = '1.0.2'
12+
version = '1.0.3'
1313

1414
nextflowPlugin {
1515
nextflowVersion = '25.10.0'
@@ -18,6 +18,7 @@ nextflowPlugin {
1818
description = 'A plugin for working with Bactopia'
1919
className = 'bactopia.plugin.BactopiaPlugin'
2020
extensionPoints = [
21+
'bactopia.plugin.BactopiaConfig',
2122
'bactopia.plugin.BactopiaExtension',
2223
'bactopia.plugin.BactopiaFactory'
2324
]

src/main/groovy/bactopia/plugin/BactopiaConfig.groovy

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package bactopia.plugin
22

33
import groovy.util.logging.Slf4j
44

5-
import nextflow.config.schema.ConfigOption
6-
import nextflow.config.schema.ConfigScope
7-
import nextflow.config.schema.ScopeName
5+
import nextflow.config.spec.ConfigOption
6+
import nextflow.config.spec.ConfigScope
7+
import nextflow.config.spec.ScopeName
88
import nextflow.script.dsl.Description
99

1010
/**
@@ -20,13 +20,23 @@ import nextflow.script.dsl.Description
2020
@Description('''
2121
The `bactopia` scope allows you to configure the `nf-bactopia` plugin.
2222
''')
23-
class BactopiaConfig implements ConfigScope {
23+
class BactopiaConfig implements ConfigScope {
2424

25+
@ConfigOption
26+
@Description('Enable monochrome logs.')
2527
final public Boolean monochromeLogs = false
2628

27-
final public CharSequence parametersSchema = "nextflow_schema.json"
29+
@ConfigOption
30+
@Description('Path to the parameters schema file.')
31+
final public CharSequence parametersSchema = "nextflow_schema.json"
32+
33+
@ConfigOption
34+
@Description('Ignore specific parameters.')
2835
final public Set<CharSequence> ignoreParams = [] // Defaults will be set on the Bactopia side
2936

37+
// Keep the no-arg constructor in order to be able to use the `@ConfigOption` annotation
38+
BactopiaConfig(){}
39+
3040
BactopiaConfig(Map map, Map params){
3141
def config = map ?: Collections.emptyMap()
3242

@@ -40,7 +50,7 @@ class BactopiaConfig implements ConfigScope {
4050
}
4151
}
4252

43-
// parameterSchema
53+
// parametersSchema
4454
if(config.containsKey("parametersSchema")) {
4555
if(config.parametersSchema instanceof CharSequence) {
4656
parametersSchema = config.parametersSchema

src/main/groovy/bactopia/plugin/BactopiaExtension.groovy

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -107,110 +107,6 @@ class BactopiaExtension extends PluginExtensionPoint {
107107
}
108108

109109

110-
//
111-
// Groovy Map of the help message
112-
//
113-
@Function
114-
public String paramsHelp() {
115-
def Map params = session.params
116-
def String help = ""
117-
def HelpMessageCreator helpCreator = new HelpMessageCreator(config, session, params["help_all"])
118-
help += helpCreator.getBeforeText(session, (String) params["workflow"]["name"], (String) params["workflow"]["description"])
119-
if (params["help_all"]) {
120-
log.debug("Printing out the full help message")
121-
help += helpCreator.getFullMessage()
122-
} else if (params["help"]) {
123-
log.debug("Printing out the short help message")
124-
def paramValue = null
125-
help += helpCreator.getShortMessage(paramValue instanceof String ? paramValue : "")
126-
}
127-
help += helpCreator.getAfterText()
128-
return help
129-
}
130-
131-
//
132-
// Groovy Map summarising parameters/workflow options used by the pipeline
133-
//
134-
@Function
135-
public Map paramsSummaryMap(
136-
Map options = null,
137-
WorkflowMetadata workflow
138-
) {
139-
def SummaryCreator creator = new SummaryCreator(config)
140-
return creator.getSummaryMap(
141-
options,
142-
workflow,
143-
session.baseDir.toString(),
144-
session.params
145-
)
146-
}
147-
148-
/*
149-
* Beautify parameters for summary and return as string
150-
*/
151-
@Function
152-
public String paramsSummaryLog(
153-
Map options = null,
154-
WorkflowMetadata workflow
155-
) {
156-
def Map params = session.params
157-
def String schemaFilename = options?.containsKey('parameters_schema') ? options.parameters_schema as String : config.parametersSchema
158-
159-
def colors = getLogColors(config.monochromeLogs)
160-
String output = ''
161-
output += getLogo(workflow, config.monochromeLogs, params.workflow.name, params.workflow.description)
162-
163-
def Map paramsMap = paramsSummaryMap(workflow, parameters_schema: schemaFilename)
164-
paramsMap.each { key, value ->
165-
paramsMap[key] = flattenNestedParamsMap(value as Map)
166-
}
167-
def maxChars = getLongestKeyLength(paramsMap)
168-
for (group in paramsMap.keySet()) {
169-
def Map group_params = paramsMap.get(group) as Map // This gets the parameters of that particular group
170-
if (group_params) {
171-
output += "$colors.bold$group$colors.reset\n"
172-
for (String param in group_params.keySet()) {
173-
output += " " + colors.blue + param.padRight(maxChars) + ": " + colors.green + group_params.get(param) + colors.reset + '\n'
174-
}
175-
output += '\n'
176-
}
177-
}
178-
output += "!! Only displaying parameters that differ from the defaults !!\n"
179-
output += dashedLine(config.monochromeLogs) + "\n"
180-
return output
181-
}
182-
183-
/*
184-
* Beautify parameters for summary and return as string
185-
*/
186-
@Function
187-
public String workflowSummary() {
188-
def Map params = session.params
189-
def WorkflowMetadata metadata = session.getWorkflowMetadata()
190-
return getWorkflowSummary(
191-
metadata,
192-
params,
193-
session.config.manifest.version,
194-
config.monochromeLogs,
195-
)
196-
}
197-
198-
private Map flattenNestedParamsMap(Map paramsMap) {
199-
def Map returnMap = [:]
200-
paramsMap.each { param, value ->
201-
def String key = param as String
202-
if (value instanceof Map) {
203-
def Map flatMap = flattenNestedParamsMap(value as Map)
204-
flatMap.each { flatParam, flatValue ->
205-
returnMap.put(key + "." + flatParam, flatValue)
206-
}
207-
} else {
208-
returnMap.put(key, value)
209-
}
210-
}
211-
return returnMap
212-
}
213-
214110
/*
215111
* Function to loop over all parameters defined in schema and check
216112
* whether the given parameters adhere to the specifications

src/main/groovy/bactopia/plugin/BactopiaFactory.groovy

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package bactopia.plugin
1818

1919
import groovy.transform.CompileStatic
20+
2021
import nextflow.Session
2122
import nextflow.trace.TraceObserverV2
2223
import nextflow.trace.TraceObserverFactoryV2
@@ -32,8 +33,13 @@ class BactopiaFactory implements TraceObserverFactoryV2 {
3233

3334
@Override
3435
Collection<TraceObserverV2> create(Session session) {
35-
final result = new ArrayList()
36-
result.add( new BactopiaObserver() )
36+
final result = new ArrayList<TraceObserverV2>()
37+
result.add(
38+
new BactopiaObserver(
39+
session,
40+
new BactopiaConfig(session?.config?.navigate('bactopia') as Map, session.params)
41+
)
42+
)
3743
return result
3844
}
3945
}

src/main/groovy/bactopia/plugin/BactopiaObserver.groovy

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ import groovy.transform.CompileStatic
2020
import groovy.util.logging.Slf4j
2121
import java.nio.file.Path
2222
import java.nio.file.Paths
23+
2324
import nextflow.Session
25+
import nextflow.script.WorkflowMetadata
2426
import nextflow.trace.TraceObserverV2
2527

28+
import bactopia.plugin.BactopiaConfig
2629
import static bactopia.plugin.BactopiaMotD.getMotD
30+
import static bactopia.plugin.BactopiaTemplate.getWorkflowSummary
31+
import static bactopia.plugin.BactopiaUtils.paramsHelp
32+
import static bactopia.plugin.BactopiaUtils.paramsSummaryLog
33+
import static bactopia.plugin.BactopiaUtils.validateParameters
2734

2835
/**
2936
* Bactopia workflow observer
@@ -34,11 +41,47 @@ import static bactopia.plugin.BactopiaMotD.getMotD
3441
@Slf4j
3542
class BactopiaObserver implements TraceObserverV2 {
3643

44+
private Session session
45+
BactopiaConfig config
46+
47+
BactopiaObserver(
48+
Session session,
49+
BactopiaConfig config
50+
) {
51+
this.session = session
52+
this.config = config
53+
}
54+
3755
@Override
38-
void onFlowCreate(Session session) {}
56+
void onFlowCreate(Session session) {
57+
def Map params = this.session.params
58+
def WorkflowMetadata metadata = this.session.getWorkflowMetadata()
59+
if (params["help"] || params["help_all"]) {
60+
println paramsHelp(session, config)
61+
System.exit(0)
62+
} else {
63+
// print params summary
64+
println paramsSummaryLog(
65+
metadata,
66+
this.session,
67+
this.config,
68+
null
69+
)
70+
}
71+
}
3972

4073
@Override
41-
void onFlowComplete() {}
74+
void onFlowComplete() {
75+
def Map params = this.session.params
76+
def WorkflowMetadata metadata = this.session.getWorkflowMetadata()
77+
println getWorkflowSummary(
78+
metadata,
79+
params,
80+
this.session.config.manifest.version,
81+
this.config.monochromeLogs,
82+
)
83+
84+
}
4285

4386
void onWorkflowPublish(String name, Object value) {}
4487
void onFilePublish(Path destination, Path source, Map annotations) {}

0 commit comments

Comments
 (0)