Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/beast-dev/beast-mcmc into…
Browse files Browse the repository at this point in the history
… nonparametrics
  • Loading branch information
mandevgill committed Aug 19, 2024
2 parents 95d319f + 98ae9c6 commit cdcfb32
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/dr/app/beast/release_parsers.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dr.evoxml.PatternSubSetParser
dr.evoxml.AscertainedSitePatternsParser
dr.evoxml.ConvertAlignmentParser
dr.evoxml.MergePatternsParser
dr.evoxml.MaskedPatternsParser
dr.evoxml.MaskedAlignmentParser
dr.evoxml.AttributePatternsParser
dr.evoxml.RandomTaxaSampleParser
dr.evoxml.ConstantPatternsParser
Expand Down
47 changes: 47 additions & 0 deletions src/dr/evolution/alignment/MaskedAlignment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* MaskedAlignment.java
*
* Copyright © 2002-2024 the BEAST Development Team
* http://beast.community/about
*
* This file is part of BEAST.
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership and licensing.
*
* BEAST is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* BEAST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with BEAST; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/

package dr.evolution.alignment;

public class MaskedAlignment extends WrappedAlignment {
public MaskedAlignment(Alignment alignment, boolean[] mask) {
super(alignment);

this.mask = mask;
}

@Override
public int getState(int taxonIndex, int siteIndex) {
if (mask[siteIndex]) {
return alignment.getState(taxonIndex, siteIndex);
} else {
return alignment.getDataType().getUnknownState();
}
}

private final boolean[] mask;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author Andrew Rambaut
* @author Marc Suchard
*/
@Deprecated // seems not to be used
public interface BeagleDataLikelihoodInterface extends DataLikelihoodDelegate {

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,47 @@

package dr.evoxml;

import dr.evolution.alignment.Alignment;
import dr.evolution.alignment.MaskedAlignment;
import dr.evolution.alignment.PatternList;
import dr.evolution.alignment.Patterns;
import dr.evolution.alignment.SiteList;
import dr.evolution.alignment.SitePatterns;
import dr.xml.*;

import java.util.logging.Logger;

/**
* @author Andrew Rambaut
*
*/
public class MaskedPatternsParser extends AbstractXMLObjectParser {
public class MaskedAlignmentParser extends AbstractXMLObjectParser {

public static final String MASKED_PATTERNS = "maskedPatterns";
public static final String MASKED_ALIGNMENT = "maskedAlignment";
public static final String MASK = "mask";
public static final String NEGATIVE = "negative";
public static final String INVERSE = "inverse";

public String getParserName() { return MASKED_PATTERNS; }
public String getParserName() { return MASKED_ALIGNMENT; }

/**
* Parses a patterns element and returns a patterns object.
* Parses an alignment element and returns a masked alignment object.
*/
public Object parseXMLObject(XMLObject xo) throws XMLParseException {

SiteList siteList = (SiteList)xo.getChild(SiteList.class);
Alignment alignment = (Alignment)xo.getChild(Alignment.class);

boolean inverseMask = xo.getBooleanAttribute(INVERSE, false) || xo.getBooleanAttribute(NEGATIVE, false);
String maskString = (String)xo.getElementFirstChild(MASK);

boolean[] mask = new boolean[siteList.getSiteCount()];
boolean[] mask = new boolean[alignment.getSiteCount()];
int k = 0;
int onCount = 0;
for (char c : maskString.toCharArray()) {
if (Character.isDigit(c)) {
if (k >= mask.length) {
break;
}
mask[k] = (c == '0' ? inverseMask : !inverseMask);
if (mask[k]) {
onCount += 1;
}
k++;
}
}
Expand All @@ -74,23 +76,11 @@ public Object parseXMLObject(XMLObject xo) throws XMLParseException {
throw new XMLParseException("The mask needs to be the same length as the alignment (spaces are ignored)");
}

throw new UnsupportedOperationException("This has not been implemented");

// @todo - work out how to do this. Create a MaskedSitePatterns which can then be put into a SitePatterns
// for compression etc. Or MaskedAlignment may make more sense here.
// SitePatterns patterns = new MaskedSitePatterns(siteList, mask);
//
// if (patterns == null) {
// throw new XMLParseException("The mask needs include at least one pattern");
// }
//
// if (xo.hasAttribute(XMLParser.ID)) {
// final Logger logger = Logger.getLogger("dr.evoxml");
// logger.info("Site patterns '" + xo.getId() + "' created by masking alignment with id '" + siteList.getId() + "'");
// logger.info(" pattern count = " + patterns.getPatternCount());
// }
//
// return patterns;
if (onCount == 0) {
throw new XMLParseException("The mask needs to have at least one site unmasked");
}

return new MaskedAlignment(alignment, mask);
}

public XMLSyntaxRule[] getSyntaxRules() { return rules; }
Expand All @@ -103,9 +93,9 @@ public Object parseXMLObject(XMLObject xo) throws XMLParseException {
};

public String getParserDescription() {
return "A weighted list of the unique site patterns (unique columns) in an alignment.";
return "Applies a mask to an alignment so that masked sites are ambiguous.";
}

public Class getReturnType() { return PatternList.class; }
public Class getReturnType() { return MaskedAlignment.class; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@

package dr.inferencexml.operators.shrinkage;

import dr.evomodel.branchratemodel.AutoCorrelatedBranchRatesDistribution;
import dr.inference.distribution.DistributionLikelihood;
import dr.inference.distribution.shrinkage.BayesianBridgeStatisticsProvider;
import dr.inference.model.Parameter;
import dr.inference.operators.shrinkage.BayesianBridgeShrinkageOperator;
import dr.math.distributions.GammaDistribution;
import dr.xml.*;

import static dr.evoxml.MaskedPatternsParser.MASK;
import static dr.inference.operators.MCMCOperator.WEIGHT;

public class BayesianBridgeShrinkageOperatorParser extends AbstractXMLObjectParser {

public final static String BAYESIAN_BRIDGE_PARSER = "bayesianBridgeGibbsOperator";
public final static String MASK = "mask";
public final static String WEIGHT = "weight";

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
import dr.math.distributions.GammaDistribution;
import dr.xml.*;

import static dr.evoxml.MaskedPatternsParser.MASK;
import static dr.inference.operators.MCMCOperator.WEIGHT;

public class DimensionMismatchedBayesianBridgeShrinkageOperatorParser extends AbstractXMLObjectParser {

public final static String BAYESIAN_BRIDGE_PARSER = "dimensionMismatchedBayesianBridgeGibbsOperator";
public final static String MASK = "mask";
public final static String WEIGHT = "weight";

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Expand Down

0 comments on commit cdcfb32

Please sign in to comment.