コード例 #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
 /**
  * Gets the contents of the given resource as a string.
  *
  * @param resource name (classpath) of the resource.
  * @return a String containing the contents of the stream
  * @exception IOException if an error occurs.
  */
 public static String resourceToString(final String resource) throws IOException {
   final InputStream str = Resources.getResourceAsStream(resource);
   if (str == null) {
     throw new RuntimeException("Unable to find resource:" + resource);
   }
   final String res = FileUtils.streamToString(str);
   str.close();
   return res;
 }
コード例 #3
0
ファイル: ZeroRBuilderTest.java プロジェクト: ppflrs/rtg-core
 private void checkLoadVersion(int version) throws IOException {
   final InputStream is =
       Resources.getResourceAsStream("com/rtg/ml/resources/testZeroRVersion_" + version);
   try (final DataInputStream dis = new DataInputStream(is)) {
     final int type = dis.readInt();
     assertEquals(MlPredictLoader.MlPredictType.ZERO_R.ordinal(), type);
     final ZeroRBuilder.ZeroRClassifier bs = new ZeroRBuilder.ZeroRClassifier(dis);
     assertEquals(version, bs.mCurrentVersion);
     final StringBuilder str = bs.toString(new StringBuilder(), "", null);
     final String s = str.toString();
     assertTrue(s.contains("808/1007"));
   }
 }
コード例 #4
0
 /**
  * Convenience method for turning a resource into a file that can be used as input.
  *
  * @param resource name (classpath) of the resource.
  * @param file a <code>File</code> to write to
  * @return a <code>File</code> containing the string content (same as <code>file</code>).
  * @throws IOException if an error occurs
  */
 public static File resourceToFile(final String resource, final File file) throws IOException {
   try (InputStream stream = Resources.getResourceAsStream(resource)) {
     return FileHelper.streamToFile(stream, file);
   }
 }