Search in sources :

Example 26 with Taxa

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();
}
Also used : Taxa(dr.evolution.util.Taxa) TaxonList(dr.evolution.util.TaxonList) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel)

Example 27 with Taxa

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();
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Taxa(dr.evolution.util.Taxa) FileReader(java.io.FileReader) File(java.io.File)

Example 28 with Taxa

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);
        }
    }
}
Also used : Taxa(dr.evolution.util.Taxa)

Example 29 with Taxa

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());
    }
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) Taxa(dr.evolution.util.Taxa) Microsatellite(dr.evolution.datatype.Microsatellite) MicroSatImporter(dr.evolution.io.MicroSatImporter) Patterns(dr.evolution.alignment.Patterns)

Example 30 with Taxa

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);
}
Also used : Taxon(dr.evolution.util.Taxon) Taxa(dr.evolution.util.Taxa)

Aggregations

Taxa (dr.evolution.util.Taxa)75 Taxon (dr.evolution.util.Taxon)34 ArrayList (java.util.ArrayList)23 Tree (dr.evolution.tree.Tree)19 TaxonList (dr.evolution.util.TaxonList)15 Attribute (dr.util.Attribute)13 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)10 TreeModel (dr.evomodel.tree.TreeModel)10 Patterns (dr.evolution.alignment.Patterns)9 Microsatellite (dr.evolution.datatype.Microsatellite)9 IOException (java.io.IOException)8 NewickImporter (dr.evolution.io.NewickImporter)7 Parameter (dr.inference.model.Parameter)6 Date (dr.evolution.util.Date)5 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 ImportException (dr.evolution.io.Importer.ImportException)4 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)3