package dr.evomodel.substmodel;

import dr.evomodel.substmodel.aminoacid.EmpiricalAminoAcidModel;
import dr.inference.model.DesignMatrix;
import dr.inference.model.Parameter;

import java.util.List;

public class AminoAcidMixture extends DesignMatrix {

    public AminoAcidMixture(List<EmpiricalAminoAcidModel> rateMatrix) {
        super("name", getParameters(rateMatrix), false);
    }

    private static Parameter[] getParameters(List<EmpiricalAminoAcidModel> rateMatrix) {
        Parameter[] p = new Parameter[rateMatrix.size()];

        for (int i = 0; i < p.length; ++i) {
            System.err.println("AminoAcidMixture::getParameters()");
            EmpiricalAminoAcidModel model = rateMatrix.get(i);
            // this is a flat representation of the lower triangular order
            double[] rates = model.getEmpiricalRateMatrix().getEmpiricalRates();

            // We need upper and lower triangular rates, both logged
            double[] ratesUpperLower = new double[2*rates.length];
            for ( int j = 0; j < rates.length; j++ ) {
                ratesUpperLower[j] = ratesUpperLower[rates.length + j] = Math.log(rates[j]);
            }
            p[i] = new Parameter.Default(ratesUpperLower);

        }
        return p;
    }


}

@@ -337,14 +337,27 @@
 per(
-%22name%22
+getName(rateMatrix)
 , ge
@@ -396,16 +396,409 @@
 %0A    %7D%0A%0A
+    private static String getName(List%3CEmpiricalAminoAcidModel%3E rateMatrix) %7B%0A        StringBuilder sb = new StringBuilder(%22designMatrix%22);%0A        for (EmpiricalAminoAcidModel matrix : rateMatrix) %7B%0A            String id = matrix.getId();%0A            if (id != null && id.length() %3E 0) %7B%0A                sb.append(%22.%22).append(id);%0A            %7D%0A        %7D%0A        return sb.toString();%0A    %7D%0A%0A
     priv
@@ -986,77 +986,8 @@
 ) %7B%0A
-            System.err.println(%22AminoAcidMixture::getParameters()%22);%0A
     
@@ -1559,17 +1559,16 @@
 Lower);%0A
-%0A
         
@@ -1591,14 +1591,12 @@
  p;%0A
+
     %7D%0A
-%0A%0A
 %7D%0A

use a nice pretty name for checkpointing