Example usage for org.apache.commons.collections TransformerUtils invokerTransformer

List of usage examples for org.apache.commons.collections TransformerUtils invokerTransformer

Introduction

In this page you can find the example usage for org.apache.commons.collections TransformerUtils invokerTransformer.

Prototype

public static Transformer invokerTransformer(String methodName) 

Source Link

Document

Gets a Transformer that invokes a method on the input object.

Usage

From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java

@Test
public void shouldFindAllDependantReportsForDataSource() {
    assertNotNull("RepositoryService service is not wired.", getRepositoryService());
    assertNotNull("SearchCriteriaFactory service is not wired.", searchCriteriaFactory);

    String uri = "/datasources/JServerJNDIDS";

    List<ResourceLookup> resources = getRepositoryService().getDependentResources(null, uri,
            searchCriteriaFactory, 0, 20);

    assertEquals("Should find 9 dependant resources.", 9, resources.size());

    assertEquals("All resources should be lookup's.", 9,
            CollectionUtils.countMatches(resources, PredicateUtils.instanceofPredicate(ResourceLookup.class)));

    Collection types = CollectionUtils.collect(resources,
            TransformerUtils.invokerTransformer("getResourceType"));

    assertEquals("All lookup's should have type ReportUnit.", 9,
            CollectionUtils.countMatches(types, PredicateUtils.equalPredicate(
                    "com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit")));

    String sortOrder = ArrayUtils.toString(
            CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getURIString")).toArray());

    assertEquals("Resources should be sorted in order.", expectedOrder, sortOrder);
}

From source file:com.jaspersoft.jasperserver.repository.test.RepositoryServiceDependentResourcesTest.java

@Test
public void shouldFindFirstFiveDependantReportsForDataSource() {
    assertNotNull("RepositoryService service is not wired.", getRepositoryService());
    assertNotNull("SearchCriteriaFactory service is not wired.", searchCriteriaFactory);

    String uri = "/datasources/JServerJNDIDS";

    List<ResourceLookup> resources = getRepositoryService().getDependentResources(null, uri,
            searchCriteriaFactory, 0, 5);

    assertEquals("Should find 5 dependant resources.", 5, resources.size());

    assertEquals("All resources should be lookup's.", 5,
            CollectionUtils.countMatches(resources, PredicateUtils.instanceofPredicate(ResourceLookup.class)));

    String sortOrder = ArrayUtils.toString(
            CollectionUtils.collect(resources, TransformerUtils.invokerTransformer("getURIString")).toArray());

    assertEquals("Resources should be sorted in order.", expectedOrderForTopFive, sortOrder);

}

From source file:org.openmrs.module.pharmacyapi.api.prescription.validation.PrescriptionItemRule.java

@SuppressWarnings("unchecked")
private void checkAllArvItemHaveUniqueRegimen(final Prescription prescription,
        final List<PrescriptionItem> prescriptionItems) throws PharmacyBusinessException {

    final DrugRegimeService drugRegimeService = Context.getService(DrugRegimeService.class);

    final Concept regimen = prescription.getRegime();

    if (regimen != null) {

        final Collection<Concept> itemsRegimens = new ArrayList<>();

        for (final PrescriptionItem prescriptionItem : prescriptionItems) {

            final Drug drug = Context.getConceptService()
                    .getDrugByUuid(prescriptionItem.getDrugOrder().getDrug().getUuid());
            final List<DrugRegime> drugRegimens = drugRegimeService.findDrugRegimeByDrugUuid(drug.getUuid());

            final Collection<Concept> regimens = CollectionUtils.collect(drugRegimens,
                    TransformerUtils.invokerTransformer("getRegime"));

            if (!regimens.isEmpty() && !regimens.contains(regimen)) {
                final Collection<String> regimeNames = CollectionUtils.collect(regimens,
                        TransformerUtils.invokerTransformer("getDisplayString"));
                throw new PharmacyBusinessException("Nao foi encontrada correspondencia entre os regimes "
                        + StringUtils.join(regimeNames, "|") + " do medicamento " + drug.getDisplayName()
                        + " e o regime " + regimen.getDisplayString() + " informado");
            }/*from   w w  w.  j  av  a2s . c  o m*/
            itemsRegimens.addAll(regimens);
        }

        if (itemsRegimens.isEmpty()) {
            throw new PharmacyBusinessException("Nao pode ser criada Prescricao ARV para medicamentos nao ARV");
        }
    }
}

From source file:org.openmrs.module.pharmacyapi.api.service.dispensationservice.DispensationServiceTest.java

@SuppressWarnings("unchecked")
@Test/*from w ww .  jav  a 2s  . c  o  m*/
public void shouldDispenseOrdersForNonArvPrescription() throws Exception {
    this.executeDataSet("dispensationservice/shouldDispenseOrdersForNonArvPrescription-dataset.xml");

    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2005);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    final Dispensation dispensation = new Dispensation();
    dispensation.setPatientUuid("5946f880-b197-400b-9caa-a3c661d23041");
    dispensation.setLocationUuid("8d6c993e-c2cc-11de-8d13-0010c6dffd0f");
    dispensation.setProviderUuid("ba1b19c2-3ed6-4f63-b8c0-f762dc8d7562");
    dispensation.setDispensationDate(calendar.getTime());
    final DispensationItem dispensationItem = new DispensationItem();
    dispensationItem.setQuantityDispensed(0d);
    dispensationItem.setQuantityToDispense(3d);

    final String orderUuid = "921de0a3-05c4-444a-be03-0001";
    final String encounterPrescriptionUuid = "eec646cb-c847-4ss-enc-who-adult";

    dispensationItem.setOrderUuid(orderUuid);
    dispensationItem.setPrescriptionUuid(encounterPrescriptionUuid);
    dispensation.setDispensationItems(Arrays.asList(dispensationItem));

    final Dispensation createdDispensation = Context.getService(DispensationService.class)
            .dispense(dispensation);

    Assert.assertNotNull(createdDispensation);

    final List<PrescriptionDispensation> prescriptionDispensations = Context
            .getService(PrescriptionDispensationService.class)
            .findPrescriptionDispensationByPrescription(new Encounter(1000));

    Assert.assertTrue(!prescriptionDispensations.isEmpty());
    Assert.assertEquals(1, prescriptionDispensations.size());

    final PrescriptionDispensation prescriptionDispensation = prescriptionDispensations.iterator().next();
    final Encounter dispensationEncounter = prescriptionDispensation.getDispensation();

    Assert.assertEquals(MappedEncounters.DISPENSATION_ENCOUNTER_TYPE,
            dispensationEncounter.getEncounterType().getUuid());

    final List<Obs> observations = Context.getObsService().getObservations(null,
            Arrays.asList(dispensationEncounter), null, null, null, null, null, null, null, null, null, false);

    MatcherAssert.assertThat(observations, IsCollectionWithSize.hasSize(3));

    final Collection<Concept> concepts = CollectionUtils.collect(observations,
            TransformerUtils.invokerTransformer("getConcept"));
    final Collection<String> uuids = CollectionUtils.collect(concepts,
            TransformerUtils.invokerTransformer("getUuid"));

    MatcherAssert.assertThat(uuids, Matchers.hasItems(MappedConcepts.DISPENSATION_SET,
            MappedConcepts.MEDICATION_QUANTITY, MappedConcepts.DATE_OF_NEXT_PICK_UP));
}

From source file:org.openmrs.module.pharmacyapi.api.service.dispensationservice.DispensationServiceTest.java

@SuppressWarnings("unchecked")
@Test//from w ww.  j av a  2s.  c om
public void shouldDispenseOrdersForArvPrescription() throws Exception {
    this.executeDataSet("dispensationservice/shouldDispenseOrdersForArvPrescription-dataset.xml");

    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2005);
    calendar.set(Calendar.MONTH, 0);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    final Dispensation dispensation = new Dispensation();
    dispensation.setPatientUuid("5946f880-b197-400b-9caa-a3c661d23041");
    dispensation.setLocationUuid("8d6c993e-c2cc-11de-8d13-0010c6dffd0f");
    dispensation.setProviderUuid("ba1b19c2-3ed6-4f63-b8c0-f762dc8d7562");
    dispensation.setDispensationDate(calendar.getTime());
    final DispensationItem dispensationItem = new DispensationItem();
    dispensationItem.setQuantityDispensed(0d);
    dispensationItem.setQuantityToDispense(3d);

    final String orderUuid = "921de0a3-05c4-444a-be03-0001";
    final String encounterPrescriptionUuid = "eec646cb-c847-4ss-enc-who-adult";

    dispensationItem.setOrderUuid(orderUuid);
    dispensationItem.setRegimeUuid("9dc17c1b-7b6d-488e-a38d-505a7b6xxx1");
    dispensationItem.setPrescriptionUuid(encounterPrescriptionUuid);
    dispensation.setDispensationItems(Arrays.asList(dispensationItem));

    final Dispensation createdDispensation = Context.getService(DispensationService.class)
            .dispense(dispensation);

    Assert.assertNotNull(createdDispensation);

    final List<PrescriptionDispensation> prescriptionDispensations = Context
            .getService(PrescriptionDispensationService.class)
            .findPrescriptionDispensationByPrescription(new Encounter(1000));

    Assert.assertTrue(!prescriptionDispensations.isEmpty());
    Assert.assertEquals(1, prescriptionDispensations.size());

    final PrescriptionDispensation prescriptionDispensation = prescriptionDispensations.iterator().next();
    final Encounter dispensationEncounter = prescriptionDispensation.getDispensation();

    Assert.assertEquals(MappedEncounters.DISPENSATION_ENCOUNTER_TYPE,
            dispensationEncounter.getEncounterType().getUuid());

    final List<Obs> observations = Context.getObsService().getObservations(null,
            Arrays.asList(dispensationEncounter), null, null, null, null, null, null, null, null, null, false);

    MatcherAssert.assertThat(observations, IsCollectionWithSize.hasSize(4));

    final Collection<Concept> concepts = CollectionUtils.collect(observations,
            TransformerUtils.invokerTransformer("getConcept"));
    final Collection<String> uuids = CollectionUtils.collect(concepts,
            TransformerUtils.invokerTransformer("getUuid"));

    MatcherAssert.assertThat(uuids,
            Matchers.hasItems(MappedConcepts.DISPENSATION_SET, MappedConcepts.MEDICATION_QUANTITY,
                    MappedConcepts.DATE_OF_NEXT_PICK_UP, MappedConcepts.PREVIOUS_ANTIRETROVIRAL_DRUGS));

}

From source file:ubic.gemma.analysis.expression.diff.LinearModelAnalyzer.java

/**
 * @param bioAssaySet source data//from   w  ww.ja v a  2 s .  c o  m
 * @param config
 * @param dmatrix data
 * @param samplesUsed analyzed
 * @param factors included in the model
 * @param subsetFactorValue null unless analyzing a subset (only used for book-keeping)
 * @return analysis, or null if there was a problem.
 */
private DifferentialExpressionAnalysis doAnalysis(BioAssaySet bioAssaySet,
        DifferentialExpressionAnalysisConfig config, ExpressionDataDoubleMatrix dmatrix,
        List<BioMaterial> samplesUsed, List<ExperimentalFactor> factors, FactorValue subsetFactorValue) {

    if (factors.isEmpty()) {
        log.error("Must provide at least one factor");
        return null;
    }

    if (samplesUsed.size() <= factors.size()) {
        log.error("Must have more samples than factors");
        return null;
    }

    final Map<String, Collection<ExperimentalFactor>> label2Factors = getRNames(factors);

    Map<ExperimentalFactor, FactorValue> baselineConditions = ExperimentalDesignUtils
            .getBaselineConditions(samplesUsed, factors);

    QuantitationType quantitationType = dmatrix.getQuantitationTypes().iterator().next();

    ExperimentalFactor interceptFactor = determineInterceptFactor(factors, quantitationType);

    /*
     * Build our factor terms, with interactions handled specially
     */
    List<String[]> interactionFactorLists = new ArrayList<String[]>();
    ObjectMatrix<String, String, Object> designMatrix = ExperimentalDesignUtils.buildDesignMatrix(factors,
            samplesUsed, baselineConditions);

    setupFactors(designMatrix, baselineConditions);

    String modelFormula = "";
    boolean oneSampleTtest = interceptFactor != null && factors.size() == 1;
    if (oneSampleTtest) {
        modelFormula = " ";
    } else {
        modelFormula = buildModelFormula(config, label2Factors, interceptFactor, interactionFactorLists);
    }

    dmatrix = filterAndLogTransform(quantitationType, dmatrix);
    DoubleMatrix<CompositeSequence, BioMaterial> namedMatrix = dmatrix.getMatrix();

    if (log.isDebugEnabled())
        outputForDebugging(dmatrix, designMatrix);

    /*
     * PREPARATION FOR 'NATIVE' FITTING
     */
    DoubleMatrix<String, String> sNamedMatrix = makeDataMatrix(designMatrix, namedMatrix);
    DesignMatrix properDesignMatrix = makeDesignMatrix(designMatrix, interactionFactorLists,
            baselineConditions);

    /*
     * Run the analysis NOTE this can be simplified if we strip out R code.
     */
    final Map<String, LinearModelSummary> rawResults = runAnalysis(namedMatrix, sNamedMatrix, label2Factors,
            modelFormula, properDesignMatrix, interceptFactor, interactionFactorLists, baselineConditions,
            quantitationType);

    if (rawResults.size() == 0) {
        log.error("Got no results from the analysis");
        return null;
    }

    /*
     * Initialize data structures we need to hold results
     */

    // this used to be a Set, but a List is much faster.
    Map<String, List<DifferentialExpressionAnalysisResult>> resultLists = new HashMap<String, List<DifferentialExpressionAnalysisResult>>();
    Map<String, List<Double>> pvaluesForQvalue = new HashMap<String, List<Double>>();
    for (String factorName : label2Factors.keySet()) {
        if (properDesignMatrix.getDroppedFactors().contains(factorName)) {
            continue;
        }
        resultLists.put(factorName, new ArrayList<DifferentialExpressionAnalysisResult>());
        pvaluesForQvalue.put(factorName, new ArrayList<Double>());
    }
    addinteraction: for (String[] fs : interactionFactorLists) {
        for (String f : fs) {
            if (properDesignMatrix.getDroppedFactors().contains(f)) {
                continue addinteraction;
            }
        }
        String intF = StringUtils.join(fs, ":");
        resultLists.put(intF, new ArrayList<DifferentialExpressionAnalysisResult>());
        pvaluesForQvalue.put(intF, new ArrayList<Double>());
    }

    if (pvaluesForQvalue.isEmpty()) {
        log.warn(
                "No results were obtained for the current stage of analysis, possibly due to dropped factors.");
        return null;
    }

    /*
     * Create result objects for each model fit. Keeping things in order is important.
     */
    final Transformer rowNameExtractor = TransformerUtils.invokerTransformer("getId");
    boolean warned = false;
    int notUsable = 0;
    int processed = 0;
    for (CompositeSequence el : namedMatrix.getRowNames()) {

        if (++processed % 15000 == 0) {
            log.info("Processed results for " + processed + " elements ...");
        }

        LinearModelSummary lm = rawResults.get(rowNameExtractor.transform(el).toString());

        if (log.isDebugEnabled())
            log.debug(el.getName() + "\n" + lm);

        if (lm == null) {
            if (!warned) {
                log.warn("No result for " + el + ", further warnings suppressed");
                warned = true;
            }
            notUsable++;
            continue;
        }

        for (String factorName : label2Factors.keySet()) {

            if (!pvaluesForQvalue.containsKey(factorName)) {
                // was dropped.
                continue;
            }

            Double overallPValue = null;
            DifferentialExpressionAnalysisResult probeAnalysisResult = DifferentialExpressionAnalysisResult.Factory
                    .newInstance();
            probeAnalysisResult.setProbe(el);

            if (lm.getCoefficients() == null) {
                // probeAnalysisResult.setPvalue( null );
                // pvaluesForQvalue.get( factorName ).add( overallPValue );
                // resultLists.get( factorName ).add( probeAnalysisResult );
                notUsable++;
                continue;
            }

            Collection<ExperimentalFactor> factorsForName = label2Factors.get(factorName);

            if (factorsForName.size() > 1) {
                /*
                 * Interactions
                 */
                if (factorsForName.size() > 2) {
                    log.error("Handling more than two-way interactions is not implemented");
                    return null;
                }

                assert factorName.contains(":");
                String[] factorNames = StringUtils.split(factorName, ":");
                assert factorNames.length == factorsForName.size();
                overallPValue = lm.getInteractionEffectP(factorNames);

                if (overallPValue != null && !Double.isNaN(overallPValue)) {

                    Map<String, Double> interactionContrastTStats = lm.getContrastTStats(factorName);
                    Map<String, Double> interactionContrastCoeffs = lm.getContrastCoefficients(factorName);
                    Map<String, Double> interactionContrastPValues = lm.getContrastPValues(factorName);

                    for (String term : interactionContrastPValues.keySet()) {
                        Double contrastPvalue = interactionContrastPValues.get(term);

                        makeContrast(probeAnalysisResult, factorsForName, term, factorName, contrastPvalue,
                                interactionContrastTStats, interactionContrastCoeffs);

                    }
                } else {
                    if (!warned) {
                        log.warn("Interaction could not be computed for " + el
                                + ", further warnings suppressed");
                        warned = true;
                    }

                    if (log.isDebugEnabled())
                        log.debug("Interaction could not be computed for " + el
                                + ", further warnings suppressed");

                    notUsable++; // will over count?
                    continue;
                }

            } else {

                /*
                 * Main effect
                 */

                assert factorsForName.size() == 1;
                ExperimentalFactor experimentalFactor = factorsForName.iterator().next();

                if (interceptFactor != null && factorsForName.size() == 1
                        && experimentalFactor.equals(interceptFactor)) {
                    overallPValue = lm.getInterceptP();
                } else {
                    overallPValue = lm.getMainEffectP(factorName);
                }

                /*
                 * Add contrasts unless overallpvalue is NaN
                 */
                if (overallPValue != null && !Double.isNaN(overallPValue)) {

                    Map<String, Double> mainEffectContrastTStats = lm.getContrastTStats(factorName);
                    Map<String, Double> mainEffectContrastPvalues = lm.getContrastPValues(factorName);
                    Map<String, Double> mainEffectContrastCoeffs = lm.getContrastCoefficients(factorName);

                    for (String term : mainEffectContrastPvalues.keySet()) {

                        Double contrastPvalue = mainEffectContrastPvalues.get(term);

                        makeContrast(probeAnalysisResult, factorsForName, term, factorName, contrastPvalue,
                                mainEffectContrastTStats, mainEffectContrastCoeffs);

                    }
                } else {
                    if (!warned) {
                        log.warn("ANOVA could not be done for " + experimentalFactor + " on " + el
                                + ", further warnings suppressed");
                        warned = true;
                    }

                    if (log.isDebugEnabled())
                        log.debug("ANOVA could not be done for " + experimentalFactor + " on " + el);

                    notUsable++; // will over count?
                    continue;
                }
            }

            assert !Double.isNaN(overallPValue) : "We should not be keeping non-number pvalues (null or NaNs)";

            probeAnalysisResult.setPvalue(nan2Null(overallPValue));
            pvaluesForQvalue.get(factorName).add(overallPValue);
            resultLists.get(factorName).add(probeAnalysisResult);
        } // over terms

    } // over probes

    if (notUsable > 0) {
        log.info(notUsable + " elements or results were not usable - model could not be fit, etc.");
    }

    getRanksAndQvalues(resultLists, pvaluesForQvalue);

    DifferentialExpressionAnalysis expressionAnalysis = makeAnalysisEntity(bioAssaySet, config, label2Factors,
            baselineConditions, interceptFactor, interactionFactorLists, oneSampleTtest, resultLists,
            subsetFactorValue);

    log.info("Analysis processing phase done ...");

    return expressionAnalysis;
}

From source file:ubic.gemma.core.analysis.expression.diff.LinearModelAnalyzer.java

/**
 * @param bioAssaySet       source data, could be a SubSet
 * @param dmatrix           data (for the subset, if it's a subset)
 * @param samplesUsed       analyzed/*from  www.j av  a 2 s .co  m*/
 * @param factors           included in the model
 * @param subsetFactorValue null unless analyzing a subset (only used for book-keeping)
 * @return analysis, or null if there was a problem.
 */
private DifferentialExpressionAnalysis doAnalysis(BioAssaySet bioAssaySet,
        DifferentialExpressionAnalysisConfig config, ExpressionDataDoubleMatrix dmatrix,
        List<BioMaterial> samplesUsed, List<ExperimentalFactor> factors, FactorValue subsetFactorValue) {

    // We may want to change this to fall back to running normally, though the real fix is to just finish the ebayes implementation.
    if (config.getModerateStatistics() && dmatrix.hasMissingValues()) {
        throw new UnsupportedOperationException(
                "Ebayes cannot be used when there are values missing in the data");
    }

    if (factors.isEmpty()) {
        LinearModelAnalyzer.log.error("Must provide at least one factor");
        return null;
    }

    if (samplesUsed.size() <= factors.size()) {
        LinearModelAnalyzer.log.error("Must have more samples than factors");
        return null;
    }

    final Map<String, Collection<ExperimentalFactor>> label2Factors = this.getRNames(factors);

    Map<ExperimentalFactor, FactorValue> baselineConditions = ExperimentalDesignUtils
            .getBaselineConditions(samplesUsed, factors);

    this.dropIncompleteFactors(samplesUsed, factors, baselineConditions);

    if (factors.isEmpty()) {
        LinearModelAnalyzer.log
                .error("Must provide at least one factor; they were all removed due to incomplete values");
        return null;
    }

    QuantitationType quantitationType = dmatrix.getQuantitationTypes().iterator().next();

    ExperimentalFactor interceptFactor = this.determineInterceptFactor(factors, quantitationType);

    /*
     * Build our factor terms, with interactions handled specially
     */
    List<String[]> interactionFactorLists = new ArrayList<>();
    ObjectMatrix<String, String, Object> designMatrix = ExperimentalDesignUtils.buildDesignMatrix(factors,
            samplesUsed, baselineConditions);

    config.setBaseLineFactorValues(baselineConditions);

    boolean oneSampleTTest = interceptFactor != null && factors.size() == 1;
    if (!oneSampleTTest) {
        this.buildModelFormula(config, label2Factors, interactionFactorLists);
    }

    /*
     * FIXME: remove columns that are marked as outliers.
     */
    dmatrix = ExpressionDataDoubleMatrixUtil.filterAndLog2Transform(quantitationType, dmatrix);
    DoubleMatrix<CompositeSequence, BioMaterial> namedMatrix = dmatrix.getMatrix();

    DoubleMatrix1D librarySize = getLibrarySizes(config, dmatrix);

    if (LinearModelAnalyzer.log.isDebugEnabled())
        this.outputForDebugging(dmatrix, designMatrix);

    /*
     * PREPARATION FOR 'NATIVE' FITTING
     */
    DoubleMatrix<String, String> sNamedMatrix = LinearModelAnalyzer.makeDataMatrix(designMatrix, namedMatrix);
    DesignMatrix properDesignMatrix = this.makeDesignMatrix(designMatrix, interactionFactorLists,
            baselineConditions);

    /*
     * Run the analysis NOTE this can be simplified if we strip out R code.
     */
    final Map<String, LinearModelSummary> rawResults = this.runAnalysis(namedMatrix, sNamedMatrix,
            properDesignMatrix, librarySize, config);

    if (rawResults.size() == 0) {
        LinearModelAnalyzer.log.error("Got no results from the analysis");
        return null;
    }

    /*
     * Initialize data structures we need to hold results.
     */

    // this used to be a Set, but a List is much faster.
    Map<String, List<DifferentialExpressionAnalysisResult>> resultLists = new HashMap<>();
    Map<String, List<Double>> pvaluesForQvalue = new HashMap<>();

    for (String factorName : label2Factors.keySet()) {
        resultLists.put(factorName, new ArrayList<DifferentialExpressionAnalysisResult>());
        pvaluesForQvalue.put(factorName, new ArrayList<Double>());
    }

    for (String[] fs : interactionFactorLists) {
        String intF = StringUtils.join(fs, ":");
        resultLists.put(intF, new ArrayList<DifferentialExpressionAnalysisResult>());
        pvaluesForQvalue.put(intF, new ArrayList<Double>());
    }

    if (pvaluesForQvalue.isEmpty()) {
        LinearModelAnalyzer.log.warn("No results were obtained for the current stage of analysis.");
        return null;
    }

    /*
     * Create result objects for each model fit. Keeping things in order is important.
     */
    final Transformer rowNameExtractor = TransformerUtils.invokerTransformer("getId");
    boolean warned = false;
    int notUsable = 0;
    int processed = 0;
    for (CompositeSequence el : namedMatrix.getRowNames()) {

        if (++processed % 15000 == 0) {
            LinearModelAnalyzer.log.info("Processed results for " + processed + " elements ...");
        }

        LinearModelSummary lm = rawResults.get(rowNameExtractor.transform(el).toString());

        if (LinearModelAnalyzer.log.isDebugEnabled())
            LinearModelAnalyzer.log.debug(el.getName() + "\n" + lm);

        if (lm == null) {
            if (!warned) {
                LinearModelAnalyzer.log.warn("No result for " + el + ", further warnings suppressed");
                warned = true;
            }
            notUsable++;
            continue;
        }

        for (String factorName : label2Factors.keySet()) {

            if (!pvaluesForQvalue.containsKey(factorName)) {
                // was dropped.
                continue;
            }

            Double overallPValue;
            DifferentialExpressionAnalysisResult probeAnalysisResult = DifferentialExpressionAnalysisResult.Factory
                    .newInstance();
            probeAnalysisResult.setProbe(el);

            if (lm.getCoefficients() == null) {
                // probeAnalysisResult.setPvalue( null );
                // pvaluesForQvalue.get( factorName ).add( overallPValue );
                // resultLists.get( factorName ).add( probeAnalysisResult );
                notUsable++;
                continue;
            }

            Collection<ExperimentalFactor> factorsForName = label2Factors.get(factorName);

            if (factorsForName.size() > 1) {
                /*
                 * Interactions
                 */
                if (factorsForName.size() > 2) {
                    LinearModelAnalyzer.log.error("Handling more than two-way interactions is not implemented");
                    return null;
                }

                assert factorName.contains(":");
                String[] factorNames = StringUtils.split(factorName, ":");
                assert factorNames.length == factorsForName.size();
                overallPValue = lm.getInteractionEffectP(factorNames);

                if (overallPValue != null && !Double.isNaN(overallPValue)) {

                    Map<String, Double> interactionContrastTStats = lm.getContrastTStats(factorName);
                    Map<String, Double> interactionContrastCoeffs = lm.getContrastCoefficients(factorName);
                    Map<String, Double> interactionContrastPValues = lm.getContrastPValues(factorName);

                    for (String term : interactionContrastPValues.keySet()) {
                        Double contrastPvalue = interactionContrastPValues.get(term);

                        this.makeContrast(probeAnalysisResult, factorsForName, term, factorName, contrastPvalue,
                                interactionContrastTStats, interactionContrastCoeffs);

                    }
                } else {
                    if (!warned) {
                        LinearModelAnalyzer.log.warn("Interaction could not be computed for " + el
                                + ", further warnings suppressed");
                        warned = true;
                    }

                    if (LinearModelAnalyzer.log.isDebugEnabled())
                        LinearModelAnalyzer.log.debug("Interaction could not be computed for " + el
                                + ", further warnings suppressed");

                    notUsable++; // will over count?
                    continue;
                }

            } else {

                /*
                 * Main effect
                 */
                assert factorsForName.size() == 1;
                ExperimentalFactor experimentalFactor = factorsForName.iterator().next();

                if (factorsForName.size() == 1 && experimentalFactor.equals(interceptFactor)) {
                    overallPValue = lm.getInterceptP();
                } else {
                    overallPValue = lm.getMainEffectP(factorName);
                }

                /*
                 * Add contrasts unless overall pvalue is NaN
                 */
                if (overallPValue != null && !Double.isNaN(overallPValue)) {

                    Map<String, Double> mainEffectContrastTStats = lm.getContrastTStats(factorName);
                    Map<String, Double> mainEffectContrastPvalues = lm.getContrastPValues(factorName);
                    Map<String, Double> mainEffectContrastCoeffs = lm.getContrastCoefficients(factorName);

                    for (String term : mainEffectContrastPvalues.keySet()) {

                        Double contrastPvalue = mainEffectContrastPvalues.get(term);

                        this.makeContrast(probeAnalysisResult, factorsForName, term, factorName, contrastPvalue,
                                mainEffectContrastTStats, mainEffectContrastCoeffs);

                    }
                } else {
                    if (!warned) {
                        LinearModelAnalyzer.log.warn("ANOVA could not be done for " + experimentalFactor
                                + " on " + el + ", further warnings suppressed");
                        warned = true;
                    }

                    if (LinearModelAnalyzer.log.isDebugEnabled())
                        LinearModelAnalyzer.log
                                .debug("ANOVA could not be done for " + experimentalFactor + " on " + el);

                    notUsable++; // will over count?
                    continue;
                }
            }

            assert !Double.isNaN(overallPValue) : "We should not be keeping non-number pvalues (null or NaNs)";

            probeAnalysisResult.setPvalue(this.nan2Null(overallPValue));
            pvaluesForQvalue.get(factorName).add(overallPValue);
            resultLists.get(factorName).add(probeAnalysisResult);
        } // over terms

    } // over probes

    if (notUsable > 0) {
        LinearModelAnalyzer.log
                .info(notUsable + " elements or results were not usable - model could not be fit, etc.");
    }

    this.getRanksAndQvalues(resultLists, pvaluesForQvalue);

    DifferentialExpressionAnalysis expressionAnalysis = this.makeAnalysisEntity(bioAssaySet, config,
            label2Factors, baselineConditions, interceptFactor, interactionFactorLists, oneSampleTTest,
            resultLists, subsetFactorValue);

    LinearModelAnalyzer.log.info("Analysis processing phase done ...");

    return expressionAnalysis;
}