Skip to content

Commit 5fa82c1

Browse files
committed
clean-up TagPileupCLI param assignment
There is a lot of redundant code that this commit helps to streamline for future development. -ReadType directly updated instead of changing intermediate variables -RequirePE directly updated instead of changing intermediate variables -Output Matrix validation structures dramatically consolidated: -No matrix output vs make default matrix basename vs user provides matrix basename -Output type flags related to matrix validated once -Default basename construction left to TagPileup script like TagPileupWindow -PileupParams output directory assigned a value as needed -parent directory of matrix basename validated if user provided -Strand directly updated instead of changing intermediate variables (like changing when ReadType=midpoint)
1 parent d312227 commit 5fa82c1

1 file changed

Lines changed: 34 additions & 62 deletions

File tree

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,11 @@ public Integer call() throws Exception {
148148
private String validateInput() throws IOException {
149149
String r = "";
150150

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-
}
151+
// Set READ
152+
if(readType.read1){ p.setRead(0); }
153+
else if(readType.read2){ p.setRead(1); }
154+
else if(readType.allreads){ p.setRead(2); }
155+
else if(readType.midpoint){ p.setRead(3); }
160156

161157
//check input extensions
162158
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
@@ -192,38 +188,14 @@ else if(readType.midpoint){
192188
}
193189
}
194190

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-
219191
//validate smooth params
220192
if(smoothType.winVals!=-9999 && smoothType.winVals<1){ r += "(!)Invalid Smoothing Window Size. Must be larger than 0 bins, winSize=" + smoothType.winVals + "\n"; }
221193
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"; }
222194
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"; }
223195

224196
//set require PE for appropriate flags
225-
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999){ filterOptions.requirePE = true; }
226-
if( readType.midpoint ){ filterOptions.requirePE = true; }
197+
p.setPErequire(filterOptions.requirePE);
198+
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getRead() == 3) { p.setPErequire(true); }
227199

228200
//validate shift, binSize, and CPUs
229201
if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; }
@@ -237,38 +209,41 @@ else if(readType.midpoint){
237209
r += "(!)MAX_INSERT must be larger/equal to MIN_INSERT: " + filterOptions.MIN_INSERT + "," + filterOptions.MAX_INSERT + "\n";
238210
}
239211

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

264240
//Set COMPOSITE file
241+
p.setOutputCompositeStatus(true);
265242
p.setCompositePrintStream(new PrintStream(outputOptions.outputComposite));
266243

267-
//Set READ
268-
p.setRead(readType.finalRead);
269244
//Set STRAND
270245
p.setStrand(0);
271-
if(combStatus) { p.setStrand(1); }
246+
if(combStatus || p.getRead() == 3) { p.setStrand(1); }
272247

273248
//Set smooth type and parameters
274249
if(smoothType.noSmooth){ //default behavior
@@ -298,9 +273,6 @@ else if(readType.midpoint){
298273
p.setBlacklist(filterOptions.blacklistFilter);
299274
p.setStandard(calcOptions.tagsEqual);
300275

301-
//Set PE requirement
302-
p.setPErequire(filterOptions.requirePE);
303-
304276
//Set output statuses
305277
p.setGZIPstatus(outputOptions.zip);
306278

0 commit comments

Comments
 (0)