Skip to content

Commit 591a7b9

Browse files
Simplified code
accidentally was on sort-by-ref branch when making documentation, so I rewrote some tools and it turned out to be better than the code on this branch
1 parent 9e250c7 commit 591a7b9

File tree

18 files changed

+81
-72
lines changed

18 files changed

+81
-72
lines changed

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,15 @@
2020
<nature>org.eclipse.jdt.core.javanature</nature>
2121
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
2222
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1696639028865</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
2334
</projectDescription>

src/main/java/scriptmanager/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private String validateInput() throws IOException {
6464
}
6565
//set default output filename
6666
if(output==null && !stdout){
67-
String NAME = ExtensionFileFilter.stripExtension(bedFile) + ".gff";
67+
String NAME = ExtensionFileFilter.stripExtensionIgnoreGZ(bedFile) + ".gff";
6868
NAME += gzOutput ? ".gz" : "";
6969
output = new File(NAME);
7070
//check stdout and output not both selected

src/main/java/scriptmanager/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public class SortBEDCLI implements Callable<Integer> {
3636

3737
@Option(names = {"-o", "--output"}, description = "specify output file basename with no .cdt/.bed/.jtv extension (default=<bedFile>_SORT")
3838
private String outputBasename = null;
39-
@Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)")
40-
private int center = -999;
4139
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
4240
private boolean gzOutput = false;
41+
@Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)")
42+
private int center = -999;
4343
@Option(names = {"-x", "--index"}, description = "sort by index from the specified start to the specified stop (0-indexed and half-open interval)",
4444
arity = "2")
4545
private int[] index = {-999, -999};

src/main/java/scriptmanager/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ExpandGFFCLI implements Callable<Integer> {
3030

3131
@Option(names = {"-o", "--output"}, description = "specify output filename (name will be same as original with coordinate info appended)")
3232
private File output = null;
33-
@Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT")
33+
@Option(names = {"-s", "--stdout"}, description = "output gff to STDOUT")
3434
private boolean stdout = false;
3535
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
3636
private boolean gzOutput = false;
@@ -72,7 +72,7 @@ private String validateInput() throws IOException {
7272
return(r);
7373
}
7474
//check input extensions
75-
if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){
75+
if(!"gff".equals(ExtensionFileFilter.getExtensionIgnoreGZ(gffFile))){
7676
r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n";
7777
}
7878

src/main/java/scriptmanager/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private String validateInput() throws IOException {
6060
}
6161
//set default output filename
6262
if(output==null && !stdout){
63-
output = new File(ExtensionFileFilter.stripExtension(gffFile) + ".bed");
63+
output = new File(ExtensionFileFilter.stripExtensionIgnoreGZ(gffFile) + ".bed");
6464
//check stdout and output not both selected
6565
}else if(stdout){
6666
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }

src/main/java/scriptmanager/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class SortGFFCLI implements Callable<Integer> {
3333

3434
@Option(names = {"-o", "--output"}, description = "specify output file basename with no .cdt/.gff/.jtv extension (default=<gffFile>_SORT")
3535
private String outputBasename = null;
36-
@Option(names = {"-z", "--compression"}, description = "Output compressed GFF file" )
36+
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
3737
private boolean gzOutput = false;
3838
@Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)")
3939
private int center = -999;
@@ -93,7 +93,7 @@ private String validateInput() throws IOException {
9393

9494
//set default output filename
9595
if(outputBasename==null){
96-
outputBasename = ExtensionFileFilter.stripExtension(gffFile) + "_SORT";
96+
outputBasename = ExtensionFileFilter.stripExtensionIgnoreGZ(gffFile) + "_SORT";
9797
//check output filename is valid
9898
}else{
9999
//no extension check

src/main/java/scriptmanager/cli/Sequence_Analysis/SearchMotifCLI.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ private String validateInput() throws IOException {
7777
if (output == null) {
7878
String NAME = motif + "_" + Integer.toString(ALLOWED_MISMATCH) + "Mismatch_"
7979
+ ExtensionFileFilter.stripExtension(fastaFile) + ".bed";
80-
NAME += gzOutput ? ".gz" : "";
8180
output = new File(NAME);
8281
// check output filename is valid
8382
} else {

src/main/java/scriptmanager/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package scriptmanager.scripts.Coordinate_Manipulation.BED_Manipulation;
22

3-
import java.io.BufferedOutputStream;
43
import java.io.BufferedReader;
54
import java.io.File;
6-
import java.io.FileInputStream;
7-
import java.io.FileOutputStream;
85
import java.io.IOException;
9-
import java.io.InputStreamReader;
106
import java.io.PrintStream;
117
import java.util.Arrays;
12-
import java.util.zip.GZIPInputStream;
13-
import java.util.zip.GZIPOutputStream;
148

159
import scriptmanager.util.GZipUtilities;
1610

@@ -35,19 +29,10 @@ public static void convertBEDtoGFF(File outpath, File input, boolean gzOutput) t
3529
// Initialize output writer
3630
PrintStream OUT = System.out;
3731
if (outpath != null) {
38-
if (gzOutput) {
39-
OUT = new PrintStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outpath))));
40-
} else {
41-
OUT = new PrintStream(new BufferedOutputStream(new FileOutputStream(outpath)));
42-
}
32+
OUT = GZipUtilities.makePrintStream(outpath, gzOutput);
4333
}
4434
// Check if file is gzipped and instantiate appropriate BufferedReader
45-
BufferedReader br;
46-
if(GZipUtilities.isGZipped(input)) {
47-
br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(input)), "UTF-8"));
48-
} else {
49-
br = new BufferedReader(new InputStreamReader(new FileInputStream(input), "UTF-8"));
50-
}
35+
BufferedReader br = GZipUtilities.makeReader(input);
5136
// Initialize line variable to loop through
5237
String line = br.readLine();
5338
while (line != null) {

src/main/java/scriptmanager/scripts/Coordinate_Manipulation/BED_Manipulation/SortBED.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_IN
7878
if (!ID.contains("YORF") && !ID.contains("NAME")) {
7979
BEDFile.put(ID, line);
8080
}
81+
line = br.readLine();
8182
}
8283
br.close();
8384

src/main/java/scriptmanager/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
import java.io.IOException;
66
import java.io.PrintStream;
77
import java.util.Arrays;
8-
import scriptmanager.util.GZipUtilities;
98

9+
import scriptmanager.util.GZipUtilities;
1010

1111
public class GFFtoBED {
12-
public static void convertGFFtoBED(File out_filepath, File input, boolean outputGzip) throws IOException {
12+
public static void convertGFFtoBED(File out_filepath, File input, boolean gzOutput) throws IOException {
1313
// GFF: chr22 TeleGene enhancer 10000000 10001000 500 + . touch1
1414
// BED: chr12 605113 605120 region_0 0 +
1515

1616
PrintStream OUT = System.out;
1717
if (out_filepath != null)
18-
OUT = GZipUtilities.makePrintStream(out_filepath, outputGzip);
18+
OUT = GZipUtilities.makePrintStream(out_filepath, gzOutput);
1919

20-
// Checks if file is gzipped and instantiate appropriate BufferedReader
21-
String line;
2220
BufferedReader br = GZipUtilities.makeReader(input);
23-
while ((line = br.readLine()) != null) {
21+
// Initialize line variable to loop through
22+
String line = br.readLine();
23+
while (line != null) {
2424
String[] temp = line.split("\t");
2525
if (temp[0].toLowerCase().contains("track") || temp[0].startsWith("#")) {
2626
OUT.println(String.join("\t", temp));
@@ -42,6 +42,7 @@ public static void convertGFFtoBED(File out_filepath, File input, boolean output
4242
System.out.println("Invalid Coordinate in File!!!\n" + Arrays.toString(temp));
4343
}
4444
}
45+
line = br.readLine();
4546
}
4647
br.close();
4748
OUT.close();

0 commit comments

Comments
 (0)