use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.
the class TreeSpaceLogger method readTrees.
private void readTrees(String filename) {
try {
FileReader fr = new FileReader(new File(filename));
BufferedReader br = new BufferedReader(fr);
String line;
List<Tree> trees = new ArrayList<Tree>();
List<Integer> islands = new ArrayList<Integer>();
while ((line = br.readLine()) != null) {
// read trees
String[] tokens = line.split("\\s++");
NewickImporter importer = new NewickImporter(line);
Tree t = importer.importNextTree();
trees.add(t);
islands.add(Integer.parseInt(tokens[0]));
}
br.close();
fr.close();
this.trees = new String[trees.size()];
this.islands = new int[trees.size()];
int maxIsland = 0;
for (int i = 0; i < trees.size(); i++) {
Tree tree = trees.get(i);
String newick = TreeUtils.uniqueNewick(tree, tree.getRoot());
this.trees[i] = newick;
this.islands[i] = islands.get(i) - 1;
if (islands.get(i) > maxIsland) {
maxIsland = islands.get(i);
}
}
transitions = new int[trees.size()][trees.size()];
steps = new int[trees.size()][trees.size()];
islandTransitions = new int[maxIsland][maxIsland];
islandDwellTimes = new int[maxIsland];
// pathes = new HashMap[trees.size()][trees.size()];
// for (int i = 0; i < trees.size(); i++) {
// for (int j = 0; j < trees.size(); j++) {
// pathes[i][j] = new HashMap<String, Integer>();
// }
// }
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ImportException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.
the class DataModelImporter method importFastaFile.
// FASTA
private void importFastaFile(File file, DateGuesser guesser, Map dataModel) throws IOException, ImportException {
try {
FileReader reader = new FileReader(file);
FastaImporter importer = new FastaImporter(reader, Nucleotides.INSTANCE);
Alignment alignment = importer.importAlignment();
reader.close();
setData(dataModel, guesser, file.getName(), alignment, null, alignment, null, null, null);
} catch (ImportException e) {
throw new ImportException(e.getMessage());
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.
the class BeautiFrame method importFiles.
private void importFiles(File[] files) {
for (File file : files) {
if (file == null || file.getName().equals("")) {
JOptionPane.showMessageDialog(this, "Invalid file name", "Invalid file name", JOptionPane.ERROR_MESSAGE);
} else {
try {
BEAUTiImporter beautiImporter = new BEAUTiImporter(this, options);
beautiImporter.importFromFile(file);
setDirty();
// } catch (FileNotFoundException fnfe) {
// JOptionPane.showMessageDialog(this, "Unable to open file: File not found",
// "Unable to open file", JOptionPane.ERROR_MESSAGE);
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this, "File I/O Error unable to read file: " + ioe.getMessage(), "Unable to read file", JOptionPane.ERROR_MESSAGE);
ioe.printStackTrace();
// there may be other files in the list so don't return
// return;
} catch (MissingBlockException ex) {
JOptionPane.showMessageDialog(this, "TAXON, DATA or CHARACTERS block is missing in Nexus file: " + ex, "Missing Block in Nexus File", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
} catch (ImportException ime) {
JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE);
ime.printStackTrace();
} catch (JDOMException jde) {
JOptionPane.showMessageDialog(this, "Error parsing imported file: " + jde, "Error reading file", JOptionPane.ERROR_MESSAGE);
jde.printStackTrace();
}
}
}
if (!options.hasIdenticalTaxa()) {
// need this to refresh panels otherwise it will throw exception
setAllOptions();
dataPanel.selectAll();
dataPanel.unlinkTreeModels();
}
setAllOptions();
}
use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.
the class DataModelImporter method checkTaxonList.
private void checkTaxonList(TaxonList taxonList, DateGuesser guesser) throws ImportException {
// check the taxon names for invalid characters
boolean foundAmp = false;
for (Taxon taxon : taxonList) {
String name = taxon.getId();
if (name.indexOf('&') >= 0) {
foundAmp = true;
}
}
if (foundAmp) {
throw new ImportException("One or more taxon names include an illegal character ('&').\n" + "These characters will prevent BEAST from reading the resulting XML file.\n\n" + "Please edit the taxon name(s) before reloading the data file.");
}
if (guesser != null) {
guesser.guessDates(taxonList);
} else {
// make sure they all have dates...
for (int i = 0; i < taxonList.getTaxonCount(); i++) {
if (taxonList.getTaxonAttribute(i, "date") == null) {
Date origin = new Date(0);
dr.evolution.util.Date date = dr.evolution.util.Date.createTimeSinceOrigin(0.0, Units.Type.YEARS, origin);
taxonList.getTaxon(i).setAttribute("date", date);
}
}
}
}
use of dr.evolution.io.Importer.ImportException in project beast-mcmc by beast-dev.
the class BEAUTiImporter method importMicroSatFile.
// micro-sat
private void importMicroSatFile(File file) throws IOException, ImportException {
try {
Reader reader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(reader);
MicroSatImporter importer = new MicroSatImporter(bufferedReader);
List<Patterns> microsatPatList = importer.importPatterns();
Taxa unionSetTaxonList = importer.getUnionSetTaxonList();
Microsatellite microsatellite = importer.getMicrosatellite();
// options.allowDifferentTaxa = importer.isHasDifferentTaxon();
bufferedReader.close();
PartitionSubstitutionModel substModel = new PartitionSubstitutionModel(options, microsatPatList.get(0).getId());
substModel.setMicrosatellite(microsatellite);
for (Patterns patterns : microsatPatList) {
setData(file.getName(), unionSetTaxonList, patterns, substModel, null);
}
// has to call after data is imported
options.microsatelliteOptions.initModelParametersAndOpererators();
} catch (ImportException e) {
throw new ImportException(e.getMessage());
} catch (IOException e) {
throw new IOException(e.getMessage());
}
}
Aggregations