Skip to content

Commit dd3fea7

Browse files
committed
create ExpandGFF 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/*/ ExpandGFFOutput class. As a result, fewer 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 -add capability to print to STDOUT 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 8776b45 commit dd3fea7

3 files changed

Lines changed: 89 additions & 14 deletions

File tree

src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import objects.ToolDescriptions;
1515
import util.ExtensionFileFilter;
16-
//import scripts.Coordinate_Manipulation.GFF_Manipulation.ExpandGFF;
16+
import scripts.Coordinate_Manipulation.GFF_Manipulation.ExpandGFF;
1717

1818
/**
1919
Coordinate_ManipulationCLI/ExpandGFFCLI
@@ -25,6 +25,26 @@
2525
exitCodeOnExecutionException = 1)
2626
public class ExpandGFFCLI implements Callable<Integer> {
2727

28+
@Parameters( index = "0", description = "the GFF file to expand on")
29+
private File gffFile;
30+
31+
@Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with coordinate info appended)")
32+
private File output = null;
33+
@Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT")
34+
private boolean stdout = false;
35+
36+
@ArgGroup(validate = false, heading = "%nType of Expansion%n")
37+
ExpandType expandType = new ExpandType();
38+
static class ExpandType {
39+
@Option(names = {"-c", "--center"}, description = "expand from center (default, at 250bp)")
40+
private int center = -999;
41+
@Option(names = {"-b", "--border"}, description = "add to border")
42+
private int border = -999;
43+
}
44+
45+
private boolean byCenter = true;
46+
private int SIZE = 250;
47+
2848
@Override
2949
public Integer call() throws Exception {
3050
System.err.println( ">ExpandGFFCLI.call()" );
@@ -35,16 +55,66 @@ public Integer call() throws Exception {
3555
System.exit(1);
3656
}
3757

38-
//SEStats.getSEStats( output, bamFile, null );
58+
ExpandGFF.expandGFFBorders(output, gffFile, SIZE, byCenter);
3959

40-
//System.err.println("Calculations Complete");
60+
System.err.println("Expansion Complete");
4161
return(0);
4262
}
4363

4464
private String validateInput() throws IOException {
4565
String r = "";
46-
//validate input here
47-
//append messages to the user to `r`
66+
67+
//check inputs exist
68+
if(!gffFile.exists()){
69+
r += "(!)GFF file does not exist: " + gffFile.getName() + "\n";
70+
return(r);
71+
}
72+
//check input extensions
73+
if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){
74+
r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n";
75+
}
76+
77+
// Define default behavior
78+
if(expandType.center==-999 && expandType.border==-999){
79+
SIZE = 250;
80+
byCenter = true;
81+
}else if(expandType.border==-999){
82+
SIZE = expandType.center;
83+
byCenter = false;
84+
}else if(expandType.center==-999){
85+
SIZE = expandType.border;
86+
byCenter = false;
87+
}else{
88+
r += "(!) Both center and border are flagged. This should have been caught by Picocli.";
89+
}
90+
//check size of expansion is valid
91+
if(SIZE<=0){
92+
r += "(!) Invalid size input. Must be a positive integer greater than 0.";
93+
}
94+
95+
//set default output filename
96+
if(output==null && !stdout){
97+
if(byCenter){ output = new File(ExtensionFileFilter.stripExtension(gffFile) + "_" + Integer.toString(SIZE) + "bp.gff"); }
98+
else{ output = new File(ExtensionFileFilter.stripExtension(gffFile) + "_border_" + Integer.toString(SIZE) + "bp.gff"); }
99+
//check stdout and output not both selected
100+
}else if(stdout){
101+
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
102+
//check output filename is valid
103+
}else{
104+
//check ext
105+
try{
106+
if(!"gff".equals(ExtensionFileFilter.getExtension(output))){
107+
r += "(!)Use GFF extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".gff\n";
108+
}
109+
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use GFF extension for output filename. Try: " + output + ".gff\n"; }
110+
//check directory
111+
if(output.getParent()==null){
112+
// System.err.println("default to current directory");
113+
} else if(!new File(output.getParent()).exists()){
114+
r += "(!)Check output directory exists: " + output.getParent() + "\n";
115+
}
116+
}
117+
48118
return(r);
49119
}
50-
}
120+
}

src/scripts/Coordinate_Manipulation/GFF_Manipulation/ExpandGFF.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
import java.util.Scanner;
88

99
public class ExpandGFF {
10-
public static void expandGFFBorders(File out_path, File input, int SIZE, boolean ExCenter) throws IOException {
10+
public static void expandGFFBorders(File out_filepath, File input, int SIZE, boolean ExCenter) throws IOException {
1111
//GFF: chr22 TeleGene enhancer 10000000 10001000 500 + . touch1
1212
//GFF: chr12 bed2gff chr12_384641_384659_+ 384642 384659 42.6 + . chr12_384641_384659_+;
13-
14-
String newName = (input.getName()).substring(0,input.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.gff";
15-
Scanner scan = new Scanner(input);
16-
PrintStream OUT = null;
17-
if(out_path == null) OUT = new PrintStream(newName);
18-
else OUT = new PrintStream(out_path + File.separator + newName);
13+
14+
Scanner scan = new Scanner(input);
15+
PrintStream OUT = System.out;
16+
if( out_filepath != null ) OUT = new PrintStream(out_filepath);
1917

2018
while (scan.hasNextLine()) {
2119
String[] temp = scan.nextLine().split("\t");

src/window_interface/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFWindow.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ public Void doInBackground() throws IOException {
7070
} else {
7171
setProgress(0);
7272
for(int x = 0; x < GFFFiles.size(); x++) {
73-
ExpandGFF.expandGFFBorders(OUTPUT_PATH, GFFFiles.get(x), SIZE, rdbtnExpandFromCenter.isSelected());
73+
File XGFF = GFFFiles.get(x);
74+
// Set outfilepath
75+
String newName = (XGFF.getName()).substring(0,XGFF.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.gff";
76+
File OUT_FILE = null;
77+
if(OUTPUT_PATH == null) OUT_FILE = new File( newName );
78+
else OUT_FILE = new File( OUTPUT_PATH + File.separator + newName );
79+
// Execute expansion and update progress
80+
ExpandGFF.expandGFFBorders(OUTPUT_PATH, XGFF, SIZE, rdbtnExpandFromCenter.isSelected());
7481
int percentComplete = (int)(((double)(x + 1) / GFFFiles.size()) * 100);
7582
setProgress(percentComplete);
7683
}

0 commit comments

Comments
 (0)