Created
March 30, 2012 04:48
-
-
Save jmchilton/2246553 to your computer and use it in GitHub Desktop.
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
public Ratios computeRatios(final ITraqLabel numLabel, final ITraqLabel denLabel, final ReportSummary reportSummary, | |
final Function<Double, Double> weightFunction) { | |
final double[] ratios = new double[reportSummary.getNumProteins()], pValues = new double[reportSummary.getNumProteins()]; | |
int proteinNum = 0; | |
for(final String protein : reportSummary.getProteins()) { | |
final ProteinSummary proteinSummary = reportSummary.getProteinSummary(protein); | |
final double[] iRatio = new double[proteinSummary.getNumEntries()]; | |
final double[] num = proteinSummary.getIntensities(numLabel); | |
final double[] den = proteinSummary.getIntensities(denLabel); | |
double[] weights = proteinSummary.getLogIntensitiesProducts(); | |
if(weightFunction != null) { | |
final double[] modifiedWeights = new double[weights.length]; | |
for(int i = 0; i < weights.length; i++) { | |
modifiedWeights[i] = weightFunction.apply(weights[i]); | |
} | |
weights = modifiedWeights; | |
} | |
for(int i = 0; i < iRatio.length; i++) { | |
iRatio[i] = Math.log(num[i] / den[i]); | |
} | |
if(normalizeRatios) { | |
final double median = RUtils.median(iRatio); | |
for(int i = 0; i < iRatio.length; i++) { | |
iRatio[i] = iRatio[i] / median; | |
} | |
} | |
final double iRatioW1 = RUtils.weightedMean(iRatio, weights); | |
final double iRatioW = Math.exp(iRatioW1); | |
double pValue = 2.0; | |
if(iRatio.length > 2) { | |
pValue = RMethods.getWeightedPValue(iRatio, weights); | |
} | |
ratios[proteinNum] = iRatioW; | |
pValues[proteinNum] = pValue; | |
proteinNum++; | |
} | |
return new Ratios(ratios, pValues); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment