-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Clenaups for LinearModelAnalyzer"
This reverts commit 7935d5d.
- Loading branch information
Showing
25 changed files
with
1,772 additions
and
1,603 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
gemma-core/src/main/java/ubic/gemma/core/analysis/expression/diff/AbstractAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* The Gemma project | ||
* | ||
* Copyright (c) 2006 University of British Columbia | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package ubic.gemma.core.analysis.expression.diff; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import ubic.gemma.core.analysis.service.ExpressionDataMatrixService; | ||
import ubic.gemma.persistence.service.expression.designElement.CompositeSequenceService; | ||
|
||
/** | ||
* Analyzer base class. | ||
* | ||
* @author keshav | ||
*/ | ||
public abstract class AbstractAnalyzer { | ||
|
||
@Autowired | ||
protected ExpressionDataMatrixService expressionDataMatrixService = null; | ||
|
||
@Autowired | ||
protected CompositeSequenceService compositeSequenceService; | ||
|
||
@SuppressWarnings("unused") // needed for tests. | ||
public void setExpressionDataMatrixService( ExpressionDataMatrixService expressionDataMatrixService ) { | ||
this.expressionDataMatrixService = expressionDataMatrixService; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...java/ubic/gemma/core/analysis/expression/diff/AbstractDifferentialExpressionAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* The Gemma project | ||
* | ||
* Copyright (c) 2006-2010 University of British Columbia | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package ubic.gemma.core.analysis.expression.diff; | ||
|
||
import cern.colt.list.DoubleArrayList; | ||
import cern.colt.matrix.DoubleMatrix1D; | ||
import org.apache.commons.lang3.ArrayUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import ubic.basecode.dataStructure.matrix.DenseDoubleMatrix1D; | ||
import ubic.basecode.math.MultipleTestCorrection; | ||
import ubic.basecode.math.Rank; | ||
import ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix; | ||
import ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis; | ||
import ubic.gemma.model.expression.experiment.BioAssaySet; | ||
import ubic.gemma.model.expression.experiment.ExpressionExperiment; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
|
||
/** | ||
* An abstract differential expression analyzer to be extended | ||
* | ||
* @author keshav | ||
*/ | ||
public abstract class AbstractDifferentialExpressionAnalyzer extends AbstractAnalyzer implements DiffExAnalyzer { | ||
|
||
private final Log log = LogFactory.getLog( this.getClass() ); | ||
|
||
@Override | ||
public abstract Collection<DifferentialExpressionAnalysis> run( ExpressionExperiment expressionExperiment, | ||
DifferentialExpressionAnalysisConfig config ); | ||
|
||
@Override | ||
public abstract Collection<DifferentialExpressionAnalysis> run( ExpressionExperiment expressionExperiment, | ||
ExpressionDataDoubleMatrix dmatrix, DifferentialExpressionAnalysisConfig config ); | ||
|
||
/** | ||
* @param pvalues pvalues | ||
* @return normalized ranks of the pvalues, or null if they were invalid/unusable. | ||
*/ | ||
double[] computeRanks( double[] pvalues ) { | ||
if ( pvalues == null ) { | ||
log.error( "Null pvalues" ); | ||
return null; | ||
} | ||
if ( pvalues.length == 0 ) { | ||
log.error( "Empty pvalues array" ); | ||
return null; | ||
} | ||
|
||
DoubleArrayList ranks = Rank.rankTransform( new DoubleArrayList( pvalues ) ); | ||
|
||
if ( ranks == null ) { | ||
log.error( "Pvalue ranks could not be computed" ); | ||
return null; | ||
} | ||
|
||
double[] normalizedRanks = new double[ranks.size()]; | ||
for ( int i = 0; i < ranks.size(); i++ ) { | ||
normalizedRanks[i] = ranks.get( i ) / ranks.size(); | ||
} | ||
return normalizedRanks; | ||
} | ||
|
||
/** | ||
* @param pvalues pvalues | ||
* @return Qvalues, or null if they could not be computed. | ||
*/ | ||
@Nullable | ||
double[] benjaminiHochberg( Double[] pvalues ) { | ||
DoubleMatrix1D benjaminiHochberg = MultipleTestCorrection | ||
.benjaminiHochberg( new DenseDoubleMatrix1D( ArrayUtils.toPrimitive( pvalues ) ) ); | ||
return benjaminiHochberg != null ? benjaminiHochberg.toArray() : null; | ||
} | ||
|
||
DifferentialExpressionAnalysis initAnalysisEntity( BioAssaySet bioAssaySet, | ||
DifferentialExpressionAnalysisConfig config ) { | ||
|
||
if ( config == null ) { | ||
config = new DifferentialExpressionAnalysisConfig(); | ||
} | ||
DifferentialExpressionAnalysis expressionAnalysis = config.toAnalysis(); | ||
expressionAnalysis.setExperimentAnalyzed( bioAssaySet ); | ||
return expressionAnalysis; | ||
} | ||
|
||
/** | ||
* Needed to convert NaN or infinity values to a value we can store in the database. | ||
* | ||
* @param e e | ||
* @return converted | ||
*/ | ||
Double nan2Null( Double e ) { | ||
boolean isNaN = ( e == null || Double.isNaN( e ) || e == Double.NEGATIVE_INFINITY | ||
|| e == Double.POSITIVE_INFINITY ); | ||
if ( isNaN ) { | ||
return null; | ||
} | ||
return e; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
gemma-core/src/main/java/ubic/gemma/core/analysis/expression/diff/DiffExAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* The Gemma project | ||
* | ||
* Copyright (c) 2012 University of British Columbia | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package ubic.gemma.core.analysis.expression.diff; | ||
|
||
import ubic.gemma.core.analysis.service.ExpressionDataMatrixService; | ||
import ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix; | ||
import ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis; | ||
import ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult; | ||
import ubic.gemma.model.analysis.expression.diff.HitListSize; | ||
import ubic.gemma.model.common.quantitationtype.QuantitationType; | ||
import ubic.gemma.model.expression.designElement.CompositeSequence; | ||
import ubic.gemma.model.expression.experiment.ExperimentalFactor; | ||
import ubic.gemma.model.expression.experiment.ExpressionExperiment; | ||
import ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet; | ||
import ubic.gemma.model.genome.Gene; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author paul | ||
*/ | ||
@SuppressWarnings({ "unused", "WeakerAccess" }) // Possible external use | ||
public interface DiffExAnalyzer { | ||
|
||
ExperimentalFactor determineInterceptFactor( Collection<ExperimentalFactor> factors, | ||
QuantitationType quantitationType ); | ||
|
||
/** | ||
* @param expressionExperiment the experiment | ||
* @param config config | ||
* @return analyses. There will be more than one if a subset factor is defined. | ||
*/ | ||
Collection<DifferentialExpressionAnalysis> run( ExpressionExperiment expressionExperiment, | ||
DifferentialExpressionAnalysisConfig config ); | ||
|
||
/*** | ||
* Allows entry of modified data matrices into the workflow. | ||
* @param config config | ||
* @param expressionExperiment the experiment | ||
* @param dmatrix D matrix | ||
* @return analyses | ||
*/ | ||
Collection<DifferentialExpressionAnalysis> run( ExpressionExperiment expressionExperiment, | ||
ExpressionDataDoubleMatrix dmatrix, DifferentialExpressionAnalysisConfig config ); | ||
|
||
/** | ||
* Generate HitListSize entities that will be stored to count the number of diff. ex probes at various preset | ||
* thresholds, to avoid wasting time generating these counts on the fly later. This is done automatically during | ||
* analysis, so is just here to allow 'backfilling'. | ||
* | ||
* @param probeToGeneMap map | ||
* @param results results | ||
* @return hit list sizes | ||
*/ | ||
Set<HitListSize> computeHitListSizes( Collection<DifferentialExpressionAnalysisResult> results, | ||
Map<CompositeSequence, Collection<Gene>> probeToGeneMap ); | ||
|
||
/** | ||
* Utility method | ||
* | ||
* @param probeToGeneMap map | ||
* @param resultList result list | ||
* @return number of genes tested | ||
*/ | ||
int getNumberOfGenesTested( Collection<DifferentialExpressionAnalysisResult> resultList, | ||
Map<CompositeSequence, Collection<Gene>> probeToGeneMap ); | ||
|
||
/** | ||
* this is needed so we can alter this in tests | ||
* | ||
* @param expressionDataMatrixService EE data matrix service | ||
*/ | ||
void setExpressionDataMatrixService( ExpressionDataMatrixService expressionDataMatrixService ); | ||
|
||
/** | ||
* Note that normally when we run a subset analysis, the subsetting is done internally, so we pass in the expression | ||
* experiment, not the subset. This method is used for exceptions to that. | ||
* | ||
* @param subset subset | ||
* @param config config | ||
* @return analysis | ||
*/ | ||
DifferentialExpressionAnalysis run( ExpressionExperimentSubSet subset, | ||
DifferentialExpressionAnalysisConfig config ); | ||
|
||
} |
Oops, something went wrong.