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

PCA, flexible highlight selection scoreplot, samplelist #1997

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ public void handleEvent(BaseChart baseChart, Event event) {
/*
* Get all currently selected features
*/
List<Feature> selected = new ArrayList<>();
List<Feature> highlighted = new ArrayList<>();
for(Feature feature : evaluationPCA.getFeatureDataMatrix().getFeatures()) {
if(evaluationPCA.getHighlightedVariables().contains(feature.getVariable())) {
selected.add(feature);
highlighted.add(feature);
}
}
/*
Expand All @@ -288,19 +288,19 @@ public void handleEvent(BaseChart baseChart, Event event) {
double[] variableLoading = getVariableLoading(resultsPCA, i);
IPoint pointResult = getPoint(variableLoading, pcX, pcY, i);
if(pointResult.getX() > pXStart && pointResult.getX() < pXStop && pointResult.getY() < pYStart && pointResult.getY() > pYStop) {
if(selected.contains(featuresSelected.get(i))) {
int index = selected.indexOf(featuresSelected.get(i));
selected.remove(index);
if(highlighted.contains(featuresSelected.get(i))) {
int index = highlighted.indexOf(featuresSelected.get(i));
highlighted.remove(index);
} else {
selected.add(featuresSelected.get(i));
highlighted.add(featuresSelected.get(i));
}
}
}
/*
* Get the closest result.
*/
if(!selected.isEmpty()) {
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_PLOT_VARIABLE, selected.toArray());
if(!highlighted.isEmpty()) {
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_PLOT_VARIABLE, highlighted.toArray());
}
/*
* Finish User Selection Process
Expand Down Expand Up @@ -464,10 +464,10 @@ public void handleEvent(BaseChart baseChart, Event event) {
/*
* Get all currently selected features
*/
List<Feature> selected = new ArrayList<>();
List<Feature> highlighted = new ArrayList<>();
for(Feature feature : evaluationPCA.getFeatureDataMatrix().getFeatures()) {
if(evaluationPCA.getHighlightedVariables().contains(feature.getVariable())) {
selected.add(feature);
highlighted.add(feature);
}
}
/*
Expand All @@ -476,13 +476,13 @@ public void handleEvent(BaseChart baseChart, Event event) {
if(!featureDeltas.isEmpty()) {
Collections.sort(featureDeltas, Comparator.comparing(FeatureDelta::getDistance));
FeatureDelta featureDelta = featureDeltas.get(0);
if(selected.contains(featureDelta.getFeature())) {
int index = selected.indexOf(featureDelta.getFeature());
selected.remove(index);
if(highlighted.contains(featureDelta.getFeature())) {
int index = highlighted.indexOf(featureDelta.getFeature());
highlighted.remove(index);
} else {
selected.add(featureDelta.getFeature());
highlighted.add(featureDelta.getFeature());
}
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_PLOT_VARIABLE, selected.toArray());
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_PLOT_VARIABLE, highlighted.toArray());
highlightClick = true;
}
userSelection.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public int getStateMask() {
@Override
public void handleEvent(BaseChart baseChart, Event event) {

if(evaluationPCA != null) {
if(evaluationPCA != null && isBoxSelection()) {
/*
* Prepare Data viewport
*/
Expand Down Expand Up @@ -273,24 +273,28 @@ public void handleEvent(BaseChart baseChart, Event event) {
int pcX = principalComponentUI.getPCX();
int pcY = principalComponentUI.getPCY();
IResultsPCA<? extends IResultPCA, ? extends IVariable> resultsPCA = evaluationPCA.getResults();
List<ISample> sampleSelected = new ArrayList<>();
List<ISample> samplesHighlighted = evaluationPCA.getHighlightedSamples();
List<? extends IResultPCA> resultList = resultsPCA.getPcaResultList();
/*
* get samples within selection
* get samples within box selection
*/
for(int i = 0; i < resultList.size(); i++) {
IResultPCA pcaResult = resultList.get(i);
IPoint pointResult = getPoint(pcaResult, pcX, pcY, i);
if(pointResult.getX() > pXStart && pointResult.getX() < pXStop && pointResult.getY() < pYStart && pointResult.getY() > pYStop) {
sampleSelected.add(resultList.get(i).getSample());
if(samplesHighlighted.contains(resultList.get(i).getSample())) {
samplesHighlighted.remove(samplesHighlighted.indexOf(resultList.get(i).getSample()));
} else {
samplesHighlighted.add(resultList.get(i).getSample());
}
}
}
/*
* Send Update event.
*/
if(!sampleSelected.isEmpty()) {
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_RESULT, sampleSelected.toArray());
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_SAMPLE, sampleSelected.toArray());
if(!samplesHighlighted.isEmpty()) {
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_RESULT, samplesHighlighted.toArray());
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_SAMPLE, samplesHighlighted.toArray());
}
/*
* Finish User Selection Process
Expand Down Expand Up @@ -381,6 +385,98 @@ public void handleEvent(BaseChart baseChart, Event event) {
}
});
scorePlot.applySettings(chartSettings);
chartSettings.addHandledEventProcessor(new IHandledEventProcessor() {

@Override
public int getEvent() {

return IMouseSupport.EVENT_MOUSE_DOUBLE_CLICK;
}

@Override
public int getButton() {

return IMouseSupport.MOUSE_BUTTON_LEFT;
}

@Override
public int getStateMask() {

return SWT.MOD1;
}

@Override
public void handleEvent(BaseChart baseChart, Event event) {

if(evaluationPCA != null) {
/*
* Determine the x|y coordinates.
*/
Rectangle rectangle = baseChart.getPlotArea().getBounds();
double x = event.x;
double y = event.y;
double width = rectangle.width;
double height = rectangle.height;
/*
* Calculate the selected point.
*/
Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
/*
* Map the result deltas.
*/
PrincipalComponentUI principalComponentUI = principalComponentControl.get();
int pcX = principalComponentUI.getPCX();
int pcY = principalComponentUI.getPCY();
IResultsPCA<? extends IResultPCA, ? extends IVariable> resultsPCA = evaluationPCA.getResults();
List<? extends IResultPCA> resultList = resultsPCA.getPcaResultList();
List<ResultDelta> resultDeltas = new ArrayList<>();
/*
* prepare result object with score vectors per variable
*/
for(int i = 0; i < resultsPCA.getPcaResultList().size(); i++) {
IPoint pointResult = getPoint(resultList.get(i), pcX, pcY, i);
if(pointResult.getX() > rangeX.lower && pointResult.getX() < rangeX.upper && pointResult.getY() > rangeY.lower && pointResult.getY() < rangeY.upper) {
double deltaX = 0;
double deltaY = 0;
if(rangeX.upper < 0 || rangeX.lower > 0) {
deltaX = Math.abs(1.00 / Math.abs((Math.abs(rangeX.upper) - Math.abs(rangeX.lower))) * (pointResult.getX() - rangeX.lower) * width - x);
} else {
deltaX = Math.abs(1.00 / (rangeX.upper - rangeX.lower) * (pointResult.getX() - rangeX.lower) * width - x);
}
if(rangeY.upper < 0 || rangeY.lower > 0) {
deltaY = Math.abs(1.00 / Math.abs((Math.abs(rangeY.upper) - Math.abs(rangeY.lower))) * (pointResult.getY() - rangeY.lower) * height - (height - y));
} else {
deltaY = Math.abs(1.00 / (rangeY.upper - rangeY.lower) * (pointResult.getY() - rangeY.lower) * height - (height - y));
}
resultDeltas.add(new ResultDelta(resultList.get(i), deltaX, deltaY));
}
}
/*
* Get all currently selected Samples
*/
List<ISample> highlightedSamples = evaluationPCA.getHighlightedSamples();
/*
* Get the closest result.
*/
if(!resultDeltas.isEmpty()) {
Collections.sort(resultDeltas, Comparator.comparing(ResultDelta::getDistance));
ResultDelta resultDelta = resultDeltas.get(0);
if(highlightedSamples.contains(resultDelta.getResultPCA().getSample())) {
int index = highlightedSamples.indexOf(resultDelta.getResultPCA().getSample());
highlightedSamples.remove(index);
} else {
highlightedSamples.add(resultDelta.getResultPCA().getSample());
}
// List<ISample> highlightedSamples = new ArrayList<>();
// highlightedSamples.add(resultDelta.getResultPCA().getSample());
UpdateNotifierUI.update(event.display, IChemClipseEvents.TOPIC_PCA_UPDATE_HIGHLIGHT_SAMPLE, highlightedSamples.toArray());
}
}
userSelection.reset();
}
});
scorePlot.applySettings(chartSettings);
/*
* Paint Listener
*/
Expand Down Expand Up @@ -499,4 +595,12 @@ private void updatePlot(int pcX, int pcY) {
scorePlot.setInput(null, pcX, pcY);
}
}

private boolean isBoxSelection() {

if(userSelection.getStartX() != 0 && userSelection.getStartY() != 0 && userSelection.getStopX() != 0 && userSelection.getStopY() != 0) {
return true;
}
return false;
}
}
Loading