Skip to content

Commit 9c99c59

Browse files
committed
Update BAM Dedup to run Picard's MarkDuplicates natively
1 parent c3dd892 commit 9c99c59

4 files changed

Lines changed: 88 additions & 117 deletions

File tree

src/main/ScriptManagerGUI.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import window_interface.BAM_Statistics.SEStatWindow;
2020
import window_interface.BAM_Statistics.BAMGenomeCorrelationWindow;
2121
import window_interface.BAM_Manipulation.BAIIndexerWindow;
22-
import window_interface.BAM_Manipulation.BAMRemoveDupWindow;
22+
import window_interface.BAM_Manipulation.BAMMarkDupWindow;
2323
import window_interface.BAM_Manipulation.FilterforPIPseqWindow;
2424
import window_interface.BAM_Manipulation.MergeBAMWindow;
2525
import window_interface.BAM_Manipulation.SortBAMWindow;
@@ -240,20 +240,20 @@ public void run() {
240240
pnlBamManip.add(btnBamSort);
241241

242242
// >BAMRemoveDup
243-
JTextArea txtBamRemoveDuplicates = new JTextArea();
244-
initializeTextArea(txtBamRemoveDuplicates);
245-
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamRemoveDuplicates, 10, SpringLayout.SOUTH, txtBamSort);
246-
sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamRemoveDuplicates, -10, SpringLayout.EAST, pnlBamManip);
247-
txtBamRemoveDuplicates.setText(ToolDescriptions.remove_duplicates_description);
248-
pnlBamManip.add(txtBamRemoveDuplicates);
249-
250-
JButton btnBamRemoveDuplicates = new JButton("BAM Remove Duplicates");
251-
btnBamRemoveDuplicates.addActionListener(new ActionListener() {
243+
JTextArea txtMarkDuplicates = new JTextArea();
244+
initializeTextArea(txtMarkDuplicates);
245+
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtMarkDuplicates, 10, SpringLayout.SOUTH, txtBamSort);
246+
sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtMarkDuplicates, -10, SpringLayout.EAST, pnlBamManip);
247+
txtMarkDuplicates.setText(ToolDescriptions.remove_duplicates_description);
248+
pnlBamManip.add(txtMarkDuplicates);
249+
250+
JButton btnMarkDuplicates = new JButton("BAM MarkDuplicates");
251+
btnMarkDuplicates.addActionListener(new ActionListener() {
252252
public void actionPerformed(ActionEvent e) {
253253
EventQueue.invokeLater(new Runnable() {
254254
public void run() {
255255
try {
256-
BAMRemoveDupWindow frame = new BAMRemoveDupWindow();
256+
BAMMarkDupWindow frame = new BAMMarkDupWindow();
257257
frame.setVisible(true);
258258
} catch (Exception e) {
259259
e.printStackTrace();
@@ -262,18 +262,15 @@ public void run() {
262262
});
263263
}
264264
});
265-
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamRemoveDuplicates, 0, SpringLayout.NORTH,
266-
txtBamRemoveDuplicates);
267-
sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamRemoveDuplicates, 10, SpringLayout.WEST, pnlBamManip);
268-
sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamRemoveDuplicates, 10, SpringLayout.EAST,
269-
btnBamRemoveDuplicates);
270-
pnlBamManip.add(btnBamRemoveDuplicates);
265+
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnMarkDuplicates, 0, SpringLayout.NORTH, txtMarkDuplicates);
266+
sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnMarkDuplicates, 10, SpringLayout.WEST, pnlBamManip);
267+
sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtMarkDuplicates, 10, SpringLayout.EAST, btnMarkDuplicates);
268+
pnlBamManip.add(btnMarkDuplicates);
271269

272270
// >BAMReplicateMerge
273271
JTextArea txtBamReplicateMerge = new JTextArea();
274272
initializeTextArea(txtBamReplicateMerge);
275-
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamReplicateMerge, 10, SpringLayout.SOUTH,
276-
txtBamRemoveDuplicates);
273+
sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamReplicateMerge, 10, SpringLayout.SOUTH, txtMarkDuplicates);
277274
sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamReplicateMerge, -10, SpringLayout.EAST, pnlBamManip);
278275
txtBamReplicateMerge.setText(ToolDescriptions.merge_bam_description);
279276
pnlBamManip.add(txtBamReplicateMerge);
@@ -1211,7 +1208,7 @@ public void run() {
12111208
sl_pnlFigure.putConstraint(SpringLayout.EAST, txtTwoColorHeatMap, -10, SpringLayout.EAST, pnlFigure);
12121209
pnlFigure.add(txtTwoColorHeatMap);
12131210

1214-
JButton btnTwoColorHeatMap = new JButton("Two-Color Heat Map (Original Heat Map)");
1211+
JButton btnTwoColorHeatMap = new JButton("Two-Color Heat Map");
12151212
btnTwoColorHeatMap.addActionListener(new ActionListener() {
12161213
public void actionPerformed(ActionEvent arg0) {
12171214
EventQueue.invokeLater(new Runnable() {
@@ -1350,7 +1347,7 @@ public ScriptManagerGUI() {
13501347
/**
13511348
* Launch the application.
13521349
*/
1353-
public static void launchApplication() {
1350+
public void launchApplication() {
13541351
try {
13551352
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
13561353
} catch (Throwable e) {

src/scripts/BAM_Manipulation/BAMDeDuplication.java

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package scripts.BAM_Manipulation;
2+
3+
import picard.sam.markduplicates.MarkDuplicates;
4+
5+
import java.io.File;
6+
import java.io.IOException;
7+
import java.util.ArrayList;
8+
9+
import javax.swing.JFrame;
10+
import javax.swing.JOptionPane;
11+
12+
@SuppressWarnings("serial")
13+
public class BAMMarkDuplicates extends JFrame {
14+
File bamFile = null;
15+
boolean removeDuplicates = true;
16+
File output = null;
17+
File metrics = null;
18+
19+
public BAMMarkDuplicates(File in, boolean remove, File out, File met) {
20+
bamFile = in;
21+
removeDuplicates = remove;
22+
output = out;
23+
metrics = met;
24+
}
25+
26+
public void run() throws IOException {
27+
//Check if BAI index file exists
28+
File f = new File(bamFile + ".bai");
29+
if(f.exists() && !f.isDirectory()) {
30+
final MarkDuplicates markDuplicates = new MarkDuplicates();
31+
final ArrayList<String> args = new ArrayList<>();
32+
args.add("INPUT=" + bamFile.getAbsolutePath());
33+
args.add("OUTPUT=" + output.getAbsolutePath());
34+
args.add("METRICS_FILE=" + metrics.getAbsolutePath());
35+
if(removeDuplicates) { args.add("REMOVE_DUPLICATES=true"); }
36+
else { args.add("REMOVE_DUPLICATES=false"); }
37+
markDuplicates.instanceMain(args.toArray(new String[args.size()]));
38+
} else {
39+
JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + bamFile.getName() + "\n");
40+
}
41+
}
42+
}

src/window_interface/BAM_Manipulation/BAMRemoveDupWindow.java renamed to src/window_interface/BAM_Manipulation/BAMMarkDupWindow.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
import util.FileSelection;
3333
import scripts.BAM_Manipulation.BAIIndexer;
34-
import scripts.BAM_Manipulation.BAMDeDuplication;
34+
import scripts.BAM_Manipulation.BAMMarkDuplicates;
3535

3636
@SuppressWarnings("serial")
37-
public class BAMRemoveDupWindow extends JFrame implements ActionListener, PropertyChangeListener {
37+
public class BAMMarkDupWindow extends JFrame implements ActionListener, PropertyChangeListener {
3838
private JPanel contentPane;
3939
protected JFileChooser fc = new JFileChooser(new File(System.getProperty("user.dir")));
4040

@@ -52,6 +52,7 @@ public class BAMRemoveDupWindow extends JFrame implements ActionListener, Proper
5252
private JLabel label;
5353
private JLabel lblDefaultToLocal;
5454
private JCheckBox chckbxGenerateBaiIndex;
55+
private JCheckBox chckbxRemoveDuplicates;
5556

5657
class Task extends SwingWorker<Void, Void> {
5758
@Override
@@ -60,17 +61,25 @@ public Void doInBackground() throws Exception {
6061
for(int x = 0; x < BAMFiles.size(); x++) {
6162
String[] NAME = BAMFiles.get(x).getName().split("\\.");
6263
File OUTPUT = null;
63-
if(OUTPUT_PATH != null) { OUTPUT = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME[0] + "_dedup.bam"); }
64-
else { OUTPUT = new File(NAME[0] + "_dedup.bam"); }
65-
BAMDeDuplication dedup = new BAMDeDuplication(BAMFiles.get(x), OUTPUT);
64+
File METRICS = null;
65+
if(OUTPUT_PATH != null) {
66+
OUTPUT = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME[0] + "_dedup.bam");
67+
METRICS = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME[0] + "_dedup.metrics");
68+
} else {
69+
OUTPUT = new File(NAME[0] + "_dedup.bam");
70+
METRICS = new File(NAME[0] + "_dedup.metrics");
71+
}
72+
73+
BAMMarkDuplicates dedup = new BAMMarkDuplicates(BAMFiles.get(x), chckbxRemoveDuplicates.isSelected(), OUTPUT, METRICS);
6674
dedup.run();
75+
6776
if(chckbxGenerateBaiIndex.isSelected()) { BAIIndexer.generateIndex(OUTPUT); }
6877

6978
int percentComplete = (int)(((double)(x + 1) / BAMFiles.size()) * 100);
7079
setProgress(percentComplete);
7180
}
7281
setProgress(100);
73-
JOptionPane.showMessageDialog(null, "De-Duplication Complete");
82+
JOptionPane.showMessageDialog(null, "Mark Duplicates Complete");
7483
return null;
7584
}
7685

@@ -80,11 +89,11 @@ public void done() {
8089
}
8190
}
8291

83-
public BAMRemoveDupWindow() {
84-
setTitle("BAM Remove Duplicate Reads");
92+
public BAMMarkDupWindow() {
93+
setTitle("BAM MarkDuplicates (picard)");
8594
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
8695

87-
setBounds(125, 125, 450, 330);
96+
setBounds(125, 125, 450, 360);
8897
contentPane = new JPanel();
8998
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
9099
setContentPane(contentPane);
@@ -132,7 +141,7 @@ public void actionPerformed(ActionEvent arg0) {
132141
});
133142
contentPane.add(btnRemoveBam);
134143

135-
btnSort = new JButton("De-Duplicate");
144+
btnSort = new JButton("Mark Duplicates");
136145
sl_contentPane.putConstraint(SpringLayout.WEST, btnSort, 160, SpringLayout.WEST, contentPane);
137146
sl_contentPane.putConstraint(SpringLayout.SOUTH, btnSort, 0, SpringLayout.SOUTH, contentPane);
138147
sl_contentPane.putConstraint(SpringLayout.EAST, btnSort, -160, SpringLayout.EAST, contentPane);
@@ -149,7 +158,7 @@ public void actionPerformed(ActionEvent arg0) {
149158
contentPane.add(progressBar);
150159

151160
btnOutput = new JButton("Output Directory");
152-
sl_contentPane.putConstraint(SpringLayout.SOUTH, scrollPane, -42, SpringLayout.NORTH, btnOutput);
161+
sl_contentPane.putConstraint(SpringLayout.SOUTH, scrollPane, -72, SpringLayout.NORTH, btnOutput);
153162
btnOutput.addActionListener(new ActionListener() {
154163
public void actionPerformed(ActionEvent e) {
155164
OUTPUT_PATH = FileSelection.getOutputDir(fc);
@@ -176,10 +185,16 @@ public void actionPerformed(ActionEvent e) {
176185
contentPane.add(lblDefaultToLocal);
177186

178187
chckbxGenerateBaiIndex = new JCheckBox("Generate BAI Index for new BAM file");
188+
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxGenerateBaiIndex, 40, SpringLayout.SOUTH, scrollPane);
189+
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxGenerateBaiIndex, 5, SpringLayout.WEST, contentPane);
179190
chckbxGenerateBaiIndex.setSelected(true);
180-
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxGenerateBaiIndex, 11, SpringLayout.SOUTH, scrollPane);
181-
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxGenerateBaiIndex, 0, SpringLayout.WEST, scrollPane);
182191
contentPane.add(chckbxGenerateBaiIndex);
192+
193+
chckbxRemoveDuplicates = new JCheckBox("Remove Duplicates");
194+
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxRemoveDuplicates, 0, SpringLayout.WEST, scrollPane);
195+
sl_contentPane.putConstraint(SpringLayout.SOUTH, chckbxRemoveDuplicates, -6, SpringLayout.NORTH, chckbxGenerateBaiIndex);
196+
chckbxRemoveDuplicates.setSelected(true);
197+
contentPane.add(chckbxRemoveDuplicates);
183198
}
184199

185200
@Override

0 commit comments

Comments
 (0)