use of dr.inference.trace.TraceException in project beast-mcmc by beast-dev.
the class GPSkytrackAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
System.err.println("The Summary Statistics are being created...");
try {
// 10% is brun-in default
final double burnin = xo.getAttribute(BURN_IN, 0.1);
if (burnin < 0) {
throw new XMLParseException("burnIn should be either between 0 and 1 or a positive number");
}
Parameter numGridPoints = new Parameter.Default(0, 1);
if (xo.getChild(N_GRID) != null) {
XMLObject cxo = xo.getChild(N_GRID);
numGridPoints = (Parameter) cxo.getChild(Parameter.class);
}
final File log = FileHelpers.getFile(getElementText(xo, LOG_FILE_NAME));
return new dr.evomodel.coalescent.GPSkytrackAnalysis(log, burnin, numGridPoints);
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (Importer.ImportException e) {
throw new XMLParseException(e.toString());
} catch (TraceException e) {
throw new XMLParseException(e.toString());
}
}
use of dr.inference.trace.TraceException in project beast-mcmc by beast-dev.
the class MapperFrame method processTraces.
protected void processTraces(final LogFileTraces[] tracesArray) {
final JFrame frame = this;
if (tracesArray.length == 1) {
try {
final LogFileTraces traces = tracesArray[0];
final String fileName = traces.getName();
final ProgressMonitorInputStream in = new ProgressMonitorInputStream(this, "Reading " + fileName, new FileInputStream(traces.getFile()));
in.getProgressMonitor().setMillisToDecideToPopup(0);
in.getProgressMonitor().setMillisToPopup(0);
// final Reader reader = new InputStreamReader(in);
Thread readThread = new Thread() {
public void run() {
try {
traces.loadTraces(in);
EventQueue.invokeLater(new Runnable() {
public void run() {
// analyseTraceList(traces);
// addTraceList(traces);
}
});
} catch (final TraceException te) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "Problem with trace file: " + te.getMessage(), "Problem with tree file", JOptionPane.ERROR_MESSAGE);
}
});
} catch (final InterruptedIOException iioex) {
// The cancel dialog button was pressed - do nothing
} catch (final IOException ioex) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "File I/O Error: " + ioex.getMessage(), "File I/O Error", JOptionPane.ERROR_MESSAGE);
}
});
// } catch (final Exception ex) {
// EventQueue.invokeLater (
// new Runnable () {
// public void run () {
// JOptionPane.showMessageDialog(frame, "Fatal exception: " + ex.getMessage(),
// "Error reading file",
// JOptionPane.ERROR_MESSAGE);
// }
// });
}
}
};
readThread.start();
} catch (FileNotFoundException fnfe) {
JOptionPane.showMessageDialog(this, "Unable to open file: File not found", "Unable to open file", JOptionPane.ERROR_MESSAGE);
} catch (IOException ioex) {
JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
}
} else {
Thread readThread = new Thread() {
public void run() {
try {
for (final LogFileTraces traces : tracesArray) {
// final Reader reader = new FileReader(traces.getFile());
traces.loadTraces();
EventQueue.invokeLater(new Runnable() {
public void run() {
// analyseTraceList(traces);
// addTraceList(traces);
}
});
}
} catch (final TraceException te) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "Problem with trace file: " + te.getMessage(), "Problem with tree file", JOptionPane.ERROR_MESSAGE);
}
});
} catch (final InterruptedIOException iioex) {
// The cancel dialog button was pressed - do nothing
} catch (final IOException ioex) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "File I/O Error: " + ioex.getMessage(), "File I/O Error", JOptionPane.ERROR_MESSAGE);
}
});
// } catch (final Exception ex) {
// EventQueue.invokeLater (
// new Runnable () {
// public void run () {
// JOptionPane.showMessageDialog(frame, "Fatal exception: " + ex.getMessage(),
// "Error reading file",
// JOptionPane.ERROR_MESSAGE);
// }
// });
}
}
};
readThread.start();
}
}
use of dr.inference.trace.TraceException in project beast-mcmc by beast-dev.
the class SkylineReconstructor method main.
public static void main(String[] argv) {
Variate x = null;
List<Variate> plots = new ArrayList<Variate>();
for (int i = 1; i <= 200; i++) {
String stem = "sim" + (i < 10 ? "00" : (i < 100 ? "0" : "")) + i;
try {
SkylineReconstructor skyline = new SkylineReconstructor(new File(stem + ".log"), new File(stem + ".trees"), 1000000, 200, 0.0, 150000, 0.0);
if (x == null) {
x = skyline.getXData();
}
plots.add(skyline.getYDataMean());
} catch (IOException e) {
e.printStackTrace();
} catch (ImportException e) {
e.printStackTrace();
} catch (TraceException e) {
e.printStackTrace();
}
if (i % 10 == 0) {
System.err.println("Read " + i);
}
}
for (int i = 0; i < x.getCount(); i++) {
System.out.print(x.get(i));
for (Variate y : plots) {
System.out.print("\t" + y.get(i));
}
System.out.println();
}
}
use of dr.inference.trace.TraceException in project beast-mcmc by beast-dev.
the class MarginalLikelihoodAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
try {
File file = new File(fileName);
String name = file.getName();
String parent = file.getParent();
if (!file.isAbsolute()) {
parent = System.getProperty("user.dir");
}
file = new File(parent, name);
fileName = file.getAbsolutePath();
XMLObject cxo = xo.getChild(COLUMN_NAME);
String likelihoodName = cxo.getStringAttribute(Attribute.NAME);
LogFileTraces traces = new LogFileTraces(fileName, file);
traces.loadTraces();
long maxState = traces.getMaxState();
// leaving the burnin attribute off will result in 10% being used
long burnin = xo.getAttribute(BURN_IN, maxState / 10);
if (burnin < 0 || burnin >= maxState) {
burnin = maxState / 10;
System.out.println("WARNING: Burn-in larger than total number of states - using to 10%");
}
traces.setBurnIn(burnin);
int traceIndex = -1;
for (int i = 0; i < traces.getTraceCount(); i++) {
String traceName = traces.getTraceName(i);
if (traceName.equals(likelihoodName)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
throw new XMLParseException("Column '" + likelihoodName + "' can not be found for " + getParserName() + " element.");
}
// Set analysisType
String analysisType = "smoothed";
boolean harmonicOnly = false;
if (xo.hasAttribute(ONLY_HARMONIC))
harmonicOnly = xo.getBooleanAttribute(ONLY_HARMONIC);
if (harmonicOnly)
analysisType = "harmonic";
int bootstrapLength = cxo.getAttribute(BOOTSTRAP_LENGTH, 1000);
List<Double> sample = traces.getValues(traceIndex);
MarginalLikelihoodAnalysis analysis = new MarginalLikelihoodAnalysis(sample, traces.getTraceName(traceIndex), (int) burnin, analysisType, bootstrapLength);
System.out.println(analysis.toString());
return analysis;
} catch (FileNotFoundException fnfe) {
throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (TraceException e) {
throw new XMLParseException(e.getMessage());
}
}
use of dr.inference.trace.TraceException in project beast-mcmc by beast-dev.
the class CoalGenFrame method readFromFile.
protected boolean readFromFile(final File file) throws IOException {
try {
final String fileName = file.getName();
final ProgressMonitorInputStream in = new ProgressMonitorInputStream(this, "Reading " + fileName, new FileInputStream(file));
// final Reader reader = new InputStreamReader(in);
final JFrame frame = this;
// the monitored activity must be in a new thread.
Thread readThread = new Thread() {
public void run() {
try {
final File file1 = new File(fileName);
final LogFileTraces traces = new LogFileTraces(fileName, file1);
traces.loadTraces(in);
EventQueue.invokeLater(new Runnable() {
public void run() {
data.logFile = file;
data.traces = traces;
fireTracesChanged();
}
});
} catch (final TraceException tex) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "Error reading trace file: " + tex, "Error reading trace file", JOptionPane.ERROR_MESSAGE);
}
});
} catch (final InterruptedIOException iioex) {
// The cancel dialog button was pressed - do nothing
} catch (final IOException ioex) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
}
});
} catch (final Exception ex) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(frame, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
}
});
}
}
};
readThread.start();
} catch (IOException ioex) {
JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
return false;
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
Aggregations