Skip to content

Commit

Permalink
Common: Use temporary directory when invoking circos
Browse files Browse the repository at this point in the history
  • Loading branch information
luan-n-nguyen committed Nov 25, 2024
1 parent 72b1d5f commit 4969e97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hmf-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -44,10 +48,22 @@ public Integer generateCircos(

LOGGER.info(String.format("generating " + outputFile + " via command: %s", String.join(" ", command)));

ProcessBuilder processBuilder = new ProcessBuilder(command);
Map<String, String> environment = processBuilder.environment();

// Circos writes the temporary file circos.colorlist. However, this file would be overwritten multiple times when invoking circos
// from multiple threads which results in a race condition. We make sure that circos writes to different temporary directories to
// avoid this race condition
Path tempDir = Files.createTempDirectory("circos");
environment.put("TMPDIR", tempDir.toString());

// must redirect error stream to stdout, as circos print some errors to stdout
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
Process process = processBuilder.redirectErrorStream(true).start();

int result = process.waitFor();

FileUtils.deleteDirectory(tempDir.toFile());

if(result != 0)
{
System.err.print(new String(process.getInputStream().readAllBytes()));
Expand Down

0 comments on commit 4969e97

Please sign in to comment.