Skip to content

Commit c99547f

Browse files
committed
output composite via printstream to fix overwrite
Problem: When the gui wrote the composite output to the composite_average.out file, runs with multiple BED x BAM combinations would be sequentially overwritten. This was fixed by changing the PileupParams composite output object to a PrintStream that could be initialized at the TagPileupWindow object before iterating through each BAM and BED file. The get and set methods for the PileupParams were updated accordingly for all classes that used the get/setCompositeFile --> get/setCompositePrintStream.
1 parent 6df782c commit c99547f

5 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.File;
1313
import java.io.IOException;
14+
import java.io.PrintStream;
1415

1516
import util.BAMUtilities;
1617
import util.ExtensionFileFilter;
@@ -263,7 +264,7 @@ else if(readType.midpoint){
263264
p.setOutputCompositeStatus(true);
264265

265266
//Set COMPOSITE file
266-
p.setCompositeFile(outputOptions.outputComposite);
267+
p.setCompositePrintStream(new PrintStream(outputOptions.outputComposite));
267268

268269
//Set READ
269270
p.setRead(readType.finalRead);

src/objects/PileupParameters.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import java.awt.Color;
44
import java.io.File;
55
import java.util.ArrayList;
6+
import java.io.PrintStream;
67

78
public class PileupParameters {
89
//Directory to save matrix and composite into
910
private File OUTPUT = null;
1011
//Composite values file if output
11-
private String COMPOSITE = null;
12+
private PrintStream COMPOSITE = null;
1213

1314
//Read type:
1415
// 0=read1, 1=read2, 2=allreads, 3=midpoint
@@ -126,10 +127,10 @@ public void setPErequire(boolean status) {
126127
requirePE = status;
127128
}
128129

129-
public String getCompositeFile() {
130+
public PrintStream getCompositePrintStream() {
130131
return COMPOSITE;
131132
}
132-
public void setCompositeFile(String comp) {
133+
public void setCompositePrintStream(PrintStream comp) {
133134
COMPOSITE = comp;
134135
}
135136

src/scripts/Read_Analysis/TagPileup.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,7 @@ public void run() throws IOException {
242242
DOMAIN = DOMAIN_trim;
243243

244244
// Output composite data file setup
245-
if (PARAM.getOutputCompositeStatus()) {
246-
try {
247-
COMPOSITE = new PrintStream(PARAM.getCompositeFile());
248-
} catch (FileNotFoundException e) {
249-
e.printStackTrace();
250-
}
251-
}
245+
COMPOSITE = PARAM.getCompositePrintStream();
252246

253247
// Output composite data to tab-delimited file
254248
if (COMPOSITE != null) {

src/window_interface/Read_Analysis/TagPileupOutput.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.awt.BorderLayout;
44
import java.io.File;
5-
import java.io.FileNotFoundException;
65
import java.io.IOException;
76
import java.io.PrintStream;
87
import java.util.Vector;
@@ -63,14 +62,6 @@ public TagPileupOutput(Vector<File> be, Vector<File> ba, PileupParameters param)
6362
}
6463

6564
public void run() throws IOException {
66-
if (PARAM.getOutputCompositeStatus()) {
67-
try {
68-
COMPOSITE = new PrintStream(PARAM.getCompositeFile());
69-
} catch (FileNotFoundException e) {
70-
e.printStackTrace();
71-
}
72-
}
73-
7465
// Check if BAI index file exists for all BAM files
7566
boolean[] BAMvalid = new boolean[BAMFiles.size()];
7667
for (int z = 0; z < BAMFiles.size(); z++) {

src/window_interface/Read_Analysis/TagPileupWindow.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import java.beans.PropertyChangeEvent;
1313
import java.beans.PropertyChangeListener;
1414
import java.io.File;
15+
import java.io.FileNotFoundException;
1516
import java.io.IOException;
17+
import java.io.PrintStream;
1618
import java.util.Vector;
1719

1820
import javax.swing.ButtonGroup;
@@ -166,7 +168,13 @@ public Void doInBackground() throws IOException, InterruptedException {
166168
else { param.setOutputDirectory(OUT_DIR); }
167169

168170
param.setOutputCompositeStatus(chckbxOutputCompositeData.isSelected()); //Outputs composite plots if check box is selected
169-
if(chckbxOutputCompositeData.isSelected()) { param.setCompositeFile(OUT_DIR + File.separator + txtCompositeName.getText()); }
171+
if(chckbxOutputCompositeData.isSelected()) {
172+
try {
173+
param.setCompositePrintStream(new PrintStream(OUT_DIR + File.separator + txtCompositeName.getText()));
174+
} catch (FileNotFoundException e) {
175+
e.printStackTrace();
176+
}
177+
}
170178

171179
if (chckbxOutputData.isSelected()) {
172180
if (rdbtnTabdelimited.isSelected()) { param.setOutputType(1); }

0 commit comments

Comments
 (0)