Newer
Older
for(int i=0; i<bamList.size(); i++)
addToViewMenu(i);
menu.add(new JSeparator());
cbStackView.setFont(viewMenu.getFont());
cbIsizeStackView.setFont(viewMenu.getFont());
cbPairedStackView.setFont(viewMenu.getFont());
cbStrandStackView.setFont(viewMenu.getFont());
cbCoverageView.setFont(viewMenu.getFont());
baseQualityColour.setFont(viewMenu.getFont());
colourByCoverageColour.setFont(viewMenu.getFont());
markInsertions.setFont(viewMenu.getFont());
cbIsizeStackView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
laststart = -1;
logMenuItem.setEnabled(isIsizeStackView());
viewMenu.add(cbIsizeStackView);
cbStackView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
laststart = -1;
logMenuItem.setEnabled(isIsizeStackView());
cbPairedStackView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
laststart = -1;
logMenuItem.setEnabled(isIsizeStackView());
repaint();
}
});
viewMenu.add(cbPairedStackView);
cbStrandStackView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
laststart = -1;
logMenuItem.setEnabled(isIsizeStackView());
viewMenu.add(cbStrandStackView);
cbCoverageView.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
laststart = -1;
logMenuItem.setEnabled(isIsizeStackView());
repaint();
}
});
viewMenu.add(cbCoverageView);
final JCheckBoxMenuItem checkBoxSNPs = new JCheckBoxMenuItem("SNP marks");
//
JMenu colourMenu = new JMenu("Colour By");
colourMenu.add(colourByCoverageColour);
baseQualityColour.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(baseQualityColour.isSelected())
{
checkBoxSNPs.setSelected(false);
isSNPs = false;
}
repaint();
}
});
colourMenu.add(baseQualityColour);
menu.add(colourMenu);
//
JCheckBoxMenuItem checkBoxOrientation = new JCheckBoxMenuItem("Orientation");
checkBoxOrientation.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
isOrientation = !isOrientation;
repaint();
}
});
showMenu.add(checkBoxOrientation);
JCheckBoxMenuItem checkBoxSingle = new JCheckBoxMenuItem("Single Reads");
checkBoxSingle.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
repaint();
isSingle = !isSingle;
}
});
showMenu.add(checkBoxSingle);
checkBoxSNPs.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (isSNPs && bases == null)
{
JOptionPane.showMessageDialog(null,
"No reference sequence supplied to identify SNPs.", "SNPs",
JOptionPane.INFORMATION_MESSAGE);
}
isSNPs = !isSNPs;
if(isSNPs)
baseQualityColour.setSelected(false);
repaint();
}
});
showMenu.add(checkBoxSNPs);
markInsertions.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
repaint();
}
});
showMenu.add(markInsertions);
JCheckBoxMenuItem checkBoxCoverage = new JCheckBoxMenuItem("Coverage");
checkBoxCoverage.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
isCoverage = !isCoverage;
coveragePanel.setVisible(isCoverage);
graphMenu.add(checkBoxCoverage);
JCheckBoxMenuItem checkBoxSNP = new JCheckBoxMenuItem("SNP");
checkBoxSNP.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
isSNPplot = !isSNPplot;
snpPanel.setVisible(isSNPplot);
repaint();
}
});
graphMenu.add(checkBoxSNP);
menu.add(graphMenu);
final JCheckBoxMenuItem checkBoxSync =
new JCheckBoxMenuItem("Asynchronous", asynchronous);
checkBoxSync.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
{
asynchronous = checkBoxSync.isSelected();
}
});
JMenu maxHeightMenu = new JMenu("BamView Height");
final String hgts[] =
{"500", "800", "1000", "1500", "2500", "5000", "50000"};
ButtonGroup bgroup = new ButtonGroup();
for(int i=0; i<hgts.length; i++)
{
final String hgt = hgts[i];
final JCheckBoxMenuItem maxHeightMenuItem = new JCheckBoxMenuItem(hgt);
bgroup.add(maxHeightMenuItem);
maxHeightMenuItem.setSelected(hgts[i].equals(Integer.toString(maxHeight)));
maxHeightMenu.add(maxHeightMenuItem);
maxHeightMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(maxHeightMenuItem.isSelected())
maxHeight = Integer.parseInt(hgt);
int start = getBaseAtStartOfView();
setDisplay(start, nbasesInView+start, null);
}
});
}
logMenuItem.setEnabled(isIsizeStackView());
logMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
logScale = logMenuItem.isSelected();
repaint();
}
});
JMenuItem filter = new JMenuItem("Filter by Flag...");
menu.add(filter);
filter.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
new SAMRecordFilter(BamView.this);
}
});
//
JMenu coverageMenu = new JMenu("Coverage Options");
coverageView.init(this, 0.f, 0, 0);
coverageView.createMenus(coverageMenu);
viewMenu.add(new JSeparator());
viewMenu.add(coverageMenu);
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
private JComponent bamTopPanel(final JFrame frame)
{
final JComponent topPanel;
if(feature_display != null)
{
this.selection = feature_display.getSelection();
topPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
}
else
{
topPanel = new JMenuBar();
frame.setJMenuBar((JMenuBar)topPanel);
JMenu fileMenu = new JMenu("File");
topPanel.add(fileMenu);
JMenuItem readBam = new JMenuItem("Open new BamView ...");
fileMenu.add(readBam);
readBam.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String[] s = new String[0];
BamView.main(s);
}
});
JMenuItem close = new JMenuItem("Close");
fileMenu.add(close);
close.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
BamView.this.setVisible(false);
Component comp = BamView.this;
while( !(comp instanceof JFrame) )
comp = comp.getParent();
((JFrame)comp).dispose();
}
});
JMenuItem exit = new JMenuItem("Exit");
fileMenu.add(new JSeparator());
fileMenu.add(exit);
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
int status = JOptionPane.showConfirmDialog(BamView.this,
"Exit BamView?", "Exit",
JOptionPane.OK_CANCEL_OPTION);
if(status != JOptionPane.OK_OPTION)
return;
System.exit(0);
}
});
addKeyListener(new KeyAdapter()
{
public void keyPressed(final KeyEvent event)
{
switch (event.getKeyCode())
{
case KeyEvent.VK_UP:
setZoomLevel((int) (BamView.this.nbasesInView * 1.1));
break;
case KeyEvent.VK_DOWN:
if (showBaseAlignment)
break;
setZoomLevel((int) (BamView.this.nbasesInView * .9));
break;
default:
break;
}
}
});
}
if(seqNames.size() > 1)
{
int len = 0;
for(int i=0; i<seqNames.size(); i++)
len += seqLengths.get(seqNames.get(i));
if(feature_display != null &&
len == feature_display.getSequenceLength())
concatSequences = true;
else if(bases != null &&
len == bases.getLength() )
concatSequences = true;
}
// auto hide top panel
final JCheckBox buttonAutoHide = new JCheckBox("Hide", (feature_display != null));
buttonAutoHide.setToolTipText("Auto-Hide");
final MouseMotionListener mouseMotionListener = new MouseMotionListener()
{
public void mouseDragged(MouseEvent event)
{
handleCanvasMouseDrag(event);
}
public void mouseMoved(MouseEvent e)
{
lastMousePoint = e.getPoint();
int thisHgt = HEIGHT;
if (thisHgt < 5)
thisHgt = 15;
int y = (int) (e.getY() - jspView.getViewport().getViewRect().getY());
if (y < thisHgt)
{
topPanel.setVisible(true);
}
else
{
if (buttonAutoHide.isSelected())
topPanel.setVisible(false);
}
mainPanel.repaint();
mainPanel.revalidate();
}
};
addMouseMotionListener(mouseMotionListener);
combo = new JComboBox(seqNames);
combo.setEditable(false);
combo.setMaximumRowCount(20);
combo.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
laststart = -1;
if(feature_display != null)
setZoomLevel(feature_display.getMaxVisibleBases());
else
setZoomLevel(BamView.this.nbasesInView);
}
});
topPanel.add(combo);
if(feature_display == null)
{
final JTextField baseText = new JTextField(8);
JButton goTo = new JButton("GoTo:");
goTo.setToolTipText("Go to base position");
goTo.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
int basePosition = Integer.parseInt(baseText.getText());
scrollBar.setValue(basePosition);
}
catch (NumberFormatException nfe)
{
JOptionPane.showMessageDialog(BamView.this,
"Expecting a base number!", "Number Format",
JOptionPane.WARNING_MESSAGE);
}
}
});
topPanel.add(goTo);
topPanel.add(baseText);
JButton zoomIn = new JButton("-");
Insets ins = new Insets(1,1,1,1);
zoomIn.setMargin(ins);
zoomIn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
setZoomLevel((int) (BamView.this.nbasesInView * 1.1));
}
});
topPanel.add(zoomIn);
JButton zoomOut = new JButton("+");
zoomOut.setMargin(ins);
zoomOut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (showBaseAlignment)
return;
setZoomLevel((int) (BamView.this.nbasesInView * .9));
}
});
topPanel.add(zoomOut);
}
topPanel.add(buttonAutoHide);
return topPanel;
}
public void setVisible(boolean visible)
{
super.setVisible(visible);
mainPanel.setVisible(visible);
private void setViewportMidPoint()
{
Point p = jspView.getViewport().getLocation();
p.y = (getHeight() - jspView.getViewport().getViewRect().height)/2;
jspView.getViewport().setViewPosition(p);
}
if(feature_display != null)
return feature_display.getForwardBaseAtLeftEdge();
else
return scrollBar.getValue();
}
/**
* Set the panel size based on the number of bases visible
* and repaint.
* @param nbasesInView
*/
if(isBaseAlignmentView(pixPerBase))
this.nbasesInView = (int)(mainPanel.getWidth()/pixPerBase);
if(ruler == null)
ruler = new Ruler();
jspView.setColumnHeaderView(ruler);
showBaseAlignment = true;
markInsertions.setEnabled(true);
if(!cbCoverageView.isSelected() && nbasesInView >= MAX_BASES)
{
cbLastSelected = getSelectedCheckBoxMenuItem();
cbCoverageView.setSelected(true);
}
else if(cbCoverageView.isSelected() && nbasesInView < MAX_BASES && cbLastSelected != null)
{
cbLastSelected.setSelected(true);
cbLastSelected = null;
}
jspView.getVerticalScrollBar().setValue(
jspView.getVerticalScrollBar().getMaximum());
markInsertions.setEnabled(false);
{
scrollBar.setValues(startValue, nbasesInView, 1,
getMaxBasesInPanel(getSequenceLength()));
scrollBar.setUnitIncrement(nbasesInView/20);
scrollBar.setBlockIncrement(nbasesInView);
}
* Set the start and end base positions to display.
* @param start
* @param end
* @param event
public void setDisplay(int start,
int end,
DisplayAdjustmentEvent event)
this.startBase = start;
this.endBase = end;
else
{
if(feature_display == null)
pixPerBase = 1000.f/(float)(end-start+1);
else
pixPerBase = feature_display.getWidth()/(float)(end-start+1);
}
if(event == null)
{
this.startBase = -1;
this.endBase = -1;
}
/**
* Return an Artemis entry from a file
* @param entryFileName
* @param entryGroup
* @return
* @throws NoSequenceException
*/
private Entry getEntry(final String entryFileName, final EntryGroup entryGroup)
throws NoSequenceException
{
final Document entry_document = DocumentFactory.makeDocument(entryFileName);
final EntryInformation artemis_entry_information =
Options.getArtemisEntryInformation();
//System.out.println(entryFileName);
final uk.ac.sanger.artemis.io.Entry new_embl_entry =
EntryFileDialog.getEntryFromFile(null, entry_document,
artemis_entry_information,
false);
if(new_embl_entry == null) // the read failed
return null;
Entry entry = null;
try
{
if(entryGroup.getSequenceEntry() != null)
bases = entryGroup.getSequenceEntry().getBases();
else
entry = new Entry(bases,new_embl_entry);
entryGroup.add(entry);
}
catch(OutOfRangeException e)
{
new MessageDialog(null, "read failed: one of the features in " +
entryFileName + " has an out of range " +
"location: " + e.getMessage());
}
return entry;
}
private boolean isShowScale()
{
return (feature_display == null ? true : false);
}
public JScrollPane getJspView()
{
return jspView;
}
/**
* Handle a mouse drag event on the drawing canvas.
**/
if(event.getButton() == MouseEvent.BUTTON3 || bases == null)
tjc
committed
highlightSAMRecord = null;
if(event.getClickCount() > 1)
{
getSelection().clear();
repaint();
return;
}
highlightRange(event,
MouseEvent.BUTTON1_DOWN_MASK & MouseEvent.BUTTON2_DOWN_MASK);
}
/**
*
* @param event
* @param onmask
*/
private void highlightRange(MouseEvent event, int onmask)
{
int start = (int) ( ( (event.getPoint().getX())/pixPerBase) + getBaseAtStartOfView() );
if(start < 1)
start = 1;
if(start > seqLength)
start = seqLength;
if (dragStart < 0 && (event.getModifiersEx() & onmask) == onmask)
dragStart = start;
else if((event.getModifiersEx() & onmask) != onmask)
dragStart = -1;
if(dragStart < 0)
drag_range = new MarkerRange (bases.getForwardStrand(), start, start);
else
drag_range = new MarkerRange (bases.getForwardStrand(), dragStart, start);
getSelection().setMarkerRange(drag_range);
repaint();
/**
* Get the colour for the given read given to it by the coverage plot.
* @param samRecord
* @return
*/
private Color getColourByCoverageColour(SAMRecord samRecord)
{
LineAttributes lines[] = CoveragePanel.getLineAttributes(bamList.size());
int fileIndex = 0;
if(bamList.size()>1)
fileIndex = (Integer) samRecord.getAttribute("FL");
return lines[fileIndex].getLineColour();
}
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
protected int getMaxBases()
{
return MAX_BASES;
}
protected void setMaxBases(int max)
{
MAX_BASES = max;
}
private boolean isStackView()
{
return cbStackView.isSelected();
}
private boolean isPairedStackView()
{
return cbPairedStackView.isSelected();
}
private boolean isStrandStackView()
{
return cbStrandStackView.isSelected();
}
private boolean isCoverageView(float pixPerBase)
{
if(isBaseAlignmentView(pixPerBase))
return false;
return cbCoverageView.isSelected();
}
private boolean isIsizeStackView()
{
return cbIsizeStackView.isSelected();
}
private boolean isBaseAlignmentView(float pixPerBase)
{
if(pixPerBase*1.08f >= ALIGNMENT_PIX_PER_BASE)
return true;
return false;
}
private JCheckBoxMenuItem getSelectedCheckBoxMenuItem()
{
if(isStackView())
return cbStackView;
if(isPairedStackView())
return cbPairedStackView;
if(isStrandStackView())
return cbStrandStackView;
if(isIsizeStackView())
return cbIsizeStackView;
return cbCoverageView;
}
private Selection getSelection()
{
return selection;
}
protected int getBasesInView()
{
return nbasesInView;
}
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
private String getVersion()
{
final ClassLoader cl = this.getClass().getClassLoader();
try
{
String line;
InputStream in = cl.getResourceAsStream("etc/versions");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while((line = reader.readLine()) != null)
{
if(line.startsWith("BamView"))
return line.substring( "BamView".length() ).trim();
}
reader.close();
in.close();
}
catch (Exception ex)
{
}
return null;
}
public void displayAdjustmentValueChanged(final DisplayAdjustmentEvent event)
if(event.getType() == DisplayAdjustmentEvent.REV_COMP_EVENT &&
event.isRevCompDisplay())
JOptionPane.showMessageDialog(this,
"Flipping the display is not supported by BamView.", "Warning",
JOptionPane.WARNING_MESSAGE);
if(!asynchronous)
{
// if not asynchronous
displayAdjustmentWork(event);
return;
}
public Object construct()
{
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
if(event.getStart() != ((FeatureDisplay)event.getSource()).getForwardBaseAtLeftEdge())
{
waitingFrame.showWaiting("waiting...", mainPanel);
waitingFrame.setVisible(false);
return null;
}
};
worker.start();
/**
* Carry out the display agjustment event action.
* @param event
*/
private void displayAdjustmentWork(final DisplayAdjustmentEvent event)
{
if(event.getType() == DisplayAdjustmentEvent.SCALE_ADJUST_EVENT)
{
laststart = -1;
BamView.this.startBase = event.getStart();
BamView.this.endBase = event.getEnd();
int width = feature_display.getMaxVisibleBases();
setZoomLevel(width);
repaint();
}
else
{
setDisplay(event.getStart(),
event.getStart()+feature_display.getMaxVisibleBases(), event);
repaint();
}
}
public void selectionChanged(SelectionChangeEvent event)
{
repaint();
setPreferredSize(new Dimension(mainPanel.getWidth(), 15));
setBackground(Color.white);
setFont(getFont().deriveFont(11.f));
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawBaseScale(g2, start, end, 12);
}
private void drawBaseScale(Graphics2D g2, int start, int end, int ypos)
{
int startMark = (((int)(start/10))*10)+1;
if(end > getSequenceLength())
end = getSequenceLength();
g2.drawString(Integer.toString(i), xpos, ypos);
xpos+=(ALIGNMENT_PIX_PER_BASE/2);
g2.drawLine(xpos, ypos+1, xpos, ypos+5);
}
}
/**
* Popup menu listener
*/
class PopupListener extends MouseAdapter
{
JMenuItem gotoMateMenuItem;
tjc
committed
JMenuItem showDetails;
public void mouseClicked(MouseEvent e)
{
if(e.isPopupTrigger() ||
e.getButton() == MouseEvent.BUTTON3)
return;
BamView.this.requestFocus();
if(e.getClickCount() > 1)
getSelection().clear();
else if(e.getButton() == MouseEvent.BUTTON1)
highlightSAMRecord = mouseOverSAMRecord;
else
highlightRange(e, MouseEvent.BUTTON2_DOWN_MASK);
repaint();
}
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e)
{
if(e.isPopupTrigger())
if(gotoMateMenuItem != null)
popup.remove(gotoMateMenuItem);
tjc
committed
if(showDetails != null)
popup.remove(showDetails);
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
if( mouseOverSAMRecord != null &&
mouseOverSAMRecord.getReadPairedFlag() &&
!mouseOverSAMRecord.getMateUnmappedFlag() )
{
final SAMRecord thisSAMRecord = mouseOverSAMRecord;
gotoMateMenuItem = new JMenuItem("Go to mate of : "+
thisSAMRecord.getReadName());
gotoMateMenuItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String name = thisSAMRecord.getMateReferenceName();
if(name.equals("="))
name = thisSAMRecord.getReferenceName();
int offset = getSequenceOffset(name);
if(feature_display != null)
feature_display.makeBaseVisible(
thisSAMRecord.getMateAlignmentStart()+offset);
else
scrollBar.setValue(
thisSAMRecord.getMateAlignmentStart()+offset-
(nbasesInView/2));
highlightSAMRecord = thisSAMRecord;
}
});
popup.add(gotoMateMenuItem);
tjc
committed
}
if( mouseOverSAMRecord != null)
{
final SAMRecord thisSAMRecord = mouseOverSAMRecord;
showDetails = new JMenuItem("Show details of : "+
thisSAMRecord.getReadName());
showDetails.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FileViewer viewDetail = new FileViewer(thisSAMRecord.getReadName(), true, false);