diff --git a/src/leb/main/EzAAI.java b/src/leb/main/EzAAI.java index ff4b902..5e5f5ce 100644 --- a/src/leb/main/EzAAI.java +++ b/src/leb/main/EzAAI.java @@ -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 @@ -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) { @@ -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 @@ -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(); @@ -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(); @@ -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 { @@ -390,8 +411,8 @@ private int runCalculate() { // convert profiles into FASTA files List ilist = new ArrayList<>(), jlist = new ArrayList<>(); List 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; @@ -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); @@ -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)"); @@ -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(); } @@ -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"); @@ -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(); } diff --git a/src/leb/process/ProcCalcPairwiseAAI.java b/src/leb/process/ProcCalcPairwiseAAI.java index 9abaa34..7d8b7de 100644 --- a/src/leb/process/ProcCalcPairwiseAAI.java +++ b/src/leb/process/ProcCalcPairwiseAAI.java @@ -23,7 +23,6 @@ import leb.wrapper.DiamondWrapper; public class ProcCalcPairwiseAAI { - public static final String TMPDIR = "/tmp/"; public static final int MODE_DEFAULT = 3, MODE_BLASTP = 1, @@ -31,7 +30,9 @@ public class ProcCalcPairwiseAAI { 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; @@ -262,10 +263,10 @@ private List 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 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 hits_versa = procBlast.execute(faa2, faa1, GenericConfig.VERB); // Clean up stubs @@ -347,14 +348,14 @@ private List 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); @@ -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%+ @@ -421,7 +422,7 @@ private List 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."); @@ -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"); }