Skip to content

Commit

Permalink
use getExcludedGenerator first #136
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Apr 16, 2024
1 parent 502a991 commit 5a3b303
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 48 deletions.
56 changes: 9 additions & 47 deletions lphybeast/src/main/java/lphybeast/spi/LPhyBEASTExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,12 @@
import beast.base.evolution.datatype.DataType;
import jebl.evolution.sequences.SequenceType;
import lphy.base.distribution.DiscretizedGamma;
import lphy.base.distribution.RandomComposition;
import lphy.base.distribution.Sample;
import lphy.base.distribution.WeightedDirichlet;
import lphy.base.evolution.Taxa;
import lphy.base.evolution.alignment.Alignment;
import lphy.base.evolution.tree.TimeTree;
import lphy.base.function.*;
import lphy.base.function.alignment.*;
import lphy.base.function.datatype.BinaryDatatypeFunction;
import lphy.base.function.datatype.NucleotidesFunction;
import lphy.base.function.datatype.StandardDatatypeFunction;
import lphy.base.function.io.WriteFasta;
import lphy.base.function.taxa.*;
import lphy.base.function.tree.ExtantTree;
import lphy.base.function.tree.MigrationCount;
import lphy.base.function.tree.NodeCount;
import lphy.core.model.ExpressionNode;
import lphy.core.model.Generator;
import lphy.core.model.Value;
import lphy.core.parser.function.ExpressionNodeWrapper;
import lphy.core.parser.function.MapFunction;
import lphy.core.parser.function.MethodCall;
import lphy.core.simulator.Simulate;
import lphy.core.vectorization.IID;
import lphy.core.vectorization.array.ArrayFunction;
import lphy.core.vectorization.operation.ElementsAt;
import lphy.core.vectorization.operation.Range;
import lphy.core.vectorization.operation.RangeList;
import lphybeast.GeneratorToBEAST;
import lphybeast.ValueToBEAST;
import lphybeast.tobeast.operators.DefaultTreeOperatorStrategy;
Expand Down Expand Up @@ -77,6 +55,7 @@ default TreeOperatorStrategy getTreeOperatorStrategy() {
* For a complex logic, or arrays.
* @param val Value
* @return if the value type is excluded.
* @see LPhyBEASTExtImpl#getExcludedValueType()
*/
static boolean isExcludedValue(Value<?> val) {
Object ob = val.value();
Expand All @@ -86,33 +65,16 @@ static boolean isExcludedValue(Value<?> val) {
ob instanceof TimeTree[];
}

/**
* For a complex logic, or arrays.
* @param generator Generator
* @return if the Generator is excluded.
* @see LPhyBEASTExtImpl#getExcludedGenerator()
*/
static boolean isExcludedGenerator(Generator generator) {

return generator instanceof WeightedDirichlet || generator instanceof ArrayFunction ||
generator instanceof ExpressionNode || generator instanceof RandomComposition ||
generator instanceof NTaxaFunction || generator instanceof NCharFunction ||
generator instanceof TaxaFunction || generator instanceof NodeCount ||
generator instanceof CreateTaxa || generator instanceof SpeciesTaxa ||
generator instanceof TaxaAgesFromFunction || generator instanceof Get<?> ||
generator instanceof MissingSites || generator instanceof SelectSitesByMissingFraction ||
generator instanceof InvariableSites || generator instanceof VariableSites ||
generator instanceof CopySites || generator instanceof Sample<?> ||
generator instanceof Simulate || generator instanceof WriteFasta ||
// generator instanceof ReadNexus || generator instanceof ReadFasta ||
generator instanceof ExtractTrait || generator instanceof Unique ||
generator instanceof Intersect || generator instanceof RepArray ||
generator instanceof Sort<?> || generator instanceof ConcatArray ||
generator instanceof ARange || generator instanceof Range ||
generator instanceof MapFunction || generator instanceof MethodCall ||
generator instanceof RangeList || generator instanceof ElementsAt || generator instanceof Rep ||
generator instanceof MigrationMatrix || generator instanceof MigrationCount ||
generator instanceof Length || generator instanceof Select || generator instanceof SumBoolean ||
generator instanceof DiscretizedGamma || generator instanceof ExtantTree ||
// ignore all data types
generator instanceof NucleotidesFunction || generator instanceof StandardDatatypeFunction ||
generator instanceof BinaryDatatypeFunction || //generator instanceof PhasedGenotypeFunction ||
(generator instanceof IID && ((IID<?>) generator).getBaseDistribution() instanceof DiscretizedGamma) ||
generator instanceof ExpressionNodeWrapper;
return (generator instanceof IID && ((IID<?>) generator).getBaseDistribution() instanceof DiscretizedGamma);
// use || to add more ...
}

}
47 changes: 46 additions & 1 deletion lphybeast/src/main/java/lphybeast/spi/LPhyBEASTExtImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@

import beast.base.evolution.datatype.DataType;
import jebl.evolution.sequences.SequenceType;
import lphy.base.distribution.DiscretizedGamma;
import lphy.base.distribution.RandomComposition;
import lphy.base.distribution.Sample;
import lphy.base.distribution.WeightedDirichlet;
import lphy.base.evolution.datatype.Binary;
import lphy.base.evolution.datatype.Continuous;
import lphy.base.function.*;
import lphy.base.function.alignment.*;
import lphy.base.function.datatype.BinaryDatatypeFunction;
import lphy.base.function.datatype.NucleotidesFunction;
import lphy.base.function.datatype.StandardDatatypeFunction;
import lphy.base.function.io.ReadFasta;
import lphy.base.function.io.ReadNexus;
import lphy.base.function.io.WriteFasta;
import lphy.base.function.taxa.*;
import lphy.base.function.tree.ExtantTree;
import lphy.base.function.tree.MigrationCount;
import lphy.base.function.tree.NodeCount;
import lphy.core.model.ExpressionNode;
import lphy.core.model.Generator;
import lphy.core.parser.function.ExpressionNodeWrapper;
import lphy.core.parser.function.MapFunction;
import lphy.core.parser.function.MethodCall;
import lphy.core.simulator.Simulate;
import lphy.core.vectorization.array.ArrayFunction;
import lphy.core.vectorization.operation.ElementsAt;
import lphy.core.vectorization.operation.Range;
import lphy.core.vectorization.operation.RangeList;
import lphybeast.GeneratorToBEAST;
import lphybeast.ValueToBEAST;
import lphybeast.tobeast.generators.*;
import lphybeast.tobeast.values.*;

import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -99,7 +123,28 @@ public Map<SequenceType, DataType> getDataTypeMap() {
@Override
public List<Class<? extends Generator>> getExcludedGenerator() {
return List.of(
ReadNexus.class, ReadFasta.class
ReadNexus.class, ReadFasta.class, WriteFasta.class, // IO
// Taxa and sites
NTaxaFunction.class, NCharFunction.class, TaxaFunction.class, CreateTaxa.class,
SpeciesTaxa.class, TaxaAgesFromFunction.class,
CopySites.class, MissingSites.class, SelectSitesByMissingFraction.class, InvariableSites.class,
VariableSites.class,
DiscretizedGamma.class,
// Tree
NodeCount.class, ExtractTrait.class, ExtantTree.class,
MigrationMatrix.class, MigrationCount.class,
// distribution
WeightedDirichlet.class,
// utils
MapFunction.class, ConcatArray.class, ARange.class, Range.class, RangeList.class,
ElementsAt.class, Rep.class, RepArray.class, Sort.class, Unique.class,
Get.class, Length.class, Select.class, Intersect.class,
RandomComposition.class, SumBoolean.class,
// sequence typs
NucleotidesFunction.class, StandardDatatypeFunction.class, BinaryDatatypeFunction.class,
// lphy
MethodCall.class, Simulate.class, Sample.class, ArrayFunction.class,
ExpressionNode.class, ExpressionNodeWrapper.class
);
}

Expand Down

0 comments on commit 5a3b303

Please sign in to comment.