use of bacter.Region in project bacter by tgvaughan.
the class ConversionGraphStatsLogger method getMeanRegionLength.
/**
* Obtain mean length of contiguous regions having the same marginal
* tree and being affected by at least 1 conversion.
*
* @param acg
* @param locus
* @return mean length
*/
public static double getMeanRegionLength(ConversionGraph acg, Locus locus) {
double sum = 0.0;
int count = 0;
for (Region region : acg.getRegions(locus)) if (!region.isClonalFrame()) {
sum += region.getRegionLength();
count += 1;
}
if (count == 0)
return Double.NaN;
else
return sum / count;
}
use of bacter.Region in project bacter by tgvaughan.
the class ACGLikelihoodSlow method calculateLogP.
@Override
public double calculateLogP() {
logP = 0.0;
for (Region region : acg.getRegions(locus)) {
Alignment margAlign = createMarginalAlignment(alignment, acg, region);
Tree margTree = new Tree(new MarginalTree(acg, region).getRoot());
TreeLikelihood treeLikelihood = new TreeLikelihood();
treeLikelihood.initByName("data", margAlign, "tree", margTree, "siteModel", siteModel, "useAmbiguities", useAmbiguitiesInput.get());
logP += treeLikelihood.calculateLogP();
}
return logP;
}
use of bacter.Region in project bacter by tgvaughan.
the class SimulatedAlignment method simulate.
/**
* Perform actual sequence simulation.
*/
private void simulate(Locus locus) {
Node cfRoot = acg.getRoot();
int nTaxa = acg.getLeafNodeCount();
double[] categoryProbs = siteModel.getCategoryProportions(cfRoot);
int nCategories = siteModel.getCategoryCount();
int nStates = dataType.getStateCount();
double[][] transitionProbs = new double[nCategories][nStates * nStates];
int[][] alignment = new int[nTaxa][locus.getSiteCount()];
for (Region region : acg.getRegions(locus)) {
int thisLength = region.getRegionLength();
MarginalTree marginalTree = new MarginalTree(acg, region);
int[] categories = new int[thisLength];
for (int i = 0; i < thisLength; i++) categories[i] = Randomizer.randomChoicePDF(categoryProbs);
int[][] regionAlignment = new int[nTaxa][thisLength];
Node thisRoot = marginalTree.getRoot();
int[] parentSequence = new int[region.getRegionLength()];
double[] frequencies = siteModel.getSubstitutionModel().getFrequencies();
for (int i = 0; i < parentSequence.length; i++) parentSequence[i] = Randomizer.randomChoicePDF(frequencies);
traverse(thisRoot, parentSequence, categories, transitionProbs, regionAlignment);
// DEBUG: Count differences
int segsites = 0;
for (int s = 0; s < regionAlignment[0].length; s++) {
int state = regionAlignment[0][s];
for (int l = 1; l < nTaxa; l++) {
if (state != regionAlignment[l][s]) {
segsites += 1;
break;
}
}
}
System.out.println(segsites + " segregating sites in region " + region);
copyToAlignment(alignment, regionAlignment, region);
}
for (int leafIdx = 0; leafIdx < nTaxa; leafIdx++) {
String sSeq = dataType.encodingToString(alignment[leafIdx]);
String sTaxon = acg.getNode(leafIdx).getID();
sequenceInput.setValue(new Sequence(sTaxon, sSeq), this);
}
}
Aggregations