-
Notifications
You must be signed in to change notification settings - Fork 85
/
AnnotatorPanel.java
1071 lines (939 loc) · 46.5 KB
/
AnnotatorPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.bbop.apollo.gwt.client;
import com.google.gwt.cell.client.ClickableTextCell;
import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.cell.client.NumberCell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.builder.shared.DivBuilder;
import com.google.gwt.dom.builder.shared.TableCellBuilder;
import com.google.gwt.dom.builder.shared.TableRowBuilder;
import com.google.gwt.dom.client.BrowserEvents;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.http.client.*;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.text.shared.AbstractSafeHtmlRenderer;
import com.google.gwt.text.shared.SafeHtmlRenderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.view.client.*;
import org.bbop.apollo.gwt.client.dto.AnnotationInfo;
import org.bbop.apollo.gwt.client.dto.AnnotationInfoConverter;
import org.bbop.apollo.gwt.client.dto.UserInfo;
import org.bbop.apollo.gwt.client.dto.UserInfoConverter;
import org.bbop.apollo.gwt.client.event.AnnotationInfoChangeEvent;
import org.bbop.apollo.gwt.client.event.AnnotationInfoChangeEventHandler;
import org.bbop.apollo.gwt.client.event.UserChangeEvent;
import org.bbop.apollo.gwt.client.event.UserChangeEventHandler;
import org.bbop.apollo.gwt.client.oracles.ReferenceSequenceOracle;
import org.bbop.apollo.gwt.client.resources.TableResources;
import org.bbop.apollo.gwt.client.rest.UserRestService;
import org.bbop.apollo.gwt.shared.FeatureStringEnum;
import org.bbop.apollo.gwt.shared.PermissionEnum;
import org.gwtbootstrap3.client.ui.Button;
import org.gwtbootstrap3.client.ui.CheckBox;
import org.gwtbootstrap3.client.ui.Label;
import org.gwtbootstrap3.client.ui.ListBox;
import org.gwtbootstrap3.client.ui.TextBox;
import org.gwtbootstrap3.client.ui.*;
import org.gwtbootstrap3.client.ui.constants.ButtonType;
import org.gwtbootstrap3.client.ui.constants.IconType;
import org.gwtbootstrap3.extras.bootbox.client.Bootbox;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by ndunn on 12/17/14.
*/
public class AnnotatorPanel extends Composite {
interface AnnotatorPanelUiBinder extends UiBinder<com.google.gwt.user.client.ui.Widget, AnnotatorPanel> {
}
private static AnnotatorPanelUiBinder ourUiBinder = GWT.create(AnnotatorPanelUiBinder.class);
private DateTimeFormat outputFormat = DateTimeFormat.getFormat("MMM dd, yyyy");
private Column<AnnotationInfo, String> nameColumn;
private TextColumn<AnnotationInfo> typeColumn;
private TextColumn<AnnotationInfo> sequenceColumn;
private Column<AnnotationInfo, Number> lengthColumn;
private Column<AnnotationInfo, String> dateColumn;
private Column<AnnotationInfo, String> showHideColumn;
private long requestIndex = 0;
private static String selectedChildUniqueName = null;
private static int selectedSubTabIndex = 0;
private static int pageSize = 25;
private final String COLLAPSE_ICON_UNICODE = "\u25BC";
private final String EXPAND_ICON_UNICODE = "\u25C0";
@UiField
TextBox nameSearchBox;
@UiField(provided = true)
org.gwtbootstrap3.client.ui.SuggestBox sequenceList;
private static DataGrid.Resources tablecss = GWT.create(TableResources.TableCss.class);
@UiField(provided = true)
static DataGrid<AnnotationInfo> dataGrid = new DataGrid<>(pageSize, tablecss);
@UiField(provided = true)
WebApolloSimplePager pager = null;
@UiField
ListBox typeList;
@UiField
static GeneDetailPanel geneDetailPanel;
@UiField
static TranscriptDetailPanel transcriptDetailPanel;
@UiField
static ExonDetailPanel exonDetailPanel;
@UiField
static RepeatRegionDetailPanel repeatRegionDetailPanel;
@UiField
static VariantDetailPanel variantDetailPanel;
@UiField
static VariantAllelesPanel variantAllelesPanel;
@UiField
static VariantInfoPanel variantInfoPanel;
@UiField
static AlleleInfoPanel alleleInfoPanel;
@UiField
static TabLayoutPanel tabPanel;
@UiField
ListBox userField;
@UiField
DockLayoutPanel splitPanel;
@UiField
Container northPanelContainer;
// @UiField
// Button toggleAnnotation;
@UiField
com.google.gwt.user.client.ui.ListBox pageSizeSelector;
@UiField
GoPanel goPanel;
@UiField
CheckBox goOnlyCheckBox;
@UiField
static DbXrefPanel dbXrefPanel;
@UiField
static CommentPanel commentPanel;
@UiField
static AttributePanel attributePanel;
@UiField
CheckBox uniqueNameCheckBox;
@UiField
Button showAllSequences;
// manage UI-state
private Boolean showDetails = true;
static AnnotationInfo selectedAnnotationInfo;
private MultiWordSuggestOracle sequenceOracle = new ReferenceSequenceOracle();
private static AsyncDataProvider<AnnotationInfo> dataProvider;
private SingleSelectionModel<AnnotationInfo> singleSelectionModel = new SingleSelectionModel<>();
private final Set<String> showingTranscripts = new HashSet<String>();
public enum TAB_INDEX {
DETAILS(0),
CODING(1),
ALTERNATE_ALLELES(2),
VARIANT_INFO(3),
ALLELE_INFO(4),
GO(5),
DB_XREF(6),
COMMENT(7),
ATTRIBUTES(8),
;
public int index;
TAB_INDEX(int index) {
this.index = index;
}
public static TAB_INDEX getTabEnumForIndex(int selectedSubTabIndex) {
for (TAB_INDEX value : values()) {
if (value.index == selectedSubTabIndex) {
return value;
}
}
return null;
}
public int getIndex() {
return index;
}
}
public AnnotatorPanel() {
sequenceList = new org.gwtbootstrap3.client.ui.SuggestBox(sequenceOracle);
sequenceList.getElement().setAttribute("placeHolder", "Reference Sequence");
dataGrid.setWidth("100%");
dataGrid.setTableBuilder(new CustomTableBuilder());
dataGrid.setLoadingIndicator(new Label("Loading"));
dataGrid.setEmptyTableWidget(new Label("No results"));
initializeTable();
pager = new WebApolloSimplePager(WebApolloSimplePager.TextLocation.CENTER);
dataGrid.addCellPreviewHandler(new CellPreviewEvent.Handler<AnnotationInfo>() {
@Override
public void onCellPreview(CellPreviewEvent<AnnotationInfo> event) {
AnnotationInfo annotationInfo = event.getValue();
if (event.getNativeEvent().getType().equals(BrowserEvents.CLICK)) {
if (event.getContext().getSubIndex() == 0) {
// subIndex from dataGrid will be 0 only when top-level cell values are clicked
// ie. gene, pseudogene
GWT.log("Safe to call updateAnnotationInfo");
updateAnnotationInfo(annotationInfo);
}
}
}
});
exportStaticMethod(this);
initWidget(ourUiBinder.createAndBindUi(this));
handleDetails();
dataProvider = new AsyncDataProvider<AnnotationInfo>() {
@Override
protected void onRangeChanged(HasData<AnnotationInfo> display) {
final Range range = display.getVisibleRange();
final ColumnSortList sortList = dataGrid.getColumnSortList();
final int start = range.getStart();
final int length = range.getLength();
String sequenceName = sequenceList.getText().trim();
String url = Annotator.getRootUrl() + "annotator/findAnnotationsForSequence/?sequenceName=" + sequenceName;
url += "&request=" + requestIndex;
url += "&offset=" + start + "&max=" + length;
url += "&annotationName=" + nameSearchBox.getText();
url += "&type=" + typeList.getSelectedValue();
url += "&user=" + userField.getSelectedValue();
url += "&clientToken=" + Annotator.getClientToken();
url += "&showOnlyGoAnnotations=" + goOnlyCheckBox.getValue();
url += "&searchUniqueName=" + uniqueNameCheckBox.getValue();
ColumnSortList.ColumnSortInfo nameSortInfo = sortList.get(0);
Column<AnnotationInfo, ?> sortColumn = (Column<AnnotationInfo, ?>) sortList.get(0).getColumn();
Integer columnIndex = dataGrid.getColumnIndex(sortColumn);
String searchColumnString = null;
switch (columnIndex) {
case 0:
searchColumnString = "name";
break;
case 1:
searchColumnString = "sequence";
break;
case 3:
searchColumnString = "length";
break;
case 4:
searchColumnString = "date";
default:
break;
}
Boolean sortNameAscending = nameSortInfo.isAscending();
url += "&sortorder=" + (sortNameAscending ? "asc" : "desc");
url += "&sort=" + searchColumnString;
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
builder.setHeader("Content-type", "application/x-www-form-urlencoded");
RequestCallback requestCallback = new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
JSONValue returnValue = null;
try {
returnValue = JSONParser.parseStrict(response.getText());
} catch (Exception e) {
Bootbox.alert(e.getMessage());
}
JSONValue localRequestObject = returnValue.isObject().get(FeatureStringEnum.REQUEST_INDEX.getValue());
if (localRequestObject != null) {
long localRequestValue = (long) localRequestObject.isNumber().doubleValue();
if (localRequestValue <= requestIndex) {
return;
} else {
requestIndex = localRequestValue;
}
Integer annotationCount = (int) returnValue.isObject().get(FeatureStringEnum.ANNOTATION_COUNT.getValue()).isNumber().doubleValue();
JSONArray jsonArray = returnValue.isObject().get(FeatureStringEnum.FEATURES.getValue()).isArray();
dataGrid.setRowCount(annotationCount, true);
final List<AnnotationInfo> annotationInfoList = AnnotationInfoConverter.convertFromJsonArray(jsonArray);
dataGrid.setRowData(start, annotationInfoList);
if (annotationInfoList.size() == 1) {
selectedAnnotationInfo = annotationInfoList.get(0);
String type = selectedAnnotationInfo.getType();
if (!type.equals("repeat_region") && !type.equals("transposable_element")) {
toggleOpen(1, selectedAnnotationInfo);
}
}
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
if (selectedAnnotationInfo != null) {
// Window.alert("setting data: "+selectedAnnotationInfo.getName());
// refind and update internally
for (AnnotationInfo annotationInfo : annotationInfoList) {
GWT.log("top-level: " + annotationInfo.getType());
// will be found if a top-level selection
if (annotationInfo.getUniqueName().equals(selectedAnnotationInfo.getUniqueName())) {
selectedAnnotationInfo = annotationInfo;
singleSelectionModel.clear();
singleSelectionModel.setSelected(selectedAnnotationInfo, true);
updateAnnotationInfo(selectedAnnotationInfo);
return;
}
// if a child, we need to get the index I think?
final String thisUniqueName = selectedChildUniqueName;
for (AnnotationInfo annotationInfoChild : annotationInfo.getChildAnnotations()) {
GWT.log("next-level: " + annotationInfoChild.getType());
if (annotationInfoChild.getUniqueName().equals(selectedAnnotationInfo.getUniqueName())) {
// selectedAnnotationInfo = annotationInfo;
selectedAnnotationInfo = getChildAnnotation(annotationInfo, thisUniqueName);
singleSelectionModel.clear();
singleSelectionModel.setSelected(selectedAnnotationInfo, true);
updateAnnotationInfo(selectedAnnotationInfo);
return;
}
}
}
}
}
});
}
}
@Override
public void onError(Request request, Throwable exception) {
Bootbox.alert("Error loading organisms");
}
};
try {
if (MainPanel.getInstance().getCurrentUser() != null) {
builder.setCallback(requestCallback);
builder.send();
}
} catch (RequestException e) {
// Couldn't connect to server
Bootbox.alert(e.getMessage());
}
}
};
ColumnSortEvent.AsyncHandler columnSortHandler = new ColumnSortEvent.AsyncHandler(dataGrid);
dataGrid.addColumnSortHandler(columnSortHandler);
dataGrid.getColumnSortList().push(nameColumn);
dataGrid.getColumnSortList().push(sequenceColumn);
dataGrid.getColumnSortList().push(lengthColumn);
dataGrid.getColumnSortList().push(dateColumn);
dataProvider.addDataDisplay(dataGrid);
pager.setDisplay(dataGrid);
pageSizeSelector.addItem("10");
pageSizeSelector.addItem("25");
pageSizeSelector.addItem("50");
pageSizeSelector.addItem("100");
pageSizeSelector.addItem("500");
pageSizeSelector.setSelectedIndex(1);
initializeTypes();
sequenceList.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
@Override
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
reload();
}
});
sequenceList.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
if (sequenceList.getText() == null || sequenceList.getText().trim().length() == 0) {
reload();
}
}
});
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(SelectionEvent<Integer> event) {
selectedSubTabIndex = event.getSelectedItem();
TAB_INDEX tab = TAB_INDEX.getTabEnumForIndex(selectedSubTabIndex);
switch (tab) {
case DETAILS:
break;
case CODING:
exonDetailPanel.redrawExonTable();
break;
case ALTERNATE_ALLELES:
variantAllelesPanel.redrawTable();
break;
case VARIANT_INFO:
variantInfoPanel.redrawTable();
case ALLELE_INFO:
alleleInfoPanel.redrawTable();
case GO:
goPanel.redraw();
case DB_XREF:
dbXrefPanel.updateData(selectedAnnotationInfo);
break;
case COMMENT:
commentPanel.updateData(selectedAnnotationInfo);
break;
case ATTRIBUTES:
attributePanel.updateData(selectedAnnotationInfo);
}
}
});
Annotator.eventBus.addHandler(AnnotationInfoChangeEvent.TYPE, new AnnotationInfoChangeEventHandler() {
@Override
public void onAnnotationChanged(AnnotationInfoChangeEvent annotationInfoChangeEvent) {
reload();
}
});
Annotator.eventBus.addHandler(UserChangeEvent.TYPE,
new UserChangeEventHandler() {
@Override
public void onUserChanged(UserChangeEvent authenticationEvent) {
switch (authenticationEvent.getAction()) {
case PERMISSION_CHANGED:
PermissionEnum hiPermissionEnum = authenticationEvent.getHighestPermission();
if (MainPanel.getInstance().isCurrentUserAdmin()) {
hiPermissionEnum = PermissionEnum.ADMINISTRATE;
}
boolean editable = false;
switch (hiPermissionEnum) {
case ADMINISTRATE:
case WRITE:
editable = true;
break;
// default is false
}
transcriptDetailPanel.setEditable(editable);
geneDetailPanel.setEditable(editable);
exonDetailPanel.setEditable(editable);
repeatRegionDetailPanel.setEditable(editable);
reload();
break;
}
}
}
);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
initializeUsers();
userField.setVisible(true);
}
});
}
void selectGoPanel() {
goPanel.redraw();
tabPanel.selectTab(5);
}
private void initializeUsers() {
userField.clear();
userField.addItem("All Users", "");
RequestCallback requestCallback = new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() == 401) {
return;
}
JSONValue returnValue = JSONParser.parseStrict(response.getText());
JSONArray array = returnValue.isArray();
for (int i = 0; array != null && i < array.size(); i++) {
JSONObject object = array.get(i).isObject();
UserInfo userInfo = UserInfoConverter.convertToUserInfoFromJSON(object);
userField.addItem(userInfo.getName(), userInfo.getEmail());
}
}
@Override
public void onError(Request request, Throwable exception) {
Bootbox.alert("Error retrieving users: " + exception.fillInStackTrace());
}
};
UserRestService.loadUsers(requestCallback);
}
private void initializeTypes() {
typeList.addItem("All Types", "");
typeList.addItem("Gene");
typeList.addItem("Pseudogene");
typeList.addItem("Transposable Element", "transposable_element");
typeList.addItem("Terminator", "terminator");
typeList.addItem("Repeat Region", "repeat_region");
typeList.addItem("Variant", "sequence_alteration");
}
private static void hideDetailPanels() {
geneDetailPanel.setVisible(false);
transcriptDetailPanel.setVisible(false);
repeatRegionDetailPanel.setVisible(false);
variantDetailPanel.setVisible(false);
// exonDetailPanel.setVisible(false);
}
private static void updateAnnotationInfo(AnnotationInfo annotationInfo) {
if (annotationInfo == null) {
return;
}
String type = annotationInfo.getType();
GWT.log("annotation type: " + type);
hideDetailPanels();
switch (type) {
case "gene":
case "pseudogene":
geneDetailPanel.updateData(annotationInfo);
dbXrefPanel.updateData(annotationInfo);
commentPanel.updateData(annotationInfo);
attributePanel.updateData(annotationInfo);
tabPanel.getTabWidget(TAB_INDEX.DETAILS.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALTERNATE_ALLELES.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.VARIANT_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALLELE_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.GO.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.DB_XREF.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.COMMENT.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ATTRIBUTES.index).getParent().setVisible(true);
break;
case "transcript":
transcriptDetailPanel.updateData(annotationInfo);
dbXrefPanel.updateData(annotationInfo);
commentPanel.updateData(annotationInfo);
attributePanel.updateData(annotationInfo);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(true);
exonDetailPanel.updateData(annotationInfo, selectedAnnotationInfo);
tabPanel.getTabWidget(TAB_INDEX.DETAILS.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ALTERNATE_ALLELES.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.VARIANT_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALLELE_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.GO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.DB_XREF.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.COMMENT.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ATTRIBUTES.index).getParent().setVisible(true);
break;
case "mRNA":
case "miRNA":
case "tRNA":
case "rRNA":
case "snRNA":
case "snoRNA":
case "ncRNA":
transcriptDetailPanel.updateData(annotationInfo);
exonDetailPanel.updateData(annotationInfo, selectedAnnotationInfo);
dbXrefPanel.updateData(annotationInfo);
commentPanel.updateData(annotationInfo);
attributePanel.updateData(annotationInfo);
tabPanel.getTabWidget(TAB_INDEX.DETAILS.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ALTERNATE_ALLELES.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.VARIANT_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALLELE_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.GO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.DB_XREF.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.COMMENT.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ATTRIBUTES.index).getParent().setVisible(true);
break;
case "terminator":
case "transposable_element":
case "repeat_region":
repeatRegionDetailPanel.updateData(annotationInfo);
dbXrefPanel.updateData(annotationInfo);
commentPanel.updateData(annotationInfo);
attributePanel.updateData(annotationInfo);
tabPanel.getTabWidget(TAB_INDEX.DETAILS.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALTERNATE_ALLELES.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.VARIANT_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALLELE_INFO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.GO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.DB_XREF.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.COMMENT.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ATTRIBUTES.index).getParent().setVisible(true);
break;
case "deletion":
case "insertion":
case "SNV":
case "SNP":
case "MNV":
case "MNP":
case "indel":
variantDetailPanel.updateData(annotationInfo);
variantAllelesPanel.updateData(annotationInfo);
variantInfoPanel.updateData(annotationInfo);
alleleInfoPanel.updateData(annotationInfo);
dbXrefPanel.updateData(annotationInfo);
commentPanel.updateData(annotationInfo);
attributePanel.updateData(annotationInfo);
tabPanel.getTabWidget(TAB_INDEX.DETAILS.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.CODING.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.ALTERNATE_ALLELES.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.VARIANT_INFO.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ALLELE_INFO.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.GO.index).getParent().setVisible(false);
tabPanel.getTabWidget(TAB_INDEX.DB_XREF.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.COMMENT.index).getParent().setVisible(true);
tabPanel.getTabWidget(TAB_INDEX.ATTRIBUTES.index).getParent().setVisible(true);
break;
default:
GWT.log("not sure what to do with " + type);
}
reselectSubTab();
}
private static void reselectSubTab() {
// attempt to select the last tab
if (tabPanel.getSelectedIndex() != selectedSubTabIndex) {
tabPanel.selectTab(selectedSubTabIndex);
}
// if current tab is not visible, then select tab 0
while (!tabPanel.getTabWidget(selectedSubTabIndex).getParent().isVisible() && selectedSubTabIndex >= 0) {
--selectedSubTabIndex;
tabPanel.selectTab(selectedSubTabIndex);
}
}
public static void fireAnnotationInfoChangeEvent(AnnotationInfo annotationInfo) {
// this method is for firing AnnotationInfoChangeEvent for single level features such as transposable_element and repeat_region
AnnotationInfoChangeEvent annotationInfoChangeEvent = new AnnotationInfoChangeEvent(annotationInfo, AnnotationInfoChangeEvent.Action.SET_FOCUS);
Annotator.eventBus.fireEvent(annotationInfoChangeEvent);
}
public void toggleOpen(int index, AnnotationInfo annotationInfo) {
if (showingTranscripts.contains(annotationInfo.getUniqueName())) {
showingTranscripts.remove(annotationInfo.getUniqueName());
} else {
showingTranscripts.add(annotationInfo.getUniqueName());
}
// Redraw the modified row.
if (index < dataGrid.getRowCount()) {
dataGrid.redrawRow(index);
}
}
private void initializeTable() {
// View friends.
SafeHtmlRenderer<String> anchorRenderer = new AbstractSafeHtmlRenderer<String>() {
@Override
public SafeHtml render(String object) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
sb.appendHtmlConstant("<a href=\"javascript:;\">").appendEscaped(object)
.appendHtmlConstant("</a>");
return sb.toSafeHtml();
}
};
nameColumn = new Column<AnnotationInfo, String>(new ClickableTextCell(anchorRenderer)) {
@Override
public String getValue(AnnotationInfo annotationInfo) {
return annotationInfo.getName();
}
};
nameColumn.setSortable(true);
showHideColumn = new Column<AnnotationInfo, String>(new ClickableTextCell(anchorRenderer)) {
@Override
public String getValue(AnnotationInfo annotationInfo) {
if (annotationInfo.getType().equals("gene") || annotationInfo.getType().equals("pseudogene")) {
SafeHtmlBuilder sb = new SafeHtmlBuilder();
if (showingTranscripts.contains(annotationInfo.getUniqueName())) {
sb.appendHtmlConstant(COLLAPSE_ICON_UNICODE);
} else {
sb.appendHtmlConstant(EXPAND_ICON_UNICODE);
}
return sb.toSafeHtml().asString();
}
return " ";
}
};
showHideColumn.setSortable(false);
showHideColumn.setFieldUpdater(new FieldUpdater<AnnotationInfo, String>() {
@Override
public void update(int index, AnnotationInfo annotationInfo, String value) {
toggleOpen(index, annotationInfo);
}
});
sequenceColumn = new TextColumn<AnnotationInfo>() {
@Override
public String getValue(AnnotationInfo annotationInfo) {
return annotationInfo.getSequence();
}
};
sequenceColumn.setSortable(true);
sequenceColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
typeColumn = new TextColumn<AnnotationInfo>() {
@Override
public String getValue(AnnotationInfo annotationInfo) {
String type = annotationInfo.getType();
switch (type) {
case "terminator":
return "terminator";
case "repeat_region":
return "repeat rgn";
case "transposable_element":
return "transp elem";
default:
return type;
}
}
};
typeColumn.setSortable(false);
typeColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
lengthColumn = new Column<AnnotationInfo, Number>(new NumberCell()) {
@Override
public Integer getValue(AnnotationInfo annotationInfo) {
return annotationInfo.getLength();
}
};
lengthColumn.setSortable(true);
lengthColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
lengthColumn.setCellStyleNames("dataGridLastColumn");
// unused?
dateColumn = new Column<AnnotationInfo, String>(new TextCell()) {
@Override
public String getValue(AnnotationInfo annotationInfo) {
return annotationInfo.getDateLastModified();
}
};
dateColumn.setSortable(true);
dateColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
dateColumn.setCellStyleNames("dataGridLastColumn");
dateColumn.setDefaultSortAscending(false);
dataGrid.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(DoubleClickEvent event) {
AnnotationInfo annotationInfo = singleSelectionModel.getSelectedObject();
int index = dataGrid.getKeyboardSelectedRow();
index += pager.getPage() * pager.getPageSize();
toggleOpen(index, annotationInfo);
}
}, DoubleClickEvent.getType());
singleSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
selectedAnnotationInfo = singleSelectionModel.getSelectedObject();
tabPanel.setVisible(showDetails && selectedAnnotationInfo != null);
GWT.log("select info" + selectedAnnotationInfo);
if (selectedAnnotationInfo != null) {
exonDetailPanel.updateData(selectedAnnotationInfo);
goPanel.updateData(selectedAnnotationInfo);
dbXrefPanel.updateData(selectedAnnotationInfo);
commentPanel.updateData(selectedAnnotationInfo);
attributePanel.updateData(selectedAnnotationInfo);
} else {
exonDetailPanel.updateData();
goPanel.updateData();
dbXrefPanel.updateData();
commentPanel.updateData();
attributePanel.updateData();
}
}
});
dataGrid.addColumn(nameColumn, "Name");
dataGrid.addColumn(sequenceColumn, "Seq");
dataGrid.addColumn(typeColumn, "Type");
dataGrid.addColumn(lengthColumn, "Length");
dataGrid.addColumn(dateColumn, "Updated");
dataGrid.addColumn(showHideColumn, "");
dataGrid.setColumnWidth(0, 75, Unit.PCT);
dataGrid.setColumnWidth(1, 25, Unit.PCT);
dataGrid.setColumnWidth(2, 45.0, Unit.PX);
dataGrid.setColumnWidth(3, 65.0, Unit.PX);
dataGrid.setColumnWidth(4, 100.0, Unit.PX);
dataGrid.setColumnWidth(5, 30.0, Unit.PX);
dataGrid.setSelectionModel(singleSelectionModel);
}
private String getType(JSONObject internalData) {
return internalData.get("type").isObject().get("name").isString().stringValue();
}
public void reload(Boolean forceReload) {
showAllSequences.setEnabled(isSearchDirty());
showAllSequences.setType(isSearchDirty() ? ButtonType.INFO : ButtonType.DEFAULT);
if (MainPanel.annotatorPanel.isVisible() || forceReload) {
hideDetailPanels();
pager.setPageStart(0);
dataGrid.setVisibleRangeAndClearData(dataGrid.getVisibleRange(), true);
}
}
public void reload() {
reload(false);
}
private Boolean isSearchDirty() {
if(typeList.getSelectedIndex()>0) return true;
if(userField.getSelectedIndex()>0) return true;
if(goOnlyCheckBox.getValue()) return true;
if(uniqueNameCheckBox.getValue()) return true;
if(uniqueNameCheckBox.getValue()) return true;
if(nameSearchBox.getText().trim().length()>0) return true;
if(sequenceList.getValue().trim().length()>0) return true;
return false ;
}
@UiHandler(value = {"pageSizeSelector"})
public void changePageSize(ChangeEvent changeEvent) {
pageSize = Integer.parseInt(pageSizeSelector.getSelectedValue());
dataGrid.setPageSize(pageSize);
reload();
}
@UiHandler(value = {"typeList", "userField", "goOnlyCheckBox","uniqueNameCheckBox"})
public void searchType(ChangeEvent changeEvent) {
reload();
}
@UiHandler("nameSearchBox")
public void searchName(KeyUpEvent keyUpEvent) {
reload();
}
@UiHandler("showAllSequences")
public void setShowAllSequences(ClickEvent clickEvent) {
nameSearchBox.setText("");
sequenceList.setText("");
userField.setSelectedIndex(0);
typeList.setSelectedIndex(0);
uniqueNameCheckBox.setValue(false);
goOnlyCheckBox.setValue(false);
reload();
}
private void handleDetails() {
// if (showDetails) {
// toggleAnnotation.setText("Hide Details");
// toggleAnnotation.setIcon(IconType.EYE_SLASH);
// } else {
// toggleAnnotation.setText("Show Details");
// toggleAnnotation.setIcon(IconType.INFO_CIRCLE);
// }
tabPanel.setVisible(showDetails && singleSelectionModel.getSelectedObject() != null);
}
//
// @UiHandler("toggleAnnotation")
// void toggleAnnotation(ClickEvent clickEvent) {
// showDetails = !showDetails;
// handleDetails();
// }
private static AnnotationInfo getChildAnnotation(AnnotationInfo annotationInfo, String uniqueName) {
for (AnnotationInfo childAnnotation : annotationInfo.getChildAnnotations()) {
if (childAnnotation.getUniqueName().equalsIgnoreCase(uniqueName)) {
return childAnnotation;
}
}
return null;
}
// used by javascript function
public void enableGoto(int geneIndex, String uniqueName) {
AnnotationInfo annotationInfo = dataGrid.getVisibleItem(Math.abs(dataGrid.getVisibleRange().getStart() - geneIndex));
selectedAnnotationInfo = getChildAnnotation(annotationInfo, uniqueName);
exonDetailPanel.updateData(selectedAnnotationInfo);
updateAnnotationInfo(selectedAnnotationInfo);
selectedChildUniqueName = selectedAnnotationInfo.getUniqueName();
}
// used by javascript function
public void displayTranscript(int geneIndex, String uniqueName) {
// for some reason doesn't like call enableGoto
enableGoto(geneIndex, uniqueName);
// for some reason doesn't like call gotoAnnotation
Integer min = selectedAnnotationInfo.getMin() - 50;
Integer max = selectedAnnotationInfo.getMax() + 50;
min = min < 0 ? 0 : min;
MainPanel.updateGenomicViewerForLocation(selectedAnnotationInfo.getSequence(), min, max, false, false);
}
// also used by javascript function
public void displayFeature(int featureIndex) {
AnnotationInfo annotationInfo = dataGrid.getVisibleItem(Math.abs(dataGrid.getVisibleRange().getStart() - featureIndex));
String type = annotationInfo.getType();
if (type.equals("transposable_element") || type.equals("repeat_region") || type.equals("terminator")) {
// do nothing
} else {
exonDetailPanel.updateData(annotationInfo);
}
// gotoAnnotation.setEnabled(true);
// deleteAnnotation.setEnabled(true);
Integer min = selectedAnnotationInfo.getMin() - 50;
Integer max = selectedAnnotationInfo.getMax() + 50;
min = min < 0 ? 0 : min;
MainPanel.updateGenomicViewerForLocation(selectedAnnotationInfo.getSequence(), min, max, false, false);
}
public static native void exportStaticMethod(AnnotatorPanel annotatorPanel) /*-{
$wnd.displayTranscript = $entry(annotatorPanel.@org.bbop.apollo.gwt.client.AnnotatorPanel::displayTranscript(ILjava/lang/String;));
$wnd.displayFeature = $entry(annotatorPanel.@org.bbop.apollo.gwt.client.AnnotatorPanel::displayFeature(I));
$wnd.enableGoto = $entry(annotatorPanel.@org.bbop.apollo.gwt.client.AnnotatorPanel::enableGoto(ILjava/lang/String;));
}-*/;
private class CustomTableBuilder extends AbstractCellTableBuilder<AnnotationInfo> {
public CustomTableBuilder() {
super(dataGrid);
}
@Override
protected void buildRowImpl(AnnotationInfo rowValue, int absRowIndex) {
buildAnnotationRow(rowValue, absRowIndex, false);
if (showingTranscripts.contains(rowValue.getUniqueName())) {
// add some random rows
Set<AnnotationInfo> annotationInfoSet = rowValue.getChildAnnotations();
if (annotationInfoSet.size() > 0) {
for (AnnotationInfo annotationInfo : annotationInfoSet) {
buildAnnotationRow(annotationInfo, absRowIndex, true);
}
}
}
}
private void buildAnnotationRow(final AnnotationInfo rowValue, int absRowIndex, boolean showTranscripts) {
TableRowBuilder row = startRow();
TableCellBuilder td = row.startTD();
td.style().outlineStyle(Style.OutlineStyle.NONE).endStyle();
if (showTranscripts) {
// TODO: this is ugly, but it works
// a custom cell rendering might work as well, but not sure
String transcriptStyle = "margin-left: 10px; color: green; padding-left: 5px; padding-right: 5px; border-radius: 15px; background-color: #EEEEEE;";
String htmlString = "<a style='" + transcriptStyle + "' onclick=\"enableGoto(" + absRowIndex + ",'" + rowValue.getUniqueName() + "');\">" + rowValue.getName() + "</a>";
htmlString += " <button type='button' class='btn btn-primary' onclick=\"displayTranscript(" + absRowIndex + ",'" + rowValue.getUniqueName() + "')\" style=\"line-height: 0; margin-bottom: 5px;\" ><i class='fa fa-arrow-circle-o-right fa-lg'></i></a>";
HTML html = new HTML(htmlString);
SafeHtml safeHtml = new SafeHtmlBuilder().appendHtmlConstant(html.getHTML()).toSafeHtml();
td.html(safeHtml);
} else {
String type = rowValue.getType();
if (type.equals("gene") || type.equals("pseudogene")) {
renderCell(td, createContext(0), nameColumn, rowValue);
} else {
// handles singleton features
String featureStyle = "color: #800080;";
HTML html = new HTML("<a style='" + featureStyle + "' ondblclick=\"displayFeature(" + absRowIndex + ")\");\">" + rowValue.getName() + "</a>");
SafeHtml htmlString = new SafeHtmlBuilder().appendHtmlConstant(html.getHTML()).toSafeHtml();
td.html(htmlString);