Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:pt.webdetails.cda.dataaccess.XPathDataAccess.java

private static boolean legacyFallbackInvoke(Object object, String methodName, Class<?>[] argTypes,
        Object[] args, Class<?>[] argTypesFallback, Object[] argsFallback) {
    Method method = null;/*from w ww  .  j av a  2  s .  co  m*/
    try {
        try {
            method = object.getClass().getMethod(methodName, argTypes);
        } catch (NoSuchMethodException e1) {
            logger.debug(String.format("failed to find %s(%s): ", methodName, ArrayUtils.toString(argTypes),
                    e1.getLocalizedMessage()));
            try {
                method = object.getClass().getMethod(methodName, argTypesFallback);
                args = argsFallback;
            } catch (NoSuchMethodException e2) {
                logger.error(String.format("failed to find %1$s(%2$s) or %1$s(%3$s) ", methodName,
                        ArrayUtils.toString(argTypes), ArrayUtils.toString(argTypesFallback)));
                throw e2;
            }
        }
        method.invoke(object, args);
        return true;
    } catch (Exception e) {
        logger.error(String.format("%s call failed ", methodName), e);
    }
    return false;
}

From source file:tudresden.ocl20.pivot.essentialocl.expressions.factory.EssentialOclFactory.java

/**
 * <p>/*from w w w .  j a  v a2 s  .c o m*/
 * Creates a new {@link ExpressionInOcl}. The body expression and the context
 * variable must not be <code>null</code>. The result and parameter variables
 * are optional since they are only required for constraints whose context is
 * an operation.
 * </p>
 * 
 * @param body
 *          The body expression as a {@link String} in OCL concrete syntax.
 * @param bodyExpression
 *          The {@link OclExpression} that is the body of the
 *          {@link ExpressionInOcl}.
 * @param context
 *          The {@link Variable} representing the contextual classifier.
 * @param result
 *          The result {@link Variable} of an operation {@link Constraint} .
 * @param parameter
 *          The parameters of an operation {@link Constraint}.
 * 
 * @return An {@link ExpressionInOcl} instance.
 */
public ExpressionInOcl createExpressionInOcl(String body, OclExpression bodyExpression, Variable context,
        Variable result, Variable... parameter) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("createExpressionInOcl(bodyExpression=" + bodyExpression //$NON-NLS-1$
                + ", context=" + context + ", result=" + result + ", parameter=" //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
                + ArrayUtils.toString(parameter) + ") - enter"); //$NON-NLS-1$
    }

    if (bodyExpression == null || context == null) {
        throw new NullArgumentException("bodyExpression or context"); //$NON-NLS-1$
    }

    ExpressionInOcl expressionInOcl;

    expressionInOcl = ExpressionsFactory.INSTANCE.createExpressionInOcl();
    expressionInOcl.setBodyExpression(bodyExpression);
    expressionInOcl.setContext(context);

    if (StringUtils.isNotEmpty(body)) {
        expressionInOcl.setBody(body);
    }

    if (result != null) {
        expressionInOcl.setResult(result);
    }

    if (parameter != null) {
        expressionInOcl.getParameter().addAll(Arrays.asList(parameter));
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("createExpressionInOcl() - exit - return value=" //$NON-NLS-1$
                + expressionInOcl);
    }

    return expressionInOcl;
}

From source file:ubic.gemma.analysis.expression.coexpression.links.AbstractMatrixRowPairAnalysis.java

/**
 * populate geneToProbeMap and gather stats. Probes that do not map to any genes are still counted.
 *///from w  ww .j  a va2 s  .  co  m
private void initGeneToProbeMap() {
    int[] stats = new int[20]; // how many genes per probe
    this.numUniqueGenes = 0;
    this.flatProbe2GeneMap = new HashMap<CompositeSequence, Collection<Gene>>();
    this.geneToProbeMap = new HashMap<Gene, Collection<CompositeSequence>>();
    for (CompositeSequence cs : probeToGeneMap.keySet()) {

        if (!this.flatProbe2GeneMap.containsKey(cs)) {
            this.flatProbe2GeneMap.put(cs, new HashSet<Gene>());
        }

        Collection<Collection<Gene>> genes = probeToGeneMap.get(cs);

        /*
         * Genes will be empty if the probe does not map to any genes.
         */
        if (genes == null)
            continue; // defensive.

        for (Collection<Gene> cluster : genes) {
            if (cluster.isEmpty())
                continue;
            numUniqueGenes++;
            for (Gene g : cluster) {
                if (!geneToProbeMap.containsKey(g)) {
                    geneToProbeMap.put(g, new HashSet<CompositeSequence>());
                }
                this.geneToProbeMap.get(g).add(cs);
                this.flatProbe2GeneMap.get(cs).add(g);
            }

            if (cluster.size() >= stats.length) {
                stats[stats.length - 1]++;
            } else {
                stats[cluster.size()]++;
            }
        }
    }

    if (numUniqueGenes == 0) {
        log.warn("There are no genes for this data set, " + this.flatProbe2GeneMap.size() + " probes.");
    }

    log.info("Mapping Stats: " + numUniqueGenes + " unique genes; genes per probe distribution summary: "
            + ArrayUtils.toString(stats));
}

From source file:uk.ac.diamond.scisoft.analysis.io.numpy.NumPyTest.java

public NumPyTest(int index, String numpyDataType, int abstractDatasetDataType, int[] shape, boolean addInf,
        boolean unsigned) {
    this.index = index;
    this.numpyDataType = numpyDataType;
    this.abstractDatasetDataType = abstractDatasetDataType;
    this.shape = shape;
    this.addInf = addInf;
    this.unsigned = unsigned;
    this.len = 1;
    for (int i = 0; i < shape.length; i++) {
        this.len *= shape[i];
    }/*from  www  .  j av  a 2 s . co m*/
    this.shapeStr = ArrayUtils.toString(shape);
    this.shapeStr = this.shapeStr.substring(1, shapeStr.length() - 1);
    // System.out.println(this.toString());
}

From source file:uk.ac.diamond.scisoft.analysis.io.numpy.NumPyTest.java

@Override
public String toString() {
    return String.format("TEST %d: numpyType=%s datasetType=%d len=%d shape=%s", index, numpyDataType,
            abstractDatasetDataType, len, ArrayUtils.toString(shape));
}

From source file:uk.ac.diamond.scisoft.ncd.core.data.plots.GuinierPlotData.java

public Object[] getGuinierPlotParameters(IDataset data, IDataset axis) {
    Dataset guinierData = getSaxsPlotDataset(data, axis);
    Dataset guinierAxis = getSaxsPlotAxis(axis);
    /*      int sliceSize = data.getSize() / 10;
          int[] step = new int[] {sliceSize};
          IndexIterator dataSliceIter = guinierData.getSliceIterator(null, null, null);
          IndexIterator axisSliceIter = guinierAxis.getSliceIterator(null, null, null);
          // Iterate over data slices//w w  w.j a  v a2  s  .  c  o m
          int[] minPosition = new int[] {-1};
          double minError = Double.MAX_VALUE;
          double slope = Double.NaN;
          double intercept = Double.NaN;
          Map<DoublePoint, Double> clusterInputMap = new HashMap<DoublePoint, Double>();
          while (dataSliceIter.hasNext() && axisSliceIter.hasNext()) {
             SimpleRegression regression = new SimpleRegression();
             int[] pos = dataSliceIter.getPos();
             // Iterate over data values for linear regression
             IndexIterator dataIter = new SliceIterator(
       guinierData.getShape(),
       guinierData.getSize(),
       pos, step);
             pos = axisSliceIter.getPos();
             IndexIterator axisIter = new SliceIterator(
       guinierAxis.getShape(),
       guinierAxis.getSize(),
       pos, step);
             int points = 0;
             while (dataIter.hasNext() && axisIter.hasNext()) {
    double dataVal = guinierData.getDouble(dataIter.getPos());
    double axisVal = guinierAxis.getDouble(axisIter.getPos());
    regression.addData(axisVal, dataVal);
    points++;
             }
             if (points == sliceSize) {
    regression.regress();
    double err = regression.getMeanSquareError();
    if (err < minError) {
       minError = err;
       minPosition = Arrays.copyOf(pos, pos.length);
       slope = regression.getSlope();
       intercept = regression.getIntercept();
       double I0 = Math.exp(intercept);
       double Rg = Math.sqrt(-3.0*slope);
       System.out.println("    Min Pos : " + Arrays.toString(minPosition));
       System.out.println("   Min Error : " + Double.toString(minError));
       System.out.println("   Slope : " + Double.toString(slope) + "   Intercept : " + Double.toString(intercept));
       System.out.println("   I(0) : " + Double.toString(I0) + "   Rg : " + Double.toString(Rg));
       clusterInputMap.put(new DoublePoint(minPosition), minError);
    }
             } else {
    break;
             }
          }
                  
          DBSCANClusterer<DoublePoint> clusterer = new DBSCANClusterer<DoublePoint>(5, 5);
          List<Cluster<DoublePoint>> clusterResults = clusterer.cluster(clusterInputMap.keySet());
            
          // output the clusters
          for (int i = 0; i < clusterResults.size(); i++) {
              System.out.println("Cluster " + i);
             double[] minPoint = null;
             double minVal = Double.MAX_VALUE;
              for (DoublePoint point : clusterResults.get(i).getPoints()) {
      System.out.println(Arrays.toString(point.getPoint()));
      Double val = clusterInputMap.get(point);
      if (val < minVal) {
         minVal = val;
         minPoint = Arrays.copyOf(point.getPoint(), point.getPoint().length);
      }
      minVal = (val < minVal ? val : minVal);
              }
               System.out.println("Min cluster point : " + Arrays.toString(minPoint));
               System.out.println("Min cluster value : " + Double.toString(minVal));
              System.out.println();
          }
                  
    */ ConvergenceChecker<PointValuePair> cmaesChecker = new SimplePointChecker<PointValuePair>(1e-6, 1e-8);
    RandomDataGenerator rnd = new RandomDataGenerator();
    CMAESOptimizer optimizer = new CMAESOptimizer(cmaesMaxIterations, 0.0, true, 0, cmaesCheckFeasableCount,
            rnd.getRandomGenerator(), false, cmaesChecker);
    GuinierLineFitFunction function = new GuinierLineFitFunction(guinierData, guinierAxis);

    Amount<Dimensionless> I0 = Amount.valueOf(Double.NaN, Double.NaN, Dimensionless.UNIT);
    Amount<Dimensionless> Rg = Amount.valueOf(Double.NaN, Double.NaN, Dimensionless.UNIT);
    double[] qvals = new double[] { Double.NaN, Double.NaN };

    double q0 = guinierAxis.getDouble(0);
    double qMin = guinierAxis.getDouble(1);
    double qMax = guinierAxis.getDouble(guinierAxis.getSize() - 1);
    double[] startPosition = new double[] { guinierAxis.getDouble(0),
            guinierAxis.getDouble(GuinierLineFitFunction.MIN_POINTS) };
    double[] cmaesInputSigma = new double[] { (qMin - q0) * 0.1, qMax * 0.1 };
    try {
        final PointValuePair res = optimizer.optimize(new MaxEval(cmaesMaxIterations),
                new ObjectiveFunction(function), GoalType.MAXIMIZE,
                new CMAESOptimizer.PopulationSize(cmaesLambda), new CMAESOptimizer.Sigma(cmaesInputSigma),
                new SimpleBounds(new double[] { q0, q0 }, new double[] { qMin, qMax }),
                new InitialGuess(startPosition));

        qvals = res.getPoint();
        function.value(qvals);
        I0 = getI0(function.regression);
        Rg = getRg(function.regression);

        System.out.println("Final Result");
        String msg = StringUtils.join(new String[] { "   I(0) ", I0.toString(), "   Rg ", Rg.toString() },
                " : ");
        System.out.println(msg);
        msg = StringUtils.join(new String[] { "Slice", ArrayUtils.toString(res.getPoint()), "R",
                Double.toString(function.regression.getR()) }, " : ");
        System.out.println(msg);

        /*         // Run Monte-Carlo simulation to generate error estimates Rg values 
                 //double finalR = function.regression.getR();
                 int maxSample = 10000;
                 int minSample = 10;
                 int totalSample = 100000;
                 int counter = 0;
                 int totalCounter = 0;
                 GuinierLineFitFunction mcFunction = new GuinierLineFitFunction(guinierData, guinierAxis);
                 DescriptiveStatistics statsR = new DescriptiveStatistics();
                 List<Pair<Double, Amount<Dimensionless>>> listI0 = new ArrayList<Pair<Double,Amount<Dimensionless>>>();
                 List<Pair<Double, Amount<Dimensionless>>> listRg = new ArrayList<Pair<Double,Amount<Dimensionless>>>();
                 while ((counter < maxSample && totalCounter < totalSample)
                       || (counter < minSample && totalCounter >= totalSample)) {
                    double q1 = rnd.nextUniform(q0, qMin);
                    double q2 = rnd.nextUniform(q0, qMax);
                    if (!(q2 > q1)) {
                       continue;
                    }
                    totalCounter++;
                     mcFunction.value(new double[] {q1, q2});
                     double tmpR = Math.abs(mcFunction.regression.getR());
                     //boolean equalsR = Precision.equalsWithRelativeTolerance(tmpR, finalR, 0.1); 
                     if (!(Double.isNaN(tmpR) || Double.isInfinite(tmpR))) {
        statsR.addValue(tmpR);
        Amount<Dimensionless> tmpI0 = getI0(mcFunction.regression);
        Amount<Dimensionless> tmpRg = getRg(mcFunction.regression);
         if (Double.isNaN(tmpI0.getEstimatedValue()) || Double.isInfinite(tmpI0.getEstimatedValue()) ||
               Double.isNaN(tmpRg.getEstimatedValue()) || Double.isInfinite(tmpRg.getEstimatedValue())) {
            continue;
         }
        listI0.add(new Pair<Double, Amount<Dimensionless>>(tmpR, tmpI0));
        listRg.add(new Pair<Double, Amount<Dimensionless>>(tmpR, tmpRg));
        counter++;
                     }
                 }
                         
                 double threshold = statsR.getPercentile(90);
                 //double threshold = 0.95*statsR.getMax();
                 SummaryStatistics statsI0 = new SummaryStatistics();
                 SummaryStatistics statsRg = new SummaryStatistics();
                 for (Pair<Double, Amount<Dimensionless>> tmpVal : listRg) {
                    if (tmpVal.getFirst() > threshold) {
        statsRg.addValue(tmpVal.getSecond().getEstimatedValue());
                    }
                 }
                 for (Pair<Double, Amount<Dimensionless>> tmpVal : listI0) {
                    if (tmpVal.getFirst() > threshold) {
        statsI0.addValue(tmpVal.getSecond().getEstimatedValue());
                    }
                 }
                         
                 double meanI0 = statsI0.getMean();
                 double stdI0 = statsI0.getStandardDeviation();
                 I0 = Amount.valueOf(meanI0, stdI0, Dimensionless.UNIT);
                         
                 double meanRg = statsRg.getMean();
                 double stdRg = statsRg.getStandardDeviation();
                 Rg = Amount.valueOf(meanRg, stdRg, Dimensionless.UNIT);
                         
                 String msg = StringUtils.join(new String[] {
                       "Monte-Carlo Rg", Rg.toString()
                       },
                       " : ");
                 System.out.println(msg);
        */
    } catch (MaxCountExceededException e) {
        System.out.println("Maximum counts exceeded");
        return null;
    }
    return new Object[] { I0, Rg, qvals[0], qvals[1] };
}

From source file:uk.ac.diamond.scisoft.ncd.core.data.plots.PorodPlotData.java

public SimpleRegression getPorodPlotParameters(IDataset data, IDataset axis) {
    Dataset porodData = getSaxsPlotDataset(data, axis);
    Dataset porodAxis = getSaxsPlotAxis(axis);
    CMAESOptimizer optimizer = new CMAESOptimizer(cmaesMaxIterations, 0.0, true, 0, cmaesCheckFeasableCount,
            new Well19937a(), false, cmaesChecker);
    PorodLineFitFunction function = new PorodLineFitFunction(porodData, porodAxis);

    int dataSize = porodAxis.getSize();
    double q0 = porodAxis.getDouble(0);
    double qMax = porodAxis.getDouble(dataSize - 1);
    double[] startPosition = new double[] { porodAxis.getDouble(dataSize - PorodLineFitFunction.MIN_POINTS - 1),
            porodAxis.getDouble(dataSize - 1) };
    double[] cmaesInputSigma = new double[] { qMax * 0.1, qMax * 0.1 };
    try {//from   ww w  .j av a 2s  .  c o m
        final PointValuePair res = optimizer.optimize(new MaxEval(cmaesMaxIterations),
                new ObjectiveFunction(function), GoalType.MAXIMIZE,
                new CMAESOptimizer.PopulationSize(cmaesLambda), new CMAESOptimizer.Sigma(cmaesInputSigma),
                new SimpleBounds(new double[] { q0, q0 }, new double[] { qMax, qMax }),
                new InitialGuess(startPosition));

        function.value(res.getPoint());
        double slope = function.regression.getSlope();
        Amount<Dimensionless> c4 = getC4(function.regression);

        System.out.println("Final Result");
        String msg = StringUtils
                .join(new String[] { "   c4 ", c4.toString(), "   slope ", Double.toString(slope) }, " : ");
        System.out.println(msg);
        msg = StringUtils.join(new String[] { "Slice", ArrayUtils.toString(res.getPoint()), "R",
                Double.toString(function.regression.getR()) }, " : ");
        System.out.println(msg);
    } catch (MaxCountExceededException e) {
        return null;
    }
    return function.regression;
}

From source file:uk.ac.ebi.embl.api.storage.DataRow.java

@Override
public String toString() {
    return ArrayUtils.toString(values);
}

From source file:uk.ac.tgac.rampart.RampartConfig.java

@Override
public String toString() {

    StringJoiner sj = new StringJoiner("\n");
    sj.add("Job Configuration File: " + this.getConfigFile().getAbsolutePath());
    sj.add("Output Directory: " + this.getOutputDir().getAbsolutePath());
    sj.add("Job Prefix: " + this.getJobPrefix());
    sj.add("Stages: " + ArrayUtils.toString(stages));

    return sj.toString();
}

From source file:uk.ac.tgac.rampart.stage.analyse.asm.selector.DefaultAssemblySelector.java

@Override
public AssemblyStats selectAssembly(AssemblyStatsTable table, Organism organism,
        QuastV23.AssemblyStats refStats, boolean cegmaEnabled) {

    boolean referenceProvided = refStats != null;
    boolean estimatesProvided = organism.getEstimated() != null;

    // Acquire metric groups
    ContiguityMetrics.Matrix contiguity = new ContiguityMetrics.Matrix(table, referenceProvided);
    ProblemMetrics.Matrix problems = new ProblemMetrics.Matrix(table, referenceProvided);
    ConservationMetrics.Matrix conservation = new ConservationMetrics.Matrix(table,
            referenceProvided ? refStats.getTotalLengthGt0()
                    : estimatesProvided ? organism.getEstimated().getEstGenomeSize() : 0,
            referenceProvided ? refStats.getGcPc()
                    : estimatesProvided ? organism.getEstimated().getEstGcPercentage() : 0.0,
            referenceProvided ? refStats.getNbGenes()
                    : estimatesProvided ? organism.getEstimated().getEstNbGenes() : 0,
            cegmaEnabled);/*  ww  w  .  ja  v  a2s .c  om*/
    log.info("Acquired metrics");

    log.debug("Contiguity");
    log.debug(contiguity.toString());

    log.debug("Problems");
    log.debug(problems.toString());

    log.debug("Conservation");
    log.debug(conservation.toString());

    // Normalise matrices
    contiguity.normalise();
    problems.normalise();
    conservation.normalise();
    log.info("Scaled metrics");

    log.debug("Contiguity");
    log.debug(contiguity.toString());

    log.debug("Problems");
    log.debug(problems.toString());

    log.debug("Conservation");
    log.debug(conservation.toString());

    // Apply weightings
    contiguity.weight(contiguityWeightings);
    problems.weight(problemWeightings);
    conservation.weight(conservationWeightings);
    log.info("Applied weightings");

    log.debug("Contiguity");
    log.debug(contiguity.toString());

    log.debug("Problems");
    log.debug(problems.toString());

    log.debug("Conservation");
    log.debug(conservation.toString());

    // Calc scores for groups
    double[] contiguityScores = contiguity.calcScores();
    double[] problemScores = problems.calcScores();
    double[] conservationsScores = conservation.calcScores();
    log.info("Calculated scores for each metric group");

    log.debug("Contiguity: " + Arrays.toString(contiguityScores));
    log.debug("Problems: " + Arrays.toString(problemScores));
    log.debug("Conservation: " + Arrays.toString(conservationsScores));

    table.addGroupScores(contiguityScores, problemScores, conservationsScores);

    AssemblyGroupStats.Matrix finalScores = new AssemblyGroupStats.Matrix(contiguityScores, problemScores,
            conservationsScores);
    finalScores.weight(groupWeightings);
    double[] scores = finalScores.calcScores();
    log.info("Weightings applied to group scores.  Final scores calculated.");

    // Save merged matrix with added scores
    table.addScores(scores);
    log.debug("Final scores are: " + ArrayUtils.toString(scores));

    // Report best assembly stats
    log.info("Best assembly stats: " + table.getBest().toString());

    return table.getBest();
}