Skip to content

Commit 1b34196

Browse files
committed
fix PEStat GUI to execute on batch of BAM files
This update fixes the GUI PEStat bugs that cause the PEStat tool to quit execution after the first BAM file has its stats calculated. It also fixes the GUI so that BAM files without BAI do not interrupt execution of a set of BAMs. window_interface/PEStatWindow -fix default and base output directory information window_interface/PEStatOutput -fix default output filename -rename output variables to be more specific (output directory vs output file basename) -perform check so that close attempts are not made for null PrintStream objects scripts/PEStats -moved or stripped some unnecessary print statements -display null charts when BAI does not exist (prevents thrown Exceptions that terminate execution of the whole set of BAM files prematurely) -removed the redundant PrintStream close statements (remaining close statements in PEStatOutput class)
1 parent 3757ec9 commit 1b34196

3 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/scripts/BAM_Statistics/PEStats.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
public class PEStats {
2828

2929
public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, boolean DUP_STATUS, int MIN_INSERT, int MAX_INSERT, PrintStream PS_INSERT, PrintStream PS_DUP, boolean SUM_STATUS ){
30-
System.out.println("getPEStats called");
3130
final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT);
3231

3332
// Output Vecotr of Charts to be returned
@@ -40,6 +39,7 @@ public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, bo
4039
PrintStream OUT_DUP = null;
4140
File OUT_DUPPNG = null;
4241

42+
// Set output PrintStreams and PNG file objects
4343
if( out_basename!=null ) {
4444
try {
4545
OUT_INSERT = new PrintStream(new File( out_basename.getCanonicalPath() + "_InsertHistogram.out"));
@@ -60,9 +60,7 @@ public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, bo
6060
printBoth( null, OUT_INSERT_SUM, time );
6161
printBoth( PS_INSERT, OUT_INSERT, time );
6262
printBoth( PS_DUP, OUT_DUP, time );
63-
64-
if(PS_DUP!=null){ PS_DUP.println("YO!"); }
65-
63+
6664
//Check if BAI index file exists
6765
File f = new File(bamFile + ".bai");
6866
if(f.exists() && !f.isDirectory()) {
@@ -77,6 +75,7 @@ public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, bo
7775
//Code to get individual chromosome stats
7876
SamReader reader = factory.open(bamFile);
7977
AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex();
78+
System.out.println(bamFile);
8079

8180
//Variables to keep track of insert size histogram
8281
double InsertAverage = 0;
@@ -197,13 +196,13 @@ public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, bo
197196
try{
198197
charts.add( 0, Histogram.createBarChart(HIST, DOMAIN, OUT_INSPNG) );
199198
}catch( IOException e ){ e.printStackTrace(); }
200-
199+
200+
//Duplication statistics
201201
if(DUP_STATUS) {
202-
//Duplication statistics
203202
double UNIQUE_MOLECULES = 0;
204203
String[] BIN_NAME = initializeBIN_Names();
205204
ArrayList<Double> BIN = new ArrayList<Double>();
206-
initializeBINS(BIN);
205+
initializeBINS(BIN);
207206

208207
Iterator<Integer> keys = ALL_COMPLEXITY.keySet().iterator();
209208
while(keys.hasNext()) {
@@ -223,14 +222,13 @@ public static Vector<ChartPanel> getPEStats( File out_basename, File bamFile, bo
223222
charts.add( 1, LineChart.createLineChart(BIN, BIN_NAME, OUT_DUPPNG) );
224223
}catch( IOException e ){ e.printStackTrace(); }
225224
}
226-
227225
} else {
226+
charts.add(0, new ChartPanel(null));
227+
charts.add(1, new ChartPanel(null));
228228
printBoth( PS_INSERT, OUT_INSERT, "BAI Index File does not exist for: " + bamFile.getName() );
229229
printBoth( System.err, OUT_INSERT_SUM, "BAI Index File does not exist for: " + bamFile.getName() );
230230
printBoth( PS_DUP, OUT_DUP, "BAI Index File does not exist for: " + bamFile.getName() );
231231
}
232-
if(PS_INSERT != null){ PS_INSERT.close(); }
233-
if(PS_DUP!=null){ PS_DUP.close(); }
234232

235233
if(OUT_INSERT != null){ OUT_INSERT.close(); }
236234
if(OUT_INSERT_SUM!=null){ OUT_INSERT_SUM.close(); }

src/window_interface/BAM_Statistics/PEStatOutput.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class PEStatOutput extends JFrame {
2424

2525
Vector<File> bamFiles = null;
26-
private File OUTPUT_PATH = null;
26+
private File OUT_DIR = null;
2727
private boolean OUTPUT_STATUS = false;
2828
private boolean DUP_STATUS = false;
2929
private static int MIN_INSERT = 0;
@@ -54,7 +54,7 @@ public PEStatOutput(Vector<File> input, File o, boolean out, boolean dup, int mi
5454
layeredPane.add(tabbedPane);
5555

5656
bamFiles = input;
57-
OUTPUT_PATH = o;
57+
OUT_DIR = o;
5858
OUTPUT_STATUS = out;
5959
DUP_STATUS = dup;
6060
MIN_INSERT = min;
@@ -76,17 +76,17 @@ public PEStatOutput(Vector<File> input, File o, boolean out, boolean dup, int mi
7676
public void run() throws IOException {
7777
//Iterate through all BAM files in Vector
7878
for(int x = 0; x < bamFiles.size(); x++) {
79-
8079
// Construct Basename
81-
File NAME = null;
80+
File OUT_BASENAME = null;
8281
if(OUTPUT_STATUS){
8382
try{
84-
NAME = new File( bamFiles.get(x).getName().split("\\.")[0] );
85-
if(OUTPUT_PATH != null){ NAME = new File( OUTPUT_PATH.getCanonicalPath() + File.separator + NAME.getCanonicalPath() ); }
83+
if(OUT_DIR == null) { OUT_BASENAME = new File(bamFiles.get(x).getName().split("\\.")[0]); }
84+
else { OUT_BASENAME = new File( OUT_DIR.getCanonicalPath() + File.separator + bamFiles.get(x).getName().split("\\.")[0] ); }
8685
}
8786
catch (FileNotFoundException e) { e.printStackTrace(); }
8887
// catch (IOException e) { e.printStackTrace(); }
8988
}
89+
9090
// Initialize PrintStream and TextArea for PE stats (insert sizes)
9191
PrintStream ps_insert = null;
9292
JTextArea PE_STATS = new JTextArea();
@@ -99,9 +99,9 @@ public void run() throws IOException {
9999
DUP_STATS.setEditable(false);
100100
ps_dup = new PrintStream(new CustomOutputStream( DUP_STATS ));
101101
}
102-
102+
103103
//Call public static method from scripts
104-
Vector<ChartPanel> charts = PEStats.getPEStats( NAME, bamFiles.get(x), DUP_STATUS, MIN_INSERT, MAX_INSERT, ps_insert, ps_dup, false );
104+
Vector<ChartPanel> charts = PEStats.getPEStats( OUT_BASENAME, bamFiles.get(x), DUP_STATUS, MIN_INSERT, MAX_INSERT, ps_insert, ps_dup, false );
105105

106106
//Add pe stats to tabbed pane
107107
PE_STATS.setCaretPosition(0);
@@ -117,7 +117,7 @@ public void run() throws IOException {
117117
tabbedPane_Duplication.add(bamFiles.get(x).getName(), charts.get(1));
118118
}
119119

120-
ps_dup.close();
120+
if(ps_dup!=null) { ps_dup.close(); }
121121
ps_insert.close();
122122

123123
firePropertyChange("bam",x, x + 1);

src/window_interface/BAM_Statistics/PEStatWindow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class PEStatWindow extends JFrame implements ActionListener, PropertyChan
5252

5353
final DefaultListModel<String> expList;
5454
Vector<File> BAMFiles = new Vector<File>();
55-
private File OUTPUT_PATH = null;
55+
private File OUTPUT_PATH = new File(System.getProperty("user.dir"));
5656

5757
JProgressBar progressBar;
5858
public Task task;
@@ -72,7 +72,7 @@ public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
7272
setProgress(percentComplete);
7373
}
7474
});
75-
stat.setVisible(true);
75+
stat.setVisible(true);
7676
stat.run();
7777
} catch(NumberFormatException nfe){
7878
JOptionPane.showMessageDialog(null, "Input Fields Must Contain Integers");

0 commit comments

Comments
 (0)