Debian Codegraph @

src/dr/app/beauti/options/PartitionData.java

raw symbols SCIP
1 /*
2 * PartitionData.java
3 *
4 * Copyright (c) 2002-2015 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.beauti.options;
27
28 import dr.evolution.alignment.Alignment;
29 import dr.evolution.alignment.Patterns;
30 import dr.evolution.datatype.DataType;
31 import dr.evolution.util.TaxonList;
32
33 import java.util.List;
34
35 /**
36 * @author Andrew Rambaut
37 * @author Alexei Drummond
38 * @author Walter Xie
39 */
40 public class PartitionData extends AbstractPartitionData {
41
42 private static final long serialVersionUID = 1642891822797102561L;
43
44 private final Alignment alignment;
45
46 private int fromSite;
47 private int toSite;
48 private int every = 1;
49
50
51 public PartitionData(BeautiOptions options, String name, String fileName, Alignment alignment) {
52 this(options, name, fileName, alignment, -1, -1, 1);
53 }
54
55 public PartitionData(BeautiOptions options, String name, String fileName, Alignment alignment, int fromSite, int toSite, int every) {
56 super(options, name, fileName);
57 this.alignment = alignment;
58
59 this.fromSite = fromSite;
60 this.toSite = toSite;
61 this.every = every;
62
63 this.traits = null;
64
65 Patterns patterns = null;
66 if (alignment != null) {
67 patterns = new Patterns(alignment);
68 }
69
70 // This is too slow to be done at data loading.
71 // calculateMeanDistance(patterns);
72 calculateMeanDistance(null);
73 }
74
75 public PartitionData(BeautiOptions options, String name, String fileName, List<TraitData> traits) {
76 super(options, name, fileName);
77 this.alignment = null;
78
79 this.fromSite = -1;
80 this.toSite = -1;
81 this.every = 1;
82
83 this.traits = traits;
84
85 calculateMeanDistance(null);
86 }
87
88 public Alignment getAlignment() {
89 return alignment;
90 }
91
92 public int getFromSite() {
93 return fromSite;
94 }
95
96 public int getToSite() {
97 return toSite;
98 }
99
100 public int getEvery() {
101 return every;
102 }
103
104 public TaxonList getTaxonList() {
105 if (traits != null) {
106 // // if this is a trait then just give the complete taxon list (taxa without specified
107 // // traits are treated as missing data.
108 // return options.taxonList;
109 return null;
110 }
111 return getAlignment();
112 }
113
114 public int getSiteCount() {
115 if (alignment != null) {
116 int from = getFromSite();
117 if (from < 1) {
118 from = 1;
119 }
120 int to = getToSite();
121 if (to < 1) {
122 to = alignment.getSiteCount();
123 }
124 return (to - from + 1) / every;
125 } else {
126 return traits.size();
127 }
128 }
129
130 public DataType getDataType() {
131 if (alignment != null) {
132 return alignment.getDataType();
133 } else if (traits != null) {
134 return traits.get(0).getDataType();
135 } else {
136 throw new RuntimeException("Trait and alignment are null");
137 }
138 }
139
140 public String getDataDescription() {
141 if (alignment != null) {
142 return alignment.getDataType().getDescription();
143 } else if (traits != null) {
144 return traits.get(0).getTraitType().toString();
145 } else {
146 throw new RuntimeException("Trait and alignment are null");
147 }
148 }
149
150 public String getPrefix() {
151 String prefix = "";
152
153 if (getTraits() != null) {
154 // if it is a trait partition then always give a prefix
155 prefix += getName() + ".";
156 } else {
157 // this method provides prefix as long as multi-data-partitions case,
158 // because options.dataPartitions may contain traits, use options.getPartitionData()
159 if (options.getPartitionData().size() > 1) { // getPartitionData() already excludes traits and microsatellite
160 prefix += getName() + ".";
161 }
162 }
163
164 return prefix;
165 }
166
167 }