Example usage for org.apache.commons.lang.time StopWatch reset

List of usage examples for org.apache.commons.lang.time StopWatch reset

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch reset.

Prototype

public void reset() 

Source Link

Document

Resets the stopwatch.

Usage

From source file:ubic.gemma.analysis.preprocess.batcheffects.ComBat.java

/**
 * @param parametric if false, use the non-parametric (slower) method for estimating the priors.
 * @return corrected data/*from  w  w  w . j ava 2 s  .  c o m*/
 * @throws ComBatException
 */
public DoubleMatrix2D run(boolean parametric) throws ComBatException {

    StopWatch timer = new StopWatch();
    timer.start();

    final DoubleMatrix2D sdata = standardize(y, X);

    checkForProblems(sdata);

    if (timer.getTime() > 1000) {
        log.info("Standardized");
    }
    timer.reset();
    timer.start();

    gammaHat(sdata);

    deltaHat(sdata);
    // assertEquals( 1.618, deltaHat.get( 0, 0 ), 0.001 );

    // gamma.bar <- apply(gamma.hat, 1, mean)
    gammaBar = new DoubleArrayList();
    t2 = new DoubleArrayList();
    for (int batchIndex = 0; batchIndex < gammaHat.rows(); batchIndex++) {
        double mean = DescriptiveWithMissing.mean(new DoubleArrayList(gammaHat.viewRow(batchIndex).toArray()));
        gammaBar.add(mean);
        t2.add(DescriptiveWithMissing
                .sampleVariance(new DoubleArrayList(gammaHat.viewRow(batchIndex).toArray()), mean));
    }

    // assertEquals( -0.092144, gammaBar.get( 0 ), 0.001 );
    // assertEquals( 0.2977, t2.get( 1 ), 0.001 );

    aPrior = aPrior(deltaHat);
    bPrior = bPrior(deltaHat);

    if (timer.getTime() > 1000) {
        log.info("Computed priors");
    }

    // assertEquals( 17.4971, aPrior.get( 0 ), 0.0001 );
    // assertEquals( 4.514, bPrior.get( 1 ), 0.0001 );

    DoubleMatrix2D gammastar = new DenseDoubleMatrix2D(numBatches, numProbes);
    DoubleMatrix2D deltastar = new DenseDoubleMatrix2D(numBatches, numProbes);

    if (!parametric) {
        runNonParametric(sdata, gammastar, deltastar);
    } else {
        runParametric(sdata, gammastar, deltastar);
    }

    DoubleMatrix2D adjustedData = rawAdjust(sdata, gammastar, deltastar);

    // assertEquals( -0.95099, adjustedData.get( 18, 0 ), 0.0001 );
    // assertEquals( -0.30273984, adjustedData.get( 14, 6 ), 0.0001 );
    // assertEquals( 0.2097977, adjustedData.get( 7, 3 ), 0.0001 );
    // log.info( adjustedData );
    DoubleMatrix2D result = restoreScale(adjustedData);
    if (timer.getTime() > 1000) {
        log.info("Done");
    }
    return result;
}

From source file:ubic.gemma.annotation.geommtx.ExpressionExperimentAnnotatorImpl.java

/**
 * @param model// w ww  . ja v a  2 s .  c  o  m
 * @param experiment
 */
private void annotateBioAssays(Model model, ExpressionExperiment experiment) {

    int i = 0;
    StopWatch timer = new StopWatch();
    timer.start();
    for (BioAssay ba : experiment.getBioAssays()) {
        String nameSpaceBase = "bioAssay/" + ba.getId() + "/";
        if (ba.getName() != null) {
            doRDF(model, experiment.getId(), ba.getName().replace("Expr(", "Expr "), nameSpaceBase + "name");
        }

        if (ba.getDescription() != null) {
            doRDF(model, experiment.getId(), ba.getDescription(), nameSpaceBase + "description");
        }

        if (++i % 10 == 0 && timer.getTime() > 10000) {
            log.info(i + " bioassays processed");
            timer.reset();
            timer.start();
        }

    }
}

From source file:ubic.gemma.loader.expression.arrayDesign.AffyProbeReader.java

@Override
public void parse(InputStream is) throws IOException {
    if (is == null)
        throw new IllegalArgumentException("InputStream was null");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    StopWatch timer = new StopWatch();
    timer.start();/*w ww.ja v  a2s .  c om*/
    int nullLines = 0;
    String line = null;
    int linesParsed = 0;
    while ((line = br.readLine()) != null) {

        if (line.startsWith(COMMENTMARK)) {
            continue;
        }
        parseOneLine(line);

        if (++linesParsed % PARSE_ALERT_FREQUENCY == 0 && timer.getTime() > PARSE_ALERT_TIME_FREQUENCY_MS) {
            String message = "Parsed " + linesParsed + " lines...  ";
            log.info(message);
            timer.reset();
            timer.start();
        }

    }
    log.info("Parsed " + linesParsed + " lines. "
            + (nullLines > 0 ? nullLines + " yielded no parse result (they may have been filtered)." : ""));

    br.close();
}

From source file:ubic.gemma.loader.genome.gene.ncbi.NcbiGeneLoader.java

/**
 * @param geneQueue//from   www  .  j a  v  a 2 s  .c o  m
 */
void doLoad(final BlockingQueue<Gene> geneQueue) {
    StopWatch timer = new StopWatch();
    timer.start();
    int skipped = 0;
    while (!(converterDone.get() && geneQueue.isEmpty())) {
        Gene gene = null;
        try {
            // the converted genes.
            gene = geneQueue.poll();
            if (gene == null) {
                continue;
            }

            if (gene.getProducts().isEmpty()) {
                // // log.warn( gene + " has no products, skipping" ); // common!!!
                // skipped++;
            }

            persisterHelper.persistOrUpdate(gene);

            if (++loadedGeneCount % 1000 == 0 || timer.getTime() > 30 * 1000) {
                log.info("Processed " + loadedGeneCount + " genes. Queue has " + geneQueue.size()
                        + " items; last gene: " + gene);
                if (skipped > 0) {
                    log.info(skipped + " skipped because they had no gene products.");
                }
                timer.reset();
                timer.start();
            }

        } catch (Exception e) {
            log.error("Error while loading gene: " + gene + ": " + e.getMessage(), e);
            loaderDone.set(true);
            throw new RuntimeException(e);
        }
    }
    log.info("Loaded " + loadedGeneCount + " genes. ");
    loaderDone.set(true);
}

From source file:ubic.gemma.loader.genome.goldenpath.GoldenPathBioSequenceLoader.java

/**
 * @param bioSequences// w  ww  .  j  a v  a  2 s.c  om
 */
void load(BlockingQueue<BioSequence> queue) {
    log.debug("Entering 'load' ");

    StopWatch timer = new StopWatch();
    timer.start();

    int count = 0;
    int cpt = 0;
    double secspt = 0.0;

    Collection<BioSequence> bioSequencesToPersist = new ArrayList<BioSequence>();
    try {
        while (!(producerDone && queue.isEmpty())) {
            BioSequence sequence = queue.poll();

            if (sequence == null) {
                continue;
            }

            sequence.getSequenceDatabaseEntry().setExternalDatabase(genbank);
            sequence.setTaxon(taxon);
            bioSequencesToPersist.add(sequence);
            if (++count % BATCH_SIZE == 0) {
                bioSequenceService.create(bioSequencesToPersist);
                bioSequencesToPersist.clear();
            }

            // just some timing information.
            if (count % 1000 == 0) {
                cpt++;
                timer.stop();
                double secsperthousand = timer.getTime() / 1000.0;
                secspt += secsperthousand;
                double meanspt = secspt / cpt;

                String progString = "Processed and loaded " + count + " sequences, last one was "
                        + sequence.getName() + " (" + secsperthousand + "s for last 1000, mean per 1000 ="
                        + String.format("%.1f", meanspt) + "s)";
                log.info(progString);
                timer.reset();
                timer.start();
            }

        }
    } catch (Exception e) {
        consumerDone = true;
        throw new RuntimeException(e);
    }

    // finish up.
    bioSequenceService.create(bioSequencesToPersist);

    log.info("Loaded total of " + count + " sequences");
    consumerDone = true;

}

From source file:ubic.gemma.loader.genome.ProbeSequenceParser.java

@Override
public void parse(InputStream is) throws IOException {

    if (is == null)
        throw new IllegalArgumentException("InputStream was null");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    StopWatch timer = new StopWatch();
    timer.start();//from  ww w .j a  v  a2 s . com
    int nullLines = 0;
    String line = null;
    int linesParsed = 0;
    while ((line = br.readLine()) != null) {

        BioSequence newItem = parseOneLine(line);

        if (++linesParsed % PARSE_ALERT_FREQUENCY == 0 && timer.getTime() > PARSE_ALERT_TIME_FREQUENCY_MS) {
            String message = "Parsed " + linesParsed + " lines ";
            log.info(message);
            timer.reset();
            timer.start();
        }

        if (newItem == null) {
            nullLines++;
            continue;
        }

    }
    log.info("Parsed " + linesParsed + " lines. "
            + (nullLines > 0 ? nullLines + " yielded no parse result (they may have been filtered)." : ""));

    br.close();
}

From source file:ubic.gemma.loader.util.fetcher.AbstractFetcher.java

/**
 * @param future/*from   w w  w  .  j a  v a 2s.  c  o  m*/
 * @param expectedSize
 * @param outputFileName
 * @return true if it finished normally, false if it was cancelled.
 */
protected boolean waitForDownload(FutureTask<Boolean> future, long expectedSize, File outputFile) {
    int iters = 0;
    long previousSize = 0;
    StopWatch idleTimer = new StopWatch();
    while (!future.isDone() && !future.isCancelled()) {
        try {
            Thread.sleep(INFO_UPDATE_INTERVAL);
        } catch (InterruptedException ie) {
            log.info("Cancelling download");
            boolean cancelled = future.cancel(true);
            if (cancelled) {
                return false;
            }

            // double check...
            if (future.isCancelled() || future.isDone()) {
                return false;
            }

            log.error("Cancellation of actual download might not have happend? Task says it was not cancelled: "
                    + future);

            return false;

        }

        /*
         * Avoid logging too much. If we're waiting for a long download, reduce frequency of updates.
         */
        if (outputFile.length() < expectedSize
                && (iters < NUMBER_OF_TIMES_TO_LOG_WAITING_BEFORE_REDUCING_VERBOSITY
                        || iters % NUMBER_OF_TIMES_TO_LOG_WAITING_BEFORE_REDUCING_VERBOSITY == 0)) {

            double percent = 100.00 * outputFile.length() / expectedSize;

            // can cause npe error, breaking hot deploy
            if (log != null && log.isInfoEnabled()) {
                log.info((outputFile.length() + (expectedSize > 0 ? "/" + expectedSize : "") + " bytes read ("
                        + String.format("%.1f", percent) + "%)"));
            }

            if (previousSize == outputFile.length()) {
                /*
                 * Possibly consider bailing after a while.
                 */
                if (idleTimer.getTime() > STALLED_BAIL_TIME_LIMIT) {
                    log.warn("Download does not seem to be happening, bailing");
                    return false;
                }
                if (idleTimer.getTime() == 0)
                    idleTimer.start();
            } else {
                idleTimer.reset();
                idleTimer.start();
            }
        }

        if (outputFile.length() >= expectedSize) {
            // no special action, it will finish soon enough.
        }

        previousSize = outputFile.length();

        iters++;
    }
    if (iters == 0)
        log.info("File with size " + outputFile.length() + " bytes.");
    return true;
}

From source file:ubic.gemma.loader.util.parser.BasicLineMapParser.java

@Override
public void parse(InputStream is) throws IOException {

    if (is == null)
        throw new IllegalArgumentException("InputStream was null");
    BufferedReader br = new BufferedReader(new InputStreamReader(is));

    StopWatch timer = new StopWatch();
    timer.start();//  w ww. ja va 2  s .  c  om

    int nullLines = 0;
    String line = null;
    int linesParsed = 0;
    while ((line = br.readLine()) != null) {

        if (line.startsWith(COMMENTMARK)) {
            continue;
        }
        T newItem = parseOneLine(line);

        if (newItem == null) {
            nullLines++;
            continue;
        }

        K key = getKey(newItem);
        if (key == null) {
            throw new IllegalStateException("Got null key for item " + linesParsed);
        }
        put(key, newItem);

        if (++linesParsed % PARSE_ALERT_FREQUENCY == 0 && timer.getTime() > PARSE_ALERT_TIME_FREQUENCY_MS) {
            String message = "Parsed " + linesParsed + " lines, last had key " + key;
            log.info(message);
            timer.reset();
            timer.start();
        }

    }
    log.info("Parsed " + linesParsed + " lines. "
            + (nullLines > 0 ? nullLines + " yielded no parse result (they may have been filtered)." : ""));

    br.close();
}

From source file:ubic.gemma.loader.util.parser.BasicLineParser.java

@Override
public void parse(InputStream is) throws IOException {

    linesParsed = 0;/*from   ww w.  ja v  a  2  s.  c o m*/
    int nullLines = 0;

    if (br == null) {
        if (is == null) {
            throw new IllegalArgumentException("Inputstream null");
        }

        if (is.available() == 0) {
            throw new IOException("No bytes available to read from inputStream");
        }
        br = new BufferedReader(new InputStreamReader(is));
    }

    String line = null;

    StopWatch timer = new StopWatch();
    timer.start();
    while ((line = br.readLine()) != null) {

        if (line.startsWith(COMMENTMARK)) {
            continue;
        }

        T newItem = parseOneLine(line);

        if (newItem != null) {
            addResult(newItem);
        } else {
            // if ( log.isDebugEnabled() ) log.debug( "Got null parse from " + line );
            nullLines++;
        }

        if (++linesParsed % PARSE_ALERT_FREQUENCY == 0 && timer.getTime() > PARSE_ALERT_TIME_FREQUENCY_MS) {
            String message = "Parsed " + linesParsed + " lines...";
            log.info(message);
            timer.reset();
            timer.start();
        }

    }

    if (linesParsed > MIN_PARSED_LINES_FOR_UPDATE && this.getResults() != null) {
        log.info("Parsed " + linesParsed + " lines, " + this.getResults().size() + " items");
    }
    if (nullLines > 0)
        log.info(nullLines + " yielded no parse result (they may have been filtered).");
}

From source file:ubic.gemma.loader.util.parser.LineMapParser.java

@Override
public void parse(InputStream is) throws IOException {

    if (is == null) {
        throw new IllegalArgumentException("Inputstream null");
    }/*from w w  w  . ja  va  2 s  .  c o  m*/

    if (is.available() == 0) {
        throw new IOException("No bytes available to read from inputStream");
    }

    linesParsed = 0;
    int nullLines = 0;
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    StopWatch timer = new StopWatch();
    timer.start();
    String line = null;

    while ((line = br.readLine()) != null) {

        if (line.startsWith(COMMENTMARK)) {
            continue;
        }

        // The returned object is just used to check if the was data in the line. Storing the data has to be taken
        // care of by the subclass.
        Object newItem = parseOneLine(line);

        if (newItem == null) {
            nullLines++;
        }

        if (++linesParsed % PARSE_ALERT_FREQUENCY == 0 && timer.getTime() > PARSE_ALERT_TIME_FREQUENCY_MS) {
            String message = "Parsed " + linesParsed + " lines...";
            log.info(message);
            timer.reset();
            timer.start();
        }

    }

    if (linesParsed > MIN_PARSED_LINES_FOR_UPDATE) {
        log.info("Parsed " + linesParsed + " lines, " + this.getResults().size() + " items");
    }
    if (nullLines > 0)
        log.info(nullLines + " yielded no parse result (they may have been filtered).");
}