示例#1
0
  /** Try and convert an object to a List. */
  private List<?> toList(Object o) {
    Class<?> c = o.getClass();
    if (!c.isArray()) {
      return null;
    }

    if (c.getComponentType().isPrimitive()) {
      if (o instanceof boolean[]) {
        return Arrays.asList(ArrayUtils.toObject((boolean[]) o));
      } else if (o instanceof byte[]) {
        return Arrays.asList(ArrayUtils.toObject((byte[]) o));
      } else if (o instanceof short[]) {
        return Arrays.asList(ArrayUtils.toObject((short[]) o));
      } else if (o instanceof int[]) {
        return Arrays.asList(ArrayUtils.toObject((int[]) o));
      } else if (o instanceof long[]) {
        return Arrays.asList(ArrayUtils.toObject((long[]) o));
      } else if (o instanceof float[]) {
        return Arrays.asList(ArrayUtils.toObject((float[]) o));
      } else if (o instanceof double[]) {
        return Arrays.asList(ArrayUtils.toObject((double[]) o));
      } else if (o instanceof char[]) {
        return Arrays.asList(ArrayUtils.toObject((char[]) o));
      } else {
        throw new RuntimeException("Unhandled primitive type");
      }
    } else {
      return Arrays.asList((Object[]) o);
    }
  }
示例#2
0
 public void deleteFile(
     String user, String password, String file, String recursive, int... status) {
   getMock("WEBHDFS")
       .expect()
       .method("DELETE")
       .pathInfo("/v1" + file)
       .queryParam("user.name", user)
       .queryParam("op", "DELETE")
       .queryParam("recursive", recursive)
       .respond()
       .status(status[0]);
   given()
       // .log().all()
       .auth()
       .preemptive()
       .basic(user, password)
       .header("X-XSRF-Header", "jksdhfkhdsf")
       .queryParam("op", "DELETE")
       .queryParam("recursive", recursive)
       .expect()
       // .log().all()
       .statusCode(isIn(ArrayUtils.toObject(status)))
       .when()
       .delete(getUrl("WEBHDFS") + "/v1" + file + (isUseGateway() ? "" : "?user.name=" + user));
   assertComplete();
 }
 @Test
 public void testPrimitiveArray() {
   final int[] beast = {6, 6, 6};
   assertEquals(
       Arrays.asList(ArrayUtils.toObject(beast)),
       therianContext.eval(
           Convert.to(new TypeLiteral<List<Integer>>() {}, Positions.readOnly(beast))));
 }
 /** {@inheritDoc} */
 @Override
 public Integer[] getFromFile() {
   if (getPropertiesFile().containsKey(getKey())) {
     return ArrayUtils.toObject(getPropertiesFile().getIntArray(getKey(), getSpacer()));
   } else {
     return new Integer[0];
   }
 }
  @Override
  public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
    if (getActivity() == null) {
      return null;
    }
    String selection =
        KEY_PARENTID
            + " is null AND "
            + KEY_ROWID
            + " NOT IN ("
            + Joiner.on(',').join(ArrayUtils.toObject(getArguments().getLongArray(KEY_EXCLUDED_ID)))
            + ")";

    CursorLoader cursorLoader =
        new CursorLoader(
            getActivity(), TransactionProvider.CATEGORIES_URI, projection, selection, null, null);
    return cursorLoader;
  }
示例#6
0
 public String submitPig(
     String user,
     String password,
     String group,
     String file,
     String arg,
     String statusDir,
     int... status) {
   getMock("WEBHCAT")
       .expect()
       .method("POST")
       .pathInfo("/v1/pig")
       .respond()
       .status(status[0])
       .contentType("application/json")
       .content("{\"id\":\"job_201210301335_0086\"}".getBytes());
   String json =
       given()
           // .log().all()
           .auth()
           .preemptive()
           .basic(user, password)
           .header("X-XSRF-Header", "jksdhfkhdsf")
           // BUG: The identity asserter needs to check for this too.
           .formParam("user.name", user)
           .formParam("group", group)
           .formParam("file", file)
           .formParam("arg", arg)
           .formParam("statusdir", statusDir)
           .expect()
           // .log().all();
           .statusCode(isIn(ArrayUtils.toObject(status)))
           .contentType("application/json")
           // .content( "boolean", equalTo( true ) )
           .when()
           .post(getUrl("WEBHCAT") + "/v1/pig" + (isUseGateway() ? "" : "?user.name=" + user))
           .asString();
   log.trace("JSON=" + json);
   String job = from(json).getString("id");
   log.debug("JOB=" + job);
   assertComplete();
   return job;
 }
 @Override
 public DocScoreList mostSimilar(String phrase, int maxResults, TIntSet validIds)
     throws IOException {
   final TIntDoubleHashMap scores = getConceptVector(phrase, validIds);
   Integer luceneIds[] = ArrayUtils.toObject(scores.keys());
   Arrays.sort(
       luceneIds,
       new Comparator<Integer>() {
         @Override
         public int compare(Integer id1, Integer id2) {
           return -1 * new Double(scores.get(id1)).compareTo(scores.get(id2));
         }
       });
   DocScoreList result = new DocScoreList(Math.min(luceneIds.length, maxResults));
   for (int i = 0; i < result.numDocs(); i++) {
     result.set(i, esaHelper.luceneIdToWpId(luceneIds[i]), scores.get(luceneIds[i]));
   }
   return normalize(result);
 }
  @Test
  public void testPerReadAlleleLikelihoodMap() {
    final PerReadAlleleLikelihoodMap map = new PerReadAlleleLikelihoodMap();

    final Allele alleleA = Allele.create("A");
    final double lik = -1.0; // ignored

    final int[] MQs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, QualityUtils.MAPPING_QUALITY_UNAVAILABLE};
    final List<Integer> MQsList = Arrays.asList(ArrayUtils.toObject(MQs));

    // MQ 255 are excluded from the calculations, we test it here.
    final List<Integer> MQsListOK = new ArrayList<>(MQsList);
    // NOTE: if we just call remove(i), Java thinks i is an index.
    // A workaround for this overloading bogosity to to call removeAll and pass a collection
    // (casting i to (Object) would work too but it's more error prone)
    MQsListOK.removeAll(Collections.singleton(QualityUtils.MAPPING_QUALITY_UNAVAILABLE));

    final int n1A = MQs.length;
    for (int i = 0; i < n1A; i++) {
      final GATKRead read = ArtificialReadUtils.createArtificialRead(TextCigarCodec.decode("10M"));
      read.setMappingQuality(MQs[i]);
      map.add(read, alleleA, lik);
    }

    final Map<String, PerReadAlleleLikelihoodMap> perReadAlleleLikelihoodMap =
        Collections.singletonMap("sample1", map);
    final VariantContext vc = makeVC();
    final ReferenceContext referenceContext = null;
    final Map<String, Object> annotate =
        new RMSMappingQuality().annotate(referenceContext, vc, perReadAlleleLikelihoodMap);
    Assert.assertEquals(annotate.size(), 1, "size");
    Assert.assertEquals(
        annotate.keySet(), Collections.singleton(VCFConstants.RMS_MAPPING_QUALITY_KEY), "annots");
    final double rms = MathUtils.rms(MQsListOK); // only those are MQ0
    Assert.assertEquals(
        annotate.get(VCFConstants.RMS_MAPPING_QUALITY_KEY), String.format("%.2f", rms));
  }