Skip to content

Commit b99a496

Browse files
committed
rocplot: Individual curve sliders used to be proportional to the range
of the score, which didn't work well for things like GQ / QUAL. Now based on number of points within the curve. Also, output status bar accuracy stats during sliding.
1 parent 5852bdd commit b99a496

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

src/com/rtg/graph/DataBundle.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ void setTitle(String title) {
6464
}
6565

6666
void setScoreRange(float min, float max) {
67-
final float smin = mScoreMin + (mScoreMin == mScoreMax ? 0.0f : min * (mScoreMax - mScoreMin));
68-
final float smax = mScoreMin + (mScoreMin == mScoreMax ? 0.0f : max * (mScoreMax - mScoreMin));
67+
final int smin = (int) (min * mScores.length);
68+
final int smax = (int) (max * mScores.length);
6969

7070
final ArrayList<Float> scores = new ArrayList<>();
7171
final ArrayList<Point2D> points = new ArrayList<>();
7272

73-
for (int i = 0; i < mScores.length; i++) {
74-
if (smin <= mScores[i] && mScores[i] <= smax) {
75-
scores.add(mScores[i]);
76-
points.add(mPoints[i]);
77-
}
73+
for (int i = smin; i < smax; i++) {
74+
scores.add(mScores[i]);
75+
points.add(mPoints[i]);
7876
}
7977

8078
mRangedPoints = points.toArray(new Point2D[points.size()]);
@@ -134,6 +132,10 @@ private void updateLabels() {
134132
mRangedPosPoints = posPoints.toArray(new TextPoint2D[posPoints.size()]);
135133
}
136134

135+
TextPoint2D getMaxRangedPoint() {
136+
return mRangedPosPoints.length == 0 ? null : mRangedPosPoints[mRangedPosPoints.length - 1];
137+
}
138+
137139
PointPlot2D getPlot(int lineWidth, int colour) {
138140
final PointPlot2D lplot = new PointPlot2D();
139141
lplot.setData(mRangedPoints);

src/com/rtg/graph/RocLinePanel.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.swing.plaf.basic.BasicArrowButton;
3838

3939
import com.reeltwo.jumble.annotations.JumbleIgnore;
40+
import com.reeltwo.plot.TextPoint2D;
4041

4142
/**
4243
* A panel that lets you enable or disable showing of a ROC line, rename the ROC line, and has buttons for
@@ -152,8 +153,12 @@ public void mouseClicked(MouseEvent e) {
152153
@Override
153154
public void stateChanged(ChangeEvent e) {
154155
final JSlider slider = (JSlider) e.getSource();
155-
mDataBundle.setScoreRange(1.0f - slider.getValue() / 1000.0f, 1.0f);
156+
mDataBundle.setScoreRange(0.0f, slider.getValue() / 1000.0f);
156157
mRocPlot.showCurrentGraph();
158+
final TextPoint2D data = mDataBundle.getMaxRangedPoint();
159+
if (data != null) {
160+
mStatusBar.setString(RocPlot.getTpFpString(data.getY(), data.getX(), mDataBundle.getTotalVariants()) + " Threshold=" + data.getText());
161+
}
157162
}
158163
});
159164

src/com/rtg/graph/RocPlot.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,11 @@ public void mouseClicked(MouseEvent e) {
523523
final Mapping[] mapping = mPlotPanel.getMapping();
524524
final int maxVariants = ((RocGraph2D) mPlotPanel.getGraph()).getMaxVariants();
525525
if (mapping != null && mapping.length > 1 && p != null) {
526-
final float x = mapping[0].screenToWorld((float) p.getX());
527-
final float y = mapping[1].screenToWorld((float) p.getY());
528-
if (x >= 0 && y >= 0 && (x + y > 0)) {
529-
String message = String.format("TP=%.0f FP=%.0f Precision=%.2f%%", y, x, y / (x + y) * 100);
530-
if (maxVariants > 0) {
531-
message += String.format(" Sensitivity=%.2f%%", y / maxVariants * 100);
532-
}
533-
mZoomPP.setCrossHair(new Point((int) x, (int) y));
534-
mProgressBar.setString(message);
526+
final float fp = mapping[0].screenToWorld((float) p.getX());
527+
final float tp = mapping[1].screenToWorld((float) p.getY());
528+
if (fp >= 0 && tp >= 0 && (fp + tp > 0)) {
529+
mProgressBar.setString(getTpFpString(tp, fp, maxVariants));
530+
mZoomPP.setCrossHair(new Point((int) fp, (int) tp));
535531
} else {
536532
mZoomPP.setCrossHair(null);
537533
mProgressBar.setString("");
@@ -556,6 +552,14 @@ private void maybeShowPopup(MouseEvent e) {
556552
}
557553
}
558554

555+
static String getTpFpString(float tp, float fp, int maxVariants) {
556+
String message = String.format("TP=%.0f FP=%.0f Precision=%.2f%%", tp, fp, tp / (fp + tp) * 100);
557+
if (maxVariants > 0) {
558+
message += String.format(" Sensitivity=%.2f%%", tp / maxVariants * 100);
559+
}
560+
return message;
561+
}
562+
559563

560564
void rocStandalone(ArrayList<File> fileList, ArrayList<String> nameList, String title, boolean scores, final boolean hideSidePanel, int lineWidth) throws InterruptedException, InvocationTargetException, IOException {
561565
final RocPlot rp = new RocPlot();

0 commit comments

Comments
 (0)