Skip to content

Commit 535b7bd

Browse files
committed
analysis: write trace.txt in output directory, #TASK-6445
1 parent 9e0cf12 commit 535b7bd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

opencga-analysis/src/main/java/org/opencb/opencga/analysis/workflow/NextFlowExecutor.java

+21-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import org.slf4j.Logger;
3232
import org.slf4j.LoggerFactory;
3333

34-
import java.io.IOException;
35-
import java.io.UncheckedIOException;
34+
import java.io.*;
3635
import java.net.URL;
3736
import java.nio.file.Files;
3837
import java.nio.file.Path;
38+
import java.nio.file.Paths;
3939
import java.text.ParseException;
4040
import java.text.SimpleDateFormat;
4141
import java.util.*;
@@ -197,7 +197,7 @@ protected void run() throws Exception {
197197
Path nextflowConfigPath;
198198
if (nextflowConfig != null) {
199199
nextflowConfigPath = temporalInputDir.resolve("nextflow.config");
200-
Files.copy(nextflowConfig.openStream(), nextflowConfigPath);
200+
writeNextflowConfigFile(Paths.get(nextflowConfig.toURI()), nextflowConfigPath, outDirPath);
201201
dockerInputBindings.add(new AbstractMap.SimpleEntry<>(nextflowConfigPath.toString(), nextflowConfigPath.toString()));
202202
} else {
203203
throw new RuntimeException("Can't fetch nextflow.config file");
@@ -236,8 +236,8 @@ protected void run() throws Exception {
236236
// when nextflow runs on other dockers, we need to store those files in a path shared between the parent docker and the host
237237
dockerParams.put("-e", "HOME=" + temporalInputDir);
238238
dockerParams.put("-e", "OPENCGA_TOKEN=" + getExpiringToken());
239-
// Disable user param
240-
dockerParams.put("user", "");
239+
// Set user uid and guid to 1001
240+
dockerParams.put("user", "1001:1001");
241241

242242
// Execute docker image
243243
StopWatch stopWatch = StopWatch.createStarted();
@@ -257,6 +257,22 @@ protected void close() {
257257
deleteTemporalFiles();
258258
}
259259

260+
private void writeNextflowConfigFile(Path inputFile, Path outputFile, String outdirPath) {
261+
try (BufferedReader reader = Files.newBufferedReader(inputFile);
262+
BufferedWriter writer = Files.newBufferedWriter(outputFile)) {
263+
264+
String line;
265+
while ((line = reader.readLine()) != null) {
266+
// Replace occurrences of "$OUTPUT" with the replacement string
267+
line = line.replace("$OUTPUT", outdirPath);
268+
writer.write(line);
269+
writer.newLine();
270+
}
271+
} catch (IOException e) {
272+
throw new RuntimeException(e);
273+
}
274+
}
275+
260276
private void deleteTemporalFiles() {
261277
// Delete temporal files and folders created by nextflow
262278
try (Stream<Path> paths = Files.walk(getOutDir().resolve(".nextflow"))) {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
trace {
22
enabled = true
3-
file = '/data/output/trace.txt'
3+
file = '$OUTPUT/trace.txt'
44
overwrite = true
55
fields = 'task_id,hash,name,status,start,complete,%cpu,peak_vmem'
66
}

0 commit comments

Comments
 (0)