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

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

Introduction

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

Prototype

public void stop() 

Source Link

Document

Stop the stopwatch.

This method ends a new timing session, allowing the time to be retrieved.

Usage

From source file:ubic.gemma.loader.expression.AffyPowerToolsProbesetSummarize.java

/**
 * @param ee/*w  w  w  .  j  a  v  a  2s . co  m*/
 * @param targetPlatform target platform
 * @param files list of CEL files (any other files included will be ignored)
 * @return
 */
public Collection<RawExpressionDataVector> processExonArrayData(ExpressionExperiment ee,
        ArrayDesign targetPlatform, Collection<LocalFile> files) {

    Collection<BioAssay> bioAssays = ee.getBioAssays();

    if (bioAssays.isEmpty()) {
        throw new IllegalArgumentException("Experiment had no assays");
    }

    if (targetPlatform.getCompositeSequences().isEmpty()) {
        throw new IllegalArgumentException("Target design had no elements");
    }

    List<String> celfiles = getCelFiles(files);
    log.info(celfiles.size() + " cel files");

    String outputPath = getOutputFilePath(ee, "apt-output");

    String cmd = getCommand(targetPlatform, celfiles, outputPath);

    log.info("Running: " + cmd);

    int exitVal = Integer.MIN_VALUE;

    StopWatch overallWatch = new StopWatch();
    overallWatch.start();
    try {
        final Process run = Runtime.getRuntime().exec(cmd);
        GenericStreamConsumer gscErr = new GenericStreamConsumer(run.getErrorStream());
        GenericStreamConsumer gscIn = new GenericStreamConsumer(run.getInputStream());
        gscErr.start();
        gscIn.start();

        while (exitVal == Integer.MIN_VALUE) {
            try {
                exitVal = run.exitValue();
            } catch (IllegalThreadStateException e) {
                // okay, still
                // waiting.
            }
            Thread.sleep(AFFY_UPDATE_INTERVAL_MS);

            synchronized (outputPath) {
                File outputFile = new File(outputPath + File.separator + "apt-probeset-summarize.log");
                Long size = outputFile.length();

                String minutes = TimeUtil.getMinutesElapsed(overallWatch);
                log.info(String.format("apt-probeset-summarize logging output so far: %.2f", size / 1024.0)
                        + " kb (" + minutes + " minutes elapsed)");
            }
        }

        overallWatch.stop();
        String minutes = TimeUtil.getMinutesElapsed(overallWatch);
        log.info("apt-probeset-summarize took a total of " + minutes + " minutes");

        return processExonArrayData(ee, outputPath + File.separator + METHOD + ".summary.txt", targetPlatform);

    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}

From source file:ubic.gemma.loader.expression.geo.GeoFamilyParser.java

/**
 * @param dis//from w  ww.  jav  a  2  s.  co  m
 * @throws IOException
 */
private Exception doParse(BufferedReader dis) {
    if (dis == null) {
        throw new RuntimeException("Null reader");
    }
    this.numWarnings = 0;
    haveReadPlatformHeader = false;
    haveReadSampleDataHeader = false;
    alreadyWarnedAboutClobbering = false;
    alreadyWarnedAboutInconsistentColumnOrder = false;
    alreadyWarnedAboutDuplicateColumnName = false;
    String line = "";
    parsedLines = 0;
    processedDesignElements.clear();

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

        while ((line = dis.readLine()) != null) {
            if (StringUtils.isBlank(line)) {
                continue;
            }

            parseLine(line);
            if (++parsedLines % 20000 == 0 && Thread.currentThread().isInterrupted()) {
                dis.close(); // clean up
                throw new java.util.concurrent.CancellationException(
                        "Thread was terminated during parsing. " + this.getClass());
            }
        }

        tidyUp();

    } catch (Exception e) {
        log.error("Parsing failed (Cancelled?) :" + e.getMessage());
        /*
         * This happens if there was a cancellation.
         */
        throw new RuntimeException(e);
    }

    timer.stop();
    if (timer.getTime() > 10000) { // 10 s
        log.info("Parsed total of " + parsedLines + " lines in "
                + String.format("%.2gs", timer.getTime() / 1000.0));
    }
    log.debug(this.platformLines + " platform  lines");
    log.debug(this.seriesDataLines + " series data lines");
    log.debug(this.dataSetDataLines + " data set data lines");
    log.debug(this.sampleDataLines + " sample data lines");
    return null;
}

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

/**
 * @param bioSequences//  w w w  . j a  v  a2s. co  m
 */
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.util.ParserAndLoaderTools.java

/**
 * User the loader to persist the collection.
 * /*from  ww w  .j a va2s.  c  o  m*/
 * @param loader
 * @param col
 */
public static final void loadDatabase(Persister loader, Collection<?> col) {
    assert (loader != null);
    assert (col != null);
    if (col.size() == 0)
        return;

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

    loader.persist(col);

    stopWatch.stop();

    long time = stopWatch.getTime();
    if (time < 1000)
        log.info("Time taken: " + time + " ms.");
    else {
        log.info("Time taken: " + time / 1000 + " s.");
    }
}

From source file:ubic.gemma.ontology.providers.GeneOntologyServiceImpl.java

/**
 * /*from  w  w w.j  a va  2  s  .c o  m*/
 */
private synchronized void initializeGeneOntology() {

    Thread loadThread = new Thread(new Runnable() {
        @Override
        public void run() {
            running.set(true);
            uri2Term = new HashMap<String, OntologyTerm>();
            log.info("Loading Gene Ontology...");
            StopWatch loadTime = new StopWatch();
            loadTime.start();
            //
            try {
                loadTermsInNameSpace(MF_URL);
                log.info("Gene Ontology Molecular Function loaded, total of " + uri2Term.size() + " items in "
                        + loadTime.getTime() / 1000 + "s");

                loadTermsInNameSpace(BP_URL);
                log.info("Gene Ontology Biological Process loaded, total of " + uri2Term.size() + " items in "
                        + loadTime.getTime() / 1000 + "s");

                loadTermsInNameSpace(CC_URL);
                log.info("Gene Ontology Cellular Component loaded, total of " + uri2Term.size() + " items in "
                        + loadTime.getTime() / 1000 + "s");

                ready.set(true);
                running.set(false);

                log.info("Done loading GO");
                loadTime.stop();
            } catch (Throwable e) {
                if (log != null)
                    log.error(e, e);// log call can break hot deploy
                ready.set(false);
                running.set(false);
            }
        }

    });

    if (running.get())
        return;
    loadThread.start();

}

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * A general search for array designs./*from w  w w .  j  av  a  2s  . c  om*/
 * <p>
 * This search does both an database search and a compass search. This is also contains an underlying
 * {@link CompositeSequence} search, returning the {@link ArrayDesign} collection for the given composite sequence
 * search string (the returned collection of array designs does not contain duplicates).
 * 
 * @param searchString
 * @param probeResults Collection of results from a previous CompositeSequence search. Can be null; otherwise used
 *        to avoid a second search for probes. The array designs for the probes are added to the final results.
 * @return
 */
private Collection<SearchResult> arrayDesignSearch(SearchSettings settings,
        Collection<SearchResult> probeResults) {

    StopWatch watch = startTiming();
    String searchString = settings.getQuery();
    Collection<SearchResult> results = new HashSet<SearchResult>();

    ArrayDesign shortNameResult = arrayDesignService.findByShortName(searchString);
    if (shortNameResult != null) {
        results.add(new SearchResult(shortNameResult, 1.0));
    } else {
        Collection<ArrayDesign> nameResult = arrayDesignService.findByName(searchString);
        if (nameResult != null)
            for (ArrayDesign ad : nameResult) {
                results.add(new SearchResult(ad, 1.0));
            }
    }

    Collection<ArrayDesign> altNameResults = arrayDesignService.findByAlternateName(searchString);
    for (ArrayDesign arrayDesign : altNameResults) {
        results.add(new SearchResult(arrayDesign, 0.9));
    }

    Collection<ArrayDesign> manufacturerResults = arrayDesignService.findByManufacturer(searchString);
    for (ArrayDesign arrayDesign : manufacturerResults) {
        results.add(new SearchResult(arrayDesign, 0.9));
    }

    results.addAll(compassArrayDesignSearch(settings));
    results.addAll(databaseArrayDesignSearch(settings));

    Collection<SearchResult> probes = null;
    if (probeResults == null) {
        probes = compassCompositeSequenceSearch(settings);
    } else {
        probes = probeResults;
    }

    for (SearchResult r : probes) {
        CompositeSequence cs = (CompositeSequence) r.getResultObject();
        if (cs.getArrayDesign() == null) // This might happen as compass
            // might not have indexed the AD
            // for the CS
            continue;
        results.add(r);
    }

    watch.stop();
    if (watch.getTime() > 1000)
        log.info("Array Design search for '" + settings + "' took " + watch.getTime() + " ms");

    return results;
}

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * *//  w  ww.  jav a2s  . c  o  m
 * 
 * @param searchString
 * @param previousGeneSearchResults Can be null, otherwise used to avoid a second search for genes. The biosequences
 *        for the genes are added to the final results.
 * @return
 */
private Collection<SearchResult> bioSequenceSearch(SearchSettings settings,
        Collection<SearchResult> previousGeneSearchResults) {
    StopWatch watch = startTiming();

    Collection<SearchResult> searchResults = new HashSet<SearchResult>();
    searchResults.addAll(compassBioSequenceSearch(settings, previousGeneSearchResults));
    searchResults.addAll(databaseBioSequenceSearch(settings));

    watch.stop();
    if (watch.getTime() > 1000)
        log.info("Biosequence search for '" + settings + "' took " + watch.getTime() + " ms "
                + searchResults.size() + " results.");

    return searchResults;
}

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * @param classes/*  w  ww .  j ava  2 s  .co m*/
 * @param matches
 * @param query
 * @return
 */
private Collection<SearchResult> characteristicSearchWord(Collection<Class<?>> classes,
        Map<SearchResult, String> matches, String query) {

    StopWatch watch = startTiming();
    Collection<String> characteristicUris = new HashSet<String>();

    Collection<OntologyIndividual> individuals = ontologyService.findIndividuals(query);
    if (individuals.size() > 0 && watch.getTime() > 1000) {
        log.info("Found " + individuals.size() + " individuals matching '" + query + "' in " + watch.getTime()
                + "ms");
    }
    watch.reset();
    watch.start();

    for (OntologyIndividual term : individuals) {
        if ((term != null) && (term.getUri() != null))
            characteristicUris.add(term.getUri());
    }

    Collection<OntologyTerm> matchingTerms = ontologyService.findTerms(query);

    if (watch.getTime() > 1000) {
        log.info("Found " + matchingTerms.size() + " ontology classes matching '" + query + "' in "
                + watch.getTime() + "ms");
    }

    watch.reset();
    Collection<SearchResult> results = new HashSet<SearchResult>();
    Collection<Characteristic> cs = new HashSet<Characteristic>();
    if (!matchingTerms.isEmpty()) {
        watch.start();

        for (OntologyTerm term : matchingTerms) {
            String uri = term.getUri();
            if (uri == null || uri.isEmpty())
                continue;
            characteristicUris.add(uri);
            addChildTerms(characteristicUris, term);
        }

        // int cacheHits = childTermCache.getStatistics().getCacheHits();
        // if ( log.isDebugEnabled() ) log.debug( cacheHits + " cache hits for ontology children" );

        if (watch.getTime() > 1000) {
            log.info("Found " + characteristicUris.size() + " possible matches + child terms in "
                    + watch.getTime() + "ms");
        }

        /*
         * Find occurrences of these terms in our system. This is fast, so long as there aren't too many.
         */
        Collection<SearchResult> matchingCharacteristics = dbHitsToSearchResult(
                characteristicService.findByUri(classes, characteristicUris));

        for (SearchResult crs : matchingCharacteristics) {
            cs.add((Characteristic) crs.getResultObject());
        }
    }
    watch.reset();
    watch.start();
    /*
     * Add characteristics that have values matching the query; this pulls in items not associated with ontology
     * terms (free text). We do this here so we can apply the query logic to the matches.
     */
    String dbQueryString = query.replaceAll("\\*", "");
    Collection<Characteristic> valueMatches = characteristicService.findByValue(classes, dbQueryString);

    if (valueMatches != null && !valueMatches.isEmpty())
        cs.addAll(valueMatches);

    /*
     * Retrieve the owner objects
     */
    Collection<SearchResult> matchingEntities = getAnnotatedEntities(classes, cs);
    results.addAll(matchingEntities);

    if (watch.getTime() > 1000) {
        log.info("Slow search: found " + matchingEntities.size() + " matches to characteristics for '" + query
                + "' from " + characteristicUris.size() + " URIS in " + watch.getTime() + "ms");
    }

    watch.stop();

    for (SearchResult searchR : results) {
        if (!matches.containsKey(searchR)) {
            matches.put(searchR, query);
        } else {
            matches.put(searchR, matches.get(searchR) + " " + query);
        }
    }

    return results;
}

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * Search by name of the composite sequence as well as gene.
 * //from w w w  .j  a v a 2s .c o  m
 * @return
 * @throws Exception
 */
private Collection<SearchResult> compositeSequenceSearch(SearchSettings settings) {

    StopWatch watch = startTiming();

    /*
     * FIXME: this at least partly ignores any array design that was set as a restriction, especially in a gene
     * search.
     */

    Collection<SearchResult> allResults = new HashSet<SearchResult>();
    // Temporaily removing compass searching of composite sequences because it only bloats the results.
    // allResults.addAll( compassCompositeSequenceSearch( settings ) );
    allResults.addAll(databaseCompositeSequenceSearch(settings));
    // allResults.addAll( compositeSequenceByGeneSearch( settings, geneSearchResults ) );

    /*
     * This last step is needed because the compassSearch for compositeSequences returns bioSequences too.
     */
    Collection<SearchResult> finalResults = new HashSet<SearchResult>();
    for (SearchResult sr : allResults) {
        if (CompositeSequence.class.isAssignableFrom(sr.getResultClass())) {
            finalResults.add(sr);
        }
    }

    watch.stop();
    if (watch.getTime() > 1000)
        log.info("Composite sequence search for '" + settings + "' took " + watch.getTime() + " ms, "
                + finalResults.size() + " results.");
    return finalResults;
}

From source file:ubic.gemma.search.SearchServiceImpl.java

/**
 * Searches the DB for array designs which have composite sequences whose names match the given search string.
 * Because of the underlying database search, this is acl aware. That is, returned array designs are filtered based
 * on access control list (ACL) permissions.
 * // ww  w . j a va2  s. c  o m
 * @param searchString
 * @return
 * @throws Exception
 */
private Collection<SearchResult> databaseArrayDesignSearch(SearchSettings settings) {

    if (!settings.getUseDatabase())
        return new HashSet<SearchResult>();

    StopWatch watch = startTiming();

    Collection<ArrayDesign> adSet = new HashSet<ArrayDesign>();

    // search by exact composite sequence name
    Collection<CompositeSequence> matchedCs = compositeSequenceService.findByName(settings.getQuery());
    for (CompositeSequence sequence : matchedCs) {
        adSet.add(sequence.getArrayDesign());
    }

    watch.stop();
    if (watch.getTime() > 1000)
        log.info("Array Design Compositesequence DB search for " + settings + " took " + watch.getTime() + " ms"
                + " found " + adSet.size() + " Ads");

    return dbHitsToSearchResult(adSet);

}