You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Gzip support for the UI file selection classes. #91
- FileSelection: Specifically, the extension-based single file selection was adjusted to add support for ignoring or including files with a ".gz" extension.
- ExtensionFileFilter: add a stripExtension method that works on String-type filenames
- decorate both classes with JavaDocs
Copy file name to clipboardExpand all lines: src/util/ExtensionFileFilter.java
+85-8Lines changed: 85 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -5,27 +5,48 @@
5
5
6
6
importjavax.swing.filechooser.FileFilter;
7
7
8
+
/**
9
+
* Filters files such as BAI, BAM, BED, CDT, FASTA, FA, GFF, TAB for the FileSelection tool base on the extension of the filename. Also includes file extension parsing utilities used across all ScriptManager classes (especially for creating default filenames).
10
+
*
11
+
* @author William KM Lai
12
+
* @see util.FileSelection
13
+
*
14
+
*/
8
15
publicclassExtensionFileFilterextendsFileFilter{
9
-
//Filters files such as BAI, BAM, BED, CDT, FASTA, FA, GFF, TAB
10
-
16
+
11
17
privateStringext = "";
12
18
privateStringext2 = "";
13
19
privateStringext3 = "";
14
20
privatebooleanincludeGZ = false;
15
-
21
+
22
+
/**
23
+
* Create file filter for the given file extension.
24
+
* If ExtensionFileFilter is instantiated with "fa", file extensions "fasta" and "fsa" are set to be equivalent.
25
+
* If ExtensionFileFilter is instantiated with "gff", file extensions "gtf" and "gff3" are set to be equivalent.
26
+
*
27
+
* @param filter file extension to filter by (see notes on "fa" and "gff").
* Create file filter for the given file extension with option to ignore or include ".gz" extensions.
37
+
* If ExtensionFileFilter is instantiated with "fa", file extensions "fasta" and "fsa" are set to be equivalent.
38
+
* If ExtensionFileFilter is instantiated with "gff", file extensions "gtf" and "gff3" are set to be equivalent.
39
+
*
40
+
* @param filter file extension to filter by (see notes on "fa" and "gff").
41
+
* @param gz whether or not to ignore the ".gz" extension (e.g. if gz=true and filter="bed", then "XXX.bed.gz" will pass the filter, "XXX.bed" will pass the filter, but "XXX.gff" will NOT pass the filter).
@@ -38,7 +59,13 @@ public boolean accept(File f) {
38
59
}
39
60
returnfalse;
40
61
}
41
-
62
+
63
+
/**
64
+
* Get the extension string from a File object.
65
+
*
66
+
* @param f the input file to get the extension for
67
+
* @return the file extension string (without "." char)
68
+
*/
42
69
publicstaticStringgetExtension(Filef) {
43
70
Stringext = null;
44
71
Strings = f.getName();
@@ -48,7 +75,13 @@ public static String getExtension(File f) {
48
75
}
49
76
returnext;
50
77
}
51
-
78
+
79
+
/**
80
+
* Get the extension string from a File object, ignoring ".gz" extension if present and searching for next extension.
81
+
*
82
+
* @param f the input file to get the extension for
83
+
* @return the file extension string (without "." char)
84
+
*/
52
85
publicstaticStringgetExtensionIgnoreGZ(Filef) {
53
86
Stringext = null;
54
87
Strings = f.getName();
@@ -65,6 +98,15 @@ public static String getExtensionIgnoreGZ(File f) {
65
98
returnext;
66
99
}
67
100
101
+
/**
102
+
* Get the filename without the last extension (tokenize filename by "." char and pull off last "." character and last token. If no "." characters, return the whole filename)
103
+
* e.g. f="blahblah.fa" returns "blahblah"
104
+
* e.g. f="oompaloompa" returns "oompaloompa"
105
+
*
106
+
* @param f the File to strip an extension from
107
+
* @return string of filename with extension stripped away
* Get the string without the last extension, ignoring any ".gz" extensions (tokenize strings by "." char and pull off last "." character and last token. If no "." characters, return the whole filename)
121
+
* e.g. f="blahblah.fa" returns "blahblah"
122
+
* e.g. f="oompaloompa" returns "oompaloompa"
123
+
* e.g. f="blahblah.fa.gz" returns "blahblah"
124
+
* e.g. f="oompaloompa.gz" returns "oompaloompa"
125
+
*
126
+
* @param f the File to strip an extension from
127
+
* @return string of filename with extension stripped away
* Get the string without the last extension (tokenize strings by "." char and pull off last "." character and last token. If no "." characters, return the whole filename)
142
+
* e.g. f="blahblah.fa" returns "blahblah"
143
+
* e.g. f="oompaloompa" returns "oompaloompa"
144
+
*
145
+
* @param f the String to strip an extension from
146
+
* @return string of filename with extension stripped away
147
+
*/
148
+
publicstaticStringstripExtension(Stringf) {
149
+
String[] name = f.split("\\.");
150
+
StringNEWNAME = name[0];
151
+
for(intx = 1; x < name.length-1; x++) {
152
+
NEWNAME += ("." + name[x]);
153
+
}
154
+
return(NEWNAME);
155
+
}
156
+
157
+
/**
158
+
* Get the string of the cannonical filepath without the last extension. Return every character in the path until the last instance of "." character (not including ".").
159
+
* e.g. f="/parent/directory/blahblah.fa" returns "/parent/directory/blahblah"
160
+
*
161
+
* @param f the String to strip an extension from
162
+
* @return string of filename with extension stripped away
0 commit comments