Skip to content

Commit a84bf55

Browse files
committed
Update PEStatOutput.java
Relating to issue #83, user interface does not notify user when stats can not be generated due to a missing BAI index. This commit pastes the BAI check code and if-statement from TagPileupOutput.
1 parent 07a3655 commit a84bf55

1 file changed

Lines changed: 58 additions & 43 deletions

File tree

src/window_interface/BAM_Statistics/PEStatOutput.java

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import javax.swing.JFrame;
1111
import javax.swing.JLayeredPane;
12+
import javax.swing.JOptionPane;
1213
import javax.swing.JScrollPane;
1314
import javax.swing.JTabbedPane;
1415
import javax.swing.JTextArea;
@@ -74,53 +75,67 @@ public PEStatOutput(Vector<File> input, File o, boolean out, boolean dup, int mi
7475
}
7576

7677
public void run() throws IOException {
77-
//Iterate through all BAM files in Vector
78+
// Check if BAI index file exists for all BAM files
79+
boolean[] BAMvalid = new boolean[bamFiles.size()];
80+
for (int z = 0; z < bamFiles.size(); z++) {
81+
File BAM = bamFiles.get(z); // Pull current BAM file
82+
File f = new File(BAM + ".bai"); // Generate file name for BAI index file
83+
if (!f.exists() || f.isDirectory()) {
84+
BAMvalid[z] = false;
85+
JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + BAM.getName());
86+
System.err.println("BAI Index File does not exist for: " + BAM.getName());
87+
} else {
88+
BAMvalid[z] = true;
89+
}
90+
}
91+
//Iterate through all BAM files in Vector
7892
for(int x = 0; x < bamFiles.size(); x++) {
79-
// Construct Basename
80-
File OUT_BASENAME = null;
81-
if(OUTPUT_STATUS){
82-
try{
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] ); }
93+
if (BAMvalid[x]) {
94+
// Construct Basename
95+
File OUT_BASENAME = null;
96+
if(OUTPUT_STATUS){
97+
try{
98+
if(OUT_DIR == null) { OUT_BASENAME = new File(bamFiles.get(x).getName().split("\\.")[0]); }
99+
else { OUT_BASENAME = new File( OUT_DIR.getCanonicalPath() + File.separator + bamFiles.get(x).getName().split("\\.")[0] ); }
100+
}
101+
catch (FileNotFoundException e) { e.printStackTrace(); }
85102
}
86-
catch (FileNotFoundException e) { e.printStackTrace(); }
87-
// catch (IOException e) { e.printStackTrace(); }
88-
}
89-
90-
// Initialize PrintStream and TextArea for PE stats (insert sizes)
91-
PrintStream ps_insert = null;
92-
JTextArea PE_STATS = new JTextArea();
93-
PE_STATS.setEditable(false);
94-
ps_insert = new PrintStream(new CustomOutputStream( PE_STATS ));
95-
// Initialize PrintStream and TextArea for DUP stats
96-
PrintStream ps_dup = null;
97-
JTextArea DUP_STATS = new JTextArea();
98-
if(DUP_STATUS) {
99-
DUP_STATS.setEditable(false);
100-
ps_dup = new PrintStream(new CustomOutputStream( DUP_STATS ));
101-
}
102103

103-
//Call public static method from scripts
104-
Vector<ChartPanel> charts = PEStats.getPEStats( OUT_BASENAME, bamFiles.get(x), DUP_STATUS, MIN_INSERT, MAX_INSERT, ps_insert, ps_dup, false );
105-
106-
//Add pe stats to tabbed pane
107-
PE_STATS.setCaretPosition(0);
108-
JScrollPane pe_pane = new JScrollPane(PE_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
109-
tabbedPane_InsertStats.add(bamFiles.get(x).getName(), pe_pane);
110-
tabbedPane_Histogram.add(bamFiles.get(x).getName(), charts.get(0));
111-
112-
if(DUP_STATUS) {
113-
//Add duplication stats to tabbed pane
114-
DUP_STATS.setCaretPosition(0);
115-
JScrollPane dup_pane = new JScrollPane(DUP_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
116-
tabbedPane_DupStats.add(bamFiles.get(x).getName(), dup_pane);
117-
tabbedPane_Duplication.add(bamFiles.get(x).getName(), charts.get(1));
104+
// Initialize PrintStream and TextArea for PE stats (insert sizes)
105+
PrintStream ps_insert = null;
106+
JTextArea PE_STATS = new JTextArea();
107+
PE_STATS.setEditable(false);
108+
ps_insert = new PrintStream(new CustomOutputStream( PE_STATS ));
109+
// Initialize PrintStream and TextArea for DUP stats
110+
PrintStream ps_dup = null;
111+
JTextArea DUP_STATS = new JTextArea();
112+
if(DUP_STATUS) {
113+
DUP_STATS.setEditable(false);
114+
ps_dup = new PrintStream(new CustomOutputStream( DUP_STATS ));
115+
}
116+
117+
//Call public static method from scripts
118+
Vector<ChartPanel> charts = PEStats.getPEStats( OUT_BASENAME, bamFiles.get(x), DUP_STATUS, MIN_INSERT, MAX_INSERT, ps_insert, ps_dup, false );
119+
120+
//Add pe stats to tabbed pane
121+
PE_STATS.setCaretPosition(0);
122+
JScrollPane pe_pane = new JScrollPane(PE_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
123+
tabbedPane_InsertStats.add(bamFiles.get(x).getName(), pe_pane);
124+
tabbedPane_Histogram.add(bamFiles.get(x).getName(), charts.get(0));
125+
126+
if(DUP_STATUS) {
127+
//Add duplication stats to tabbed pane
128+
DUP_STATS.setCaretPosition(0);
129+
JScrollPane dup_pane = new JScrollPane(DUP_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
130+
tabbedPane_DupStats.add(bamFiles.get(x).getName(), dup_pane);
131+
tabbedPane_Duplication.add(bamFiles.get(x).getName(), charts.get(1));
132+
}
133+
134+
if(ps_dup!=null) { ps_dup.close(); }
135+
ps_insert.close();
136+
137+
firePropertyChange("bam",x, x + 1);
118138
}
119-
120-
if(ps_dup!=null) { ps_dup.close(); }
121-
ps_insert.close();
122-
123-
firePropertyChange("bam",x, x + 1);
124139
}
125140
}
126141
}

0 commit comments

Comments
 (0)