Skip to content

Commit 99a4c1f

Browse files
committed
bugfix sort-by-dist support gff
miscellaneous bug fixes from #35 including - copy-paste error leading to gff input option processing bed - allow gz file extension selection in GUI - add '.gz' extension when gzOutput selected - set default output directory - general exception catching - copy-paste error in cli documentation for `-m` option - add/clean-up comments
1 parent a870ecc commit 99a4c1f

4 files changed

Lines changed: 35 additions & 32 deletions

File tree

src/main/java/scriptmanager/cli/Peak_Analysis/SortByDistCLI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SortByDistCLI implements Callable<Integer> {
3838
private Long upstreamBound = null;
3939
@Option(names = {"-d"}, description = "Restrict search to exclude peaks downstream of this distance (default = no bound)")
4040
private Long downstreamBound = null;
41-
@Option(names = {"-m", "--match-strand"}, description = "Output compressed GFF file" )
41+
@Option(names = {"-m", "--match-strand"}, description = "only check peaks with strand matching reference" )
4242
private boolean matchStrand = false;
4343
@Option(names = {"-z", "--compression"}, description = "Output compressed GFF file" )
4444
private boolean gzOutput = false;
@@ -101,7 +101,7 @@ private String validateInput() throws IOException {
101101

102102
public static String getCLIcommand(File ref, File peak, File out, boolean gff, boolean gzOutput, boolean mstrand, Long upstream, Long downstream){
103103
String command = "java -jar $SCRIPTMANAGER peak-analysis sort-by-dist";
104-
command += gff? " --gff": "";
104+
command += gff ? " --gff": "";
105105
command += gzOutput ? " -z": "";
106106
command += mstrand ? " -m": "";
107107
command += upstream == null ? "": " -u " + upstream;

src/main/java/scriptmanager/scripts/Peak_Analysis/SortByDist.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ public class SortByDist {
3434
private boolean matchStrand = false;
3535
private Long maxUp = null;
3636
private Long maxDown = null;
37-
38-
// // TODO: add strand match restriction
39-
// private boolean restrictStrandedness = false;
40-
37+
4138
public SortByDist(File ref, File peak, File out, boolean gzOutput, boolean m, Long upstream, Long downstream, PrintStream ps) throws IOException {
4239
PS = ps;
4340
OUT = GZipUtilities.makePrintStream(out, gzOutput);

src/main/java/scriptmanager/window_interface/Peak_Analysis/SortByDistOutput.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class SortByDistOutput extends JFrame{
4141

4242
private JTextArea textArea;
4343

44-
public SortByDistOutput(File ref, File peak, File outpath, boolean gzOutput, boolean gff, boolean strand, Long upstream, Long downstream) throws IOException {
44+
public SortByDistOutput(File ref, File peak, File odir, boolean gzOutput, boolean gff, boolean strand, Long upstream, Long downstream) throws IOException {
4545
setTitle("Align to Reference Progress");
4646
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
4747
setBounds(150, 150, 600, 800);
@@ -62,9 +62,9 @@ public SortByDistOutput(File ref, File peak, File outpath, boolean gzOutput, boo
6262
DOWNSTREAM_BOUND = downstream;
6363

6464
OUTFILE = new File(ExtensionFileFilter.stripExtensionIgnoreGZ(PEAK) + "_" + ExtensionFileFilter.stripExtensionIgnoreGZ(REF) +
65-
"_DistSort." + ExtensionFileFilter.getExtensionIgnoreGZ(REF));
66-
if(outpath != null) {
67-
OUTFILE = new File(outpath.getCanonicalPath() + OUTFILE.getName());
65+
"_DistSort." + ExtensionFileFilter.getExtensionIgnoreGZ(REF) + (gzOutput ? ".gz" : ""));
66+
if(odir != null) {
67+
OUTFILE = new File(odir.getCanonicalPath() + File.separator + OUTFILE.getName());
6868
}
6969
}
7070

@@ -82,7 +82,7 @@ public void run() throws IOException, InterruptedException {
8282
} else {
8383
script_obj.sortBED();
8484
}
85-
// Update log item
85+
// Update LogItem
8686
li.setStopTime(new Timestamp(new Date().getTime()));
8787
li.setStatus(0);
8888
firePropertyChange("log", li, null);

src/main/java/scriptmanager/window_interface/Peak_Analysis/SortByDistWindow.java

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import javax.swing.border.EmptyBorder;
3838
import javax.swing.border.TitledBorder;
3939

40+
import scriptmanager.objects.ToolDescriptions;
4041
import scriptmanager.util.FileSelection;
4142

4243
/**
@@ -61,7 +62,7 @@ public class SortByDistWindow extends JFrame implements ActionListener, Property
6162
ArrayList<File> PeakGFFFiles = new ArrayList<File>();
6263
ArrayList<File> RefBEDFiles = new ArrayList<File>();
6364
ArrayList<File> RefGFFFiles = new ArrayList<File>();
64-
private File OUT_DIR = null;
65+
private File OUT_DIR = new File(System.getProperty("user.dir"));
6566

6667
private JButton btnLoadPeakBed;
6768
private JButton btnLoadPeakGff;
@@ -136,10 +137,10 @@ public void propertyChange(PropertyChangeEvent evt) {
136137
} else {
137138
setProgress(0);
138139
int counter = 0;
139-
for (File RefBED : RefBEDFiles) {
140-
for (File PeakBED : PeakBEDFiles) {
140+
for (File RefGFF : RefGFFFiles) {
141+
for (File PeakGFF : PeakGFFFiles) {
141142
// Execute script
142-
SortByDistOutput output_obj = new SortByDistOutput(RefBED, PeakBED, OUT_DIR, chckbxGzipOutput.isSelected(), true, chckbxMatchStrand.isSelected(), UPSTREAM, DOWNSTREAM);
143+
SortByDistOutput output_obj = new SortByDistOutput(RefGFF, PeakGFF, OUT_DIR, chckbxGzipOutput.isSelected(), true, chckbxMatchStrand.isSelected(), UPSTREAM, DOWNSTREAM);
143144
output_obj.addPropertyChangeListener("log", new PropertyChangeListener() {
144145
public void propertyChange(PropertyChangeEvent evt) {
145146
firePropertyChange("log", evt.getOldValue(), evt.getNewValue());
@@ -161,6 +162,9 @@ public void propertyChange(PropertyChangeEvent evt) {
161162
ioe.printStackTrace();
162163
} catch (NumberFormatException nfe) {
163164
JOptionPane.showMessageDialog(null, "Distance bound inputs are invalid!!! They must be formatted like valid integers.");
165+
} catch (Exception e) {
166+
e.printStackTrace();
167+
JOptionPane.showMessageDialog(null, ToolDescriptions.UNEXPECTED_EXCEPTION_MESSAGE + e.getMessage());
164168
}
165169
setProgress(100);
166170
return null;
@@ -237,7 +241,7 @@ public SortByDistWindow() {
237241

238242
btnLoadPeakBed.addActionListener(new ActionListener() {
239243
public void actionPerformed(ActionEvent e) {
240-
File[] newBEDFiles = FileSelection.getFiles(fc,"bed");
244+
File[] newBEDFiles = FileSelection.getFiles(fc,"bed", true);
241245
if(newBEDFiles != null) {
242246
for(int x = 0; x < newBEDFiles.length; x++) {
243247
PeakBEDFiles.add(newBEDFiles[x]);
@@ -267,23 +271,23 @@ public void actionPerformed(ActionEvent arg0) {
267271
sl_bedInputPane.putConstraint(SpringLayout.NORTH, btnRemoveRefBed, 10, SpringLayout.SOUTH, scrollPaneBedPeak);
268272
sl_bedInputPane.putConstraint(SpringLayout.EAST, btnRemoveRefBed, -5, SpringLayout.EAST, bedInputPane);
269273

270-
JScrollPane scrollPane_Ref = new JScrollPane();
271-
sl_bedInputPane.putConstraint(SpringLayout.NORTH, scrollPane_Ref, 10, SpringLayout.SOUTH, btnLoadRefBed);
272-
//sl_bedInputPane.putConstraint(SpringLayout.SOUTH, scrollPane_Ref, -100, SpringLayout.SOUTH, btnLoadRefBed);
273-
sl_bedInputPane.putConstraint(SpringLayout.WEST, scrollPane_Ref, 5, SpringLayout.WEST, bedInputPane);
274-
sl_bedInputPane.putConstraint(SpringLayout.EAST, scrollPane_Ref, -5, SpringLayout.EAST, bedInputPane);
275-
sl_bedInputPane.putConstraint(SpringLayout.SOUTH, scrollPane_Ref, 0, SpringLayout.SOUTH, bedInputPane);
276-
bedInputPane.add(scrollPane_Ref);
274+
JScrollPane scrollPaneBedRef = new JScrollPane();
275+
sl_bedInputPane.putConstraint(SpringLayout.NORTH, scrollPaneBedRef, 10, SpringLayout.SOUTH, btnLoadRefBed);
276+
//sl_bedInputPane.putConstraint(SpringLayout.SOUTH, scrollPaneBedRef, -100, SpringLayout.SOUTH, btnLoadRefBed);
277+
sl_bedInputPane.putConstraint(SpringLayout.WEST, scrollPaneBedRef, 5, SpringLayout.WEST, bedInputPane);
278+
sl_bedInputPane.putConstraint(SpringLayout.EAST, scrollPaneBedRef, -5, SpringLayout.EAST, bedInputPane);
279+
sl_bedInputPane.putConstraint(SpringLayout.SOUTH, scrollPaneBedRef, 0, SpringLayout.SOUTH, bedInputPane);
280+
bedInputPane.add(scrollPaneBedRef);
277281

278282
refBEDList = new DefaultListModel<String>();
279283
final JList<String> listRef = new JList<String>(refBEDList);
280284
listRef.setForeground(Color.BLACK);
281285
listRef.setFont(new Font("Lucida Grande", Font.PLAIN, 12));
282-
scrollPane_Ref.setViewportView(listRef);
286+
scrollPaneBedRef.setViewportView(listRef);
283287

284288
btnLoadRefBed.addActionListener(new ActionListener() {
285289
public void actionPerformed(ActionEvent e) {
286-
File[] newBEDFiles = FileSelection.getFiles(fc,"bed");
290+
File[] newBEDFiles = FileSelection.getFiles(fc,"bed", true);
287291
if(newBEDFiles != null) {
288292
for(int x = 0; x < newBEDFiles.length; x++) {
289293
RefBEDFiles.add(newBEDFiles[x]);
@@ -327,7 +331,7 @@ public void actionPerformed(ActionEvent arg0) {
327331

328332
btnLoadPeakGff.addActionListener(new ActionListener() {
329333
public void actionPerformed(ActionEvent e) {
330-
File[] newGFFFiles = FileSelection.getFiles(fc,"GFF");
334+
File[] newGFFFiles = FileSelection.getFiles(fc,"gff", true);
331335
if(newGFFFiles != null) {
332336
for(int x = 0; x < newGFFFiles.length; x++) {
333337
PeakGFFFiles.add(newGFFFiles[x]);
@@ -373,7 +377,7 @@ public void actionPerformed(ActionEvent arg0) {
373377

374378
btnLoadRefGff.addActionListener(new ActionListener() {
375379
public void actionPerformed(ActionEvent e) {
376-
File[] newGFFFiles = FileSelection.getFiles(fc,"GFF");
380+
File[] newGFFFiles = FileSelection.getFiles(fc,"gff", true);
377381
if(newGFFFiles != null) {
378382
for(int x = 0; x < newGFFFiles.length; x++) {
379383
RefGFFFiles.add(newGFFFiles[x]);
@@ -394,7 +398,7 @@ public void actionPerformed(ActionEvent arg0) {
394398
});
395399
gffInputPane.add(btnRemoveReGff);
396400

397-
// Search Options
401+
// >>>>> Search Options <<<<<
398402
JPanel pnlSearchOptions = new JPanel();
399403
sl_contentPane.putConstraint(SpringLayout.NORTH, pnlSearchOptions, 10, SpringLayout.SOUTH, inputCards);
400404
sl_contentPane.putConstraint(SpringLayout.WEST, pnlSearchOptions, 10, SpringLayout.WEST, contentPane);
@@ -408,7 +412,7 @@ public void actionPerformed(ActionEvent arg0) {
408412
ttlSearch.setTitleFont(new Font("Lucida Grande", Font.ITALIC, 13));
409413
pnlSearchOptions.setBorder(ttlSearch);
410414

411-
//Initialize upstream restrict distance checkbox and input
415+
// Upstream restrict distance checkbox and input
412416
chckbxRestrictUpstreamDistance = new JCheckBox("Restrict upstream bound (bp):");
413417
sl_SearchOptions.putConstraint(SpringLayout.NORTH, chckbxRestrictUpstreamDistance, 0, SpringLayout.NORTH, pnlSearchOptions);
414418
sl_SearchOptions.putConstraint(SpringLayout.WEST, chckbxRestrictUpstreamDistance, 10, SpringLayout.WEST, pnlSearchOptions);
@@ -428,7 +432,7 @@ public void itemStateChanged(ItemEvent e) {
428432
}
429433
});
430434

431-
//Initialize downstream restrict distance checkbox and input
435+
// Downstream restrict distance checkbox and input
432436
chckbxRestrictDownstreamDistance = new JCheckBox("Restrict downstream bound (bp):");
433437
sl_SearchOptions.putConstraint(SpringLayout.NORTH, chckbxRestrictDownstreamDistance, 0, SpringLayout.SOUTH, chckbxRestrictUpstreamDistance);
434438
sl_SearchOptions.putConstraint(SpringLayout.WEST, chckbxRestrictDownstreamDistance, 0, SpringLayout.WEST, chckbxRestrictUpstreamDistance);
@@ -455,13 +459,14 @@ public void itemStateChanged(ItemEvent e) {
455459
lblSizeAdmonishment.setFont(new Font("Dialog", Font.ITALIC, 12));
456460
pnlSearchOptions.add(lblSizeAdmonishment);
457461

462+
// Add strand match selection option
458463
chckbxMatchStrand = new JCheckBox("Strand matched");
459464
sl_SearchOptions.putConstraint(SpringLayout.SOUTH, chckbxMatchStrand, 0, SpringLayout.SOUTH, pnlSearchOptions);
460465
sl_SearchOptions.putConstraint(SpringLayout.EAST, chckbxMatchStrand, 0, SpringLayout.EAST, pnlSearchOptions);
461466
chckbxMatchStrand.setToolTipText("Only check peaks that are on the same strand as the RefPT");
462467
pnlSearchOptions.add(chckbxMatchStrand);
463468

464-
// Output Options
469+
// >>>>> Output Options <<<<<
465470
JPanel pnlOutputOptions = new JPanel();
466471
sl_contentPane.putConstraint(SpringLayout.NORTH, pnlOutputOptions, 0, SpringLayout.SOUTH, pnlSearchOptions);
467472
sl_contentPane.putConstraint(SpringLayout.WEST, pnlOutputOptions, 10, SpringLayout.WEST, contentPane);
@@ -475,7 +480,7 @@ public void itemStateChanged(ItemEvent e) {
475480
ttlOutput.setTitleFont(new Font("Lucida Grande", Font.ITALIC, 13));
476481
pnlOutputOptions.setBorder(ttlOutput);
477482

478-
//Initialize output directory
483+
// Output directory
479484
btnOutputDirectory = new JButton("Output Directory");
480485
sl_OutputOptions.putConstraint(SpringLayout.NORTH, btnOutputDirectory, 0, SpringLayout.NORTH, pnlOutputOptions);
481486
sl_OutputOptions.putConstraint(SpringLayout.WEST, btnOutputDirectory, 10, SpringLayout.WEST, pnlOutputOptions);
@@ -491,6 +496,7 @@ public void actionPerformed(ActionEvent e) {
491496
});
492497
pnlOutputOptions.add(btnOutputDirectory);
493498

499+
// Gzip Output
494500
chckbxGzipOutput = new JCheckBox("Output GZip");
495501
sl_OutputOptions.putConstraint(SpringLayout.NORTH, chckbxGzipOutput, 0, SpringLayout.NORTH, btnOutputDirectory);
496502
sl_OutputOptions.putConstraint(SpringLayout.WEST, chckbxGzipOutput, 10, SpringLayout.EAST, btnOutputDirectory);

0 commit comments

Comments
 (0)