Exemple #1
0
  public ArrayList<String> getPosteriorDecodingPath(
      SingleDPMatrix fMatrix, SingleDPMatrix bMatrix) {
    ArrayList<String> pdPath = new ArrayList<String>();
    State states[] = fMatrix.states();
    double fScore = fMatrix.getScore();
    double fMatrixScores[][] = fMatrix.scores;
    double bMatrixScores[][] = bMatrix.scores;

    int numberOfObservations = fMatrixScores.length;
    int numberOfStates = states.length;
    for (int i = 1; i < numberOfObservations - 1; i++) {
      ArrayList<Double> probOfStates = new ArrayList<Double>();
      for (int s = 0; s < numberOfStates; s++) {
        double probOfOneState = Math.exp(fMatrixScores[i][s] + bMatrixScores[i][s] - fScore);
        probOfStates.add(probOfOneState);
      }
      Object max_obj = Collections.max(probOfStates);
      int maxValueIndex = probOfStates.indexOf(max_obj);
      State topScoredState = states[maxValueIndex];
      pdPath.add(topScoredState.getName());
      // System.out.print(topScoredState.getName());
    }
    // System.out.println();
    // System.out.println("\n number of rows is " + numberOfObservations);
    // System.out.println("\n length of posterior decoding path is " + pdPath.size());
    return pdPath;
  } /*getPosteriorDecodingPath*/
Exemple #2
0
  public ArrayList<Double> getPosteriorDecodingScores(
      SingleDPMatrix fMatrix, SingleDPMatrix bMatrix) {
    ArrayList<Double> pdScores = new ArrayList<Double>();
    State states[] = fMatrix.states();
    double fScore = fMatrix.getScore();
    double fMatrixScores[][] = fMatrix.scores;
    double bMatrixScores[][] = bMatrix.scores;

    int numberOfObservations = fMatrixScores.length;
    int numberOfStates = states.length;

    for (int i = 1; i < numberOfObservations - 1; i++) {
      double sum = 0;
      double g = Double.MIN_VALUE;
      for (int s = 0; s < numberOfStates; s++) {
        g = getWeight(states[s].getName());
        /*
        				if( states[s].getName().equals("M")){
        					g=0;
        				}
        				else
        				{
        					g=1;
        				}

        */
        double probOfOneState = Math.exp(fMatrixScores[i][s] + bMatrixScores[i][s] - fScore);
        sum = sum + (probOfOneState * g);
      }
      pdScores.add(sum);
    }
    return pdScores;
  } /*getPosteriorDecodingScores*/
Exemple #3
0
  public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub

    // TODO Auto-generated method stub

    VITERBI3 app = new VITERBI3();

    String serDirName = app.getSerDir();
    String aliDirName = app.getAliDir();
    String[] stateNames = app.getStates();
    double[] strProb = app.getStartProbabilities();
    double[][] tranProb = app.getTransitionProbability();
    app.checkTransitionMatrixNormality(tranProb);

    double scoreThr = app.getScoreThreshold();
    int minLenForTrhoughs = app.getMinLengthThreshold();
    int minLenForPeakDis = app.getMinPeakLengths();
    int lengthThresholdForBlocks = app.getBlockLengthThreshold();

    double backGroundAlpha[] = {
      0.7, 0.8, 1
    }; // {0.15106438458196936,0.20973711740901407,0.22900628496706044}  {0.8, 0.9, 1}
    double greenStateAlpha[] = {
      0.9, 2.3, 1
    }; // {0.1713002602078479,11.729438447100865,1.3763120488468623}; {0.9,2.3,1}
    double greenFollowingMixedAlpha[] = {
      0.8, 2.3, 0.9
    }; // {0.16327302239493097,9.219505194760753,1.8283941303615243} {0.8,2.3,0.9}
    double greenToRedEdgeAlpah[] = {
      1.3, 1.4, 1.2
    }; // {0.4799631840073914,0.4944929532552769,0.2857067163030646}; {1.3,1.4,1.2}
    double redStateAlpha[] = {
      2.5, 1, 0.8
    }; // {71.25302335371902,0.201959003605188,0.20299272598532336} {5,1.1,0.9}
    double redToGreenEdgeAlpha[] = {
      5, 1.1, 0.9
    }; // {0.39728078185044136,0.3710506533397517,0.2490053255191496}{1.4,1.3,1.2}
    // double redFollowingMixedAlpha  []  = {10,0.1,0.1};
    // //{4.5200496933818615,0.1772646945273629,0.17979061871698085};
    double junctionStateAlpha[] = {0.7, 0.8, 1};

    LinkedHashMap<String, double[]> statesAndDirPar = new LinkedHashMap<String, double[]>();
    // statesAndDirPar.put("P", x);

    statesAndDirPar.put("M", backGroundAlpha);
    statesAndDirPar.put("r", redStateAlpha);
    statesAndDirPar.put("E", redToGreenEdgeAlpha);
    statesAndDirPar.put("G", greenStateAlpha);
    statesAndDirPar.put("g", greenFollowingMixedAlpha);
    statesAndDirPar.put("e", greenToRedEdgeAlpah);
    statesAndDirPar.put("R", redStateAlpha);
    statesAndDirPar.put("J", junctionStateAlpha);

    File serDir = new File(serDirName);
    for (File aSerFile : serDir.listFiles()) {
      String oneFileName = aSerFile.getName();
      if (oneFileName.startsWith(".")) {
        continue;
      }
      BLOCK block = new BLOCK(aSerFile, aliDirName);
      String blockId = block.blockId;
      int blockLength = app.getBlockLength(blockId);
      if (blockLength < lengthThresholdForBlocks) {
        // System.out.println(" found sequence :" + blockId + " with too short length :" +
        // blockLength);
        continue;
      }
      Matrix2D m = block.blockMatrix;
      Sequence seq = block.blockSeq;
      ArrayList<Integer> rowsWithSumZero = block.missingData;
      SimpleAlphabet observedSeqAlphabet = block.blockObservedSeqAlphabet;
      SimpleSymbolList symbolList = block.blockSimpleSymbolList;

      // System.out.println("seq " + blockId + " is processed");

      MarkovModel mm =
          BLOCK.makeMarkovModel(
              observedSeqAlphabet, tranProb, strProb, statesAndDirPar, "dirichletMM");
      DP dp = new SingleDP(mm);

      SymbolList[] symList = {symbolList};

      StatePath viterbiPath = dp.viterbi(symList, ScoreType.PROBABILITY);
      SymbolList symbolsInViterbi = viterbiPath.symbolListForLabel(StatePath.STATES);
      ArrayList<String> viterbiPathAsAnArrayList = app.symbolListToArrayList(symbolsInViterbi);
      System.out.println("veterbi path length for " + blockId + " is " + viterbiPath.length());

      ArrayList<String> ViterbiPath = new ArrayList<String>();

      for (int i = 1; i <= symbolsInViterbi.length(); i++) {
        Symbol oneSym = symbolsInViterbi.symbolAt(i);
        ViterbiPath.add(oneSym.getName());
        // System.out.print(oneSym.getName());
      }

      System.out.println();
      boolean isFiltering = app.getFilterMeaningLessPicks();
      app.filterMeaningLessPicks(ViterbiPath, isFiltering);

      ArrayList<Double> viterbiTranslatedToNumbersAndMappedToAlingment =
          app.mapViterbiPathToAlignment(ViterbiPath, seq, rowsWithSumZero);
      String outputFileName =
          "/Users/hk3/Desktop/Main/Composure_Droshophila_Model/ANALYSIS_EISENLAB/2L/ViterbiPaths/VITERBI2_"
              + blockId
              + ".txt";
      app.printoutViterbiPath(viterbiTranslatedToNumbersAndMappedToAlingment, outputFileName);

      SingleDPMatrix forwardMatrix =
          (SingleDPMatrix) dp.forwardMatrix(new SymbolList[] {symbolList}, ScoreType.PROBABILITY);

      double score = forwardMatrix.getScore();
      // System.err.printf("Forward: %g%n", score);
      System.out.println();
      SingleDPMatrix backwardMatrix =
          (SingleDPMatrix) dp.backwardMatrix(new SymbolList[] {symbolList}, ScoreType.PROBABILITY);

      ArrayList<Double> posteriorScores =
          app.getPosteriorDecodingScores(forwardMatrix, backwardMatrix);
      // posteriorScores = app.fillInShortTroughs(posteriorScores, scoreThr, minLenForTrhoughs);
      // posteriorScores = app.filterOutShortPeaks(posteriorScores, scoreThr, minLenForPeakDis);
      // posteriorScores = app.getEnhancerRegions(posteriorScores, scoreThr);
      ArrayList<Double> PDScoresMapedToalignment =
          app.mapPDScoresToAlignment(posteriorScores, seq, rowsWithSumZero);
      String posteriorOutputFileName =
          "/Users/hk3/Desktop/Main/Composure_Droshophila_Model/ANALYSIS_EISENLAB/2L/ViterbiPaths/Posterior_"
              + blockId
              + ".txt";
      app.printoutViterbiPath(PDScoresMapedToalignment, posteriorOutputFileName);

      // writte chains into gff files
      String chainDir = app.getChainDir();
      app.wirteChainsIntoAGffFile(PDScoresMapedToalignment, blockId, chainDir, scoreThr);
    }
  } /*main*/