Debian Codegraph @

src/dr/evolution/alignment/UncertainSiteList.java

raw symbols SCIP
1 /*
2 * UncertainSiteList.java
3 *
4 * Copyright (c) 2002-2016 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * Created by msuchard on 2016-05-19.
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 }