use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class AncestralSequenceAnnotator method main.
//Main method
public static void main(String[] args) throws IOException {
String targetTreeFileName = null;
String inputFileName = null;
String outputFileName = null;
printTitle();
Arguments arguments = new Arguments(new Arguments.Option[] { //new Arguments.StringOption("target", new String[] { "maxclade", "maxtree" }, false, "an option of 'maxclade' or 'maxtree'"),
new Arguments.StringOption("heights", new String[] { "keep", "median", "mean" }, false, "an option of 'keep', 'median' or 'mean'"), new Arguments.IntegerOption("burnin", "the number of states to be considered as 'burn-in'"), new Arguments.StringOption("beastInput", new String[] { "true", "false" }, false, "If the input is taken from BEAST rather than BAli-Phy"), new Arguments.RealOption("limit", "the minimum posterior probability for a node to be annotated"), new Arguments.StringOption("target", "target_file_name", "specifies a user target tree to be annotated"), new Arguments.Option("help", "option to print this message"), new Arguments.StringOption("kalign", "full_path_to_kalign", "specifies full path to the kalign executable file") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println(ae);
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption("help")) {
printUsage(arguments);
System.exit(0);
}
int heights = KEEP_HEIGHTS;
if (arguments.hasOption("heights")) {
String value = arguments.getStringOption("heights");
if (value.equalsIgnoreCase("mean")) {
heights = MEAN_HEIGHTS;
} else if (value.equalsIgnoreCase("median")) {
heights = MEDIAN_HEIGHTS;
}
}
int burnin = -1;
if (arguments.hasOption("burnin")) {
burnin = arguments.getIntegerOption("burnin");
}
double posteriorLimit = 0.0;
if (arguments.hasOption("limit")) {
posteriorLimit = arguments.getRealOption("limit");
}
boolean beastInput = false;
if (arguments.hasOption("beastInput") && arguments.getStringOption("beastInput").equals("true")) {
SEQ_STRING = "states";
}
int target = MAX_CLADE_CREDIBILITY;
if (arguments.hasOption("target")) {
target = USER_TARGET_TREE;
targetTreeFileName = arguments.getStringOption("target");
}
// String kalignExecutable = "/usr/local/bin/clustalw";
String kalignExecutable = "/usr/local/bin/kalign";
if (arguments.hasOption("kalign")) {
kalignExecutable = arguments.getStringOption("kalign");
}
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 2) {
System.err.println("Unknown option: " + args2[2]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
if (args2.length == 2) {
targetTreeFileName = null;
inputFileName = args2[0];
outputFileName = args2[1];
} else {
if (inputFileName == null) {
// No input file name was given so throw up a dialog box...
inputFileName = Utils.getLoadFileName("AncestralSequenceAnnotator " + version.getVersionString() + " - Select input file file to analyse");
}
if (outputFileName == null) {
outputFileName = Utils.getSaveFileName("AncestralSequenceAnnotator " + version.getVersionString() + " - Select output file");
}
}
if (inputFileName == null || outputFileName == null) {
System.err.println("Missing input or output file name");
printUsage(arguments);
System.exit(1);
}
new AncestralSequenceAnnotator(burnin, heights, posteriorLimit, target, targetTreeFileName, inputFileName, outputFileName, kalignExecutable);
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class RootToTip method main.
//Main method
public static void main(String[] args) throws IOException {
String inputFileName = null;
String outputFileName = null;
printTitle();
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption("burnin", "the number of trees to be ignored as 'burn-in' [default = 0]"), new Arguments.StringOption("dateorder", "date_order", "order of date field in taxon name: first, last, 1, 2 etc. [default = last]"), // new Arguments.StringOption("outgroup", "{taxon list}", "one or more taxa that will be used to root the tree(s) [default = find root]"),
new Arguments.Option("keeproot", "keep the existing root of the input trees [default = estimate root]"), new Arguments.Option("writetree", "Write the optimally rooted tree to the output file"), new Arguments.Option("help", "option to print this message") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println(ae);
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption("help")) {
printUsage(arguments);
System.exit(0);
}
int burnin = 0;
if (arguments.hasOption("burnin")) {
burnin = arguments.getIntegerOption("burnin");
}
String dateOrder = "LAST";
if (arguments.hasOption("dateorder")) {
dateOrder = arguments.getStringOption("dateorder").toUpperCase();
}
String outgroup = null;
if (arguments.hasOption("outgroup")) {
outgroup = arguments.getStringOption("dateorder").toUpperCase();
}
boolean keepRoot = arguments.hasOption("keeproot");
boolean writeTree = arguments.hasOption("writetree");
String[] args2 = arguments.getLeftoverArguments();
if (args2.length > 2) {
System.err.println("Unknown option: " + args2[2]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
if (args2.length == 0) {
System.err.println("Missing input file name");
printUsage(arguments);
System.exit(1);
}
inputFileName = args2[0];
if (args2.length == 2) {
outputFileName = args2[1];
}
new RootToTip(burnin, dateOrder, keepRoot, outgroup, writeTree, inputFileName, outputFileName);
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class CheckPointUpdaterApp method main.
public static void main(String[] args) throws java.io.IOException {
// There is a major issue with languages that use the comma as a decimal separator.
// To ensure compatibility between programs in the package, enforce the US locale.
Locale.setDefault(Locale.US);
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption("BEAST_XML", "FILENAME", "Specify a BEAST XML file"), new Arguments.StringOption("load_dump", "FILENAME", "Specify a filename to load a dumped state from"), new Arguments.StringOption("output_file", "FILENAME", "Specify a filename for the output file"), new Arguments.StringOption("update_choice", "UPDATECHOICE", "Specify a function by which to update the tree"), new Arguments.Option("help", "Print this information and stop") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
System.out.println();
System.out.println(ae.getMessage());
System.out.println();
//printUsage(arguments);
System.exit(1);
}
String inputFile = null;
if (arguments.hasOption("BEAST_XML")) {
inputFile = arguments.getStringOption("BEAST_XML");
} else {
throw new RuntimeException("No BEAST XML file specified.");
}
String debugStateFile;
if (arguments.hasOption("load_dump")) {
debugStateFile = arguments.getStringOption("load_dump");
//pass on as argument
System.setProperty(BeastCheckpointer.LOAD_STATE_FILE, debugStateFile);
} else {
throw new RuntimeException("No dump file specified.");
}
String choice = "";
if (arguments.hasOption("update_choice")) {
choice = arguments.getStringOption("update_choice");
} else {
throw new RuntimeException("Update mechanism needs to be specified.");
}
UpdateChoice chosen = null;
for (UpdateChoice ch : UpdateChoice.values()) {
if (choice.equals(ch.getName())) {
chosen = ch;
break;
}
}
if (chosen == null) {
throw new RuntimeException("Incorrect update mechanism specified.");
}
if (arguments.hasOption("output_file")) {
String outputStateFile = arguments.getStringOption("output_file");
//pass on as argument
System.setProperty(BeastCheckpointer.SAVE_STATE_FILE, outputStateFile);
} else {
throw new RuntimeException("No output file specified.");
}
new CheckPointUpdaterApp(inputFile, debugStateFile, chosen);
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class RateIndicatorBF method main.
public static void main(String[] args) throws IOException {
String inputFileName = null;
String outputFileName = null;
String locationsFileName = null;
String[][] locations = null;
boolean kml = false;
boolean calculateRates = false;
//red: 0000FF green: 00FF00 magenta: FF00FF white: FFFFFF yellow: 00FFFF cyan: FFFF00
String lowerLinkColor = "FFFFFF";
String upperLinkColor = "FF00FF";
String KMLoutputFile = "KMLrates.kml";
double branchWidthConstant = 2.5;
double branchWidthMultiplier = 7.0;
double altitudeFactor = 500;
//Double width = 3.0;
int burnin = -1;
double meanPoissonPrior = 0.693;
int offsetPoissonPrior = 0;
int numberOfStates = 0;
double cutoff = 3.0;
// if false, we will use an indicator cut off value
boolean bayesFactor = true;
boolean rateSummary = false;
String rateIndicatorString = "indicators";
String actualRateString = "actualRates";
String relativeRateString = "rates";
String frequencyString = "frequencies";
//this is for rate (dist/time) summaries
String clockRateString = "clock.rate";
String unitString = "year";
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.IntegerOption(BURNIN, "the number of states to be considered as 'burn-in' " + "[default = 0]"), new Arguments.StringOption(LOCATIONSFILE, "coordinates file", "a file with latitudes and " + "longitudes for each location (required for a kml output)"), //boolean for KML
new Arguments.StringOption(KML, falseTrue, false, "generate a KML file including well-supported rates [default = false]"), new Arguments.StringOption(CALCULATERATES, falseTrue, false, "calculate the actual rates for well-supported transitions"), new Arguments.IntegerOption(LOCATIONSTATES, "the number of locations states used in the " + "analyses [requires a coordinates file if not provided]"), new Arguments.IntegerOption(POFFSET, "the offset of the (truncated) Poisson prior " + "[default=locations-1]"), new Arguments.RealOption(PMEAN, "the mean of the (truncated) Poisson prior " + "[default=0.693 (log2)]"), new Arguments.RealOption(BFCUTOFF, "the Bayes Factor values above which we consider rates to " + "be well supported [default=3.0]"), new Arguments.RealOption(ICUTOFF, "the indicator values above which we consider rates to be " + "well supported [default uses a Bayes factor cut off of 3.0]"), new Arguments.StringOption(ISTRING, "indicator_string", "prefix string used for outputting " + "the rate indicators in the log file [default = indicators]"), new Arguments.StringOption(RSTRING, "relativeRate_string", "prefix string used for " + "outputting the relative rates in the log file [default = rates]"), new Arguments.StringOption(FSTRING, "frequencies_string", "prefix string used for outputting " + "the state frequencies in the log file [default = frequencies]"), new Arguments.StringOption(PSTRING, "rate*indicator_string", "prefix string used for " + "outputting the product statistic for rates*indicators [default = actualRates]"), new Arguments.StringOption(CSTRING, "clock_rate_string", "string used for outputting " + "the overall clock rate in the log file [default = clock.rate]"), new Arguments.StringOption(USTRING, "units_string", "string describing the time unit" + "[default = year]"), new Arguments.StringOption(KMLFILE, "KML output file", "KML output file name " + "[default=KMLrates.kml]"), new Arguments.StringOption(LOWCOLOR, "lower link strength color", "specifies an lower link " + "color for the links [default=FF00FF]"), new Arguments.StringOption(UPCOLOR, "upper link strength color", "specifies an upper link " + "color for the links [default=FFFF00]"), new Arguments.RealOption(BWC, "specifies the connection (rate) width constant [default=2.5]"), new Arguments.RealOption(BWM, "specifies the connection (rate) width multiplier [default=7.0]"), new Arguments.RealOption(ALTITUDE, "specifies the altitude factor for the connections (rate) " + "[default=500]") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
progressStream.println(ae);
printUsage(arguments);
System.exit(1);
}
if (arguments.hasOption(HELP)) {
printUsage(arguments);
System.exit(0);
}
if (arguments.hasOption(BURNIN)) {
burnin = arguments.getIntegerOption(BURNIN);
}
progressStream.println("Ignoring " + burnin + " states as burn-in");
if (arguments.hasOption(LOCATIONSTATES)) {
numberOfStates = arguments.getIntegerOption(LOCATIONSTATES);
}
locationsFileName = arguments.getStringOption(LOCATIONSFILE);
if (locationsFileName != null) {
int[] counts = countLinesAndTokens(locationsFileName);
//read in locations
if (numberOfStates > 0) {
if (numberOfStates != counts[0]) {
System.err.println("number of states provided (" + numberOfStates + ") does not match lines in coordinates file (" + counts[0] + ") ??");
}
}
locations = new String[counts[0]][counts[1]];
readLocationsCoordinates(locationsFileName, locations);
if (numberOfStates == 0) {
numberOfStates = counts[0];
}
} else {
if (numberOfStates == 0) {
System.err.println("no states provided, nor coordinates file ??");
}
}
String kmlBooleanString = arguments.getStringOption(KML);
if (kmlBooleanString != null && kmlBooleanString.compareToIgnoreCase("true") == 0) {
kml = true;
if (locationsFileName == null) {
System.err.println("you want a KML file without a coordinates file??");
}
}
String ratesBooleanString = arguments.getStringOption(CALCULATERATES);
if (ratesBooleanString != null && ratesBooleanString.compareToIgnoreCase("true") == 0) {
calculateRates = true;
}
String kmlFileName = arguments.getStringOption(KMLFILE);
if (kmlFileName != null) {
KMLoutputFile = kmlFileName;
}
if (arguments.hasOption(PMEAN)) {
meanPoissonPrior = arguments.getRealOption(PMEAN);
progressStream.println("Poisson prior with mean " + meanPoissonPrior);
} else {
progressStream.println("Poisson prior with mean " + meanPoissonPrior + " (default)");
}
if (arguments.hasOption(POFFSET)) {
offsetPoissonPrior = arguments.getIntegerOption(POFFSET);
progressStream.println("Poisson offset = " + offsetPoissonPrior);
} else {
offsetPoissonPrior = numberOfStates - 1;
progressStream.println("Poisson offset = " + offsetPoissonPrior + " (locations - 1)");
}
if (arguments.hasOption(BFCUTOFF)) {
cutoff = arguments.getRealOption(BFCUTOFF);
}
if (arguments.hasOption(ICUTOFF)) {
cutoff = arguments.getRealOption(ICUTOFF);
bayesFactor = false;
}
if (bayesFactor) {
progressStream.println("Bayes factor cutoff = " + cutoff);
} else {
progressStream.println("indicator factor cutoff = " + cutoff);
}
if (arguments.hasOption(BWC)) {
branchWidthConstant = arguments.getRealOption(BWC);
}
if (arguments.hasOption(BWM)) {
branchWidthMultiplier = arguments.getRealOption(BWM);
}
if (arguments.hasOption(ALTITUDE)) {
altitudeFactor = arguments.getRealOption(ALTITUDE);
}
String indicatorString = arguments.getStringOption(ISTRING);
if (indicatorString != null) {
rateIndicatorString = indicatorString;
}
String rateString = arguments.getStringOption(PSTRING);
if (rateString != null) {
actualRateString = rateString;
}
String freqString = arguments.getStringOption(FSTRING);
if (freqString != null) {
frequencyString = freqString;
}
String relRateString = arguments.getStringOption(RSTRING);
if (relRateString != null) {
relativeRateString = relRateString;
}
String clockString = arguments.getStringOption(CSTRING);
if (clockString != null) {
clockRateString = clockString;
}
String color1String = arguments.getStringOption(LOWCOLOR);
if (color1String != null) {
lowerLinkColor = color1String;
if (locationsFileName == null) {
System.err.print("color string but no coordinates file for KML output??");
}
}
String color2String = arguments.getStringOption(UPCOLOR);
if (color2String != null) {
upperLinkColor = color2String;
if (locationsFileName == null) {
System.err.print("color string but no coordinates file for KML output??");
}
}
final String[] args2 = arguments.getLeftoverArguments();
switch(args2.length) {
case 0:
printUsage(arguments);
System.exit(1);
case 2:
outputFileName = args2[1];
// fall to
case 1:
inputFileName = args2[0];
break;
default:
{
System.err.println("Unknown option: " + args2[2]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
}
RateIndicatorBF rateIndicatorBF = new RateIndicatorBF(inputFileName, burnin, rateIndicatorString, numberOfStates, locations, bayesFactor, cutoff, meanPoissonPrior, offsetPoissonPrior, actualRateString, relativeRateString, frequencyString, clockRateString, unitString, calculateRates);
rateIndicatorBF.outputTextFile(outputFileName);
if (kml) {
rateIndicatorBF.outputKML(KMLoutputFile, lowerLinkColor, upperLinkColor, branchWidthConstant, branchWidthMultiplier, altitudeFactor);
}
System.exit(0);
}
use of dr.app.util.Arguments in project beast-mcmc by beast-dev.
the class DiscreteTreeToKML method main.
public static void main(String[] args) throws Arguments.ArgumentException {
String inputFileName = null;
String outputFileName = null;
RootedTree tree = null;
String[][] locations = null;
String stateAnnotation = "state";
//in case trees are scaled in other time units
double timeScaler = 1;
// the width of branches will be stateProbability*branchWidthMultiplier+branchWidthConstant
double branchWidthConstant = 2.0;
double branchWidthMultiplier = 5.0;
// this is to chop up the branches of the surface tree in 'divider' segments
double divider = 100;
// use state probabilities for branch width
boolean useStateProbability = true;
// branch width if posterior probabilities are not used
double branchWidth = 10.0;
// use posterior probabilities to color branch
boolean usePosterior = false;
// use heights (time) to color branches
boolean useHeights = true;
//red: 0000FF green: 00FF00 magenta: FF00FF white: FFFFFF yellow: 00FFFF cyan: FFFF00
String startBranchColor = "FF00FF";
String endBranchColor = "FFFF00";
// branch color if color range based on rates is not used
String branchColor = "ffffff";
// branches are arcs with heights proportional to the distance between locations
boolean arcBranches = true;
// the height of the arcs is proportional to the time the branch spans, by default arch-heights are proportional to the distance between locations
boolean arcTimeHeight = false;
// this is the factor with which to multiply the time of the branch to get the altitude for that branch in the surface Tree
double altitudeFactor = 100;
boolean temporary = false;
// required to convert heights to calendar dates
double mostRecentDate = 2010;
//circles
int numberOfIntervals = 100;
//boolean autoRadius = false;
double radius = 0;
String circleOpacity = "8F";
//extra coordinates for some taxa
boolean coordinatesForTaxa = false;
String[][] taxaCoordinates = null;
//tree slices for google maps, requires treeHeight in exporterString: e.g., exporterString.writeTreeToKML(0.025);
//TODO: have this outputed to a different file (what happens now)?
boolean makeTreeSlices = false;
double[] sliceTimes = null;
double treeSliceBranchWidth = 3;
// shows complete branch for slice if time is more recent than the branch's midpoint
boolean showBranchAtMidPoint = false;
Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption(COORDINATES, "coordinate file", "specifies a tab-delimited file with coordinates for the locations"), new Arguments.StringOption(ANNOTATION, "location state annotation string", "specifies the string used for location state annotation [default=state]"), new Arguments.RealOption(TIMESCALER, "specifies the scaling factor by which to rescale time [default=1]"), new Arguments.RealOption(MRSD, "specifies the most recent sampling data in fractional years to rescale time [default=2010]"), new Arguments.RealOption(BWC, "specifies the branch width constant [default=2]"), new Arguments.RealOption(BWM, "specifies the branch width multiplier [default=5]"), new Arguments.StringOption(USP, falseTrue, false, "use state probabilities for branch width [default = true]"), new Arguments.StringOption(BCUSE, use, false, "use heights or posterior probabilities for branch colors [default = heights]"), new Arguments.RealOption(BW, "specifies the branch width if posterior probabilities are not used [default=10]"), new Arguments.IntegerOption(DIVIDER, "specifies in how many segments at branch should be chopped up [default=50]"), new Arguments.StringOption(BSTARTCOLOR, "branch start color", "specifies a starting color for the branches [default=FF00FF]"), new Arguments.StringOption(BENDCOLOR, "branch end color", "specifies an end color for the branches [default=FFFF00]"), new Arguments.StringOption(BCOLOR, "branch color", "specifies a branch color if color range based on rates is not used [default=ffffff]"), new Arguments.StringOption(ARCHBRANCH, falseTrue, false, "use arcs for the branches [default = true], by default arc-heights are proportional to the distance between locations"), new Arguments.StringOption(ARCHHEIGHT, arch, false, "use time or distance for arch heights [default = no arcs]"), new Arguments.RealOption(ALTITUDE, "specifies the altitudefactor for the branches [default=1000]"), new Arguments.StringOption(TEMP, falseTrue, false, "display branches only temporary [default=false"), new Arguments.IntegerOption(CIRCLESEGMENTS, "specifies the number of segments to construct circles [default=100]"), new Arguments.IntegerOption(RADIUS, "specifies the radiusfactor for the circles [default='autoradius']"), new Arguments.StringOption(CIRCLEOP, "circle opacity", "sets the opacity of the circles [default=8F]"), new Arguments.Option(HELP, "option to print this message"), new Arguments.StringOption(COORDSFORTAXA, "file with taxa coords", "specifies a file with additional coordinates for particular taxa"), new Arguments.RealOption(SLICEBW, "specifies the branch width for tree slices [default=3]"), new Arguments.StringOption(SLICES, "time", "specifies a slice time-list [default=none]"), new Arguments.StringOption(SLICEMIDPOINT, falseTrue, false, "shows complete branch for sliced tree if time is more recent than the branch's midpoint [default=false") });
try {
arguments.parseArguments(args);
} catch (Arguments.ArgumentException ae) {
progressStream.println(ae);
printUsage(arguments);
System.exit(1);
}
if (args.length == 0 || arguments.hasOption(HELP)) {
printUsage(arguments);
System.exit(0);
}
try {
String coordinatesFileString = arguments.getStringOption(COORDINATES);
//System.out.println(coordinatesFileString);
if (coordinatesFileString != null) {
// count lines in locations file and tokens per line
int[] counts = countLinesAndTokens(coordinatesFileString);
//System.out.println(counts[0]+"\t"+counts[1]);
//read in locations
locations = new String[counts[0]][counts[1]];
readLocationsCoordinates(coordinatesFileString, locations);
} else {
progressStream.println("no coordinates for taxa??");
System.exit(1);
}
if (arguments.hasOption(MRSD)) {
mostRecentDate = arguments.getRealOption(MRSD);
}
if (arguments.hasOption(TIMESCALER)) {
timeScaler = arguments.getRealOption(TIMESCALER);
}
if (arguments.hasOption(DIVIDER)) {
divider = arguments.getRealOption(DIVIDER);
}
if (arguments.hasOption(ALTITUDE)) {
altitudeFactor = arguments.getRealOption(ALTITUDE);
}
String stateAnnotationString = arguments.getStringOption(ANNOTATION);
if (stateAnnotationString != null) {
stateAnnotation = stateAnnotationString;
}
String useStateProbString = arguments.getStringOption(USP);
if (useStateProbString != null && useStateProbString.compareToIgnoreCase("posteriors") != 0)
useStateProbability = false;
String useColorString = arguments.getStringOption(BCUSE);
if (useColorString != null && useColorString.compareToIgnoreCase("posteriors") == 0) {
usePosterior = true;
useHeights = false;
}
if (useColorString != null && useColorString.compareToIgnoreCase("heights") == 0) {
useHeights = true;
usePosterior = false;
}
if (arguments.hasOption(BWC)) {
branchWidthConstant = arguments.getRealOption(BWC);
}
if (arguments.hasOption(BWM)) {
branchWidthMultiplier = arguments.getRealOption(BWM);
}
if (arguments.hasOption(BW)) {
branchWidth = arguments.getRealOption(BW);
}
String color1String = arguments.getStringOption(BSTARTCOLOR);
if (color1String != null) {
startBranchColor = color1String;
}
String color2String = arguments.getStringOption(BENDCOLOR);
if (color2String != null) {
endBranchColor = color2String;
}
String colorString = arguments.getStringOption(BCOLOR);
if (colorString != null) {
branchColor = colorString;
}
String archString = arguments.getStringOption(ARCHBRANCH);
if (archString != null && archString.compareToIgnoreCase("false") == 0)
arcBranches = false;
String archHeightString = arguments.getStringOption(ARCHHEIGHT);
if (archHeightString != null && archHeightString.compareToIgnoreCase("time") == 0) {
arcTimeHeight = true;
}
String tempString = arguments.getStringOption(TEMP);
if (tempString != null && tempString.compareToIgnoreCase("true") == 0)
temporary = true;
if (arguments.hasOption(CIRCLESEGMENTS)) {
numberOfIntervals = arguments.getIntegerOption(CIRCLESEGMENTS);
}
if (arguments.hasOption(RADIUS)) {
radius = arguments.getIntegerOption(RADIUS);
}
String circleOpacityString = arguments.getStringOption(CIRCLEOP);
if (circleOpacityString != null) {
circleOpacity = circleOpacityString;
}
//read in extra taxon locations
String taxaCoordinatesFileString = arguments.getStringOption(COORDSFORTAXA);
if (taxaCoordinatesFileString != null) {
coordinatesForTaxa = true;
progressStream.println("\radditional taxa locations:");
// count lines in locations file and tokens per line
int[] counts = countLinesAndTokens(taxaCoordinatesFileString);
//read in locations
taxaCoordinates = new String[counts[0]][counts[1]];
readLocationsCoordinates(taxaCoordinatesFileString, taxaCoordinates);
}
String sliceString = arguments.getStringOption(SLICES);
if (sliceString != null) {
makeTreeSlices = true;
sliceTimes = parseVariableLengthDoubleArray(sliceString);
}
if (arguments.hasOption(SLICEBW)) {
treeSliceBranchWidth = arguments.getRealOption(SLICEBW);
}
String midpointString = arguments.getStringOption(SLICEMIDPOINT);
if (midpointString != null && midpointString.compareToIgnoreCase("true") == 0)
showBranchAtMidPoint = true;
} catch (Arguments.ArgumentException e) {
progressStream.println(e);
printUsage(arguments);
System.exit(-1);
}
final String[] args2 = arguments.getLeftoverArguments();
outputFileName = args2[0] + ".kml";
switch(args2.length) {
case 0:
printUsage(arguments);
System.exit(1);
case 2:
outputFileName = args2[1];
// fall to
case 1:
inputFileName = args2[0];
tree = readTree(inputFileName);
break;
default:
{
System.err.println("Unknown option: " + args2[2]);
System.err.println();
printUsage(arguments);
System.exit(1);
}
}
DiscreteKMLString exporterString = new DiscreteKMLString(tree, stateAnnotation, locations, inputFileName, mostRecentDate, timeScaler, divider, branchWidthConstant, branchWidthMultiplier, useStateProbability, branchWidth, startBranchColor, endBranchColor, branchColor, useHeights, usePosterior, arcBranches, arcTimeHeight, altitudeFactor, temporary, numberOfIntervals, radius, circleOpacity, coordinatesForTaxa, taxaCoordinates, makeTreeSlices);
try {
BufferedWriter out1 = new BufferedWriter(new FileWriter(outputFileName));
StringBuffer buffer = new StringBuffer();
if (makeTreeSlices) {
for (int i = 0; i < sliceTimes.length; i++) exporterString.writeTreeToKML(sliceTimes[i], treeSliceBranchWidth, showBranchAtMidPoint);
} else {
exporterString.writeTreeToKML();
exporterString.writeLineagesToCircles();
}
exporterString.writeLocationsKML();
exporterString.compileBuffer(buffer);
out1.write(buffer.toString());
out1.close();
} catch (IOException e) {
e.printStackTrace();
return;
}
}
Aggregations