Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fb bilinear regression fit #752

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/org/labkey/targetedms/TargetedMSModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.labkey.panoramapremium.PanoramaPremiumController;
import org.labkey.panoramapremium.QCNotificationSender;
import org.labkey.panoramapremium.View.QCSummaryMenuCustomizer;
import org.labkey.targetedms.calculations.quantification.RegressionFit;
import org.labkey.targetedms.chart.ComparisonCategory;
import org.labkey.targetedms.chart.ReplicateLabelMinimizer;
import org.labkey.targetedms.datasource.MsDataSourceUtil;
Expand Down Expand Up @@ -667,7 +668,7 @@ public Set<Class> getUnitTests()
TargetedMSController.TestCase.class,
PrecursorManager.TestCase.class,
CrossLinkedPeptideInfo.TestCase.class,
Protein.TestCase.class
RegressionFit.TestCase.class
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@
*/
package org.labkey.targetedms.calculations.quantification;

public class CalibrationCurve {
import org.jetbrains.annotations.Nullable;

public class CalibrationCurve implements Cloneable {
private Double slope;
private Double intercept;
private Double turningPoint;
private Integer pointCount;
private Double quadraticCoefficient;
private Double rSquared;
private String errorMessage;
private RegressionFit regressionFit;

public CalibrationCurve(RegressionFit regressionFit) {
this.regressionFit = regressionFit;
}

public double getSlope() {
return slope == null ? 0 : slope;
Expand All @@ -38,13 +46,25 @@ public double getIntercept() {
return intercept == null ? 0 : intercept;
}


public boolean hasIntercept() {
return intercept != null;
}

public void setIntercept(Double intercept) {
this.intercept = intercept;
}
public double getTurningPoint()
{
return turningPoint == null ? 0 : turningPoint;
}
public boolean hasTurningPoint() {
return turningPoint != null;
}
public void setTurningPoint(Double turningPoint)
{
this.turningPoint = turningPoint;
}

public int getPointCount() {
return pointCount == null ? 0 : pointCount;
Expand Down Expand Up @@ -88,30 +108,25 @@ public void setErrorMessage(String errorMessage) {

public Double getY(double x)
{
if (hasQuadraticCoefficient())
{
return x*x*getQuadraticCoefficient() + x*getSlope() + getIntercept();
}
return x*getSlope() + getIntercept();
return regressionFit.getY(this, x);
}

@Nullable
public Double getX(double y)
{
if (hasQuadraticCoefficient())
{
double discriminant = getSlope()*getSlope()- 4*getQuadraticCoefficient()*(getIntercept() - y);
if (discriminant < 0)
{
return Double.NaN;
}
double sqrtDiscriminant = Math.sqrt(discriminant);
return (-getSlope() + sqrtDiscriminant)/2/getQuadraticCoefficient();
}
return (y - getIntercept())/getSlope();
return regressionFit.getX(this, y);
}

public RegressionFit getRegressionFit() {
return regressionFit;
}

public void setRegressionFit(RegressionFit regressionFit) {
this.regressionFit = regressionFit;
}

public static CalibrationCurve forNoExternalStandards() {
CalibrationCurve calibrationCurve = new CalibrationCurve();
CalibrationCurve calibrationCurve = new CalibrationCurve(RegressionFit.NONE);
calibrationCurve.setPointCount(0);
calibrationCurve.setSlope(1.0);
return calibrationCurve;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.labkey.targetedms.calculations.quantification;

import org.apache.commons.math3.fitting.WeightedObservedPoint;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -100,6 +101,7 @@ public TransitionKeys getFeaturesToQuantifyOn(String label) {
return transitionKeys;
}

@Nullable
public Double getCalculatedConcentration(String label, CalibrationCurve calibrationCurve, Replicate replicate) {
if (calibrationCurve == null) {
return null;
Expand All @@ -108,7 +110,11 @@ public Double getCalculatedConcentration(String label, CalibrationCurve calibrat
if (y == null) {
return null;
}
return calibrationCurve.getX(y) * replicate.getSampleDilutionFactor();
Double x = calibrationCurve.getX(y);
if (x == null) {
return null;
}
return x * replicate.getSampleDilutionFactor();
}

/**
Expand Down
Loading