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

samrecord filter changes

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@12505 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 42067a17
No related branches found
No related tags found
No related merge requests found
package uk.ac.sanger.artemis.components.alignment;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import uk.ac.sanger.artemis.components.Utilities;
class SAMRecordFilter extends JPanel
{
......@@ -17,13 +23,20 @@ class SAMRecordFilter extends JPanel
{
super();
int nflags = SAMRecordFlagPredicate.FLAGS.length;
setLayout(new GridLayout(nflags, 2));
setLayout(new GridLayout(nflags+1, 2));
final JCheckBox flagCheck[] = new JCheckBox[nflags];
final SAMRecordFlagPredicate predicate = bamView.getSamRecordFlagPredicate();
for(int j=0; j<nflags; j++)
{
flagCheck[j] = new JCheckBox(
SAMRecordFlagPredicate.FLAGS_DESCRUIPTION[j], false);
if(predicate != null &&
predicate.isFlagSet(SAMRecordFlagPredicate.FLAGS[j]))
flagCheck[j].setSelected(true);
flagCheck[j].addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
......@@ -33,43 +46,39 @@ class SAMRecordFilter extends JPanel
});
add(flagCheck[j]);
}
int status = JOptionPane.showConfirmDialog(bamView,
this, "Filter Out Reads Based on Flag",
JOptionPane.OK_CANCEL_OPTION);
if(status != JOptionPane.OK_OPTION)
return;
final JFrame f = new JFrame("Filter Out Reads Based on Flag");
JButton closeFrame = new JButton("Close");
closeFrame.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
f.dispose();
}
});
add(closeFrame);
f.getContentPane().add(this);
f.pack();
Utilities.centreFrame(f);
f.setVisible(true);
}
private void filterChange(final BamView bamView,
final JCheckBox flagCheck[])
{
int nflags = SAMRecordFlagPredicate.FLAGS.length;
int flagsChecked = 0;
int flagCombined = 0;
for(int j=0; j<nflags; j++)
{
if(flagCheck[j].isSelected())
flagsChecked++;
flagCombined = flagCombined | SAMRecordFlagPredicate.FLAGS[j];
}
bamView.setSamRecordFlagPredicate(null);
if(flagsChecked == 0)
{
bamView.repaint();
return;
}
int flagsOn[] = new int[flagsChecked];
int num = 0;
for(int j=0; j<nflags; j++)
{
if(flagCheck[j].isSelected())
flagsOn[num++] = SAMRecordFlagPredicate.FLAGS[j];
}
bamView.setSamRecordFlagPredicate(new SAMRecordFlagPredicate(flagsOn));
if(flagCombined == 0)
bamView.setSamRecordFlagPredicate(null);
else
bamView.setSamRecordFlagPredicate(new SAMRecordFlagPredicate(flagCombined));
bamView.repaint();
}
......
......@@ -28,7 +28,7 @@ import net.sf.samtools.SAMRecord;
**/
public class SAMRecordFlagPredicate implements SAMRecordPredicate
{
private int flag[];
private int flag;
private static final int READ_PAIRED_FLAG = 0x1;
private static final int PROPER_PAIR_FLAG = 0x2;
......@@ -73,7 +73,7 @@ public class SAMRecordFlagPredicate implements SAMRecordPredicate
};
public SAMRecordFlagPredicate(int flag[])
public SAMRecordFlagPredicate(int flag)
{
this.flag = flag;
}
......@@ -86,11 +86,20 @@ public class SAMRecordFlagPredicate implements SAMRecordPredicate
**/
public boolean testPredicate (final SAMRecord samRecord)
{
for(int i=0; i<flag.length; i++)
return isFlagSet(samRecord.getFlags());
}
protected boolean isFlagSet(int thisFlag)
{
for(int i=0; i<FLAGS.length; i++)
{
if((samRecord.getFlags() & flag[i]) == flag[i])
return true;
if((flag & FLAGS[i]) == FLAGS[i])
{
if((thisFlag & FLAGS[i]) == FLAGS[i])
return true;
}
}
return false;
}
}
......
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