| 1 |
|
package jalview.ws2.actions.annotation; |
| 2 |
|
|
| 3 |
|
import java.util.ArrayList; |
| 4 |
|
import java.util.Collections; |
| 5 |
|
import java.util.List; |
| 6 |
|
|
| 7 |
|
import jalview.analysis.AlignmentAnnotationUtils; |
| 8 |
|
import jalview.api.AlignViewportI; |
| 9 |
|
import jalview.api.AlignmentViewPanel; |
| 10 |
|
import jalview.api.PollableAlignCalcWorkerI; |
| 11 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 12 |
|
import jalview.datamodel.AlignmentI; |
| 13 |
|
import jalview.workers.AlignCalcWorker; |
| 14 |
|
import jalview.ws.params.ArgumentI; |
| 15 |
|
import jalview.ws2.actions.api.TaskEventListener; |
| 16 |
|
import jalview.ws2.actions.api.TaskI; |
| 17 |
|
import jalview.ws2.api.Credentials; |
| 18 |
|
|
| |
|
| 0% |
Uncovered Elements: 72 (72) |
Complexity: 19 |
Complexity Density: 0.4 |
|
| 19 |
|
public class AlignCalcWorkerAdapter extends AlignCalcWorker implements PollableAlignCalcWorkerI |
| 20 |
|
{ |
| 21 |
|
private static int calcCount = 0; |
| 22 |
|
|
| 23 |
|
private final int calcNumber = calcCount++; |
| 24 |
|
|
| 25 |
|
private final AnnotationAction action; |
| 26 |
|
|
| 27 |
|
private final List<ArgumentI> args; |
| 28 |
|
|
| 29 |
|
private final Credentials credentials; |
| 30 |
|
|
| 31 |
|
private TaskI<AnnotationResult> currentTask = null; |
| 32 |
|
|
| 33 |
|
private TaskEventListener<AnnotationResult> taskListener = new TaskEventListener<>() |
| 34 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 35 |
0 |
@Override... |
| 36 |
|
public void taskCompleted(TaskI source, AnnotationResult result) |
| 37 |
|
{ |
| 38 |
0 |
int graphGroup = alignViewport.getAlignment().getLastGraphGroup(); |
| 39 |
0 |
List<AlignmentAnnotation> annotations = new ArrayList<>(); |
| 40 |
0 |
for (AlignmentAnnotation ala : result.getAnnotations()) |
| 41 |
|
{ |
| 42 |
0 |
if (ala.graphGroup > 0) |
| 43 |
0 |
ala.graphGroup += graphGroup; |
| 44 |
0 |
var newAnnot = alignViewport.getAlignment() |
| 45 |
|
.updateFromOrCopyAnnotation(ala); |
| 46 |
0 |
if (newAnnot.sequenceRef != null) |
| 47 |
|
{ |
| 48 |
0 |
newAnnot.sequenceRef.addAlignmentAnnotation(newAnnot); |
| 49 |
0 |
newAnnot.adjustForAlignment(); |
| 50 |
0 |
AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith( |
| 51 |
|
newAnnot, newAnnot.label, newAnnot.getCalcId()); |
| 52 |
|
} |
| 53 |
0 |
annotations.add(newAnnot); |
| 54 |
|
} |
| 55 |
0 |
updateOurAnnots(annotations); |
| 56 |
0 |
listener.workerHasResult( |
| 57 |
|
AlignCalcWorkerAdapter.this, |
| 58 |
|
new AnnotationResult( |
| 59 |
|
annotations, |
| 60 |
|
result.hasFeatures, |
| 61 |
|
result.featureColours, |
| 62 |
|
result.featureFilters)); |
| 63 |
|
} |
| 64 |
|
}; |
| 65 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 66 |
0 |
public AlignCalcWorkerAdapter(AlignViewportI alignViewport, AlignmentViewPanel alignPanel, AnnotationAction action,... |
| 67 |
|
List<ArgumentI> args, Credentials credentials) |
| 68 |
|
{ |
| 69 |
0 |
super(alignViewport, alignPanel); |
| 70 |
0 |
this.action = action; |
| 71 |
0 |
this.args = args; |
| 72 |
0 |
this.credentials = credentials; |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
0 |
@Override... |
| 76 |
|
public String getCalcName() |
| 77 |
|
{ |
| 78 |
0 |
return action.getWebService().getName(); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 81 |
0 |
@Override... |
| 82 |
|
public void updateAnnotation() |
| 83 |
|
{ |
| 84 |
|
|
| 85 |
|
} |
| 86 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 87 |
0 |
private void updateOurAnnots(List<AlignmentAnnotation> newAnnots)... |
| 88 |
|
{ |
| 89 |
0 |
List<AlignmentAnnotation> oldAnnots = ourAnnots != null ? ourAnnots : List.of(); |
| 90 |
0 |
AlignmentI alignment = alignViewport.getAlignment(); |
| 91 |
0 |
for (AlignmentAnnotation annotation : oldAnnots) |
| 92 |
0 |
if (!newAnnots.contains(annotation)) |
| 93 |
0 |
alignment.deleteAnnotation(annotation); |
| 94 |
0 |
for (AlignmentAnnotation annotation : newAnnots) |
| 95 |
0 |
alignment.validateAnnotation(annotation); |
| 96 |
0 |
ourAnnots = Collections.synchronizedList(newAnnots); |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 99 |
0 |
@Override... |
| 100 |
|
public synchronized void startUp() throws Throwable |
| 101 |
|
{ |
| 102 |
0 |
if (alignViewport.isClosed()) |
| 103 |
|
{ |
| 104 |
0 |
calcMan.disableWorker(this); |
| 105 |
0 |
abortAndDestroy(); |
| 106 |
0 |
throw new IllegalStateException("Starting calculation for closed viewport"); |
| 107 |
|
} |
| 108 |
0 |
currentTask = action.createTask(alignViewport, args, credentials); |
| 109 |
0 |
currentTask.addTaskEventListener(taskListener); |
| 110 |
0 |
currentTask.init(); |
| 111 |
0 |
listener.workerStarted(this); |
| 112 |
|
} |
| 113 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 114 |
0 |
@Override... |
| 115 |
|
public boolean poll() throws Throwable |
| 116 |
|
{ |
| 117 |
0 |
return currentTask.poll(); |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 120 |
0 |
@Override... |
| 121 |
|
public synchronized void cancel() |
| 122 |
|
{ |
| 123 |
0 |
try |
| 124 |
|
{ |
| 125 |
0 |
currentTask.cancel(); |
| 126 |
|
} finally |
| 127 |
|
{ |
| 128 |
0 |
currentTask.removeTaskEventListener(taskListener); |
| 129 |
0 |
listener.workerStopped(this); |
| 130 |
|
} |
| 131 |
|
} |
| 132 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 133 |
0 |
@Override... |
| 134 |
|
public synchronized void done() |
| 135 |
|
{ |
| 136 |
0 |
try |
| 137 |
|
{ |
| 138 |
0 |
currentTask.complete(); |
| 139 |
|
} catch (Exception e) |
| 140 |
|
{ |
| 141 |
|
} finally |
| 142 |
|
{ |
| 143 |
0 |
currentTask.removeTaskEventListener(taskListener); |
| 144 |
0 |
listener.workerStopped(this); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 148 |
0 |
@Override... |
| 149 |
|
public boolean isDeletable() |
| 150 |
|
{ |
| 151 |
0 |
return true; |
| 152 |
|
} |
| 153 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 154 |
0 |
@Override... |
| 155 |
|
public String toString() |
| 156 |
|
{ |
| 157 |
0 |
return "AlignCalcWorkerAdapter-" + calcNumber + " for " + getCalcName(); |
| 158 |
|
} |
| 159 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 3 |
Complexity Density: - |
|
| 160 |
|
public interface WorkerListener extends java.util.EventListener |
| 161 |
|
{ |
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 162 |
0 |
default void workerStarted(AlignCalcWorkerAdapter source)... |
| 163 |
|
{ |
| 164 |
|
}; |
| 165 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 166 |
0 |
default void workerStopped(AlignCalcWorkerAdapter source)... |
| 167 |
|
{ |
| 168 |
|
}; |
| 169 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 170 |
0 |
default void workerHasResult(AlignCalcWorkerAdapter source, AnnotationResult result)... |
| 171 |
|
{ |
| 172 |
|
}; |
| 173 |
|
|
| 174 |
|
static final WorkerListener NULL_LISTENER = new WorkerListener() |
| 175 |
|
{ |
| 176 |
|
}; |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
private WorkerListener listener = WorkerListener.NULL_LISTENER; |
| 180 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 181 |
0 |
public void setWorkerListener(WorkerListener listener)... |
| 182 |
|
{ |
| 183 |
0 |
if (listener == null) listener = WorkerListener.NULL_LISTENER; |
| 184 |
0 |
this.listener = listener; |
| 185 |
|
} |
| 186 |
|
} |