Skip to content

Commit

Permalink
Merged version 0.3.0 from development branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kvb2univpitt committed Dec 6, 2017
2 parents a7798d2 + 35219ec commit 026930b
Show file tree
Hide file tree
Showing 108 changed files with 3,260 additions and 66,641 deletions.
28 changes: 14 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.pitt.dbmi</groupId>
<artifactId>causal-cmd</artifactId>
<version>0.2.1</version>
<version>0.3.0</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -73,7 +73,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -119,25 +119,26 @@
<version>1.4</version>
</dependency>
<dependency>
<groupId>edu.pitt.dbmi</groupId>
<artifactId>data-reader</artifactId>
<version>0.2.1</version>
<groupId>edu.cmu</groupId>
<artifactId>tetrad-lib</artifactId>
<version>6.4.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>edu.cmu</groupId>
<artifactId>tetrad-lib</artifactId>
<version>6.3.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand All @@ -149,7 +150,6 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package edu.pitt.dbmi.causal.cmd.sim;
package edu.pitt.dbmi.causal.cmd;

/**
*
* Mar 10, 2017 12:55:49 PM
* Oct 2, 2017 10:45:47 AM
*
* @author Kevin V. Bui ([email protected])
*/
public enum DataSimulationType {
public class AlgorithmRunException extends Exception {

SEM_RAND_FWD("Sem-Random Foward Continuous Data Simulation", "sem-rand-fwd"),
BAYES_NET_RAND_FWD("Bayes Net-Random Foward Discrete Data Simulation", "bayes-net-rand-fwd"),
LEE_HASTIE("Lee-Hastie Mixed Data Simulation", "lee-hastie");
private static final long serialVersionUID = -1034221611736404899L;

private final String title;
public AlgorithmRunException() {
}

private final String cmd;
public AlgorithmRunException(String message) {
super(message);
}

private DataSimulationType(String title, String cmd) {
this.title = title;
this.cmd = cmd;
public AlgorithmRunException(String message, Throwable cause) {
super(message, cause);
}

public String getTitle() {
return title;
public AlgorithmRunException(Throwable cause) {
super(cause);
}

public String getCmd() {
return cmd;
public AlgorithmRunException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

}
174 changes: 42 additions & 132 deletions src/main/java/edu/pitt/dbmi/causal/cmd/CausalCmdApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@
*/
package edu.pitt.dbmi.causal.cmd;

import edu.pitt.dbmi.causal.cmd.algo.AlgorithmType;
import edu.pitt.dbmi.causal.cmd.algo.FGEScAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.algo.FGESdAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.algo.FGESmCGAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.algo.GFCIcAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.algo.GFCIdAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.algo.GFCImCGAlgorithmRunner;
import edu.pitt.dbmi.causal.cmd.sim.BayNetRandFwdDataSimulationRunner;
import edu.pitt.dbmi.causal.cmd.sim.DataSimulationType;
import edu.pitt.dbmi.causal.cmd.sim.LeeHastieDataSimulationRunner;
import edu.pitt.dbmi.causal.cmd.sim.SemRandFwdDataSimulationRunner;
import edu.pitt.dbmi.causal.cmd.util.AppUtils;
import edu.cmu.tetrad.latest.LatestClient;
import edu.pitt.dbmi.causal.cmd.tetrad.TetradRunner;
import edu.pitt.dbmi.causal.cmd.util.Application;
import edu.pitt.dbmi.causal.cmd.util.Args;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
Expand All @@ -45,133 +33,55 @@
*/
public class CausalCmdApplication {

private static final Options MAIN_OPTIONS = new Options();
private static final Logger LOGGER = LoggerFactory.getLogger(CausalCmdApplication.class);

private static final String ALGO_OPT = "algorithm";
private static final String SIM_DATA_OPT = "simulate-data";
private static final String VERSION_OPT = "version";

private static final Map<String, AlgorithmType> ALGO_TYPES = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
private static final Map<String, DataSimulationType> DATA_SIM_TYPES = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

static {
populateMainOptions();
populateCmdTypes();
}
public static final String FOOTER = "Use --help for guidance list of options. Use --help-all to show all options.";

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
if (Args.hasLongOption(args, VERSION_OPT)) {
System.out.println(AppUtils.jarTitle() + " version " + AppUtils.jarVersion());
args = Args.clean(args);
if (Args.hasLongParam(args, CmdParams.HELP)) {
try {
Application.showHelp(args, CmdParser.getHelpOptions(args), null);
} catch (CmdParserException exception) {
System.err.println(exception.getCause().getMessage());
Application.showHelp(args, exception.getParseOptions(), null);
}
} else if (Args.hasLongParam(args, CmdParams.HELP_ALL)) {
Application.showHelp(CmdOptions.getInstance().getOptions(), null);
} else if (Args.hasLongParam(args, CmdParams.VERSION)) {
System.out.println(Application.getVersion());
} else {
boolean algoOpt = Args.hasLongOption(args, ALGO_OPT);
boolean simDataOpt = Args.hasLongOption(args, SIM_DATA_OPT);
if (algoOpt ^ simDataOpt) {
if (algoOpt) {
String algorithm = Args.getOptionValue(args, ALGO_OPT);
if (algorithm == null) {
algorithm = "";
}
AlgorithmType algorithmType = ALGO_TYPES.get(algorithm);
if (algorithmType == null) {
showHelp();
} else {
args = Args.removeOption(args, ALGO_OPT);
switch (algorithmType) {
case FGESC:
new FGEScAlgorithmRunner().runAlgorithm(args);
break;
case FGESD:
new FGESdAlgorithmRunner().runAlgorithm(args);
break;
case FGESM_CG:
new FGESmCGAlgorithmRunner().runAlgorithm(args);
break;
case GFCIC:
new GFCIcAlgorithmRunner().runAlgorithm(args);
break;
case GFCID:
new GFCIdAlgorithmRunner().runAlgorithm(args);
break;
case GFCIM_CG:
new GFCImCGAlgorithmRunner().runAlgorithm(args);
}
}
} else {
String simulation = Args.getOptionValue(args, SIM_DATA_OPT);
DataSimulationType dataSimulationType = DATA_SIM_TYPES.get(simulation);
if (dataSimulationType == null) {
showHelp();
} else {
args = Args.removeOption(args, SIM_DATA_OPT);
switch (dataSimulationType) {
case BAYES_NET_RAND_FWD:
new BayNetRandFwdDataSimulationRunner().runDataSimulation(args);
break;
case SEM_RAND_FWD:
new SemRandFwdDataSimulationRunner().runDataSimulation(args);
break;
case LEE_HASTIE:
new LeeHastieDataSimulationRunner().runDataSimulation(args);
break;
}
}
}
} else {
showHelp();
CmdArgs cmdArgs = null;
try {
cmdArgs = CmdParser.parse(args);
} catch (CmdParserException exception) {
System.err.println(exception.getCause().getMessage());
Application.showHelp(args, exception.getParseOptions(), FOOTER);
}
}
}

private static void showHelp() {
AppUtils.showHelp(MAIN_OPTIONS, "Additional parameters are available when using --algorithm <arg> or --simulate-data <arg>.");
}

private static void populateCmdTypes() {
for (AlgorithmType type : AlgorithmType.values()) {
ALGO_TYPES.put(type.getCmd(), type);
}
for (DataSimulationType type : DataSimulationType.values()) {
DATA_SIM_TYPES.put(type.getCmd(), type);
}
}

private static void populateMainOptions() {
OptionGroup optGrp = new OptionGroup();
optGrp.addOption(new Option(null, ALGO_OPT, true, algorithmCmd()));
optGrp.addOption(new Option(null, SIM_DATA_OPT, true, simulationCmd()));
optGrp.setRequired(true);
MAIN_OPTIONS.addOptionGroup(optGrp);

MAIN_OPTIONS.addOption(null, VERSION_OPT, false, "Show software version.");
}

private static String algorithmCmd() {
StringBuilder algoOpt = new StringBuilder();
AlgorithmType[] types = AlgorithmType.values();
int lastIndex = types.length - 1;
for (int i = 0; i < lastIndex; i++) {
algoOpt.append(types[i].getCmd());
algoOpt.append(", ");
}
algoOpt.append(types[lastIndex].getCmd());
if (cmdArgs == null) {
System.exit(-1);
}

return algoOpt.toString();
}
if (!cmdArgs.isSkipLatest()) {
try {
LatestClient latestClient = LatestClient.getInstance();
String version = Application.jarVersion();
if (version == null) {
version = "DEVELOPMENT";
}
latestClient.checkLatest("causal-cmd", version);
System.out.println(latestClient.getLatestResult());
} catch (Exception exception) {
LOGGER.error("Unable to check for the latest version.", exception);
}
}

private static String simulationCmd() {
StringBuilder algoOpt = new StringBuilder();
DataSimulationType[] types = DataSimulationType.values();
int lastIndex = types.length - 1;
for (int i = 0; i < lastIndex; i++) {
algoOpt.append(types[i].getCmd());
algoOpt.append(", ");
TetradRunner.runTetrad(cmdArgs);
}
algoOpt.append(types[lastIndex].getCmd());

return algoOpt.toString();
}

}
Loading

0 comments on commit 026930b

Please sign in to comment.