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);
}
}
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;
}
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;
}
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);
}
}
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
}
}
}
Aggregations