package dr.app.seqgen;

import dr.evolution.tree.Tree;
import dr.evolution.tree.NodeRef;
import dr.evolution.datatype.Microsatellite;
import dr.evolution.alignment.Alignment;
import dr.evolution.alignment.Patterns;
import dr.evolution.sequence.Sequence;
import dr.evolution.util.Taxa;
import dr.evomodel.sitemodel.SiteModel;
import dr.evomodel.branchratemodel.BranchRateModel;

/**
 * @author Chieh-Hsi Wu
 *
 * Simulates a pattern of microsatellites given a tree and microsatellite model
 *
 */
public class MicrosatelliteSimulator extends SequenceSimulator{
    private Taxa taxa;
    private Microsatellite dataType;

    public MicrosatelliteSimulator(
            Microsatellite dataType,
            Taxa taxa,
            Tree tree,
            SiteModel siteModel,
            BranchRateModel branchRateModel) {

    	super(tree, siteModel, branchRateModel, 1);
        this.dataType = dataType;
        this.taxa = taxa;
    }

    /**
     * Convert integer representation of microsatellite length to string.
     */
	Sequence intArray2Sequence(int [] seq, NodeRef node) {
    	String sSeq = ""+seq[0];
		return new Sequence(m_tree.getNodeTaxon(node), sSeq);
    } // intArray2Sequence

    /**
     * Convert an alignment to a pattern
     */
    public Patterns simulateMsatPattern(){
        Alignment align = simulate();

        int[] pattern = new int[align.getTaxonCount()];
        for(int i = 0; i < pattern.length; i++){
            String taxonName = align.getSequence(i).getTaxon().getId();
            int index = taxa.getTaxonIndex(taxonName);
            pattern[index] = Integer.parseInt(align.getSequence(i).getSequenceString());
        }
        Patterns patterns = new Patterns(dataType,taxa);
        patterns.addPattern(pattern);
        return patterns;
    }

}

@@ -351,39 +351,164 @@
 del.
-branchratemodel.BranchRateModel
+sitemodel.GammaSiteModel;%0D%0Aimport dr.evomodel.branchratemodel.BranchRateModel;%0D%0Aimport dr.evomodel.substmodel.MicrosatelliteModel;%0D%0Aimport dr.math.MathUtils
 ;%0D%0A%0D
@@ -717,24 +717,24 @@
 Taxa taxa;%0D%0A
-
     private 
@@ -757,24 +757,334 @@
 ataType;%0D%0A%0D%0A
+    public MicrosatelliteSimulator(%0D%0A            Microsatellite dataType,%0D%0A            Taxa taxa,%0D%0A            Tree tree,%0D%0A            MicrosatelliteModel msatModel,%0D%0A            BranchRateModel branchRateModel)%7B%0D%0A        this(dataType, taxa, tree, new GammaSiteModel(msatModel), branchRateModel);%0D%0A%0D%0A    %7D%0D%0A%0D%0A
     public M
@@ -2242,24 +2242,172 @@
 (pattern);%0D%0A
+        for(int i = 0; i %3C pattern.length;i++)%7B%0D%0A            System.out.print(pattern%5Bi%5D+%22,%22);%0D%0A        %7D%0D%0A        System.out.println();%0D%0A        %0D%0A
         retu

add new constructor.