Skip to content
Snippets Groups Projects
BamView.java 118 KiB
Newer Older
tjc's avatar
tjc committed
/* BamView
tjc's avatar
tjc committed
 *
 * 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.GridBagConstraints;
import java.awt.GridBagLayout;
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;
import java.awt.image.BufferedImage;
tjc's avatar
tjc committed
import java.io.BufferedReader;
tjc's avatar
tjc committed
import java.io.File;
tjc's avatar
tjc committed
import java.io.FileOutputStream;
import java.io.IOException;
tjc's avatar
tjc committed
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.reflect.Field;
tjc's avatar
tjc committed
import java.net.URL;
tjc's avatar
tjc committed
import java.util.Collections;
tjc's avatar
tjc committed
import java.util.Enumeration;
import java.util.HashMap;
tjc's avatar
tjc committed
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
tjc's avatar
tjc committed
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.Box;
tjc's avatar
tjc committed
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
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;
import javax.swing.JRadioButton;
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;
import javax.swing.SwingUtilities;
tjc's avatar
tjc committed
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.text.JTextComponent;
tjc's avatar
tjc committed

import net.sf.picard.reference.ReferenceSequenceFile;
import net.sf.picard.sam.BuildBamIndex;
import net.sf.samtools.AlignmentBlock;
import net.sf.samtools.SAMException;
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.FeatureVector;
tjc's avatar
tjc committed
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.circular.TextFieldInt;
import uk.ac.sanger.artemis.components.DisplayAdjustmentEvent;
import uk.ac.sanger.artemis.components.DisplayAdjustmentListener;
import uk.ac.sanger.artemis.components.EntryEdit;
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.NonModalDialog;
import uk.ac.sanger.artemis.components.SwingWorker;
import uk.ac.sanger.artemis.components.genebuilder.AutoCompleteComboDocument;
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.FTPSeekableStream;
tjc's avatar
tjc committed
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<BamViewRecord> readsInView;
tjc's avatar
tjc committed
  private Hashtable<String, SAMFileReader> samFileReaderHash = new Hashtable<String, SAMFileReader>();

  private HashMap<String, Integer> seqLengths = new HashMap<String, Integer>();
  private HashMap<String, Integer> offsetLengths;
tjc's avatar
tjc committed
  private Vector<String> seqNames = new Vector<String>();
  protected List<Integer> hideBamList = new Vector<Integer>();
tjc's avatar
tjc committed

tjc's avatar
tjc committed
  private SAMRecordPredicate samRecordFlagPredicate;
tjc's avatar
tjc committed
  private SAMRecordMapQPredicate samRecordMapQPredicate;
tjc's avatar
tjc committed

  private SAMRecordFilter filterFrame;

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;
  private boolean isOrientation = false;
tjc's avatar
tjc committed
  private boolean isSingle = false;
  private boolean isSNPs = false;
  private boolean isCoverage = false;
tjc's avatar
tjc committed
  private boolean isSNPplot = false;
tjc's avatar
tjc committed
  
  private EntryEdit entry_edit;
  private FeatureDisplay feature_display;
  private Selection selection;
tjc's avatar
tjc committed
  private JPanel mainPanel = new JPanel();
  private CoveragePanel coveragePanel;
tjc's avatar
tjc committed
  private SnpPanel snpPanel;
  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 boolean asynchronous = true;
  private boolean showBaseAlignment = false;
  private JMenu bamFilesMenu = new JMenu("BAM files");
  private JCheckBoxMenuItem logMenuItem = new JCheckBoxMenuItem("Use Log Scale", logScale);
  
  private JCheckBoxMenuItem cbStackView = new JCheckBoxMenuItem("Stack", true);
  private JCheckBoxMenuItem cbPairedStackView = new JCheckBoxMenuItem("Paired Stack");
Loading
Loading full blame...