Skip to content

Commit 341da94

Browse files
committed
add tag shift option to bam-to-scidx
#172 add new option and reorganize window to fit new components. Also migrate "Output GZip" checkbox to next to "Output Directory" button
1 parent f977d1d commit 341da94

4 files changed

Lines changed: 65 additions & 32 deletions

File tree

src/main/java/scriptmanager/cli/BAM_Format_Converter/BAMtoscIDXCLI.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ static class ReadType {
6262
@Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp")
6363
private int MIN_INSERT = -9999;
6464
@Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp")
65-
private int MAX_INSERT = -9999;
65+
private int MAX_INSERT = -9999;
66+
@Option(names = {"--shift"}, description = "set a shift in bp (default=0bp)")
67+
private int SHIFT = 0;
68+
6669

6770
private int STRAND = -9999;
6871
private int PAIR;
@@ -81,7 +84,7 @@ public Integer call() throws Exception {
8184
System.exit(1);
8285
}
8386

84-
BAMtoscIDX script_obj = new BAMtoscIDX(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null, gzOutput);
87+
BAMtoscIDX script_obj = new BAMtoscIDX(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, SHIFT, null, gzOutput);
8588
script_obj.run();
8689

8790
System.err.println("Conversion Complete");
@@ -139,7 +142,7 @@ private String validateInput() throws IOException {
139142
PAIR = matePair ? 1 : 0;
140143
return(r);
141144
}
142-
public static String getCLIcommand(File BAM, File output, int strand, int pair, int min, int max) {
145+
public static String getCLIcommand(File BAM, File output, int strand, int pair, int min, int shift, int max) {
143146
String command = "java -jar $SCRIPTMANAGER bam-format-converter bam-to-scidx";
144147
System.out.println(output);
145148
System.out.println(BAM);
@@ -160,6 +163,7 @@ public static String getCLIcommand(File BAM, File output, int strand, int pair,
160163
} else if (max != -9999) {
161164
command += " -x " + max;
162165
}
166+
command += " --shift " + shift;
163167
return command;
164168
}
165169
}

src/main/java/scriptmanager/scripts/BAM_Format_Converter/BAMtoscIDX.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class BAMtoscIDX {
3434
private int STRAND = 0;
3535
private String READ = "READ1";
3636
private static int PAIR = 1;
37+
private int SHIFT = 0;
3738
private static int MIN_INSERT = -9999;
3839
private static int MAX_INSERT = -9999;
3940

@@ -56,17 +57,19 @@ public class BAMtoscIDX {
5657
* !0 = required)
5758
* @param min_size minimum acceptable insert size
5859
* @param max_size maximum acceptable insert size
60+
* @param shift shift tags in bp
5961
* @param ps PrintStream to output results
6062
* @param gzOutput whether or not to gzip output
6163
*/
62-
public BAMtoscIDX(File b, File o, int s, int pair_status, int min_size, int max_size, PrintStream ps, boolean gzOutput) {
64+
public BAMtoscIDX(File b, File o, int s, int pair_status, int min_size, int max_size, int shift, PrintStream ps, boolean gzOutput) {
6365
BAM = b;
6466
OUTFILE = o;
6567
PS = ps;
6668
STRAND = s;
6769
PAIR = pair_status;
6870
MIN_INSERT = min_size;
6971
MAX_INSERT = max_size;
72+
SHIFT = shift;
7073
if (STRAND == 0) {
7174
READ = "READ1";
7275
} else if (STRAND == 1) {
@@ -129,6 +132,8 @@ public void run() throws IOException, InterruptedException {
129132
printPS("Maximum insert size required to output: " + MAX_INSERT);
130133
}
131134

135+
printPS("Tag shift: " + SHIFT);
136+
132137
if (OUTPUT_GZIP){
133138
printPS("Output GZip: yes");
134139
} else {
@@ -168,11 +173,11 @@ public void run() throws IOException, InterruptedException {
168173
*/
169174
public void addTag(SAMRecord sr) {
170175
// Get the start of the record
171-
int recordStart = sr.getUnclippedStart();// .getAlignmentStart();
176+
int recordStart = sr.getUnclippedStart() + SHIFT;// .getAlignmentStart();
172177
// Accounts for reverse tag reporting 3' end of tag and converting BED to
173178
// IDX/GFF format
174179
if (sr.getReadNegativeStrandFlag()) {
175-
recordStart = sr.getUnclippedEnd();
180+
recordStart = sr.getUnclippedEnd() - SHIFT;
176181
} // .getAlignmentEnd(); }
177182

178183
// Make sure we only add tags that have valid starts
@@ -232,7 +237,10 @@ public void addMidTag(SAMRecord sr) {
232237
recordStart = sr.getMateAlignmentStart() - 1;
233238
recordStop = sr.getUnclippedEnd();
234239
}
240+
// calculate midpoint
235241
int recordMid = (recordStart + recordStop) / 2;
242+
// strand-aware tag shift
243+
recordMid += (sr.getReadNegativeStrandFlag() ? - SHIFT : SHIFT);
236244

237245
// Make sure we only add tags that have valid midpoints
238246
if (recordMid > 0 && recordMid <= CHROMSTOP) {

src/main/java/scriptmanager/window_interface/BAM_Format_Converter/BAMtoscIDXOutput.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ public class BAMtoscIDXOutput extends JFrame {
3737
private static int PAIR = 1;
3838
private static int MIN_INSERT = -9999;
3939
private static int MAX_INSERT = -9999;
40+
private static int SHIFT = 0;
4041

4142
private JTextArea textArea;
4243

4344
/**
4445
* Creates a new instance of a BAMtoscIDX script with a single BAM file
45-
* @param b BAM file
46-
* @param out_dir Output directory
47-
* @param s Specifies which reads to output
48-
* @param pair_status Specifies if proper pairs are required (0 = not required, !0 = required)
49-
* @param min_size Minimum acceptable insert size
50-
* @param max_size Maximum acceptable insert size
51-
* @param gzOutput whether or not to gzip output
46+
*
47+
* @param b BAM file
48+
* @param out_dir Output directory
49+
* @param s Specifies which reads to output
50+
* @param pair_status Specifies if proper pairs are required (0 = not required,
51+
* !0 = required)
52+
* @param min_size Minimum acceptable insert size
53+
* @param max_size Maximum acceptable insert size
54+
* @param shift set a tag shift in bp
55+
* @param gzOutput whether or not to gzip output
5256
*/
53-
public BAMtoscIDXOutput(File b, File out_dir, int s, int pair_status, int min_size, int max_size, boolean gzOutput) {
57+
public BAMtoscIDXOutput(File b, File out_dir, int s, int pair_status, int min_size, int max_size, int shift, boolean gzOutput) {
5458
setTitle("BAM to scIDX Progress");
5559
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
5660
setBounds(150, 150, 600, 800);
@@ -68,6 +72,7 @@ public BAMtoscIDXOutput(File b, File out_dir, int s, int pair_status, int min_si
6872
PAIR = pair_status;
6973
MIN_INSERT = min_size;
7074
MAX_INSERT = max_size;
75+
SHIFT = shift;
7176
if (STRAND == 0) {
7277
READ = "READ1";
7378
} else if (STRAND == 1) {
@@ -97,12 +102,12 @@ public void run() throws IOException, InterruptedException {
97102
PS.println(OUTPUT);
98103

99104
// Initialize LogItem
100-
String command = BAMtoscIDXCLI.getCLIcommand(BAM, new File(OUTPUT), STRAND, PAIR, MIN_INSERT, MAX_INSERT);
105+
String command = BAMtoscIDXCLI.getCLIcommand(BAM, new File(OUTPUT), STRAND, PAIR, MIN_INSERT, MAX_INSERT, SHIFT);
101106
LogItem new_li = new LogItem(command);
102107
firePropertyChange("log", null, new_li);
103108

104109
// Execute script
105-
BAMtoscIDX script_obj = new BAMtoscIDX(BAM, new File(OUTPUT), STRAND, PAIR, MIN_INSERT, MAX_INSERT, PS, OUTPUT_GZIP);
110+
BAMtoscIDX script_obj = new BAMtoscIDX(BAM, new File(OUTPUT), STRAND, PAIR, MIN_INSERT, MAX_INSERT, SHIFT, PS, OUTPUT_GZIP);
106111
script_obj.run();
107112

108113
// Update LogItem

src/main/java/scriptmanager/window_interface/BAM_Format_Converter/BAMtoscIDXWindow.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class BAMtoscIDXWindow extends JFrame implements ActionListener, Property
7575
private JCheckBox chckbxFilterByMinimum;
7676
private JTextField txtMin;
7777
private JTextField txtMax;
78+
private JTextField txtShift;
7879

7980
JProgressBar progressBar;
8081
/**
@@ -123,9 +124,10 @@ public Void doInBackground() {
123124
if (chckbxFilterByMaximum.isSelected()) {
124125
MAX = Integer.parseInt(txtMax.getText());
125126
}
127+
int SHIFT = Integer.parseInt(txtShift.getText());
126128
// process each bam
127129
for (int x = 0; x < BAMFiles.size(); x++) {
128-
BAMtoscIDXOutput output_obj = new BAMtoscIDXOutput(BAMFiles.get(x), OUT_DIR, STRAND, PAIR, MIN, MAX, chckbxGzipOutput.isSelected());
130+
BAMtoscIDXOutput output_obj = new BAMtoscIDXOutput(BAMFiles.get(x), OUT_DIR, STRAND, PAIR, MIN, MAX, SHIFT, chckbxGzipOutput.isSelected());
129131
output_obj.addPropertyChangeListener("log", new PropertyChangeListener() {
130132
public void propertyChange(PropertyChangeEvent evt) {
131133
firePropertyChange("log", evt.getOldValue(), evt.getNewValue());
@@ -287,8 +289,8 @@ public void itemStateChanged(ItemEvent e) {
287289
contentPane.add(btnOutputDirectory);
288290

289291
chckbxGzipOutput = new JCheckBox("Output GZip");
290-
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxGzipOutput, 0, SpringLayout.NORTH, btnIndex);
291-
sl_contentPane.putConstraint(SpringLayout.EAST, chckbxGzipOutput, -83, SpringLayout.WEST, btnOutputDirectory);
292+
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxGzipOutput, 2, SpringLayout.NORTH, btnOutputDirectory);
293+
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxGzipOutput, 20, SpringLayout.EAST, btnOutputDirectory);
292294
contentPane.add(chckbxGzipOutput);
293295

294296
progressBar = new JProgressBar();
@@ -301,13 +303,13 @@ public void itemStateChanged(ItemEvent e) {
301303
btnIndex.setActionCommand("start");
302304

303305
chckbxRequireProperMatepair = new JCheckBox("Require Proper Mate-Pair");
304-
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxRequireProperMatepair, 6, SpringLayout.SOUTH,
305-
rdbtnRead2);
306+
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxRequireProperMatepair, 6, SpringLayout.SOUTH, rdbtnRead2);
307+
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxRequireProperMatepair, 10, SpringLayout.WEST, contentPane);
306308
contentPane.add(chckbxRequireProperMatepair);
307309

308-
chckbxFilterByMinimum = new JCheckBox("Filter by Min Insert Size (bp)");
309-
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxFilterByMinimum, 35, SpringLayout.SOUTH, rdbtnRead1);
310-
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxFilterByMinimum, 10, SpringLayout.WEST, contentPane);
310+
chckbxFilterByMinimum = new JCheckBox("Filter Min Insert Size (bp)");
311+
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxFilterByMinimum, 0, SpringLayout.NORTH, chckbxRequireProperMatepair);
312+
sl_contentPane.putConstraint(SpringLayout.EAST, chckbxFilterByMinimum, -150, SpringLayout.EAST, contentPane);
311313
chckbxFilterByMinimum.addItemListener(new ItemListener() {
312314
public void itemStateChanged(ItemEvent e) {
313315
if (chckbxFilterByMinimum.isSelected()) {
@@ -325,19 +327,18 @@ public void itemStateChanged(ItemEvent e) {
325327
contentPane.add(chckbxFilterByMinimum);
326328

327329
txtMin = new JTextField();
328-
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxRequireProperMatepair, 0, SpringLayout.WEST, txtMin);
329-
txtMin.setEnabled(false);
330330
sl_contentPane.putConstraint(SpringLayout.NORTH, txtMin, 2, SpringLayout.NORTH, chckbxFilterByMinimum);
331331
sl_contentPane.putConstraint(SpringLayout.WEST, txtMin, 6, SpringLayout.EAST, chckbxFilterByMinimum);
332332
sl_contentPane.putConstraint(SpringLayout.EAST, txtMin, 75, SpringLayout.EAST, chckbxFilterByMinimum);
333333
txtMin.setHorizontalAlignment(SwingConstants.CENTER);
334334
txtMin.setText("0");
335335
contentPane.add(txtMin);
336+
txtMin.setEnabled(false);
336337
txtMin.setColumns(10);
337338

338-
chckbxFilterByMaximum = new JCheckBox("Filter by Max Insert Size (bp)");
339-
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxFilterByMaximum, 35, SpringLayout.SOUTH, rdbtnCombined);
340-
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxFilterByMaximum, 25, SpringLayout.EAST, txtMin);
339+
chckbxFilterByMaximum = new JCheckBox("Filter Max Insert Size (bp)");
340+
sl_contentPane.putConstraint(SpringLayout.NORTH, chckbxFilterByMaximum, 3, SpringLayout.SOUTH, chckbxFilterByMinimum);
341+
sl_contentPane.putConstraint(SpringLayout.WEST, chckbxFilterByMaximum, 0, SpringLayout.WEST, chckbxFilterByMinimum);
341342
chckbxFilterByMaximum.addItemListener(new ItemListener() {
342343
public void itemStateChanged(ItemEvent e) {
343344
if (chckbxFilterByMaximum.isSelected()) {
@@ -355,14 +356,28 @@ public void itemStateChanged(ItemEvent e) {
355356
contentPane.add(chckbxFilterByMaximum);
356357

357358
txtMax = new JTextField();
358-
txtMax.setEnabled(false);
359+
sl_contentPane.putConstraint(SpringLayout.NORTH, txtMax, 2, SpringLayout.NORTH, chckbxFilterByMaximum);
359360
sl_contentPane.putConstraint(SpringLayout.WEST, txtMax, 6, SpringLayout.EAST, chckbxFilterByMaximum);
360-
sl_contentPane.putConstraint(SpringLayout.NORTH, txtMax, 2, SpringLayout.NORTH, chckbxFilterByMinimum);
361361
sl_contentPane.putConstraint(SpringLayout.EAST, txtMax, 75, SpringLayout.EAST, chckbxFilterByMaximum);
362362
txtMax.setHorizontalAlignment(SwingConstants.CENTER);
363363
txtMax.setText("1000");
364-
contentPane.add(txtMax);
365364
txtMax.setColumns(10);
365+
txtMax.setEnabled(false);
366+
contentPane.add(txtMax);
367+
368+
JLabel lblTagShift = new JLabel("Tag Shift (bp):");
369+
sl_contentPane.putConstraint(SpringLayout.NORTH, lblTagShift, 6, SpringLayout.SOUTH, chckbxRequireProperMatepair);
370+
sl_contentPane.putConstraint(SpringLayout.WEST, lblTagShift, 10, SpringLayout.WEST, contentPane);
371+
contentPane.add(lblTagShift);
372+
373+
txtShift = new JTextField();
374+
sl_contentPane.putConstraint(SpringLayout.NORTH, txtShift, -1, SpringLayout.NORTH, lblTagShift);
375+
sl_contentPane.putConstraint(SpringLayout.WEST, txtShift, 100, SpringLayout.WEST, lblTagShift);
376+
sl_contentPane.putConstraint(SpringLayout.WEST, txtShift, 120, SpringLayout.WEST, contentPane);
377+
txtShift.setText("0");
378+
txtShift.setHorizontalAlignment(SwingConstants.CENTER);
379+
txtShift.setColumns(10);
380+
contentPane.add(txtShift);
366381

367382
btnOutputDirectory.addActionListener(new ActionListener() {
368383
public void actionPerformed(ActionEvent e) {
@@ -372,6 +387,7 @@ public void actionPerformed(ActionEvent e) {
372387
}
373388
}
374389
});
390+
375391
}
376392

377393
/**

0 commit comments

Comments
 (0)