Skip to content
Snippets Groups Projects
Commit dd058f3e authored by tjc's avatar tjc
Browse files

change to using a JScrollBar

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@11936 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 459dd2ed
No related branches found
No related tags found
No related merge requests found
/* CoveragePanel
*
* 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.
*
*/
package uk.ac.sanger.artemis.components.alignment;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.util.List;
import javax.swing.JPanel;
import net.sf.samtools.SAMRecord;
public class CoveragePanel extends JPanel
{
private static final long serialVersionUID = 1L;
private int start;
private int end;
private float pixPerBase;
private Color lightBlue = new Color(30,144,255);
private JamView jamView;
public CoveragePanel(JamView jamView)
{
super();
setBackground(Color.white);
this.jamView = jamView;
}
/**
* Override
*/
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
List<SAMRecord> readsInView = jamView.getReadsInView();
if(readsInView == null)
return;
int windowSize = 10;
int nBins = Math.round((end-start+1.f)/windowSize);
int coverage[] = new int[nBins];
for(int i=0; i<coverage.length; i++)
coverage[i] = 0;
int max = 0;
for(int i=0; i<readsInView.size(); i++)
{
SAMRecord thisRead = readsInView.get(i);
int offset = jamView.getSequenceOffset(thisRead.getReferenceName());
int length = thisRead.getReadLength();
for(int j=0; j<length;j++)
{
int bin =
Math.round(((thisRead.getAlignmentStart()-start) + j + offset) / windowSize);
if(bin < 0 || bin > coverage.length-1)
continue;
coverage[bin]+=1;
if(coverage[bin] > max)
max = coverage[bin];
}
}
g2.setColor(lightBlue);
GeneralPath shape = new GeneralPath();
shape.moveTo(0,getHeight());
for(int i=0; i<coverage.length; i++)
{
float xpos = ((i*(windowSize)) - windowSize/2.f)*pixPerBase;
shape.lineTo(xpos,
getHeight() - (((float)coverage[i]/(float)max)*getHeight()));
}
shape.lineTo(getWidth(),getHeight());
g2.fill(shape);
String maxStr = Float.toString(max/windowSize);
FontMetrics fm = getFontMetrics(getFont());
g2.setColor(Color.black);
int xpos = getWidth() - fm.stringWidth(maxStr) -
jamView.getJspView().getVerticalScrollBar().getWidth();
g2.drawString(maxStr, xpos, fm.getHeight());
}
protected void setStartAndEnd(int start, int end)
{
this.start = start;
this.end = end;
}
protected void setPixPerBase(float pixPerBase)
{
this.pixPerBase = pixPerBase;
}
}
\ No newline at end of file
This diff is collapsed.
/* SAMRecordComparator
*
* 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.
*
*/
package uk.ac.sanger.artemis.components.alignment;
import java.util.Comparator;
import uk.ac.sanger.artemis.components.alignment.JamView.PairedRead;
class PairedReadComparator implements Comparator<Object>
{
public int compare(Object o1, Object o2)
{
PairedRead pr1 = (PairedRead) o1;
PairedRead pr2 = (PairedRead) o2;
int start1 = pr1.sam1.getAlignmentStart();
if(pr1.sam1.getAlignmentEnd() < start1)
start1 = pr1.sam1.getAlignmentEnd();
int start2 = pr2.sam1.getAlignmentStart();
if(pr2.sam1.getAlignmentEnd() < start2)
start2 = pr1.sam1.getAlignmentEnd();
return start1-start2;
}
}
\ No newline at end of file
/* SAMRecordComparator
*
* 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.
*
*/
package uk.ac.sanger.artemis.components.alignment;
import java.util.Comparator;
import net.sf.samtools.SAMRecord;
class SAMRecordComparator implements Comparator<Object>
{
public int compare(Object o1, Object o2)
{
SAMRecord pr1 = (SAMRecord) o1;
SAMRecord pr2 = (SAMRecord) o2;
int cmp = pr1.getReadName().compareTo(pr2.getReadName());
if(cmp == 0)
{
if(pr1.getAlignmentStart() < pr2.getAlignmentStart())
return -1;
else
return 1;
}
return cmp;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment