Search in sources :

Example 1 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class TaxonSetInputEditor method parseTrait.

void parseTrait(String trait) {
    Map<String, String> traitmap = new HashMap<>();
    for (String line : trait.split(",")) {
        String[] strs = line.split("=");
        if (strs.length == 2) {
            traitmap.put(strs[0].trim(), strs[1].trim());
        }
    }
    m_taxonset.clear();
    Set<Taxon> taxa = new HashSet<>();
    Set<String> taxonIDs = new HashSet<>();
    for (Alignment alignment : getDoc().alignments) {
        if (alignment instanceof FilteredAlignment) {
            alignment = ((FilteredAlignment) alignment).alignmentInput.get();
        }
        for (String id : alignment.getTaxaNames()) {
            if (!taxonIDs.contains(id)) {
                Taxon taxon = getDoc().getTaxon(id);
                taxa.add(taxon);
                taxonIDs.add(id);
            }
        }
    }
    HashMap<String, TaxonSet> map = new HashMap<>();
    List<String> unknowns = new ArrayList<>();
    for (Taxon taxon : taxa) {
        if (!(taxon instanceof TaxonSet)) {
            String match = traitmap.get(taxon.getID());
            if (match == null) {
                match = "UNKNOWN";
                unknowns.add(taxon.getID());
            }
            try {
                if (map.containsKey(match)) {
                    TaxonSet set = map.get(match);
                    set.taxonsetInput.setValue(taxon, set);
                } else {
                    TaxonSet set = newTaxonSet(match);
                    set.taxonsetInput.setValue(taxon, set);
                    map.put(match, set);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    // add taxon sets
    for (TaxonSet set : map.values()) {
        m_taxonset.add(set);
    }
    if (unknowns.size() > 0) {
        showMisMatchMessage(unknowns);
    }
}
Also used : HashMap(java.util.HashMap) Taxon(beast.evolution.alignment.Taxon) ArrayList(java.util.ArrayList) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) TaxonSet(beast.evolution.alignment.TaxonSet) PatternSyntaxException(java.util.regex.PatternSyntaxException) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) HashSet(java.util.HashSet)

Example 2 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project Babel by rbouckaert.

the class DolloAnnotator method getAlignment.

private Alignment getAlignment() throws IOException {
    if (nexusFileInput.get() != null && !outputInput.get().getName().equals("[[none]]")) {
        NexusParser nexus = new NexusParser();
        nexus.parseFile(nexusFileInput.get());
        Alignment data = nexus.m_alignment;
        if (data == null || !data.getDataType().getTypeDescription().equals("binary")) {
            throw new IllegalArgumentException("Expected a binary alignment in the NEXUS file");
        }
        if (filterInput.get() != null) {
            FilteredAlignment filtered = new FilteredAlignment();
            filtered.initByName("data", data, "filter", filterInput.get());
            data = filtered;
        }
        return data;
    }
    return null;
}
Also used : FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) NexusParser(babel.util.NexusParser) FilteredAlignment(beast.evolution.alignment.FilteredAlignment)

Example 3 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project BEASTLabs by BEAST2-Dev.

the class TreeLikelihoodRLCTestDraft method getFilteredAlignment.

private FilteredAlignment getFilteredAlignment() {
    Alignment alignment = getAlignment();
    IntegerParameter constantSiteWeights = new IntegerParameter(new Integer[] { 1000000, 1000000, 1000000, 1000000 });
    FilteredAlignment filteredAlignment = new FilteredAlignment();
    filteredAlignment.initByName("data", alignment, "filter", "-", "constantSiteWeights", constantSiteWeights, "dataType", "nucleotide");
    return filteredAlignment;
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment)

Example 4 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class TaxonSetInputEditor method parseTrait.

void parseTrait(Map<String, String> traitMap) {
    m_taxonset.clear();
    Set<Taxon> taxa = new HashSet<>();
    Set<String> taxonIDs = new HashSet<>();
    for (Alignment alignment : getDoc().alignments) {
        if (alignment instanceof FilteredAlignment) {
            alignment = ((FilteredAlignment) alignment).alignmentInput.get();
        }
        for (String id : alignment.getTaxaNames()) {
            if (!taxonIDs.contains(id)) {
                Taxon taxon = getDoc().getTaxon(id);
                taxa.add(taxon);
                taxonIDs.add(id);
            }
        }
    }
    HashMap<String, TaxonSet> map = new HashMap<>();
    List<String> unknowns = new ArrayList<>();
    for (Taxon taxon : taxa) {
        if (!(taxon instanceof TaxonSet)) {
            String match = traitMap.get(taxon.getID());
            if (match == null) {
                match = "UNKNOWN";
                unknowns.add(taxon.getID());
            }
            try {
                if (map.containsKey(match)) {
                    TaxonSet set = map.get(match);
                    set.taxonsetInput.setValue(taxon, set);
                } else {
                    TaxonSet set = newTaxonSet(match);
                    set.taxonsetInput.setValue(taxon, set);
                    map.put(match, set);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    // add taxon sets
    for (TaxonSet set : map.values()) {
        m_taxonset.add(set);
    }
    if (unknowns.size() > 0) {
        showMisMatchMessage(unknowns);
    }
}
Also used : HashMap(java.util.HashMap) Taxon(beast.evolution.alignment.Taxon) ArrayList(java.util.ArrayList) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) TaxonSet(beast.evolution.alignment.TaxonSet) PatternSyntaxException(java.util.regex.PatternSyntaxException) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) HashSet(java.util.HashSet)

Example 5 with FilteredAlignment

use of beast.evolution.alignment.FilteredAlignment in project beast2 by CompEvol.

the class AlignmentListInputEditor method initTableData.

void initTableData() {
    this.likelihoods = new GenericTreeLikelihood[partitionCount];
    if (tableData == null) {
        tableData = new Object[partitionCount][NR_OF_COLUMNS];
    }
    CompoundDistribution likelihoods = (CompoundDistribution) doc.pluginmap.get("likelihood");
    for (int i = 0; i < partitionCount; i++) {
        Alignment data = alignments.get(i);
        // partition name
        tableData[i][NAME_COLUMN] = data;
        // alignment name
        if (data instanceof FilteredAlignment) {
            tableData[i][FILE_COLUMN] = ((FilteredAlignment) data).alignmentInput.get();
        } else {
            tableData[i][FILE_COLUMN] = data;
        }
        // # taxa
        tableData[i][TAXA_COLUMN] = data.getTaxonCount();
        // # sites
        tableData[i][SITES_COLUMN] = data.getSiteCount();
        // Data type
        tableData[i][TYPE_COLUMN] = data.getDataType();
        // site model
        GenericTreeLikelihood likelihood = (GenericTreeLikelihood) likelihoods.pDistributions.get().get(i);
        assert (likelihood != null);
        this.likelihoods[i] = likelihood;
        tableData[i][SITEMODEL_COLUMN] = getPartition(likelihood.siteModelInput);
        // clock model
        tableData[i][CLOCKMODEL_COLUMN] = getPartition(likelihood.branchRateModelInput);
        // tree
        tableData[i][TREE_COLUMN] = getPartition(likelihood.treeInput);
        // useAmbiguities
        tableData[i][USE_AMBIGUITIES_COLUMN] = null;
        try {
            if (hasUseAmbiguitiesInput(i)) {
                tableData[i][USE_AMBIGUITIES_COLUMN] = likelihood.getInputValue("useAmbiguities");
            }
        } catch (Exception e) {
        // ignore
        }
    }
}
Also used : CompoundDistribution(beast.core.util.CompoundDistribution) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Alignment(beast.evolution.alignment.Alignment) GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) FilteredAlignment(beast.evolution.alignment.FilteredAlignment)

Aggregations

FilteredAlignment (beast.evolution.alignment.FilteredAlignment)18 Alignment (beast.evolution.alignment.Alignment)17 Test (org.junit.Test)7 TaxonSet (beast.evolution.alignment.TaxonSet)4 ArrayList (java.util.ArrayList)4 BEASTInterface (beast.core.BEASTInterface)3 Taxon (beast.evolution.alignment.Taxon)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 CompoundDistribution (beast.core.util.CompoundDistribution)2 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)2 MRCAPrior (beast.math.distributions.MRCAPrior)2 ParametricDistribution (beast.math.distributions.ParametricDistribution)2 XMLParser (beast.util.XMLParser)2 IOException (java.io.IOException)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 SAXException (org.xml.sax.SAXException)2 NexusParser (babel.util.NexusParser)1