use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class TaxonSetPanel method setCurrentTaxonSet.
protected void setCurrentTaxonSet(Taxa taxonSet) {
this.currentTaxonSet = taxonSet;
includedTaxa.clear();
excludedTaxa.clear();
if (currentTaxonSet != null) {
for (int i = 0; i < taxonSet.getTaxonCount(); i++) {
includedTaxa.add(taxonSet.getTaxon(i));
}
Collections.sort(includedTaxa);
// get taxa associated to each tree
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(currentTaxonSet);
TaxonList alignment = options.getDataPartitions(treeModel).get(0).getTaxonList();
Taxa taxa = new Taxa(alignment);
for (int i = 0; i < taxa.getTaxonCount(); i++) {
excludedTaxa.add(taxa.getTaxon(i));
}
excludedTaxa.removeAll(includedTaxa);
Collections.sort(excludedTaxa);
}
setTaxonSetTitle();
setupTaxonSetsComboBoxes();
includedTaxaTableModel.fireTableDataChanged();
excludedTaxaTableModel.fireTableDataChanged();
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class TaxonSetPanel method importTaxonSets.
public void importTaxonSets() {
File[] files = frame.selectImportFiles("Import Taxon Set File...", false, new FileNameExtensionFilter[] { new FileNameExtensionFilter("Tab-delimited text files", "txt", "tab", "dat") });
DataTable<String[]> dataTable;
if (files != null && files.length != 0) {
try {
// Load the file as a table
dataTable = DataTable.Text.parse(new FileReader(files[0]), false, true, false, false);
} catch (FileNotFoundException fnfe) {
JOptionPane.showMessageDialog(this, "Unable to open file: File not found", "Unable to open file", JOptionPane.ERROR_MESSAGE);
return;
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this, "Unable to read file: " + ioe.getMessage(), "Unable to read file", JOptionPane.ERROR_MESSAGE);
return;
} catch (Exception ex) {
ex.printStackTrace(System.err);
JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
return;
}
} else {
return;
}
String[] taxonNames = dataTable.getRowLabels();
if (dataTable.getColumnCount() == 0) {
String name = files[0].getName();
int lastDot = name.lastIndexOf('.');
if (lastDot >= 1) {
name = name.substring(0, lastDot);
}
Taxa taxa = new Taxa();
// Only one column so assume the entire set is defined in this file.
for (String taxonName : taxonNames) {
final int index = options.taxonList.getTaxonIndex(taxonName);
if (index >= 0) {
taxa.addTaxon(options.taxonList.getTaxon(index));
}
}
taxa.setId(name);
options.taxonSets.add(taxa);
options.taxonSetsTreeModel.put(taxa, options.getPartitionTreeModels().get(0));
} else {
// assume column one is the taxon labels and column two is the set names
String[] taxonSetNames = dataTable.getColumn(0);
Map<String, Taxa> taxonSets = new HashMap<String, Taxa>();
int i = 0;
for (String taxonName : taxonNames) {
final int index = options.taxonList.getTaxonIndex(taxonName);
if (index >= 0) {
Taxa taxa = taxonSets.get(taxonSetNames[i]);
if (taxa == null) {
taxa = new Taxa();
taxa.setId(taxonSetNames[i]);
taxonSets.put(taxonSetNames[i], taxa);
}
taxa.addTaxon(options.taxonList.getTaxon(index));
}
i++;
}
for (Taxa taxa : taxonSets.values()) {
options.taxonSets.add(taxa);
options.taxonSetsTreeModel.put(taxa, options.getPartitionTreeModels().get(0));
options.taxonSetsMono.put(taxa, false);
options.taxonSetsIncludeStem.put(taxa, false);
options.taxonSetsHeights.put(taxa, 0.0);
}
}
taxonSetsTableModel.fireTableDataChanged();
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class BEAUTiImporter method addTaxonSets.
private void addTaxonSets(TaxonList taxonList, List<NexusApplicationImporter.TaxSet> taxSets) throws ImportException {
if (taxSets != null) {
for (NexusApplicationImporter.TaxSet taxSet : taxSets) {
Taxa taxa = new Taxa(taxSet.getName());
for (CharSetBlock block : taxSet.getBlocks()) {
for (int i = block.getFromSite(); i <= block.getToSite(); i++) {
taxa.addTaxon(taxonList.getTaxon(i - 1));
}
}
options.taxonSets.add(taxa);
options.taxonSetsTreeModel.put(taxa, options.getPartitionTreeModels().get(0));
options.taxonSetsMono.put(taxa, false);
options.taxonSetsIncludeStem.put(taxa, false);
options.taxonSetsHeights.put(taxa, 0.0);
}
}
}
use of dr.evolution.util.Taxa 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());
}
}
use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.
the class BEAUTiImporter method importTraits.
public void importTraits(final File file) throws Exception {
List<TraitData> importedTraits = new ArrayList<TraitData>();
Taxa taxa = options.taxonList;
DataTable<String[]> dataTable = DataTable.Text.parse(new FileReader(file));
String[] traitNames = dataTable.getColumnLabels();
String[] taxonNames = dataTable.getRowLabels();
for (int i = 0; i < dataTable.getColumnCount(); i++) {
boolean warningGiven = false;
String traitName = traitNames[i];
String[] values = dataTable.getColumn(i);
Class c = null;
if (!isMissingValue(values[0])) {
c = Utils.detectType(values[0]);
}
for (int j = 1; j < values.length; j++) {
if (!isMissingValue(values[j])) {
if (c == null) {
c = Utils.detectType(values[j]);
} else {
Class c1 = Utils.detectType(values[j]);
if (c == Integer.class && c1 == Double.class) {
// change the type to double
c = Double.class;
}
if (c1 != c && !(c == Double.class && c1 == Integer.class) && !warningGiven) {
JOptionPane.showMessageDialog(frame, "Not all values of same type for trait" + traitName, "Incompatible values", JOptionPane.WARNING_MESSAGE);
warningGiven = true;
}
}
}
}
TraitData.TraitType t = (c == Boolean.class || c == String.class || c == null) ? TraitData.TraitType.DISCRETE : (c == Integer.class) ? TraitData.TraitType.INTEGER : TraitData.TraitType.CONTINUOUS;
TraitData newTrait = new TraitData(options, traitName, file.getName(), t);
if (validateTraitName(traitName)) {
importedTraits.add(newTrait);
}
int j = 0;
for (final String taxonName : taxonNames) {
final int index = taxa.getTaxonIndex(taxonName);
Taxon taxon;
if (index >= 0) {
taxon = taxa.getTaxon(index);
} else {
taxon = new Taxon(taxonName);
taxa.addTaxon(taxon);
}
if (!isMissingValue(values[j])) {
taxon.setAttribute(traitName, Utils.constructFromString(c, values[j]));
} else {
// AR - merge rather than replace existing trait values
if (taxon.getAttribute(traitName) == null) {
taxon.setAttribute(traitName, "?");
}
}
j++;
}
}
setData(file.getName(), taxa, null, null, null, null, importedTraits, null);
}
Aggregations