Skip to content

Commit

Permalink
interactive mode fix
Browse files Browse the repository at this point in the history
  • Loading branch information
endixk committed Dec 13, 2022
1 parent bf4b6ad commit 01dd389
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
20 changes: 16 additions & 4 deletions src/envs/config/GenericConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static int setThreadPoolSize(String val) {
if(size < 1) {
ExceptionHandler.pass(size);
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}

if(size > CPU_COUNT) {
Expand Down Expand Up @@ -148,6 +149,7 @@ public static int setFastBlockSearchCutoff(String val) {
if(cutoff <= .0) {
ExceptionHandler.pass(cutoff);
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}

setFastBlockSearchCutoff(cutoff);
Expand All @@ -164,21 +166,24 @@ public static int setFastBlockSearchCutoff(String val) {
public static void setFastBlockSearchHits(int hits) {
FastBlockSearchHits = hits;
}
public static void setFastBlockSearchHits(String val) {
public static int setFastBlockSearchHits(String val) {
try {
Prompt.talk("Custom fastBlockSearch hits check : " + ANSIHandler.wrapper(val, 'B'));
int hits = Integer.parseInt(val);

if(hits <= 0) {
ExceptionHandler.pass(hits);
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}

setFastBlockSearchHits(hits);
return 0;
}
catch(NumberFormatException nfe) {
ExceptionHandler.pass(val + " (Integer value expected)");
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}
}

Expand Down Expand Up @@ -207,7 +212,7 @@ public static int setAugustusPredictionOffset(String val) {
}

public static double HmmsearchScoreCutoff = 100.0;
public static void setHmmsearchScoreCutoff(double cutoff) {
/* public static void setHmmsearchScoreCutoff(double cutoff) {
HmmsearchScoreCutoff = cutoff;
}
public static int setHmmsearchScoreCutoff(String val) {
Expand All @@ -218,6 +223,7 @@ public static int setHmmsearchScoreCutoff(String val) {
if(cutoff <= .0) {
ExceptionHandler.pass(cutoff);
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}
setHmmsearchScoreCutoff(cutoff);
Expand All @@ -228,27 +234,30 @@ public static int setHmmsearchScoreCutoff(String val) {
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}
}
} */

public static double EvalueCutoff = 1e-3;
public static void setEvalueCutoff(double cutoff) {
EvalueCutoff = cutoff;
}
public static void setEvalueCutoff(String val) {
public static int setEvalueCutoff(String val) {
try {
Prompt.talk("Custom e-value cutoff check : " + ANSIHandler.wrapper(val, 'B'));
double cutoff = Double.parseDouble(val);

if(cutoff <= .0) {
ExceptionHandler.pass(cutoff);
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}

setEvalueCutoff(cutoff);
return 0;
}
catch(NumberFormatException nfe) {
ExceptionHandler.pass(val + " (Floating point value expected)");
ExceptionHandler.handle(ExceptionHandler.INVALID_VALUE);
return 1;
}
}

Expand Down Expand Up @@ -532,6 +541,7 @@ public static int solveGeneset() {
}

if(!(NUC | PRO | BUSCO)) return 1; // invalid if nothing is detected
for(String pro : pros) if(!Character.isLetterOrDigit(pro.charAt(0))) return 1; // invalid if non-alphanumeric characters are detected
if(pros.size() > 0) FCG = Arrays.copyOf(pros.toArray(), pros.toArray().length, String[].class); // use custom proteins if detected
return 0;
}
Expand Down Expand Up @@ -561,6 +571,7 @@ public static int getBuscos() {
catch(java.io.IOException e) {
e.printStackTrace();
ExceptionHandler.handle(ExceptionHandler.EXCEPTION);
return 1;
}

// validate list using model directory
Expand All @@ -587,6 +598,7 @@ public static int getBuscos() {
catch(java.io.IOException e) {
e.printStackTrace();
ExceptionHandler.handle(ExceptionHandler.EXCEPTION);
return 1;
}

Prompt.talk("Number of BUSCOs to extract : " + ANSIHandler.wrapper(String.valueOf(BUSCOS.length), 'B'));
Expand Down
12 changes: 10 additions & 2 deletions src/envs/config/PathConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ public static int setOutputPath(String path) {
if(!output.canWrite()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
}
} else if(!output.mkdir()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
}
}
catch(Exception e) {
Expand Down Expand Up @@ -274,15 +276,17 @@ public static int setModelPath(String path) {
if(!output.exists()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
} else if(!output.canRead()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
}
}
catch(Exception e) {
e.printStackTrace();
ExceptionHandler.handle(ExceptionHandler.EXCEPTION);
return 2;
return 1;
}

ModelPath = path;
Expand Down Expand Up @@ -319,25 +323,29 @@ public static boolean checkModelPath() {

public static String SeqPath = EnvironmentPath + "config/seq/";
private static void renewSeqPath() {SeqPath = EnvironmentPath + "config/seq/";}
public static void setSeqPath(String path) {
public static int setSeqPath(String path) {
try {
Prompt.talk("Gene sequence directory check : " + ANSIHandler.wrapper(path, 'B'));
File output = new File(path);
if(!output.exists()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
} else if(!output.canRead()) {
ExceptionHandler.pass(path);
ExceptionHandler.handle(ExceptionHandler.INVALID_DIRECTORY);
return 1;
}
}
catch(Exception e) {
e.printStackTrace();
ExceptionHandler.handle(ExceptionHandler.EXCEPTION);
return 1;
}

SeqPath = path;
if(!SeqPath.endsWith("/")) SeqPath += "/";
return 0;
}
public static boolean checkSeqPath() {
int[] cnt = new int[GenericConfig.FCG.length];
Expand Down
66 changes: 50 additions & 16 deletions src/module/ProfileModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static int parseArgument(String[] args) throws ParseException {

opts.addOption("m", "metadata", true, "metadata path");
opts.addOption(null, "info", true, "single file metadata information");
opts.addOption("n", "intron", false, "include intron sequences");
opts.addOption("n", "exon", false, "exclude intron sequences");
opts.addOption(null, "modelpath", true, "gene profile path");
opts.addOption(null, "seqpath", true, "gene sequence path");
opts.addOption(null, "ppxcfg", true, "AUGUSTUS-PPX config path");
Expand Down Expand Up @@ -493,7 +493,7 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
if(buf.length() == 0) continue;
if(GenericConfig.setThreadPoolSize(buf) == 0) {
proceed = true;
command.append(" --thread ").append(buf);
command.append(" --thread ").append(GenericConfig.ThreadPoolSize);
}
}
proceed = false;
Expand Down Expand Up @@ -521,13 +521,30 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
proceed = false;

/* locate config/model directory; request custom folder if failed */
// --modelpath
String ptype = Shell.exec("file -b " + jarPath + "config/model/")[0];
// --seqpath
String ptype = Shell.exec("file -b " + jarPath + "config/seq/")[0];
boolean flag = ptype.contains("directory") && !ptype.contains("cannot");
if(!flag) {
Prompt.print("Default core gene profile directory not found.");
Prompt.print("Default core gene sequence database not found.");
while(!proceed) {
Prompt.print_nnc("Enter your custom core gene profile directory (--modelpath) : ");
Prompt.print_nnc("Enter your custom directory with core gene sequences (--seqpath) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(PathConfig.setSeqPath(buf) == 0) {
proceed = true;
command.append(" --seqpath ").append(buf);
}
}
proceed = false;
}

// --modelpath
ptype = Shell.exec("file -b " + jarPath + "config/model/")[0];
flag = ptype.contains("directory") && !ptype.contains("cannot");
if(!flag) {
Prompt.print("Default core gene model database not found.");
while(!proceed) {
Prompt.print_nnc("Enter your custom directory with core gene models (--modelpath) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(PathConfig.setModelPath(buf) == 0) {
Expand All @@ -539,9 +556,14 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
}

/* profile directory validation */
if(PathConfig.checkSeqPath()) {
ExceptionHandler.handle(ExceptionHandler.INVALID_SEQ_PATH);
Prompt.print("Please check the path and content of your core gene sequence directory and relaunch the program.\n");
System.exit(0);
}
if(PathConfig.checkModelPath()) {
ExceptionHandler.handle(ExceptionHandler.INVALID_MODEL_PATH);
Prompt.print("Please check the path and content of your core gene profile directory and relaunch the program.\n");
Prompt.print("Please check the path and content of your core gene model directory and relaunch the program.\n");
System.exit(0);
}

Expand Down Expand Up @@ -602,7 +624,7 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
// --verbose
while(!proceed) {
if(GenericConfig.VERB) break;
Prompt.print_nnc("Make the program chitty-chatty (--verbose)? (y/n) : ");
Prompt.print_nnc("Make the program chatty (--verbose)? (y/n) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(buf.startsWith("n") || buf.startsWith("N")) proceed = true;
Expand All @@ -629,15 +651,15 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
}
proceed = false;
*/
// --intron
// --exon
while(!proceed) {
Prompt.print_nnc("Include introns from predicted ORFs? (y/n) : ");
Prompt.print_nnc("Exclude introns from predicted ORFs (--exon)? (y/n) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(buf.startsWith("n") || buf.startsWith("N")) proceed = true;
if(buf.startsWith("y") || buf.startsWith("Y")) {
GenericConfig.INTRON = true;
command.append(" --intron ");
GenericConfig.INTRON = false;
command.append(" --exon ");
proceed = true;
}
}
Expand All @@ -654,6 +676,18 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
}
}
proceed = false;

// --fbshits
while(!proceed) {
Prompt.print_nnc("Enter the maximum number of hits to include from fastBlockSearch results (--fbshits, default = 5) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(GenericConfig.setFastBlockSearchHits(buf) == 0) {
proceed = true;
command.append(" --fbscutoff ").append(buf);
}
}
proceed = false;

// --augoffset
while(!proceed) {
Expand All @@ -667,14 +701,14 @@ else if(buf.startsWith("n") || buf.startsWith("N")) {
}
proceed = false;

// --hmmscore
// --evalue
while(!proceed) {
Prompt.print_nnc("Enter the score cutoff for hmmsearch validation (--hmmscore, default = 100.0) : ");
Prompt.print_nnc("Enter the E-value cutoff for validation (--evalue, default = 1e-3) : ");
buf = stream.readLine();
if(buf.length() == 0) continue;
if(GenericConfig.setHmmsearchScoreCutoff(buf) == 0) {
if(GenericConfig.setEvalueCutoff(buf) == 0) {
proceed = true;
command.append(" --hmmscore ").append(buf);
command.append(" --evalue ").append(buf);
}
}
proceed = false;
Expand Down

0 comments on commit 01dd389

Please sign in to comment.