Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 23.50 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class HMM {
  5.  
  6.     private final List<State> startCodons = new ArrayList<State>();
  7.     private final List<State> stopCodons = new ArrayList<State>();
  8.     private final List<State> codingRegionTypicals = new ArrayList<State>();
  9.     private final List<State> codingRegionAtypicals = new ArrayList<State>();
  10.     private final Transition transition = new Transition();
  11.    
  12.     public HMM(bool probabilitySet) {
  13.         if (probabilitySet == true) {
  14.             probability();
  15.         }
  16.     }
  17.  
  18.     public HMM() {
  19.         startCodons.add(new State(0.8, 0.01, 0.01, 0.18));
  20.         startCodons.add(new State(0.01, 0.97, 0.01, 0.01));
  21.         startCodons.add(new State(0.01, 0.01, 0.01, 0.97));
  22.  
  23.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  24.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  25.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  26.  
  27.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  28.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  29.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  30.  
  31.         stopCodons.add(new State(0.01, 0.97, 0.01, 0.01));
  32.         stopCodons.add(new State(0.97, 0.01, 0.01, 0.01));
  33.         stopCodons.add(new State(0.3, 0.15, 0.15, 0.3));
  34.  
  35.         transition.setStartAtypical(0.2);
  36.         transition.setStartTypical(0.8);
  37.         transition.setTypicalTypical(0.5);
  38.         transition.setAtypicalAtypical(0.5);
  39.         transition.setTypicalStop(0.5);
  40.         transition.setAtypicalStop(0.5);
  41.  
  42.     }
  43.  
  44.     public void probability() {
  45.         startCodons.add(new State(0.8, 0.01, 0.01, 0.18));
  46.         startCodons.add(new State(0.01, 0.97, 0.01, 0.01));
  47.         startCodons.add(new State(0.01, 0.01, 0.01, 0.97));
  48.  
  49.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  50.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  51.         codingRegionTypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  52.  
  53.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  54.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  55.         codingRegionAtypicals.add(new State(0.25, 0.25, 0.25, 0.25));
  56.  
  57.         stopCodons.add(new State(0.01, 0.97, 0.01, 0.01));
  58.         stopCodons.add(new State(0.97, 0.01, 0.01, 0.01));
  59.         stopCodons.add(new State(0.3, 0.15, 0.15, 0.3));
  60.  
  61.         transition.setStartAtypical(0.2);
  62.         transition.setStartTypical(0.8);
  63.         transition.setTypicalTypical(0.5);
  64.         transition.setAtypicalAtypical(0.5);
  65.         transition.setTypicalStop(0.5);
  66.         transition.setAtypicalStop(0.5);
  67.  
  68.     }
  69.  
  70.     public void prediction(DNA dna) {
  71.         double deltaTypical1, deltaTypical2, deltaTypical3;
  72.         double deltaATypical1, deltaATypical2, deltaATypical3;
  73.  
  74.         for (Gen pgen : dna.getPredictionGenes()) {
  75.             deltaTypical1 = deltaTypical2 = deltaTypical3 = 1;
  76.             deltaATypical1 = deltaATypical2 = deltaATypical3 = 1;
  77.  
  78.             // hitung delta1
  79.             deltaTypical1 = startCodons.get(0).get(pgen.getBasaStartCodon()[0])
  80.                     * startCodons.get(1).get(pgen.getBasaStartCodon()[1])
  81.                     * startCodons.get(2).get(pgen.getBasaStartCodon()[2]);
  82.             deltaATypical1 = startCodons.get(0)
  83.                     .get(pgen.getBasaStartCodon()[0])
  84.                     * startCodons.get(1).get(pgen.getBasaStartCodon()[1])
  85.                     * startCodons.get(2).get(pgen.getBasaStartCodon()[2]);
  86.  
  87.             // delta2
  88.             deltaTypical2 *= transition.getStartTypical()
  89.                     * transition.getTypicalTypical() * deltaTypical1;
  90.             deltaATypical2 *= transition.getStartAtypical()
  91.                     * transition.getAtypicalAtypical() * deltaATypical1;
  92.             for (int i = 0; i < pgen.getBasaCodingRegion().length; i++) {
  93.                 char b = pgen.getBasaCodingRegion()[i];
  94.                 int index = 0;
  95.                 if (index % 3 == 0) {
  96.                     deltaTypical2 *= codingRegionTypicals.get(0).get(b)
  97.                             * codingRegionTypicals.get(1).get(b)
  98.                             * codingRegionTypicals.get(2).get(b) * 100;
  99.                     deltaATypical2 *= codingRegionAtypicals.get(0).get(b)
  100.                             * codingRegionAtypicals.get(1).get(b)
  101.                             * codingRegionAtypicals.get(2).get(b) * 100;
  102.                 }
  103.                 index++;
  104.             }
  105.  
  106.             deltaTypical3 *= deltaTypical2 * transition.getTypicalStop()
  107.                     * stopCodons.get(0).get(pgen.getBasaStopCodon()[0])
  108.                     * stopCodons.get(1).get(pgen.getBasaStopCodon()[1])
  109.                     * stopCodons.get(2).get(pgen.getBasaStopCodon()[2]);
  110.             deltaATypical3 *= deltaATypical2 * transition.getAtypicalStop()
  111.                     * stopCodons.get(0).get(pgen.getBasaStopCodon()[0])
  112.                     * stopCodons.get(1).get(pgen.getBasaStopCodon()[1])
  113.                     * stopCodons.get(2).get(pgen.getBasaStopCodon()[2]);
  114.         }
  115.  
  116.     }
  117.  
  118.     public void train(DNA dna) {
  119.         double alphaTypical1, alphaTypical2, alphaTypical3;
  120.         double alphaATypical1, alphaATypical2, alphaATypical3;
  121.         double betaTypical1, betaTypical2, betaTypical3;
  122.         double betaATypical1, betaATypical2, betaATypical3;
  123.         double startTypical, startAtypical, typicalStop, atypicalStop, typicalTypical, atypicalAtypical;
  124.  
  125.         for (Gen gen : dna.getGenes()) {
  126.             alphaTypical1 = alphaTypical2 = alphaTypical3 = 1;
  127.             alphaATypical1 = alphaATypical2 = alphaATypical3 = 1;
  128.             betaTypical1 = betaTypical2 = betaTypical3 = 1;
  129.             betaATypical1 = betaATypical2 = betaATypical3 = 1;
  130.  
  131.             int[][][] typicalStates = {
  132.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } },
  133.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } },
  134.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } };
  135.             int[][][] atypicalState = {
  136.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } },
  137.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } },
  138.                     { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } } };
  139.  
  140.             // hitung alpha1
  141.             alphaTypical1 = startCodons.get(0).get(gen.getBasaStartCodon()[0])
  142.                     * startCodons.get(1).get(gen.getBasaStartCodon()[1])
  143.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2]);
  144.             alphaATypical1 = alphaTypical1;
  145.             gen.getAlphaTypical1().add(0,
  146.                     startCodons.get(0).get(gen.getBasaStartCodon()[0]));
  147.             gen.getAlphaTypical1().add(
  148.                     1,
  149.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  150.                             * startCodons.get(1)
  151.                                     .get(gen.getBasaStartCodon()[1]));
  152.             gen.getAlphaTypical1().add(
  153.                     2,
  154.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  155.                             * startCodons.get(1)
  156.                                     .get(gen.getBasaStartCodon()[1])
  157.                             * startCodons.get(2)
  158.                                     .get(gen.getBasaStartCodon()[2]));
  159.  
  160.             gen.getAlphaATypical1().add(0,
  161.                     startCodons.get(0).get(gen.getBasaStartCodon()[0]));
  162.             gen.getAlphaATypical1().add(
  163.                     1,
  164.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  165.                             * startCodons.get(1)
  166.                                     .get(gen.getBasaStartCodon()[1]));
  167.             gen.getAlphaATypical1().add(
  168.                     2,
  169.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  170.                             * startCodons.get(1)
  171.                                     .get(gen.getBasaStartCodon()[1])
  172.                             * startCodons.get(2)
  173.                                     .get(gen.getBasaStartCodon()[2]));
  174.  
  175.             // end hitung alpha1
  176.  
  177.             // hitung beta3
  178.             betaTypical3 = stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  179.                     * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  180.                     * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  181.                     * transition.getTypicalStop();
  182.             // *set beta*
  183.             gen.getBetaTypical3().add(
  184.                     0,
  185.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  186.                             * transition.getTypicalStop());
  187.             gen.getBetaTypical3().add(
  188.                     1,
  189.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  190.                             * stopCodons.get(1).get(gen.getBasaStartCodon()[1])
  191.                             * transition.getTypicalStop());
  192.             gen.getBetaTypical3().add(
  193.                     2,
  194.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  195.                             * stopCodons.get(1).get(gen.getBasaStartCodon()[1])
  196.                             * stopCodons.get(2).get(gen.getBasaStartCodon()[2])
  197.                             * transition.getTypicalStop());
  198.  
  199.             betaATypical3 = stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  200.                     * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  201.                     * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  202.                     * transition.getAtypicalStop();
  203.  
  204.             gen.getBetaATypical3().add(
  205.                     0,
  206.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  207.                             * transition.getAtypicalStop());
  208.             gen.getBetaATypical3().add(
  209.                     1,
  210.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  211.                             * stopCodons.get(1).get(gen.getBasaStartCodon()[1])
  212.                             * transition.getAtypicalStop());
  213.             gen.getBetaATypical3().add(
  214.                     2,
  215.                     stopCodons.get(0).get(gen.getBasaStartCodon()[0])
  216.                             * stopCodons.get(1).get(gen.getBasaStartCodon()[1])
  217.                             * stopCodons.get(2).get(gen.getBasaStartCodon()[2])
  218.                             * transition.getAtypicalStop());
  219.  
  220.             // end hitung beta 3
  221.  
  222.             // hitung alpha 2 dan beta 2
  223.             alphaTypical2 *= transition.getStartTypical()
  224.                     * transition.getTypicalTypical() * alphaTypical1;
  225.             alphaATypical2 *= transition.getStartAtypical()
  226.                     * transition.getAtypicalAtypical() * alphaATypical1;
  227.             betaTypical2 *= transition.getTypicalTypical()
  228.                     * transition.getStartTypical() * betaTypical3;
  229.             betaATypical2 *= transition.getAtypicalAtypical()
  230.                     * transition.getStartAtypical() * betaATypical3;
  231.  
  232.             int index = 0;
  233.             int j = 0;
  234.             for (int i = 0; i < gen.getBasaCodingRegion().length; i++) {
  235.                 char basa = gen.getBasaCodingRegion()[i];
  236.                 char b_basa = gen.getBasaCodingRegion()[gen
  237.                         .getBasaCodingRegion().length
  238.                         - i - 1];
  239.                 if (index % 3 == 0) {
  240.                     if (gen.isTypical()) {
  241.                         alphaTypical2 *= codingRegionTypicals.get(0).get(basa)
  242.                                 * codingRegionTypicals.get(1).get(basa)
  243.                                 * codingRegionTypicals.get(2).get(basa) * 100;
  244.                         // set
  245.                         gen.getAlphaTypical2().add(index, alphaTypical2);
  246.  
  247.                         betaTypical2 *= codingRegionTypicals.get(0).get(b_basa)
  248.                                 * codingRegionTypicals.get(1).get(b_basa)
  249.                                 * codingRegionTypicals.get(2).get(b_basa) * 100;
  250.                         // set
  251.                         gen.getBetaTypical2().add(index, betaTypical2);
  252.                         alphaATypical2 *= codingRegionAtypicals.get(0)
  253.                                 .get(basa)
  254.                                 * codingRegionAtypicals.get(1).get(basa)
  255.                                 * codingRegionAtypicals.get(2).get(basa) * 100;
  256.                         // set
  257.                         gen.getAlphaATypical2().add(index, alphaATypical2);
  258.                         betaATypical2 *= codingRegionAtypicals.get(0).get(
  259.                                 b_basa)
  260.                                 * codingRegionAtypicals.get(1).get(b_basa)
  261.                                 * codingRegionAtypicals.get(2).get(b_basa)
  262.                                 * 100;
  263.                         // set
  264.                         gen.getBetaATypical2().add(index, betaATypical2);
  265.                         // System.out.println("urutan :" + i);
  266.                         // System.out.println("Alpha Typical 2: " +
  267.                         // alphaTypical2);
  268.                         // System.out.println("Alpha ATypical 2: "
  269.                         // + alphaATypical2);
  270.                     } else {
  271.                         alphaTypical2 *= codingRegionTypicals.get(0).get(basa)
  272.                                 * codingRegionTypicals.get(1).get(basa)
  273.                                 * codingRegionTypicals.get(2).get(basa) * 100;
  274.                         // set
  275.                         gen.getAlphaTypical2().add(index, alphaTypical2);
  276.  
  277.                         betaTypical2 *= codingRegionTypicals.get(0).get(b_basa)
  278.                                 * codingRegionTypicals.get(1).get(b_basa)
  279.                                 * codingRegionTypicals.get(2).get(b_basa) * 100;
  280.                         // set
  281.                         gen.getBetaTypical2().add(index, betaTypical2);
  282.                         alphaATypical2 *= codingRegionAtypicals.get(0)
  283.                                 .get(basa)
  284.                                 * codingRegionAtypicals.get(1).get(basa)
  285.                                 * codingRegionAtypicals.get(2).get(basa) * 100;
  286.                         // set
  287.                         gen.getAlphaATypical2().add(index, alphaATypical2);
  288.                         betaATypical2 *= codingRegionAtypicals.get(0).get(
  289.                                 b_basa)
  290.                                 * codingRegionAtypicals.get(1).get(b_basa)
  291.                                 * codingRegionAtypicals.get(2).get(b_basa)
  292.                                 * 100;
  293.                         // set
  294.                         gen.getBetaATypical2().add(index, betaATypical2);
  295.  
  296.                         if (i % 6 == 0) {
  297.                             alphaTypical2 *= 0.1;
  298.                             alphaATypical2 *= 0.1;
  299.                             betaTypical2 *= 0.1;
  300.                             betaATypical2 *= 0.1;
  301.                         }
  302.  
  303.                         // System.out.println("urutan :" + i);
  304.                         // System.out.println("Alpha Typical 2: " +
  305.                         // alphaTypical2);
  306.                         // System.out.println("Alpha ATypical 2: "+
  307.                         // alphaATypical2);
  308.                     }
  309.  
  310.                     /*
  311.                      * double typ_typ = alphaTypical2
  312.                      * codingRegionAtypicals.get(0).get(basa)
  313.                      * codingRegionAtypicals.get(0).get(b_basa) betaTypical2;
  314.                      */
  315.                 }
  316.                 switch (basa) {
  317.                 case 'a':
  318.                     typicalStates[1][index % 3][0]++;
  319.                     break;
  320.                 case 't':
  321.                     typicalStates[1][index % 3][1]++;
  322.                     break;
  323.                 case 'c':
  324.                     typicalStates[1][index % 3][2]++;
  325.                     break;
  326.                 case 'g':
  327.                     typicalStates[1][index % 3][3]++;
  328.                     break;
  329.                 }
  330.             }
  331.             // double x = Math.pow(10, 308);
  332.  
  333.             // end hitung alpha2 dan beta 2
  334.  
  335.             // hitung alpha3
  336.  
  337.             alphaTypical3 = stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  338.                     * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  339.                     * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  340.                     * transition.getTypicalStop() * alphaTypical2;
  341.             // set
  342.             gen.getAlphaTypical3().add(
  343.                     0,
  344.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  345.                             * transition.getTypicalStop() * alphaTypical2);
  346.             gen.getAlphaTypical3().add(
  347.                     1,
  348.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  349.                             * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  350.                             * transition.getTypicalStop() * alphaTypical2);
  351.             gen.getAlphaTypical3().add(
  352.                     2,
  353.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  354.                             * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  355.                             * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  356.                             * transition.getTypicalStop() * alphaTypical2);
  357.  
  358.             alphaATypical3 = stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  359.                     * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  360.                     * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  361.                     * transition.getAtypicalStop() * alphaATypical2;
  362.             // set
  363.             gen.getAlphaATypical3().add(
  364.                     0,
  365.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  366.                             * transition.getAtypicalStop() * alphaATypical2);
  367.             gen.getAlphaATypical3().add(
  368.                     1,
  369.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  370.                             * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  371.                             * transition.getAtypicalStop() * alphaATypical2);
  372.             gen.getAlphaATypical3().add(
  373.                     2,
  374.                     stopCodons.get(0).get(gen.getBasaStopCodon()[0])
  375.                             * stopCodons.get(1).get(gen.getBasaStopCodon()[1])
  376.                             * stopCodons.get(2).get(gen.getBasaStopCodon()[2])
  377.                             * transition.getAtypicalStop() * alphaATypical2);
  378.             // end hitung alpha3
  379.  
  380.             // hitung beta1
  381.             betaTypical1 = startCodons.get(0).get(gen.getBasaStartCodon()[0])
  382.                     * startCodons.get(1).get(gen.getBasaStartCodon()[1])
  383.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  384.                     * betaTypical2;
  385.             gen.getBetaTypical1().add(
  386.                     0,
  387.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  388.                             * betaTypical2);
  389.             gen.getBetaTypical1().add(
  390.                     1,
  391.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  392.                             * startCodons.get(1)
  393.                                     .get(gen.getBasaStartCodon()[1])
  394.                             * betaTypical2);
  395.             gen.getBetaTypical1().add(
  396.                     2,
  397.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  398.                             * startCodons.get(1)
  399.                                     .get(gen.getBasaStartCodon()[1])
  400.                             * startCodons.get(2)
  401.                                     .get(gen.getBasaStartCodon()[2])
  402.                             * betaTypical2);
  403.  
  404.             betaATypical1 = startCodons.get(0).get(gen.getBasaStartCodon()[0])
  405.                     * startCodons.get(1).get(gen.getBasaStartCodon()[1])
  406.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  407.                     * betaATypical2;
  408.             gen.getBetaATypical1().add(
  409.                     0,
  410.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  411.                             * betaATypical2);
  412.             gen.getBetaATypical1().add(
  413.                     1,
  414.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  415.                             * startCodons.get(1)
  416.                                     .get(gen.getBasaStartCodon()[1])
  417.                             * betaATypical2);
  418.             gen.getBetaATypical1().add(
  419.                     2,
  420.                     startCodons.get(0).get(gen.getBasaStartCodon()[0])
  421.                             * startCodons.get(1)
  422.                                     .get(gen.getBasaStartCodon()[1])
  423.                             * startCodons.get(2)
  424.                                     .get(gen.getBasaStartCodon()[2])
  425.                             * betaATypical2);
  426.             // end hitung beta1
  427.  
  428.             System.out.println("Alpha Typical 1: " + alphaTypical1);
  429.             System.out.println("Alpha Typical 2: " + alphaTypical2);
  430.             System.out.println("Alpha Typical 3: " + alphaTypical3);
  431.  
  432.             System.out.println("Alpha Atypical 1: " + alphaATypical1);
  433.             System.out.println("Alpha Atypical 2: " + alphaATypical2);
  434.             System.out.println("Alpha Atypical 3: " + alphaATypical3);
  435.  
  436.             System.out.println("Beta Typical 3: " + betaTypical3);
  437.             System.out.println("Beta Typical 2: " + betaTypical2);
  438.             System.out.println("Beta Typical 1: " + betaTypical1);
  439.  
  440.             System.out.println("Beta Atypical 3: " + betaATypical3);
  441.             System.out.println("Beta Atypical 2: " + betaATypical2);
  442.             System.out.println("Beta Atypical 1: " + betaATypical1);
  443.             System.out.println("------------------------------------------- ");
  444.  
  445.             // -------------------------------------------------------------
  446.  
  447.             // hitung transition probability
  448.             double sTyp = alphaTypical1
  449.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  450.                     * codingRegionTypicals.get(0).get(
  451.                             gen.getBasaCodingRegion()[0]) * betaTypical3
  452.                     / (alphaTypical3 + alphaATypical3);
  453.             double sATyp = alphaATypical1
  454.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  455.                     * codingRegionTypicals.get(0).get(
  456.                             gen.getBasaCodingRegion()[2]) * betaATypical3
  457.                     / (alphaTypical3 + alphaATypical3);
  458.             double typEnd = (alphaTypical2
  459.                     * codingRegionTypicals.get(2).get(
  460.                             gen.getBasaCodingRegion()[2]) / (alphaTypical3 + alphaATypical3))
  461.                     * (codingRegionTypicals.get(0).get(
  462.                             gen.getBasaCodingRegion()[0])
  463.                             * betaTypical2 / (alphaTypical3 + betaTypical1));
  464.             double atypEnd = (alphaATypical2
  465.                     * codingRegionTypicals.get(2).get(
  466.                             gen.getBasaCodingRegion()[2]) / (alphaTypical3 + alphaATypical3))
  467.                     * (codingRegionTypicals.get(0).get(
  468.                             gen.getBasaCodingRegion()[0])
  469.                             * betaATypical2 / (alphaTypical3 + alphaATypical3));
  470.  
  471.             startTypical = sTyp / (sTyp + sATyp);
  472.             startAtypical = sATyp / (sTyp + sATyp);
  473.             typicalStop = typEnd / (typEnd + atypEnd);
  474.             atypicalStop = atypEnd / (typEnd + atypEnd);
  475.             typicalTypical = (1 - typicalStop);
  476.             atypicalAtypical = (1 - atypicalStop);
  477.  
  478.             double x = typicalStop + atypicalStop;
  479.  
  480.             transition.setStartTypical(startTypical);
  481.             transition.setStartAtypical(startAtypical);
  482.             transition.setTypicalStop(atypicalStop);
  483.             transition.setAtypicalStop(atypicalStop);
  484.             transition.setTypicalTypical(typicalTypical);
  485.             transition.setAtypicalAtypical(atypicalAtypical);
  486.  
  487.             System.out.println("startTypical: " + startTypical);
  488.             System.out.println("startATypical: " + startAtypical);
  489.             System.out.println("typcalTypical" + typicalTypical);
  490.             System.out.println("atypAtyp" + atypicalAtypical);
  491.             System.out.println("typicalStop: " + typicalStop);
  492.             System.out.println("atypStop: " + atypicalStop);
  493.  
  494.             // ================================================================
  495.             // emition probability
  496.  
  497.             // sum_state += (alpha char . beta char) / fwdbwd -> yg ini u/state
  498.             double sumStateStart = gen.sumStateStart();
  499.  
  500.             double a_StartTyp1 = startCodons.get(0).get(
  501.                     gen.getBasaStartCodon()[0])
  502.                     * startCodons.get(1).get(gen.getBasaStartCodon()[1])
  503.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  504.                     * betaTypical2 / sumStateStart;
  505.             double a_StartTyp2 = startCodons.get(1).get(
  506.                     gen.getBasaStartCodon()[1])
  507.                     * startCodons.get(2).get(gen.getBasaStartCodon()[2])
  508.                     * betaTypical2 / sumStateStart;
  509.             double a_StartTyp3 = startCodons.get(2).get(
  510.                     gen.getBasaStartCodon()[2])
  511.                     * betaTypical2 / sumStateStart;
  512.  
  513.             double sumStateTyp0 = gen.sumStateTypical(0);
  514.             double sumStateTyp1 = gen.sumStateTypical(1);
  515.             double sumStateTyp2 = gen.sumStateTypical(2);
  516.             double sumStateAtyp0 = gen.sumStateATypical(0);
  517.             double sumStateAtyp1 = gen.sumStateATypical(1);
  518.             double sumStateAtyp2 = gen.sumStateATypical(2);
  519.  
  520.             // System.out.println(sumStateAtyp0);
  521.  
  522.             // sum_char += (alpha char . beta char) / fwdbwd ---> yg ini untuk
  523.             // for (int z = 1; z <= 3; z++) {
  524.             double a_Typ1 = gen.sumCharTypical(0, 'a') / sumStateTyp0;
  525.             double t_Typ1 = gen.sumCharTypical(0, 't') / sumStateTyp0;
  526.             double c_Typ1 = gen.sumCharTypical(0, 'c') / sumStateTyp0;
  527.             double g_Typ1 = gen.sumCharTypical(0, 'g') / sumStateTyp0;
  528.  
  529.             double a_Typ2 = gen.sumCharTypical(1, 'a') / sumStateTyp1;
  530.             double t_Typ2 = gen.sumCharTypical(1, 't') / sumStateTyp1;
  531.             double c_Typ2 = gen.sumCharTypical(1, 'c') / sumStateTyp1;
  532.             double g_Typ2 = gen.sumCharTypical(1, 'g') / sumStateTyp1;
  533.  
  534.             double a_Typ3 = gen.sumCharTypical(2, 'a') / sumStateTyp2;
  535.             double t_Typ3 = gen.sumCharTypical(2, 't') / sumStateTyp2;
  536.             double c_Typ3 = gen.sumCharTypical(2, 'c') / sumStateTyp2;
  537.             double g_Typ3 = gen.sumCharTypical(2, 'g') / sumStateTyp2;
  538.  
  539.             codingRegionTypicals.get(0).set(gen.getBasaCodingRegion()[0],
  540.                     a_Typ1);
  541.             codingRegionTypicals.get(0).set(gen.getBasaCodingRegion()[1],
  542.                     t_Typ1);
  543.             codingRegionTypicals.get(0).set(gen.getBasaCodingRegion()[2],
  544.                     c_Typ1);
  545.             codingRegionTypicals.get(0).set(gen.getBasaCodingRegion()[3],
  546.                     g_Typ1);
  547.             codingRegionTypicals.get(1).set(gen.getBasaCodingRegion()[0],
  548.                     a_Typ2);
  549.             codingRegionTypicals.get(1).set(gen.getBasaCodingRegion()[1],
  550.                     t_Typ2);
  551.             codingRegionTypicals.get(1).set(gen.getBasaCodingRegion()[2],
  552.                     c_Typ2);
  553.             codingRegionTypicals.get(1).set(gen.getBasaCodingRegion()[3],
  554.                     g_Typ2);
  555.             codingRegionTypicals.get(2).set(gen.getBasaCodingRegion()[0],
  556.                     a_Typ3);
  557.             codingRegionTypicals.get(2).set(gen.getBasaCodingRegion()[1],
  558.                     t_Typ3);
  559.             codingRegionTypicals.get(2).set(gen.getBasaCodingRegion()[2],
  560.                     c_Typ3);
  561.             codingRegionTypicals.get(2).set(gen.getBasaCodingRegion()[3],
  562.                     g_Typ3);
  563.  
  564.             double a_ATyp1 = gen.sumCharATypical(0, 'a') / sumStateTyp0;
  565.             double t_ATyp1 = gen.sumCharATypical(0, 't') / sumStateTyp0;
  566.             double c_ATyp1 = gen.sumCharATypical(0, 'c') / sumStateTyp0;
  567.             double g_ATyp1 = gen.sumCharATypical(0, 'g') / sumStateTyp0;
  568.  
  569.             double a_ATyp2 = gen.sumCharATypical(1, 'a') / sumStateTyp1;
  570.             double t_ATyp2 = gen.sumCharATypical(1, 't') / sumStateTyp1;
  571.             double c_ATyp2 = gen.sumCharATypical(1, 'c') / sumStateTyp1;
  572.             double g_ATyp2 = gen.sumCharATypical(1, 'g') / sumStateTyp1;
  573.  
  574.             double a_ATyp3 = gen.sumCharATypical(2, 'a') / sumStateTyp2;
  575.             double t_ATyp3 = gen.sumCharATypical(2, 't') / sumStateTyp2;
  576.             double c_ATyp3 = gen.sumCharATypical(2, 'c') / sumStateTyp2;
  577.             double g_ATyp3 = gen.sumCharATypical(2, 'g') / sumStateTyp2;
  578.  
  579.             codingRegionAtypicals.get(0).set(gen.getBasaCodingRegion()[0],
  580.                     a_ATyp1);
  581.             codingRegionAtypicals.get(0).set(gen.getBasaCodingRegion()[1],
  582.                     t_ATyp1);
  583.             codingRegionAtypicals.get(0).set(gen.getBasaCodingRegion()[2],
  584.                     c_ATyp1);
  585.             codingRegionAtypicals.get(0).set(gen.getBasaCodingRegion()[3],
  586.                     g_ATyp1);
  587.             codingRegionAtypicals.get(1).set(gen.getBasaCodingRegion()[0],
  588.                     a_ATyp2);
  589.             codingRegionAtypicals.get(1).set(gen.getBasaCodingRegion()[1],
  590.                     t_ATyp2);
  591.             codingRegionAtypicals.get(1).set(gen.getBasaCodingRegion()[2],
  592.                     c_ATyp2);
  593.             codingRegionAtypicals.get(1).set(gen.getBasaCodingRegion()[3],
  594.                     g_ATyp2);
  595.             codingRegionAtypicals.get(2).set(gen.getBasaCodingRegion()[0],
  596.                     a_ATyp3);
  597.             codingRegionAtypicals.get(2).set(gen.getBasaCodingRegion()[1],
  598.                     t_ATyp3);
  599.             codingRegionAtypicals.get(2).set(gen.getBasaCodingRegion()[2],
  600.                     c_ATyp3);
  601.             codingRegionAtypicals.get(2).set(gen.getBasaCodingRegion()[3],
  602.                     g_ATyp3);
  603.  
  604.             System.out.println("Typical State 1 --> a : " + a_Typ1 + ",t : "
  605.                     + t_Typ1 + ",c : " + c_Typ1 + ",g :" + g_Typ1);
  606.             System.out.println("Typical State 2 --> a : " + a_Typ2 + ",t : "
  607.                     + t_Typ2 + ",c : " + c_Typ2 + ",g :" + g_Typ2);
  608.             System.out.println("Typical State 3 --> a : " + a_Typ3 + ",t : "
  609.                     + t_Typ3 + ",c : " + c_Typ3 + ",g :" + g_Typ3);
  610.  
  611.             // atyp
  612.             System.out.println("Atypical State 1 --> a : " + a_ATyp1 + ",t : "
  613.                     + t_ATyp1 + ",c : " + c_ATyp1 + ",g :" + g_ATyp1);
  614.             System.out.println("Atypical State 1 --> a : " + a_ATyp2 + ",t : "
  615.                     + t_ATyp2 + ",c : " + c_ATyp2 + ",g :" + g_ATyp2);
  616.             System.out.println("Atypical State 1 --> a : " + a_ATyp3 + ",t : "
  617.                     + t_ATyp3 + ",c : " + c_ATyp3 + ",g :" + g_ATyp3);
  618.             System.out.println("========================================");
  619.             // }
  620.  
  621.             // perchar
  622.             // sum = sum_char / sum_state nilai e_prob
  623.  
  624.         }
  625.     }
  626.  
  627.     public List<State> getStartCodons() {
  628.         return startCodons;
  629.     }
  630.  
  631.     public List<State> getStopCodons() {
  632.         return stopCodons;
  633.     }
  634.  
  635.     public List<State> getCodingRegionTypicals() {
  636.         return codingRegionTypicals;
  637.     }
  638.  
  639.     public List<State> getCodingRegionAtypicals() {
  640.         return codingRegionAtypicals;
  641.     }
  642.  
  643. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement