Skip to content

Commit 23fdab0

Browse files
committed
create GFFtoBED 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/*/ GFFtoBEDOutput 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 dbb3200 commit 23fdab0

3 files changed

Lines changed: 58 additions & 15 deletions

File tree

src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java

Lines changed: 44 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.Coordinate_Manipulation.GFF_Manipulation.GFFtoBED;
15+
import scripts.Coordinate_Manipulation.GFF_Manipulation.GFFtoBED;
1616

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

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

37-
//SEStats.getSEStats( output, bamFile, null );
45+
GFFtoBED.convertGFFtoBED(output, gffFile);
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(!gffFile.exists()){
56+
r += "(!)GFF file does not exist: " + gffFile.getName() + "\n";
57+
return(r);
58+
}
59+
//check input extensions
60+
if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){
61+
r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n";
62+
}
63+
//set default output filename
64+
if(output==null && !stdout){
65+
output = new File(ExtensionFileFilter.stripExtension(gffFile) + ".bed");
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 GFF extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".gff\n";
75+
}
76+
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use GFF extension for output filename. Try: " + output + ".gff\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
}
49-
}
87+
}

src/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.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 GFFtoBED {
10-
public static void convertBEDtoGFF(File out_path, File input) throws IOException {
10+
public static void convertGFFtoBED(File out_filepath, File input) throws IOException {
1111
//GFF: chr22 TeleGene enhancer 10000000 10001000 500 + . touch1
1212
//BED: chr12 605113 605120 region_0 0 +
13-
14-
String bedName = (input.getName()).substring(0,input.getName().length() - 4) + ".bed";
15-
Scanner scan = new Scanner(input);
16-
PrintStream OUT = null;
17-
if(out_path == null) OUT = new PrintStream(bedName);
18-
else OUT = new PrintStream(out_path + File.separator + bedName);
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/GFFtoBEDWindow.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ class Task extends SwingWorker<Void, Void> {
5454
@Override
5555
public Void doInBackground() throws IOException {
5656
setProgress(0);
57-
for(int x = 0; x < BEDFiles.size(); x++) {
58-
GFFtoBED.convertBEDtoGFF(OUTPUT_PATH, BEDFiles.get(x));
57+
for(int x = 0; x < BEDFiles.size(); x++) {
58+
File XGFF = BEDFiles.get(x);
59+
// Set outfilepath
60+
String bedName = (XGFF.getName()).substring(0,XGFF.getName().length() - 4) + ".bed";
61+
File OUT_FILE = null;
62+
if(OUTPUT_PATH == null) OUT_FILE = new File( bedName );
63+
else OUT_FILE = new File( OUTPUT_PATH + File.separator + bedName );
64+
// Execute conversion and update progress
65+
GFFtoBED.convertGFFtoBED(OUTPUT_PATH, XGFF);
5966
int percentComplete = (int)(((double)(x + 1) / BEDFiles.size()) * 100);
6067
setProgress(percentComplete);
6168
}

0 commit comments

Comments
 (0)