Skip to content

Commit accf3ff

Browse files
authored
Merge pull request #98 from CEGRcode/tagpileup-overhaul
Tagpileup overhaul
2 parents 190598d + 30d2ae9 commit accf3ff

6 files changed

Lines changed: 662 additions & 268 deletions

File tree

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ static class OutputOptions{
5858
private boolean tab = false;
5959
}
6060

61+
//Aspect
62+
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Aspect of Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
63+
AspectType aspectType = new AspectType();
64+
static class AspectType {
65+
@Option(names = {"-5", "--five-prime"}, description = "pileup of 5' end of read(default)")
66+
boolean fiveprime = false;
67+
@Option(names = {"-3", "--three-prime"}, description = "pileup of 3' end of read")
68+
boolean threeprime = false;
69+
@Option(names = {"-m", "--midpoint"}, description = "pileup fragment midpoints (require PE, combined)")
70+
boolean midpoint = false;
71+
}
72+
6173
//Read
6274
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
6375
ReadType readType = new ReadType();
@@ -68,9 +80,6 @@ static class ReadType {
6880
boolean read2 = false;
6981
@Option(names = {"-a", "--all-reads"}, description = "pileup all reads")
7082
boolean allreads = false;
71-
@Option(names = {"-m", "--midpoint"}, description = "pile midpoint (require PE and combined, -p --combined)")
72-
boolean midpoint = false;
73-
int finalRead = 0;
7483
}
7584

7685
//Strand
@@ -148,15 +157,15 @@ public Integer call() throws Exception {
148157
private String validateInput() throws IOException {
149158
String r = "";
150159

151-
//check ReadType, interpret booleans for int value
152-
if(readType.read1){ readType.finalRead = 0; }
153-
else if(readType.read2){ readType.finalRead = 1; }
154-
else if(readType.allreads){ readType.finalRead = 2; }
155-
else if(readType.midpoint){
156-
readType.finalRead = 3;
157-
filterOptions.requirePE = true;
158-
combStatus = true;
159-
}
160+
// Set ASPECT
161+
if(aspectType.fiveprime) { p.setAspect(0); }
162+
else if(aspectType.threeprime) { p.setAspect(1); }
163+
else if(aspectType.midpoint) { p.setAspect(2); }
164+
165+
// Set READ
166+
if(readType.read1){ p.setRead(0); }
167+
else if(readType.read2){ p.setRead(1); }
168+
else if(readType.allreads){ p.setRead(2); }
160169

161170
//check input extensions
162171
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
@@ -192,39 +201,15 @@ else if(readType.midpoint){
192201
}
193202
}
194203

195-
//set default output MATRIX (if output MATRIX not to be output)
196-
if(outputOptions.outputMatrix.size()>1){
197-
outputOptions.outputMatrix.set(0,null);
198-
//set default output MATRIX basename (allow scripts/*/TagPileup to generate ret of filename)
199-
} else if(outputOptions.outputMatrix.size()==0){ //generate default basename
200-
String readString = "read1";
201-
if(readType.finalRead == 1) { readString = "read2"; }
202-
else if(readType.finalRead == 2) { readString = "allreads"; }
203-
else if(readType.finalRead == 3) { readString = "midpoint"; }
204-
outputOptions.outputMatrix.add(
205-
ExtensionFileFilter.stripExtension(new File(bedFile.getName())) + "_" +
206-
ExtensionFileFilter.stripExtension(new File(bamFile.getName())) + "_" + readString);
207-
//check output filename is valid
208-
}else{ //check basename
209-
File output = new File(outputOptions.outputMatrix.get(0));
210-
//no extension check b/c basename should have no extension
211-
//check directory
212-
if(output.getParent()==null){
213-
// System.err.println("default to current directory");
214-
} else if(!new File(output.getParent()).exists()){
215-
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
216-
}
217-
}
218-
219204
//validate smooth params
220205
if(smoothType.winVals!=-9999 && smoothType.winVals<1){ r += "(!)Invalid Smoothing Window Size. Must be larger than 0 bins, winSize=" + smoothType.winVals + "\n"; }
221206
if(smoothType.winVals!=-9999 && smoothType.winVals%2==0){ r += "(!)Invalid Smoothing Window Size. Must be odd for symmetrical smoothing (so that the window is centered properly), winSize=" + smoothType.winVals + "\n"; }
222207
if(smoothType.gaussVals[0]!=-9999 && smoothType.gaussVals[0]<1){ r += "(!)Invalid Standard Deviation Size. Must be larger than 0 bins, stdSize=" + smoothType.gaussVals[0] + "\n"; }
223208
if(smoothType.gaussVals[1]!=-9999 && smoothType.gaussVals[1]<1){ r += "(!)Invalid Number of Standard Deviations. Must be larger than 0 standard deviations, stdNum=" + smoothType.gaussVals[1] + "\n"; }
224209

225210
//set require PE for appropriate flags
226-
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999){ filterOptions.requirePE = true; }
227-
if( readType.midpoint ){ filterOptions.requirePE = true; }
211+
p.setPErequire(filterOptions.requirePE);
212+
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getAspect()==2) { p.setPErequire(true); }
228213

229214
//validate shift, binSize, and CPUs
230215
if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; }
@@ -238,38 +223,41 @@ else if(readType.midpoint){
238223
r += "(!)MAX_INSERT must be larger/equal to MIN_INSERT: " + filterOptions.MIN_INSERT + "," + filterOptions.MAX_INSERT + "\n";
239224
}
240225

241-
// LOAD UP PileupParameters OBJECT!
242-
243-
//Set OUTPUT
244-
if(outputOptions.outputMatrix.size()<=1){
245-
p.setOutputType(2); //default behavior
246-
//check output type
247-
if(outputOptions.cdt && outputOptions.tab) { //both set? write error
248-
r += "(!)Cannot flag both --cdt and --tab. Please choose one.";
249-
} else if(outputOptions.tab){ //set tab
250-
p.setOutputType(1);
251-
}
252-
}else{
253-
outputOptions.outputMatrix.set(0,null);
254-
p.setOutputType(0); //no matrix output
255-
if(outputOptions.cdt){
256-
p.setOutputType(2);
257-
outputOptions.outputMatrix.set(0,null);
258-
} else if(outputOptions.tab) {
259-
p.setOutputType(1);
260-
outputOptions.outputMatrix.set(0,null);
226+
// No Matrix Output
227+
if(outputOptions.outputMatrix.size() > 1){
228+
p.setOutputType(0);
229+
if(outputOptions.cdt || outputOptions.tab) { r += "(!)Cannot flag --cdt or --tab without -M."; }
230+
// Output Matrix
231+
} else {
232+
// Determine output type
233+
p.setOutputType(2);
234+
if(outputOptions.cdt && outputOptions.tab) { r += "(!)Cannot flag both --cdt and --tab. Please choose one."; }
235+
else if(outputOptions.tab) { p.setOutputType(1); }
236+
// No matrix basename specified
237+
if(outputOptions.outputMatrix.size() == 0) {
238+
outputOptions.outputMatrix.add(null);
239+
if(p.getOutputDirectory() == null) {
240+
p.setOutputDirectory(new File(System.getProperty("user.dir")));
241+
}
242+
// Validate matrix specified basename
243+
} else if(outputOptions.outputMatrix.size() == 1) {
244+
File output = new File(outputOptions.outputMatrix.get(0));
245+
// Check parent directory is non-null and exists
246+
if(output.getParent()!=null){
247+
if(!new File(output.getParent()).exists()) {
248+
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
249+
}
250+
}
261251
}
262252
}
263-
p.setOutputCompositeStatus(true);
264253

265254
//Set COMPOSITE file
255+
p.setOutputCompositeStatus(true);
266256
p.setCompositePrintStream(new PrintStream(outputOptions.outputComposite));
267257

268-
//Set READ
269-
p.setRead(readType.finalRead);
270258
//Set STRAND
271259
p.setStrand(0);
272-
if(combStatus) { p.setStrand(1); }
260+
if(combStatus || p.getAspect() == 2) { p.setStrand(1); }
273261

274262
//Set smooth type and parameters
275263
if(smoothType.noSmooth){ //default behavior
@@ -299,9 +287,6 @@ else if(readType.midpoint){
299287
p.setBlacklist(filterOptions.blacklistFilter);
300288
p.setStandard(calcOptions.tagsEqual);
301289

302-
//Set PE requirement
303-
p.setPErequire(filterOptions.requirePE);
304-
305290
//Set output statuses
306291
p.setGZIPstatus(outputOptions.zip);
307292

src/objects/PileupParameters.java

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,46 @@
33
import java.io.File;
44
import java.io.PrintStream;
55

6+
/**
7+
* Object for storing pileup-related parameter information and constants.
8+
* @see scripts.Read_Analysis.PileupScripts.PileupExtract
9+
* @author William KM Lai
10+
*/
11+
612
public class PileupParameters {
7-
//Directory to save matrix and composite into
8-
private File OUTPUT = null;
9-
//Composite values file if output
10-
private PrintStream COMPOSITE = null;
13+
//Read aspect
14+
final static int FIVE = 0;
15+
final static int THREE = 1;
16+
final static int MIDPOINT = 2;
17+
final static int FRAGMENT = 3;
18+
private int ASPECT = PileupParameters.FIVE;
1119

12-
//Read type:
13-
// 0=read1, 1=read2, 2=allreads, 3=midpoint
14-
private int READ = 0;
20+
//Read type
21+
final static int READ1 = 0;
22+
final static int READ2 = 1;
23+
final static int ALLREADS = 2;
24+
private int READ = PileupParameters.READ1;
1525

16-
//Strand type:
17-
// 0=separate, 1=combined
18-
private int STRAND = 0;
26+
//Strand type
27+
final static int COMBINED = 1;
28+
final static int SEPARATE = 0;
29+
private int STRAND = PileupParameters.SEPARATE;
30+
31+
//Transformation/smoothing type
32+
final static int NO_SMOOTH = 0;
33+
final static int WINDOW = 1;
34+
final static int GAUSSIAN = 2;
35+
private int TRANS = PileupParameters.NO_SMOOTH;
1936

20-
//Transformation/smoothing type:
21-
// 0=no_smooth, 1=window, 2=gaussian
22-
private int TRANS = 0;
2337
//TRANS=1 parameters: window size (#bins)
2438
private int SMOOTH = 0;
25-
//TRANS=2 parameters: stdev window size (#bins) and number of standard devations
39+
//TRANS=2 parameters: stdev window size (#bins) and number of standard deviations
2640
private int STDSIZE = 0;
27-
private int STDNUM = 0;
41+
private int STDNUM = 0;
2842

2943
private int SHIFT = 0;
3044
private int BIN = 1;
45+
private int TAGEXTEND = 0;
3146
private int CPU = 1;
3247
private int OUTTYPE = 0; //0=no output, 1=TAB, 2=CDT
3348
private File BLACKLIST = null;
@@ -39,16 +54,23 @@ public class PileupParameters {
3954

4055
private int MIN_INSERT = -9999;
4156
private int MAX_INSERT = -9999;
42-
57+
58+
//Directory to save matrix and composite into
59+
private File OUTPUT = null;
60+
//Composite values file if output
61+
private PrintStream COMPOSITE = null;
62+
4363
public void printAll(){
4464
System.out.println( "<><><><><><><><><><><><><><><><><><><><>" );
4565
System.out.println( "private File OUTPUT = " + OUTPUT );
4666
System.out.println( "private String COMPOSITE = " + COMPOSITE );
4767
System.out.println( "private int READ = " + READ );
68+
System.out.println( "private int ASPECT = " + ASPECT );
4869
System.out.println( "private int STRAND = " + STRAND );
4970
System.out.println( "private int TRANS = " + TRANS );
5071
System.out.println( "private int SHIFT = " + SHIFT );
5172
System.out.println( "private int BIN = " + BIN );
73+
System.out.println( "private int TAGEXTEND = " + TAGEXTEND );
5274
System.out.println( "private int SMOOTH = " + SMOOTH );
5375
System.out.println( "private int STDSIZE = " + STDSIZE );
5476
System.out.println( "private int STDNUM = " + STDNUM );
@@ -144,6 +166,13 @@ public void setOutputDirectory(File oUTPUT) {
144166
OUTPUT = oUTPUT;
145167
}
146168

169+
public int getAspect() {
170+
return ASPECT;
171+
}
172+
public void setAspect(int aSPECT) {
173+
ASPECT = aSPECT;
174+
}
175+
147176
public int getRead() {
148177
return READ;
149178
}
@@ -179,6 +208,13 @@ public void setBin(int bIN) {
179208
BIN = bIN;
180209
}
181210

211+
public int getTagExtend() {
212+
return TAGEXTEND;
213+
}
214+
public void setTagExtend(int tAGEXTEND) {
215+
TAGEXTEND = tAGEXTEND;
216+
}
217+
182218
public int getSmooth() {
183219
return SMOOTH;
184220
}

0 commit comments

Comments
 (0)