/* SnpPanel * * created: 2010 * * This file is part of Artemis * * Copyright(C) 2010 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. * */ package uk.ac.sanger.artemis.components.alignment; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.GeneralPath; import java.util.List; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JTextField; import uk.ac.sanger.artemis.io.Range; import uk.ac.sanger.artemis.sequence.Bases; import uk.ac.sanger.artemis.util.OutOfRangeException; import htsjdk.samtools.AlignmentBlock; import htsjdk.samtools.SAMRecord; public class SnpPanel extends AbstractGraphPanel { private static final long serialVersionUID = 1L; private Bases bases; private float minBaseQualityFilter = 0; private int snpCount[]; public SnpPanel(final BamView bamView, Bases bases) { super(); this.bamView = bamView; this.bases = bases; initPopupMenu(popup); JMenuItem configure = new JMenuItem("Filter by Base Quality..."); configure.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // filter by base quality JTextField filterField = new JTextField(Float.toString(minBaseQualityFilter)); int status = JOptionPane.showConfirmDialog(SnpPanel.this, filterField, "Base Quality Filter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if(status == JOptionPane.CANCEL_OPTION) return; try { minBaseQualityFilter = Float.parseFloat(filterField.getText()); } catch(NumberFormatException nfe) { JOptionPane.showMessageDialog(SnpPanel.this, nfe.getMessage(), "Number Format", JOptionPane.WARNING_MESSAGE); } } }); popup.add(configure); } /** * Override */ protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; if(bases == null || nBins == 0 || snpCount == null) return; drawSelectionRange(g2, pixPerBase, start, end, getHeight(), Color.PINK); draw(g2); drawMax(g2); } protected void init(BamView bamView, float pixPerBase, int start, int end) { this.bamView = bamView; setPixPerBase(pixPerBase); setStartAndEnd(start, end); if(autoWinSize) { windowSize = (bamView.getBasesInView()/300); userWinSize = windowSize; } else windowSize = userWinSize; if(windowSize < 1) windowSize = 1; nBins = Math.round((end-start+1.f)/windowSize); max = 0; snpCount = null; } protected void draw(Graphics2D g2) { g2.setColor(Color.red); g2.setStroke(new BasicStroke(1.f)); if(windowSize == 1) { GeneralPath shape = new GeneralPath(); shape.moveTo(0,getHeight()); for(int i=0; i blocks = thisRead.getAlignmentBlocks(); final byte[] phredQuality = thisRead.getBaseQualities(); try { char[] refSeq = bases.getSubSequenceC( new Range(thisStart+offset, thisEnd+offset), Bases.FORWARD); byte[] readSeq = thisRead.getReadBases(); offset = offset - bamView.getBaseAtStartOfView(); for(int i=0; i nBins-1) continue; snpCount[bin]+=1; if(snpCount[bin] > max) max = snpCount[bin]; } } } } catch (OutOfRangeException e) { e.printStackTrace(); } } }