Skip to content

Commit

Permalink
remove in/out extension restrictions on CLI tools
Browse files Browse the repository at this point in the history
This commit removes unnecessary extension filename validation from the CLI tools. This validation is too restrictive and interferes with development of Galaxy wrappers by forcing workarounds (Galaxy uses `.dat` extensions).
  • Loading branch information
owlang committed Jun 29, 2023
1 parent 5aacbe5 commit f411d02
Show file tree
Hide file tree
Showing 20 changed files with 3 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand All @@ -116,12 +112,6 @@ private String validateInput() throws IOException {
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
//check output filename is valid
}else{
//check ext
try{
if(!"bed".equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use BED extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".bed\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use BED extension for output filename. Try: " + output + ".bed\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand All @@ -116,12 +112,6 @@ private String validateInput() throws IOException {
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
//check output filename is valid
}else{
//check ext
try{
if(!"gff".equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use GFF extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".gff\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use GFF extension for output filename. Try: " + output + ".gff\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand All @@ -113,12 +109,6 @@ private String validateInput() throws IOException {
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
//check output filename is valid
}else{
//check ext
try{
if(!"tab".equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use \".tab\" extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".tab\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use \".tab\" extension for output filename. Try: " + output + ".tab\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ private String validateInput() throws IOException {
if (!r.equals("")) {
return (r);
}
// check input extensions
ExtensionFileFilter faFilter = new ExtensionFileFilter("fa");
if (!faFilter.accept(genomeFASTA)) {
r += "(!)Is this a FASTA file? Check extension: " + genomeFASTA.getName() + "\n";
}
if (!"bam".equals(ExtensionFileFilter.getExtension(bamFile))) {
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
// check BAI exists
File f = new File(bamFile + ".bai");
if (!f.exists() || f.isDirectory()) {
Expand All @@ -98,16 +90,6 @@ private String validateInput() throws IOException {
output = new File(ExtensionFileFilter.stripExtension(bamFile) + "_PSfilter.bam");
// check output filename is valid
} else {
// check ext
try {
if (!"bam".equals(ExtensionFileFilter.getExtension(output))) {
r += "(!)Use BAM extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output)
+ ".bam\n";
}
} catch (NullPointerException e) {
r += "(!)Output filename must have extension: use BAM extension for output filename. Try: "
+ ExtensionFileFilter.stripExtension(output) + ".bam\n";
}
// check directory
if (output.getParent() == null) {
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ private String validateInput() throws IOException {
//check input exists
if(!BAM.exists()|| BAM.isDirectory()){
r += "(!)BAM[" + x + "] file does not exist: " + BAM.getName() + "\n";
//check input extensions
}else if(!"bam".equals(ExtensionFileFilter.getExtension(BAM))){
r += "(!)Is this a BAM file? Check extension: " + BAM.getName() + "\n";
//check BAI exists
}else if(!BAI.exists() || BAI.isDirectory()){
r += "(!)BAI Index File does not exist for: " + BAM.getName() + "\n";
Expand All @@ -137,7 +134,6 @@ private String validateInput() throws IOException {
outputBasename = new File("correlation_matrix");
//check output filename is valid
}else{
//no check ext
//check directory
if(outputBasename.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand All @@ -77,7 +73,6 @@ private String validateInput() throws IOException {
outputBasename = new File(ExtensionFileFilter.stripExtension(bamFile));
//check output filename is valid
}else{
//no check ext
//check directory
if(outputBasename.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ private String validateInput() throws IOException {
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
Expand All @@ -68,7 +64,6 @@ private String validateInput() throws IOException {
output = new File(ExtensionFileFilter.stripExtension(bamFile) + "_stats.txt");
//check output filename is valid
}else{
//no check ext
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class MergeHeatMapCLI implements Callable<Integer> {
@Parameters(index = "1", description = "Second(anti) PNG heatmap to merge, input2")
private File antiFile;

@Option(names = { "-o",
"--output" }, description = "specify output filename, please use PNG extension\n(default=\"<senseFile>_merged.png\" appended to the name in working directory of ScriptManager")
@Option(names = { "-o", "--output" }, description = "specify output filename, please use PNG extension\n(default=\"<senseFile>_merged.png\" appended to the name in working directory of ScriptManager")
private File output = null;

@Override
Expand Down Expand Up @@ -64,29 +63,12 @@ private String validateInput() throws IOException {
if (!r.equals("")) {
return (r);
}
// check input extensions
if (!"png".equals(ExtensionFileFilter.getExtension(senseFile))) {
r += "(!)Is this a PNG file? Check extension: " + senseFile.getName() + "\n";
}
if (!"png".equals(ExtensionFileFilter.getExtension(antiFile))) {
r += "(!)Is this a PNG file? Check extension: " + antiFile.getName() + "\n";
}
// set default output filename
if (output == null) {
String NAME = ExtensionFileFilter.stripExtension(senseFile);
output = new File(NAME + "_merged.png");
// check output filename is valid
} else {
// check ext
try {
if (!"png".equals(ExtensionFileFilter.getExtension(output))) {
r += "(!)Use PNG extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output)
+ ".png\n";
}
} catch (NullPointerException e) {
r += "(!)Output filename must have extension: use PNG extension for output filename. Try: " + output
+ ".png\n";
}
// check directory
if (output.getParent() == null) {
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,12 @@ private String validateInput() throws IOException {
r += "(!)CDT file does not exist: " + CDT.getName() + "\n";
return (r);
}
// check input extensions
if (!"cdt".equals(ExtensionFileFilter.getExtension(CDT))) {
r += "(!)Is this a CDT file? Check extension: " + CDT.getName() + "\n";
}
// set default output filename
if (output == null) {
String NAME = ExtensionFileFilter.stripExtension(CDT);
output = new File(NAME + "_" + scaleType + ".png");
// check output filename is valid
} else {
// check ext
try {
if (!"png".equals(ExtensionFileFilter.getExtension(output))) {
r += "(!)Use PNG extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output)
+ ".png\n";
}
} catch (NullPointerException e) {
r += "(!)Output filename must have extension: use PNG extension for output filename. Try: " + output
+ ".png\n";
}
// check directory
if (output.getParent() == null) {
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,11 @@ private String validateInput() throws IOException {
r += "(!)BED-ref file does not exist: " + refBED.getName() + "\n";
}
if(!r.equals("")){ return(r); }
//check input extensions
if(!"bed".equals(ExtensionFileFilter.getExtension(peakBED))){
r += "(!)Is this a BED file? Check extension: " + peakBED.getName() + "\n";
}
if(!"bed".equals(ExtensionFileFilter.getExtension(refBED))){
r += "(!)Is this a BED file? Check extension: " + refBED.getName() + "\n";
}
//set default output filename
if(output==null){
output = new File(ExtensionFileFilter.stripExtension(peakBED) + "_" + ExtensionFileFilter.stripExtension(refBED) + "_Output.cdt");
//check output filename is valid
}else{
//check ext
try{
if(!"cdt".equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use CDT extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".cdt\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use CDT extension for output filename. Try: " + output + ".cdt\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,11 @@ private String validateInput() throws IOException {
r += "(!)BED file does not exist: " + bedFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
}
//set default output filename
if(outputBasename==null){
outputBasename = ExtensionFileFilter.stripExtension(bedFile) + "_" + Integer.toString(exclusion) + "bp";
//check output filename is valid
}else{
//no check ext
//check directory
File tmpOut = new File(outputBasename);
if(tmpOut.getParent()==null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ private String validateInput() throws IOException {
output = new File("random_coordinates_" + genomeName + "_" + numSites + "sites_" + window + "bp." + ext);
//check output filename is valid
}else{
//check ext
try{
if(!ext.equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + "." + ext + "\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + output + "." + ext + "\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ private String validateInput() throws IOException {
output = new File(genomeName + "_" + window + "bp." + ext);
//check output filename is valid
}else{
//check ext
try{
if(!ext.equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + "." + ext + "\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use \"." + ext.toUpperCase() + "\" extension for output filename. Try: " + output + "." + ext + "\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,11 @@ private String validateInput() throws IOException {
if(!controlBAM.exists()){ r += "(!)BAM(control) file does not exist: " + controlBAM.getName() + "\n"; }
}
if(!r.equals("")){ return(r); }
//check input extensions & BAI exists
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM(input) file? Check extension: " + bamFile.getName() + "\n";
}
//check BAI exists
File f = new File(bamFile+".bai");
if(!f.exists() || f.isDirectory()){
r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n";
}
if(blacklistFilter!=null){
if(!"bed".equals(ExtensionFileFilter.getExtension(blacklistFilter))){
r += "(!)Is this a BED file? Check extension: " + blacklistFilter.getName() + "\n";
}
}
if(controlBAM!=null){
if(!"bam".equals(ExtensionFileFilter.getExtension(controlBAM))){
r += "(!)Is this a BAM(control) file? Check extension: " + controlBAM.getName() + "\n";
Expand All @@ -114,7 +106,6 @@ private String validateInput() throws IOException {
//check output filename is valid
}else{
File tempOut = new File(outputBasename);
//no check ext
//check directory
if(tempOut.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private String validateInput() throws IOException {
//check output COMPOSITE filename is valid
if(outputOptions.outputComposite!="composite_average.out"){
File output = new File(outputOptions.outputComposite);
//no check ext
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ private String validateInput() throws IOException {
if (!r.equals("")) {
return (r);
}
// check input extensions
ExtensionFileFilter faFilter = new ExtensionFileFilter("fa");
if (!faFilter.accept(genomeFASTA)) {
r += "(!)Is this a FASTA file? Check extension: " + genomeFASTA.getName() + "\n";
}
if (!"bed".equals(ExtensionFileFilter.getExtension(bedFile))) {
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
}
// set default output filename
if (outputBasename == null) {
outputBasename = ExtensionFileFilter.stripExtension(bedFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,12 @@ private String validateInput() throws IOException {
r += "(!)FASTA file does not exist: " + fastaFile.getName() + "\n";
return (r);
}
// check input extensions
ExtensionFileFilter faFilter = new ExtensionFileFilter("fa");
if (!faFilter.accept(fastaFile)) {
r += "(!)Is this a FASTA file? Check extension: " + fastaFile.getName() + "\n";
}
// set default output filename
if (outputBasename == null) {
outputBasename = ExtensionFileFilter.stripExtension(fastaFile);
// check output filename is valid
} else {
String outParent = new File(outputBasename).getParent();
// no extension check
// check directory
if (outParent == null) {
// System.err.println("default to current directory");
Expand Down
Loading

0 comments on commit f411d02

Please sign in to comment.