Skip to content

Commit 4e28799

Browse files
committed
create RandomCoordinate command line version
This tool did not implement JFrame elements in the script class so the CLI implementation did not need to create an src/window_interface/*/ RandomCoordinateOutput class. As a result, no need to create an Output window class so fewer edits to be made: window_interface/*Window -adjust output argument when initializing script class to be full filename and not just directory script/* -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user
1 parent b0a813f commit 4e28799

3 files changed

Lines changed: 66 additions & 8 deletions

File tree

src/cli/Peak_Analysis/RandomCoordinateCLI.java

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import objects.ToolDescriptions;
1414
import util.ExtensionFileFilter;
15-
//import scripts.Peak_Analysis.RandomCoordinate;
15+
import scripts.Peak_Analysis.RandomCoordinate;
1616

1717
/**
1818
Peak_AnalysisCLI/RandomCoordinateCLI
@@ -24,6 +24,18 @@
2424
exitCodeOnExecutionException = 1)
2525
public class RandomCoordinateCLI implements Callable<Integer> {
2626

27+
@Parameters( index = "0", description = "reference genome [sacCer3_cegr|hg19|hg19_contigs|mm10]")
28+
private String genomeName;
29+
30+
@Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be random_coordinates_<genomeName>_<window>bp.<ext>")
31+
private File output = null;
32+
@Option(names = {"-f", "--gff"}, description = "file format output as GFF (default format as BED)")
33+
private boolean formatIsBed = true;
34+
@Option(names = {"-n", "--num-sites"}, description = "number of sites (default=1000)")
35+
private int numSites = 1000;
36+
@Option(names = {"-w", "--window"}, description = "window size in bp (default=200)")
37+
private int window = 200;
38+
2739
@Override
2840
public Integer call() throws Exception {
2941
System.err.println( ">RandomCoordinateCLI.call()" );
@@ -34,16 +46,52 @@ public Integer call() throws Exception {
3446
System.exit(1);
3547
}
3648

37-
//SEStats.getSEStats( output, bamFile, null );
49+
RandomCoordinate script_obj = new RandomCoordinate(genomeName, numSites, window, formatIsBed, output);
50+
script_obj.execute();
3851

39-
//System.err.println("Calculations Complete");
52+
System.err.println( "Random Coordinate Generation Complete." );
4053
return(0);
4154
}
4255

4356
private String validateInput() throws IOException {
4457
String r = "";
45-
//validate input here
46-
//append messages to the user to `r`
58+
59+
//check input genomes are valid
60+
if(genomeName.equals("sacCer3_cegr") || genomeName.equals("hg19") || genomeName.equals("hg19_contigs") || genomeName.equals("mm10") ){
61+
// System.err.println("Input genomeName is valid");
62+
}else{
63+
r += "(!)Invalid genomeName selected(" +genomeName+ "), please select from one of the provided genomes: sacCer3_cegr, hg19, hg19_contigs, and mm10\n";
64+
}
65+
String ext = "gff";
66+
if(formatIsBed){ ext = "bed"; }
67+
//set default output filename
68+
if(output==null){
69+
output = new File("random_coordinates_" + genomeName + "_" + numSites + "sites_" + window + "bp." + ext);
70+
//check output filename is valid
71+
}else{
72+
//check ext
73+
try{
74+
if(!ext.equals(ExtensionFileFilter.getExtension(output))){
75+
r += "(!)Use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + "." + ext + "\n";
76+
}
77+
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + output + "." + ext + "\n"; }
78+
//check directory
79+
if(output.getParent()==null){
80+
// System.err.println("default to current directory");
81+
} else if(!new File(output.getParent()).exists()){
82+
r += "(!)Check output directory exists: " + output.getParent() + "\n";
83+
}
84+
}
85+
86+
//check number of sites
87+
if( numSites<1 ){
88+
r += "(!)Number of sites needs to be a positive integer.\n";
89+
}
90+
//check window size
91+
if( window<1 ){
92+
r += "(!)Window size needs to be a positive integer.\n";
93+
}
94+
4795
return(r);
4896
}
49-
}
97+
}

src/scripts/Peak_Analysis/RandomCoordinate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void execute() throws IOException {
3939
String randomName = GENOME + "_" + numSites + "SITES_" + windowSize + "bp" + EXTENSION;
4040
PrintStream OUT = null;
4141
if(OUTPUT == null) OUT = new PrintStream(randomName);
42-
else OUT = new PrintStream(OUTPUT + File.separator + randomName);
42+
else OUT = new PrintStream(OUTPUT);
4343
for(int x = 0; x < numSites; x++) {
4444
GenericCoord temp = coord.generateRandomCoord(windowSize);
4545
if(BEDout) {

src/window_interface/Peak_Analysis/RandomCoordinateWindow.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ public Void doInBackground() throws IOException, InterruptedException {
5858
} else if(Integer.parseInt(txtSize.getText()) < 1) {
5959
JOptionPane.showMessageDialog(null, "Invalid Window Size Entered!!!");
6060
} else {
61-
RandomCoordinate generate = new RandomCoordinate((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSites.getText()), Integer.parseInt(txtSize.getText()), rdbtnBed.isSelected(), OUTPUT_PATH);
61+
boolean bedStatus = rdbtnBed.isSelected();
62+
String randomName = (String)cmbGenome.getSelectedItem() + "_" + Integer.parseInt(txtSites.getText()) + "SITES_" + Integer.parseInt(txtSize.getText()) + "bp";
63+
if(bedStatus){ randomName += ".bed"; }
64+
else{ randomName += ".gff"; }
65+
File OUTFILE;
66+
if(OUTPUT_PATH != null){
67+
OUTFILE = new File(OUTPUT_PATH + File.separator + randomName);
68+
}else{
69+
OUTFILE = new File(randomName);
70+
}
71+
RandomCoordinate generate = new RandomCoordinate((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSites.getText()), Integer.parseInt(txtSize.getText()), bedStatus, OUTFILE);
6272
generate.execute();
6373
JOptionPane.showMessageDialog(null, "Random Coordinate Generation Complete");
6474
}

0 commit comments

Comments
 (0)