@@ -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
0 commit comments