예제 #1
0
 public <BLOCK extends Block> BLOCK newBlock(
     String name, Class<BLOCK> cls, Class itemClass, String title) {
   try {
     int id = config.getBlock(name, 4095).getInt();
     Constructor<BLOCK> ctor = cls.getConstructor(int.class);
     BLOCK block = ctor.newInstance(id);
     String qualName = assetKey + ":" + name;
     block.setUnlocalizedName(qualName);
     // block.func_111022_d(qualName.toLowerCase()); // Set default icon name
     // block.func_111022_d(qualName); // Set default icon name
     block.setTextureName(qualName); // Set default icon name
     GameRegistry.registerBlock(block, itemClass);
     if (title != null) {
       LanguageRegistry.addName(block, title);
       if (clientSide) {
         // System.out.printf("%s: BaseMod.newBlock: %s: creative tab = %s\n",
         //	this, block.getUnlocalizedName(), block.getCreativeTabToDisplayOn());
         if (block.getCreativeTabToDisplayOn() == null && !title.startsWith("["))
           block.setCreativeTab(CreativeTabs.tabMisc);
       }
     }
     if (block instanceof IBlock) registeredBlocks.add((IBlock) block);
     return block;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
예제 #2
0
 @Override
 public void execute(Robot robot) {
   while (true) {
     condition.evaluate(robot);
     if (condition.getValue().equals("1")) { // true
       block.execute(robot);
     } else {
       return;
     }
   }
 }
예제 #3
0
 @Override
 public boolean parse(Scanner s) {
   Parser.require(Parser.WHILEPAT, LOG + "Expecting " + Parser.WHILEPAT.toString(), s);
   Parser.require(Parser.OPENPAREN, LOG + "Expecting (", s);
   condition = new COND(getRoot());
   if (!condition.parse(s)) {
     return false;
   }
   Parser.require(Parser.CLOSEPAREN, LOG + "Expecting )", s);
   Parser.require(Parser.OPENBRACE, LOG + "Expecting {", s);
   block = new BLOCK(getRoot());
   if (!block.parse(s)) {
     return false;
   }
   Parser.require(Parser.CLOSEBRACE, LOG + "Expecting }", s);
   return true;
 }
예제 #4
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*/
예제 #5
0
 @Override
 public String toString() {
   return "while(" + condition.toString() + ") " + block.toString();
 }