Пример #1
0
  /**
   * Matrix for protein distance
   *
   * @param matrixName "<code>BLOSUM45</code>", "<code>BLOSUM62</code>", "<code>BLOSUM80</code>"
   *     etc.
   * @throws InvalidParamsException exception when invalid parameters.
   * @throws IOException exception when IO goes wrong
   */
  public ProteinScoringMatrix(String matrixName) throws InvalidParamsException, IOException {
    final String mat = matrixName.toUpperCase(Locale.getDefault());
    final int len = Protein.values().length;
    mScores = new int[len][];
    // C# restrictions
    for (int i = 0; i < len; i++) {
      mScores[i] = new int[len];
    }
    final String res = "com/rtg/mode/" + mat;
    try (InputStream in = Resources.getResourceAsStream(res)) {
      if (in == null) {
        throw new MissingResourceException(
            "Could not find:" + res, ProteinScoringMatrix.class.getName(), res);
      }
      try (BufferedReader re = new BufferedReader(new InputStreamReader(in))) {
        try {
          parse(re);
        } catch (final IOException | NumberFormatException e) {
          throw new MissingResourceException(
              "Malformed resource: " + res + " message: " + e.getMessage(),
              ProteinScoringMatrix.class.getName(),
              res);
        }
        final String resProps = "com/rtg/mode/" + mat + ".properties";
        try (final InputStream inProps = Resources.getResourceAsStream(resProps)) {
          if (inProps == null) {
            throw new MissingResourceException(
                "Could not find:" + resProps, ProteinScoringMatrix.class.getName(), resProps);
          }

          final Properties pr = new Properties();
          try {
            pr.load(inProps);
          } catch (final IOException e) {
            throw new InvalidParamsException(
                ErrorType.PROPS_LOAD_FAILED, "Matrix", resProps, e.getMessage());
          } catch (final IllegalArgumentException e) {
            throw new InvalidParamsException(ErrorType.PROPS_INVALID, "Matrix", resProps);
          }
          mK = getDouble(mat, pr, "K");
          mLogK = Math.log(mK);
          mH = getDouble(mat, pr, "H");
          mLambda = getDouble(mat, pr, "LAMBDA");
          mHit = getDouble(mat, pr, "HIT");
          mMiss = getDouble(mat, pr, "MISS");
          mGap = getDouble(mat, pr, "GAP");
          mExtend = getDouble(mat, pr, "EXTEND");
          mExpected = getDouble(mat, pr, "EXPECTED");
          mMax = findMax();
        }
      }
    }
    assert integrity();
  }
Пример #2
0
  private static Tester getTesterForFile(String filename, String[] glossar, Language language) {
    File inF = new File(url, filename);

    File outF = new File(url, "out." + filename.substring(0, filename.indexOf('.')) + ".xml");
    PrintStream output = null;
    BufferedReader input = null;
    try {
      input = new BufferedReader(new InputStreamReader(new FileInputStream(inF)));
      StringBuilder stringBuilder = new StringBuilder();
      String tmp = null;
      while ((tmp = input.readLine()) != null) {
        stringBuilder.append(tmp);
        stringBuilder.append('\n');
      }
      String whole = stringBuilder.toString();
      if (!outF.exists()) outF.createNewFile();
      output = new PrintStream(outF);
      // Do actual checking
      String[] lines = whole.split(RegEx.Newline);
      int[] tmpLevels = new int[lines.length - 1];
      String[] tmpHadings = new String[tmpLevels.length], tmpTexts = new String[tmpLevels.length];
      for (int i = 1; i < lines.length; i++) {
        String[] split = lines[i].split("\",\"");
        tmpLevels[i - 1] = Integer.parseInt(split[0].substring(1));
        tmpHadings[i - 1] = split[1];
        tmpTexts[i - 1] =
            split[2].substring(
                0, split[2].length() - 1); // Take the whole string, except of the last char
      }
      Tester tester =
          new Tester(
              output,
              tmpLevels,
              tmpHadings,
              tmpTexts,
              glossar,
              language,
              url + "rules.xml",
              url + "rules.xsd");
      return tester;
    } catch (IOException | NumberFormatException | ArrayIndexOutOfBoundsException e) {
      e.printStackTrace();
      return null;
    }
  }
  @Override
  protected Application configure() {
    faker = new Faker();

    final Configuration configuration;
    try {
      configuration = new Configuration(CONFIG);
    } catch (IOException | NumberFormatException e) {
      System.out.println("Properties error:");
      System.out.println(e.getMessage());
      System.exit(1);
      return null;
    }

    final AccountServiceImpl accountService;
    try {
      accountService =
          new AccountServiceImpl(
              configuration.getDbName(),
              configuration.getDbHost(),
              configuration.getDbPort(),
              configuration.getDbUsername(),
              configuration.getDbPassword());
    } catch (SQLException | IOException e) {
      e.printStackTrace();
      System.exit(1);
      return null;
    }

    final ResourceConfig config = new ResourceConfig(Session.class, Users.class);
    config.register(new AccountServiceAbstractBinder(accountService));
    final HttpServletRequest httpServletRequest = mock(HttpServletRequest.class);
    final HttpSession httpSession = mock(HttpSession.class);
    final String sessionId = faker.lorem().fixedString(15);
    Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession);
    Mockito.when(httpSession.getId()).thenReturn(sessionId);

    config.register(new ServletAbstractBinder(httpServletRequest));
    return config;
  }