Debian Codegraph @

src/dr/evolution/MetagenomeData.java

raw symbols SCIP
1 /*
2 * MetagenomeData.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.evolution;
27
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
31
32 import dr.evolution.alignment.Alignment;
33 import dr.evolution.tree.Tree;
34 import dr.evolution.util.Taxa;
35 import dr.evolution.util.Taxon;
36 import dr.evolution.util.TaxonList;
37 import dr.util.Attributable;
38 import dr.util.Identifiable;
39
40 /**
41 * @author Aaron Darling (koadman)
42 */
43 public class MetagenomeData implements Attributable, Identifiable {
44
45 protected String id = null;
46 protected Alignment alignment;
47 protected Taxa referenceTaxa;
48 protected Taxa reads;
49 protected LinkageConstraints constraints;
50 protected boolean fixedReferenceTree;
51
52 public MetagenomeData(TaxonList taxa, Alignment alignment)
53 {
54 this(taxa, alignment, null, false);
55 }
56 public MetagenomeData(TaxonList taxa, Alignment alignment, LinkageConstraints constraints, boolean fixedReferenceTree)
57 {
58 this.alignment = alignment;
59 this.constraints = constraints;
60 this.fixedReferenceTree = fixedReferenceTree;
61 referenceTaxa = new Taxa(taxa.asList());
62 if(fixedReferenceTree == true && !(taxa instanceof Tree)){
63 throw new RuntimeException("Error, a tree must be provided in order to fix the topology of reference taxa");
64 }
65 reads = new Taxa();
66 List<Taxon> alltaxa = alignment.asList();
67 for(int i=0; i<alltaxa.size(); i++)
68 {
69 if(!referenceTaxa.contains(alltaxa.get(i)))
70 reads.addTaxon(alltaxa.get(i));
71 }
72 if(constraints==null){
73 this.constraints = new LinkageConstraints(new ArrayList<LinkedGroup>());
74 }
75 }
76
77 public TaxonList getReferenceTaxa(){
78 return referenceTaxa;
79 }
80 public TaxonList getReadsTaxa(){
81 return reads;
82 }
83
84 public Alignment getAlignment() {
85 return alignment;
86 }
87
88 public void setAlignment(Alignment alignment) {
89 this.alignment = alignment;
90 }
91
92 public ArrayList<LinkedGroup> getConstraints(){
93 return constraints.getLinkedGroups();
94 }
95
96 public boolean getFixedReferenceTree(){
97 return fixedReferenceTree;
98 }
99 public void setFixedReferenceTree(boolean fixedReferenceTree){
100 this.fixedReferenceTree = fixedReferenceTree;
101 }
102
103 public String getId() {
104 return id;
105 }
106
107 public void setId(String id) {
108 this.id = id;
109 }
110 // **************************************************************
111 // Attributable IMPLEMENTATION
112 // **************************************************************
113
114 private Attributable.AttributeHelper attributes = null;
115
116 /**
117 * Sets an named attribute for this object.
118 *
119 * @param name the name of the attribute.
120 * @param value the new value of the attribute.
121 */
122 public void setAttribute(String name, Object value) {
123 if (attributes == null)
124 attributes = new Attributable.AttributeHelper();
125 attributes.setAttribute(name, value);
126 }
127
128 /**
129 * @param name the name of the attribute of interest.
130 * @return an object representing the named attributed for this object.
131 */
132 public Object getAttribute(String name) {
133 if (attributes == null)
134 return null;
135 else
136 return attributes.getAttribute(name);
137 }
138
139 /**
140 * @return an iterator of the attributes that this object has.
141 */
142 public Iterator<String> getAttributeNames() {
143 if (attributes == null)
144 return null;
145 else
146 return attributes.getAttributeNames();
147 }
148
149 }