Skip to content

Commit

Permalink
Added extension to gzipped files made by GUI
Browse files Browse the repository at this point in the history
And made checkbox UI more consistent
  • Loading branch information
benjaminbeer256 committed Nov 3, 2023
1 parent 1b81fca commit 87e31ff
Show file tree
Hide file tree
Showing 51 changed files with 170 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public class SortBEDCLI implements Callable<Integer> {

@Option(names = {"-o", "--output"}, description = "specify output file basename with no .cdt/.bed/.jtv extension (default=<bedFile>_SORT")
private String outputBasename = null;
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
private boolean gzOutput = false;
@Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)")
private int center = -999;
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
private boolean gzOutput = false;
@Option(names = {"-x", "--index"}, description = "sort by index from the specified start to the specified stop (0-indexed and half-open interval)",
arity = "2")
private int[] index = {-999, -999};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RandomCoordinateCLI implements Callable<Integer> {
@Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be random_coordinates_<genomeName>_<window>bp.<ext>")
private File output = null;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;
@Option(names = {"-f", "--gff"}, description = "file format output as GFF (default format as BED)")
private boolean formatIsBed = true;
@Option(names = {"-n", "--num-sites"}, description = "number of sites (default=1000)")
Expand All @@ -48,7 +48,7 @@ public Integer call() throws Exception {
System.exit(1);
}

RandomCoordinate.execute(genomeName, numSites, window, formatIsBed, output, zip);
RandomCoordinate.execute(genomeName, numSites, window, formatIsBed, output, gzOutput);

System.err.println( "Random Coordinate Generation Complete." );
return(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TileGenomeCLI implements Callable<Integer> {
@Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be genome_tiles_<genomeName>_<window>bp.<ext>")
private File output = null;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;
@Option(names = {"-f", "--gff"}, description = "file format output as GFF (default format as BED)")
private boolean formatIsBed = true;
@Option(names = {"-w", "--window"}, description = "window size in bp (default=200)")
Expand All @@ -46,7 +46,7 @@ public Integer call() throws Exception {
System.exit(1);
}

TileGenome.execute(genomeName, window, formatIsBed, output, zip);
TileGenome.execute(genomeName, window, formatIsBed, output, gzOutput);

System.err.println( "Genomic Tiling Complete." );
return(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import scriptmanager.objects.ToolDescriptions;
import scriptmanager.scripts.Read_Analysis.AggregateData;
import scriptmanager.util.ExtensionFileFilter;

/**
Read_AnalysisCLI/AggregateDataCLI
Expand All @@ -34,7 +33,7 @@ public class AggregateDataCLI implements Callable<Integer> {
@Option(names = {"-o", "--output"}, description = "Specify output file (default = <input1>_SCORES.out, <input2_SCORES.out, ... or ALL_SCORES.out if -m flag is used)")
private File output;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;

@ArgGroup(exclusive = true, heading = "Aggregation Method%n")
AggType aggr = new AggType();
Expand Down Expand Up @@ -75,7 +74,7 @@ public Integer call() throws Exception {
System.exit(1);
}

AggregateData script_obj = new AggregateData(matFiles, output, merge, startROW, startCOL, aggType, zip);
AggregateData script_obj = new AggregateData(matFiles, output, merge, startROW, startCOL, aggType, gzOutput);
script_obj.run();

System.err.println(script_obj.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ScaleMatrixCLI implements Callable<Integer> {
@Option(names = {"-o", "--output"}, description = "Specify output file (default = <matrixFilename>_SCALE.tab)")
private File output = null;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;
@Option(names = {"-s", "--scaling-factor"}, description = "scaling factor (default=1)")
private double scale = 1;
@Option(names = {"-r", "--start-row"}, description = "")
Expand All @@ -49,7 +49,7 @@ public Integer call() throws Exception {
System.exit(1);
}

ScaleMatrix script_obj = new ScaleMatrix(matrixFile, output, scale, startROW, startCOL, zip);
ScaleMatrix script_obj = new ScaleMatrix(matrixFile, output, scale, startROW, startCOL, gzOutput);
script_obj.run();

System.err.println("All Matrices Scaled.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static class OutputOptions{
arity="0..1")
private ArrayList<String> outputMatrix = new ArrayList<String>(Arrays.asList("no","matrix","output"));
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;
@Option(names = {"--cdt"}, description = "output matrix in cdt format (default)")
private boolean cdt = false;
@Option(names = {"--tab"}, description = "output matrix in tab format")
Expand Down Expand Up @@ -286,7 +286,7 @@ private String validateInput() throws IOException {
p.setStandard(calcOptions.tagsEqual);

//Set output statuses
p.setGZIPstatus(outputOptions.zip);
p.setGZIPstatus(outputOptions.gzOutput);

//Set Ratio (code to standardize tags sequenced to genome size (1 tag / 1 bp))
if( p.getStandard() && filterOptions.blacklistFilter!=null ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DNAShapefromBEDCLI implements Callable<Integer> {
"--output" }, description = "Specify basename for output files, files for each shape indicated will share this name with a different suffix")
private String outputBasename = null;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;
@Option(names = { "--avg-composite" }, description = "Save average composite")
private boolean avgComposite = false;
@Option(names = { "-n", "--no-force" }, description = "don't force-strandedness (default is to force strandedness)")
Expand Down Expand Up @@ -76,7 +76,7 @@ public Integer call() throws Exception {
try {
// Generate Composite Plot
DNAShapefromBED script_obj = new DNAShapefromBED(genomeFASTA, bedFile, outputBasename, OUTPUT_TYPE,
forceStrand, new PrintStream[] { null, null, null, null }, zip);
forceStrand, new PrintStream[] { null, null, null, null }, gzOutput);
script_obj.run();

if (avgComposite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DNAShapefromFASTACLI implements Callable<Integer> {
@Option(names = { "--avg-composite" }, description = "Save average composite")
private boolean avgComposite = false;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;

@ArgGroup(validate = false, heading = "Shape Options%n")
ShapeType shape = new ShapeType();
Expand Down Expand Up @@ -70,7 +70,7 @@ public Integer call() throws Exception {

// Generate Composite Plot
DNAShapefromFASTA script_obj = new DNAShapefromFASTA(fastaFile, outputBasename, OUTPUT_TYPE,
new PrintStream[] { null, null, null, null }, zip);
new PrintStream[] { null, null, null, null }, gzOutput);
script_obj.run();

// Print Composite Scores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RandomizeFASTACLI implements Callable<Integer> {
@Option(names = {"-s", "--seed"}, description = "specify an integer seed for reproducible outputs")
private Integer seed = null;
@Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)")
private boolean zip = false;
private boolean gzOutput = false;

@Override
public Integer call() throws Exception {
Expand All @@ -46,7 +46,7 @@ public Integer call() throws Exception {
System.exit(1);
}

RandomizeFASTA.randomizeFASTA(fastaFile, output, seed, zip);
RandomizeFASTA.randomizeFASTA(fastaFile, output, seed, gzOutput);

System.err.println("Randomization Complete.");
return (0);
Expand All @@ -73,15 +73,15 @@ private String validateInput() throws IOException {
}
// set default output filename
if (output == null) {
String NAME = ExtensionFileFilter.stripExtension(fastaFile) + "_RAND.fa";
String NAME = ExtensionFileFilter.stripExtensionIgnoreGZ(fastaFile) + "_RAND.fa";
output = new File(NAME);
// check output filename is valid
} else {
// check ext
try {
if (!faFilter.accept(output)) {
r += "(!)Use FASTA extension for output filename. Try: "
+ ExtensionFileFilter.stripExtension(output) + ".fa\n";
+ ExtensionFileFilter.stripExtensionIgnoreGZ(output) + ".fa\n";
}
} catch (NullPointerException e) {
r += "(!)Output filename must have extension: use \".fa\" extension for output filename. Try: " + output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public void run() throws IOException, InterruptedException {
}

if (OUTPUT_GZIP){
printPS("Output Gzip: yes");
} else{
printPS("Output Gzip: no");
printPS("Output GZip: yes");
} else {
printPS("Output GZip: no");
}

// Build&Print Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public void run() throws IOException, InterruptedException {
}

if (OUTPUT_GZIP){
printPS("Output Gzip: yes");
} else{
printPS("Output Gzip: no");
printPS("Output GZip: yes");
} else {
printPS("Output GZip: no");
}

// Build&Print Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public void run() throws IOException, InterruptedException {
// Open Output File
if (OUTBASENAME != null) {
try {
String SUFFIX = ".bedGraph" + (OUTPUT_GZIP? ".gz": "");
if (STRAND <= 2) {
OUTF = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_forward.bedGraph"), OUTPUT_GZIP);
OUTR = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_reverse.bedGraph") , OUTPUT_GZIP);
OUTF = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_forward" + SUFFIX), OUTPUT_GZIP);
OUTR = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_reverse" + SUFFIX) , OUTPUT_GZIP);
} else {
OUTF = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_midpoint.bedGraph"), OUTPUT_GZIP);
OUTF = GZipUtilities.makePrintStream(new File(OUTBASENAME + "_midpoint" + SUFFIX), OUTPUT_GZIP);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Expand Down Expand Up @@ -109,9 +110,9 @@ public void run() throws IOException, InterruptedException {
}

if (OUTPUT_GZIP){
printPS("Output Gzip: yes");
} else{
printPS("Output Gzip: no");
printPS("Output GZip: yes");
} else {
printPS("Output GZip: no");
}

// Print Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void run() throws IOException, InterruptedException {
}

if (OUTPUT_GZIP){
printPS("Output Gzip: yes");
} else{
printPS("Output Gzip: no");
printPS("Output GZip: yes");
} else {
printPS("Output GZip: no");
}

// Print Header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import scriptmanager.util.GZipUtilities;

/**
* This class contains scripts for sorting coordinate intervals (BED/GFF) by the tag counts of a CDT matrix file.
* Sort coordinate intervals (BED) by the tag counts of a CDT matrix file.
*
* @author William KM Lai
* @see scriptmanager.cli.Coordinate_Manipulation.BED_Manipulation.SortBEDCLI
Expand All @@ -28,7 +28,7 @@ public class SortBED {
* @param START_INDEX the start column to consider when summing values to sort
* @param STOP_INDEX
* @param gzOutput if true, the output files will be gzipped.
* @throws IOException
* @throws IOException Invalid file or parameters
*/
public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_INDEX, int STOP_INDEX, boolean gzOutput ) throws IOException {
ArrayList<BEDCoord> SORT = new ArrayList<BEDCoord>();
Expand All @@ -38,7 +38,7 @@ public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_IN
BufferedReader br = GZipUtilities.makeReader(cdt);
// Initialize line variable to loop through
String line = br.readLine();
while ((line = br.readLine()) != null) {
while (line != null) {
String[] ID = line.split("\t");
if (!ID[0].contains("YORF") && !ID[0].contains("NAME")) {
double count = 0;
Expand All @@ -50,14 +50,16 @@ public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_IN
} else {
CDTHeader = line;
}
line = br.readLine();
}
br.close();
// Sort by score
Collections.sort(SORT, BEDCoord.ScoreComparator);

PrintStream OUT;
// Initialize output writer
OUT = GZipUtilities.makePrintStream(new File(outbase + ".cdt"), gzOutput);
String suffix = ".cdt" + (gzOutput? ".gz": "");
OUT = GZipUtilities.makePrintStream(new File(outbase + suffix), gzOutput);
// Output sorted CDT File
OUT.println(CDTHeader);
for (int x = 0; x < SORT.size(); x++) {
Expand All @@ -73,7 +75,7 @@ public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_IN
br = GZipUtilities.makeReader(bed);
// Initialize line variable to loop through
line = br.readLine();
while ((line = br.readLine()) != null) {
while (line != null) {
String ID = line.split("\t")[3];
if (!ID.contains("YORF") && !ID.contains("NAME")) {
BEDFile.put(ID, line);
Expand All @@ -83,11 +85,12 @@ public static void sortBEDbyCDT(String outbase, File bed, File cdt, int START_IN
br.close();

// Initialize output writer
OUT = GZipUtilities.makePrintStream(new File(outbase + ".bed"), gzOutput);
suffix = ".bed" + (gzOutput? ".gz": "");
OUT = GZipUtilities.makePrintStream(new File(outbase + suffix), gzOutput);
// Output sorted BED File
for (int x = 0; x < SORT.size(); x++) {
OUT.println(BEDFile.get(SORT.get(x).getName()));
}
OUT.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static void sortGFFbyCDT(String outname, File gff, File cdt, int START_IN
Collections.sort(SORT, GFFCoord.ScoreComparator);

// Output sorted CDT File
PrintStream OUT = GZipUtilities.makePrintStream(new File(outname + ".cdt"), gzOutput);
String SUFFIX = ".cdt" + (gzOutput? ".gz": "");
PrintStream OUT = GZipUtilities.makePrintStream(new File(outname + SUFFIX), gzOutput);
OUT.println(CDTHeader);
for (int x = 0; x < SORT.size(); x++) {
OUT.println(CDTFile.get(SORT.get(x).getName()));
Expand All @@ -64,7 +65,8 @@ public static void sortGFFbyCDT(String outname, File gff, File cdt, int START_IN
br.close();

// Output sorted GFF File
OUT = GZipUtilities.makePrintStream(new File(outname + ".gff"), gzOutput);
SUFFIX = ".gff" + (gzOutput? ".gz": "");
OUT = GZipUtilities.makePrintStream(new File(outname + SUFFIX), gzOutput);
for (int x = 0; x < SORT.size(); x++) {
OUT.println(GFFFile.get(SORT.get(x).getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public FilterBEDbyProximity(File input, int cutoff, String outputBase, PrintStre
if(outputBase == null) {
outputBase = ExtensionFileFilter.stripExtensionIgnoreGZ(input) + "_" + Integer.toString(CUTOFF) + "bp";
}
OUT_Filter = GZipUtilities.makePrintStream(new File(outputBase + "-FILTER" + ".bed"), gzOutput);
OUT_Cluster = GZipUtilities.makePrintStream(new File(outputBase + "-CLUSTER" + ".bed"), gzOutput);
OUT_Filter = GZipUtilities.makePrintStream(new File(outputBase + "-FILTER.bed" + (gzOutput? ".gz": "")), gzOutput);
OUT_Cluster = GZipUtilities.makePrintStream(new File(outputBase + "-CLUSTER.bed" + (gzOutput? ".gz": "")), gzOutput);
}catch (FileNotFoundException e) { e.printStackTrace(); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public void run() throws IOException {

String name = "ALL_SCORES.out";
if (OUT_PATH == null) {
OUT = GZipUtilities.makePrintStream(new File(name), OUTPUT_GZIP);
OUT = GZipUtilities.makePrintStream(new File(name + (OUTPUT_GZIP? ".gz": "")), OUTPUT_GZIP);
} else if (!OUT_PATH.isDirectory()) {
OUT = GZipUtilities.makePrintStream(OUT_PATH, OUTPUT_GZIP);
} else {
OUT = GZipUtilities.makePrintStream(new File(OUT_PATH.getCanonicalPath() + File.separator + name), OUTPUT_GZIP);
OUT = GZipUtilities.makePrintStream(new File(OUT_PATH.getCanonicalPath() + File.separator + name + (OUTPUT_GZIP? ".gz": "")), OUTPUT_GZIP);
}

// Check all arrays are the same size
Expand Down Expand Up @@ -142,11 +142,11 @@ public String getMessage() {
}

public void outputFileScore(File IN) throws FileNotFoundException, IOException {
String NEWNAME = ExtensionFileFilter.stripExtension(IN);
String NEWNAME = ExtensionFileFilter.stripExtension(IN) + "_SCORES.out";
if (OUT_PATH != null) {
OUT = GZipUtilities.makePrintStream(new File(OUT_PATH.getAbsolutePath() + File.separator + NEWNAME + "_SCORES.out"), OUTPUT_GZIP);
OUT = GZipUtilities.makePrintStream(new File(OUT_PATH.getAbsolutePath() + File.separator + NEWNAME + (OUTPUT_GZIP? ".gz": "")), OUTPUT_GZIP);
} else {
OUT = GZipUtilities.makePrintStream(new File(NEWNAME + "_SCORES.out"), OUTPUT_GZIP);
OUT = GZipUtilities.makePrintStream(new File(NEWNAME + (OUTPUT_GZIP? ".gz": "")), OUTPUT_GZIP);
}
outputFileScore(IN, OUT);
}
Expand Down
Loading

0 comments on commit 87e31ff

Please sign in to comment.