Skip to content

Commit 932a3bf

Browse files
committed
create TileGenome 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/*/ TileGenomeOutput class. As a result, just the following files were affected: 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 4e28799 commit 932a3bf

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

src/cli/Peak_Analysis/TileGenomeCLI.java

Lines changed: 47 additions & 5 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.TileGenome;
15+
import scripts.Peak_Analysis.TileGenome;
1616

1717
/**
1818
Peak_AnalysisCLI/TileGenomeCLI
@@ -24,6 +24,16 @@
2424
exitCodeOnExecutionException = 1)
2525
public class TileGenomeCLI 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 genome_tiles_<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 = {"-w", "--window"}, description = "window size in bp (default=200)")
35+
private int window = 200;
36+
2737
@Override
2838
public Integer call() throws Exception {
2939
System.err.println( ">TileGenomeCLI.call()" );
@@ -34,16 +44,48 @@ public Integer call() throws Exception {
3444
System.exit(1);
3545
}
3646

37-
//SEStats.getSEStats( output, bamFile, null );
47+
TileGenome script_obj = new TileGenome(genomeName, window, formatIsBed, output);
48+
script_obj.execute();
3849

39-
//System.err.println("Calculations Complete");
50+
System.err.println( "Genomic Tiling Complete." );
4051
return(0);
4152
}
4253

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

src/scripts/Peak_Analysis/TileGenome.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public void execute() throws IOException {
2929

3030
String fileName = GENOME + "_" + windowSize + "bp" + EXTENSION;
3131
PrintStream OUT = null;
32-
if(OUTPUT == null) OUT = new PrintStream(fileName);
33-
else OUT = new PrintStream(OUTPUT + File.separator + fileName);
32+
if(OUTPUT == null) OUT = new PrintStream(new File(fileName));
33+
else OUT = new PrintStream(OUTPUT);
3434

3535
for(int x = 0; x < coord.getChrom().size(); x++) {
3636
String CHROM = coord.getChrom().get(x);

src/window_interface/Peak_Analysis/TileGenomeWindow.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ public Void doInBackground() throws IOException, InterruptedException {
5353
} else if(Integer.parseInt(txtSize.getText()) < 1) {
5454
JOptionPane.showMessageDialog(null, "Invalid Window Size Entered!!!");
5555
} else {
56-
TileGenome generate = new TileGenome((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSize.getText()), rdbtnBed.isSelected(), OUTPUT_PATH);
56+
boolean bedStatus = rdbtnBed.isSelected();
57+
String randomName = (String)cmbGenome.getSelectedItem() + "_" + Integer.parseInt(txtSize.getText()) + "bp";
58+
if(bedStatus){ randomName += ".bed"; }
59+
else{ randomName += ".gff"; }
60+
File OUTFILE;
61+
if(OUTPUT_PATH != null){
62+
OUTFILE = new File(OUTPUT_PATH + File.separator + randomName);
63+
}else{
64+
OUTFILE = new File(randomName);
65+
}
66+
TileGenome generate = new TileGenome((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSize.getText()), bedStatus, OUTFILE);
5767
generate.execute();
5868
JOptionPane.showMessageDialog(null, "Genomic Tiling Complete");
5969
}

0 commit comments

Comments
 (0)