Example usage for org.apache.commons.lang StringUtils chomp

List of usage examples for org.apache.commons.lang StringUtils chomp

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils chomp.

Prototype

public static String chomp(String str, String separator) 

Source Link

Document

Removes separator from the end of str if it's there, otherwise leave it alone.

Usage

From source file:ubic.gemma.analysis.service.ExpressionDataFileServiceImpl.java

@Override
public List<DifferentialExpressionAnalysisResult> analysisResultSetToString(ExpressionAnalysisResultSet ears,
        Map<Long, String[]> geneAnnotations, StringBuilder buf, Map<Long, StringBuilder> probe2String,
        List<DifferentialExpressionAnalysisResult> sortedFirstColumnOfResults) {

    if (sortedFirstColumnOfResults == null) { // Sort P values in ears (because 1st column)
        sortedFirstColumnOfResults = new ArrayList<DifferentialExpressionAnalysisResult>(ears.getResults());
        Collections.sort(sortedFirstColumnOfResults,
                DifferentialExpressionAnalysisResultComparator.Factory.newInstance());
    }/* www.j av a  2 s. c o  m*/

    // Generate a description of the factors involved "(factor1:factor2: .... :factorN)"
    String factorColumnName = "(";
    for (ExperimentalFactor ef : ears.getExperimentalFactors()) {
        factorColumnName += ef.getName() + ":";
    }
    factorColumnName = StringUtils.chomp(factorColumnName, ":") + ")";

    // Generate headers
    buf.append("\tQValue" + factorColumnName);
    buf.append("\tPValue" + factorColumnName);

    // Generate probe details
    for (DifferentialExpressionAnalysisResult dear : ears.getResults()) {
        StringBuilder probeBuffer = new StringBuilder();

        CompositeSequence cs = dear.getProbe();

        // Make a hashmap so we can organize the data by probe with factors as colums
        // Need to cache the information untill we have it organized in the correct format to write
        Long csid = cs.getId();
        if (probe2String.containsKey(csid)) {
            probeBuffer = probe2String.get(csid);
        } else {// no entry for probe yet
            probeBuffer.append(cs.getName());
            if (geneAnnotations.containsKey(csid)) {
                String[] annotationStrings = geneAnnotations.get(csid);
                probeBuffer.append("\t" + annotationStrings[1] + "\t" + annotationStrings[2]);

                // leaving out Gemma ID, which is annotationStrings[3]
                if (annotationStrings.length > 4) {
                    // ncbi id.
                    probeBuffer.append("\t" + annotationStrings[4]);
                }
            }

            probe2String.put(csid, probeBuffer);
        }

        Double correctedPvalue = dear.getCorrectedPvalue();
        Double pvalue = dear.getPvalue();

        String formattedCP = correctedPvalue == null ? "" : String.format(DECIMAL_FORMAT, correctedPvalue);
        String formattedP = pvalue == null ? "" : String.format(DECIMAL_FORMAT, pvalue);
        probeBuffer.append("\t" + formattedCP + "\t" + formattedP);

    } // ears.getResults loop
    return sortedFirstColumnOfResults;
}