Debian Codegraph @

src/dr/app/realtime/SimpleDistanceMatrix.java

raw symbols SCIP
1 /*
2 * SimpleDistanceMatrix.java
3 *
4 * Copyright (c) 2002-2017 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.app.realtime;
27
28 import dr.evolution.alignment.PatternList;
29 import dr.evolution.distance.DistanceMatrix;
30
31 /**
32 * @author Guy Baele
33 */
34 public class SimpleDistanceMatrix extends DistanceMatrix
35 {
36
37 /** constructor */
38 public SimpleDistanceMatrix()
39 {
40 super();
41 }
42
43 /** constructor taking a pattern source */
44 public SimpleDistanceMatrix(PatternList patterns)
45 {
46 super(patterns);
47 }
48
49 /**
50 * set the pattern source
51 */
52 public void setPatterns(PatternList patterns) {
53 super.setPatterns(patterns);
54
55 final int stateCount = patterns.getStateCount();
56 }
57
58 /**
59 * Calculate a pairwise distance
60 */
61 protected double calculatePairwiseDistance(int taxon1, int taxon2) {
62
63 int state1, state2;
64 int n = patterns.getPatternCount();
65 int gapState = patterns.getDataType().getGapState();
66 int[] pattern;
67 double weight, distance;
68 double sumDistance = 0.0;
69 double sumWeight = 0.0;
70
71 for (int i = 0; i < n; i++) {
72 pattern = patterns.getPattern(i);
73
74 state1 = pattern[taxon1];
75 state2 = pattern[taxon2];
76 weight = patterns.getPatternWeight(i);
77
78 //only count if neither state is a gap
79 if (state1 != gapState && state2 != gapState) {
80 if (!dataType.isAmbiguousState(state1) && !dataType.isAmbiguousState(state2) && state1 != state2) {
81 sumDistance += weight;
82 }
83 sumWeight += weight;
84 }
85
86 }
87
88 distance = sumDistance / sumWeight;
89
90 return distance;
91 }
92
93 }