Search in sources :

Example 26 with TaxonList

use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.

the class FixedDriftModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    /*
        String idOne = xo.getStringAttribute(RATE_ONE_ID);

        String idTwo = xo.getStringAttribute(RATE_TWO_ID);

        Parameter rateOne = (Parameter) xo.getElementFirstChild(RATE_ONE);

        Parameter rateTwo = (Parameter) xo.getElementFirstChild(RATE_TWO);

        Parameter remainingRates = (Parameter) xo.getElementFirstChild(REMAINING_RATES);
        */
    TaxonList taxonList = (TaxonList) xo.getElementFirstChild(BACKBONE_TAXON_LIST);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    Parameter backboneDrift = (Parameter) xo.getElementFirstChild(BACKBONE_DRIFT);
    Parameter otherDrift = (Parameter) xo.getElementFirstChild(OTHER_DRIFT);
    Logger.getLogger("dr.evomodel").info("Using fixed drift model.");
    return new FixedDriftModel(treeModel, backboneDrift, otherDrift, taxonList);
//  return new FixedDriftModel(rateOne, rateTwo, remainingRates, idOne, idTwo);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TaxonList(dr.evolution.util.TaxonList) FixedDriftModel(dr.evomodel.branchratemodel.FixedDriftModel) Parameter(dr.inference.model.Parameter)

Example 27 with TaxonList

use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.

the class DataModelImporter method importNexusFile.

// nexus
private void importNexusFile(File file, DateGuesser guesser, Map dataModel) throws IOException, ImportException {
    TaxonList taxa = null;
    SimpleAlignment alignment = null;
    List<Tree> trees = new ArrayList<Tree>();
    List<NexusApplicationImporter.CharSet> charSets = new ArrayList<NexusApplicationImporter.CharSet>();
    try {
        FileReader reader = new FileReader(file);
        NexusApplicationImporter importer = new NexusApplicationImporter(reader);
        boolean done = false;
        while (!done) {
            try {
                NexusBlock block = importer.findNextBlock();
                if (block == NexusImporter.TAXA_BLOCK) {
                    if (taxa != null) {
                        throw new MissingBlockException("TAXA block already defined");
                    }
                    taxa = importer.parseTaxaBlock();
                    dataModel.put("taxa", createTaxonList(taxa));
                } else if (block == NexusImporter.CALIBRATION_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA or DATA block must be defined before a CALIBRATION block");
                    }
                    importer.parseCalibrationBlock(taxa);
                } else if (block == NexusImporter.CHARACTERS_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA block must be defined before a CHARACTERS block");
                    }
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    alignment = (SimpleAlignment) importer.parseCharactersBlock(taxa);
                } else if (block == NexusImporter.DATA_BLOCK) {
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    // A data block doesn't need a taxon block before it
                    // but if one exists then it will use it.
                    alignment = (SimpleAlignment) importer.parseDataBlock(taxa);
                    if (taxa == null) {
                        taxa = alignment;
                    }
                } else if (block == NexusImporter.TREES_BLOCK) {
                    // I guess there is no reason not to allow multiple trees blocks
                    //                        if (trees.size() > 0) {
                    //                            throw new MissingBlockException("TREES block already defined");
                    //                        }
                    Tree[] treeArray = importer.parseTreesBlock(taxa);
                    trees.addAll(Arrays.asList(treeArray));
                    if (taxa == null && trees.size() > 0) {
                        taxa = trees.get(0);
                    }
                } else if (block == NexusApplicationImporter.ASSUMPTIONS_BLOCK) {
                    importer.parseAssumptionsBlock(charSets);
                } else {
                // Ignore the block..
                }
            } catch (EOFException ex) {
                done = true;
            }
        }
        reader.close();
        // Allow the user to load taxa only (perhaps from a tree file) so that they can sample from a prior...
        if (alignment == null && taxa == null) {
            throw new MissingBlockException("TAXON, DATA or CHARACTERS block is missing");
        }
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    //        } catch (Exception e) {
    //            throw new Exception(e.getMessage());
    }
    setData(dataModel, guesser, file.getName(), taxa, null, alignment, charSets, null, trees);
}
Also used : TaxonList(dr.evolution.util.TaxonList) ImportException(dr.evolution.io.Importer.ImportException) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) NexusBlock(dr.evolution.io.NexusImporter.NexusBlock) Tree(dr.evolution.tree.Tree) MissingBlockException(dr.evolution.io.NexusImporter.MissingBlockException)

Example 28 with TaxonList

use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.

the class BEAUTiImporter method importNexusFile.

// nexus
private void importNexusFile(File file) throws IOException, ImportException {
    TaxonList taxa = null;
    SimpleAlignment alignment = null;
    List<Tree> trees = new ArrayList<Tree>();
    PartitionSubstitutionModel model = null;
    List<NexusApplicationImporter.CharSet> charSets = new ArrayList<NexusApplicationImporter.CharSet>();
    try {
        FileReader reader = new FileReader(file);
        NexusApplicationImporter importer = new NexusApplicationImporter(reader);
        boolean done = false;
        while (!done) {
            try {
                NexusBlock block = importer.findNextBlock();
                if (block == NexusImporter.TAXA_BLOCK) {
                    if (taxa != null) {
                        throw new MissingBlockException("TAXA block already defined");
                    }
                    taxa = importer.parseTaxaBlock();
                } else if (block == NexusImporter.CALIBRATION_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA or DATA block must be defined before a CALIBRATION block");
                    }
                    importer.parseCalibrationBlock(taxa);
                } else if (block == NexusImporter.CHARACTERS_BLOCK) {
                    if (taxa == null) {
                        throw new MissingBlockException("TAXA block must be defined before a CHARACTERS block");
                    }
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    alignment = (SimpleAlignment) importer.parseCharactersBlock(taxa);
                } else if (block == NexusImporter.DATA_BLOCK) {
                    if (alignment != null) {
                        throw new MissingBlockException("CHARACTERS or DATA block already defined");
                    }
                    // A data block doesn't need a taxon block before it
                    // but if one exists then it will use it.
                    alignment = (SimpleAlignment) importer.parseDataBlock(taxa);
                    if (taxa == null) {
                        taxa = alignment;
                    }
                } else if (block == NexusImporter.TREES_BLOCK) {
                    // I guess there is no reason not to allow multiple trees blocks
                    //                        if (trees.size() > 0) {
                    //                            throw new MissingBlockException("TREES block already defined");
                    //                        }
                    Tree[] treeArray = importer.parseTreesBlock(taxa);
                    trees.addAll(Arrays.asList(treeArray));
                    if (taxa == null && trees.size() > 0) {
                        taxa = trees.get(0);
                    }
                } else if (block == NexusApplicationImporter.PAUP_BLOCK) {
                    model = importer.parsePAUPBlock(options, charSets);
                } else if (block == NexusApplicationImporter.MRBAYES_BLOCK) {
                    model = importer.parseMrBayesBlock(options, charSets);
                } else if (block == NexusApplicationImporter.ASSUMPTIONS_BLOCK || block == NexusApplicationImporter.SETS_BLOCK) {
                    importer.parseAssumptionsBlock(charSets);
                } else {
                // Ignore the block..
                }
            } catch (EOFException ex) {
                done = true;
            }
        }
        reader.close();
        // Allow the user to load taxa only (perhaps from a tree file) so that they can sample from a prior...
        if (alignment == null && taxa == null) {
            throw new MissingBlockException("TAXON, DATA or CHARACTERS block is missing");
        }
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    //        } catch (Exception e) {
    //            throw new Exception(e.getMessage());
    }
    setData(file.getName(), taxa, alignment, charSets, model, null, trees);
}
Also used : TaxonList(dr.evolution.util.TaxonList) ArrayList(java.util.ArrayList) ImportException(dr.evolution.io.Importer.ImportException) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) NexusBlock(dr.evolution.io.NexusImporter.NexusBlock) Tree(dr.evolution.tree.Tree) MissingBlockException(dr.evolution.io.NexusImporter.MissingBlockException)

Example 29 with TaxonList

use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.

the class BEAUTiImporter method importBEASTFile.

// xml
private void importBEASTFile(File file) throws IOException, ImportException, JDOMException {
    try {
        FileReader reader = new FileReader(file);
        BeastImporter importer = new BeastImporter(reader);
        List<TaxonList> taxonLists = new ArrayList<TaxonList>();
        List<Alignment> alignments = new ArrayList<Alignment>();
        importer.importBEAST(taxonLists, alignments);
        TaxonList taxa = taxonLists.get(0);
        int count = 1;
        for (Alignment alignment : alignments) {
            String name = file.getName();
            if (alignment.getId() != null && alignment.getId().length() > 0) {
                name = alignment.getId();
            } else {
                if (alignments.size() > 1) {
                    name += count;
                }
            }
            setData(name, taxa, alignment, null, null, null, null);
            count++;
        }
        // assume that any additional taxon lists are taxon sets...
        for (int i = 1; i < taxonLists.size(); i++) {
            Taxa taxonSet = (Taxa) taxonLists.get(i);
            options.taxonSets.add(taxonSet);
            options.taxonSetsMono.put(taxonSet, false);
            options.taxonSetsIncludeStem.put(taxonSet, false);
            options.taxonSetsTreeModel.put(taxonSet, options.getPartitionTreeModels().get(0));
        }
        reader.close();
    } catch (JDOMException e) {
        throw new JDOMException(e.getMessage());
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : TaxonList(dr.evolution.util.TaxonList) ArrayList(java.util.ArrayList) JDOMException(org.jdom.JDOMException) ImportException(dr.evolution.io.Importer.ImportException) Taxa(dr.evolution.util.Taxa) Alignment(dr.evolution.alignment.Alignment) SimpleAlignment(dr.evolution.alignment.SimpleAlignment)

Example 30 with TaxonList

use of dr.evolution.util.TaxonList in project beast-mcmc by beast-dev.

the class Coevolve method readTreeFile.

/**
     * @param fileName
     * @throws java.io.IOException
     */
private Tree readTreeFile(String fileName) throws java.io.IOException {
    Alignment alignment = null;
    Tree[] trees = null;
    TaxonList taxonList = null;
    try {
        FileReader reader = new FileReader(fileName);
        NexusImporter importer = new NexusImporter(reader);
        boolean done = false;
        while (!done) {
            try {
                NexusImporter.NexusBlock block = importer.findNextBlock();
                if (block == NexusImporter.TAXA_BLOCK) {
                    if (taxonList != null) {
                        throw new NexusImporter.MissingBlockException("TAXA block already defined");
                    }
                    taxonList = importer.parseTaxaBlock();
                } else if (block == NexusImporter.DATA_BLOCK) {
                    // A data block doesn't need a taxon block before it
                    // but if one exists then it will use it.
                    alignment = importer.parseDataBlock(taxonList);
                    if (taxonList == null) {
                        taxonList = alignment;
                    }
                } else if (block == NexusImporter.TREES_BLOCK) {
                    trees = importer.parseTreesBlock(taxonList);
                    if (taxonList == null) {
                        taxonList = alignment;
                    }
                } else {
                // Ignore the block..
                }
            } catch (EOFException ex) {
                done = true;
            }
        }
    } catch (Importer.ImportException ime) {
        System.err.println("Error reading alignment: " + ime);
    }
    return trees[0];
}
Also used : NexusImporter(dr.evolution.io.NexusImporter) TaxonList(dr.evolution.util.TaxonList) Tree(dr.evolution.tree.Tree) NexusImporter(dr.evolution.io.NexusImporter) Importer(dr.evolution.io.Importer)

Aggregations

TaxonList (dr.evolution.util.TaxonList)59 Tree (dr.evolution.tree.Tree)18 Taxon (dr.evolution.util.Taxon)18 TreeUtils (dr.evolution.tree.TreeUtils)15 Taxa (dr.evolution.util.Taxa)13 Parameter (dr.inference.model.Parameter)13 ArrayList (java.util.ArrayList)13 TreeModel (dr.evomodel.tree.TreeModel)11 Alignment (dr.evolution.alignment.Alignment)6 SitePatterns (dr.evolution.alignment.SitePatterns)5 SimpleTree (dr.evolution.tree.SimpleTree)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 Importer (dr.evolution.io.Importer)4 ImportException (dr.evolution.io.Importer.ImportException)4 NexusImporter (dr.evolution.io.NexusImporter)4 CoalescentLikelihood (dr.evomodel.coalescent.CoalescentLikelihood)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 NodeRef (dr.evolution.tree.NodeRef)3 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)3 CompoundLikelihood (dr.inference.model.CompoundLikelihood)3