Skip to content

Commit

Permalink
customizable tmp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
endixk committed Jan 23, 2024
1 parent 1f58f87 commit cf7e102
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
56 changes: 41 additions & 15 deletions src/leb/main/EzAAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EzAAI(String module) {
}

// Argument variables
String input1 = null, output = null; // universal
String input1 = null, output = null, tmp = "/tmp"; // universal
boolean outExists = false;
boolean seqNucl = true; // convert
boolean multithread = false; // extract
Expand Down Expand Up @@ -115,6 +115,23 @@ private int parseArguments(String[] args) {
else Prompt.warning("Output file exists. Results will be overwritten.");
}
}
if(arg.get("-tmp") != null) {
tmp = arg.get("-tmp");
if((new File(tmp)).exists()) {
if(!(new File(tmp)).isDirectory()) {
Prompt.error("Invalid temporary directory given: " + tmp);
return -1;
}
else Prompt.talk("Using existing temporary directory: " + tmp);
}
else {
if((new File(tmp)).mkdirs()) Prompt.talk("Created temporary directory: " + tmp);
else {
Prompt.error("Failed to create temporary directory: " + tmp);
return -1;
}
}
}

if(module == MODULE_CONVERT) {
if(arg.get("-s") == null) {
Expand Down Expand Up @@ -249,7 +266,7 @@ private int runConvert() {

Prompt.print("Converting given CDS file into protein database... ("+input1+" -> "+output+")");
String hex = Long.toHexString(new Random().nextLong());
String faaPath = "/tmp/" + hex + ".faa";
String faaPath = tmp + File.separator + hex + ".faa";

try {
// copy input to temporary directory, translate if seq type is nucleotide
Expand All @@ -266,14 +283,18 @@ private int runConvert() {
bw.close();

// create databases
Shell.exec("mkdir /tmp/" + hex);
String dir = tmp + File.separator + hex;
if(!(new File(dir)).mkdirs()) {
Prompt.error("Failed to create temporary directory: " + dir);
return -1;
}
ProcFuncAnnoByMMSeqs2 procMmseqs = new ProcFuncAnnoByMMSeqs2();
procMmseqs.setMmseqsPath(path_mmseqs);
procMmseqs.executeCreateDb(faaPath, "/tmp/" + hex + "/mm");
procMmseqs.executeCreateDb(faaPath, dir + File.separator + "mm");

// create label info file
Prompt.debug("Writing file /tmp/" + hex + "/mm.label");
bw = new BufferedWriter(new FileWriter("/tmp/" + hex + "/mm.label"));
Prompt.debug("Writing file mm.label");
bw = new BufferedWriter(new FileWriter(dir + File.separator + "mm.label"));
bw.write(label + "\n");
bw.close();

Expand All @@ -282,12 +303,12 @@ private int runConvert() {
// create .db file
StringBuilder buf = new StringBuilder("tar -c -z -f " + "mm.tar.gz");
for(String name : names) buf.append(" ").append(name);
Shell.exec(buf.toString(), new File("/tmp/" + hex));
Shell.exec("mv /tmp/" + hex + "/mm.tar.gz " + output);
Shell.exec(buf.toString(), new File(dir));
Shell.exec("mv " + dir + File.separator + "mm.tar.gz " + output);

// remove temporary files
for(String name : names) (new File("/tmp/" + hex + "/" + name)).delete();
(new File("/tmp/" + hex)).delete();
for(String name : names) (new File(dir + File.separator + name)).delete();
(new File(dir)).delete();

// tidy up
(new File(faaPath)).delete();
Expand All @@ -304,14 +325,14 @@ private int runConvert() {

private int runExtract() {
Prompt.debug("EzAAI - extract module");
String gffFile = "/tmp/" + GenericConfig.SESSION_UID + ".gff",
String gffFile = tmp + File.separator + GenericConfig.SESSION_UID + ".gff",
faaFile = input1 + ".faa",
ffnFile = "/tmp/" + GenericConfig.SESSION_UID + ".ffn";
ffnFile = tmp + File.separator + GenericConfig.SESSION_UID + ".ffn";

try {
Prompt.print("Running prodigal on genome " + input1 + "...");
if(multithread) {
ProcParallelProdigal procProdigal = new ProcParallelProdigal(input1, faaFile, "/tmp/", path_ufasta, path_prodigal, thread);
ProcParallelProdigal procProdigal = new ProcParallelProdigal(input1, faaFile, tmp + File.separator, path_ufasta, path_prodigal, thread);
if(procProdigal.run() < 0) return -1;
}
else {
Expand Down Expand Up @@ -390,8 +411,8 @@ private int runCalculate() {
// convert profiles into FASTA files
List<String> ilist = new ArrayList<>(), jlist = new ArrayList<>();
List<String> ilabs = new ArrayList<>(), jlabs = new ArrayList<>();
File faaDir = new File("/tmp" + File.separator + GenericConfig.SESSION_UID + "_faa");
if(!faaDir.exists()) faaDir.mkdir();
File faaDir = new File(tmp + File.separator + GenericConfig.SESSION_UID + "_faa");
if(!faaDir.exists()) faaDir.mkdirs();
else if(!faaDir.isDirectory()) {
Prompt.error("Could not create temporary directory for FASTA files.");
return -1;
Expand Down Expand Up @@ -450,6 +471,7 @@ else if(!faaDir.isDirectory()) {
procAAI.setMode(ProcCalcPairwiseAAI.MODE_BLASTP);
break;
}
procAAI.setGlobaltmp(tmp);
procAAI.setNthread(thread);
procAAI.setIdentity(identity);
procAAI.setCoverage(coverage);
Expand Down Expand Up @@ -706,6 +728,7 @@ private static void printHelp(int module) {
System.out.println(ANSIHandler.wrapper(" Argument\tDescription", 'c'));
System.out.printf(" %s\t\t%s%n", "-l", "Taxonomic label for phylogenetic tree");
System.out.printf(" %s\t\t%s%n", "-t", "Number of CPU threads - multi-threading requires ufasta (default: 1)");
System.out.printf(" %s\t%s%n", "-tmp", "Custom temporary directory (default: /tmp)");
//System.out.println(String.format(" %s\t\t%s", " ", "https://github.com/gmarcais/ufasta"));
System.out.printf(" %s\t%s%n", "-prodigal", "Custom path to prodigal binary (default: prodigal)");
System.out.printf(" %s\t%s%n", "-mmseqs", "Custom path to MMSeqs2 binary (default: mmseqs)");
Expand All @@ -730,6 +753,7 @@ private static void printHelp(int module) {
System.out.println(ANSIHandler.wrapper("\n Additional options", 'y'));
System.out.println(ANSIHandler.wrapper(" Argument\tDescription", 'c'));
System.out.printf(" %s\t\t%s%n", "-l", "Taxonomic label for phylogenetic tree");
System.out.printf(" %s\t%s%n", "-tmp", "Custom temporary directory (default: /tmp)");
System.out.printf(" %s\t%s%n", "-mmseqs", "Custom path to MMSeqs2 binary (default: mmseqs)");
System.out.println();
}
Expand All @@ -752,6 +776,7 @@ private static void printHelp(int module) {
System.out.println(ANSIHandler.wrapper(" Argument\tDescription", 'c'));
System.out.printf(" %s\t%s%n", "-p ", "Customize calculation program [mmseqs / diamond / blastp] (default: mmseqs)");
System.out.printf(" %s\t%s%n", "-t ", "Number of CPU threads to use (default: 10)");
System.out.printf(" %s\t%s%n", "-tmp ", "Custom temporary directory (default: /tmp)");
System.out.printf(" %s\t%s%n", "-id ", "Minimum identity threshold for AAI calculations [0 - 1.0] (default: 0.4)");
System.out.printf(" %s\t%s%n", "-cov ", "Minimum query coverage threshold for AAI calculations [0 - 1.0] (default: 0.5)");
System.out.printf(" %s\t%s%n", "-match ", "Path to write a result of matched CDS names");
Expand Down Expand Up @@ -793,6 +818,7 @@ private static void printHelp(int module) {

System.out.println(ANSIHandler.wrapper("\n Additional options", 'y'));
System.out.println(ANSIHandler.wrapper(" Argument\tDescription", 'c'));
System.out.printf(" %s\t%s%n", "-tmp", "Custom temporary directory (default: /tmp)");
System.out.printf(" %s\t%s%n", "-mmseqs", "Custom path to MMSeqs2 binary (default: mmseqs)");
System.out.println();
}
Expand Down
21 changes: 11 additions & 10 deletions src/leb/process/ProcCalcPairwiseAAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
import leb.wrapper.DiamondWrapper;

public class ProcCalcPairwiseAAI {
public static final String TMPDIR = "/tmp/";
public static final int
MODE_DEFAULT = 3,
MODE_BLASTP = 1,
// MODE_USEARCH = 2,
MODE_MMSEQS = 3,
MODE_DIAMOND = 4,
MODE_DSENS = 5;


private String globaltmp = "/tmp/";
public void setGlobaltmp(String globaltmp) {this.globaltmp = globaltmp;}
private int mode = MODE_DEFAULT;
public void setMode(int mode) {this.mode = mode;}
private int nthread = 1;
Expand Down Expand Up @@ -262,10 +263,10 @@ private List<String> pairwiseBlastp(String faa1, String faa2) throws IOException
procBlast.executeMakeBlastDb(faa1, 1, GenericConfig.VERB);
procBlast.executeMakeBlastDb(faa2, 1, GenericConfig.VERB);
Prompt.print(String.format("Running BLASTp+... (%s vs. %s)", faa1, faa2));
procBlast.setOutFileName(TMPDIR + File.separator + GenericConfig.TEMP_HEADER + "vice.out");
procBlast.setOutFileName(globaltmp + File.separator + GenericConfig.TEMP_HEADER + "vice.out");
List<Blast6FormatHitDomain> hits_vice = procBlast.execute(faa1, faa2, GenericConfig.VERB);
Prompt.print(String.format("Running BLASTp+... (%s vs. %s)", faa2, faa1));
procBlast.setOutFileName(TMPDIR + File.separator + GenericConfig.TEMP_HEADER + "versa.out");
procBlast.setOutFileName(globaltmp + File.separator + GenericConfig.TEMP_HEADER + "versa.out");
List<Blast6FormatHitDomain> hits_versa = procBlast.execute(faa2, faa1, GenericConfig.VERB);

// Clean up stubs
Expand Down Expand Up @@ -347,14 +348,14 @@ private List<String> pairwiseMmseqs(String faa1, String faa2) throws IOException
if(path == null) path = "mmseqs";
procMmseqs.setMmseqsPath(path);

File mmout = new File(TMPDIR + GenericConfig.SESSION_UID + "_MM");
File mmout = new File(globaltmp + GenericConfig.SESSION_UID + "_MM");
if(!mmout.exists()) mmout.mkdir();
else if(!mmout.isDirectory()) {
Prompt.error("FATAL ERROR : MMSeqs2 output directory could not be created.");
return null;
}
String outDir = mmout.getAbsolutePath();
String tmpDir = TMPDIR + GenericConfig.SESSION_UID + "_tmp";
String tmpDir = globaltmp + GenericConfig.SESSION_UID + "_tmp";

procMmseqs.setThreads(nthread);
procMmseqs.setAlignmentMode(3);
Expand Down Expand Up @@ -394,8 +395,8 @@ else if(!mmout.isDirectory()) {

// Clean up stubs
if(!GenericConfig.KEEP) {
FileUtils.deleteDirectory(new File(TMPDIR + GenericConfig.SESSION_UID + "_MM"));
FileUtils.deleteDirectory(new File(TMPDIR + GenericConfig.SESSION_UID + "_tmp"));
FileUtils.deleteDirectory(new File(globaltmp + GenericConfig.SESSION_UID + "_MM"));
FileUtils.deleteDirectory(new File(globaltmp + GenericConfig.SESSION_UID + "_tmp"));
}

// Collect pairs with reciprocal hits with id 40%+, q_cov 50%+
Expand All @@ -421,7 +422,7 @@ private List<String> pairwiseDiamond(String faa1, String faa2, boolean sensitive
if(path == null) path = "diamond";
procDiamond.setDiamondPath(path);

File dmout = new File(TMPDIR + GenericConfig.SESSION_UID + "_DM");
File dmout = new File(globaltmp + GenericConfig.SESSION_UID + "_DM");
if(!dmout.exists()) dmout.mkdir();
else if(!dmout.isDirectory()) {
Prompt.error("FATAL ERROR : Diamond output directory could not be created.");
Expand All @@ -444,7 +445,7 @@ else if(!dmout.isDirectory()) {

// Clean up stubs
if(!GenericConfig.KEEP) {
FileUtils.deleteDirectory(new File(TMPDIR + GenericConfig.SESSION_UID + "_DM"));
FileUtils.deleteDirectory(new File(globaltmp + GenericConfig.SESSION_UID + "_DM"));
// FileUtils.deleteDirectory(TMPDIR + GenericConfig.SESSION_UID + "_tmp");
}

Expand Down

0 comments on commit cf7e102

Please sign in to comment.