Debian Codegraph @

src/dr/evomodel/alloppnet/operators/AlloppSequenceReassignment.java

raw symbols SCIP
1 /*
2 * AlloppSequenceReassignment.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.evomodel.alloppnet.operators;
27
28 import dr.evolution.util.Taxon;
29 import dr.evomodel.alloppnet.speciation.AlloppLeggedTree;
30 import dr.evomodel.alloppnet.speciation.AlloppSpeciesBindings;
31 import dr.evomodel.alloppnet.speciation.AlloppSpeciesNetworkModel;
32 import dr.evomodel.alloppnet.parsers.AlloppSequenceReassignmentParser;
33 import dr.inference.operators.SimpleMCMCOperator;
34 import dr.math.MathUtils;
35
36 import java.util.ArrayList;
37
38
39 /**
40 *
41 * @author Graham Jones
42 * Date: 01/07/2011
43 */
44 public class AlloppSequenceReassignment extends SimpleMCMCOperator {
45
46 private final AlloppSpeciesNetworkModel apspnet;
47 private final AlloppSpeciesBindings apsp;
48
49
50 public AlloppSequenceReassignment(AlloppSpeciesNetworkModel apspnet, AlloppSpeciesBindings apsp, double weight) {
51 this.apspnet = apspnet;
52 this.apsp = apsp;
53 setWeight(weight);
54 }
55
56
57 public String getPerformanceSuggestion() {
58 return "None";
59 }
60
61 @Override
62 public String getOperatorName() {
63 return AlloppSequenceReassignmentParser.SEQUENCE_REASSIGNMENT + "(" + apspnet.getId() +
64 "," + apsp.getId() + ")";
65 }
66
67 @Override
68 public double doOperation() {
69 apspnet.beginNetworkEdit();
70
71 if (MathUtils.nextInt(10) == 0) {
72 int tt = MathUtils.nextInt(apspnet.getNumberOfTetraTrees());
73 AlloppLeggedTree ttree = apspnet.getTetraploidTree(tt);
74 ArrayList<Taxon> sptxs = ttree.getSpeciesTaxons();
75 for (Taxon tx : sptxs) {
76 int spi = apsp.apspeciesId2index(tx.getId());
77 apsp.flipAssignmentsForAllGenesOneSpecies(spi);
78 }
79 apspnet.flipLegsOfTetraTree(tt);
80 } else {
81 if (MathUtils.nextInt(2) == 0) {
82 apsp.permuteOneSpeciesOneIndivForOneGene();
83 } else {
84 apsp.permuteSetOfIndivsForOneGene();
85 }
86 }
87
88
89 apspnet.endNetworkEdit();
90 assert apspnet.alloppspeciesnetworkOK();
91 return 0;
92 }
93
94 }
95
96