Skip to content

Commit dbb3200

Browse files
committed
create BEDtoGFF 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/*/ BEDtoGFFOutput 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 dd3fea7 commit dbb3200

3 files changed

Lines changed: 56 additions & 12 deletions

File tree

src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java

Lines changed: 43 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.Coordinate_Manipulation.BED_Manipulation.BEDtoGFF;
15+
import scripts.Coordinate_Manipulation.BED_Manipulation.BEDtoGFF;
1616

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

27+
@Parameters( index = "0", description = "the BED file to convert")
28+
private File bedFile;
29+
30+
@Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .gff ext)")
31+
private File output = null;
32+
@Option(names = {"-s", "--stdout"}, description = "output gff to STDOUT")
33+
private boolean stdout = false;
34+
2735
@Override
2836
public Integer call() throws Exception {
2937
System.err.println( ">BEDtoGFFCLI.call()" );
@@ -34,16 +42,46 @@ public Integer call() throws Exception {
3442
System.exit(1);
3543
}
3644

37-
//SEStats.getSEStats( output, bamFile, null );
45+
BEDtoGFF.convertBEDtoGFF(output, bedFile);
3846

39-
//System.err.println("Calculations Complete");
47+
System.err.println("Conversion Complete");
4048
return(0);
4149
}
4250

4351
private String validateInput() throws IOException {
4452
String r = "";
45-
//validate input here
46-
//append messages to the user to `r`
53+
54+
//check inputs exist
55+
if(!bedFile.exists()){
56+
r += "(!)BED file does not exist: " + bedFile.getName() + "\n";
57+
return(r);
58+
}
59+
//check input extensions
60+
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
61+
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
62+
}
63+
//set default output filename
64+
if(output==null && !stdout){
65+
output = new File(ExtensionFileFilter.stripExtension(bedFile) + ".gff");
66+
//check stdout and output not both selected
67+
}else if(stdout){
68+
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
69+
//check output filename is valid
70+
}else{
71+
//check ext
72+
try{
73+
if(!"gff".equals(ExtensionFileFilter.getExtension(output))){
74+
r += "(!)Use BED extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".bed\n";
75+
}
76+
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use BED extension for output filename. Try: " + output + ".youroutputextensionhere\n"; }
77+
//check directory
78+
if(output.getParent()==null){
79+
// System.err.println("default to current directory");
80+
} else if(!new File(output.getParent()).exists()){
81+
r += "(!)Check output directory exists: " + output.getParent() + "\n";
82+
}
83+
}
84+
4785
return(r);
4886
}
4987
}

src/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java

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

99
public class BEDtoGFF {
10-
public static void convertBEDtoGFF(File out_path, File input) throws IOException {
10+
public static void convertBEDtoGFF(File out_filepath, File input) throws IOException {
1111
//chr22 TeleGene enhancer 10000000 10001000 500 + . touch1
12-
String gffName = (input.getName()).substring(0,input.getName().length() - 4) + ".gff";
13-
Scanner scan = new Scanner(input);
14-
PrintStream OUT = null;
15-
if(out_path == null) OUT = new PrintStream(gffName);
16-
else OUT = new PrintStream(out_path + File.separator + gffName);
12+
13+
Scanner scan = new Scanner(input);
14+
PrintStream OUT = System.out;
15+
if( out_filepath != null ) OUT = new PrintStream(out_filepath);
1716

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

src/window_interface/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFWindow.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ class Task extends SwingWorker<Void, Void> {
5555
public Void doInBackground() throws IOException {
5656
setProgress(0);
5757
for(int x = 0; x < BEDFiles.size(); x++) {
58-
BEDtoGFF.convertBEDtoGFF(OUTPUT_PATH, BEDFiles.get(x));
58+
File XBED = BEDFiles.get(x);
59+
// Set outfilepath
60+
String gffName = (XBED.getName()).substring(0,XBED.getName().length() - 4) + ".gff";
61+
File OUT_FILE = null;
62+
if(OUTPUT_PATH == null) OUT_FILE = new File( gffName );
63+
else OUT_FILE = new File( OUTPUT_PATH + File.separator + gffName );
64+
// Execute conversion and update progress
65+
BEDtoGFF.convertBEDtoGFF(OUTPUT_PATH, XBED);
5966
int percentComplete = (int)(((double)(x + 1) / BEDFiles.size()) * 100);
6067
setProgress(percentComplete);
6168
}

0 commit comments

Comments
 (0)