Skip to content
Snippets Groups Projects
BamView.java 78.6 KiB
Newer Older
tjc's avatar
tjc committed
/* JamView
 *
 * created: 2009
 *
 * This file is part of Artemis
 *
 * Copyright(C) 2009  Genome Research Limited
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or(at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
tjc's avatar
tjc committed
package uk.ac.sanger.artemis.components.alignment;

import java.awt.AlphaComposite;
tjc's avatar
tjc committed
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Composite;
tjc's avatar
tjc committed
import java.awt.Dimension;
tjc's avatar
tjc committed
import java.awt.FlowLayout;
tjc's avatar
tjc committed
import java.awt.FontMetrics;
tjc's avatar
tjc committed
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
tjc's avatar
tjc committed
import java.awt.Point;
import java.awt.Rectangle;
tjc's avatar
tjc committed
import java.awt.Stroke;
tjc's avatar
tjc committed
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
tjc's avatar
tjc committed
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
tjc's avatar
tjc committed
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
tjc's avatar
tjc committed
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
tjc's avatar
tjc committed
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
tjc's avatar
tjc committed
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
tjc's avatar
tjc committed
import java.util.Collections;
tjc's avatar
tjc committed
import java.util.Enumeration;
tjc's avatar
tjc committed
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import javax.swing.ButtonGroup;
tjc's avatar
tjc committed
import javax.swing.JButton;
tjc's avatar
tjc committed
import javax.swing.JCheckBox;
tjc's avatar
tjc committed
import javax.swing.JCheckBoxMenuItem;
tjc's avatar
tjc committed
import javax.swing.JComboBox;
tjc's avatar
tjc committed
import javax.swing.JComponent;
tjc's avatar
tjc committed
import javax.swing.JFrame;
import javax.swing.JMenu;
tjc's avatar
tjc committed
import javax.swing.JMenuBar;
tjc's avatar
tjc committed
import javax.swing.JOptionPane;
tjc's avatar
tjc committed
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
tjc's avatar
tjc committed
import javax.swing.JScrollBar;
tjc's avatar
tjc committed
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
tjc's avatar
tjc committed
import javax.swing.JTextField;
tjc's avatar
tjc committed
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
tjc's avatar
tjc committed

import net.sf.samtools.AlignmentBlock;
tjc's avatar
tjc committed
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMFileReader;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMSequenceRecord;
import net.sf.samtools.SAMFileReader.ValidationStringency;
import net.sf.samtools.util.CloseableIterator;

tjc's avatar
tjc committed
import uk.ac.sanger.artemis.Entry;
import uk.ac.sanger.artemis.EntryGroup;
import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.Selection;
import uk.ac.sanger.artemis.SelectionChangeEvent;
import uk.ac.sanger.artemis.SelectionChangeListener;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.SimpleEntryGroup;
import uk.ac.sanger.artemis.components.DisplayAdjustmentEvent;
import uk.ac.sanger.artemis.components.DisplayAdjustmentListener;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.components.EntryFileDialog;
import uk.ac.sanger.artemis.components.FeatureDisplay;
import uk.ac.sanger.artemis.components.FileViewer;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.components.MessageDialog;
import uk.ac.sanger.artemis.components.SwingWorker;
import uk.ac.sanger.artemis.editor.MultiLineToolTipUI;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.io.EntryInformation;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.io.Range;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.sequence.Bases;
import uk.ac.sanger.artemis.sequence.MarkerRange;
tjc's avatar
tjc committed
import uk.ac.sanger.artemis.sequence.NoSequenceException;
import uk.ac.sanger.artemis.util.Document;
import uk.ac.sanger.artemis.util.DocumentFactory;
import uk.ac.sanger.artemis.util.OutOfRangeException;

public class BamView extends JPanel
tjc's avatar
tjc committed
                     implements DisplayAdjustmentListener, SelectionChangeListener
tjc's avatar
tjc committed
{
  private static final long serialVersionUID = 1L;
tjc's avatar
tjc committed
  private List<SAMRecord> readsInView;
tjc's avatar
tjc committed
  private Hashtable<String, Integer> seqLengths = new Hashtable<String, Integer>();
  private Hashtable<String, Integer> offsetLengths;
tjc's avatar
tjc committed
  private Vector<String> seqNames = new Vector<String>();
  private String bam;
tjc's avatar
tjc committed

  private SAMRecordFlagPredicate samRecordFlagPredicate;
tjc's avatar
tjc committed
  private SAMRecordMapQPredicate samRecordMapQPredicate;
tjc's avatar
tjc committed
  private Bases bases;
tjc's avatar
tjc committed
  private JScrollPane jspView;
tjc's avatar
tjc committed
  private JScrollBar scrollBar;
  
tjc's avatar
tjc committed
  private JComboBox combo;
tjc's avatar
tjc committed
  private boolean isSingle = false;
  private boolean isSNPs = false;
  private boolean isStackView = false;
  private boolean isPairedStackView = false;
tjc's avatar
tjc committed
  private boolean isStrandStackView = false;
  private boolean isCoverage = false;
tjc's avatar
tjc committed
  
  private FeatureDisplay feature_display;
  private Selection selection;
  private JPanel mainPanel;
  private CoveragePanel coveragePanel;
  private boolean showScale = true;
  private boolean logScale = false;
tjc's avatar
tjc committed
  private int nbasesInView;
  
  private int startBase = -1;
  private int endBase   = -1;
tjc's avatar
tjc committed
  private int laststart;
  private int lastend;
  private int maxUnitIncrement = 8;
  
  private boolean asynchronous = true;
  private boolean showBaseAlignment = false;
  
  private JCheckBoxMenuItem logMenuItem = new JCheckBoxMenuItem("Use Log Scale", logScale);
  private JCheckBoxMenuItem checkBoxStackView = new JCheckBoxMenuItem("Stack View");
  private JCheckBoxMenuItem baseQualityColour = new JCheckBoxMenuItem("Colour by Base Quality");;
  private JCheckBoxMenuItem markInsertions = new JCheckBoxMenuItem("Mark Insertions");
    AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
  
  /** Used to colour the frames. */
  private Color lightGrey = new Color(200, 200, 200);
  private Color darkGreen = new Color(0, 150, 0);
  private Color darkOrange = new Color(255,140,0);
  private Color deepPink   = new Color(139,10,80);
  private Point lastMousePoint = null;
  private SAMRecord mouseOverSAMRecord = null;
  private SAMRecord highlightSAMRecord = null;
  private String mouseOverInsertion;
  // record of where a mouse drag starts
  private int dragStart = -1;
  private int maxHeight = 800;
tjc's avatar
tjc committed
  private boolean concatSequences = false;
tjc's avatar
tjc committed
  private int ALIGNMENT_PIX_PER_BASE;
tjc's avatar
tjc committed
  
  private JPopupMenu popup;
  private PopupMessageFrame popFrame = new PopupMessageFrame();
  private PopupMessageFrame waitingFrame = new PopupMessageFrame("waiting...");
tjc's avatar
tjc committed
  public static org.apache.log4j.Logger logger4j = 
    org.apache.log4j.Logger.getLogger(BamView.class);
  
tjc's avatar
tjc committed
                 String reference,
                 int nbasesInView)
  {
    super();
    setBackground(Color.white);
    this.bam = bam;
Loading
Loading full blame...