Debian Codegraph @

src/dr/app/seqgen/MicrosatelliteSimulator.java

raw symbols SCIP
1 /*
2 * MicrosatelliteSimulator.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.seqgen;
27
28 import dr.evolution.tree.Tree;
29 import dr.evolution.tree.NodeRef;
30 import dr.evolution.datatype.Microsatellite;
31 import dr.evolution.alignment.Alignment;
32 import dr.evolution.alignment.Patterns;
33 import dr.evolution.sequence.Sequence;
34 import dr.evolution.util.Taxa;
35 import dr.oldevomodel.sitemodel.SiteModel;
36 import dr.oldevomodel.sitemodel.GammaSiteModel;
37 import dr.evomodel.branchratemodel.BranchRateModel;
38 import dr.oldevomodel.substmodel.MicrosatelliteModel;
39
40 /**
41 * @author Chieh-Hsi Wu
42 *
43 * Simulates a pattern of microsatellites given a tree and microsatellite model
44 *
45 */
46 public class MicrosatelliteSimulator extends SequenceSimulator{
47 private Taxa taxa;
48 private Microsatellite dataType;
49
50 public MicrosatelliteSimulator(
51 Microsatellite dataType,
52 Taxa taxa,
53 Tree tree,
54 MicrosatelliteModel msatModel,
55 BranchRateModel branchRateModel){
56 this(dataType, taxa, tree, new GammaSiteModel(msatModel), branchRateModel);
57
58 }
59
60 public MicrosatelliteSimulator(
61 Microsatellite dataType,
62 Taxa taxa,
63 Tree tree,
64 SiteModel siteModel,
65 BranchRateModel branchRateModel) {
66
67 super(tree, siteModel, branchRateModel, 1);
68 this.dataType = dataType;
69 this.taxa = taxa;
70 }
71
72 /**
73 * Convert integer representation of microsatellite length to string.
74 */
75 Sequence intArray2Sequence(int [] seq, NodeRef node) {
76 String sSeq = ""+seq[0];
77 return new Sequence(m_tree.getNodeTaxon(node), sSeq);
78 } // intArray2Sequence
79
80 /**
81 * Convert an alignment to a pattern
82 */
83 public Patterns simulateMsatPattern(){
84 Alignment align = simulate();
85
86 int[] pattern = new int[align.getTaxonCount()];
87 for(int i = 0; i < pattern.length; i++){
88 String taxonName = align.getSequence(i).getTaxon().getId();
89 int index = taxa.getTaxonIndex(taxonName);
90 pattern[index] = Integer.parseInt(align.getSequence(i).getSequenceString());
91 }
92 Patterns patterns = new Patterns(dataType,taxa);
93 patterns.addPattern(pattern);
94 for(int i = 0; i < pattern.length;i++){
95 System.out.print(pattern[i]+",");
96 }
97 System.out.println();
98
99 return patterns;
100 }
101
102 }