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

Add ability to set Nextflow environment variables #13

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add possibility to set env variables for nextflow
  • Loading branch information
lukfor committed Oct 1, 2024
commit 90c031535ec24755f5c46cc6c00fb35f0e226a47
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ export default Control.extend({
var nextflowProfile = $('#nextflow-profile').val();
var nextflowConfig = $('#nextflow-config').val();
var nextflowWork = $('#nextflow-work').val();
var nextflowEnv = $('#nextflow-env').val();


this.application.attr('config').attr('nextflow.profile', nextflowProfile);
this.application.attr('config').attr('nextflow.config', nextflowConfig);
this.application.attr('config').attr('nextflow.work', nextflowWork);
this.application.attr('config').attr('nextflow.env', nextflowEnv);
this.application.save(function (data) {
bootbox.alert("Application settings updated.");
},
Expand Down
12 changes: 10 additions & 2 deletions src/main/html/webapp/components/admin/app/settings/settings.stache
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@
<input class="form-control" id="nextflow-work" name="nextflow-work" autocomplete="off" value="{{application.config.attr('nextflow.work')}}"/>

<br><p>Custom Configuration:<br>
<small class="text-muted">All hardware specific parameters can be set here. If you use the AWSBatch profile this is the place to set your credentials</small></p>
<small class="text-muted">All app-specific parameters can be set here.</small></p>

<div style=" display: flex;
justify-content: center;
align-items: center;
align-items: flex-start;
flex-direction: row;">

<div style=" width: 75%; align-self: stretch;">
<textarea class="form-control" id="nextflow-config" name="nextflow-config" style="height: 550px; font-size: 14px; font-family: SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;">{{application.config.attr('nextflow.config')}}</textarea>
<br>

<p>Custom Environment:<br>
<small class="text-muted">All app-specific environment variables can be set here.</small></p>

<textarea class="form-control" id="nextflow-env" name="nextflow-env" style="height: 550px; font-size: 14px; font-family: SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;">{{application.config.attr('nextflow.env')}}</textarea>

<br>

<div class="form-group">
<button id="save" class="btn btn-primary" data-loading-text="please wait..."><i class="far fa-save"></i> Save changes</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cloudgene/mapred/jobs/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public Environment addContext(CloudgeneContext context) {
add("JOB_PRIORITY", context.getJob().getPriority() + "");
add("JOB_SUBMITTED_ON", context.getJob().getSubmittedOn() + "");
}
add("JOB_LOCATION", context.getLocalTemp());
add("USER_NAME", context.getUser().getUsername());
add("USER_EMAIL", context.getUser().getMail());
add("USER_FULL_NAME", context.getUser().getFullName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class NextflowBinary {

private String name;

private File envScript;

public static NextflowBinary build(Settings settings) {
String binary = new BinaryFinder("nextflow").settings(settings, "nextflow", "home").env("NEXTFLOW_HOME")
.envPath().path("/usr/local/bin").find();
Expand Down Expand Up @@ -125,10 +127,17 @@ public void setName(String name) {
this.name = name;
}

public void setEnvScript(File envScript) {
this.envScript = envScript;
}

public List<String> buildCommand() {

List<String> nextflow = new Vector<String>();
nextflow.add("PATH=$PATH:/usr/local/bin");
if (envScript != null && envScript.exists()) {
nextflow.add("source " + envScript.getAbsolutePath() + ";");
}
nextflow.add(getBinary());

nextflow.add("-log");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class NextflowPlugin implements IPlugin {
public static final String ID = "nextflow";
public static final String NEXTFLOW_CONFIG = "nextflow.config";
public static final String NEXTFLOW_YAML = "nextflow.yaml";
public static final String NEXTFLOW_ENV = "nextflow.env";

private Settings settings;

Expand Down Expand Up @@ -82,6 +83,10 @@ public void updateConfig(WdlApp app, Map<String, String> config) throws IOExcept
writer.write(properties);
writer.close();

String nextflowEnv = FileUtil.path(appFolder, NEXTFLOW_ENV);
String contentEnv = config.get("nextflow.env");
StringBuffer contentNextflowEnv = new StringBuffer(contentEnv == null ? "" : contentEnv);
FileUtil.writeStringBufferToFile(nextflowEnv, contentNextflowEnv);
}

@Override
Expand Down Expand Up @@ -114,6 +119,12 @@ public Map<String, String> getConfig(WdlApp app) throws IOException {
config.put("nextflow.work", properties.get("work").toString());
}

String nextflowEnv = FileUtil.path(appFolder, NEXTFLOW_ENV);
if (new File(nextflowEnv).exists()) {
String content = FileUtil.readFileAsString(nextflowEnv);
config.put("nextflow.env", content);
}

return config;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public boolean run(WdlStep step, CloudgeneContext context) {
String appConfig = FileUtil.path(appFolder, "nextflow.config");
nextflow.addConfig(appConfig);

String appEnv = FileUtil.path(appFolder, "nextflow.env");
nextflow.setEnvScript(new File(appEnv));


// set work directory
IWorkspace workspace = job.getWorkspace();

Expand Down