1313import java .io .PrintStream ;
1414
1515import scriptmanager .objects .ToolDescriptions ;
16+ import scriptmanager .objects .Exceptions .OptionException ;
1617import scriptmanager .util .ExtensionFileFilter ;
1718import scriptmanager .scripts .Sequence_Analysis .DNAShapefromBED ;
1819
2223 *
2324 * @author Olivia Lang
2425 */
25- @ Command (name = "dna-shape-bed" , mixinStandardHelpOptions = true , description = ToolDescriptions .dna_shape_from_bed_description , version = "ScriptManager "
26- + ToolDescriptions .VERSION , sortOptions = false , exitCodeOnInvalidInput = 1 , exitCodeOnExecutionException = 1 )
26+ @ Command (name = "dna-shape-bed" , mixinStandardHelpOptions = true ,
27+ description = ToolDescriptions .dna_shape_from_bed_description ,
28+ version = "ScriptManager " + ToolDescriptions .VERSION ,
29+ sortOptions = false ,
30+ exitCodeOnInvalidInput = 1 ,
31+ exitCodeOnExecutionException = 1 )
2732public class DNAShapefromBEDCLI implements Callable <Integer > {
2833
2934 /**
@@ -36,13 +41,16 @@ public DNAShapefromBEDCLI(){}
3641 @ Parameters (index = "1" , description = "the BED file of sequences to extract" )
3742 private File bedFile ;
3843
39- @ Option (names = { "-o" ,
40- "--output" }, description = "Specify basename for output files, files for each shape indicated will share this name with a different suffix" )
41- private String outputBasename = null ;
44+ @ Option (names = { "-o" , "--output" }, description = "Specify basename for output files, files for each shape indicated will share this name with a different suffix" )
45+ private File outputBasename = null ;
4246 @ Option (names = {"-z" , "--gzip" }, description = "gzip output (default=false)" )
4347 private boolean gzOutput = false ;
44- @ Option (names = { "--avg-composite" }, description = "Save average composite" )
45- private boolean avgComposite = false ;
48+ @ Option (names = { "--composite" }, description = "Save average composite (column-wise avg of matrix)" )
49+ private boolean composite = false ;
50+ @ Option (names = { "--matrix" }, description = "Save tab-delimited matrix of shape scores" )
51+ private boolean matrix = false ;
52+ @ Option (names = { "--cdt" }, description = "Save CDT-formatted matrix" )
53+ private boolean cdt = true ;
4654 @ Option (names = { "-n" , "--no-force" }, description = "don't force-strandedness (default is to force strandedness)" )
4755 private boolean forceStrand = true ;
4856
@@ -63,6 +71,7 @@ static class ShapeType {
6371 }
6472
6573 private boolean [] OUTPUT_TYPE = new boolean [] { false , false , false , false };
74+ private short outputMatrix = DNAShapefromBED .NO_MATRIX ;
6675
6776 /**
6877 * Runs when this subcommand is called, running script in respective script package with user defined arguments
@@ -78,36 +87,30 @@ public Integer call() throws Exception {
7887 System .exit (1 );
7988 }
8089
90+ // Generate Composite Plot
91+ DNAShapefromBED script_obj = new DNAShapefromBED (genomeFASTA , bedFile , outputBasename , OUTPUT_TYPE ,
92+ forceStrand , composite , outputMatrix , gzOutput );
93+ script_obj .run ();
8194 // Print Composite Scores
82- try {
83- // Generate Composite Plot
84- DNAShapefromBED script_obj = new DNAShapefromBED (genomeFASTA , bedFile , outputBasename , OUTPUT_TYPE ,
85- forceStrand , new PrintStream [] { null , null , null , null }, gzOutput );
86- script_obj .run ();
87-
88- if (avgComposite ) {
89- String [] headers = new String [] { "AVG_MGW" , "AVG_PropT" , "AVG_HelT" , "AVG_Roll" };
90- for (int t = 0 ; t < OUTPUT_TYPE .length ; t ++) {
91- if (OUTPUT_TYPE [t ]) {
92- PrintStream COMPOSITE = new PrintStream (new File (outputBasename + "_" + headers [t ] + ".out" ));
93- double [] AVG = script_obj .getAvg (t );
94- // position vals
95- for (int z = 0 ; z < AVG .length ; z ++) {
96- COMPOSITE .print ("\t " + z );
97- }
98- COMPOSITE .print ("\n " + ExtensionFileFilter .stripExtension (bedFile ) + "_" + headers [t ]);
99- // score vals
100- for (int z = 0 ; z < AVG .length ; z ++) {
101- COMPOSITE .print ("\t " + AVG [z ]);
102- }
103- COMPOSITE .println ();
95+ if (composite ) {
96+ String [] headers = new String [] { "AVG_MGW" , "AVG_PropT" , "AVG_HelT" , "AVG_Roll" };
97+ for (int t = 0 ; t < OUTPUT_TYPE .length ; t ++) {
98+ if (OUTPUT_TYPE [t ]) {
99+ PrintStream COMPOSITE = new PrintStream (new File (outputBasename + "_" + headers [t ] + ".out" ));
100+ double [] AVG = script_obj .getAvg (t );
101+ // position vals
102+ for (int z = 0 ; z < AVG .length ; z ++) {
103+ COMPOSITE .print ("\t " + z );
104104 }
105+ COMPOSITE .print ("\n " + ExtensionFileFilter .stripExtension (bedFile ) + "_" + headers [t ]);
106+ // score vals
107+ for (int z = 0 ; z < AVG .length ; z ++) {
108+ COMPOSITE .print ("\t " + AVG [z ]);
109+ }
110+ COMPOSITE .println ();
105111 }
106112 }
107- } catch (FileNotFoundException e ) {
108- e .printStackTrace ();
109113 }
110-
111114 System .err .println ("Shapes Calculated." );
112115 return (0 );
113116 }
@@ -134,10 +137,10 @@ private String validateInput() throws IOException {
134137 }
135138 // set default output filename
136139 if (outputBasename == null ) {
137- outputBasename = ExtensionFileFilter .stripExtension (bedFile );
140+ outputBasename = new File ( ExtensionFileFilter .stripExtension (bedFile ) );
138141 // check output filename is valid
139142 } else {
140- String outParent = new File ( outputBasename ) .getParent ();
143+ String outParent = outputBasename .getParent ();
141144 // no extension check
142145 // check directory
143146 if (outParent == null ) {
@@ -171,34 +174,59 @@ private String validateInput() throws IOException {
171174 OUTPUT_TYPE = new boolean [] { true , true , true , true };
172175 }
173176
177+ if (matrix && cdt ) {
178+ r += "(!)Please select either the matrix or the cdt flag.\n " ;
179+ } else if (matrix ) {
180+ outputMatrix = DNAShapefromBED .TAB ;
181+ } else if (cdt ) {
182+ outputMatrix = DNAShapefromBED .CDT ;
183+ }
184+
174185 return (r );
175186 }
176187
177188 /**
178189 * Reconstruct CLI command
179190 *
180- * @param gen the reference genome sequence in FASTA-format (FAI will be
181- * automatically generated)
182- * @param input the BED-formatted coordinate intervals to extract sequence from
183- * @param out the output file name base (to add _<shapetype>.cdt suffix
184- * to)
185- * @param type a four-element boolean list for specifying shape type to output
186- * (no enforcement on size)
187- * @param str force strandedness (true=forced, false=not forced)
188- * @param gzOutput whether or not to gzip output
191+ * @param gen the reference genome sequence in FASTA-format (FAI
192+ * will be automatically generated)
193+ * @param input the BED-formatted coordinate intervals to extract
194+ * sequence from
195+ * @param out the output file name base (to add
196+ * _<shapetype>.cdt suffix to)
197+ * @param type a four-element boolean list for specifying shape type
198+ * to output (no enforcement on size)
199+ * @param str force strandedness (true=forced, false=not forced)
200+ * @param outputComposite whether to output a composite average output
201+ * @param outputMatrix value encoding not to write output matrix data, write
202+ * matrix in CDT format, and write matrix in tab format
203+ * @param gzOutput whether or not to gzip output
189204 * @return command line to execute with formatted inputs
190205 */
191- public static String getCLIcommand (File gen , File input , String out , boolean [] type , boolean str , boolean gzOutput ) {
206+ public static String getCLIcommand (File gen , File input , File out , boolean [] type , boolean str , boolean outputComposite , short outputMatrix , boolean gzOutput ) throws OptionException {
192207 String command = "java -jar $SCRIPTMANAGER sequence-analysis dna-shape-bed" ;
193- command += " -o " + out ;
208+ command += " -o " + out . getAbsolutePath () ;
194209 command += gzOutput ? " -z " : "" ;
195210 command += type [0 ] ? " --groove" : "" ;
196211 command += type [1 ] ? " --propeller" : "" ;
197212 command += type [2 ] ? " --helical" : "" ;
198213 command += type [3 ] ? " --roll" : "" ;
199214 command += str ? "" : "--no-force" ;
200- command += " " + gen ;
201- command += " " + input ;
215+ command += outputComposite ? "--composite" : "" ;
216+ switch (outputMatrix ) {
217+ case DNAShapefromBED .NO_MATRIX :
218+ break ;
219+ case DNAShapefromBED .TAB :
220+ command += " --matrix" ;
221+ break ;
222+ case DNAShapefromBED .CDT :
223+ command += " --cdt" ;
224+ break ;
225+ default :
226+ throw new OptionException ("outputMatrix type value " + outputMatrix + " not supported" );
227+ }
228+ command += " " + gen .getAbsolutePath ();
229+ command += " " + input .getAbsolutePath ();
202230 return (command );
203231 }
204232}
0 commit comments