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

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

Introduction

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

Prototype

public long getTime() 

Source Link

Document

Get the time on the stopwatch.

This is either the time between the start and the moment this method is called, or the amount of time between start and stop.

Usage

From source file:ubic.gemma.apps.LinkAnalysisCli.java

/**
 * @param args//ww w . ja v a2 s  .c  om
 */
public static void main(String[] args) {
    LinkAnalysisCli analysis = new LinkAnalysisCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = analysis.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Elapsed time: " + watch.getTime() / 1000 + " seconds");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.apps.LinkEvalCli.java

/**
 * @param scoreMap//  w w w  .  jav a  2 s .c  om
 * @param overallWatch
 */
private void writeGoSimilarityResults(Map<GenePair, Double> scoreMap) {
    StopWatch overallWatch = new StopWatch();
    overallWatch.start();
    subsetLinks = scoreMap.size();
    try {
        Writer write = initOutputFile(outFile);
        for (GenePair pair : scoreMap.keySet()) {
            List<Gene> firstGenes = pair.getFirstGenes();
            List<Gene> secondGenes = pair.getSecondGenes();

            String pairString = pair.toString();
            Double score = scoreMap.get(pair);
            if (score == null) {
                log.warn("Score is null for " + pair);
                continue;
            }
            int masterGOTerms = 0;
            int coExpGOTerms = 0;
            Collection<OntologyTerm> overlappingGoTerms = null;
            if (firstGenes.size() == 1 && secondGenes.size() == 1) {
                Gene mGene = firstGenes.iterator().next();
                Gene cGene = secondGenes.iterator().next();

                if (!geneGoMap.containsKey(mGene.getId()))
                    masterGOTerms = 0;
                else
                    masterGOTerms = (geneGoMap.get(mGene.getId())).size();

                if (!geneGoMap.containsKey(cGene.getId()))
                    coExpGOTerms = 0;
                else
                    coExpGOTerms = (geneGoMap.get(cGene.getId())).size();

                overlappingGoTerms = getTermOverlap(mGene, cGene);

            } else {
                Map<String, List<Gene>> orgGenes1 = organizeDuplicates(firstGenes);
                Map<String, List<Gene>> orgGenes2 = organizeDuplicates(secondGenes);

                GenePair uniquePair = new GenePair();
                List<Set<String>> mergedGoTerms1 = new ArrayList<Set<String>>();
                List<Set<String>> mergedGoTerms2 = new ArrayList<Set<String>>();
                for (String geneName1 : orgGenes1.keySet()) {
                    List<Gene> tempGenes = orgGenes1.get(geneName1);
                    uniquePair.addFirstGene(tempGenes.get(0));
                    Set<String> uniqGoTerms = new HashSet<String>();
                    for (Gene g1 : tempGenes) {
                        if (geneGoMap.containsKey(g1.getId())) {
                            uniqGoTerms.addAll(geneGoMap.get(g1.getId()));
                        }
                    }
                    mergedGoTerms1.add(uniqGoTerms);
                }
                for (String geneName2 : orgGenes2.keySet()) {
                    List<Gene> tempGenes = orgGenes2.get(geneName2);
                    uniquePair.addSecondGene(tempGenes.get(0));
                    Set<String> uniqGoTerms = new HashSet<String>();
                    for (Gene g2 : tempGenes) {
                        if (geneGoMap.containsKey(g2.getId())) {
                            uniqGoTerms.addAll(geneGoMap.get(g2.getId()));
                        }
                    }
                    mergedGoTerms2.add(uniqGoTerms);
                }
                pairString = uniquePair.toString();
                if (orgGenes1.size() == 1 && orgGenes2.size() == 1) {
                    masterGOTerms = mergedGoTerms1.get(0).size();
                    coExpGOTerms = mergedGoTerms2.get(0).size();
                    overlappingGoTerms = getMergedTermOverlap(mergedGoTerms1.get(0), mergedGoTerms2.get(0));
                }
            }
            writeOverlapLine(write, pairString, score, overlappingGoTerms, masterGOTerms, coExpGOTerms);
        }
        write.flush();
        overallWatch.stop();
        log.info("Compute GoOverlap takes " + overallWatch.getTime() + "ms");

        // printResults(masterTermCountMap);
    } catch (IOException ioe) {
        log.error("Couldn't write to file: " + ioe);

    }
}

From source file:ubic.gemma.apps.LoadExpressionDataCli.java

/**
 * @param args/* w  ww.  j av  a2  s  . c o m*/
 */
public static void main(String[] args) {
    LoadExpressionDataCli p = new LoadExpressionDataCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = p.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info(watch.getTime());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.apps.LoadSimpleExpressionDataCli.java

/**
 * @param args/*from   w  ww  .  ja  v a 2  s . c  om*/
 */
public static void main(String[] args) {
    LoadSimpleExpressionDataCli p = new LoadSimpleExpressionDataCli();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = p.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info(watch.getTime());
    } catch (Exception e) {
        log.fatal(e, e);
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.apps.ProcessedDataComputeCLI.java

/**
 * @param args/*www  . j av a 2  s  . co  m*/
 */
public static void main(String[] args) {
    ProcessedDataComputeCLI computing = new ProcessedDataComputeCLI();
    StopWatch watch = new StopWatch();
    watch.start();
    try {
        Exception ex = computing.doWork(args);
        if (ex != null) {
            ex.printStackTrace();
        }
        watch.stop();
        log.info("Elapsed time: " + watch.getTime() / 1000 + " seconds");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ubic.gemma.association.phenotype.PhenotypeAssociationManagerServiceImpl.java

/**
 * Giving a phenotype searchQuery, returns a selection choice to the user
 * //from  ww w .  ja va2 s  . co  m
 * @param searchQuery query typed by the user
 * @param geneId the id of the chosen gene
 * @return Collection<CharacteristicValueObject> list of choices returned
 */
@Override
public Collection<CharacteristicValueObject> searchOntologyForPhenotypes(String searchQuery, Long geneId) {
    StopWatch timer = new StopWatch();
    timer.start();
    ArrayList<CharacteristicValueObject> orderedPhenotypesFromOntology = new ArrayList<CharacteristicValueObject>();

    boolean geneProvided = true;

    if (geneId == null) {
        geneProvided = false;
    }

    // prepare the searchQuery to correctly query the Ontology
    String newSearchQuery = prepareOntologyQuery(searchQuery);

    // search the Ontology with the new search query
    Set<CharacteristicValueObject> allPhenotypesFoundInOntology = this.ontologyHelper
            .findPhenotypesInOntology(newSearchQuery);

    // All phenotypes present on the gene (if the gene was given)
    Set<CharacteristicValueObject> phenotypesOnCurrentGene = null;

    if (geneProvided) {
        phenotypesOnCurrentGene = findUniquePhenotypesForGeneId(geneId);
    }

    // all phenotypes currently in the database
    Set<String> allPhenotypesInDatabase = this.associationService.loadAllPhenotypesUri();

    // rules to order the Ontology results found
    Set<CharacteristicValueObject> phenotypesWithExactMatch = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesAlreadyPresentOnGene = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesStartWithQueryAndInDatabase = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesStartWithQuery = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesSubstringAndInDatabase = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesSubstring = new TreeSet<CharacteristicValueObject>();
    Set<CharacteristicValueObject> phenotypesNoRuleFound = new TreeSet<CharacteristicValueObject>();

    /*
     * for each CharacteristicVO found from the Ontology, filter them and add them to a specific list if they
     * satisfied the condition
     */
    for (CharacteristicValueObject cha : allPhenotypesFoundInOntology) {

        // set flag for UI, flag if the phenotype is on the Gene or if in the database
        if (phenotypesOnCurrentGene != null && phenotypesOnCurrentGene.contains(cha)) {
            cha.setAlreadyPresentOnGene(true);
        } else if (allPhenotypesInDatabase.contains(cha.getValueUri())) {
            cha.setAlreadyPresentInDatabase(true);
        }

        // order the results by specific rules

        // Case 1, exact match
        if (cha.getValue().equalsIgnoreCase(searchQuery)) {
            phenotypesWithExactMatch.add(cha);
        }
        // Case 2, phenotype already present on Gene
        else if (phenotypesOnCurrentGene != null && phenotypesOnCurrentGene.contains(cha)) {
            phenotypesAlreadyPresentOnGene.add(cha);
        }
        // Case 3, starts with a substring of the word
        else if (cha.getValue().toLowerCase().startsWith(searchQuery.toLowerCase())) {
            if (allPhenotypesInDatabase.contains(cha.getValueUri())) {
                phenotypesStartWithQueryAndInDatabase.add(cha);
            } else {
                phenotypesStartWithQuery.add(cha);
            }
        }
        // Case 4, contains a substring of the word
        else if (cha.getValue().toLowerCase().indexOf(searchQuery.toLowerCase()) != -1) {
            if (allPhenotypesInDatabase.contains(cha.getValueUri())) {
                phenotypesSubstringAndInDatabase.add(cha);
            } else {
                phenotypesSubstring.add(cha);
            }
        } else {
            phenotypesNoRuleFound.add(cha);
        }
    }

    // place them in the correct order to display
    orderedPhenotypesFromOntology.addAll(phenotypesWithExactMatch);
    orderedPhenotypesFromOntology.addAll(phenotypesAlreadyPresentOnGene);
    orderedPhenotypesFromOntology.addAll(phenotypesStartWithQueryAndInDatabase);
    orderedPhenotypesFromOntology.addAll(phenotypesSubstringAndInDatabase);
    orderedPhenotypesFromOntology.addAll(phenotypesStartWithQuery);
    orderedPhenotypesFromOntology.addAll(phenotypesSubstring);
    orderedPhenotypesFromOntology.addAll(phenotypesNoRuleFound);

    // limit the size of the returned phenotypes to 100 terms
    if (orderedPhenotypesFromOntology.size() > MAX_PHENOTYPES_FROM_ONTOLOGY) {
        if (timer.getTime() > 1000) {
            log.info("Phenotype search: " + timer.getTime() + "ms");
        }
        return orderedPhenotypesFromOntology.subList(0, MAX_PHENOTYPES_FROM_ONTOLOGY);
    }
    if (timer.getTime() > 1000) {
        log.info("Phenotype search: " + timer.getTime() + "ms");
    }
    return orderedPhenotypesFromOntology;
}

From source file:ubic.gemma.genome.gene.service.GeneSearchServiceImpl.java

/**
 * if query is blank, return list of public sets, user-owned sets (if logged in) and user's recent session-bound
 * sets called by ubic.gemma.web.controller.genome.gene.GenePickerController.searchGenesAndGeneGroups(String, Long)
 * /*from  www. j  av  a 2 s.c om*/
 * @param taxonId
 * @return Collection<SearchResultDisplayObject>
 */
private Collection<SearchResultDisplayObject> searchGenesAndGeneGroupsBlankQuery(Long taxonId) {
    Taxon taxon = null;
    if (taxonId != null) {
        taxon = taxonService.load(taxonId);
        if (taxon == null) {
            log.warn("No such taxon with id=" + taxonId);
        }
    }

    // if query is blank, return list of auto generated sets, user-owned sets (if logged in) and user's recent
    // session-bound sets

    // right now, no public gene sets are useful so we don't want to prompt them
    boolean promptPublicSets = false;

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

    // get all public sets (if user is admin, these were already loaded with geneSetService.loadMySets() )
    // filtered by security.
    Collection<GeneSet> sets = new ArrayList<GeneSet>();
    if (promptPublicSets && !SecurityServiceImpl.isUserLoggedIn()) {
        try {
            sets = geneSetService.loadAll(taxon);
        } catch (AccessDeniedException e) {
            // okay, they just aren't allowed to see those.
        }
    } else if (SecurityServiceImpl.isUserLoggedIn()) {
        /*
         * actually, loadMyGeneSets and loadAll point to the same method (they just use different spring security
         * filters)
         */
        sets = (taxon != null) ? geneSetService.loadMyGeneSets(taxon) : geneSetService.loadMyGeneSets();
        log.info("Loading the user's gene sets took: " + watch.getTime());
    }

    // separate these out because they go at the top of the list
    List<SearchResultDisplayObject> displayResultsPrivate = new LinkedList<SearchResultDisplayObject>();
    List<SearchResultDisplayObject> displayResultsPublic = new LinkedList<SearchResultDisplayObject>();
    SearchResultDisplayObject newSRDO = null;
    for (GeneSet set : sets) {
        GeneSetValueObject gsvo = geneSetValueObjectHelper.convertToValueObject(set);
        newSRDO = new SearchResultDisplayObject(gsvo);
        newSRDO.setTaxonId(((GeneSetValueObject) newSRDO.getResultValueObject()).getTaxonId());
        newSRDO.setTaxonName(((GeneSetValueObject) newSRDO.getResultValueObject()).getTaxonName());
        boolean isPrivate = securityService.isPrivate(set);
        newSRDO.setUserOwned(isPrivate);
        ((GeneSetValueObject) newSRDO.getResultValueObject()).setIsPublic(!isPrivate);
        if (isPrivate) {
            displayResultsPrivate.add(newSRDO);
        } else {
            displayResultsPublic.add(newSRDO);
        }
    }

    // keep sets in proper order (user's groups first, then public ones)
    Collections.sort(displayResultsPrivate);
    Collections.sort(displayResultsPublic);

    List<SearchResultDisplayObject> displayResults = new LinkedList<SearchResultDisplayObject>();

    displayResults.addAll(displayResultsPrivate);
    displayResults.addAll(displayResultsPublic);

    if (displayResults.isEmpty()) {
        log.info(
                "No results for blank query search, taxon=" + ((taxon == null) ? null : taxon.getCommonName()));
        return new HashSet<SearchResultDisplayObject>();
    }
    log.info("Results for blank query search, size=" + displayResults.size());

    return displayResults;

}

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();/*from   w  w  w.ja va 2 s .  c o m*/
    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.expression.arrayDesign.ArrayDesignSequenceProcessingServiceImpl.java

/**
 * @param sequenceIdentifierFile with two columns: first is probe id, second is genbank accession.
 * @return//from   w w  w.  j a v a 2 s .  co  m
 * @throws IOException
 */
private Map<String, String> parseAccessionFile(InputStream sequenceIdentifierFile) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(sequenceIdentifierFile));

    String line = null;

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

    Map<String, String> probe2acc = new HashMap<String, String>();
    int count = 0;
    int totalLines = 0;
    while ((line = br.readLine()) != null) {
        String[] fields = line.split("\t");
        ++totalLines;
        if (fields.length < 2) {
            continue;
        }

        String probeName = fields[0];
        String seqAcc = fields[1];

        if (StringUtils.isBlank(seqAcc)) {
            continue;
        }

        probe2acc.put(probeName, seqAcc);
        if (++count % 2000 == 0 && timer.getTime() > 10000) {
            log.info(count + " / " + totalLines + " probes read so far have identifiers");
        }
    }
    br.close();
    log.info(count + " / " + totalLines + " probes have accessions");
    return probe2acc;

}

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

/**
 * @param dis/*  w w w.j av a 2s.c  om*/
 * @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;
}