use of javafx.scene.control.ContextMenu in project jvarkit by lindenb.
the class BamStage method makeRecordTable.
private TableView<SAMRecord> makeRecordTable() {
final Font font1 = new Font("Courier", 9);
/* get max SEQ length displayed */
int prefnum = 0;
try {
prefnum = Integer.parseInt(this.owner.preferences.get(this.owner.pref_bam_max_seq_length_displayed.key, "500"));
} catch (final NumberFormatException err) {
prefnum = 500;
}
final int max_seq_length = prefnum;
/* get MAX number of items in cigar */
try {
prefnum = Integer.parseInt(this.owner.preferences.get(this.owner.pref_bam_max_cigar_items_displayed.key, "50"));
} catch (final NumberFormatException err) {
prefnum = 50;
}
final int max_items_in_cigar = prefnum;
/* utility function to make column specific of paired data */
final Function<TableColumn<SAMRecord, ?>, TableColumn<SAMRecord, ?>> insertPairdColumn = TC -> {
this.pairedEndColumns.add(TC);
return TC;
};
final TableView<SAMRecord> table = new TableView<SAMRecord>();
table.getColumns().add(makeColumn("Read-Name", REC -> REC.getReadName()));
table.getColumns().add(makeColumn("Flag", REC -> REC.getFlags()));
table.getColumns().add(makeColumn("Ref", REC -> REC.getReferenceName()));
table.getColumns().add(formatIntegerColumn(makeColumn("UStart", REC -> {
if (REC.getReadUnmappedFlag() || REC.getCigar() == null)
return null;
final int upos = REC.getUnclippedStart();
if (upos == REC.getAlignmentStart())
return null;
return upos;
})));
table.getColumns().add(formatIntegerColumn(makeColumn("Start", REC -> {
final int pos = REC.getAlignmentStart();
if (pos == SAMRecord.NO_ALIGNMENT_START)
return null;
return pos;
})));
table.getColumns().add(formatIntegerColumn(makeColumn("End", REC -> {
final int pos = REC.getAlignmentEnd();
if (pos == SAMRecord.NO_ALIGNMENT_START)
return null;
return pos;
})));
table.getColumns().add(formatIntegerColumn(makeColumn("UEnd", REC -> {
if (REC.getReadUnmappedFlag() || REC.getCigar() == null)
return null;
final int upos = REC.getUnclippedEnd();
if (upos == REC.getAlignmentEnd())
return null;
return upos;
})));
table.getColumns().add(makeColumn("MAPQ", REC -> REC.getMappingQuality()));
TableColumn<SAMRecord, Cigar> tc0 = makeColumn("CIGAR", REC -> REC.getCigar());
tc0.setCellFactory(tv -> new TableCell<SAMRecord, Cigar>() {
final TextFlow textFlow = new TextFlow();
@Override
protected void updateItem(final Cigar cigar, boolean empty) {
super.updateItem(cigar, empty);
setText(null);
setTextOverrun(OverrunStyle.CLIP);
if (cigar == null || cigar.isEmpty()) {
// setText(null);
setGraphic(null);
return;
}
if (cigar.numCigarElements() >= max_items_in_cigar) {
setGraphic(null);
setText(" num(items) > " + max_items_in_cigar);
return;
}
final List<Text> L = new ArrayList<>(cigar.numCigarElements());
for (final CigarElement ce : cigar.getCigarElements()) {
final Text txt = new Text(String.valueOf(ce.getLength()) + (char) CigarOperator.enumToCharacter(ce.getOperator()));
txt.setFont(font1);
switch(ce.getOperator()) {
case H:
case S:
txt.setStroke(Color.ORANGE);
break;
case X:
case N:
case D:
case I:
txt.setStroke(Color.RED);
break;
case M:
txt.setStroke(Color.BLUE);
break;
case EQ:
txt.setStroke(Color.GREEN);
break;
case P:
txt.setStroke(Color.GRAY);
break;
default:
txt.setStroke(Color.BLACK);
break;
}
L.add(txt);
}
this.textFlow.setLineSpacing(0.1);
this.textFlow.setMaxHeight(10);
this.textFlow.setPrefHeight(10);
this.textFlow.getChildren().setAll(L);
this.setGraphic(textFlow);
}
});
table.getColumns().add(tc0);
table.getColumns().add(insertPairdColumn.apply(formatIntegerColumn(makeColumn("LEN", REC -> !REC.getReadPairedFlag() || REC.getMateUnmappedFlag() ? null : REC.getInferredInsertSize()))));
table.getColumns().add(insertPairdColumn.apply(makeColumn("Mate-Ref", REC -> !REC.getReadPairedFlag() || REC.getMateUnmappedFlag() ? null : REC.getMateReferenceName())));
table.getColumns().add(insertPairdColumn.apply(formatIntegerColumn(makeColumn("Mate-Pos", REC -> !REC.getReadPairedFlag() || REC.getMateUnmappedFlag() ? null : REC.getMateAlignmentStart()))));
TableColumn<SAMRecord, String> tc = makeColumn("SEQ", REC -> REC.getReadString());
// http://stackoverflow.com/questions/42187987/
tc.setCellFactory(tv -> new TableCell<SAMRecord, String>() {
final TextFlow textFlow = new TextFlow();
@Override
protected void updateItem(final String item, boolean empty) {
super.updateItem(item, empty);
setText(null);
setTextOverrun(OverrunStyle.CLIP);
if (item == null) {
// setText(null);
setGraphic(null);
return;
}
if (item.length() >= max_seq_length) {
setGraphic(null);
setText("len > " + max_seq_length);
return;
}
final List<Text> L = new ArrayList<>(item.length());
for (int i = 0; i < item.length(); ++i) {
final Text txt = new Text(String.valueOf(item.charAt(i)));
txt.setFont(font1);
txt.setStroke(JfxNgs.BASE2COLOR.apply(item.charAt(i)));
L.add(txt);
}
this.textFlow.setLineSpacing(0.1);
this.textFlow.setMaxHeight(10);
this.textFlow.setPrefHeight(10);
this.textFlow.getChildren().setAll(L);
this.setGraphic(textFlow);
}
});
table.getColumns().add(tc);
tc = makeColumn("QUAL", REC -> REC.getBaseQualityString());
tc.setCellFactory(tv -> new TableCell<SAMRecord, String>() {
final TextFlow textFlow = new TextFlow();
@Override
protected void updateItem(final String item, boolean empty) {
super.updateItem(item, empty);
setTextOverrun(OverrunStyle.CLIP);
setText(null);
if (item == null) {
// setText(null);
setGraphic(null);
return;
}
if (item.length() >= max_seq_length) {
setGraphic(null);
setText("len > " + max_seq_length);
return;
}
final List<Text> L = new ArrayList<>(item.length());
for (int i = 0; i < item.length(); ++i) {
char c = item.charAt(i);
int ch = (int) c;
double qual = 93.0;
if (!(ch < 33 || ch > 126)) {
qual = SAMUtils.fastqToPhred(c);
}
final Text txt = new Text(String.valueOf(c));
txt.setFont(font1);
txt.setStroke(Color.gray(qual / 93.0));
L.add(txt);
}
this.textFlow.setLineSpacing(0.1);
this.textFlow.setMaxHeight(10);
this.textFlow.setPrefHeight(10);
this.textFlow.getChildren().setAll(L);
this.setGraphic(textFlow);
}
});
table.getColumns().add(tc);
final short SA = SAMTagUtil.getSingleton().makeBinaryTag("SA");
table.getColumns().add(makeColumn("SA", REC -> REC.getAttribute(SA) == null ? null : "*"));
table.getColumns().add(makeColumn("NM", REC -> REC.getIntegerAttribute("NM")));
table.setPlaceholder(new Label("No Read."));
final ContextMenu ctxMenu = new ContextMenu();
ctxMenu.getItems().addAll(super.buildItemsForContextMenu());
table.setContextMenu(ctxMenu);
return table;
}
Aggregations