| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 42 |
|
| 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 |
|