| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.alignment; |
| 27 |
|
| 28 |
import dr.evolution.datatype.DataType; |
| 29 |
import dr.evolution.util.TaxonList; |
| 30 |
import dr.util.Author; |
| 31 |
import dr.util.Citable; |
| 32 |
import dr.util.Citation; |
| 33 |
|
| 34 |
import java.util.*; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class UncertainSiteList extends SimpleSiteList implements Citable { |
| 40 |
|
| 41 |
public UncertainSiteList(DataType dataType, TaxonList taxonList) { |
| 42 |
super(dataType, taxonList); |
| 43 |
} |
| 44 |
|
| 45 |
public int addPattern(int[] pattern) { |
| 46 |
throw new IllegalArgumentException("Do not call directly"); |
| 47 |
} |
| 48 |
|
| 49 |
public void addPattern(double[][] uncertainPattern) { |
| 50 |
uncertainSitePatterns.add(uncertainPattern); |
| 51 |
|
| 52 |
int[] map = new int[uncertainPattern.length]; |
| 53 |
for (int i = 0; i < uncertainPattern.length; ++i) { |
| 54 |
map[i] = getMostProbable(uncertainPattern[i]); |
| 55 |
} |
| 56 |
super.addPattern(map); |
| 57 |
} |
| 58 |
|
| 59 |
private static int getMostProbable(double[] probabilities) { |
| 60 |
int map = 0; |
| 61 |
double maxProb = probabilities[0]; |
| 62 |
|
| 63 |
for (int i = 1; i < probabilities.length; ++i) { |
| 64 |
if (probabilities[i] > maxProb) { |
| 65 |
maxProb = probabilities[i]; |
| 66 |
map = i; |
| 67 |
} |
| 68 |
} |
| 69 |
return map; |
| 70 |
} |
| 71 |
|
| 72 |
public void fillPartials(final int sequenceIndex, final int site, double[] partials, final int offset) { |
| 73 |
double[][] sitePatterns = uncertainSitePatterns.get(site); |
| 74 |
System.arraycopy(sitePatterns[sequenceIndex], 0, partials, offset, getDataType().getStateCount()); |
| 75 |
} |
| 76 |
|
| 77 |
@Override |
| 78 |
public Citation.Category getCategory() { |
| 79 |
return Citation.Category.DATA_MODELS; |
| 80 |
} |
| 81 |
|
| 82 |
@Override |
| 83 |
public String getDescription() { |
| 84 |
return "Uncertain site list"; |
| 85 |
} |
| 86 |
|
| 87 |
public List<Citation> getCitations() { |
| 88 |
return Arrays.asList( |
| 89 |
new Citation( |
| 90 |
new Author[]{ |
| 91 |
new Author("MA", "Suchard"), |
| 92 |
new Author("P", "Lemey"), |
| 93 |
new Author("M", "Scotch"), |
| 94 |
|
| 95 |
}, |
| 96 |
Citation.Status.IN_PREPARATION |
| 97 |
)); |
| 98 |
} |
| 99 |
|
| 100 |
private List<double[][]> uncertainSitePatterns = new ArrayList<double[][]>(); |
| 101 |
} |