From d87b9c1ee757a0a6da8e58e65da3639b50f3725e Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 14:25:33 -0400 Subject: [PATCH 01/43] write template for command line interface Outlining the empty classes for building the command line version. Although the jar file should build sucessfully, the command line version isn't working and the tools just print the tool name for now. build.gradle -change version name to reflect that its devCLI -add Picocli to the libraries to build with src/main/ScriptManagerGUI -moved most of the code from old ScriptManager class to here as the GUI application class src/main/ScriptManager -new main class to call GUI version or CLI version depending on input parameters -multiple classes defined for each tool group based on a generic abstract toolgroup class (SubcommandCLI) that is also defined here -the abstract class prints the usage message for the tool group if the tool name subcommand is not given by the user. src/objects/ToolDescriptions -store tool descriptions in a separate object so the GUI and CLI versions are pulling from the same text--so its easier if we ever want to adjust the text src/cli/* -all classes named to reflect organization of window_interface and scripts files -each implements Callable and contains relevant Picocli imports -each contains an empty `validateInput()` method where parameter formatting and validation will be carried out -executing will just print its class name for now until it is updated to execute its respective tool script --- build.gradle | 10 +- src/cli/BAM_Format_Converter/BAMtoBEDCLI.java | 50 + src/cli/BAM_Format_Converter/BAMtoGFFCLI.java | 50 + .../BAMtobedGraphCLI.java | 50 + .../BAM_Format_Converter/BAMtoscIDXCLI.java | 50 + src/cli/BAM_Manipulation/BAIIndexerCLI.java | 43 + src/cli/BAM_Manipulation/BAMRemoveDupCLI.java | 44 + .../BAM_Manipulation/FilterforPIPseqCLI.java | 53 + src/cli/BAM_Manipulation/MergeBAMCLI.java | 43 + src/cli/BAM_Manipulation/SortBAMCLI.java | 43 + .../BAMGenomeCorrelationCLI.java | 52 + src/cli/BAM_Statistics/PEStatsCLI.java | 48 + src/cli/BAM_Statistics/SEStatsCLI.java | 50 + src/cli/Coordinate_Manipulation/.DS_Store | Bin 0 -> 6148 bytes .../BED_Manipulation/BEDtoGFFCLI.java | 49 + .../BED_Manipulation/ExpandBEDCLI.java | 50 + .../BED_Manipulation/SortBEDCLI.java | 50 + .../GFF_Manipulation/ExpandGFFCLI.java | 50 + .../GFF_Manipulation/GFFtoBEDCLI.java | 49 + .../GFF_Manipulation/SortGFFCLI.java | 50 + .../Figure_Generation/CompositePlotCLI.java | 64 + .../FourColorSequenceCLI.java | 54 + src/cli/Figure_Generation/HeatMapCLI.java | 54 + .../Figure_Generation/MergeHeatMapCLI.java | 49 + src/cli/File_Utilities/MD5ChecksumCLI.java | 52 + .../Peak_Analysis/BEDPeakAligntoRefCLI.java | 49 + .../FilterBEDbyProximityCLI.java | 49 + .../Peak_Analysis/RandomCoordinateCLI.java | 49 + .../Peak_Analysis/SignalDuplicationCLI.java | 55 + src/cli/Peak_Analysis/TileGenomeCLI.java | 49 + src/cli/Peak_Calling/GeneTrackCLI.java | 47 + src/cli/Peak_Calling/PeakPairCLI.java | 47 + src/cli/Read_Analysis/AggregateDataCLI.java | 51 + src/cli/Read_Analysis/ScaleMatrixCLI.java | 49 + src/cli/Read_Analysis/ScalingFactorCLI.java | 50 + .../Read_Analysis/SimilarityMatrixCLI.java | 47 + src/cli/Read_Analysis/TagPileupCLI.java | 53 + .../Sequence_Analysis/DNAShapefromBEDCLI.java | 57 + .../DNAShapefromFASTACLI.java | 57 + .../Sequence_Analysis/FASTAExtractCLI.java | 51 + .../Sequence_Analysis/RandomizeFASTACLI.java | 49 + src/cli/Sequence_Analysis/SearchMotifCLI.java | 49 + src/main/ScriptManager.java | 1335 +++-------------- src/main/ScriptManagerGUI.java | 1239 +++++++++++++++ src/objects/ToolDescriptions.java | 64 + 45 files changed, 3513 insertions(+), 1140 deletions(-) create mode 100644 src/cli/BAM_Format_Converter/BAMtoBEDCLI.java create mode 100644 src/cli/BAM_Format_Converter/BAMtoGFFCLI.java create mode 100644 src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java create mode 100644 src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java create mode 100644 src/cli/BAM_Manipulation/BAIIndexerCLI.java create mode 100644 src/cli/BAM_Manipulation/BAMRemoveDupCLI.java create mode 100644 src/cli/BAM_Manipulation/FilterforPIPseqCLI.java create mode 100644 src/cli/BAM_Manipulation/MergeBAMCLI.java create mode 100644 src/cli/BAM_Manipulation/SortBAMCLI.java create mode 100644 src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java create mode 100644 src/cli/BAM_Statistics/PEStatsCLI.java create mode 100644 src/cli/BAM_Statistics/SEStatsCLI.java create mode 100644 src/cli/Coordinate_Manipulation/.DS_Store create mode 100644 src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java create mode 100644 src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java create mode 100644 src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java create mode 100644 src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java create mode 100644 src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java create mode 100644 src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java create mode 100644 src/cli/Figure_Generation/CompositePlotCLI.java create mode 100644 src/cli/Figure_Generation/FourColorSequenceCLI.java create mode 100644 src/cli/Figure_Generation/HeatMapCLI.java create mode 100644 src/cli/Figure_Generation/MergeHeatMapCLI.java create mode 100644 src/cli/File_Utilities/MD5ChecksumCLI.java create mode 100644 src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java create mode 100644 src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java create mode 100644 src/cli/Peak_Analysis/RandomCoordinateCLI.java create mode 100644 src/cli/Peak_Analysis/SignalDuplicationCLI.java create mode 100644 src/cli/Peak_Analysis/TileGenomeCLI.java create mode 100644 src/cli/Peak_Calling/GeneTrackCLI.java create mode 100644 src/cli/Peak_Calling/PeakPairCLI.java create mode 100644 src/cli/Read_Analysis/AggregateDataCLI.java create mode 100644 src/cli/Read_Analysis/ScaleMatrixCLI.java create mode 100644 src/cli/Read_Analysis/ScalingFactorCLI.java create mode 100644 src/cli/Read_Analysis/SimilarityMatrixCLI.java create mode 100644 src/cli/Read_Analysis/TagPileupCLI.java create mode 100644 src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java create mode 100644 src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java create mode 100644 src/cli/Sequence_Analysis/FASTAExtractCLI.java create mode 100644 src/cli/Sequence_Analysis/RandomizeFASTACLI.java create mode 100644 src/cli/Sequence_Analysis/SearchMotifCLI.java create mode 100755 src/main/ScriptManagerGUI.java create mode 100644 src/objects/ToolDescriptions.java diff --git a/build.gradle b/build.gradle index eacb91642..f11aab392 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ apply plugin: 'eclipse' sourceSets.main.java.srcDirs = ['src'] mainClassName = "main.ScriptManager" -version = 'v0.12-dev' +version = 'v0.12-devCLI' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -48,8 +48,12 @@ repositories { // Declare the dependencies for your production and test code dependencies { - compile 'org.slf4j:slf4j-api:1.7.13' - testCompile 'junit:junit:4.12' + compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.13' + // https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api + compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1' + // https://mvnrepository.com/artifact/info.picocli/picocli #CommandLineInterface Parsing Args + compile group: 'info.picocli', name: 'picocli', version: '4.2.0' + testCompile group: 'junit', name: 'junit', version: '4.12' compile fileTree(dir: 'lib', include: ['*.jar']) } diff --git a/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java b/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java new file mode 100644 index 000000000..1c07569fd --- /dev/null +++ b/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java @@ -0,0 +1,50 @@ +package cli.BAM_Format_Converter; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Format_Converter.BAMtoBED; + +/** + BAM_Format_ConverterCLI/SEStatsCLI +*/ +@Command(name = "bam-to-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_to_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMtoBEDCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BAMtoBEDCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java b/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java new file mode 100644 index 000000000..70b34cde3 --- /dev/null +++ b/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java @@ -0,0 +1,50 @@ +package cli.BAM_Format_Converter; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Format_Converter.BAMtoGFF; + +/** + BAM_Format_ConverterCLI/SEStatsCLI +*/ +@Command(name = "bam-to-gff", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_to_gff_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMtoGFFCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BAMtoGFFCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java b/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java new file mode 100644 index 000000000..9d44c16ea --- /dev/null +++ b/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java @@ -0,0 +1,50 @@ +package cli.BAM_Format_Converter; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Format_Converter.BAMtobedGraph; + +/** + BAM_Format_ConverterCLI/BAMtobedGraphCLI +*/ +@Command(name = "bam-to-bedgraph", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_to_bedgraph_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMtobedGraphCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BAMtobedGraphCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java b/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java new file mode 100644 index 000000000..6e3d028e2 --- /dev/null +++ b/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java @@ -0,0 +1,50 @@ +package cli.BAM_Format_Converter; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Format_Converter.BAMtoscIDX; + +/** + BAM_Format_ConverterCLI/BAMtosciIDXCLI +*/ +@Command(name = "bam-to-scidx", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_to_scidx_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMtoscIDXCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BAMtoscIDXCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Manipulation/BAIIndexerCLI.java b/src/cli/BAM_Manipulation/BAIIndexerCLI.java new file mode 100644 index 000000000..5d06696da --- /dev/null +++ b/src/cli/BAM_Manipulation/BAIIndexerCLI.java @@ -0,0 +1,43 @@ +package cli.BAM_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; + +/** + BAM_ManipulatioCLIn/BAIIndexerCLI +*/ +@Command(name = "bam-indexer", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_indexer_description + "\n"+ + "@|bold **Please run the samtools tool directly:**|@ \n"+ + "@|bold,yellow 'samtools index '|@", + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAIIndexerCLI implements Callable { + @Override + public Integer call() throws Exception { + System.err.println( ">BAIIndexerCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} \ No newline at end of file diff --git a/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java b/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java new file mode 100644 index 000000000..2d9032c95 --- /dev/null +++ b/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java @@ -0,0 +1,44 @@ +package cli.BAM_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; + +/** + BAM_ManipulatioCLIn/BAMRemoveDupCLI +*/ +@Command(name = "remove-duplicates", mixinStandardHelpOptions = true, + description = ToolDescriptions.remove_duplicates_description + "\n"+ + "@|bold **Please run the picard/samtools tools directly:**|@ \n"+ + "@|bold,yellow 'java -jar picard.jar MarkDuplicates I= O=\n"+ + "samtools view -F 1024 > '|@", + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMRemoveDupCLI implements Callable { + @Override + public Integer call() throws Exception { + System.err.println( ">BAMRemoveDupCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} \ No newline at end of file diff --git a/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java b/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java new file mode 100644 index 000000000..a1807c8a5 --- /dev/null +++ b/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java @@ -0,0 +1,53 @@ +package cli.BAM_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.lang.NullPointerException; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import objects.ToolDescriptions; +import util.FASTAUtilities; +import util.ExtensionFileFilter; +//import scripts.BAM_Manipulation.FilterforPIPseq; + +/** + BAM_ManipulatioCLIn/FilterforPIPseqCLI +*/ +@Command(name = "filter-pip-seq", mixinStandardHelpOptions = true, + description = ToolDescriptions.filter_pip_seq_description + "\n" + + "Note this program does not index the resulting BAM file and user must use appropriate samtools command to generate BAI.", + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class FilterforPIPseqCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">FilterforPIPseqCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Manipulation/MergeBAMCLI.java b/src/cli/BAM_Manipulation/MergeBAMCLI.java new file mode 100644 index 000000000..e0e3ef129 --- /dev/null +++ b/src/cli/BAM_Manipulation/MergeBAMCLI.java @@ -0,0 +1,43 @@ +package cli.BAM_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; + +/** + BAM_ManipulatioCLIn/MergeBAMCLI +*/ +@Command(name = "merge-bam", mixinStandardHelpOptions = true, + description = ToolDescriptions.merge_bam_description + "\n"+ + "@|bold **Please run the picard tool directly:**|@ \n"+ + "@|bold,yellow 'java -jar picard.jar MergeSamFiles'|@", + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class MergeBAMCLI implements Callable { + @Override + public Integer call() throws Exception { + System.err.println( ">MergeBAMCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} \ No newline at end of file diff --git a/src/cli/BAM_Manipulation/SortBAMCLI.java b/src/cli/BAM_Manipulation/SortBAMCLI.java new file mode 100644 index 000000000..51b3c1707 --- /dev/null +++ b/src/cli/BAM_Manipulation/SortBAMCLI.java @@ -0,0 +1,43 @@ +package cli.BAM_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; + +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; + +/** + BAM_ManipulatioCLI/SortBAMCLI +*/ +@Command(name = "sort-bam", mixinStandardHelpOptions = true, + description = ToolDescriptions.sort_bam_description + "\n"+ + "@|bold **Please run the samtools tool directly:**|@ \n"+ + "@|bold,yellow 'samtools sort -o '|@", + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SortBAMCLI implements Callable { + @Override + public Integer call() throws Exception { + System.err.println( ">SortBAMCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} \ No newline at end of file diff --git a/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java b/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java new file mode 100644 index 000000000..b979a729e --- /dev/null +++ b/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java @@ -0,0 +1,52 @@ +package cli.BAM_Statistics; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.Scanner; +import java.util.Vector; +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Statistics.BAMGenomeCorrelation; + +/** + BAM_StatisticsCLI/SEStats +*/ +@Command(name = "bam-correlation", mixinStandardHelpOptions = true, + description = ToolDescriptions.bam_correlation_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BAMGenomeCorrelationCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BAMGenomeCorrelationCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Statistics/PEStatsCLI.java b/src/cli/BAM_Statistics/PEStatsCLI.java new file mode 100644 index 000000000..4f2425675 --- /dev/null +++ b/src/cli/BAM_Statistics/PEStatsCLI.java @@ -0,0 +1,48 @@ +package cli.BAM_Statistics; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Statistics.PEStats; + +/** + BAM_StatisticsCLI/PEStatsCLI +*/ +@Command(name = "pe-stat", mixinStandardHelpOptions = true, + description = ToolDescriptions.pe_stat_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class PEStatsCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">PEStatsCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/BAM_Statistics/SEStatsCLI.java b/src/cli/BAM_Statistics/SEStatsCLI.java new file mode 100644 index 000000000..892c99b2f --- /dev/null +++ b/src/cli/BAM_Statistics/SEStatsCLI.java @@ -0,0 +1,50 @@ +package cli.BAM_Statistics; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; +import java.util.Vector; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.BAM_Statistics.SEStats; + +/** + BAM_StatisticsCLI/SEStatsCLI + //java -jar build/libs/ScriptManager-0.12.jar bam-statistics se-stat [-o ] +*/ +@Command(name = "se-stat", mixinStandardHelpOptions = true, + description = ToolDescriptions.se_stat_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SEStatsCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SEStatsCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/.DS_Store b/src/cli/Coordinate_Manipulation/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..77420710a3793373bcbe25cd4d0d4559cda29251 GIT binary patch literal 6148 zcmeH~O^XvT7{{ON*4>O-*;x==!9zgAOAj+vy4!;=)K(D`#TNJAOLxW@?8ulY)9Dti zmHGv|yL#~A%lFWWpFqEecb~j;wYE}05Yap(`RC<%67ma~Gyp(q{m=!l0f1r>S~!f^ z925N_&DfG|SwSUoj4R*+hZwrhpYb*ghJYdPw-FF$*M=H2pbl;L{`@9*mUBGIDez#> z>jp_0pzoKUo5a1`aXyo!<-(zrRccvlMXR`8yxr`igJ$mM{a($_Zi?D9Kko#7*0xVH z<1oU~P8{Z)R>T`gv={NK*=0YElxr(Z6LgSaEkC#sM}xL~^nA*5Kju*;$5vz9+KG9X z4r*zihdt@92dDI;$6ran7PZ>;=5TnXS}n1&+tpEt4Y#%&ESD>zkwuT6E?>WM|LL>+ z7cXDGdHe3Y3<825F=-oGC-MOc3n7KQyGekn5J3x__nH|`QhpD8#iTY|gbVoll^ysv z*?~{rc7R$(=p6nUjDq?bfb~A&R%@-^bFzg-=smK { + + @Override + public Integer call() throws Exception { + System.err.println( ">BEDtoGFFCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java b/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java new file mode 100644 index 000000000..2b5ffd282 --- /dev/null +++ b/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java @@ -0,0 +1,50 @@ +package cli.Coordinate_Manipulation.BED_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Coordinate_Manipulation.BED_Manipulation.ExpandBED; + +/** + Coordinate_ManipulationCLI/ExpandBEDCLI +*/ +@Command(name = "expand-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.expand_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class ExpandBEDCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">ExpandBEDCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java b/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java new file mode 100644 index 000000000..e7ceb6840 --- /dev/null +++ b/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java @@ -0,0 +1,50 @@ +package cli.Coordinate_Manipulation.BED_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; +import java.io.FileNotFoundException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Coordinate_Manipulation.BED_Manipulation.SortBED; + +/** + Coordinate_ManipulationCLI/SortBEDCLI +*/ +@Command(name = "sort-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.sort_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SortBEDCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SortBEDCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java new file mode 100644 index 000000000..e2e0b798d --- /dev/null +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java @@ -0,0 +1,50 @@ +package cli.Coordinate_Manipulation.GFF_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Coordinate_Manipulation.GFF_Manipulation.ExpandGFF; + +/** + Coordinate_ManipulationCLI/ExpandGFFCLI +*/ +@Command(name = "expand-gff", mixinStandardHelpOptions = true, + description = ToolDescriptions.expand_gff_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class ExpandGFFCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">ExpandGFFCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java new file mode 100644 index 000000000..00d7a26d3 --- /dev/null +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java @@ -0,0 +1,49 @@ +package cli.Coordinate_Manipulation.GFF_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Coordinate_Manipulation.GFF_Manipulation.GFFtoBED; + +/** + Coordinate_ManipulationCLI/GFFtoBEDCLI +*/ +@Command(name = "gff-to-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.gff_to_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class GFFtoBEDCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">GFFtoBEDCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java new file mode 100644 index 000000000..c8ddc2e9a --- /dev/null +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java @@ -0,0 +1,50 @@ +package cli.Coordinate_Manipulation.GFF_Manipulation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; +import java.io.FileNotFoundException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Coordinate_Manipulation.GFF_Manipulation.SortGFF; + +/** + Coordinate_ManipulationCLI/SortGFFCLI +*/ +@Command(name = "sort-gff", mixinStandardHelpOptions = true, + description = ToolDescriptions.sort_gff_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SortGFFCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SortGFFCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Figure_Generation/CompositePlotCLI.java b/src/cli/Figure_Generation/CompositePlotCLI.java new file mode 100644 index 000000000..163bae025 --- /dev/null +++ b/src/cli/Figure_Generation/CompositePlotCLI.java @@ -0,0 +1,64 @@ +package cli.Figure_Generation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.awt.Color; +import java.lang.NullPointerException; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.FileOutputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.concurrent.Callable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; +import org.jfree.data.xy.XYSeriesCollection; +import org.jfree.data.xy.XYSeries; + +import charts.CompositePlot; +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Figure_Generation.MergeHeatMapPlot; + +/** + Figure_GenerationCLI/CompositePlotCLI +*/ +@Command(name = "composite-plot", mixinStandardHelpOptions = true, + description = ToolDescriptions.composite_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class CompositePlotCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">CompositePlotCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Figure_Generation/FourColorSequenceCLI.java b/src/cli/Figure_Generation/FourColorSequenceCLI.java new file mode 100644 index 000000000..ff538d82d --- /dev/null +++ b/src/cli/Figure_Generation/FourColorSequenceCLI.java @@ -0,0 +1,54 @@ +package cli.Figure_Generation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.lang.NullPointerException; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Figure_Generation.FourColorPlot; + +/** + Figure_GenerationCLI/FourColorSequenceCLI +*/ +@Command(name = "four-color", mixinStandardHelpOptions = true, + description = ToolDescriptions.four_color_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class FourColorSequenceCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">FourColorSequenceCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Figure_Generation/HeatMapCLI.java b/src/cli/Figure_Generation/HeatMapCLI.java new file mode 100644 index 000000000..d52527cbd --- /dev/null +++ b/src/cli/Figure_Generation/HeatMapCLI.java @@ -0,0 +1,54 @@ +package cli.Figure_Generation; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.lang.NullPointerException; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; + +import java.awt.Color; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Figure_Generation.HeatmapPlot; + +/** + Figure_GenerationCLI/HeatMapCLI +*/ +@Command(name = "heatmap", mixinStandardHelpOptions = true, + description = ToolDescriptions.heatmap_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class HeatMapCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">HeatMapCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Figure_Generation/MergeHeatMapCLI.java b/src/cli/Figure_Generation/MergeHeatMapCLI.java new file mode 100644 index 000000000..95aa0c080 --- /dev/null +++ b/src/cli/Figure_Generation/MergeHeatMapCLI.java @@ -0,0 +1,49 @@ +package cli.Figure_Generation; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.lang.NullPointerException; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Figure_Generation.MergeHeatMapPlot; + +/** + Figure_GenerationCLI/MergeHeatMapCLI +*/ +@Command(name = "merge-heatmap", mixinStandardHelpOptions = true, + description = ToolDescriptions.merge_heatmap_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class MergeHeatMapCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">MergeHeatMapCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/File_Utilities/MD5ChecksumCLI.java b/src/cli/File_Utilities/MD5ChecksumCLI.java new file mode 100644 index 000000000..7d35b2acc --- /dev/null +++ b/src/cli/File_Utilities/MD5ChecksumCLI.java @@ -0,0 +1,52 @@ +package cli.File_Utilities; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URISyntaxException; +import java.sql.Timestamp; +import java.util.Date; + +import objects.ToolDescriptions; +//import scripts.File_Utilities.MD5Checksum; + +/** + File_UtilitiesCLI/MD5ChecksumCLI +*/ +@Command(name = "md5checksum", mixinStandardHelpOptions = true, + description = ToolDescriptions.md5checksum_description, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class MD5ChecksumCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">MD5ChecksumCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java b/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java new file mode 100644 index 000000000..9fd78c20b --- /dev/null +++ b/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java @@ -0,0 +1,49 @@ +package cli.Peak_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Peak_Analysis.BEDPeakAligntoRef; + +/** + Peak_AnalysisCLI/BEDPeakAligntoRefCLI +*/ +@Command(name = "peak-align-ref", mixinStandardHelpOptions = true, + description = ToolDescriptions.peak_align_ref_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class BEDPeakAligntoRefCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">BEDPeakAligntoRefCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java b/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java new file mode 100644 index 000000000..cf5a2c1a0 --- /dev/null +++ b/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java @@ -0,0 +1,49 @@ +package cli.Peak_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Peak_Analysis.FilterBEDbyProximity; + +/** + Peak_AnalysisCLI/FilterBEDbyProximityCLI +*/ +@Command(name = "filter-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.filter_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class FilterBEDbyProximityCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">FilterBEDbyProximityCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Analysis/RandomCoordinateCLI.java b/src/cli/Peak_Analysis/RandomCoordinateCLI.java new file mode 100644 index 000000000..c97b01d21 --- /dev/null +++ b/src/cli/Peak_Analysis/RandomCoordinateCLI.java @@ -0,0 +1,49 @@ +package cli.Peak_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Peak_Analysis.RandomCoordinate; + +/** + Peak_AnalysisCLI/RandomCoordinateCLI +*/ +@Command(name = "rand-coord", mixinStandardHelpOptions = true, + description = ToolDescriptions.rand_coord_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class RandomCoordinateCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">RandomCoordinateCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Analysis/SignalDuplicationCLI.java b/src/cli/Peak_Analysis/SignalDuplicationCLI.java new file mode 100644 index 000000000..9f556c658 --- /dev/null +++ b/src/cli/Peak_Analysis/SignalDuplicationCLI.java @@ -0,0 +1,55 @@ +package cli.Peak_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.NullPointerException; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Peak_Analysis.SignalDuplication; + +/** + Peak_AnalysisCLI/SignalDuplicationCLI +*/ +@Command(name = "signal-dup", mixinStandardHelpOptions = true, + description = ToolDescriptions.signal_dup_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SignalDuplicationCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SignalDuplicationCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Analysis/TileGenomeCLI.java b/src/cli/Peak_Analysis/TileGenomeCLI.java new file mode 100644 index 000000000..881d66da1 --- /dev/null +++ b/src/cli/Peak_Analysis/TileGenomeCLI.java @@ -0,0 +1,49 @@ +package cli.Peak_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Peak_Analysis.TileGenome; + +/** + Peak_AnalysisCLI/TileGenomeCLI +*/ +@Command(name = "tile-genome", mixinStandardHelpOptions = true, + description = ToolDescriptions.tile_genome_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class TileGenomeCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">TileGenomeCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Calling/GeneTrackCLI.java b/src/cli/Peak_Calling/GeneTrackCLI.java new file mode 100644 index 000000000..de99c1762 --- /dev/null +++ b/src/cli/Peak_Calling/GeneTrackCLI.java @@ -0,0 +1,47 @@ +package cli.Peak_Calling; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; + +/** + Peak_CallingCLI/GeneTrackCLI +*/ +@Command(name = "gene-track", mixinStandardHelpOptions = true, + description = ToolDescriptions.gene_track_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class GeneTrackCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.out.println( ">GeneTrackCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Peak_Calling/PeakPairCLI.java b/src/cli/Peak_Calling/PeakPairCLI.java new file mode 100644 index 000000000..271cc07c5 --- /dev/null +++ b/src/cli/Peak_Calling/PeakPairCLI.java @@ -0,0 +1,47 @@ +package cli.Peak_Calling; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; + +/** + Peak_CallingCLI/PeakPairCLI +*/ +@Command(name = "peak-pair", mixinStandardHelpOptions = true, + description = ToolDescriptions.peak_pairing_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class PeakPairCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.out.println( ">PeakPairCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Read_Analysis/AggregateDataCLI.java b/src/cli/Read_Analysis/AggregateDataCLI.java new file mode 100644 index 000000000..95834a4ee --- /dev/null +++ b/src/cli/Read_Analysis/AggregateDataCLI.java @@ -0,0 +1,51 @@ +package cli.Read_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.io.File; +import java.io.IOException; +import java.util.Scanner; +import java.util.ArrayList; +import java.util.concurrent.Callable; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Read_Analysis.AggregateData; + +/** + Read_AnalysisCLI/AggregateDataCLI +*/ +@Command(name = "aggregate-data", mixinStandardHelpOptions = true, + description = ToolDescriptions.aggregate_data_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class AggregateDataCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">AggregateDataCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Read_Analysis/ScaleMatrixCLI.java b/src/cli/Read_Analysis/ScaleMatrixCLI.java new file mode 100644 index 000000000..c068b0a34 --- /dev/null +++ b/src/cli/Read_Analysis/ScaleMatrixCLI.java @@ -0,0 +1,49 @@ +package cli.Read_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Read_Analysis.ScaleMatrix; + +/** + Read_AnalysisCLI/ScaleMatrixCLI +*/ +@Command(name = "scale-matrix", mixinStandardHelpOptions = true, + description = ToolDescriptions.scale_matrix_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class ScaleMatrixCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">ScaleMatrixCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Read_Analysis/ScalingFactorCLI.java b/src/cli/Read_Analysis/ScalingFactorCLI.java new file mode 100644 index 000000000..80fd06cdd --- /dev/null +++ b/src/cli/Read_Analysis/ScalingFactorCLI.java @@ -0,0 +1,50 @@ +package cli.Read_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Read_Analysis.ScalingFactor; + +/** + Read_AnalysisCLI/ScalingFactorCLI +*/ +@Command(name = "scaling-factor", mixinStandardHelpOptions = true, + description = ToolDescriptions.scaling_factor_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class ScalingFactorCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">ScalingFactorCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Read_Analysis/SimilarityMatrixCLI.java b/src/cli/Read_Analysis/SimilarityMatrixCLI.java new file mode 100644 index 000000000..5cd5cda50 --- /dev/null +++ b/src/cli/Read_Analysis/SimilarityMatrixCLI.java @@ -0,0 +1,47 @@ +package cli.Read_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; + +/** + Read_AnalysisCLI/SimilarityMatrixCLI +*/ +@Command(name = "similarity-matrix", mixinStandardHelpOptions = true, + description = "", + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SimilarityMatrixCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SimilarityMatrixCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Read_Analysis/TagPileupCLI.java b/src/cli/Read_Analysis/TagPileupCLI.java new file mode 100644 index 000000000..bbcadfee4 --- /dev/null +++ b/src/cli/Read_Analysis/TagPileupCLI.java @@ -0,0 +1,53 @@ +package cli.Read_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.awt.Color; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import util.ExtensionFileFilter; +import objects.ToolDescriptions; +//import scripts.Read_Analysis.TagPileup; + +/** + Read_AnalysisCLI/TagPileupCLI +*/ +@Command(name = "tag-pileup", mixinStandardHelpOptions = true, + description = ToolDescriptions.tag_pileup_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class TagPileupCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">TagPileupCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java b/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java new file mode 100644 index 000000000..96985e29a --- /dev/null +++ b/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java @@ -0,0 +1,57 @@ +package cli.Sequence_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Sequence_Analysis.DNAShapefromBED; + +/** + Sequence_AnalysisCLI/DNAShapefromBEDCLI +*/ +@Command(name = "dna-shape-bed", mixinStandardHelpOptions = true, + description = ToolDescriptions.dna_shape_from_bed_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class DNAShapefromBEDCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">DNAShapefromBEDCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java b/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java new file mode 100644 index 000000000..91869dd72 --- /dev/null +++ b/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java @@ -0,0 +1,57 @@ +package cli.Sequence_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.ArgGroup; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.jfree.chart.JFreeChart; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Sequence_Analysis.DNAShapefromFASTA; + +/** + Sequence_AnalysisCLI/DNAShapefromFASTACLI +*/ +@Command(name = "dna-shape-fasta", mixinStandardHelpOptions = true, + description = ToolDescriptions.dna_shape_from_fasta_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class DNAShapefromFASTACLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">DNAShapefromFASTACLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Sequence_Analysis/FASTAExtractCLI.java b/src/cli/Sequence_Analysis/FASTAExtractCLI.java new file mode 100644 index 000000000..fb290c9d4 --- /dev/null +++ b/src/cli/Sequence_Analysis/FASTAExtractCLI.java @@ -0,0 +1,51 @@ +package cli.Sequence_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Sequence_Analysis.FASTAExtract; + +/** + Sequence_AnalysisCLI/FASTAExtractCLI +*/ +@Command(name = "fasta-extract", mixinStandardHelpOptions = true, + description = ToolDescriptions.fasta_extract_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class FASTAExtractCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">FASTAExtractCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Sequence_Analysis/RandomizeFASTACLI.java b/src/cli/Sequence_Analysis/RandomizeFASTACLI.java new file mode 100644 index 000000000..af90e4235 --- /dev/null +++ b/src/cli/Sequence_Analysis/RandomizeFASTACLI.java @@ -0,0 +1,49 @@ +package cli.Sequence_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Sequence_Analysis.RandomizeFASTA; + +/** + Sequence_AnalysisCLI/RandomizeFASTACLI +*/ +@Command(name = "randomize-fasta", mixinStandardHelpOptions = true, + description = ToolDescriptions.randomize_fasta_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class RandomizeFASTACLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">RandomizeFASTACLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/cli/Sequence_Analysis/SearchMotifCLI.java b/src/cli/Sequence_Analysis/SearchMotifCLI.java new file mode 100644 index 000000000..c0a755d5a --- /dev/null +++ b/src/cli/Sequence_Analysis/SearchMotifCLI.java @@ -0,0 +1,49 @@ +package cli.Sequence_Analysis; + +import picocli.CommandLine; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +import java.util.concurrent.Callable; + +import java.io.File; +import java.io.IOException; + +import objects.ToolDescriptions; +import util.ExtensionFileFilter; +//import scripts.Sequence_Analysis.SearchMotif; + +/** + Sequence_AnalysisCLI/SearchMotifCLI +*/ +@Command(name = "search-motif", mixinStandardHelpOptions = true, + description = ToolDescriptions.search_motif_description, + sortOptions = false, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class SearchMotifCLI implements Callable { + + @Override + public Integer call() throws Exception { + System.err.println( ">SearchMotifCLI.call()" ); + String validate = validateInput(); + if(!validate.equals("")){ + System.err.println( validate ); + System.err.println("Invalid input. Check usage using '-h' or '--help'"); + System.exit(1); + } + + //SEStats.getSEStats( output, bamFile, null ); + + //System.err.println("Calculations Complete"); + return(0); + } + + private String validateInput() throws IOException { + String r = ""; + //validate input here + //append messages to the user to `r` + return(r); + } +} diff --git a/src/main/ScriptManager.java b/src/main/ScriptManager.java index ebc9eb022..9e37a732c 100755 --- a/src/main/ScriptManager.java +++ b/src/main/ScriptManager.java @@ -1,1160 +1,221 @@ package main; -import java.awt.EventQueue; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; +import picocli.CommandLine; +import picocli.CommandLine.Command; -import javax.swing.JFrame; -import javax.swing.JButton; -import javax.swing.SpringLayout; -import javax.swing.UIManager; -import javax.swing.JTabbedPane; -import javax.swing.JPanel; -import javax.swing.JSplitPane; -import javax.swing.JTextArea; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.concurrent.Callable; -import window_interface.BAM_Statistics.PEStatWindow; -import window_interface.BAM_Statistics.SEStatWindow; -import window_interface.BAM_Statistics.BAMGenomeCorrelationWindow; -import window_interface.BAM_Manipulation.BAIIndexerWindow; -import window_interface.BAM_Manipulation.BAMRemoveDupWindow; -import window_interface.BAM_Manipulation.FilterforPIPseqWindow; -import window_interface.BAM_Manipulation.MergeBAMWindow; -import window_interface.BAM_Manipulation.SortBAMWindow; -import window_interface.BAM_Format_Converter.BAMtoBEDWindow; -import window_interface.BAM_Format_Converter.BAMtoGFFWindow; -import window_interface.BAM_Format_Converter.BAMtobedGraphWindow; -import window_interface.BAM_Format_Converter.BAMtoscIDXWindow; -import window_interface.Peak_Analysis.BEDPeakAligntoRefWindow; -import window_interface.Peak_Analysis.FilterBEDbyProximityWindow; -import window_interface.Peak_Analysis.RandomCoordinateWindow; -import window_interface.Peak_Analysis.SignalDuplicationWindow; -import window_interface.Peak_Analysis.TileGenomeWindow; -import window_interface.Peak_Calling.GeneTrackWindow; -import window_interface.Peak_Calling.PeakPairWindow; -import window_interface.Coordinate_Manipulation.BED_Manipulation.BEDtoGFFWindow; -import window_interface.Coordinate_Manipulation.BED_Manipulation.ExpandBEDWindow; -import window_interface.Coordinate_Manipulation.BED_Manipulation.SortBEDWindow; -import window_interface.Coordinate_Manipulation.GFF_Manipulation.ExpandGFFWindow; -import window_interface.Coordinate_Manipulation.GFF_Manipulation.GFFtoBEDWindow; -import window_interface.Coordinate_Manipulation.GFF_Manipulation.SortGFFWindow; -import window_interface.File_Utilities.MD5ChecksumWindow; -import window_interface.Read_Analysis.AggregateDataWindow; -import window_interface.Read_Analysis.ScaleMatrixWindow; -import window_interface.Read_Analysis.ScalingFactorWindow; -import window_interface.Read_Analysis.TagPileupWindow; -import window_interface.Sequence_Analysis.DNAShapefromBEDWindow; -import window_interface.Sequence_Analysis.DNAShapefromFASTAWindow; -import window_interface.Sequence_Analysis.FASTAExtractWindow; -import window_interface.Sequence_Analysis.RandomizeFASTAWindow; -import window_interface.Sequence_Analysis.SearchMotifWindow; -import window_interface.Figure_Generation.FourColorSequenceWindow; -import window_interface.Figure_Generation.HeatMapWindow; -import window_interface.Figure_Generation.MergeHeatMapWindow; +import main.ScriptManagerGUI; -public class ScriptManager { - public static final String VERSION = "0.12-dev"; +import cli.BAM_Format_Converter.BAMtoBEDCLI; +import cli.BAM_Format_Converter.BAMtobedGraphCLI; +import cli.BAM_Format_Converter.BAMtoGFFCLI; +import cli.BAM_Format_Converter.BAMtoscIDXCLI; - private JFrame frmScriptManager; - /** - * Initialize the contents of the frame. - */ - private void initialize() { - frmScriptManager = new JFrame(); - frmScriptManager.setTitle("Script Manager v" + VERSION); - frmScriptManager.setBounds(100, 100, 600, 350); - frmScriptManager.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frmScriptManager.setResizable(false); - SpringLayout springLayout = new SpringLayout(); - frmScriptManager.getContentPane().setLayout(springLayout); - - JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); - springLayout.putConstraint(SpringLayout.NORTH, tabbedPane, 10, SpringLayout.NORTH, frmScriptManager.getContentPane()); - springLayout.putConstraint(SpringLayout.WEST, tabbedPane, 10, SpringLayout.WEST, frmScriptManager.getContentPane()); - springLayout.putConstraint(SpringLayout.SOUTH, tabbedPane, -10, SpringLayout.SOUTH, frmScriptManager.getContentPane()); - springLayout.putConstraint(SpringLayout.EAST, tabbedPane, -10, SpringLayout.EAST, frmScriptManager.getContentPane()); - frmScriptManager.getContentPane().add(tabbedPane); - - JPanel pnlStat = new JPanel(); - SpringLayout sl_pnlStat = new SpringLayout(); - pnlStat.setLayout(sl_pnlStat); - tabbedPane.addTab("BAM Statistics", null, pnlStat, null); - - JTextArea txtOutputAlignmentStatistics = new JTextArea(); - initializeTextArea(txtOutputAlignmentStatistics); - txtOutputAlignmentStatistics.setText("Output BAM Header including alignment statistics and parameters given any indexed (BAI) BAM File."); - sl_pnlStat.putConstraint(SpringLayout.NORTH, txtOutputAlignmentStatistics, 10, SpringLayout.NORTH, pnlStat); - sl_pnlStat.putConstraint(SpringLayout.EAST, txtOutputAlignmentStatistics, -10, SpringLayout.EAST, pnlStat); - pnlStat.add(txtOutputAlignmentStatistics); - - JButton btnBAMStats = new JButton("BAM Statistics"); - btnBAMStats.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SEStatWindow frame = new SEStatWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBAMStats, 0, SpringLayout.NORTH, txtOutputAlignmentStatistics); - sl_pnlStat.putConstraint(SpringLayout.WEST, btnBAMStats, 10, SpringLayout.WEST, pnlStat); - sl_pnlStat.putConstraint(SpringLayout.WEST, txtOutputAlignmentStatistics, 10, SpringLayout.EAST, btnBAMStats); - pnlStat.add(btnBAMStats); +import cli.BAM_Manipulation.BAIIndexerCLI; +import cli.BAM_Manipulation.BAMRemoveDupCLI; +import cli.BAM_Manipulation.FilterforPIPseqCLI; +import cli.BAM_Manipulation.MergeBAMCLI; +import cli.BAM_Manipulation.SortBAMCLI; - JTextArea txtPEStats = new JTextArea(); - initializeTextArea(txtPEStats); - txtPEStats.setText("Generates Insert-size Histogram statistics (GEO requirement) and outputs BAM Header including alignment statistics and parameters given a sorted and indexed (BAI) paired-end BAM File."); - sl_pnlStat.putConstraint(SpringLayout.NORTH, txtPEStats, 10, SpringLayout.SOUTH, txtOutputAlignmentStatistics); - sl_pnlStat.putConstraint(SpringLayout.EAST, txtPEStats, -10, SpringLayout.EAST, pnlStat); - pnlStat.add(txtPEStats); - - JButton btnPEStats = new JButton("Paired-End Statistics"); - btnPEStats.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - PEStatWindow frame = new PEStatWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlStat.putConstraint(SpringLayout.NORTH, btnPEStats, 0, SpringLayout.NORTH, txtPEStats); - sl_pnlStat.putConstraint(SpringLayout.WEST, btnPEStats, 10, SpringLayout.WEST, pnlStat); - sl_pnlStat.putConstraint(SpringLayout.WEST, txtPEStats, 10, SpringLayout.EAST, btnPEStats); - pnlStat.add(btnPEStats); +import cli.BAM_Statistics.BAMGenomeCorrelationCLI; +import cli.BAM_Statistics.PEStatsCLI; +import cli.BAM_Statistics.SEStatsCLI; - JTextArea txtBamGenomeCorrelation = new JTextArea(); - initializeTextArea(txtBamGenomeCorrelation); - txtBamGenomeCorrelation.setText("Genome-Genome correlations for replicate comparisons given multiple sorted and indexed (BAI) BAM files."); - sl_pnlStat.putConstraint(SpringLayout.NORTH, txtBamGenomeCorrelation, 10, SpringLayout.SOUTH, txtPEStats); - sl_pnlStat.putConstraint(SpringLayout.EAST, txtBamGenomeCorrelation, -10, SpringLayout.EAST, pnlStat); - pnlStat.add(txtBamGenomeCorrelation); - - JButton btnBamGenomeCorrelation = new JButton("BAM Genome Correlation"); - btnBamGenomeCorrelation.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMGenomeCorrelationWindow frame = new BAMGenomeCorrelationWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBamGenomeCorrelation, 0, SpringLayout.NORTH, txtBamGenomeCorrelation); - sl_pnlStat.putConstraint(SpringLayout.WEST, btnBamGenomeCorrelation, 10, SpringLayout.WEST, pnlStat); - sl_pnlStat.putConstraint(SpringLayout.WEST, txtBamGenomeCorrelation, 10, SpringLayout.EAST, btnBamGenomeCorrelation); - pnlStat.add(btnBamGenomeCorrelation); - - JPanel pnlBamManip = new JPanel(); - SpringLayout sl_pnlBamManip = new SpringLayout(); - pnlBamManip.setLayout(sl_pnlBamManip); - tabbedPane.addTab("BAM Manipulation", null, pnlBamManip, null); - - JTextArea txtBAIIndex = new JTextArea(); - initializeTextArea(txtBAIIndex); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBAIIndex, 10, SpringLayout.NORTH, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBAIIndex, -10, SpringLayout.EAST, pnlBamManip); - txtBAIIndex.setText("Generates BAI Index for input BAM files. Output BAI is in the same directory as input BAM file."); - pnlBamManip.add(txtBAIIndex); - - JButton btnBaiIndexer = new JButton("BAM-BAI Indexer"); - btnBaiIndexer.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAIIndexerWindow frame = new BAIIndexerWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBaiIndexer, 0, SpringLayout.NORTH, txtBAIIndex); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBaiIndexer, 10, SpringLayout.WEST, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBAIIndex, 10, SpringLayout.EAST, btnBaiIndexer); - pnlBamManip.add(btnBaiIndexer); +import cli.Coordinate_Manipulation.BED_Manipulation.BEDtoGFFCLI; +import cli.Coordinate_Manipulation.BED_Manipulation.ExpandBEDCLI; +import cli.Coordinate_Manipulation.BED_Manipulation.SortBEDCLI; - JTextArea txtBamSort = new JTextArea(); - initializeTextArea(txtBamSort); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamSort, 10, SpringLayout.SOUTH, txtBAIIndex); - sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamSort, -10, SpringLayout.EAST, pnlBamManip); - txtBamSort.setText("Sort BAM files in order to efficiently extract and manipulate.\nRAM intensive process. If program freezes, increase JAVA heap size"); - pnlBamManip.add(txtBamSort); - - JButton btnBamSort = new JButton("BAM File Sorter"); - btnBamSort.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SortBAMWindow frame = new SortBAMWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamSort, 0, SpringLayout.NORTH, txtBamSort); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamSort, 10, SpringLayout.WEST, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamSort, 10, SpringLayout.EAST, btnBamSort); - pnlBamManip.add(btnBamSort); +import cli.Coordinate_Manipulation.GFF_Manipulation.ExpandGFFCLI; +import cli.Coordinate_Manipulation.GFF_Manipulation.GFFtoBEDCLI; +import cli.Coordinate_Manipulation.GFF_Manipulation.SortGFFCLI; - JTextArea txtBamRemoveDuplicates = new JTextArea(); - initializeTextArea(txtBamRemoveDuplicates); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamRemoveDuplicates, 10, SpringLayout.SOUTH, txtBamSort); - sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamRemoveDuplicates, -10, SpringLayout.EAST, pnlBamManip); - txtBamRemoveDuplicates.setText("Removes duplicate reads in Paired-End sequencing given identical 5' read locations. RAM intensive process. If program freezes, increase JAVA heap size"); - pnlBamManip.add(txtBamRemoveDuplicates); +import cli.Figure_Generation.CompositePlotCLI; +import cli.Figure_Generation.FourColorSequenceCLI; +import cli.Figure_Generation.HeatMapCLI; +import cli.Figure_Generation.MergeHeatMapCLI; - JButton btnBamRemoveDuplicates = new JButton("BAM Remove Duplicates"); - btnBamRemoveDuplicates.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMRemoveDupWindow frame = new BAMRemoveDupWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamRemoveDuplicates, 0, SpringLayout.NORTH, txtBamRemoveDuplicates); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamRemoveDuplicates, 10, SpringLayout.WEST, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamRemoveDuplicates, 10, SpringLayout.EAST, btnBamRemoveDuplicates); - pnlBamManip.add(btnBamRemoveDuplicates); +import cli.File_Utilities.MD5ChecksumCLI; - JTextArea txtBamReplicateMerge = new JTextArea(); - initializeTextArea(txtBamReplicateMerge); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamReplicateMerge, 10, SpringLayout.SOUTH, txtBamRemoveDuplicates); - sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamReplicateMerge, -10, SpringLayout.EAST, pnlBamManip); - txtBamReplicateMerge.setText("Merges Multiple BAM files into single BAM file. Sorting is performed automatically. RAM intensive process. If program freezes, increase JAVA heap size"); - pnlBamManip.add(txtBamReplicateMerge); - - JButton btnBamReplicateMerge = new JButton("BAM Replicate Merge"); - btnBamReplicateMerge.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - MergeBAMWindow frame = new MergeBAMWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamReplicateMerge, 0, SpringLayout.NORTH, txtBamReplicateMerge); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamReplicateMerge, 10, SpringLayout.WEST, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamReplicateMerge, 10, SpringLayout.EAST, btnBamReplicateMerge); - pnlBamManip.add(btnBamReplicateMerge); - - JTextArea txtFilterForPIPseq = new JTextArea(); - initializeTextArea(txtFilterForPIPseq); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtFilterForPIPseq, 10, SpringLayout.SOUTH, txtBamReplicateMerge); - sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtFilterForPIPseq, -10, SpringLayout.EAST, pnlBamManip); - txtFilterForPIPseq.setText("Filter BAM file by -1 nucleotide. Requires genome FASTA file."); - pnlBamManip.add(txtFilterForPIPseq); - - JButton btnFilterForPIPseq = new JButton("Filter for PIP-seq"); - btnFilterForPIPseq.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - FilterforPIPseqWindow frame = new FilterforPIPseqWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnFilterForPIPseq, 0, SpringLayout.NORTH, txtFilterForPIPseq); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnFilterForPIPseq, 10, SpringLayout.WEST, pnlBamManip); - sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtFilterForPIPseq, 10, SpringLayout.EAST, btnFilterForPIPseq); - pnlBamManip.add(btnFilterForPIPseq); - - JPanel pnlBamConvert = new JPanel(); - SpringLayout sl_pnlBamConvert = new SpringLayout(); - pnlBamConvert.setLayout(sl_pnlBamConvert); - tabbedPane.addTab("BAM Format Converter", null, pnlBamConvert, null); - - JTextArea txtBamToscIDX = new JTextArea(); - initializeTextArea(txtBamToscIDX); - txtBamToscIDX.setText("Convert BAM file to scIDX file"); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToscIDX, 10, SpringLayout.NORTH, pnlBamConvert); - sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToscIDX, -10, SpringLayout.EAST, pnlBamConvert); - pnlBamConvert.add(txtBamToscIDX); - - JButton btnBamToscIDX = new JButton("BAM to scIDX"); - btnBamToscIDX.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMtoscIDXWindow frame = new BAMtoscIDXWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToscIDX, 0, SpringLayout.NORTH, txtBamToscIDX); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToscIDX, 10, SpringLayout.WEST, pnlBamConvert); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToscIDX, 10, SpringLayout.EAST, btnBamToscIDX); - pnlBamConvert.add(btnBamToscIDX); - - JTextArea txtBamToGFF = new JTextArea(); - initializeTextArea(txtBamToGFF); - txtBamToGFF.setText("Convert BAM file to GFF file"); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToGFF, 10, SpringLayout.SOUTH, txtBamToscIDX); - sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToGFF, -10, SpringLayout.EAST, pnlBamConvert); - pnlBamConvert.add(txtBamToGFF); - - JButton btnBamToGff = new JButton("BAM to GFF"); - btnBamToGff.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMtoGFFWindow frame = new BAMtoGFFWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToGff, 0, SpringLayout.NORTH, txtBamToGFF); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToGff, 10, SpringLayout.WEST, pnlBamConvert); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToGFF, 10, SpringLayout.EAST, btnBamToGff); - pnlBamConvert.add(btnBamToGff); - - JTextArea txtBamToBed = new JTextArea(); - initializeTextArea(txtBamToBed); - txtBamToBed.setText("Convert BAM file to BED file"); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBed, 10, SpringLayout.SOUTH, txtBamToGFF); - sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToBed, -10, SpringLayout.EAST, pnlBamConvert); - pnlBamConvert.add(txtBamToBed); +import cli.Peak_Analysis.BEDPeakAligntoRefCLI; +import cli.Peak_Analysis.FilterBEDbyProximityCLI; +import cli.Peak_Analysis.RandomCoordinateCLI; +import cli.Peak_Analysis.SignalDuplicationCLI; +import cli.Peak_Analysis.TileGenomeCLI; - JButton btnBamToBed = new JButton("BAM to BED"); - btnBamToBed.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMtoBEDWindow frame = new BAMtoBEDWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToBed, 0, SpringLayout.NORTH, txtBamToBed); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToBed, 10, SpringLayout.WEST, pnlBamConvert); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToBed, 10, SpringLayout.EAST, btnBamToBed); - pnlBamConvert.add(btnBamToBed); - - JTextArea txtBamToBedgraph = new JTextArea(); - initializeTextArea(txtBamToBedgraph); - txtBamToBedgraph.setText("Convert BAM file to bedGraph file"); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBedgraph, 10, SpringLayout.SOUTH, txtBamToBed); - sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToBedgraph, -10, SpringLayout.EAST, pnlBamConvert); - pnlBamConvert.add(txtBamToBedgraph); - - JButton btnBamToBedgraph = new JButton("BAM to bedGraph"); - btnBamToBedgraph.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BAMtobedGraphWindow frame = new BAMtobedGraphWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToBedgraph, 0, SpringLayout.NORTH, txtBamToBedgraph); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToBedgraph, 10, SpringLayout.WEST, pnlBamConvert); - sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToBedgraph, 10, SpringLayout.EAST, btnBamToBedgraph); - pnlBamConvert.add(btnBamToBedgraph); - - JPanel pnlFileUtility = new JPanel(); - SpringLayout sl_pnlFileUtility = new SpringLayout(); - pnlFileUtility.setLayout(sl_pnlFileUtility); - tabbedPane.addTab("File Utilities", null, pnlFileUtility, null); - - JTextArea txtMD5 = new JTextArea(); - initializeTextArea(txtMD5); - txtMD5.setText("Calculate MD5 checksum for files"); - sl_pnlFileUtility.putConstraint(SpringLayout.NORTH, txtMD5, 10, SpringLayout.NORTH, pnlFileUtility); - sl_pnlFileUtility.putConstraint(SpringLayout.EAST, txtMD5, -10, SpringLayout.EAST, pnlFileUtility); - pnlFileUtility.add(txtMD5); - - JButton btnMD5 = new JButton("MD5 Checksum"); - btnMD5.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - MD5ChecksumWindow frame = new MD5ChecksumWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlFileUtility.putConstraint(SpringLayout.NORTH, btnMD5, 0, SpringLayout.NORTH, txtMD5); - sl_pnlFileUtility.putConstraint(SpringLayout.WEST, btnMD5, 10, SpringLayout.WEST, pnlFileUtility); - sl_pnlFileUtility.putConstraint(SpringLayout.WEST, txtMD5, 10, SpringLayout.EAST, btnMD5); - pnlFileUtility.add(btnMD5); +import cli.Peak_Calling.GeneTrackCLI; +import cli.Peak_Calling.PeakPairCLI; - JPanel pnlPeakCalling = new JPanel(); - SpringLayout sl_pnlPeakCalling = new SpringLayout(); - pnlPeakCalling.setLayout(sl_pnlPeakCalling); - tabbedPane.addTab("Peak Calling", null, pnlPeakCalling, null); - - JTextArea txtGenetrack = new JTextArea(); - initializeTextArea(txtGenetrack); - txtGenetrack.setText("Genetrack peak-calling algorithm"); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtGenetrack, 10, SpringLayout.NORTH, pnlPeakCalling); - sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtGenetrack, -10, SpringLayout.EAST, pnlPeakCalling); - pnlPeakCalling.add(txtGenetrack); - - JButton btnGenetrack = new JButton("GeneTrack"); - btnGenetrack.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - GeneTrackWindow frame = new GeneTrackWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnGenetrack, 0, SpringLayout.NORTH, txtGenetrack); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnGenetrack, 10, SpringLayout.WEST, pnlPeakCalling); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtGenetrack, 10, SpringLayout.EAST, btnGenetrack); - pnlPeakCalling.add(btnGenetrack); - - JTextArea txtPeakpairing = new JTextArea(); - initializeTextArea(txtPeakpairing); - txtPeakpairing.setText("Peak-pairing algorithm"); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtPeakpairing, 10, SpringLayout.SOUTH, txtGenetrack); - sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtPeakpairing, -10, SpringLayout.EAST, pnlPeakCalling); - pnlPeakCalling.add(txtPeakpairing); - - JButton btnPeakpairing = new JButton("Peak-Pairing"); - btnPeakpairing.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - PeakPairWindow frame = new PeakPairWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - pnlPeakCalling.add(btnPeakpairing); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnPeakpairing, 0, SpringLayout.NORTH, txtPeakpairing); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnPeakpairing, 10, SpringLayout.WEST, pnlPeakCalling); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtPeakpairing, 10, SpringLayout.EAST, btnPeakpairing); - btnPeakpairing.setEnabled(false); - - JTextArea txtReplicateMatch = new JTextArea(); - initializeTextArea(txtReplicateMatch); - txtReplicateMatch.setText("Peak-pair replicate analysis"); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtReplicateMatch, 10, SpringLayout.SOUTH, txtPeakpairing); - sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtReplicateMatch, -10, SpringLayout.EAST, pnlPeakCalling); - pnlPeakCalling.add(txtReplicateMatch); - - JButton btnReplicateMatch = new JButton("Replicate Match"); - sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnReplicateMatch, 0, SpringLayout.NORTH, txtReplicateMatch); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnReplicateMatch, 10, SpringLayout.WEST, pnlPeakCalling); - sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtReplicateMatch, 10, SpringLayout.EAST, btnReplicateMatch); - pnlPeakCalling.add(btnReplicateMatch); - btnReplicateMatch.setEnabled(false); - - JPanel pnlPeakAnalysis = new JPanel(); - SpringLayout sl_pnlPeakAnalysis = new SpringLayout(); - pnlPeakAnalysis.setLayout(sl_pnlPeakAnalysis); - tabbedPane.addTab("Peak Analysis", null, pnlPeakAnalysis, null); - - JTextArea txtBedPeakAlignment = new JTextArea(); - initializeTextArea(txtBedPeakAlignment); - txtBedPeakAlignment.setText("Align BED peaks to Reference BED file creating CDT files for heatmap generation"); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtBedPeakAlignment, 10, SpringLayout.NORTH, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtBedPeakAlignment, -10, SpringLayout.EAST, pnlPeakAnalysis); - pnlPeakAnalysis.add(txtBedPeakAlignment); - - JButton btnBedPeakAlignment = new JButton("Align BED to Reference"); - btnBedPeakAlignment.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BEDPeakAligntoRefWindow frame = new BEDPeakAligntoRefWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnBedPeakAlignment, 0, SpringLayout.NORTH, txtBedPeakAlignment); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnBedPeakAlignment, 10, SpringLayout.WEST, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtBedPeakAlignment, 10, SpringLayout.EAST, btnBedPeakAlignment); - pnlPeakAnalysis.add(btnBedPeakAlignment); - - JTextArea txtBedFilter = new JTextArea(); - initializeTextArea(txtBedFilter); - txtBedFilter.setText("Filter BED file using user-specified exclusion zone using the score column to determine which peak to retain."); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtBedFilter, 10, SpringLayout.SOUTH, txtBedPeakAlignment); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtBedFilter, -10, SpringLayout.EAST, pnlPeakAnalysis); - pnlPeakAnalysis.add(txtBedFilter); - - JButton btnBedFilter = new JButton("Filter BED by Proximity"); - btnBedFilter.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - FilterBEDbyProximityWindow frame = new FilterBEDbyProximityWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnBedFilter, 0, SpringLayout.NORTH, txtBedFilter); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnBedFilter, 10, SpringLayout.WEST, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtBedFilter, 10, SpringLayout.EAST, btnBedFilter); - pnlPeakAnalysis.add(btnBedFilter); - - JTextArea txtGenomicCoordinateTile = new JTextArea(); - initializeTextArea(txtGenomicCoordinateTile); - txtGenomicCoordinateTile.setText("Generate a coordinate file that tiles (non-overlapping) across an entire genome."); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtGenomicCoordinateTile, 10, SpringLayout.SOUTH, txtBedFilter); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtGenomicCoordinateTile, -10, SpringLayout.EAST, pnlPeakAnalysis); - pnlPeakAnalysis.add(txtGenomicCoordinateTile); - - JButton btnGenomicCoordinateTile = new JButton("Genomic Coordinate Tile"); - btnGenomicCoordinateTile.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - TileGenomeWindow frame = new TileGenomeWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnGenomicCoordinateTile, 0, SpringLayout.NORTH, txtGenomicCoordinateTile); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnGenomicCoordinateTile, 10, SpringLayout.WEST, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtGenomicCoordinateTile, 10, SpringLayout.EAST, btnGenomicCoordinateTile); - pnlPeakAnalysis.add(btnGenomicCoordinateTile); - - JTextArea txtRandomCoordinateGeneration = new JTextArea(); - initializeTextArea(txtRandomCoordinateGeneration); - txtRandomCoordinateGeneration.setText("Generate a coordinate file that tiles (non-overlapping) across an entire genome."); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtRandomCoordinateGeneration, 10, SpringLayout.SOUTH, txtGenomicCoordinateTile); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtRandomCoordinateGeneration, -10, SpringLayout.EAST, pnlPeakAnalysis); - pnlPeakAnalysis.add(txtRandomCoordinateGeneration); - - JButton btnRandomCoordinateGeneration = new JButton("Generate Random Coordinate"); - btnRandomCoordinateGeneration.setToolTipText("Generate random BED coordinates based on reference genome."); - btnRandomCoordinateGeneration.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - RandomCoordinateWindow frame = new RandomCoordinateWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnRandomCoordinateGeneration, 0, SpringLayout.NORTH, txtRandomCoordinateGeneration); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnRandomCoordinateGeneration, 10, SpringLayout.WEST, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtRandomCoordinateGeneration, 10, SpringLayout.EAST, btnRandomCoordinateGeneration); - pnlPeakAnalysis.add(btnRandomCoordinateGeneration); - - JTextArea txtOutputSignalDuplication = new JTextArea(); - initializeTextArea(txtOutputSignalDuplication); - txtOutputSignalDuplication.setText("Calculate duplication statistics at user-specified regsions."); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtOutputSignalDuplication, 10, SpringLayout.SOUTH, txtRandomCoordinateGeneration); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtOutputSignalDuplication, -10, SpringLayout.EAST, pnlPeakAnalysis); - pnlPeakAnalysis.add(txtOutputSignalDuplication); - - JButton btnSignalDuplication = new JButton("Signal Duplication"); - btnSignalDuplication.setToolTipText("Output signal duplication statistics"); - btnSignalDuplication.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SignalDuplicationWindow frame = new SignalDuplicationWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnSignalDuplication, 0, SpringLayout.NORTH, txtOutputSignalDuplication); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnSignalDuplication, 10, SpringLayout.WEST, pnlPeakAnalysis); - sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtOutputSignalDuplication, 10, SpringLayout.EAST, btnSignalDuplication); - pnlPeakAnalysis.add(btnSignalDuplication); - - JPanel pnlCoordManip = new JPanel(); - tabbedPane.addTab("Coordinate File Manipulation", null, pnlCoordManip, null); - - JSplitPane splitPaneExpand = new JSplitPane(); - pnlCoordManip.add(splitPaneExpand); - - JButton btnExpandBedFile = new JButton("Expand BED File"); - btnExpandBedFile.setToolTipText("Expand BED file given user-defined criteria"); - btnExpandBedFile.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ExpandBEDWindow frame = new ExpandBEDWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneExpand.setLeftComponent(btnExpandBedFile); - - JButton btnExpandGffFile = new JButton("Expand GFF File"); - btnExpandGffFile.setToolTipText("Expand GFF file given user-defined criteria"); - btnExpandGffFile.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ExpandGFFWindow frame = new ExpandGFFWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneExpand.setRightComponent(btnExpandGffFile); - - JSplitPane splitPaneConvert = new JSplitPane(); - pnlCoordManip.add(splitPaneConvert); - - JButton btnBedToGFF = new JButton("Convert BED to GFF"); - btnBedToGFF.setToolTipText("Convert BED file to GFF file"); - btnBedToGFF.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - BEDtoGFFWindow frame = new BEDtoGFFWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneConvert.setLeftComponent(btnBedToGFF); - - JButton btnGffToBed = new JButton("Convert GFF to BED"); - btnGffToBed.setToolTipText("Convert GFF file to BED file"); - btnGffToBed.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - GFFtoBEDWindow frame = new GFFtoBEDWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneConvert.setRightComponent(btnGffToBed); - - JSplitPane splitPaneSort = new JSplitPane(); - pnlCoordManip.add(splitPaneSort); - - JButton btnBEDSort = new JButton("Sort BED by CDT"); - btnBEDSort.setToolTipText("Sort BED file by CDT file statistics"); - btnBEDSort.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SortBEDWindow frame = new SortBEDWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneSort.setLeftComponent(btnBEDSort); - - JButton btnSortGffFile = new JButton("Sort GFF by CDT"); - btnSortGffFile.setToolTipText("Sort BED file by CDT file statistics"); - btnSortGffFile.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SortGFFWindow frame = new SortGFFWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - splitPaneSort.setRightComponent(btnSortGffFile); - - JPanel pnlReadAnalysis = new JPanel(); - SpringLayout sl_pnlReadAnalysis = new SpringLayout(); - pnlReadAnalysis.setLayout(sl_pnlReadAnalysis); - tabbedPane.addTab("Sequence Read Analysis", null, pnlReadAnalysis, null); - - JTextArea txtTagPileup = new JTextArea(); - initializeTextArea(txtTagPileup); - txtTagPileup.setText("Pileup 5' ends of aligned tags given BED and BAM files according to user-defined parameters"); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtTagPileup, 10, SpringLayout.NORTH, pnlReadAnalysis); - sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtTagPileup, -10, SpringLayout.EAST, pnlReadAnalysis); - pnlReadAnalysis.add(txtTagPileup); - - JButton btnTagPileup = new JButton("Tag Pileup"); - btnTagPileup.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - TagPileupWindow frame = new TagPileupWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnTagPileup, 0, SpringLayout.NORTH, txtTagPileup); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnTagPileup, 10, SpringLayout.WEST, pnlReadAnalysis); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtTagPileup, 10, SpringLayout.EAST, btnTagPileup); - pnlReadAnalysis.add(btnTagPileup); - - JTextArea txtCalculateScalingFactor = new JTextArea(); - initializeTextArea(txtCalculateScalingFactor); - txtCalculateScalingFactor.setText("Calculate scaling factor as either total tag normalization or normalization of ChIP-seq data with control (PMID: 22883957)"); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtCalculateScalingFactor, 10, SpringLayout.SOUTH, txtTagPileup); - sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtCalculateScalingFactor, -10, SpringLayout.EAST, pnlReadAnalysis); - pnlReadAnalysis.add(txtCalculateScalingFactor); - - JButton btnScale = new JButton("Calculate Scaling Factor"); - btnScale.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ScalingFactorWindow frame = new ScalingFactorWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnScale, 0, SpringLayout.NORTH, txtCalculateScalingFactor); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnScale, 10, SpringLayout.WEST, pnlReadAnalysis); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtCalculateScalingFactor, 10, SpringLayout.EAST, btnScale); - pnlReadAnalysis.add(btnScale); - - JTextArea txtApplyScalingFactor = new JTextArea(); - initializeTextArea(txtApplyScalingFactor); - txtApplyScalingFactor.setText("Apply a user-specified scaling factor to tab-delimited matrix data"); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtApplyScalingFactor, 10, SpringLayout.SOUTH, btnScale); - sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtApplyScalingFactor, -10, SpringLayout.EAST, pnlReadAnalysis); - pnlReadAnalysis.add(txtApplyScalingFactor); - - JButton btnScaleMatrixData = new JButton("Scale Matrix Data"); - btnScaleMatrixData.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ScaleMatrixWindow frame = new ScaleMatrixWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnScaleMatrixData, 0, SpringLayout.NORTH, txtApplyScalingFactor); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnScaleMatrixData, 10, SpringLayout.WEST, pnlReadAnalysis); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtApplyScalingFactor, 10, SpringLayout.EAST, btnScaleMatrixData); - pnlReadAnalysis.add(btnScaleMatrixData); - - JTextArea txtAggregateData = new JTextArea(); - initializeTextArea(txtAggregateData); - txtAggregateData.setText("Compile data from tab-delimited file into matrix according to user-specified metric"); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtAggregateData, 10, SpringLayout.SOUTH, txtApplyScalingFactor); - sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtAggregateData, -10, SpringLayout.EAST, pnlReadAnalysis); - pnlReadAnalysis.add(txtAggregateData); - - JButton btnAggregateData = new JButton("Aggregate Data"); - btnAggregateData.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - AggregateDataWindow frame = new AggregateDataWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnAggregateData, 0, SpringLayout.NORTH, txtAggregateData); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnAggregateData, 10, SpringLayout.WEST, pnlReadAnalysis); - sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtAggregateData, 10, SpringLayout.EAST, btnAggregateData); - pnlReadAnalysis.add(btnAggregateData); - - JPanel pnlSeqAnalysis = new JPanel(); - SpringLayout sl_pnlSeqAnalysis = new SpringLayout(); - pnlSeqAnalysis.setLayout(sl_pnlSeqAnalysis); - tabbedPane.addTab("DNA Sequence Analysis", null, pnlSeqAnalysis, null); - - JTextArea txtFASTAExtract = new JTextArea(); - initializeTextArea(txtFASTAExtract); - txtFASTAExtract.setText("Generate FASTA file from indexed Genome FASTA file and BED file. Script will generate FAI index if not present in Genome FASTA folder."); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtFASTAExtract, 10, SpringLayout.NORTH, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtFASTAExtract, -10, SpringLayout.EAST, pnlSeqAnalysis); - pnlSeqAnalysis.add(txtFASTAExtract); - - JButton btnFASTAExtract = new JButton("FASTA from BED"); - btnFASTAExtract.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - FASTAExtractWindow frame = new FASTAExtractWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnFASTAExtract, 0, SpringLayout.NORTH, txtFASTAExtract); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnFASTAExtract, 10, SpringLayout.WEST, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtFASTAExtract, 10, SpringLayout.EAST, btnFASTAExtract); - pnlSeqAnalysis.add(btnFASTAExtract); - - JTextArea txtRandomizeFasta = new JTextArea(); - initializeTextArea(txtRandomizeFasta); - txtRandomizeFasta.setText("Randomize FASTA sequence for each input entry"); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtRandomizeFasta, 10, SpringLayout.SOUTH, txtFASTAExtract); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtRandomizeFasta, -10, SpringLayout.EAST, pnlSeqAnalysis); - pnlSeqAnalysis.add(txtRandomizeFasta); - - JButton btnRandomizeFasta = new JButton("Randomize FASTA"); - btnRandomizeFasta.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - RandomizeFASTAWindow frame = new RandomizeFASTAWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnRandomizeFasta, 0, SpringLayout.NORTH, txtRandomizeFasta); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnRandomizeFasta, 10, SpringLayout.WEST, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtRandomizeFasta, 10, SpringLayout.EAST, btnRandomizeFasta); - pnlSeqAnalysis.add(btnRandomizeFasta); - - JTextArea txtSearchMotif = new JTextArea(); - initializeTextArea(txtSearchMotif); - txtSearchMotif.setText("Search for an IUPAC DNA sequence motif in FASTA files with mismatches allowed"); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtSearchMotif, 10, SpringLayout.SOUTH, txtRandomizeFasta); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtSearchMotif, -10, SpringLayout.EAST, pnlSeqAnalysis); - pnlSeqAnalysis.add(txtSearchMotif); - - JButton btnSearchMotif = new JButton("Search Motif in FASTA"); - btnSearchMotif.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - SearchMotifWindow frame = new SearchMotifWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnSearchMotif, 0, SpringLayout.NORTH, txtSearchMotif); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnSearchMotif, 10, SpringLayout.WEST, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtSearchMotif, 10, SpringLayout.EAST, btnSearchMotif); - pnlSeqAnalysis.add(btnSearchMotif); +import cli.Read_Analysis.AggregateDataCLI; +import cli.Read_Analysis.ScaleMatrixCLI; +import cli.Read_Analysis.ScalingFactorCLI; +import cli.Read_Analysis.SimilarityMatrixCLI; +import cli.Read_Analysis.TagPileupCLI; - JTextArea txtDnaShapeBed = new JTextArea(); - initializeTextArea(txtDnaShapeBed); - txtDnaShapeBed.setText("Calculate intrinsic DNA shape parameters given BED file and Genome FASTA file. Based on Roh's lab DNAshape server data"); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeBed, 10, SpringLayout.SOUTH, txtSearchMotif); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtDnaShapeBed, -10, SpringLayout.EAST, pnlSeqAnalysis); - pnlSeqAnalysis.add(txtDnaShapeBed); - - JButton btnDnaShapeBed = new JButton("DNA Shape from BED"); - btnDnaShapeBed.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - DNAShapefromBEDWindow frame = new DNAShapefromBEDWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnDnaShapeBed, 0, SpringLayout.NORTH, txtDnaShapeBed); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnDnaShapeBed, 10, SpringLayout.WEST, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtDnaShapeBed, 10, SpringLayout.EAST, btnDnaShapeBed); - pnlSeqAnalysis.add(btnDnaShapeBed); - - JTextArea txtDnaShapeFasta = new JTextArea(); - initializeTextArea(txtDnaShapeFasta); - txtDnaShapeFasta.setText("Calculate intrinsic DNA shape parameters given input FASTA files. Based on Roh's lab DNAshape server data"); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeFasta, 10, SpringLayout.SOUTH, txtDnaShapeBed); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtDnaShapeFasta, -10, SpringLayout.EAST, pnlSeqAnalysis); - pnlSeqAnalysis.add(txtDnaShapeFasta); - - JButton btnDnaShapeFasta = new JButton("DNA Shape from FASTA"); - btnDnaShapeFasta.setToolTipText("Calculate intrinsic DNA shape given input FASTA file"); - btnDnaShapeFasta.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - DNAShapefromFASTAWindow frame = new DNAShapefromFASTAWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnDnaShapeFasta, 0, SpringLayout.NORTH, txtDnaShapeFasta); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnDnaShapeFasta, 10, SpringLayout.WEST, pnlSeqAnalysis); - sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtDnaShapeFasta, 10, SpringLayout.EAST, btnDnaShapeFasta); - pnlSeqAnalysis.add(btnDnaShapeFasta); - - JPanel pnlFigure = new JPanel(); - SpringLayout sl_pnlFigure = new SpringLayout(); - pnlFigure.setLayout(sl_pnlFigure); - tabbedPane.addTab("Figure Generation", null, pnlFigure, null); - - JTextArea txtHeatMap = new JTextArea(); - initializeTextArea(txtHeatMap); - txtHeatMap.setText("Generate heat map using CDT files."); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtHeatMap, 10, SpringLayout.NORTH, pnlFigure); - sl_pnlFigure.putConstraint(SpringLayout.EAST, txtHeatMap, -10, SpringLayout.EAST, pnlFigure); - pnlFigure.add(txtHeatMap); - - JButton btnHeatMap = new JButton("Heat Map"); - btnHeatMap.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - HeatMapWindow frame = new HeatMapWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, btnHeatMap, 0, SpringLayout.NORTH, txtHeatMap); - sl_pnlFigure.putConstraint(SpringLayout.WEST, btnHeatMap, 10, SpringLayout.WEST, pnlFigure); - sl_pnlFigure.putConstraint(SpringLayout.WEST, txtHeatMap, 10, SpringLayout.EAST, btnHeatMap); - pnlFigure.add(btnHeatMap); - - JTextArea txtMergeHeatmap = new JTextArea(); - initializeTextArea(txtMergeHeatmap); - txtMergeHeatmap.setText("Merge Sense and Antisense png heatmaps"); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtMergeHeatmap, 10, SpringLayout.SOUTH, txtHeatMap); - sl_pnlFigure.putConstraint(SpringLayout.EAST, txtMergeHeatmap, -10, SpringLayout.EAST, pnlFigure); - pnlFigure.add(txtMergeHeatmap); - - JButton btnMergeHeatmap = new JButton("Merge Heatmaps"); - btnMergeHeatmap.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - MergeHeatMapWindow frame = new MergeHeatMapWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, btnMergeHeatmap, 0, SpringLayout.NORTH, txtMergeHeatmap); - sl_pnlFigure.putConstraint(SpringLayout.WEST, btnMergeHeatmap, 10, SpringLayout.WEST, pnlFigure); - sl_pnlFigure.putConstraint(SpringLayout.WEST, txtMergeHeatmap, 10, SpringLayout.EAST, btnMergeHeatmap); - pnlFigure.add(btnMergeHeatmap); - - JTextArea txtcolorSequencePlot = new JTextArea(); - initializeTextArea(txtcolorSequencePlot); - txtcolorSequencePlot.setText("Generate 4Color sequence plot given FASTA file and user-defined RGB colors"); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtcolorSequencePlot, 10, SpringLayout.SOUTH, txtMergeHeatmap); - sl_pnlFigure.putConstraint(SpringLayout.EAST, txtcolorSequencePlot, -10, SpringLayout.EAST, pnlFigure); - pnlFigure.add(txtcolorSequencePlot); - - JButton btncolorSequencePlot = new JButton("4Color Sequence Plot"); - btncolorSequencePlot.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - FourColorSequenceWindow frame = new FourColorSequenceWindow(); - frame.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - sl_pnlFigure.putConstraint(SpringLayout.NORTH, btncolorSequencePlot, 0, SpringLayout.NORTH, txtcolorSequencePlot); - sl_pnlFigure.putConstraint(SpringLayout.WEST, btncolorSequencePlot, 10, SpringLayout.WEST, pnlFigure); - sl_pnlFigure.putConstraint(SpringLayout.WEST, txtcolorSequencePlot, 10, SpringLayout.EAST, btncolorSequencePlot); - pnlFigure.add(btncolorSequencePlot); +import cli.Sequence_Analysis.DNAShapefromBEDCLI; +import cli.Sequence_Analysis.DNAShapefromFASTACLI; +import cli.Sequence_Analysis.FASTAExtractCLI; +import cli.Sequence_Analysis.RandomizeFASTACLI; +import cli.Sequence_Analysis.SearchMotifCLI; - } + +@Command(name = "script-manager", + subcommands = { + BAM_Format_ConverterCLI.class, + BAM_ManipulationCLI.class, + BAM_StatisticsCLI.class, + Coordinate_ManipulationCLI.class, + Figure_GenerationCLI.class, + File_UtilitiesCLI.class, + Peak_AnalysisCLI.class, + Peak_CallingCLI.class, + Read_AnalysisCLI.class, + Sequence_AnalysisCLI.class + }, + mixinStandardHelpOptions = true, + description = "Choose a tool directory from below to see more command-line tool options.", + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +public class ScriptManager implements Callable { - private void initializeTextArea(JTextArea text) { - text.setWrapStyleWord(true); - text.setEditable(false); - text.setLineWrap(true); + @Override + public Integer call(){ + System.out.println( "Use '-h' or '--help' for command-line usage guide" ); + ScriptManagerGUI gui = new ScriptManagerGUI(); + gui.launchApplication(); + return(0); } - /** - * Create the application. - */ - public ScriptManager() { - initialize(); + public static void main(String[] args) { + CommandLine cmd = new CommandLine( new ScriptManager() ); + int exitCode = cmd.execute(args); +// System.out.println("main:Exit code = " + exitCode); +// System.exit(exitCode); } +} + + +@Command(mixinStandardHelpOptions = true, + exitCodeOnInvalidInput = 1, + exitCodeOnExecutionException = 1) +abstract class SubcommandCLI implements Callable{ - /** - * Launch the application. - */ - public static void main(String[] args) { - try { - UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); - } catch (Throwable e) { - e.printStackTrace(); - } - EventQueue.invokeLater(new Runnable() { - public void run() { - try { - ScriptManager window = new ScriptManager(); - window.frmScriptManager.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); + @Override + public Integer call(){ + CommandLine cmd = new CommandLine( this ); + cmd.usage(System.out); + return(1); } } + + +@Command(name = "bam-format-converter", + subcommands = { + BAMtoBEDCLI.class, + BAMtobedGraphCLI.class, + BAMtoGFFCLI.class, + BAMtoscIDXCLI.class + }, + description = "Includes tools like BAMtoBEDCLI, BAMtobedGraphCLI, BAMtoGFFCLI, and BAMtoscIDXCLI.") +class BAM_Format_ConverterCLI extends SubcommandCLI {} + + +@Command(name = "bam-manipulation", + subcommands = { + BAIIndexerCLI.class, + BAMRemoveDupCLI.class, + FilterforPIPseqCLI.class, + MergeBAMCLI.class, + SortBAMCLI.class + }, + description = "Includes tools like BAIIndexerCLI, BAMRemoveDupCLI, FilterforPIPseqCLI, MergeBAMCLI, and SortBAMCLI.") +class BAM_ManipulationCLI extends SubcommandCLI {} + + +@Command(name = "bam-statistics", + subcommands = { + BAMGenomeCorrelationCLI.class, + PEStatsCLI.class, + SEStatsCLI.class + }, + description = "Includes tools like BAMGenomeCorrelationCLI, PEStatsCLI, and SEStatsCLI.") +class BAM_StatisticsCLI extends SubcommandCLI {} + + +@Command(name = "coordinate-manipulation", + subcommands = { + BEDtoGFFCLI.class, + ExpandBEDCLI.class, + SortBEDCLI.class, + ExpandGFFCLI.class, + GFFtoBEDCLI.class, + SortGFFCLI.class + }, + description = "Includes tools like BEDtoGFFCLI, ExpandBEDCLI, SortBEDCLI, ExpandGFFCLI, GFFtoBEDCLI, and SortGFFCLI.") +class Coordinate_ManipulationCLI extends SubcommandCLI {} + + +@Command(name = "figure-generation", + subcommands = { + CompositePlotCLI.class, + FourColorSequenceCLI.class, + HeatMapCLI.class, + MergeHeatMapCLI.class + }, + description = "Includes tools like FourColorSequenceCLI, HeatMapCLI, and MergeHeatMapCLI.") +class Figure_GenerationCLI extends SubcommandCLI {} + + +@Command(name = "file-utilities", + subcommands = { + MD5ChecksumCLI.class + }, + description = "Includes the tool MD5Checksum.") +class File_UtilitiesCLI extends SubcommandCLI {} + + +@Command(name = "peak-analysis", + subcommands = { + BEDPeakAligntoRefCLI.class, + FilterBEDbyProximityCLI.class, + RandomCoordinateCLI.class, + SignalDuplicationCLI.class, + TileGenomeCLI.class + }, + description = "Includes tools like BEDPeakAligntoRefCLI, FilterBEDbyProximityCLI, RandomCoordinateCLI, SignalDuplicationCLI, and TileGenomeCLI.") +class Peak_AnalysisCLI extends SubcommandCLI {} + + +@Command(name = "peak-calling", + subcommands = { + GeneTrackCLI.class, + PeakPairCLI.class + }, + description = "Includes tools like GeneTrackCLI and PeakPairCLI.") +class Peak_CallingCLI extends SubcommandCLI {} + + +@Command(name = "read-analysis", + subcommands = { + AggregateDataCLI.class, + ScaleMatrixCLI.class, + ScalingFactorCLI.class, + SimilarityMatrixCLI.class, + TagPileupCLI.class + }, + description = "Includes tools like AggregateDataCLI, ScaleMatrixCLI, ScalingFactorCLI, SimilarityMatrixCLI, and TagPileupCLI.") +class Read_AnalysisCLI extends SubcommandCLI {} + + +@Command(name = "sequence-analysis", + subcommands = { + DNAShapefromBEDCLI.class, + DNAShapefromFASTACLI.class, + FASTAExtractCLI.class, + RandomizeFASTACLI.class, + SearchMotifCLI.class + }, + description = "Includes tools like DNAShapefromBEDCLI, DNAShapefromFASTACLI, FASTAExtractCLI, RandomizeFASTACLI, and SearchMotifCLI.") +class Sequence_AnalysisCLI extends SubcommandCLI {} \ No newline at end of file diff --git a/src/main/ScriptManagerGUI.java b/src/main/ScriptManagerGUI.java new file mode 100755 index 000000000..30b8906a6 --- /dev/null +++ b/src/main/ScriptManagerGUI.java @@ -0,0 +1,1239 @@ +package main; + +import java.awt.EventQueue; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +import javax.swing.JFrame; +import javax.swing.JButton; +import javax.swing.SpringLayout; +import javax.swing.UIManager; +import javax.swing.JTabbedPane; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JTextArea; + +import objects.ToolDescriptions; + +import window_interface.BAM_Statistics.PEStatWindow; +import window_interface.BAM_Statistics.SEStatWindow; +import window_interface.BAM_Statistics.BAMGenomeCorrelationWindow; +import window_interface.BAM_Manipulation.BAIIndexerWindow; +import window_interface.BAM_Manipulation.BAMRemoveDupWindow; +import window_interface.BAM_Manipulation.FilterforPIPseqWindow; +import window_interface.BAM_Manipulation.MergeBAMWindow; +import window_interface.BAM_Manipulation.SortBAMWindow; +import window_interface.BAM_Format_Converter.BAMtoBEDWindow; +import window_interface.BAM_Format_Converter.BAMtoGFFWindow; +import window_interface.BAM_Format_Converter.BAMtobedGraphWindow; +import window_interface.BAM_Format_Converter.BAMtoscIDXWindow; +import window_interface.Peak_Analysis.BEDPeakAligntoRefWindow; +import window_interface.Peak_Analysis.FilterBEDbyProximityWindow; +import window_interface.Peak_Analysis.RandomCoordinateWindow; +import window_interface.Peak_Analysis.SignalDuplicationWindow; +import window_interface.Peak_Analysis.TileGenomeWindow; +import window_interface.Peak_Calling.GeneTrackWindow; +import window_interface.Peak_Calling.PeakPairWindow; +import window_interface.Coordinate_Manipulation.BED_Manipulation.BEDtoGFFWindow; +import window_interface.Coordinate_Manipulation.BED_Manipulation.ExpandBEDWindow; +import window_interface.Coordinate_Manipulation.BED_Manipulation.SortBEDWindow; +import window_interface.Coordinate_Manipulation.GFF_Manipulation.ExpandGFFWindow; +import window_interface.Coordinate_Manipulation.GFF_Manipulation.GFFtoBEDWindow; +import window_interface.Coordinate_Manipulation.GFF_Manipulation.SortGFFWindow; +import window_interface.File_Utilities.MD5ChecksumWindow; +import window_interface.Read_Analysis.AggregateDataWindow; +import window_interface.Read_Analysis.ScaleMatrixWindow; +import window_interface.Read_Analysis.ScalingFactorWindow; +import window_interface.Read_Analysis.TagPileupWindow; +import window_interface.Sequence_Analysis.DNAShapefromBEDWindow; +import window_interface.Sequence_Analysis.DNAShapefromFASTAWindow; +import window_interface.Sequence_Analysis.FASTAExtractWindow; +import window_interface.Sequence_Analysis.RandomizeFASTAWindow; +import window_interface.Sequence_Analysis.SearchMotifWindow; +import window_interface.Figure_Generation.FourColorSequenceWindow; +import window_interface.Figure_Generation.HeatMapWindow; +import window_interface.Figure_Generation.MergeHeatMapWindow; + +public class ScriptManagerGUI { + public static final String VERSION = "0.12-dev"; + + private JFrame frmScriptManager; + /** + * Initialize the contents of the frame. + */ + private void initialize() { + frmScriptManager = new JFrame(); + frmScriptManager.setTitle("Script Manager v" + VERSION); + frmScriptManager.setBounds(100, 100, 600, 350); + frmScriptManager.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frmScriptManager.setResizable(false); + SpringLayout springLayout = new SpringLayout(); + frmScriptManager.getContentPane().setLayout(springLayout); + + JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); + springLayout.putConstraint(SpringLayout.NORTH, tabbedPane, 10, SpringLayout.NORTH, frmScriptManager.getContentPane()); + springLayout.putConstraint(SpringLayout.WEST, tabbedPane, 10, SpringLayout.WEST, frmScriptManager.getContentPane()); + springLayout.putConstraint(SpringLayout.SOUTH, tabbedPane, -10, SpringLayout.SOUTH, frmScriptManager.getContentPane()); + springLayout.putConstraint(SpringLayout.EAST, tabbedPane, -10, SpringLayout.EAST, frmScriptManager.getContentPane()); + frmScriptManager.getContentPane().add(tabbedPane); + + // >>>>>>>> BAM_Statistics <<<<<<<< + JPanel pnlStat = new JPanel(); + SpringLayout sl_pnlStat = new SpringLayout(); + pnlStat.setLayout(sl_pnlStat); + tabbedPane.addTab("BAM Statistics", null, pnlStat, null); + + // >SEStats + JTextArea txtOutputAlignmentStatistics = new JTextArea(); + initializeTextArea(txtOutputAlignmentStatistics); + txtOutputAlignmentStatistics.setText(ToolDescriptions.se_stat_description); + sl_pnlStat.putConstraint(SpringLayout.NORTH, txtOutputAlignmentStatistics, 10, SpringLayout.NORTH, pnlStat); + sl_pnlStat.putConstraint(SpringLayout.EAST, txtOutputAlignmentStatistics, -10, SpringLayout.EAST, pnlStat); + pnlStat.add(txtOutputAlignmentStatistics); + + JButton btnBAMStats = new JButton("BAM Statistics"); + btnBAMStats.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SEStatWindow frame = new SEStatWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBAMStats, 0, SpringLayout.NORTH, txtOutputAlignmentStatistics); + sl_pnlStat.putConstraint(SpringLayout.WEST, btnBAMStats, 10, SpringLayout.WEST, pnlStat); + sl_pnlStat.putConstraint(SpringLayout.WEST, txtOutputAlignmentStatistics, 10, SpringLayout.EAST, btnBAMStats); + pnlStat.add(btnBAMStats); + + // >PEStats + JTextArea txtPEStats = new JTextArea(); + initializeTextArea(txtPEStats); + txtPEStats.setText(ToolDescriptions.pe_stat_description); + sl_pnlStat.putConstraint(SpringLayout.NORTH, txtPEStats, 10, SpringLayout.SOUTH, txtOutputAlignmentStatistics); +// sl_pnlStat.putConstraint(SpringLayout.NORTH, txtPEStats, 10, SpringLayout.SOUTH, btnBAMStats); + sl_pnlStat.putConstraint(SpringLayout.EAST, txtPEStats, -10, SpringLayout.EAST, pnlStat); + pnlStat.add(txtPEStats); + + JButton btnPEStats = new JButton("Paired-End Statistics"); + btnPEStats.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + PEStatWindow frame = new PEStatWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlStat.putConstraint(SpringLayout.NORTH, btnPEStats, 0, SpringLayout.NORTH, txtPEStats); + sl_pnlStat.putConstraint(SpringLayout.WEST, btnPEStats, 10, SpringLayout.WEST, pnlStat); + sl_pnlStat.putConstraint(SpringLayout.WEST, txtPEStats, 10, SpringLayout.EAST, btnPEStats); + pnlStat.add(btnPEStats); + + // >BAMCorr + JTextArea txtBamGenomeCorrelation = new JTextArea(); + initializeTextArea(txtBamGenomeCorrelation); + txtBamGenomeCorrelation.setText(ToolDescriptions.bam_correlation_description); + sl_pnlStat.putConstraint(SpringLayout.NORTH, txtBamGenomeCorrelation, 10, SpringLayout.SOUTH, txtPEStats); +// sl_pnlStat.putConstraint(SpringLayout.NORTH, txtBamGenomeCorrelation, 10, SpringLayout.SOUTH, btnPEStats); + sl_pnlStat.putConstraint(SpringLayout.EAST, txtBamGenomeCorrelation, -10, SpringLayout.EAST, pnlStat); + pnlStat.add(txtBamGenomeCorrelation); + + JButton btnBamGenomeCorrelation = new JButton("BAM Genome Correlation"); + btnBamGenomeCorrelation.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMGenomeCorrelationWindow frame = new BAMGenomeCorrelationWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBamGenomeCorrelation, 0, SpringLayout.NORTH, txtBamGenomeCorrelation); + sl_pnlStat.putConstraint(SpringLayout.WEST, btnBamGenomeCorrelation, 10, SpringLayout.WEST, pnlStat); + sl_pnlStat.putConstraint(SpringLayout.WEST, txtBamGenomeCorrelation, 10, SpringLayout.EAST, btnBamGenomeCorrelation); + pnlStat.add(btnBamGenomeCorrelation); + + // >>>>>>>> BAM_Manipulation <<<<<<<< + JPanel pnlBamManip = new JPanel(); + SpringLayout sl_pnlBamManip = new SpringLayout(); + pnlBamManip.setLayout(sl_pnlBamManip); + tabbedPane.addTab("BAM Manipulation", null, pnlBamManip, null); + + // >BAMIndexer + JTextArea txtBAIIndex = new JTextArea(); + initializeTextArea(txtBAIIndex); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBAIIndex, 10, SpringLayout.NORTH, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBAIIndex, -10, SpringLayout.EAST, pnlBamManip); + txtBAIIndex.setText(ToolDescriptions.bam_indexer_description); + pnlBamManip.add(txtBAIIndex); + + JButton btnBaiIndexer = new JButton("BAM-BAI Indexer"); + btnBaiIndexer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAIIndexerWindow frame = new BAIIndexerWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBaiIndexer, 0, SpringLayout.NORTH, txtBAIIndex); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBaiIndexer, 10, SpringLayout.WEST, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBAIIndex, 10, SpringLayout.EAST, btnBaiIndexer); + pnlBamManip.add(btnBaiIndexer); + + // >BAMFileSorter + JTextArea txtBamSort = new JTextArea(); + initializeTextArea(txtBamSort); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamSort, 10, SpringLayout.SOUTH, txtBAIIndex); + sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamSort, -10, SpringLayout.EAST, pnlBamManip); + txtBamSort.setText(ToolDescriptions.sort_bam_description); + pnlBamManip.add(txtBamSort); + + JButton btnBamSort = new JButton("BAM File Sorter"); + btnBamSort.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SortBAMWindow frame = new SortBAMWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamSort, 0, SpringLayout.NORTH, txtBamSort); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamSort, 10, SpringLayout.WEST, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamSort, 10, SpringLayout.EAST, btnBamSort); + pnlBamManip.add(btnBamSort); + + // >BAMRemoveDup + JTextArea txtBamRemoveDuplicates = new JTextArea(); + initializeTextArea(txtBamRemoveDuplicates); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamRemoveDuplicates, 10, SpringLayout.SOUTH, txtBamSort); + sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamRemoveDuplicates, -10, SpringLayout.EAST, pnlBamManip); + txtBamRemoveDuplicates.setText(ToolDescriptions.remove_duplicates_description); + pnlBamManip.add(txtBamRemoveDuplicates); + + JButton btnBamRemoveDuplicates = new JButton("BAM Remove Duplicates"); + btnBamRemoveDuplicates.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMRemoveDupWindow frame = new BAMRemoveDupWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamRemoveDuplicates, 0, SpringLayout.NORTH, txtBamRemoveDuplicates); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamRemoveDuplicates, 10, SpringLayout.WEST, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamRemoveDuplicates, 10, SpringLayout.EAST, btnBamRemoveDuplicates); + pnlBamManip.add(btnBamRemoveDuplicates); + + // >BAMReplicateMerge + JTextArea txtBamReplicateMerge = new JTextArea(); + initializeTextArea(txtBamReplicateMerge); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtBamReplicateMerge, 10, SpringLayout.SOUTH, txtBamRemoveDuplicates); + sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtBamReplicateMerge, -10, SpringLayout.EAST, pnlBamManip); + txtBamReplicateMerge.setText(ToolDescriptions.merge_bam_description); + pnlBamManip.add(txtBamReplicateMerge); + + JButton btnBamReplicateMerge = new JButton("BAM Replicate Merge"); + btnBamReplicateMerge.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MergeBAMWindow frame = new MergeBAMWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnBamReplicateMerge, 0, SpringLayout.NORTH, txtBamReplicateMerge); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnBamReplicateMerge, 10, SpringLayout.WEST, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtBamReplicateMerge, 10, SpringLayout.EAST, btnBamReplicateMerge); + pnlBamManip.add(btnBamReplicateMerge); + + // >FilterPIPseq + JTextArea txtFilterForPIPseq = new JTextArea(); + initializeTextArea(txtFilterForPIPseq); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, txtFilterForPIPseq, 10, SpringLayout.SOUTH, txtBamReplicateMerge); + sl_pnlBamManip.putConstraint(SpringLayout.EAST, txtFilterForPIPseq, -10, SpringLayout.EAST, pnlBamManip); + txtFilterForPIPseq.setText(ToolDescriptions.filter_pip_seq_description); + pnlBamManip.add(txtFilterForPIPseq); + + JButton btnFilterForPIPseq = new JButton("Filter for PIP-seq"); + btnFilterForPIPseq.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + FilterforPIPseqWindow frame = new FilterforPIPseqWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamManip.putConstraint(SpringLayout.NORTH, btnFilterForPIPseq, 0, SpringLayout.NORTH, txtFilterForPIPseq); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, btnFilterForPIPseq, 10, SpringLayout.WEST, pnlBamManip); + sl_pnlBamManip.putConstraint(SpringLayout.WEST, txtFilterForPIPseq, 10, SpringLayout.EAST, btnFilterForPIPseq); + pnlBamManip.add(btnFilterForPIPseq); + + // >>>>>>>> BAM_Format_Converter <<<<<<<< + JPanel pnlBamConvert = new JPanel(); + SpringLayout sl_pnlBamConvert = new SpringLayout(); + pnlBamConvert.setLayout(sl_pnlBamConvert); + tabbedPane.addTab("BAM Format Converter", null, pnlBamConvert, null); + + // >BAMtoscIdx + JTextArea txtBamToscIDX = new JTextArea(); + initializeTextArea(txtBamToscIDX); + txtBamToscIDX.setText(ToolDescriptions.bam_to_scidx_description); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToscIDX, 10, SpringLayout.NORTH, pnlBamConvert); + sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToscIDX, -10, SpringLayout.EAST, pnlBamConvert); + pnlBamConvert.add(txtBamToscIDX); + + JButton btnBamToscIDX = new JButton("BAM to scIDX"); + btnBamToscIDX.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMtoscIDXWindow frame = new BAMtoscIDXWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToscIDX, 0, SpringLayout.NORTH, txtBamToscIDX); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToscIDX, 10, SpringLayout.WEST, pnlBamConvert); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToscIDX, 10, SpringLayout.EAST, btnBamToscIDX); + pnlBamConvert.add(btnBamToscIDX); + + // >BAMtoGFF + JTextArea txtBamToGFF = new JTextArea(); + initializeTextArea(txtBamToGFF); + txtBamToGFF.setText(ToolDescriptions.bam_to_gff_description); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToGFF, 10, SpringLayout.SOUTH, txtBamToscIDX); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToGFF, 10, SpringLayout.SOUTH, btnBamToscIDX); + sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToGFF, -10, SpringLayout.EAST, pnlBamConvert); + pnlBamConvert.add(txtBamToGFF); + + JButton btnBamToGff = new JButton("BAM to GFF"); + btnBamToGff.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMtoGFFWindow frame = new BAMtoGFFWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToGff, 0, SpringLayout.NORTH, txtBamToGFF); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToGff, 10, SpringLayout.WEST, pnlBamConvert); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToGFF, 10, SpringLayout.EAST, btnBamToGff); + pnlBamConvert.add(btnBamToGff); + + // >BAMtoBED + JTextArea txtBamToBed = new JTextArea(); + initializeTextArea(txtBamToBed); + txtBamToBed.setText(ToolDescriptions.bam_to_bed_description); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBed, 10, SpringLayout.SOUTH, txtBamToGFF); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBed, 10, SpringLayout.SOUTH, btnBamToGff); + sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToBed, -10, SpringLayout.EAST, pnlBamConvert); + pnlBamConvert.add(txtBamToBed); + + JButton btnBamToBed = new JButton("BAM to BED"); + btnBamToBed.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMtoBEDWindow frame = new BAMtoBEDWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToBed, 0, SpringLayout.NORTH, txtBamToBed); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToBed, 10, SpringLayout.WEST, pnlBamConvert); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToBed, 10, SpringLayout.EAST, btnBamToBed); + pnlBamConvert.add(btnBamToBed); + + // >BAMtobedGraph + JTextArea txtBamToBedgraph = new JTextArea(); + initializeTextArea(txtBamToBedgraph); + txtBamToBedgraph.setText(ToolDescriptions.bam_to_bedgraph_description); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBedgraph, 10, SpringLayout.SOUTH, txtBamToBed); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, txtBamToBedgraph, 10, SpringLayout.SOUTH, btnBamToBed); + sl_pnlBamConvert.putConstraint(SpringLayout.EAST, txtBamToBedgraph, -10, SpringLayout.EAST, pnlBamConvert); + pnlBamConvert.add(txtBamToBedgraph); + + JButton btnBamToBedgraph = new JButton("BAM to bedGraph"); + btnBamToBedgraph.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BAMtobedGraphWindow frame = new BAMtobedGraphWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlBamConvert.putConstraint(SpringLayout.NORTH, btnBamToBedgraph, 0, SpringLayout.NORTH, txtBamToBedgraph); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, btnBamToBedgraph, 10, SpringLayout.WEST, pnlBamConvert); + sl_pnlBamConvert.putConstraint(SpringLayout.WEST, txtBamToBedgraph, 10, SpringLayout.EAST, btnBamToBedgraph); + pnlBamConvert.add(btnBamToBedgraph); + + // >>>>>>>> File_Utilities <<<<<<<< + JPanel pnlFileUtility = new JPanel(); + SpringLayout sl_pnlFileUtility = new SpringLayout(); + pnlFileUtility.setLayout(sl_pnlFileUtility); + tabbedPane.addTab("File Utilities", null, pnlFileUtility, null); + + // >MD5checksum + JTextArea txtMD5 = new JTextArea(); + initializeTextArea(txtMD5); + txtMD5.setText(ToolDescriptions.md5checksum_description); + sl_pnlFileUtility.putConstraint(SpringLayout.NORTH, txtMD5, 10, SpringLayout.NORTH, pnlFileUtility); + sl_pnlFileUtility.putConstraint(SpringLayout.EAST, txtMD5, -10, SpringLayout.EAST, pnlFileUtility); + pnlFileUtility.add(txtMD5); + + JButton btnMD5 = new JButton("MD5 Checksum"); + btnMD5.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MD5ChecksumWindow frame = new MD5ChecksumWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlFileUtility.putConstraint(SpringLayout.NORTH, btnMD5, 0, SpringLayout.NORTH, txtMD5); + sl_pnlFileUtility.putConstraint(SpringLayout.WEST, btnMD5, 10, SpringLayout.WEST, pnlFileUtility); + sl_pnlFileUtility.putConstraint(SpringLayout.WEST, txtMD5, 10, SpringLayout.EAST, btnMD5); + pnlFileUtility.add(btnMD5); + + // >>>>>>>> Peak_Calling <<<<<<<< + JPanel pnlPeakCalling = new JPanel(); + SpringLayout sl_pnlPeakCalling = new SpringLayout(); + pnlPeakCalling.setLayout(sl_pnlPeakCalling); + tabbedPane.addTab("Peak Calling", null, pnlPeakCalling, null); + + // >GeneTrack + JTextArea txtGenetrack = new JTextArea(); + initializeTextArea(txtGenetrack); + txtGenetrack.setText(ToolDescriptions.gene_track_description); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtGenetrack, 10, SpringLayout.NORTH, pnlPeakCalling); + sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtGenetrack, -10, SpringLayout.EAST, pnlPeakCalling); + pnlPeakCalling.add(txtGenetrack); + + JButton btnGenetrack = new JButton("GeneTrack"); + btnGenetrack.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + GeneTrackWindow frame = new GeneTrackWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnGenetrack, 0, SpringLayout.NORTH, txtGenetrack); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnGenetrack, 10, SpringLayout.WEST, pnlPeakCalling); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtGenetrack, 10, SpringLayout.EAST, btnGenetrack); + pnlPeakCalling.add(btnGenetrack); + + // >PeakPairing + JTextArea txtPeakpairing = new JTextArea(); + initializeTextArea(txtPeakpairing); + txtPeakpairing.setText(ToolDescriptions.peak_pairing_description); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtPeakpairing, 10, SpringLayout.SOUTH, txtGenetrack); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtPeakpairing, 10, SpringLayout.SOUTH, btnGenetrack); + sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtPeakpairing, -10, SpringLayout.EAST, pnlPeakCalling); + pnlPeakCalling.add(txtPeakpairing); + + JButton btnPeakpairing = new JButton("Peak-Pairing"); + btnPeakpairing.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + PeakPairWindow frame = new PeakPairWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + pnlPeakCalling.add(btnPeakpairing); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnPeakpairing, 0, SpringLayout.NORTH, txtPeakpairing); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnPeakpairing, 10, SpringLayout.WEST, pnlPeakCalling); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtPeakpairing, 10, SpringLayout.EAST, btnPeakpairing); + btnPeakpairing.setEnabled(false); + + // >ReplicateMatching + JTextArea txtReplicateMatch = new JTextArea(); + initializeTextArea(txtReplicateMatch); + txtReplicateMatch.setText(ToolDescriptions.replicate_match_description); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtReplicateMatch, 10, SpringLayout.SOUTH, txtPeakpairing); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, txtReplicateMatch, 10, SpringLayout.SOUTH, btnPeakpairing); + sl_pnlPeakCalling.putConstraint(SpringLayout.EAST, txtReplicateMatch, -10, SpringLayout.EAST, pnlPeakCalling); + pnlPeakCalling.add(txtReplicateMatch); + + JButton btnReplicateMatch = new JButton("Replicate Match"); + sl_pnlPeakCalling.putConstraint(SpringLayout.NORTH, btnReplicateMatch, 0, SpringLayout.NORTH, txtReplicateMatch); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, btnReplicateMatch, 10, SpringLayout.WEST, pnlPeakCalling); + sl_pnlPeakCalling.putConstraint(SpringLayout.WEST, txtReplicateMatch, 10, SpringLayout.EAST, btnReplicateMatch); + pnlPeakCalling.add(btnReplicateMatch); + btnReplicateMatch.setEnabled(false); + + // >>>>>>>> Peak_Analysis <<<<<<<< + JPanel pnlPeakAnalysis = new JPanel(); + SpringLayout sl_pnlPeakAnalysis = new SpringLayout(); + pnlPeakAnalysis.setLayout(sl_pnlPeakAnalysis); + tabbedPane.addTab("Peak Analysis", null, pnlPeakAnalysis, null); + + // >PeakAlign + JTextArea txtBedPeakAlignment = new JTextArea(); + initializeTextArea(txtBedPeakAlignment); + txtBedPeakAlignment.setText(ToolDescriptions.peak_align_ref_description); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtBedPeakAlignment, 10, SpringLayout.NORTH, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtBedPeakAlignment, -10, SpringLayout.EAST, pnlPeakAnalysis); + pnlPeakAnalysis.add(txtBedPeakAlignment); + + JButton btnBedPeakAlignment = new JButton("Align BED to Reference"); + btnBedPeakAlignment.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BEDPeakAligntoRefWindow frame = new BEDPeakAligntoRefWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnBedPeakAlignment, 0, SpringLayout.NORTH, txtBedPeakAlignment); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnBedPeakAlignment, 10, SpringLayout.WEST, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtBedPeakAlignment, 10, SpringLayout.EAST, btnBedPeakAlignment); + pnlPeakAnalysis.add(btnBedPeakAlignment); + + // >FilterBED + JTextArea txtBedFilter = new JTextArea(); + initializeTextArea(txtBedFilter); + txtBedFilter.setText(ToolDescriptions.filter_bed_description); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtBedFilter, 10, SpringLayout.SOUTH, txtBedPeakAlignment); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtBedFilter, -10, SpringLayout.EAST, pnlPeakAnalysis); + pnlPeakAnalysis.add(txtBedFilter); + + JButton btnBedFilter = new JButton("Filter BED by Proximity"); + btnBedFilter.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + FilterBEDbyProximityWindow frame = new FilterBEDbyProximityWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnBedFilter, 0, SpringLayout.NORTH, txtBedFilter); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnBedFilter, 10, SpringLayout.WEST, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtBedFilter, 10, SpringLayout.EAST, btnBedFilter); + pnlPeakAnalysis.add(btnBedFilter); + + // >TileGenome + JTextArea txtGenomicCoordinateTile = new JTextArea(); + initializeTextArea(txtGenomicCoordinateTile); + txtGenomicCoordinateTile.setText(ToolDescriptions.tile_genome_description); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtGenomicCoordinateTile, 10, SpringLayout.SOUTH, txtBedFilter); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtGenomicCoordinateTile, -10, SpringLayout.EAST, pnlPeakAnalysis); + pnlPeakAnalysis.add(txtGenomicCoordinateTile); + + JButton btnGenomicCoordinateTile = new JButton("Genomic Coordinate Tile"); + btnGenomicCoordinateTile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + TileGenomeWindow frame = new TileGenomeWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnGenomicCoordinateTile, 0, SpringLayout.NORTH, txtGenomicCoordinateTile); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnGenomicCoordinateTile, 10, SpringLayout.WEST, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtGenomicCoordinateTile, 10, SpringLayout.EAST, btnGenomicCoordinateTile); + pnlPeakAnalysis.add(btnGenomicCoordinateTile); + + // >RandCoord + JTextArea txtRandomCoordinateGeneration = new JTextArea(); + initializeTextArea(txtRandomCoordinateGeneration); + txtRandomCoordinateGeneration.setText(ToolDescriptions.rand_coord_description); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtRandomCoordinateGeneration, 10, SpringLayout.SOUTH, txtGenomicCoordinateTile); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtRandomCoordinateGeneration, -10, SpringLayout.EAST, pnlPeakAnalysis); + pnlPeakAnalysis.add(txtRandomCoordinateGeneration); + + JButton btnRandomCoordinateGeneration = new JButton("Generate Random Coordinate"); + btnRandomCoordinateGeneration.setToolTipText("Generate random BED coordinates based on reference genome."); + btnRandomCoordinateGeneration.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + RandomCoordinateWindow frame = new RandomCoordinateWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnRandomCoordinateGeneration, 0, SpringLayout.NORTH, txtRandomCoordinateGeneration); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnRandomCoordinateGeneration, 10, SpringLayout.WEST, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtRandomCoordinateGeneration, 10, SpringLayout.EAST, btnRandomCoordinateGeneration); + pnlPeakAnalysis.add(btnRandomCoordinateGeneration); + + // >Signal_Duplication + JTextArea txtOutputSignalDuplication = new JTextArea(); + initializeTextArea(txtOutputSignalDuplication); + txtOutputSignalDuplication.setText(ToolDescriptions.signal_dup_description); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, txtOutputSignalDuplication, 10, SpringLayout.SOUTH, txtRandomCoordinateGeneration); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.EAST, txtOutputSignalDuplication, -10, SpringLayout.EAST, pnlPeakAnalysis); + pnlPeakAnalysis.add(txtOutputSignalDuplication); + + JButton btnSignalDuplication = new JButton("Signal Duplication"); + btnSignalDuplication.setToolTipText("Output signal duplication statistics"); + btnSignalDuplication.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SignalDuplicationWindow frame = new SignalDuplicationWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.NORTH, btnSignalDuplication, 0, SpringLayout.NORTH, txtOutputSignalDuplication); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, btnSignalDuplication, 10, SpringLayout.WEST, pnlPeakAnalysis); + sl_pnlPeakAnalysis.putConstraint(SpringLayout.WEST, txtOutputSignalDuplication, 10, SpringLayout.EAST, btnSignalDuplication); + pnlPeakAnalysis.add(btnSignalDuplication); + + // >>>>>>>> Coordinate_Manipulation <<<<<<<< + JPanel pnlCoordManip = new JPanel(); + tabbedPane.addTab("Coordinate File Manipulation", null, pnlCoordManip, null); + + JSplitPane splitPaneExpand = new JSplitPane(); + pnlCoordManip.add(splitPaneExpand); + + // >ExpandBED + JButton btnExpandBedFile = new JButton("Expand BED File"); + btnExpandBedFile.setToolTipText(ToolDescriptions.expand_bed_description); + btnExpandBedFile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ExpandBEDWindow frame = new ExpandBEDWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneExpand.setLeftComponent(btnExpandBedFile); + + // >ExpandGFF + JButton btnExpandGffFile = new JButton("Expand GFF File"); + btnExpandGffFile.setToolTipText(ToolDescriptions.expand_gff_description); + btnExpandGffFile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ExpandGFFWindow frame = new ExpandGFFWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneExpand.setRightComponent(btnExpandGffFile); + + JSplitPane splitPaneConvert = new JSplitPane(); + pnlCoordManip.add(splitPaneConvert); + + // >BEDtoGFF + JButton btnBedToGFF = new JButton("Convert BED to GFF"); + btnBedToGFF.setToolTipText(ToolDescriptions.bed_to_gff_description); + btnBedToGFF.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + BEDtoGFFWindow frame = new BEDtoGFFWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneConvert.setLeftComponent(btnBedToGFF); + + // >GFFtoBED + JButton btnGffToBed = new JButton("Convert GFF to BED"); + btnGffToBed.setToolTipText(ToolDescriptions.gff_to_bed_description); + btnGffToBed.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + GFFtoBEDWindow frame = new GFFtoBEDWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneConvert.setRightComponent(btnGffToBed); + + JSplitPane splitPaneSort = new JSplitPane(); + pnlCoordManip.add(splitPaneSort); + + // >SortBED + JButton btnBEDSort = new JButton("Sort BED by CDT"); + btnBEDSort.setToolTipText(ToolDescriptions.sort_bed_description); + btnBEDSort.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SortBEDWindow frame = new SortBEDWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneSort.setLeftComponent(btnBEDSort); + + // >SortGFF + JButton btnSortGffFile = new JButton("Sort GFF by CDT"); + btnSortGffFile.setToolTipText(ToolDescriptions.sort_gff_description); + btnSortGffFile.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SortGFFWindow frame = new SortGFFWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + splitPaneSort.setRightComponent(btnSortGffFile); + + // >>>>>>>> Read_Analysis <<<<<<<< + JPanel pnlReadAnalysis = new JPanel(); + SpringLayout sl_pnlReadAnalysis = new SpringLayout(); + pnlReadAnalysis.setLayout(sl_pnlReadAnalysis); + tabbedPane.addTab("Sequence Read Analysis", null, pnlReadAnalysis, null); + + // >TagPileup + JTextArea txtTagPileup = new JTextArea(); + initializeTextArea(txtTagPileup); + txtTagPileup.setText(ToolDescriptions.tag_pileup_description); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtTagPileup, 10, SpringLayout.NORTH, pnlReadAnalysis); + sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtTagPileup, -10, SpringLayout.EAST, pnlReadAnalysis); + pnlReadAnalysis.add(txtTagPileup); + + JButton btnTagPileup = new JButton("Tag Pileup"); + btnTagPileup.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + TagPileupWindow frame = new TagPileupWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnTagPileup, 0, SpringLayout.NORTH, txtTagPileup); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnTagPileup, 10, SpringLayout.WEST, pnlReadAnalysis); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtTagPileup, 10, SpringLayout.EAST, btnTagPileup); + pnlReadAnalysis.add(btnTagPileup); + + // >ScalingFactor + JTextArea txtCalculateScalingFactor = new JTextArea(); + initializeTextArea(txtCalculateScalingFactor); + txtCalculateScalingFactor.setText(ToolDescriptions.scaling_factor_description); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtCalculateScalingFactor, 10, SpringLayout.SOUTH, txtTagPileup); +// sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtCalculateScalingFactor, 10, SpringLayout.SOUTH, btnTagPileup); + sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtCalculateScalingFactor, -10, SpringLayout.EAST, pnlReadAnalysis); + pnlReadAnalysis.add(txtCalculateScalingFactor); + + JButton btnScale = new JButton("Calculate Scaling Factor"); + btnScale.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ScalingFactorWindow frame = new ScalingFactorWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnScale, 0, SpringLayout.NORTH, txtCalculateScalingFactor); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnScale, 10, SpringLayout.WEST, pnlReadAnalysis); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtCalculateScalingFactor, 10, SpringLayout.EAST, btnScale); + pnlReadAnalysis.add(btnScale); + + // >ScaleMatrix + JTextArea txtApplyScalingFactor = new JTextArea(); + initializeTextArea(txtApplyScalingFactor); + txtApplyScalingFactor.setText(ToolDescriptions.scale_matrix_description); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtApplyScalingFactor, 10, SpringLayout.SOUTH, txtCalculateScalingFactor); +// sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtApplyScalingFactor, 10, SpringLayout.SOUTH, btnScale); + sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtApplyScalingFactor, -10, SpringLayout.EAST, pnlReadAnalysis); + pnlReadAnalysis.add(txtApplyScalingFactor); + + JButton btnScaleMatrixData = new JButton("Scale Matrix Data"); + btnScaleMatrixData.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ScaleMatrixWindow frame = new ScaleMatrixWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnScaleMatrixData, 0, SpringLayout.NORTH, txtApplyScalingFactor); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnScaleMatrixData, 10, SpringLayout.WEST, pnlReadAnalysis); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtApplyScalingFactor, 10, SpringLayout.EAST, btnScaleMatrixData); + pnlReadAnalysis.add(btnScaleMatrixData); + + // >AggregateData + JTextArea txtAggregateData = new JTextArea(); + initializeTextArea(txtAggregateData); + txtAggregateData.setText(ToolDescriptions.aggregate_data_description); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtAggregateData, 10, SpringLayout.SOUTH, txtApplyScalingFactor); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, txtAggregateData, 10, SpringLayout.SOUTH, btnScaleMatrixData); + sl_pnlReadAnalysis.putConstraint(SpringLayout.EAST, txtAggregateData, -10, SpringLayout.EAST, pnlReadAnalysis); + pnlReadAnalysis.add(txtAggregateData); + + JButton btnAggregateData = new JButton("Aggregate Data"); + btnAggregateData.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + AggregateDataWindow frame = new AggregateDataWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlReadAnalysis.putConstraint(SpringLayout.NORTH, btnAggregateData, 0, SpringLayout.NORTH, txtAggregateData); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, btnAggregateData, 10, SpringLayout.WEST, pnlReadAnalysis); + sl_pnlReadAnalysis.putConstraint(SpringLayout.WEST, txtAggregateData, 10, SpringLayout.EAST, btnAggregateData); + pnlReadAnalysis.add(btnAggregateData); + + // >>>>>>>> Sequence_Analysis <<<<<<<< + JPanel pnlSeqAnalysis = new JPanel(); + SpringLayout sl_pnlSeqAnalysis = new SpringLayout(); + pnlSeqAnalysis.setLayout(sl_pnlSeqAnalysis); + tabbedPane.addTab("DNA Sequence Analysis", null, pnlSeqAnalysis, null); + + // >FASTAExtract + JTextArea txtFASTAExtract = new JTextArea(); + initializeTextArea(txtFASTAExtract); + txtFASTAExtract.setText(ToolDescriptions.fasta_extract_description); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtFASTAExtract, 10, SpringLayout.NORTH, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtFASTAExtract, -10, SpringLayout.EAST, pnlSeqAnalysis); + pnlSeqAnalysis.add(txtFASTAExtract); + + JButton btnFASTAExtract = new JButton("FASTA from BED"); + btnFASTAExtract.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + FASTAExtractWindow frame = new FASTAExtractWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnFASTAExtract, 0, SpringLayout.NORTH, txtFASTAExtract); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnFASTAExtract, 10, SpringLayout.WEST, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtFASTAExtract, 10, SpringLayout.EAST, btnFASTAExtract); + pnlSeqAnalysis.add(btnFASTAExtract); + + // >RandomizeFASTA + JTextArea txtRandomizeFasta = new JTextArea(); + initializeTextArea(txtRandomizeFasta); + txtRandomizeFasta.setText(ToolDescriptions.randomize_fasta_description); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtRandomizeFasta, 10, SpringLayout.SOUTH, txtFASTAExtract); +// sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtRandomizeFasta, 10, SpringLayout.SOUTH, btnFASTAExtract); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtRandomizeFasta, -10, SpringLayout.EAST, pnlSeqAnalysis); + pnlSeqAnalysis.add(txtRandomizeFasta); + + JButton btnRandomizeFasta = new JButton("Randomize FASTA"); + btnRandomizeFasta.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + RandomizeFASTAWindow frame = new RandomizeFASTAWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnRandomizeFasta, 0, SpringLayout.NORTH, txtRandomizeFasta); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnRandomizeFasta, 10, SpringLayout.WEST, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtRandomizeFasta, 10, SpringLayout.EAST, btnRandomizeFasta); + pnlSeqAnalysis.add(btnRandomizeFasta); + + // >SearchMotif + JTextArea txtSearchMotif = new JTextArea(); + initializeTextArea(txtSearchMotif); + txtSearchMotif.setText(ToolDescriptions.search_motif_description); +// sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtSearchMotif, 10, SpringLayout.SOUTH, txtRandomizeFasta); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtSearchMotif, 10, SpringLayout.SOUTH, btnRandomizeFasta); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtSearchMotif, -10, SpringLayout.EAST, pnlSeqAnalysis); + pnlSeqAnalysis.add(txtSearchMotif); + + JButton btnSearchMotif = new JButton("Search Motif in FASTA"); + btnSearchMotif.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + SearchMotifWindow frame = new SearchMotifWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnSearchMotif, 0, SpringLayout.NORTH, txtSearchMotif); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnSearchMotif, 10, SpringLayout.WEST, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtSearchMotif, 10, SpringLayout.EAST, btnSearchMotif); + pnlSeqAnalysis.add(btnSearchMotif); + + // >DNAShapeFromBED + JTextArea txtDnaShapeBed = new JTextArea(); + initializeTextArea(txtDnaShapeBed); + txtDnaShapeBed.setText(ToolDescriptions.dna_shape_from_bed_description); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeBed, 10, SpringLayout.SOUTH, txtSearchMotif); +// sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeBed, 10, SpringLayout.SOUTH, btnSearchMotif); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtDnaShapeBed, -10, SpringLayout.EAST, pnlSeqAnalysis); + pnlSeqAnalysis.add(txtDnaShapeBed); + + JButton btnDnaShapeBed = new JButton("DNA Shape from BED"); + btnDnaShapeBed.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + DNAShapefromBEDWindow frame = new DNAShapefromBEDWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnDnaShapeBed, 0, SpringLayout.NORTH, txtDnaShapeBed); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnDnaShapeBed, 10, SpringLayout.WEST, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtDnaShapeBed, 10, SpringLayout.EAST, btnDnaShapeBed); + pnlSeqAnalysis.add(btnDnaShapeBed); + + // >DNAShapeFromFASTA + JTextArea txtDnaShapeFasta = new JTextArea(); + initializeTextArea(txtDnaShapeFasta); + txtDnaShapeFasta.setText(ToolDescriptions.dna_shape_from_fasta_description); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeFasta, 10, SpringLayout.SOUTH, txtDnaShapeBed); +// sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, txtDnaShapeFasta, 10, SpringLayout.SOUTH, btnDnaShapeBed); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.EAST, txtDnaShapeFasta, -10, SpringLayout.EAST, pnlSeqAnalysis); + pnlSeqAnalysis.add(txtDnaShapeFasta); + + JButton btnDnaShapeFasta = new JButton("DNA Shape from FASTA"); + btnDnaShapeFasta.setToolTipText("Calculate intrinsic DNA shape given input FASTA file"); + btnDnaShapeFasta.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + DNAShapefromFASTAWindow frame = new DNAShapefromFASTAWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.NORTH, btnDnaShapeFasta, 0, SpringLayout.NORTH, txtDnaShapeFasta); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, btnDnaShapeFasta, 10, SpringLayout.WEST, pnlSeqAnalysis); + sl_pnlSeqAnalysis.putConstraint(SpringLayout.WEST, txtDnaShapeFasta, 10, SpringLayout.EAST, btnDnaShapeFasta); + pnlSeqAnalysis.add(btnDnaShapeFasta); + + // >>>>>>>> Figure_Generation <<<<<<<< + JPanel pnlFigure = new JPanel(); + SpringLayout sl_pnlFigure = new SpringLayout(); + pnlFigure.setLayout(sl_pnlFigure); + tabbedPane.addTab("Figure Generation", null, pnlFigure, null); + + // >HeatMap + JTextArea txtHeatMap = new JTextArea(); + initializeTextArea(txtHeatMap); + txtHeatMap.setText(ToolDescriptions.heatmap_description); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtHeatMap, 10, SpringLayout.NORTH, pnlFigure); + sl_pnlFigure.putConstraint(SpringLayout.EAST, txtHeatMap, -10, SpringLayout.EAST, pnlFigure); + pnlFigure.add(txtHeatMap); + + JButton btnHeatMap = new JButton("Heat Map"); + btnHeatMap.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + HeatMapWindow frame = new HeatMapWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, btnHeatMap, 0, SpringLayout.NORTH, txtHeatMap); + sl_pnlFigure.putConstraint(SpringLayout.WEST, btnHeatMap, 10, SpringLayout.WEST, pnlFigure); + sl_pnlFigure.putConstraint(SpringLayout.WEST, txtHeatMap, 10, SpringLayout.EAST, btnHeatMap); + pnlFigure.add(btnHeatMap); + + // >MergeHeatMap + JTextArea txtMergeHeatmap = new JTextArea(); + initializeTextArea(txtMergeHeatmap); + txtMergeHeatmap.setText(ToolDescriptions.merge_heatmap_description); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtMergeHeatmap, 10, SpringLayout.SOUTH, txtHeatMap); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtMergeHeatmap, 10, SpringLayout.SOUTH, btnHeatMap); + sl_pnlFigure.putConstraint(SpringLayout.EAST, txtMergeHeatmap, -10, SpringLayout.EAST, pnlFigure); + pnlFigure.add(txtMergeHeatmap); + + JButton btnMergeHeatmap = new JButton("Merge Heatmaps"); + btnMergeHeatmap.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MergeHeatMapWindow frame = new MergeHeatMapWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, btnMergeHeatmap, 0, SpringLayout.NORTH, txtMergeHeatmap); + sl_pnlFigure.putConstraint(SpringLayout.WEST, btnMergeHeatmap, 10, SpringLayout.WEST, pnlFigure); + sl_pnlFigure.putConstraint(SpringLayout.WEST, txtMergeHeatmap, 10, SpringLayout.EAST, btnMergeHeatmap); + pnlFigure.add(btnMergeHeatmap); + + // >FourColorPlot + JTextArea txtcolorSequencePlot = new JTextArea(); + initializeTextArea(txtcolorSequencePlot); + txtcolorSequencePlot.setText(ToolDescriptions.four_color_description); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtcolorSequencePlot, 10, SpringLayout.SOUTH, txtMergeHeatmap); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, txtcolorSequencePlot, 10, SpringLayout.SOUTH, btnMergeHeatmap); + sl_pnlFigure.putConstraint(SpringLayout.EAST, txtcolorSequencePlot, -10, SpringLayout.EAST, pnlFigure); + pnlFigure.add(txtcolorSequencePlot); + + JButton btncolorSequencePlot = new JButton("4Color Sequence Plot"); + btncolorSequencePlot.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + FourColorSequenceWindow frame = new FourColorSequenceWindow(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + }); + sl_pnlFigure.putConstraint(SpringLayout.NORTH, btncolorSequencePlot, 0, SpringLayout.NORTH, txtcolorSequencePlot); + sl_pnlFigure.putConstraint(SpringLayout.WEST, btncolorSequencePlot, 10, SpringLayout.WEST, pnlFigure); + sl_pnlFigure.putConstraint(SpringLayout.WEST, txtcolorSequencePlot, 10, SpringLayout.EAST, btncolorSequencePlot); + pnlFigure.add(btncolorSequencePlot); + + //Set default tab to open to... + // 0=BAM_Statistics 5=Peak_Analysis + // 1=BAM_Manipulation 6=Coordinate_Manipulation + // 2=BAM_Format_Converter 7=Sequence_Analysis + // 3=File_Utilities 8=DNA_Sequence_Analysis + // 4=Peak_Calling 9=Figure_Generation + tabbedPane.setSelectedIndex(2); + } + + private void initializeTextArea(JTextArea text) { + text.setWrapStyleWord(true); + text.setEditable(false); + text.setLineWrap(true); + } + + /** + * Create the application. + */ + public ScriptManagerGUI() { + initialize(); + } + + /** + * Launch the application. + */ + public static void launchApplication() { + try { + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + } catch (Throwable e) { + e.printStackTrace(); + } + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + ScriptManagerGUI window = new ScriptManagerGUI(); + window.frmScriptManager.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + public static void main(String[] args) { + launchApplication(); + } + +} diff --git a/src/objects/ToolDescriptions.java b/src/objects/ToolDescriptions.java new file mode 100644 index 000000000..2d10b9fa4 --- /dev/null +++ b/src/objects/ToolDescriptions.java @@ -0,0 +1,64 @@ +package objects; + +public class ToolDescriptions { + + // BAM Statistics + public static final String se_stat_description = "Output BAM Header including alignment statistics and parameters given any indexed (BAI) BAM File."; + public static final String pe_stat_description = "Generates Insert-size Histogram statistics (GEO requirement) and outputs BAM Header including alignment statistics and parameters given a sorted and indexed (BAI) paired-end BAM File."; + public static final String bam_correlation_description = "Genome-Genome correlations for replicate comparisons given multiple sorted and indexed (BAI) BAM files."; + + // BAM Manipulation + public static final String bam_indexer_description = "Generates BAI Index for input BAM files. Output BAI is in the same directory as input BAM file."; //* + public static final String sort_bam_description = "Sort BAM files in order to efficiently extract and manipulate.\nRAM intensive process. If program freezes, increase JAVA heap size."; //* + public static final String remove_duplicates_description = "Removes duplicate reads in Paired-End sequencing given identical 5' read locations. RAM intensive process. If program freezes, increase JAVA heap size."; //* + public static final String merge_bam_description = "Merges Multiple BAM files into single BAM file. Sorting is performed automatically. RAM intensive process. If program freezes, increase JAVA heap size."; //* + public static final String filter_pip_seq_description = "Filter BAM file by -1 nucleotide. Requires genome FASTA file."; + + // BAM Format Converter + public static final String bam_to_scidx_description = "Convert BAM file to scIDX file."; + public static final String bam_to_gff_description = "Convert BAM file to GFF file."; + public static final String bam_to_bed_description = "Convert BAM file to BED file."; + public static final String bam_to_bedgraph_description = "Convert BAM file to bedGraph file."; + + // File Utilities + public static final String md5checksum_description = "Calculate MD5 checksum for files."; + + // Peak Calling + public static final String gene_track_description = "Genetrack peak-calling algorithm."; + public static final String peak_pairing_description = "Peak-pairing algorithm."; + public static final String replicate_match_description = "Peak-pair replicate analysis."; + + // Peak Analysis + public static final String peak_align_ref_description = "Align BED peaks to Reference BED file creating CDT files for heatmap generation."; + public static final String filter_bed_description = "Filter BED file using user-specified exclusion zone using the score column to determine which peak to retain."; + public static final String tile_genome_description = "Generate a coordinate file that tiles (non-overlapping) across an entire genome."; + public static final String rand_coord_description = "Generate random BED coordinates based on reference genome."; + public static final String signal_dup_description = "Calculate duplication statistics at user-specified regsions."; + + // Coordinate Manipulation + public static final String expand_bed_description = "Expand BED file given user-defined criteria."; //"Expands input BED file by adding positions to the border or around the center" + public static final String expand_gff_description = "Expand GFF file given user-defined criteria."; //"Expands input GFF file by adding positions to the border or around the center" + public static final String bed_to_gff_description = "Convert BED file to GFF file."; + public static final String gff_to_bed_description = "Convert GFF file to BED file."; + public static final String sort_bed_description = "Sort BED file by CDT file statistics."; //"Sort a CDT file and its corresponding BED file by the total score in the CDT file across the specified interval" + public static final String sort_gff_description = "Sort GFF file by CDT file statistics."; //"Sort a CDT file and its corresponding GFF file by the total score in the CDT file across the specified interval" + + // Read Analysis + public static final String tag_pileup_description = "Pileup 5' ends of aligned tags given BED and BAM files according to user-defined parameters."; + public static final String scaling_factor_description = "Calculate scaling factor as either total tag normalization or normalization of ChIP-seq data with control. (PMID: 22883957)"; + public static final String scale_matrix_description = "Apply a user-specified scaling factor to tab-delimited matrix data."; + public static final String aggregate_data_description = "Compile data from tab-delimited file into matrix according to user-specified metric."; + + // Sequence Analysis + public static final String fasta_extract_description = "Generate FASTA file from indexed Genome FASTA file and BED file. Script will generate FAI index if not present in Genome FASTA folder."; + public static final String randomize_fasta_description = "Randomize FASTA sequence for each input entry."; + public static final String search_motif_description = "Search for an IUPAC DNA sequence motif in FASTA files with mismatches allowed."; + public static final String dna_shape_from_bed_description = "Calculate intrinsic DNA shape parameters given BED file and Genome FASTA file. Based on Roh's lab DNAshape server data."; //%nNotes: Sequences with Ns are thrown out. + public static final String dna_shape_from_fasta_description = "Calculate intrinsic DNA shape parameters given input FASTA files. Based on Roh's lab DNAshape server data."; + + // Figure Generation + public static final String heatmap_description = "Generate heat map using CDT files."; + public static final String merge_heatmap_description = "Merge Sense and Antisense png heatmaps."; + public static final String four_color_description = "Generate 4Color sequence plot given FASTA file and user-defined RGB colors."; + public static final String composite_description = "Generate a Composite Plot PNG from composite data like the output in TagPileup"; +} \ No newline at end of file From 512142e05739da3407c0c58841936e68f5376b8d Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 15:16:54 -0400 Subject: [PATCH 02/43] add stripExtension function for CLI validation One of the redundant checks in validateInput() methods of the CLI will be to strip the extension off a file name to build default output filenames. The method takes a File object and returns a String object of the file's name without the extension. --- src/util/ExtensionFileFilter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/util/ExtensionFileFilter.java b/src/util/ExtensionFileFilter.java index 3d5291274..a64552306 100644 --- a/src/util/ExtensionFileFilter.java +++ b/src/util/ExtensionFileFilter.java @@ -1,6 +1,7 @@ package util; import java.io.File; +import java.io.IOException; import javax.swing.filechooser.FileFilter; @@ -30,7 +31,7 @@ public boolean accept(File f) { return false; } - public String getExtension(File f) { + public static String getExtension(File f) { String ext = null; String s = f.getName(); int i = s.lastIndexOf('.'); @@ -40,8 +41,18 @@ public String getExtension(File f) { return ext; } + public static String stripExtension(File f) throws IOException { + String NAME = f.getName(); + return(NAME.substring(0, NAME.lastIndexOf('.'))); + } + + public static String stripExtensionPath(File f) throws IOException { + String NAME = f.getCanonicalPath(); + return(NAME.substring(0, NAME.lastIndexOf('.'))); + } + @Override public String getDescription() { return null; } -} \ No newline at end of file +} From 81ae75bce436e5f75e528a0fc06f70c1c451d5a4 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 15:23:42 -0400 Subject: [PATCH 03/43] create CustomOutputStream wrapper object This wrapper class wraps the GUI's TextArea output object such that the GUI components are hidden from the CLI version to avoid exceptions being thrown when there is no way of displaying GUI components. Since some of the GUI tools output to a TextArea GUI object, running a CLI version on the terminal of a remote server without adjusting the script object would throw an exception. By wrapping the TextArea in this object, CLI won't know that it contains a GUI object unless this object is instantiated. By writing code to avoid instantiating the object if running as CLI, we've created a workaround for the GUI text components. The class extends OutputStream and takes the TextArea object and saves it in its constructor. The write() method is overriden with the code that uses the TextArea append() method. --- src/objects/CustomOutputStream.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/objects/CustomOutputStream.java diff --git a/src/objects/CustomOutputStream.java b/src/objects/CustomOutputStream.java new file mode 100644 index 000000000..0217cdb43 --- /dev/null +++ b/src/objects/CustomOutputStream.java @@ -0,0 +1,28 @@ +package objects; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.swing.JTextArea; + +/** + * This class extends from OutputStream to redirect output to a JTextArrea + * @author www.codejava.net + * source written by Nam Ha Minh written 2019/07/06, retrieved 2020/05/05, url below + * https://www.codejava.net/java-se/swing/redirect-standard-output-streams-to-jtextarea + */ +public class CustomOutputStream extends OutputStream { + private JTextArea textArea; + + public CustomOutputStream(JTextArea textArea) { + this.textArea = textArea; + } + + @Override + public void write(int b) throws IOException { + // redirects data to the text area + textArea.append(String.valueOf((char)b)); + // scrolls the text area to the end of data + textArea.setCaretPosition(textArea.getDocument().getLength()); + } +} \ No newline at end of file From 9f36aca143265219b6a8a3477cbc90cec0309580 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 16:00:57 -0400 Subject: [PATCH 04/43] create BAMtoBED command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BAMtoBEDOutput class while the calculations are kept in the src/scripts/*/BAMtoBED class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/BAM_Format_Converter/BAMtoBEDCLI.java | 102 +++++++++++++- .../BAM_Format_Converter/BAMtoBED.java | 128 ++++++++---------- .../BAM_Format_Converter/BAMtoBEDOutput.java | 72 ++++++++++ .../BAM_Format_Converter/BAMtoBEDWindow.java | 5 +- 4 files changed, 226 insertions(+), 81 deletions(-) create mode 100644 src/window_interface/BAM_Format_Converter/BAMtoBEDOutput.java diff --git a/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java b/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java index 1c07569fd..769d34b66 100644 --- a/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java +++ b/src/cli/BAM_Format_Converter/BAMtoBEDCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Format_Converter.BAMtoBED; +import scripts.BAM_Format_Converter.BAMtoBED; /** BAM_Format_ConverterCLI/SEStatsCLI @@ -25,6 +25,40 @@ exitCodeOnExecutionException = 1) public class BAMtoBEDCLI implements Callable { + @Parameters( index = "0", description = "The BAM file from which we generate a new file.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .bed ext)" ) + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "stream output file to STDOUT (cannot be used with \"-o\" flag)" ) + private boolean stdout = false; + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "output read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "output read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "output combined") + boolean combined = false; + @Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)") + boolean midpoint = false; + @Option(names = {"-f", "--fragment"}, description = "output fragment (requires PE)") + private boolean fragment = false; + } + + @Option(names = {"-p", "--mate-pair"}, description = "require proper mate pair (default not required)") + private boolean matePair = false; + @Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp") + private int MIN_INSERT = -9999; + @Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp") + private int MAX_INSERT = -9999; + + private int STRAND = -9999; + private int PAIR; + @Override public Integer call() throws Exception { System.err.println( ">BAMtoBEDCLI.call()" ); @@ -35,16 +69,72 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BAMtoBED script_obj = new BAMtoBED(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + // set strand method + if(readType.read1) { STRAND=0; } + else if(readType.read2) { STRAND=1; } + else if(readType.combined) { STRAND=2; } + else if(readType.midpoint) { STRAND=3; } + else if(readType.fragment) { STRAND=4; } + else { STRAND=0; } + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(output==null && !stdout){ + if(STRAND==0){ output = new File( bamFile.getName().split("\\.")[0] + "_READ1.bed" ); } + else if(STRAND==1){ output = new File( bamFile.getName().split("\\.")[0] + "_READ2.bed" ); } + else if(STRAND==2){ output = new File( bamFile.getName().split("\\.")[0] + "_COMBINED.bed" ); } + else if(STRAND==3){ output = new File( bamFile.getName().split("\\.")[0] + "_MIDPOINT.bed" ); } + else if(STRAND==4){ output = new File( bamFile.getName().split("\\.")[0] + "_FRAGMENT.bed" ); } + else { r += "(!)Somehow invalid STRAND!This error should never print. Check code if it does.\n"; } + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + // validate insert sizes + if( MIN_INSERT<0 && MIN_INSERT!=-9999 ){ r += "MIN_INSERT must be a positive integer value: " + MIN_INSERT + "\n"; } + if( MAX_INSERT<0 && MAX_INSERT!=-9999 ){ r += "MAX_INSERT must be a positive integer value: " + MAX_INSERT + "\n"; } + if( MAX_INSERT= 0 && recordStop < CHROMSTOP) { //Make sure we only output real reads - OUT.println(chrom + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadName() + "\t" + read.getReadLength() + "\t" + dir); + printOUT(chrom + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadName() + "\t" + read.getReadLength() + "\t" + dir); } } else if(STRAND == 3) { recordStop = read.getMateAlignmentStart() + read.getReadLength() - 1; @@ -146,7 +118,7 @@ public void outputRead(SAMRecord read) { if(midStart >= 0 && midStop < CHROMSTOP) { //Make sure we only output real reads int size = Math.abs(read.getInferredInsertSize()); - OUT.println(chrom + "\t" + midStart + "\t" + midStop + "\t" + read.getReadName() + "\t" + size + "\t" + dir); + printOUT(chrom + "\t" + midStart + "\t" + midStop + "\t" + read.getReadName() + "\t" + size + "\t" + dir); } } else if(STRAND == 4) { recordStop = read.getMateAlignmentStart() + read.getReadLength() - 1; @@ -156,7 +128,7 @@ public void outputRead(SAMRecord read) { } if(recordStart >= 0 && recordStop < CHROMSTOP) { //Make sure we only output real reads int size = Math.abs(read.getInferredInsertSize()); - OUT.println(chrom + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadName() + "\t" + size + "\t" + dir); + printOUT(chrom + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadName() + "\t" + size + "\t" + dir); } } } @@ -167,8 +139,8 @@ public void processREADS() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); CHROMSTOP = seq.getSequenceLength(); @@ -213,7 +185,17 @@ else if(sr.getReadPairedFlag()) { //otherwise, check for PE flag } bai.close(); } - + + private void printPS( String line ){ + if( PS!=null ){ PS.println(line); } + System.err.println( line ); + } + + private void printOUT( String line ){ + if( OUT!=null ){ OUT.println(line); } + else{ System.out.println( line ); } + } + private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); diff --git a/src/window_interface/BAM_Format_Converter/BAMtoBEDOutput.java b/src/window_interface/BAM_Format_Converter/BAMtoBEDOutput.java new file mode 100644 index 000000000..7af20dd18 --- /dev/null +++ b/src/window_interface/BAM_Format_Converter/BAMtoBEDOutput.java @@ -0,0 +1,72 @@ +package window_interface.BAM_Format_Converter; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.BAM_Format_Converter.BAMtoBED; + +@SuppressWarnings("serial") +public class BAMtoBEDOutput extends JFrame { + private File BAM = null; + private File OUTPUTPATH = null; + private int STRAND = 0; + private String READ = "READ1"; + + private static int PAIR = 1; + private static int MIN_INSERT = -9999; + private static int MAX_INSERT = -9999; + + private JTextArea textArea; + + public BAMtoBEDOutput(File b, File o, int s, int pair_status, int min_size, int max_size) { + setTitle("BAM to BED Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + BAM = b; + OUTPUTPATH = o; + STRAND = s; + PAIR = pair_status; + MIN_INSERT = min_size; + MAX_INSERT = max_size; + if(STRAND == 0) { READ = "READ1"; } + else if(STRAND == 1) { READ = "READ2"; } + else if(STRAND == 2) { READ = "COMBINED"; } + else if(STRAND == 3) { READ = "MIDPOINT"; } + else if(STRAND == 4) { READ = "FRAGMENT"; } + } + + public void run() throws IOException, InterruptedException { + //Open Output File + File OUT; + String NAME = BAM.getName().split("\\.")[0] + "_" + READ + ".bed"; + if(OUTPUTPATH != null) { + OUT = new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME); + } else { + OUT = new File(NAME); + } + + //Call script here, pass in ps and OUT + PrintStream PS = new PrintStream( new CustomOutputStream(textArea) ); + PS.println(NAME); + BAMtoBED script_obj = new BAMtoBED(BAM, OUT, STRAND, PAIR, MIN_INSERT, MAX_INSERT, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Format_Converter/BAMtoBEDWindow.java b/src/window_interface/BAM_Format_Converter/BAMtoBEDWindow.java index 3040015da..13d07de4d 100644 --- a/src/window_interface/BAM_Format_Converter/BAMtoBEDWindow.java +++ b/src/window_interface/BAM_Format_Converter/BAMtoBEDWindow.java @@ -36,7 +36,8 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Format_Converter.BAMtoBED; +import window_interface.BAM_Format_Converter.BAMtoBEDOutput; + @SuppressWarnings("serial") public class BAMtoBEDWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -93,7 +94,7 @@ public Void doInBackground() throws IOException, InterruptedException { if(chckbxFilterByMaximum.isSelected()) { MAX = Integer.parseInt(txtMax.getText()); } for(int x = 0; x < BAMFiles.size(); x++) { - BAMtoBED convert = new BAMtoBED(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); + BAMtoBEDOutput convert = new BAMtoBEDOutput(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); convert.setVisible(true); convert.run(); int percentComplete = (int)(((double)(x + 1) / BAMFiles.size()) * 100); From ebe78cc9ba07d2df159e8c942509e54c70ab6785 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 16:11:28 -0400 Subject: [PATCH 05/43] create BAMtobedGraph command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BAMtobedGraphOutput class while the calculations are kept in the src/scripts/*/BAMtobedGraph class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename base and not just directory script/* -strip out JFrame objects -use output basename as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../BAMtobedGraphCLI.java | 90 +++++++++++++- .../BAM_Format_Converter/BAMtobedGraph.java | 112 +++++++----------- .../BAMtobedGraphOutput.java | 68 +++++++++++ .../BAMtobedGraphWindow.java | 4 +- 4 files changed, 199 insertions(+), 75 deletions(-) create mode 100644 src/window_interface/BAM_Format_Converter/BAMtobedGraphOutput.java diff --git a/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java b/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java index 9d44c16ea..26d885835 100644 --- a/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java +++ b/src/cli/BAM_Format_Converter/BAMtobedGraphCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Format_Converter.BAMtobedGraph; +import scripts.BAM_Format_Converter.BAMtobedGraph; /** BAM_Format_ConverterCLI/BAMtobedGraphCLI @@ -25,6 +25,36 @@ exitCodeOnExecutionException = 1) public class BAMtobedGraphCLI implements Callable { + @Parameters( index = "0", description = "The BAM file from which we generate a new file.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with _.bedgraph ext)" ) + private String outputBasename = null; + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "output read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "output read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "output combined") + boolean combined = false; + @Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)") + boolean midpoint = false; + } + + @Option(names = {"-p", "--mate-pair"}, description = "require proper mate pair (default not required)") + private boolean matePair = false; + @Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp") + private int MIN_INSERT = -9999; + @Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp") + private int MAX_INSERT = -9999; + + private int STRAND = -9999; + private int PAIR; + @Override public Integer call() throws Exception { System.err.println( ">BAMtobedGraphCLI.call()" ); @@ -35,16 +65,64 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BAMtobedGraph script_obj = new BAMtobedGraph(bamFile, outputBasename, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + // set strand method + if(readType.read1) { STRAND=0; } + else if(readType.read2) { STRAND=1; } + else if(readType.combined) { STRAND=2; } + else if(readType.midpoint) { STRAND=3; } + else { STRAND=0; } + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(outputBasename==null){ + if(STRAND==0){ outputBasename = bamFile.getName().split("\\.")[0] + "_READ1"; } + else if(STRAND==1){ outputBasename = bamFile.getName().split("\\.")[0] + "_READ2"; } + else if(STRAND==2){ outputBasename = bamFile.getName().split("\\.")[0] + "_COMBINED"; } + else if(STRAND==3){ outputBasename = bamFile.getName().split("\\.")[0] + "_MIDPOINT"; } + else if(STRAND==4){ outputBasename = bamFile.getName().split("\\.")[0] + "_FRAGMENT"; } + else { r += "(!)Somehow invalid STRAND!This error should never print. Check code if it does.\n"; } + //check output filename is valid + }else{ + //no check ext + //check directory + File tmpOut = new File(outputBasename); + if(tmpOut.getParent()==null){ + // System.err.println("default to current directory"); + } else if(!tmpOut.getParentFile().exists()){ + r += "(!)Check output directory exists: " + tmpOut.getParent() + "\n"; + } + } + + // validate insert sizes + if( MIN_INSERT<0 && MIN_INSERT!=-9999 ){ r += "MIN_INSERT must be a positive integer value: " + MIN_INSERT + "\n"; } + if( MAX_INSERT<0 && MAX_INSERT!=-9999 ){ r += "MAX_INSERT must be a positive integer value: " + MAX_INSERT + "\n"; } + if( MAX_INSERT BP; private ArrayList F_OCC; private ArrayList R_OCC; private ArrayList M_OCC; - - private JTextArea textArea; private int CHROMSTOP = -999; - public BAMtobedGraph(File b, File o, int s, int pair_status, int min_size, int max_size) { - setTitle("BAM to bedGraph Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - + public BAMtobedGraph(File b, String o, int s, int pair_status, int min_size, int max_size, PrintStream ps) { BAM = b; - OUTPUTPATH = o; + OUTBASENAME = o; + PS = ps; STRAND = s; PAIR = pair_status; MIN_INSERT = min_size; @@ -69,54 +53,44 @@ public BAMtobedGraph(File b, File o, int s, int pair_status, int min_size, int m } public void run() throws IOException, InterruptedException { - System.out.println(getTimeStamp()); //Open Output File - String NAME = BAM.getName().split("\\.")[0] + "_" + READ; - if(OUTPUTPATH != null) { + if(OUTBASENAME != null) { try { if(STRAND <= 2) { - OUTF = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_forward.bedGraph")); - OUTR = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_reverse.bedGraph")); + OUTF = new PrintStream(new File(OUTBASENAME + "_forward.bedGraph")); + OUTR = new PrintStream(new File(OUTBASENAME + "_reverse.bedGraph")); } else { - OUTF = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_midpoint.bedGraph")); + OUTF = new PrintStream(new File(OUTBASENAME + "_midpoint.bedGraph")); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { - try { - if(STRAND <= 2) { - OUTF = new PrintStream(new File(NAME + "_forward.bedGraph")); - OUTR = new PrintStream(new File(NAME + "_reverse.bedGraph")); - } else { - OUTF = new PrintStream(new File(NAME + "_midpoint.bedGraph")); - } - } - catch (FileNotFoundException e) { e.printStackTrace(); } + throw new NullPointerException(); } - textArea.append(NAME + "\n"); - textArea.append(getTimeStamp() + "\n"); + // Print TimeStamp to STDERR/Output Window + printPS(OUTBASENAME); + printPS(getTimeStamp()); //Check to Make Sure BAI-index file exists File f = new File(BAM.getAbsolutePath() + ".bai"); if(f.exists() && !f.isDirectory()) { - textArea.append("-----------------------------------------\nBAM to bedGraph Parameters:\n"); - textArea.append("BAM file: " + BAM + "\n"); - textArea.append("Output: " + NAME + "\n"); + //Print Input Params + printPS("-----------------------------------------\nBAM to bedGraph Parameters:"); + printPS("BAM file: " + BAM); + printPS("Output: " + new File(OUTBASENAME).getName()); + + printPS("Output Read: " + READ); + if(PAIR == 0) { printPS( "Require proper Mate-pair: no"); } + else { printPS("Require proper Mate-pair: yes"); } - textArea.append("Require proper Mate-pair: "); - if(PAIR == 0) { textArea.append("no" + "\n"); } - else { textArea.append("yes" + "\n"); } + if(MIN_INSERT == -9999) { printPS("Minimum insert size required to output: NaN"); } + else { printPS("Minimum insert size required to output: " + MIN_INSERT); } - textArea.append("Output Read: " + READ + "\n"); - textArea.append("Minimum insert size required to output: "); - if(MIN_INSERT == -9999) { textArea.append("NaN\n"); } - else { textArea.append(MIN_INSERT + "\n"); } - textArea.append("Maximum insert size required to output: "); - if(MAX_INSERT == -9999) { textArea.append("NaN\n"); } - else { textArea.append(MAX_INSERT + "\n"); } + if(MAX_INSERT == -9999) { printPS("Maximum insert size required to output: NaN"); } + else { printPS("Maximum insert size required to output: " + MAX_INSERT); } //Print Header if(STRAND <= 2) { @@ -129,18 +103,15 @@ public void run() throws IOException, InterruptedException { //Begin processing reads in BAM file if(STRAND <= 2) { processREADS(); } else { processMIDPOINT(); } - - if(OUTF != null) { OUTF.close(); } - if(OUTR != null) { OUTR.close(); } } else { - textArea.append("BAI Index File does not exist for: " + BAM.getName() + "\n"); - if(OUTF != null) { OUTF.println("BAI Index File does not exist for: " + BAM.getName() + "\n"); } - if(OUTR != null) { OUTR.println("BAI Index File does not exist for: " + BAM.getName() + "\n"); } + printPS("BAI Index File does not exist for: " + BAM.getName()); + if(OUTF != null) { OUTF.println("BAI Index File does not exist for: " + BAM.getName()); } + if(OUTR != null) { OUTR.println("BAI Index File does not exist for: " + BAM.getName()); } } - Thread.sleep(2000); - dispose(); + if(OUTF != null) { OUTF.close(); } + if(OUTR != null) { OUTR.close(); } - System.out.println(getTimeStamp()); + printPS(getTimeStamp()); } public void addTag(SAMRecord sr) { @@ -259,8 +230,8 @@ public void processREADS() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); CHROMSTOP = seq.getSequenceLength(); BP = new ArrayList(); @@ -317,8 +288,8 @@ public void processMIDPOINT() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); BP = new ArrayList(); M_OCC = new ArrayList(); @@ -352,6 +323,11 @@ public void processMIDPOINT() { bai.close(); } + private void printPS( String line ){ + if( PS!=null ){ PS.println(line); } + System.err.println( line ); + } + private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); diff --git a/src/window_interface/BAM_Format_Converter/BAMtobedGraphOutput.java b/src/window_interface/BAM_Format_Converter/BAMtobedGraphOutput.java new file mode 100644 index 000000000..8bf22ca4d --- /dev/null +++ b/src/window_interface/BAM_Format_Converter/BAMtobedGraphOutput.java @@ -0,0 +1,68 @@ +package window_interface.BAM_Format_Converter; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.BAM_Format_Converter.BAMtobedGraph; + +@SuppressWarnings("serial") +public class BAMtobedGraphOutput extends JFrame { + private File BAM = null; + private File OUTPUTPATH = null; + private int STRAND = 0; + private String READ = "READ1"; + + private static int PAIR = 1; + private static int MIN_INSERT = -9999; + private static int MAX_INSERT = -9999; + + private JTextArea textArea; + + public BAMtobedGraphOutput(File b, File o, int s, int pair_status, int min_size, int max_size) { + setTitle("BAM to bedGraph Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + BAM = b; + OUTPUTPATH = o; + STRAND = s; + PAIR = pair_status; + MIN_INSERT = min_size; + MAX_INSERT = max_size; + if(STRAND == 0) { READ = "READ1"; } + else if(STRAND == 1) { READ = "READ2"; } + else if(STRAND == 2) { READ = "COMBINED"; } + else if(STRAND == 3) { READ = "MIDPOINT"; } + } + + public void run() throws IOException, InterruptedException { + //Open Output File + String OUTBASENAME = BAM.getName().split("\\.")[0] + "_" + READ; + if(OUTPUTPATH != null) { + OUTBASENAME = OUTPUTPATH.getCanonicalPath() + File.separator + OUTBASENAME; + } + + //Call script here, pass in ps and OUT + PrintStream PS = new PrintStream( new CustomOutputStream(textArea) ); + PS.println(OUTBASENAME); + BAMtobedGraph script_obj = new BAMtobedGraph(BAM, OUTBASENAME, STRAND, PAIR, MIN_INSERT, MAX_INSERT, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Format_Converter/BAMtobedGraphWindow.java b/src/window_interface/BAM_Format_Converter/BAMtobedGraphWindow.java index 1e4aeca92..71f5d68f3 100644 --- a/src/window_interface/BAM_Format_Converter/BAMtobedGraphWindow.java +++ b/src/window_interface/BAM_Format_Converter/BAMtobedGraphWindow.java @@ -38,6 +38,8 @@ import util.FileSelection; import scripts.BAM_Format_Converter.BAMtobedGraph; +import window_interface.BAM_Format_Converter.BAMtobedGraphOutput; + @SuppressWarnings("serial") public class BAMtobedGraphWindow extends JFrame implements ActionListener, PropertyChangeListener { private JPanel contentPane; @@ -91,7 +93,7 @@ public Void doInBackground() throws IOException, InterruptedException { if(chckbxFilterByMaximum.isSelected()) { MAX = Integer.parseInt(txtMax.getText()); } for(int x = 0; x < BAMFiles.size(); x++) { - BAMtobedGraph convert = new BAMtobedGraph(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); + BAMtobedGraphOutput convert = new BAMtobedGraphOutput(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); convert.setVisible(true); convert.run(); int percentComplete = (int)(((double)(x + 1) / BAMFiles.size()) * 100); From ce85e56326904520ce154830e909206dc7df49c8 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 16:19:16 -0400 Subject: [PATCH 06/43] create BAMtoGFF command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BAMtoGFFOutput class while the calculations are kept in the src/scripts/*/BAMtoGFF class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/BAM_Format_Converter/BAMtoGFFCLI.java | 102 +++++++++++++- .../BAM_Format_Converter/BAMtoGFF.java | 128 ++++++++---------- .../BAM_Format_Converter/BAMtoGFFOutput.java | 72 ++++++++++ .../BAM_Format_Converter/BAMtoGFFWindow.java | 4 +- 4 files changed, 225 insertions(+), 81 deletions(-) create mode 100644 src/window_interface/BAM_Format_Converter/BAMtoGFFOutput.java diff --git a/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java b/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java index 70b34cde3..dfb7ada08 100644 --- a/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java +++ b/src/cli/BAM_Format_Converter/BAMtoGFFCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Format_Converter.BAMtoGFF; +import scripts.BAM_Format_Converter.BAMtoGFF; /** BAM_Format_ConverterCLI/SEStatsCLI @@ -25,6 +25,40 @@ exitCodeOnExecutionException = 1) public class BAMtoGFFCLI implements Callable { + @Parameters( index = "0", description = "The BAM file from which we generate a new file.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .gff ext)" ) + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "stream output file to STDOUT (cannot be used with \"-o\" flag)" ) + private boolean stdout = false; + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "output read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "output read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "output combined") + boolean combined = false; + @Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)") + boolean midpoint = false; + @Option(names = {"-f", "--fragment"}, description = "output fragment (requires PE)") + private boolean fragment = false; + } + + @Option(names = {"-p", "--mate-pair"}, description = "require proper mate pair (default not required)") + private boolean matePair = false; + @Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp") + private int MIN_INSERT = -9999; + @Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp") + private int MAX_INSERT = -9999; + + private int STRAND = -9999; + private int PAIR; + @Override public Integer call() throws Exception { System.err.println( ">BAMtoGFFCLI.call()" ); @@ -35,16 +69,72 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BAMtoGFF script_obj = new BAMtoGFF(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + // set strand method + if(readType.read1) { STRAND=0; } + else if(readType.read2) { STRAND=1; } + else if(readType.combined) { STRAND=2; } + else if(readType.midpoint) { STRAND=3; } + else if(readType.fragment) { STRAND=4; } + else { STRAND=0; } + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(output==null && !stdout){ + if(STRAND==0){ output = new File( bamFile.getName().split("\\.")[0] + "_READ1.gff" ); } + else if(STRAND==1){ output = new File( bamFile.getName().split("\\.")[0] + "_READ2.gff" ); } + else if(STRAND==2){ output = new File( bamFile.getName().split("\\.")[0] + "_COMBINED.gff" ); } + else if(STRAND==3){ output = new File( bamFile.getName().split("\\.")[0] + "_MIDPOINT.gff" ); } + else if(STRAND==4){ output = new File( bamFile.getName().split("\\.")[0] + "_FRAGMENT.gff" ); } + else { r += "(!)Somehow invalid STRAND!This error should never print. Check code if it does.\n"; } + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + // validate insert sizes + if( MIN_INSERT<0 && MIN_INSERT!=-9999 ){ r += "MIN_INSERT must be a positive integer value: " + MIN_INSERT + "\n"; } + if( MAX_INSERT<0 && MAX_INSERT!=-9999 ){ r += "MAX_INSERT must be a positive integer value: " + MAX_INSERT + "\n"; } + if( MAX_INSERT 0 && recordStop <= CHROMSTOP) { //Make sure we only output real reads - OUT.println(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadLength() + "\t" + dir + "\t.\t" + read.getReadName()); + printOUT(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + recordStart + "\t" + recordStop + "\t" + read.getReadLength() + "\t" + dir + "\t.\t" + read.getReadName()); } } else if(STRAND == 3) { recordStop = read.getMateAlignmentStart() + read.getReadLength() - 1; @@ -146,7 +118,7 @@ public void outputRead(SAMRecord read) { if(midStart > 0 && midStop <= CHROMSTOP) { //Make sure we only output real reads int size = Math.abs(read.getInferredInsertSize()); - OUT.println(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + midStart + "\t" + midStop + "\t" + size + "\t" + dir + "\t.\t" + read.getReadName()); + printOUT(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + midStart + "\t" + midStop + "\t" + size + "\t" + dir + "\t.\t" + read.getReadName()); } } else if(STRAND == 4) { if(read.getReadNegativeStrandFlag()) { @@ -157,7 +129,7 @@ public void outputRead(SAMRecord read) { } if(recordStart > 0 && recordStop <= CHROMSTOP) { //Make sure we only output real reads int size = Math.abs(read.getInferredInsertSize()); - OUT.println(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + recordStart + "\t" + recordStop + "\t" + size + "\t" + dir + "\t.\t" + read.getReadName()); + printOUT(chrom + "\tbam2gff\t" + read.getReadName() + "\t" + recordStart + "\t" + recordStop + "\t" + size + "\t" + dir + "\t.\t" + read.getReadName()); } } } @@ -168,8 +140,8 @@ public void processREADS() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); CHROMSTOP = seq.getSequenceLength(); @@ -214,7 +186,17 @@ else if(sr.getReadPairedFlag()) { //otherwise, check for PE flag } bai.close(); } - + + private void printPS( String line ){ + if( PS!=null ){ PS.println(line); } + System.err.println( line ); + } + + private void printOUT( String line ){ + if( OUT!=null ){ OUT.println(line); } + else{ System.out.println( line ); } + } + private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); diff --git a/src/window_interface/BAM_Format_Converter/BAMtoGFFOutput.java b/src/window_interface/BAM_Format_Converter/BAMtoGFFOutput.java new file mode 100644 index 000000000..cd2066779 --- /dev/null +++ b/src/window_interface/BAM_Format_Converter/BAMtoGFFOutput.java @@ -0,0 +1,72 @@ +package window_interface.BAM_Format_Converter; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.BAM_Format_Converter.BAMtoGFF; + +@SuppressWarnings("serial") +public class BAMtoGFFOutput extends JFrame { + private File BAM = null; + private File OUTPUTPATH = null; + private int STRAND = 0; + private String READ = "READ1"; + + private static int PAIR = 1; + private static int MIN_INSERT = -9999; + private static int MAX_INSERT = -9999; + + private JTextArea textArea; + + public BAMtoGFFOutput(File b, File o, int s, int pair_status, int min_size, int max_size) { + setTitle("BAM to GFF Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + BAM = b; + OUTPUTPATH = o; + STRAND = s; + PAIR = pair_status; + MIN_INSERT = min_size; + MAX_INSERT = max_size; + if(STRAND == 0) { READ = "READ1"; } + else if(STRAND == 1) { READ = "READ2"; } + else if(STRAND == 2) { READ = "COMBINED"; } + else if(STRAND == 3) { READ = "MIDPOINT"; } + else if(STRAND == 4) { READ = "FRAGMENT"; } + } + + public void run() throws IOException, InterruptedException { + //Open Output File + File OUT; + String NAME = BAM.getName().split("\\.")[0] + "_" + READ + ".gff"; + if(OUTPUTPATH != null) { + OUT = new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME); + } else { + OUT = new File(NAME); + } + + //Call script here, pass in ps and OUT + PrintStream PS = new PrintStream( new CustomOutputStream(textArea) ); + PS.println(NAME); + BAMtoGFF script_obj = new BAMtoGFF(BAM, OUT, STRAND, PAIR, MIN_INSERT, MAX_INSERT, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Format_Converter/BAMtoGFFWindow.java b/src/window_interface/BAM_Format_Converter/BAMtoGFFWindow.java index cb9dd87d9..70a246aa1 100644 --- a/src/window_interface/BAM_Format_Converter/BAMtoGFFWindow.java +++ b/src/window_interface/BAM_Format_Converter/BAMtoGFFWindow.java @@ -36,7 +36,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Format_Converter.BAMtoGFF; +import window_interface.BAM_Format_Converter.BAMtoGFFOutput; @SuppressWarnings("serial") public class BAMtoGFFWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -93,7 +93,7 @@ public Void doInBackground() throws IOException, InterruptedException { if(chckbxFilterByMaximum.isSelected()) { MAX = Integer.parseInt(txtMax.getText()); } for(int x = 0; x < BAMFiles.size(); x++) { - BAMtoGFF convert = new BAMtoGFF(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); + BAMtoGFFOutput convert = new BAMtoGFFOutput(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); convert.setVisible(true); convert.run(); int percentComplete = (int)(((double)(x + 1) / BAMFiles.size()) * 100); From 2be56914a3889cbac95659add72ce9dc4ec1e306 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 16:26:49 -0400 Subject: [PATCH 07/43] create BAMtoscIDX command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BAMtoscIDXOutput class while the calculations are kept in the src/scripts/*/BAMtoscIDX class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../BAM_Format_Converter/BAMtoscIDXCLI.java | 99 +++++++++++++- .../BAM_Format_Converter/BAMtoscIDX.java | 127 ++++++++---------- .../BAMtoscIDXOutput.java | 71 ++++++++++ .../BAMtoscIDXWindow.java | 4 +- 4 files changed, 223 insertions(+), 78 deletions(-) create mode 100644 src/window_interface/BAM_Format_Converter/BAMtoscIDXOutput.java diff --git a/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java b/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java index 6e3d028e2..4bf50d4c1 100644 --- a/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java +++ b/src/cli/BAM_Format_Converter/BAMtoscIDXCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Format_Converter.BAMtoscIDX; +import scripts.BAM_Format_Converter.BAMtoscIDX; /** BAM_Format_ConverterCLI/BAMtosciIDXCLI @@ -25,6 +25,38 @@ exitCodeOnExecutionException = 1) public class BAMtoscIDXCLI implements Callable { + @Parameters( index = "0", description = "The BAM file from which we generate a new file.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .tab ext)" ) + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "stream output file to STDOUT (cannot be used with \"-o\" flag)" ) + private boolean stdout = false; + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "output read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "output read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "output combined") + boolean combined = false; + @Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)") + boolean midpoint = false; + } + + @Option(names = {"-p", "--mate-pair"}, description = "require proper mate pair (default not required)") + private boolean matePair = false; + @Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp") + private int MIN_INSERT = -9999; + @Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp") + private int MAX_INSERT = -9999; + + private int STRAND = -9999; + private int PAIR; + @Override public Integer call() throws Exception { System.err.println( ">BAMtoscIDXCLI.call()" ); @@ -35,16 +67,71 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BAMtoscIDX script_obj = new BAMtoscIDX(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + // set strand method + if(readType.read1) { STRAND=0; } + else if(readType.read2) { STRAND=1; } + else if(readType.combined) { STRAND=2; } + else if(readType.midpoint) { STRAND=3; } + else { STRAND=0; } + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(output==null && !stdout){ + if(STRAND==0){ output = new File( bamFile.getName().split("\\.")[0] + "_READ1.tab" ); } + else if(STRAND==1){ output = new File( bamFile.getName().split("\\.")[0] + "_READ2.tab" ); } + else if(STRAND==2){ output = new File( bamFile.getName().split("\\.")[0] + "_COMBINED.tab" ); } + else if(STRAND==3){ output = new File( bamFile.getName().split("\\.")[0] + "_MIDPOINT.tab" ); } + else if(STRAND==4){ output = new File( bamFile.getName().split("\\.")[0] + "_FRAGMENT.tab" ); } + else { r += "(!)Somehow invalid STRAND!This error should never print. Check code if it does.\n"; } + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + // validate insert sizes + if( MIN_INSERT<0 && MIN_INSERT!=-9999 ){ r += "MIN_INSERT must be a positive integer value: " + MIN_INSERT + "\n"; } + if( MAX_INSERT<0 && MAX_INSERT!=-9999 ){ r += "MAX_INSERT must be a positive integer value: " + MAX_INSERT + "\n"; } + if( MAX_INSERT BP; private ArrayList F_OCC; private ArrayList R_OCC; private ArrayList M_OCC; - - private JTextArea textArea; private int CHROMSTOP = -999; - public BAMtoscIDX(File b, File o, int s, int pair_status, int min_size, int max_size) { - setTitle("BAM to scIDX Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - + public BAMtoscIDX(File b, File o, int s, int pair_status, int min_size, int max_size, PrintStream ps) { BAM = b; - OUTPUTPATH = o; + OUTFILE = o; + PS = ps; STRAND = s; PAIR = pair_status; MIN_INSERT = min_size; @@ -68,61 +52,53 @@ public BAMtoscIDX(File b, File o, int s, int pair_status, int min_size, int max_ } public void run() throws IOException, InterruptedException { - System.out.println(getTimeStamp()); - - //Open Output File - String NAME = BAM.getName().split("\\.")[0] + "_" + READ + ".tab"; - if(OUTPUTPATH != null) { - try { OUT = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { OUT = new PrintStream(new File(NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } + //Set-up Output PrintStream + if(OUTFILE!=null){ + try{ OUT = new PrintStream(OUTFILE); } + catch( FileNotFoundException e ){ e.printStackTrace(); } + printPS(OUTFILE.getCanonicalPath()); + }else{ + printPS("STDOUT"); } - - textArea.append(NAME + "\n"); - textArea.append(getTimeStamp() + "\n"); + printPS(getTimeStamp()); //Check to Make Sure BAI-index file exists File f = new File(BAM.getAbsolutePath() + ".bai"); if(f.exists() && !f.isDirectory()) { - textArea.append("-----------------------------------------\nBAM to scIDX Parameters:\n"); - textArea.append("BAM file: " + BAM + "\n"); - textArea.append("Output: " + NAME + "\n"); + //Print Input Params + printPS("-----------------------------------------\nBAM to scIDX Parameters:"); + printPS("BAM file: " + BAM); + if(OUTFILE!=null){ printPS("Output: " + OUTFILE.getName()); } + else{ printPS("Output: STDOUT"); } + + printPS("Output Read: " + READ); + if(PAIR == 0) { printPS( "Require proper Mate-pair: no"); } + else { printPS("Require proper Mate-pair: yes"); } - textArea.append("Require proper Mate-pair: "); - if(PAIR == 0) { textArea.append("no" + "\n"); } - else { textArea.append("yes" + "\n"); } + if(MIN_INSERT == -9999) { printPS("Minimum insert size required to output: NaN"); } + else { printPS("Minimum insert size required to output: " + MIN_INSERT); } - textArea.append("Output Read: " + READ + "\n"); - textArea.append("Minimum insert size required to output: "); - if(MIN_INSERT == -9999) { textArea.append("NaN\n"); } - else { textArea.append(MIN_INSERT + "\n"); } - textArea.append("Maximum insert size required to output: "); - if(MAX_INSERT == -9999) { textArea.append("NaN\n"); } - else { textArea.append(MAX_INSERT + "\n"); } + if(MAX_INSERT == -9999) { printPS("Maximum insert size required to output: NaN"); } + else { printPS("Maximum insert size required to output: " + MAX_INSERT); } //Print Header - OUT.println("#" + getTimeStamp() + ";" + BAM.getName() + ";" + READ); - if(STRAND <= 2) { OUT.println("chrom\tindex\tforward\treverse\tvalue"); } - else { OUT.println("chrom\tindex\tmidpoint\tnull\tvalue"); } + printOUT("#" + getTimeStamp() + ";" + BAM.getName() + ";" + READ); + // Here add a line as CLI command "receipt" to show command to regenerate this file + if(STRAND <= 2) { printOUT("chrom\tindex\tforward\treverse\tvalue"); } + else { printOUT("chrom\tindex\tmidpoint\tnull\tvalue"); } //Begin processing reads in BAM file if(STRAND <= 2) { processREADS(); } else { processMIDPOINT(); } - - OUT.close(); } else { - textArea.append("BAI Index File does not exist for: " + BAM.getName() + "\n"); - OUT.println("BAI Index File does not exist for: " + BAM.getName() + "\n"); + printPS("BAI Index File does not exist for: " + BAM.getName()); + printOUT("BAI Index File does not exist for: " + BAM.getName()); } - Thread.sleep(2000); - dispose(); + if(OUTFILE!=null){ OUT.close(); } - System.out.println(getTimeStamp()); + printPS(getTimeStamp()); } - + public void addTag(SAMRecord sr) { //Get the start of the record int recordStart = sr.getUnclippedStart();//.getAlignmentStart(); @@ -205,13 +181,14 @@ public void addMidTag(SAMRecord sr) { } } } + } public void dumpExcess(String chrom) { int trim = 9000; while(trim > 0) { int sum = F_OCC.get(0).intValue() + R_OCC.get(0).intValue(); - OUT.println(chrom + "\t" + BP.get(0).intValue() + "\t" + F_OCC.get(0).intValue() + "\t" + R_OCC.get(0).intValue() + "\t" + sum); + printOUT(chrom + "\t" + BP.get(0).intValue() + "\t" + F_OCC.get(0).intValue() + "\t" + R_OCC.get(0).intValue() + "\t" + sum); BP.remove(0); F_OCC.remove(0); R_OCC.remove(0); @@ -223,7 +200,7 @@ public void dumpMidExcess(String chrom) { int trim = (MAX_INSERT * 10) - (MAX_INSERT * 2); if(MAX_INSERT * 10 < 1000) { trim = 600; } while(trim > 0) { - OUT.println(chrom + "\t" + BP.get(0).intValue() + "\t" + M_OCC.get(0).intValue() + "\t0\t" + M_OCC.get(0).intValue()); + printOUT(chrom + "\t" + BP.get(0).intValue() + "\t" + M_OCC.get(0).intValue() + "\t0\t" + M_OCC.get(0).intValue()); //OUT.println(chrom + "\t" + BP.get(0).intValue() + "\t" + M_OCC.get(0).intValue()); BP.remove(0); @@ -238,8 +215,8 @@ public void processREADS() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); CHROMSTOP = seq.getSequenceLength(); BP = new ArrayList(); @@ -281,7 +258,7 @@ else if(sr.getReadPairedFlag()) { //otherwise, check for PE flag iter.close(); for(int z = 0; z < BP.size(); z++) { int sum = F_OCC.get(z).intValue() + R_OCC.get(z).intValue(); - OUT.println(seq.getSequenceName() + "\t" + BP.get(z).intValue() + "\t" + F_OCC.get(z).intValue() + "\t" + R_OCC.get(z).intValue() + "\t" + sum); + printOUT(seq.getSequenceName() + "\t" + BP.get(z).intValue() + "\t" + F_OCC.get(z).intValue() + "\t" + R_OCC.get(z).intValue() + "\t" + sum); } } bai.close(); @@ -293,8 +270,8 @@ public void processMIDPOINT() { for(int numchrom = 0; numchrom < bai.getNumberOfReferences(); numchrom++) { SAMSequenceRecord seq = inputSam.getFileHeader().getSequence(numchrom); - System.out.println("Processing: " + seq.getSequenceName()); - textArea.append("Processing: " + seq.getSequenceName() + "\n"); +// System.out.println("Processing: " + seq.getSequenceName()); + printPS("Processing: " + seq.getSequenceName()); BP = new ArrayList(); M_OCC = new ArrayList(); @@ -322,13 +299,23 @@ public void processMIDPOINT() { } iter.close(); for(int z = 0; z < BP.size(); z++) { - OUT.println(seq.getSequenceName() + "\t" + BP.get(z).intValue() + "\t" + M_OCC.get(z).intValue() + "\t0\t" + M_OCC.get(z).intValue()); + printOUT(seq.getSequenceName() + "\t" + BP.get(z).intValue() + "\t" + M_OCC.get(z).intValue() + "\t0\t" + M_OCC.get(z).intValue()); //OUT.println(seq.getSequenceName() + "\t" + BP.get(z).intValue() + "\t" + M_OCC.get(z).intValue()); } } bai.close(); } + private void printPS( String line ){ + if( PS!=null ){ PS.println(line); } + System.err.println( line ); + } + + private void printOUT( String line ){ + if( OUT!=null ){ OUT.println(line); } + else{ System.out.println( line ); } + } + private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); diff --git a/src/window_interface/BAM_Format_Converter/BAMtoscIDXOutput.java b/src/window_interface/BAM_Format_Converter/BAMtoscIDXOutput.java new file mode 100644 index 000000000..5dd198127 --- /dev/null +++ b/src/window_interface/BAM_Format_Converter/BAMtoscIDXOutput.java @@ -0,0 +1,71 @@ +package window_interface.BAM_Format_Converter; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.BAM_Format_Converter.BAMtoscIDX; + +@SuppressWarnings("serial") +public class BAMtoscIDXOutput extends JFrame { + private File BAM = null; + private File OUTPUTPATH = null; + private int STRAND = 0; + private String READ = "READ1"; + + private static int PAIR = 1; + private static int MIN_INSERT = -9999; + private static int MAX_INSERT = -9999; + + private JTextArea textArea; + + public BAMtoscIDXOutput(File b, File o, int s, int pair_status, int min_size, int max_size) { + setTitle("BAM to scIDX Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + BAM = b; + OUTPUTPATH = o; + STRAND = s; + PAIR = pair_status; + MIN_INSERT = min_size; + MAX_INSERT = max_size; + if(STRAND == 0) { READ = "READ1"; } + else if(STRAND == 1) { READ = "READ2"; } + else if(STRAND == 2) { READ = "COMBINED"; } + else if(STRAND == 3) { READ = "MIDPOINT"; } + } + + public void run() throws IOException, InterruptedException { + //Open Output File + File OUT; + String NAME = BAM.getName().split("\\.")[0] + "_" + READ + ".tab"; + if(OUTPUTPATH != null) { + OUT = new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME); + } else { + OUT = new File(NAME); + } + + //Call script here, pass in ps and OUT + PrintStream PS = new PrintStream( new CustomOutputStream(textArea) ); + PS.println(NAME); + BAMtoscIDX script_obj = new BAMtoscIDX(BAM, OUT, STRAND, PAIR, MIN_INSERT, MAX_INSERT, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Format_Converter/BAMtoscIDXWindow.java b/src/window_interface/BAM_Format_Converter/BAMtoscIDXWindow.java index 0757be14d..2606f3141 100644 --- a/src/window_interface/BAM_Format_Converter/BAMtoscIDXWindow.java +++ b/src/window_interface/BAM_Format_Converter/BAMtoscIDXWindow.java @@ -36,7 +36,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Format_Converter.BAMtoscIDX; +import window_interface.BAM_Format_Converter.BAMtoscIDXOutput; @SuppressWarnings("serial") public class BAMtoscIDXWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -91,7 +91,7 @@ public Void doInBackground() throws IOException, InterruptedException { if(chckbxFilterByMaximum.isSelected()) { MAX = Integer.parseInt(txtMax.getText()); } for(int x = 0; x < BAMFiles.size(); x++) { - BAMtoscIDX convert = new BAMtoscIDX(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); + BAMtoscIDXOutput convert = new BAMtoscIDXOutput(BAMFiles.get(x), OUTPUT, STRAND, PAIR, MIN, MAX); convert.setVisible(true); convert.run(); int percentComplete = (int)(((double)(x + 1) / BAMFiles.size()) * 100); From 9172b9f9bdf087d660abd93ce9746d486d879c0e Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:09:53 -0400 Subject: [PATCH 08/43] fix stripExtension method to avoid exception The prior method for stripping extensions from filenames would throw a java.lang.StringIndexOutOfBoundsException if the File object input had a name without any periods in it. This method for stripping off the extension avoids this. --- src/util/ExtensionFileFilter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/ExtensionFileFilter.java b/src/util/ExtensionFileFilter.java index a64552306..ff7045ec3 100644 --- a/src/util/ExtensionFileFilter.java +++ b/src/util/ExtensionFileFilter.java @@ -42,8 +42,12 @@ public static String getExtension(File f) { } public static String stripExtension(File f) throws IOException { - String NAME = f.getName(); - return(NAME.substring(0, NAME.lastIndexOf('.'))); + String[] name = f.getName().split("\\."); + String NEWNAME = name[0]; + for(int x = 1; x < name.length-1; x++) { + NEWNAME += ("." + name[x]); + } + return(NEWNAME); } public static String stripExtensionPath(File f) throws IOException { From 39cb2772bb2ab727c852b44a9af4d0c9585698ae Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:17:59 -0400 Subject: [PATCH 09/43] create FilterforPIPseq command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/FilterforPIPseqOutput class while the calculations are kept in the src/scripts/*/FilterforPIPseq class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../BAM_Manipulation/FilterforPIPseqCLI.java | 78 +++++++++- .../BAM_Manipulation/FilterforPIPseq.java | 137 +++++++----------- .../FilterforPIPseqOutput.java | 68 +++++++++ .../FilterforPIPseqWindow.java | 4 +- 4 files changed, 196 insertions(+), 91 deletions(-) create mode 100644 src/window_interface/BAM_Manipulation/FilterforPIPseqOutput.java diff --git a/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java b/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java index a1807c8a5..170fb7ea6 100644 --- a/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java +++ b/src/cli/BAM_Manipulation/FilterforPIPseqCLI.java @@ -15,7 +15,7 @@ import objects.ToolDescriptions; import util.FASTAUtilities; import util.ExtensionFileFilter; -//import scripts.BAM_Manipulation.FilterforPIPseq; +import scripts.BAM_Manipulation.FilterforPIPseq; /** BAM_ManipulatioCLIn/FilterforPIPseqCLI @@ -28,6 +28,16 @@ exitCodeOnExecutionException = 1) public class FilterforPIPseqCLI implements Callable { + @Parameters( index = "0", description = "The reference genome FASTA file.") + private File genomeFASTA; + @Parameters( index = "1", description = "The BAM file from which we filter.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output file (default=_PSfilter.bam)") + private File output = null; + @Option(names = {"-f", "--filter"}, description = "filter by upstream sequence, works only for single-nucleotide A,T,C, or G. (default seq ='T')") + private String filterString = "T"; + @Override public Integer call() throws Exception { System.err.println( ">FilterforPIPseqCLI.call()" ); @@ -38,16 +48,72 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + FilterforPIPseq script_obj = new FilterforPIPseq(bamFile, genomeFASTA, output, filterString, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println( "BAM Generated." ); return(0); } + //validateInput outline private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bamFile.exists()){ + r += "(!)BAM file does not exist: " + bamFile.getName() + "\n"; + } + if(!genomeFASTA.exists()){ + r += "(!)FASTA file does not exist: " + genomeFASTA.getName() + "\n"; + } + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //check FAI exists (generate if not) + File FAI = new File(genomeFASTA + ".fai"); + if(!FAI.exists() || FAI.isDirectory()) { + System.err.println("FASTA Index file not found.\nGenerating new one...\n"); + boolean FASTA_INDEX = FASTAUtilities.buildFASTAIndex(genomeFASTA); + if(!FASTA_INDEX){ r += "FASTA Index failed to build."; } + } + //set default output filename + if(output==null){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //check filter string is valid ATCG + Pattern seqPat = Pattern.compile("[ATCG]"); + Matcher m = seqPat.matcher( filterString ); + if( !m.matches() ){ + r += "(!)Filter string must be formatted as a nucleotide sequence.\n" + filterString + + " is not a valid nucleotide sequence.\nExpected input string format: \"[ATCG]\""; + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/BAM_Manipulation/FilterforPIPseq.java b/src/scripts/BAM_Manipulation/FilterforPIPseq.java index 93186ddde..74544a25e 100644 --- a/src/scripts/BAM_Manipulation/FilterforPIPseq.java +++ b/src/scripts/BAM_Manipulation/FilterforPIPseq.java @@ -12,119 +12,90 @@ import htsjdk.samtools.util.CloseableIterator; import htsjdk.samtools.util.IOUtil; -import java.awt.BorderLayout; import java.io.File; import java.io.IOException; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; +import java.io.PrintStream; import util.FASTAUtilities; @SuppressWarnings("serial") -public class FilterforPIPseq extends JFrame { +public class FilterforPIPseq { File bamFile = null; File genome = null; File output = null; String SEQ = ""; - boolean FASTA_INDEX = true; - - private JTextArea textArea; + private PrintStream PS; - public FilterforPIPseq(File in, File gen, File out, String s) { - setTitle("Permanganate-Seq Filtering Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - + public FilterforPIPseq(File in, File gen, File out, String s, PrintStream ps) { bamFile = in; genome = gen; output = out; SEQ = s.toUpperCase(); + PS = ps; } public void run() throws IOException, InterruptedException { - File FAI = new File(genome + ".fai"); - //Check if FAI index file exists - if(!FAI.exists() || FAI.isDirectory()) { - textArea.append("FASTA Index file not found.\nGenerating new one...\n"); - FASTA_INDEX = FASTAUtilities.buildFASTAIndex(genome); - } + IndexedFastaSequenceFile QUERY = new IndexedFastaSequenceFile(genome); - //Check if BAI index file exists - File f = new File(bamFile + ".bai"); - if(f.exists() && !f.isDirectory()) { - IndexedFastaSequenceFile QUERY = new IndexedFastaSequenceFile(genome); - - IOUtil.assertFileIsReadable(bamFile); - IOUtil.assertFileIsWritable(output); - final SamReader reader = SamReaderFactory.makeDefault().open(bamFile); - reader.getFileHeader().setSortOrder(SAMFileHeader.SortOrder.coordinate); - final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), false, output); - - textArea.append(bamFile.getName() + "\n"); //output file name to textarea - - //Code to get individual chromosome stats - AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); - for (int z = 0; z < bai.getNumberOfReferences(); z++) { - SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); - System.out.println(seq.getSequenceName()); - textArea.append(seq.getSequenceName() + "\n"); - - CloseableIterator iter = reader.query(seq.getSequenceName(), 0, seq.getSequenceLength(), false); - while (iter.hasNext()) { - //Create the record object - SAMRecord sr = iter.next(); - if(sr.getReadPairedFlag()) { - if(sr.getProperPairFlag() && sr.getFirstOfPairFlag()) { - String filter = ""; - //if on the positive strand - if(!sr.getReadNegativeStrandFlag()) { - if(sr.getUnclippedStart() - 1 > 0) { filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedStart() - 1, sr.getUnclippedStart() - 1).getBases()); } - } - else { - if(sr.getUnclippedEnd() + 1 <= seq.getSequenceLength()) { - filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedEnd() + 1, sr.getUnclippedEnd() + 1).getBases()); - filter = FASTAUtilities.RevComplement(filter); - } - } - //System.out.println(sr.getReadString() + "\t" + seq.getSequenceName() + "\t" + sr.getUnclippedStart() + "\t" + sr.getUnclippedEnd() + "\t" + sr.getReadNegativeStrandFlag() + "\t" + filter); - if(filter.toUpperCase().equals(SEQ)) { writer.addAlignment(sr); } - } - } else { + IOUtil.assertFileIsReadable(bamFile); + IOUtil.assertFileIsWritable(output); + final SamReader reader = SamReaderFactory.makeDefault().open(bamFile); + reader.getFileHeader().setSortOrder(SAMFileHeader.SortOrder.coordinate); + final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), false, output); + + printBoth(bamFile.getName()); //output file name to textarea + + //Code to get individual chromosome stats + AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); + for (int z = 0; z < bai.getNumberOfReferences(); z++) { + SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); + printBoth(seq.getSequenceName()); + + CloseableIterator iter = reader.query(seq.getSequenceName(), 0, seq.getSequenceLength(), false); + while (iter.hasNext()) { + //Create the record object + SAMRecord sr = iter.next(); + if(sr.getReadPairedFlag()) { + if(sr.getProperPairFlag() && sr.getFirstOfPairFlag()) { String filter = ""; //if on the positive strand if(!sr.getReadNegativeStrandFlag()) { - filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedStart() - 1, sr.getUnclippedStart() - 1).getBases()); + if(sr.getUnclippedStart() - 1 > 0) { filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedStart() - 1, sr.getUnclippedStart() - 1).getBases()); } } else { - filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedEnd() + 1, sr.getUnclippedEnd() + 1).getBases()); - filter = FASTAUtilities.RevComplement(filter); + if(sr.getUnclippedEnd() + 1 <= seq.getSequenceLength()) { + filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedEnd() + 1, sr.getUnclippedEnd() + 1).getBases()); + filter = FASTAUtilities.RevComplement(filter); + } } //System.out.println(sr.getReadString() + "\t" + seq.getSequenceName() + "\t" + sr.getUnclippedStart() + "\t" + sr.getUnclippedEnd() + "\t" + sr.getReadNegativeStrandFlag() + "\t" + filter); - if(filter.toUpperCase().equals(SEQ)) { writer.addAlignment(sr); } + if(filter.toUpperCase().equals(SEQ)) { writer.addAlignment(sr); } + } + } else { + String filter = ""; + //if on the positive strand + if(!sr.getReadNegativeStrandFlag()) { + filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedStart() - 1, sr.getUnclippedStart() - 1).getBases()); } + else { + filter = new String(QUERY.getSubsequenceAt(seq.getSequenceName(), sr.getUnclippedEnd() + 1, sr.getUnclippedEnd() + 1).getBases()); + filter = FASTAUtilities.RevComplement(filter); + } + //System.out.println(sr.getReadString() + "\t" + seq.getSequenceName() + "\t" + sr.getUnclippedStart() + "\t" + sr.getUnclippedEnd() + "\t" + sr.getReadNegativeStrandFlag() + "\t" + filter); + if(filter.toUpperCase().equals(SEQ)) { writer.addAlignment(sr); } } - iter.close(); } - QUERY.close(); - writer.close(); - reader.close(); - bai.close(); - - Thread.sleep(2000); - dispose(); - } else { - JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + bamFile.getName() + "\n"); + iter.close(); } + QUERY.close(); + writer.close(); + reader.close(); + bai.close(); + } + + private void printBoth(String message){ + if(PS!=null){ PS.println(message); } + System.err.println(message); } } diff --git a/src/window_interface/BAM_Manipulation/FilterforPIPseqOutput.java b/src/window_interface/BAM_Manipulation/FilterforPIPseqOutput.java new file mode 100644 index 000000000..290d97324 --- /dev/null +++ b/src/window_interface/BAM_Manipulation/FilterforPIPseqOutput.java @@ -0,0 +1,68 @@ +package window_interface.BAM_Manipulation; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import util.FASTAUtilities; +import objects.CustomOutputStream; +import scripts.BAM_Manipulation.FilterforPIPseq; + +@SuppressWarnings("serial") +public class FilterforPIPseqOutput extends JFrame { + File bamFile = null; + File genome = null; + File output = null; + String SEQ = ""; + + private JTextArea textArea; + + public FilterforPIPseqOutput(File in, File gen, File out, String s) { + setTitle("Permanganate-Seq Filtering Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + bamFile = in; + genome = gen; + output = out; + SEQ = s.toUpperCase(); + } + + public void run() throws IOException, InterruptedException { + + PrintStream PS = new PrintStream(new CustomOutputStream(textArea)); + + File FAI = new File(genome + ".fai"); + //Check if FAI index file exists + if(!FAI.exists() || FAI.isDirectory()) { + PS.println("FASTA Index file not found.\nGenerating new one..."); + boolean tempBool = FASTAUtilities.buildFASTAIndex(genome); + } + + //Check if BAI index file exists + File f = new File(bamFile + ".bai"); + if(f.exists() && !f.isDirectory()) { + + FilterforPIPseq script_obj = new FilterforPIPseq(bamFile, genome, output, SEQ, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } else { + JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + bamFile.getName() + "\n"); + } + } +} diff --git a/src/window_interface/BAM_Manipulation/FilterforPIPseqWindow.java b/src/window_interface/BAM_Manipulation/FilterforPIPseqWindow.java index 1f19de707..a477dc692 100644 --- a/src/window_interface/BAM_Manipulation/FilterforPIPseqWindow.java +++ b/src/window_interface/BAM_Manipulation/FilterforPIPseqWindow.java @@ -34,7 +34,7 @@ import util.FileSelection; import util.FASTAUtilities; import scripts.BAM_Manipulation.BAIIndexer; -import scripts.BAM_Manipulation.FilterforPIPseq; +import window_interface.BAM_Manipulation.FilterforPIPseqOutput; @SuppressWarnings("serial") public class FilterforPIPseqWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -73,7 +73,7 @@ public Void doInBackground() throws Exception { File OUTPUT = null; if(OUTPUT_PATH != null) { OUTPUT = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME[0] + "_PSfilter.bam"); } else { OUTPUT = new File(NAME[0] + "_PSfilter.bam"); } - FilterforPIPseq filter = new FilterforPIPseq(BAMFiles.get(x), GENOME, OUTPUT, txtSeq.getText()); + FilterforPIPseqOutput filter = new FilterforPIPseqOutput(BAMFiles.get(x), GENOME, OUTPUT, txtSeq.getText()); filter.setVisible(true); filter.run(); From 132d4bcf6d838ab0f9472cf8b9a6fff7b741f71d Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:24:18 -0400 Subject: [PATCH 10/43] write up cli help message for BAIIndexer redirect This tool was originally written as a wrapper for an existing CLI tool so this commit just writes up the help message if a user attempts to execute this tool from the command line. The help message will redirect the user to the `samtools index` command. --- src/cli/BAM_Manipulation/BAIIndexerCLI.java | 24 ++++----------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/cli/BAM_Manipulation/BAIIndexerCLI.java b/src/cli/BAM_Manipulation/BAIIndexerCLI.java index 5d06696da..f336f468b 100644 --- a/src/cli/BAM_Manipulation/BAIIndexerCLI.java +++ b/src/cli/BAM_Manipulation/BAIIndexerCLI.java @@ -3,7 +3,6 @@ import picocli.CommandLine; import picocli.CommandLine.Command; -import java.io.IOException; import java.util.concurrent.Callable; import objects.ToolDescriptions; @@ -20,24 +19,9 @@ public class BAIIndexerCLI implements Callable { @Override public Integer call() throws Exception { - System.err.println( ">BAIIndexerCLI.call()" ); - String validate = validateInput(); - if(!validate.equals("")){ - System.err.println( validate ); - System.err.println("Invalid input. Check usage using '-h' or '--help'"); - System.exit(1); - } - - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); - return(0); - } - - private String validateInput() throws IOException { - String r = ""; - //validate input here - //append messages to the user to `r` - return(r); + System.err.println("***Please use the original tool for this job***\n"+ + "\t'samtools index '"); + System.exit(1); + return(1); } } \ No newline at end of file From a5521e4d14af074f06b8d7295ec24066e7cf0a05 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:28:15 -0400 Subject: [PATCH 11/43] write up cli help message for BAMDeDuplication redirect This tool was originally written as a wrapper for an existing CLI tool so this commit just writes up the help message if a user attempts to execute this tool from the command line. The help message will redirect the user to Picard's MarkDuplicates tool. --- src/cli/BAM_Manipulation/BAMRemoveDupCLI.java | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java b/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java index 2d9032c95..d8de913cc 100644 --- a/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java +++ b/src/cli/BAM_Manipulation/BAMRemoveDupCLI.java @@ -3,7 +3,6 @@ import picocli.CommandLine; import picocli.CommandLine.Command; -import java.io.IOException; import java.util.concurrent.Callable; import objects.ToolDescriptions; @@ -21,24 +20,10 @@ public class BAMRemoveDupCLI implements Callable { @Override public Integer call() throws Exception { - System.err.println( ">BAMRemoveDupCLI.call()" ); - String validate = validateInput(); - if(!validate.equals("")){ - System.err.println( validate ); - System.err.println("Invalid input. Check usage using '-h' or '--help'"); - System.exit(1); - } - - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); - return(0); - } - - private String validateInput() throws IOException { - String r = ""; - //validate input here - //append messages to the user to `r` - return(r); + System.err.println("***Please use the original tool for this job***\n"+ + "\t'java -jar picard.jar MarkDuplicates I= O='\n"+ + "\t'samtools view -F 1024 > '" ); + System.exit(1); + return(1); } } \ No newline at end of file From 97bc6ff8afda806bb7f6ec2cbd6e0aac4ae91740 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:32:47 -0400 Subject: [PATCH 12/43] write up cli help message for MergeSamFiles redirect This tool was originally written as a wrapper for an existing CLI tool so this commit just writes up the help message if a user attempts to execute this tool from the command line. The help message will redirect the user to Picard's MergeSamFiles tool --- src/cli/BAM_Manipulation/MergeBAMCLI.java | 24 ++++------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/cli/BAM_Manipulation/MergeBAMCLI.java b/src/cli/BAM_Manipulation/MergeBAMCLI.java index e0e3ef129..19936fca9 100644 --- a/src/cli/BAM_Manipulation/MergeBAMCLI.java +++ b/src/cli/BAM_Manipulation/MergeBAMCLI.java @@ -3,7 +3,6 @@ import picocli.CommandLine; import picocli.CommandLine.Command; -import java.io.IOException; import java.util.concurrent.Callable; import objects.ToolDescriptions; @@ -20,24 +19,9 @@ public class MergeBAMCLI implements Callable { @Override public Integer call() throws Exception { - System.err.println( ">MergeBAMCLI.call()" ); - String validate = validateInput(); - if(!validate.equals("")){ - System.err.println( validate ); - System.err.println("Invalid input. Check usage using '-h' or '--help'"); - System.exit(1); - } - - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); - return(0); - } - - private String validateInput() throws IOException { - String r = ""; - //validate input here - //append messages to the user to `r` - return(r); + System.err.println("***Please use the original tool for this job***\n"+ + "\t'java -jar picard.jar MergeSamFiles'"); + System.exit(1); + return(1); } } \ No newline at end of file From f186beae57bc11c50dce42ced1e310f5f9f0cedb Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 17:49:11 -0400 Subject: [PATCH 13/43] write up cli help message for BAMFileSort redirect This tool was originally written as a wrapper for an existing CLI tool so this commit just writes up the help message if a user attempts to execute this tool from the command line. The help message will redirect the user to the `samtools sort` command --- src/cli/BAM_Manipulation/SortBAMCLI.java | 26 +++++------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/cli/BAM_Manipulation/SortBAMCLI.java b/src/cli/BAM_Manipulation/SortBAMCLI.java index 51b3c1707..77d175b7f 100644 --- a/src/cli/BAM_Manipulation/SortBAMCLI.java +++ b/src/cli/BAM_Manipulation/SortBAMCLI.java @@ -3,7 +3,6 @@ import picocli.CommandLine; import picocli.CommandLine.Command; -import java.io.IOException; import java.util.concurrent.Callable; import objects.ToolDescriptions; @@ -20,24 +19,9 @@ public class SortBAMCLI implements Callable { @Override public Integer call() throws Exception { - System.err.println( ">SortBAMCLI.call()" ); - String validate = validateInput(); - if(!validate.equals("")){ - System.err.println( validate ); - System.err.println("Invalid input. Check usage using '-h' or '--help'"); - System.exit(1); - } - - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); - return(0); + System.err.println("***Please use the original tool for this job***\n"+ + "\t'samtools sort -o '"); + System.exit(1); + return(1); } - - private String validateInput() throws IOException { - String r = ""; - //validate input here - //append messages to the user to `r` - return(r); - } -} \ No newline at end of file +} From 6385bd7ddb05bbae20d97f4ac826622342f6d6d2 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 18:12:47 -0400 Subject: [PATCH 14/43] create SEStats command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/SEStatOutput class while the calculations are kept in the src/scripts/*/SEStats class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/BAM_Statistics/SEStatsCLI.java | 46 ++++- src/scripts/BAM_Statistics/SEStats.java | 182 +++++++----------- .../BAM_Statistics/SEStatOutput.java | 76 ++++++++ .../BAM_Statistics/SEStatWindow.java | 19 +- 4 files changed, 192 insertions(+), 131 deletions(-) create mode 100644 src/window_interface/BAM_Statistics/SEStatOutput.java diff --git a/src/cli/BAM_Statistics/SEStatsCLI.java b/src/cli/BAM_Statistics/SEStatsCLI.java index 892c99b2f..7cd18474a 100644 --- a/src/cli/BAM_Statistics/SEStatsCLI.java +++ b/src/cli/BAM_Statistics/SEStatsCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Statistics.SEStats; +import scripts.BAM_Statistics.SEStats; /** BAM_StatisticsCLI/SEStatsCLI @@ -25,6 +25,12 @@ exitCodeOnExecutionException = 1) public class SEStatsCLI implements Callable { + @Parameters( index = "0", description = "The BAM file whose statistics we want.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "Specify output file ") + private File output; + @Override public Integer call() throws Exception { System.err.println( ">SEStatsCLI.call()" ); @@ -35,16 +41,44 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + SEStats.getSEStats( output, bamFile, null ); - //System.err.println("Calculations Complete"); + System.err.println("Calculations Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(output==null){ +// output = new File("output_bam_stats.txt"); //this default name mimics the gui + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/BAM_Statistics/SEStats.java b/src/scripts/BAM_Statistics/SEStats.java index e0c662d3b..d2ffbe79a 100644 --- a/src/scripts/BAM_Statistics/SEStats.java +++ b/src/scripts/BAM_Statistics/SEStats.java @@ -10,141 +10,95 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; -import java.net.URISyntaxException; import java.sql.Timestamp; import java.util.Date; import java.util.Vector; -import javax.swing.JFrame; -import javax.swing.JScrollPane; - -import java.awt.BorderLayout; - -import javax.swing.JTextArea; - -@SuppressWarnings("serial") -public class SEStats extends JFrame { - Vector bamFiles = null; - File output = null; - //SAMFileReader reader; - - final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - SamReader reader; - PrintStream OUT = null; +public class SEStats { - private JTextArea textArea; - - public SEStats(Vector input, File o) { - setTitle("BAM File Statistics"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - bamFiles = input; - output = o; + public static void getSEStats( File out_filepath, File bamFile, PrintStream ps ) { - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - } - - public void run() { + final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - if(output != null) { + //Check and set output files (STDOUT if not specified) + PrintStream OUT = null; + if(out_filepath != null) { try { - OUT = new PrintStream(output); + OUT = new PrintStream(out_filepath); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - } + }else{ OUT = System.out; } + //Print TimeStamp String time = getTimeStamp(); - if(OUT != null) OUT.println(time); - textArea.append(time + "\n"); + printBoth( ps, OUT, time ); - for(int x = 0; x < bamFiles.size(); x++) { - //Check if BAI index file exists - File f = new File(bamFiles.get(x) + ".bai"); - if(f.exists() && !f.isDirectory()) { - if(OUT != null) OUT.println(bamFiles.get(x).getName()); - if(OUT != null) OUT.println("Chromosome_ID\tChromosome_Size\tAligned_Reads\tUnaligned_Reads"); - textArea.append(bamFiles.get(x).getName() + "\n"); - textArea.append("Chromosome_ID\tChromosome_Size\tAligned_Reads\tUnaligned_Reads\n"); - - //Code to get individual chromosome stats - //reader = new SamReader(bamFiles.get(x), new File(bamFiles.get(x) + ".bai")); - reader = factory.open(bamFiles.get(x)); - - AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); - double totalTags = 0; - double totalGenome = 0; + //Check if BAI index file exists + File f = new File(bamFile + ".bai"); + if(f.exists() && !f.isDirectory()) { - for (int z = 0; z < bai.getNumberOfReferences(); z++) { - SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); - double aligned = reader.indexing().getIndex().getMetaData(z).getAlignedRecordCount(); - double unaligned = reader.indexing().getIndex().getMetaData(z).getUnalignedRecordCount(); - if(OUT != null) OUT.println(seq.getSequenceName() + "\t" + seq.getSequenceLength() + "\t" + aligned + "\t" + unaligned); - textArea.append(seq.getSequenceName() + "\t" + seq.getSequenceLength() + "\t" + aligned + "\t" + unaligned + "\n"); - totalTags += aligned; - totalGenome += seq.getSequenceLength(); - } - - if(OUT != null) OUT.println("Total Genome Size: " + totalGenome + "\tTotal Aligned Tags: " + totalTags + "\n"); - textArea.append("Total Genome Size: " + totalGenome + "\tTotal Aligned Tags: " + totalTags + "\n\n"); - - //Output replicates used to make bam file - for( String comment : reader.getFileHeader().getComments()) { - if(OUT != null) OUT.println(comment); - textArea.append(comment + "\n"); - } - - //Output program used to align bam file - for (int z = 0; z < reader.getFileHeader().getProgramRecords().size(); z++) { - if(OUT != null) { - OUT.print(reader.getFileHeader().getProgramRecords().get(z).getId() + "\t"); - OUT.println(reader.getFileHeader().getProgramRecords().get(z).getProgramVersion()); - OUT.println(reader.getFileHeader().getProgramRecords().get(z).getCommandLine()); - } - textArea.append(reader.getFileHeader().getProgramRecords().get(z).getId() + "\t"); - textArea.append(reader.getFileHeader().getProgramRecords().get(z).getProgramVersion() + "\n"); - textArea.append(reader.getFileHeader().getProgramRecords().get(z).getCommandLine() + "\n"); - } - - if(OUT != null) OUT.println(); - textArea.append("\n"); - - try { - reader.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - bai.close(); - - } else { - if(OUT != null) OUT.println("BAI Index File does not exist for: " + bamFiles.get(x).getName() + "\n"); - textArea.append("BAI Index File does not exist for: " + bamFiles.get(x).getName() + "\n\n"); + printBoth( ps, OUT, bamFile.getName() ); + printBoth( ps, OUT, "Chromosome_ID\tChromosome_Size\tAligned_Reads\tUnaligned_Reads" ); + + //Code to get individual chromosome stats + //reader = new SamReader(bamFiles.get(x), new File(bamFiles.get(x) + ".bai")); + SamReader reader = factory.open(bamFile); + + AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); + double totalTags = 0; + double totalGenome = 0; + + for (int z = 0; z < bai.getNumberOfReferences(); z++) { + SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); + double aligned = reader.indexing().getIndex().getMetaData(z).getAlignedRecordCount(); + double unaligned = reader.indexing().getIndex().getMetaData(z).getUnalignedRecordCount(); + printBoth( ps, OUT, seq.getSequenceName() + "\t" + seq.getSequenceLength() + "\t" + aligned + "\t" + unaligned ); + totalTags += aligned; + totalGenome += seq.getSequenceLength(); + } + + printBoth( ps, OUT, "Total Genome Size: " + totalGenome + "\tTotal Aligned Tags: " + totalTags + "\n" ); + + //Output replicates used to make bam file + for( String comment : reader.getFileHeader().getComments()) { printBoth( ps, OUT, comment ); } + + //Output program used to align bam file + for (int z = 0; z < reader.getFileHeader().getProgramRecords().size(); z++) { + printBoth( ps, OUT, reader.getFileHeader().getProgramRecords().get(z).getId() + "\t" + + reader.getFileHeader().getProgramRecords().get(z).getProgramVersion() ); + printBoth( ps, OUT, reader.getFileHeader().getProgramRecords().get(z).getCommandLine() ); + } + + printBoth( ps, OUT, "" ); + + try { + reader.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - } - if(OUT != null) OUT.close(); + bai.close(); + + //Print message reminder to index BAM files + } else { printBoth( ps, OUT, "BAI Index File does not exist for: " + bamFile.getName() + "\n" ); } + + if(out_filepath != null) OUT.close(); //BAMIndexMetaData.printIndexStats(bamFiles.get(x)) + } + + //Helper method to de-clutter method above: + //Prints output to both pop-up window (for GUI) and output file (GUI and CLI) + private static void printBoth( PrintStream p, PrintStream out, String line ){ + out.println( line ); + if( p != null ){ p.println( line ); } } - + + //Returns Timestamp for printing to the output private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); return time; } - - public static void main(String[] args) { - System.out.print("java -cp "); - //Output full path of ScriptManager - try { System.out.print(new File(SEStats.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()); } - catch (URISyntaxException e) { e.printStackTrace(); } - System.out.println(" scripts.BAM_Statistics.SEStats"); - } -} +} \ No newline at end of file diff --git a/src/window_interface/BAM_Statistics/SEStatOutput.java b/src/window_interface/BAM_Statistics/SEStatOutput.java new file mode 100644 index 000000000..4232e0781 --- /dev/null +++ b/src/window_interface/BAM_Statistics/SEStatOutput.java @@ -0,0 +1,76 @@ +package window_interface.BAM_Statistics; + +import htsjdk.samtools.AbstractBAMFileIndex; +import htsjdk.samtools.SAMSequenceRecord; +import htsjdk.samtools.SamReader; +import htsjdk.samtools.SamReaderFactory; +import htsjdk.samtools.ValidationStringency; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URISyntaxException; +import java.util.Vector; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.BAM_Statistics.SEStats; + +@SuppressWarnings("serial") +public class SEStatOutput extends JFrame { + Vector bamFiles = null; + File output = null; + + PrintStream OUT = null; + + private JTextArea textArea; + private PrintStream jtxtPrintStream; + + public SEStatOutput(Vector input, File o) { + setTitle("BAM File Statistics"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + bamFiles = input; + output = o; + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + jtxtPrintStream = new PrintStream( new CustomOutputStream(textArea) ); + } + + public void run() { + if(output != null) { + try { + OUT = new PrintStream(output); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + // Execute on each BAM file in the list + for(int x = 0; x < bamFiles.size(); x++) { + // Use script and pass PrintStream object that sends to JTextArea + SEStats.getSEStats( output, bamFiles.get(x), jtxtPrintStream ); + } + if(output != null) OUT.close(); + //BAMIndexMetaData.printIndexStats(bamFiles.get(x)) + } + + public static void main(String[] args) { + System.out.print("java -cp "); + //Output full path of ScriptManager + try { System.out.print(new File(SEStats.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath()); } + catch (URISyntaxException e) { e.printStackTrace(); } + System.out.println(" scripts.BAM_Statistics.SEStats"); + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Statistics/SEStatWindow.java b/src/window_interface/BAM_Statistics/SEStatWindow.java index 152c23b09..119534f32 100644 --- a/src/window_interface/BAM_Statistics/SEStatWindow.java +++ b/src/window_interface/BAM_Statistics/SEStatWindow.java @@ -24,7 +24,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Statistics.SEStats; +import window_interface.BAM_Statistics.SEStatOutput; @SuppressWarnings("serial") public class SEStatWindow extends JFrame { @@ -67,7 +67,7 @@ public SEStatWindow() { public void actionPerformed(ActionEvent e) { File[] newBAMFiles = FileSelection.getFiles(fc,"bam"); if(newBAMFiles != null) { - for(int x = 0; x < newBAMFiles.length; x++) { + for(int x = 0; x < newBAMFiles.length; x++) { BAMFiles.add(newBAMFiles[x]); expList.addElement(newBAMFiles[x].getName()); } @@ -105,7 +105,7 @@ public void actionPerformed(ActionEvent arg0) { txtOutputName = new JTextField(); sl_contentPane.putConstraint(SpringLayout.NORTH, txtOutputName, -2, SpringLayout.NORTH, lblOutputName); sl_contentPane.putConstraint(SpringLayout.WEST, txtOutputName, 6, SpringLayout.EAST, lblOutputName); - txtOutputName.setText("output_bam stats.txt"); + txtOutputName.setText("output_bam_stats.txt"); txtOutputName.setColumns(10); txtOutputName.setEnabled(false); contentPane.add(txtOutputName); @@ -166,18 +166,15 @@ public void itemStateChanged(ItemEvent e) { sl_contentPane.putConstraint(SpringLayout.EAST, btnRun, -171, SpringLayout.EAST, contentPane); btnRun.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - SEStats stat; + SEStatOutput stat; if(chckbxOutputStatistics.isSelected()) { - if(OUTPUT_PATH != null) { stat = new SEStats(BAMFiles, new File(OUTPUT_PATH + File.separator + txtOutputName.getText())); } - else { stat = new SEStats(BAMFiles, new File(txtOutputName.getText())); } - } else { stat = new SEStats(BAMFiles, null); } + if(OUTPUT_PATH != null) { stat = new SEStatOutput(BAMFiles, new File(OUTPUT_PATH + File.separator + txtOutputName.getText())); } + else { stat = new SEStatOutput(BAMFiles, new File(txtOutputName.getText())); } + } else { stat = new SEStatOutput(BAMFiles, null); } stat.setVisible(true); stat.run(); } }); contentPane.add(btnRun); } -} - - - +} \ No newline at end of file From 9ff5d51e4e6ed335f2b68683e2b7ac203f8f6ef2 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 18:26:52 -0400 Subject: [PATCH 15/43] add createLineChart() method for that saves PNG This method was added to be used by BAM_Statistics/PEStat to save the duplication graph output as a PNG if a non-null filename is indicated. This is for the CLI implementation of saving the duplication figures shown in the GUI version. --- src/charts/LineChart.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/charts/LineChart.java b/src/charts/LineChart.java index 4422e0aeb..f7a69e4d6 100644 --- a/src/charts/LineChart.java +++ b/src/charts/LineChart.java @@ -1,11 +1,13 @@ package charts; import java.awt.Color; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; @@ -45,6 +47,24 @@ public static ChartPanel createLineChart(ArrayList y1, ArrayList return chartPanel; } + public static ChartPanel createLineChart(ArrayList y, String[] x, File output) throws IOException { + DefaultCategoryDataset dataset = new DefaultCategoryDataset(); + for(int i = 0; i < x.length; i++) { + dataset.addValue(y.get(i).doubleValue(), "Duplication Rate", x[i]); + } + + JFreeChart chart = createChart(dataset); + final ChartPanel chartPanel = new ChartPanel(chart); + chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); + + if(output != null) { + int width = 640; + int height = 480; + ChartUtilities.saveChartAsPNG(output, chart, width, height); + } + return chartPanel; + } + private static JFreeChart createChart(CategoryDataset dataset) throws IOException { final JFreeChart chart = ChartFactory.createLineChart( "Paired-End Duplication Rate", // chart title From 7c1ec84856ee748bee4a2f98b1acfa21ee5a471c Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 18:45:05 -0400 Subject: [PATCH 16/43] create PEStats command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/PEStatsOutput class while the calculations are kept in the src/scripts/*/PEStats class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/BAM_Statistics/PEStatsCLI.java | 60 ++- src/scripts/BAM_Statistics/PEStats.java | 441 ++++++++---------- .../BAM_Statistics/PEStatOutput.java | 126 +++++ .../BAM_Statistics/PEStatWindow.java | 4 +- 4 files changed, 379 insertions(+), 252 deletions(-) create mode 100644 src/window_interface/BAM_Statistics/PEStatOutput.java diff --git a/src/cli/BAM_Statistics/PEStatsCLI.java b/src/cli/BAM_Statistics/PEStatsCLI.java index 4f2425675..0122ed90a 100644 --- a/src/cli/BAM_Statistics/PEStatsCLI.java +++ b/src/cli/BAM_Statistics/PEStatsCLI.java @@ -11,7 +11,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Statistics.PEStats; +import scripts.BAM_Statistics.PEStats; /** BAM_StatisticsCLI/PEStatsCLI @@ -23,6 +23,21 @@ exitCodeOnExecutionException = 1) public class PEStatsCLI implements Callable { + @Parameters( index = "0", description = "The BAM file whose statistics we want.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "specify output basename, default is the BAM input filename without extension") + private File outputBasename = null; + + @Option(names = {"-n", "--min"}, description = "histogram range minimum (0 default)") + private int MIN_INSERT = 0; + @Option(names = {"-x", "--max"}, description = "histogram range maximum (1000 default)") + private int MAX_INSERT = 1000; + @Option(names = {"-s", "--summary"}, description = "write summary of insert histogram by chromosome (default false)") + private boolean sum = false; + @Option(names = {"-d", "--duplication-stats"}, description = "calculate duplication statistics if this flag is used (default false)") + private boolean dup = false; + @Override public Integer call() throws Exception { System.err.println( ">PEStatsCLI.call()" ); @@ -33,16 +48,49 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + PEStats.getPEStats( outputBasename, bamFile, dup, MIN_INSERT, MAX_INSERT, null, null, sum); - //System.err.println("Calculations Complete"); + System.err.println("Calculations Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bamFile.exists()){ + 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()){ + r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; + } + //set default output filename + if(outputBasename==null){ +// output = new File("output_bam_stats.txt"); //this default name mimics the gui + 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"); + } else if(!new File(outputBasename.getParent()).exists()){ + r += "(!)Check output directory exists: " + outputBasename.getParent() + "\n"; + } + } + + //validate insert sizes + if(MIN_INSERT<0){ r += "(!)MIN_INSERT must be non-negative\n"; } + if(MAX_INSERT<0){ r += "(!)MAX_INSERT must be non-negative\n"; } + if(MAX_INSERT bamFiles = null; - private File OUTPUT_PATH = null; - private boolean OUTPUT_STATUS = false; - private boolean DUP_STATUS = false; - PrintStream OUT = null; - private File OUTPNG = null; - private static int MIN_INSERT = 0; - private static int MAX_INSERT = 1000; - - SamReader reader; - final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - final JTabbedPane tabbedPane_Histogram; - final JTabbedPane tabbedPane_InsertStats; - final JTabbedPane tabbedPane_Duplication; - final JTabbedPane tabbedPane_DupStats; + public static Vector getPEStats( File out_basename, File bamFile, boolean DUP_STATUS, int MIN_INSERT, int MAX_INSERT, PrintStream PS_INSERT, PrintStream PS_DUP, boolean SUM_STATUS ){ + System.out.println("getPEStats called"); + final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - public PEStats(Vector input, File o, boolean out, boolean dup, int min, int max) { - setTitle("BAM File Paired-end Statistics"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 600); - - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); + // Output Vecotr of Charts to be returned + Vector charts = new Vector(2); + + // Output files to be saved + PrintStream OUT_INSERT = null; + PrintStream OUT_INSERT_SUM = null; + File OUT_INSPNG = null; + PrintStream OUT_DUP = null; + File OUT_DUPPNG = null; - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); + if( out_basename!=null ) { + try { + OUT_INSERT = new PrintStream(new File( out_basename.getCanonicalPath() + "_InsertHistogram.out")); + OUT_INSPNG = new File( out_basename.getCanonicalPath() + "_PE.png"); + if( DUP_STATUS ){ + OUT_DUP = new PrintStream(new File( out_basename.getCanonicalPath() + "_DuplicationSummary.out")); + OUT_DUPPNG = new File( out_basename.getCanonicalPath() + "_DUP.png" ); + } + if( SUM_STATUS ){ + OUT_INSERT_SUM = new PrintStream(new File( out_basename.getCanonicalPath() + "_InsertSummary.out")); + } + } + catch (IOException e) { e.printStackTrace(); } + } - bamFiles = input; - OUTPUT_PATH = o; - OUTPUT_STATUS = out; - DUP_STATUS = dup; - MIN_INSERT = min; - MAX_INSERT = max; + //Print TimeStamp + String time = getTimeStamp(); + printBoth( null, OUT_INSERT_SUM, time ); + printBoth( PS_INSERT, OUT_INSERT, time ); + printBoth( PS_DUP, OUT_DUP, time ); - tabbedPane_Histogram = new JTabbedPane(JTabbedPane.TOP); - tabbedPane_InsertStats = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("Insert Histogram", null, tabbedPane_Histogram, null); - tabbedPane.addTab("PE Insert Stats", null, tabbedPane_InsertStats, null); + if(PS_DUP!=null){ PS_DUP.println("YO!"); } - tabbedPane_Duplication = new JTabbedPane(JTabbedPane.TOP); - tabbedPane_DupStats = new JTabbedPane(JTabbedPane.TOP); - if(DUP_STATUS) { - tabbedPane.addTab("Duplication Rate", null, tabbedPane_Duplication, null); - tabbedPane.addTab("Duplication Stats", null, tabbedPane_DupStats, null); - } - } - - public void run() throws IOException { - //Iterate through all BAM files in Vector - for(int x = 0; x < bamFiles.size(); x++) { - //Open Output File - if(OUTPUT_STATUS) { - String NAME = bamFiles.get(x).getName().split("\\.")[0]; - if(OUTPUT_PATH != null) { - try { - OUT = new PrintStream(new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME + "_InsertHistogram.out")); - OUTPNG = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME + "_PE.png"); - } - catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { - OUT = new PrintStream(new File(NAME + "_InsertHistogram.out")); - OUTPNG = new File(NAME + "_PE.png"); - } - catch (FileNotFoundException e) { e.printStackTrace(); } - } - } + //Check if BAI index file exists + File f = new File(bamFile + ".bai"); + if(f.exists() && !f.isDirectory()) { - //Print TimeStamp - String time = getTimeStamp(); - JTextArea PE_STATS = new JTextArea(); - PE_STATS.setEditable(false); - PE_STATS.append(time + "\n"); - JTextArea DUP_STATS = new JTextArea(); - if(DUP_STATUS) { - DUP_STATS.setEditable(false); - DUP_STATS.append(time + "\n"); - } - - //Check if BAI index file exists - File f = new File(bamFiles.get(x) + ".bai"); - if(f.exists() && !f.isDirectory()) { - PE_STATS.append(bamFiles.get(x).getName() + "\n"); - PE_STATS.append("Chromosome_ID\tChromosome_Size\tAligned_Reads\tUnaligned_Reads\n"); - if(DUP_STATUS) { - DUP_STATS.append(bamFiles.get(x).getName() + "\n"); - DUP_STATS.append("Duplicate Rate\tNumber of Duplicate Molecules\n"); - } - - //Code to get individual chromosome stats - reader = factory.open(bamFiles.get(x)); - AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); + //Print input filename to all output PrintStreams + printBoth( PS_INSERT, OUT_INSERT_SUM, bamFile.getName() ); + printBoth( PS_DUP, OUT_DUP, bamFile.getName() ); + //Print headers to respective PrintStreams + printBoth( PS_INSERT, OUT_INSERT_SUM, "Chromosome_ID\tChromosome_Size\tAligned_Reads\tUnaligned_Reads" ); + printBoth( PS_DUP, OUT_DUP, "Duplicate Rate\tNumber of Duplicate Molecules" ); + + //Code to get individual chromosome stats + SamReader reader = factory.open(bamFile); + AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); + + //Variables to keep track of insert size histogram + double InsertAverage = 0; + double counter = 0; + double[] HIST = new double[(MAX_INSERT - MIN_INSERT) + 1]; + + //Variables to contain duplication rates + HashMap CHROM_COMPLEXITY = null; + HashMap ALL_COMPLEXITY = new HashMap(); + + //Variables which contain basic sequence information + double totalAlignedRead1 = 0; + double totalAlignedRead2 = 0; + double totalAlignedReads = 0; + double totalGenome = 0; + + for (int z = 0; z < bai.getNumberOfReferences(); z++) { + SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); + double aligned = reader.indexing().getIndex().getMetaData(z).getAlignedRecordCount(); + double unaligned = reader.indexing().getIndex().getMetaData(z).getUnalignedRecordCount(); - //Variables to keep track of insert size histogram - double InsertAverage = 0; - double counter = 0; - double[] HIST = new double[(MAX_INSERT - MIN_INSERT) + 1]; + //Basic statistic calculations + System.out.println("Processing: " + seq.getSequenceName()); - //Variables to contain duplication rates - HashMap CHROM_COMPLEXITY = null; - HashMap ALL_COMPLEXITY = new HashMap(); + printBoth( PS_INSERT, OUT_INSERT_SUM, seq.getSequenceName() + "\t" + seq.getSequenceLength() + "\t" + aligned + "\t" + unaligned ); + totalGenome += seq.getSequenceLength(); - //Variables which contain basic sequence information - double totalAlignedRead1 = 0; - double totalAlignedRead2 = 0; - double totalAlignedReads = 0; - double totalGenome = 0; - - for (int z = 0; z < bai.getNumberOfReferences(); z++) { - SAMSequenceRecord seq = reader.getFileHeader().getSequence(z); - double aligned = reader.indexing().getIndex().getMetaData(z).getAlignedRecordCount(); - double unaligned = reader.indexing().getIndex().getMetaData(z).getUnalignedRecordCount(); - - //Basic statistic calculations - System.out.println("Processing: " + seq.getSequenceName()); - PE_STATS.append(seq.getSequenceName() + "\t" + seq.getSequenceLength() + "\t" + aligned + "\t" + unaligned + "\n"); - totalGenome += seq.getSequenceLength(); - - //Loop through each chromosome looking at each perfect F-R PE read - CHROM_COMPLEXITY = new HashMap(); - CloseableIterator iter = reader.query(seq.getSequenceName(), 0, seq.getSequenceLength(), false); - while (iter.hasNext()) { - //Create the record object - SAMRecord sr = iter.next(); - - if(!sr.getReadUnmappedFlag()) { //Test for mapped read - if(sr.getReadPairedFlag()) { //Test for paired-end status - if(sr.getSecondOfPairFlag()) { totalAlignedRead2++; } //count read 2 - else if(sr.getFirstOfPairFlag()) { totalAlignedRead1++; } // count read 1 + //Loop through each chromosome looking at each perfect F-R PE read + CHROM_COMPLEXITY = new HashMap(); + CloseableIterator iter = reader.query(seq.getSequenceName(), 0, seq.getSequenceLength(), false); + while (iter.hasNext()) { + //Create the record object + SAMRecord sr = iter.next(); + if(!sr.getReadUnmappedFlag()) { //Test for mapped read + if(sr.getReadPairedFlag()) { //Test for paired-end status + if(sr.getSecondOfPairFlag()) { totalAlignedRead2++; } //count read 2 + else if(sr.getFirstOfPairFlag()) { totalAlignedRead1++; } // count read 1 + //Insert size calculations + if(sr.getProperPairFlag() && sr.getFirstOfPairFlag()) { //Insert size calculations - if(sr.getProperPairFlag() && sr.getFirstOfPairFlag()) { - //Insert size calculations - int distance = Math.abs(sr.getInferredInsertSize()); - if(distance <= MAX_INSERT && distance >= MIN_INSERT) HIST[distance - MIN_INSERT]++; - InsertAverage += distance; - counter++; - - if(DUP_STATUS) { - //Unique ID - String tagName = sr.getAlignmentStart() + "_" + sr.getMateAlignmentStart() + "_" + sr.getInferredInsertSize(); - //Duplication rate for each chrom determined - if(CHROM_COMPLEXITY.isEmpty()) { - CHROM_COMPLEXITY.put(tagName, new Integer(1)); - } else if(!CHROM_COMPLEXITY.containsKey(tagName)) { - CHROM_COMPLEXITY.put(tagName, new Integer(1)); - } else if(CHROM_COMPLEXITY.containsKey(tagName)){ - CHROM_COMPLEXITY.put(tagName, new Integer(((Integer) CHROM_COMPLEXITY.get(tagName)).intValue() + 1)); - } + int distance = Math.abs(sr.getInferredInsertSize()); + if(distance <= MAX_INSERT && distance >= MIN_INSERT) HIST[distance - MIN_INSERT]++; + InsertAverage += distance; + counter++; + + if(DUP_STATUS) { + //Unique ID + String tagName = sr.getAlignmentStart() + "_" + sr.getMateAlignmentStart() + "_" + sr.getInferredInsertSize(); + //Duplication rate for each chrom determined + if(CHROM_COMPLEXITY.isEmpty()) { + CHROM_COMPLEXITY.put(tagName, new Integer(1)); + } else if(!CHROM_COMPLEXITY.containsKey(tagName)) { + CHROM_COMPLEXITY.put(tagName, new Integer(1)); + } else if(CHROM_COMPLEXITY.containsKey(tagName)){ + CHROM_COMPLEXITY.put(tagName, new Integer(((Integer) CHROM_COMPLEXITY.get(tagName)).intValue() + 1)); } } - } else { //If the read is mapped but not paired-end, default to read 1 - totalAlignedRead1++; } + } else { //If the read is mapped but not paired-end, default to read 1 + totalAlignedRead1++; } } - iter.close(); - - if(DUP_STATUS) { - //Load each chromosome up into master duplication hashmap - Iterator keys = CHROM_COMPLEXITY.keySet().iterator(); - while(keys.hasNext()) { - String str = (String) keys.next(); - if(ALL_COMPLEXITY.isEmpty()) { - ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(1)); - } else if(!ALL_COMPLEXITY.containsKey(CHROM_COMPLEXITY.get(str))) { - ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(1)); - } else if(ALL_COMPLEXITY.containsKey(CHROM_COMPLEXITY.get(str))){ - ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(((Integer) ALL_COMPLEXITY.get(CHROM_COMPLEXITY.get(str))).intValue() + 1)); - } - } - } - } - totalAlignedReads = totalAlignedRead1 + totalAlignedRead2; - PE_STATS.append("Total Genome Size: " + totalGenome + "\tTotal Aligned Tags: " + totalAlignedReads + "\n\n"); - - //Output replicates used to make bam file - for( String comment : reader.getFileHeader().getComments()) { - PE_STATS.append(comment + "\n"); } + iter.close(); - //Output program used to align bam file - for (int z = 0; z < reader.getFileHeader().getProgramRecords().size(); z++) { - PE_STATS.append(reader.getFileHeader().getProgramRecords().get(z).getId() + "\t"); - PE_STATS.append(reader.getFileHeader().getProgramRecords().get(z).getProgramVersion() + "\n"); - PE_STATS.append(reader.getFileHeader().getProgramRecords().get(z).getCommandLine() + "\n"); + if(DUP_STATUS) { + //Load each chromosome up into master duplication hashmap + Iterator keys = CHROM_COMPLEXITY.keySet().iterator(); + while(keys.hasNext()) { + String str = (String) keys.next(); + if(ALL_COMPLEXITY.isEmpty()) { + ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(1)); + } else if(!ALL_COMPLEXITY.containsKey(CHROM_COMPLEXITY.get(str))) { + ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(1)); + } else if(ALL_COMPLEXITY.containsKey(CHROM_COMPLEXITY.get(str))){ + ALL_COMPLEXITY.put(CHROM_COMPLEXITY.get(str), new Integer(((Integer) ALL_COMPLEXITY.get(CHROM_COMPLEXITY.get(str))).intValue() + 1)); + } + } } + } + totalAlignedReads = totalAlignedRead1 + totalAlignedRead2; + printBoth( PS_INSERT, OUT_INSERT_SUM, "Total Genome Size: " + totalGenome + "\tTotal Aligned Tags: " + totalAlignedReads + "\n" ); + + //Output replicates used to make bam file + for( String comment : reader.getFileHeader().getComments()) { + printBoth( PS_INSERT, OUT_INSERT_SUM, comment ); + } + + //Output program used to align bam file + for (int z = 0; z < reader.getFileHeader().getProgramRecords().size(); z++) { + printBoth( PS_INSERT, OUT_INSERT_SUM, reader.getFileHeader().getProgramRecords().get(z).getId() + "\t" + reader.getFileHeader().getProgramRecords().get(z).getProgramVersion() ); + printBoth( PS_INSERT, OUT_INSERT_SUM, reader.getFileHeader().getProgramRecords().get(z).getCommandLine() ); + } + try{ reader.close(); bai.close(); - PE_STATS.append("\n"); - - //Insert Size statistics - if(counter != 0) InsertAverage /= counter; - PE_STATS.append("Average Insert Size: " + InsertAverage + "\n"); - PE_STATS.append("Median Insert Size: " + getMedian(HIST) + "\n"); - PE_STATS.append("Std deviation of Insert Size: " + getStdDev(HIST, InsertAverage) + "\n"); - PE_STATS.append("Number of ReadPairs: " + counter + "\n\nHistogram\nSize (bp)\tFrequency\n"); - if(OUT != null) { OUT.println("InsertSize (bp)\t" + bamFiles.get(x).getName()); } + printBoth( PS_INSERT, OUT_INSERT_SUM, ""); + }catch (IOException e) { e.printStackTrace(); } + + //Insert Size statistics + if(counter != 0) InsertAverage /= counter; //does this need an if statement? + printBoth( PS_INSERT, OUT_INSERT_SUM, "Average Insert Size: " + InsertAverage ); + printBoth( PS_INSERT, OUT_INSERT_SUM, "Median Insert Size: " + getMedian(HIST, MIN_INSERT, MAX_INSERT) ); + printBoth( PS_INSERT, OUT_INSERT_SUM, "Std deviation of Insert Size: " + getStdDev(HIST, InsertAverage, MIN_INSERT, MAX_INSERT) ); + printBoth( PS_INSERT, OUT_INSERT_SUM, "Number of ReadPairs: " + counter ); + + if(PS_INSERT!=null){ PS_INSERT.println( "Histogram\nSize (bp)\tFrequency" ); } + if(OUT_INSERT!=null){ OUT_INSERT.println( "InsertSize (bp)\t" + bamFile.getName() ); } - int[] DOMAIN = new int[(MAX_INSERT - MIN_INSERT) + 1]; - for(int z = 0; z < HIST.length; z++) { - int bp = MIN_INSERT + z; - DOMAIN[z] = bp; - if(OUT != null) OUT.println(bp + "\t" + HIST[z]); - PE_STATS.append(bp + "\t" + HIST[z] + "\n"); + int[] DOMAIN = new int[(MAX_INSERT - MIN_INSERT) + 1]; + for(int z = 0; z < HIST.length; z++) { + int bp = MIN_INSERT + z; + DOMAIN[z] = bp; + printBoth( PS_INSERT, OUT_INSERT, bp + "\t" + HIST[z] ); + } + + //Generate Insert Chart + try{ + charts.add( 0, Histogram.createBarChart(HIST, DOMAIN, OUT_INSPNG) ); + }catch( IOException e ){ e.printStackTrace(); } + + if(DUP_STATUS) { + //Duplication statistics + double UNIQUE_MOLECULES = 0; + String[] BIN_NAME = initializeBIN_Names(); + ArrayList BIN = new ArrayList(); + initializeBINS(BIN); + + Iterator keys = ALL_COMPLEXITY.keySet().iterator(); + while(keys.hasNext()) { + Integer str = (Integer) keys.next(); + int index = getBinIndex(str.intValue()); + BIN.set(index, BIN.get(index) + (ALL_COMPLEXITY.get(str).doubleValue() * str.doubleValue())); + UNIQUE_MOLECULES += ALL_COMPLEXITY.get(str).doubleValue(); } - //Add pe stats to tabbed pane - PE_STATS.setCaretPosition(0); - JScrollPane pe_pane = new JScrollPane(PE_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_InsertStats.add(bamFiles.get(x).getName(), pe_pane); - tabbedPane_Histogram.add(bamFiles.get(x).getName(), Histogram.createBarChart(HIST, DOMAIN, OUTPNG)); - - if(DUP_STATUS) { - //Duplication statistics - double UNIQUE_MOLECULES = 0; - String[] BIN_NAME = initializeBIN_Names(); - ArrayList BIN = new ArrayList(); - initializeBINS(BIN); - - Iterator keys = ALL_COMPLEXITY.keySet().iterator(); - while(keys.hasNext()) { - Integer str = (Integer) keys.next(); - int index = getBinIndex(str.intValue()); - BIN.set(index, BIN.get(index) + (ALL_COMPLEXITY.get(str).doubleValue() * str.doubleValue())); - UNIQUE_MOLECULES += ALL_COMPLEXITY.get(str).doubleValue(); - } - - for(int z = 0; z < BIN.size(); z++) { - DUP_STATS.append(BIN_NAME[z] + "\t" + BIN.get(z).toString() + "\n"); - } - DUP_STATS.append("Unique Molecules:\n" + UNIQUE_MOLECULES); - - //Add duplication stats to tabbed pane - DUP_STATS.setCaretPosition(0); - JScrollPane dup_pane = new JScrollPane(DUP_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_DupStats.add(bamFiles.get(x).getName(), dup_pane); - tabbedPane_Duplication.add(bamFiles.get(x).getName(), LineChart.createLineChart(BIN, BIN_NAME)); + for(int z = 0; z < BIN.size(); z++) { + printBoth( PS_DUP, OUT_DUP, BIN_NAME[z] + "\t" + BIN.get(z).toString() ); } + printBoth( PS_DUP, OUT_DUP, "Unique Molecules:\n" + UNIQUE_MOLECULES); - firePropertyChange("bam",x, x + 1); - - } else { - if(OUT != null) OUT.println("BAI Index File does not exist for: " + bamFiles.get(x).getName() + "\n"); - PE_STATS.append("BAI Index File does not exist for: " + bamFiles.get(x).getName() + "\n\n"); - DUP_STATS.append("BAI Index File does not exist for: " + bamFiles.get(x).getName() + "\n\n"); + //Generate Duplicates Chart + try{ + charts.add( 1, LineChart.createLineChart(BIN, BIN_NAME, OUT_DUPPNG) ); + }catch( IOException e ){ e.printStackTrace(); } } - if(OUT != null) OUT.close(); - } + + } else { + printBoth( PS_INSERT, OUT_INSERT, "BAI Index File does not exist for: " + bamFile.getName() ); + printBoth( System.err, OUT_INSERT_SUM, "BAI Index File does not exist for: " + bamFile.getName() ); + printBoth( PS_DUP, OUT_DUP, "BAI Index File does not exist for: " + bamFile.getName() ); + } + if(PS_INSERT != null){ PS_INSERT.close(); } + if(PS_DUP!=null){ PS_DUP.close(); } + + if(OUT_INSERT != null){ OUT_INSERT.close(); } + if(OUT_INSERT_SUM!=null){ OUT_INSERT_SUM.close(); } + if(OUT_DUP != null){ OUT_DUP.close(); } + + return(charts); } - public static double getMedian(double[] histogram) { + public static double getMedian(double[] histogram, int MIN_INSERT, int MAX_INSERT) { double sum = 0; for(int x = 0; x < histogram.length; x++) { sum += histogram[x]; } if(sum % 2 == 1 && sum > 0) { @@ -318,7 +264,7 @@ public static double getMedian(double[] histogram) { return 0; } - public static double getStdDev(double[] histogram, double avg) { + public static double getStdDev(double[] histogram, double avg, int MIN_INSERT, int MAX_INSERT) { double stddev = 0; double sum = 0; for(int x = 0; x < histogram.length; x++) { @@ -389,4 +335,11 @@ private static String getTimeStamp() { String time = new Timestamp(date.getTime()).toString(); return time; } -} + + //Helper methods to de-clutter print statements: + //Prints output to both pop-up window (for GUI) and output file (GUI and CLI) + private static void printBoth( PrintStream p, PrintStream out, String line ){ + if( p != null ){ p.println(line); } + if( out!=null ){ out.println(line); } + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Statistics/PEStatOutput.java b/src/window_interface/BAM_Statistics/PEStatOutput.java new file mode 100644 index 000000000..14197f093 --- /dev/null +++ b/src/window_interface/BAM_Statistics/PEStatOutput.java @@ -0,0 +1,126 @@ +package window_interface.BAM_Statistics; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Vector; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.SpringLayout; + +import org.jfree.chart.ChartPanel; + +import objects.CustomOutputStream; +import scripts.BAM_Statistics.PEStats; + +@SuppressWarnings("serial") +public class PEStatOutput extends JFrame { + + Vector bamFiles = null; + private File OUTPUT_PATH = null; + private boolean OUTPUT_STATUS = false; + private boolean DUP_STATUS = false; + private static int MIN_INSERT = 0; + private static int MAX_INSERT = 1000; + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + final JTabbedPane tabbedPane_Histogram; + final JTabbedPane tabbedPane_InsertStats; + final JTabbedPane tabbedPane_Duplication; + final JTabbedPane tabbedPane_DupStats; + + public PEStatOutput(Vector input, File o, boolean out, boolean dup, int min, int max) { + setTitle("BAM File Paired-end Statistics"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 600); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + bamFiles = input; + OUTPUT_PATH = o; + OUTPUT_STATUS = out; + DUP_STATUS = dup; + MIN_INSERT = min; + MAX_INSERT = max; + + tabbedPane_Histogram = new JTabbedPane(JTabbedPane.TOP); + tabbedPane_InsertStats = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("Insert Histogram", null, tabbedPane_Histogram, null); + tabbedPane.addTab("PE Insert Stats", null, tabbedPane_InsertStats, null); + + tabbedPane_Duplication = new JTabbedPane(JTabbedPane.TOP); + tabbedPane_DupStats = new JTabbedPane(JTabbedPane.TOP); + if(DUP_STATUS) { + tabbedPane.addTab("Duplication Rate", null, tabbedPane_Duplication, null); + tabbedPane.addTab("Duplication Stats", null, tabbedPane_DupStats, null); + } + } + + public void run() throws IOException { + //Iterate through all BAM files in Vector + for(int x = 0; x < bamFiles.size(); x++) { + + // Construct Basename + File NAME = null; + if(OUTPUT_STATUS){ + try{ + NAME = new File( bamFiles.get(x).getName().split("\\.")[0] ); + if(OUTPUT_PATH != null){ NAME = new File( OUTPUT_PATH.getCanonicalPath() + File.separator + NAME.getCanonicalPath() ); } + } + catch (FileNotFoundException e) { e.printStackTrace(); } +// catch (IOException e) { e.printStackTrace(); } + } + // Initialize PrintStream and TextArea for PE stats (insert sizes) + PrintStream ps_insert = null; + JTextArea PE_STATS = new JTextArea(); + PE_STATS.setEditable(false); + ps_insert = new PrintStream(new CustomOutputStream( PE_STATS )); + // Initialize PrintStream and TextArea for DUP stats + PrintStream ps_dup = null; + JTextArea DUP_STATS = new JTextArea(); + if(DUP_STATUS) { + DUP_STATS.setEditable(false); + ps_dup = new PrintStream(new CustomOutputStream( DUP_STATS )); + } + + //Call public static method from scripts + Vector charts = PEStats.getPEStats( NAME, bamFiles.get(x), DUP_STATUS, MIN_INSERT, MAX_INSERT, ps_insert, ps_dup, false ); + + //Add pe stats to tabbed pane + PE_STATS.setCaretPosition(0); + JScrollPane pe_pane = new JScrollPane(PE_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_InsertStats.add(bamFiles.get(x).getName(), pe_pane); + tabbedPane_Histogram.add(bamFiles.get(x).getName(), charts.get(0)); + + if(DUP_STATUS) { + //Add duplication stats to tabbed pane + DUP_STATS.setCaretPosition(0); + JScrollPane dup_pane = new JScrollPane(DUP_STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_DupStats.add(bamFiles.get(x).getName(), dup_pane); + tabbedPane_Duplication.add(bamFiles.get(x).getName(), charts.get(1)); + } + + ps_dup.close(); + ps_insert.close(); + + firePropertyChange("bam",x, x + 1); + } + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Statistics/PEStatWindow.java b/src/window_interface/BAM_Statistics/PEStatWindow.java index f78b32bc6..6ecac905a 100644 --- a/src/window_interface/BAM_Statistics/PEStatWindow.java +++ b/src/window_interface/BAM_Statistics/PEStatWindow.java @@ -34,7 +34,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Statistics.PEStats; +import window_interface.BAM_Statistics.PEStatOutput; @SuppressWarnings("serial") public class PEStatWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -65,7 +65,7 @@ public Void doInBackground() { try { int min = Integer.parseInt(txtMin.getText()); int max = Integer.parseInt(txtMax.getText()); - PEStats stat = new PEStats(BAMFiles, OUTPUT_PATH, chckbxOutputStatistics.isSelected(), chckbxDup.isSelected(), min, max); + PEStatOutput stat = new PEStatOutput(BAMFiles, OUTPUT_PATH, chckbxOutputStatistics.isSelected(), chckbxDup.isSelected(), min, max); stat.addPropertyChangeListener("bam", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { int temp = (Integer) propertyChangeEvent.getNewValue(); From 9a83079ec672de1924ad511288f7ff70171b5e88 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 18:56:46 -0400 Subject: [PATCH 17/43] create BAMGenomeCorrelation command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BAMGenomeCorrelationOutput class while the calculations are kept in the src/scripts/*/BAMGenomeCorrelation class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user charts/HeatMap -createCorrelationHeatmap updated to take a File object for saving the chart when executing the CLI version --- src/charts/HeatMap.java | 13 +- .../BAMGenomeCorrelationCLI.java | 110 +++++++++++- .../BAM_Statistics/BAMGenomeCorrelation.java | 164 +++++++----------- .../BAMGenomeCorrelationOutput.java | 110 ++++++++++++ .../BAMGenomeCorrelationWindow.java | 4 +- 5 files changed, 293 insertions(+), 108 deletions(-) create mode 100644 src/window_interface/BAM_Statistics/BAMGenomeCorrelationOutput.java diff --git a/src/charts/HeatMap.java b/src/charts/HeatMap.java index 97b3769c3..8e8270916 100644 --- a/src/charts/HeatMap.java +++ b/src/charts/HeatMap.java @@ -1,7 +1,10 @@ package charts; import java.awt.Color; +import java.io.File; +import java.io.IOException; import org.jfree.chart.ChartPanel; +import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.NumberAxis; @@ -21,7 +24,7 @@ public HeatMap() { } - public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX) { + public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX, File output) { // create a paint-scale and a legend showing it LookupPaintScale paintScale = new LookupPaintScale(0, 1, Color.black); paintScale.add(0.0, new Color(0, 0, 255)); @@ -60,6 +63,14 @@ public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MA chart.addSubtitle(legend); chart.setBackgroundPaint(Color.white); + + if(output!=null){ + int width = 640; + int height = 480; + try{ ChartUtilities.saveChartAsPNG(output, chart, width, height); } + catch( IOException e ){ e.printStackTrace(); } + } + return new ChartPanel(chart); } diff --git a/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java b/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java index b979a729e..e0c138a73 100644 --- a/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java +++ b/src/cli/BAM_Statistics/BAMGenomeCorrelationCLI.java @@ -15,7 +15,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.BAM_Statistics.BAMGenomeCorrelation; +import scripts.BAM_Statistics.BAMGenomeCorrelation; /** BAM_StatisticsCLI/SEStats @@ -27,6 +27,38 @@ exitCodeOnExecutionException = 1) public class BAMGenomeCorrelationCLI implements Callable { + @Parameters( index = "0..", description = "The BAM file whose statistics we want.") + private File[] inputFiles; + + @Option(names = {"-f", "--files"}, description = "Input file list of BAM filepaths to correlate (formatted so each path is on its own line)") + private boolean fileList = false; + @Option(names = {"-o", "--output"}, description = "Specify output file, default is \"correlation_matrix\" or the input filename if -f flag used") + private File outputBasename = null; + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "output read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "output read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "output combined") + boolean allreads = false; + @Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)") + boolean midpoint = false; + } + + @Option(names = {"-t", "--tag-shift"}, description = "tag shift in bp (default 0)") + private int tagshift = 0; + @Option(names = {"-b", "--bin-size"}, description = "bin size in bp (default 10)") + private int binSize = 10; + @Option(names = {"--cpu"}, description = "CPUs to use (default 1)") + private int cpu = 1; + + private int READ = 0; + private Vector bamFiles = new Vector(); + @Override public Integer call() throws Exception { System.err.println( ">BAMGenomeCorrelationCLI.call()" ); @@ -37,16 +69,82 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BAMGenomeCorrelation script_obj = new BAMGenomeCorrelation( bamFiles, outputBasename, true, tagshift, binSize, cpu, READ); + script_obj.getBAMGenomeCorrelation(false); - //System.err.println("Calculations Complete"); + System.err.println("Calculations Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + if(inputFiles==null){ + r += "(!)Please indicate at least one file.\n"; + return(r); + //Import files as Vector list (scan input file if -f flag used) + }else if(fileList){ //load files from input filelist + if(inputFiles.length>1){ + r += "(!)Please indicate only one file with bam filepaths when using the -f flag.\n"; + return(r); + }else if(!inputFiles[0].exists()){ + r += "(!)File of list of file inputs does not exist: " + inputFiles[0].getCanonicalPath() + "\n"; + return(r); + }else{ + Scanner scan = new Scanner(inputFiles[0]); + while (scan.hasNextLine()) { + bamFiles.add(new File(scan.nextLine().trim())); + } + scan.close(); + } + if(outputBasename==null){ + outputBasename = new File(ExtensionFileFilter.stripExtension(inputFiles[0])+"_BAMCorr"); + } + }else{ //load input files into bam vector + for(int x=0; x bamFiles = null; - String[] fileID = null; - private File OUTPUT_PATH = null; + private Vector bamFiles = null; + private String[] fileID = null; + private double[][] MATRIX; + private ChartPanel HEATMAP; + private File OUT_BASENAME = null; private boolean OUTPUT_STATUS = false; - PrintStream OUT = null; private int SHIFT; private int BIN; private int CPU; private int READ; + private boolean GUI = false; SamReader reader; final SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - - public BAMGenomeCorrelation(Vector input, File o, boolean out, int s, int b, int c, int r) { - - setTitle("Genome Correlation"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 600); - - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); - - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); - + + public BAMGenomeCorrelation(Vector input, File o, boolean out, int s, int b, int c, int r){ + //Load in bamFiles bamFiles = input; fileID = new String[bamFiles.size()]; - OUTPUT_PATH = o; + //Initialize correlation matrix + MATRIX = new double[bamFiles.size()][bamFiles.size()]; + //Store the rest of the variables + OUT_BASENAME = o; OUTPUT_STATUS = out; SHIFT = s; BIN = b; CPU = c; READ = r; - } - - public void run() throws IOException { - System.out.println(getTimeStamp()); + + public void getBAMGenomeCorrelation(boolean GUI) throws IOException { + System.err.println(getTimeStamp()); + // Check BAMs first if(!validateBAM()) { return; } +// // Toggle GUI v CLI status +// if( gui!=null ){ GUI = true; } + //Open Output File - if(OUTPUT_STATUS) { - String NAME = "correlation_matrix.out"; - if(OUTPUT_PATH != null) { - try { OUT = new PrintStream(new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { OUT = new PrintStream(new File(NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - } + PrintStream OUT = null; + File OUT_PNG = null; + if(OUT_BASENAME!=null) { + try { + OUT = new PrintStream(new File( OUT_BASENAME + ".out")); + OUT_PNG = new File( OUT_BASENAME + ".png" ); + } + catch (FileNotFoundException e) { e.printStackTrace(); } +// catch (IOException e) { e.printStackTrace(); } } - - //Initialize correlation matrix - double[][] MATRIX = new double[bamFiles.size()][bamFiles.size()]; - + //Iterate through all BAM files in Vector int counter = 0; for(int x = 0; x < bamFiles.size(); x++) { @@ -107,7 +87,7 @@ public void run() throws IOException { if(x != y && (x - y) >= 1) { MATRIX[x][y] = correlate(bamFiles.get(x), bamFiles.get(y)); MATRIX[y][x] = MATRIX[x][y]; - firePropertyChange("bam", counter, counter + 1); + //gui.firePropertyChange("bam", counter, counter + 1); counter++; } else if(x == y) { MATRIX[x][y] = 1; } } @@ -115,32 +95,25 @@ public void run() throws IOException { //Output correlation matrix for(int x = 0; x < bamFiles.size(); x++) { - System.out.print(bamFiles.get(x).getName() + "\t"); fileID[x] = bamFiles.get(x).getName(); - if(OUT != null) { OUT.print(bamFiles.get(x).getName() + "\t"); } + printBoth( OUT, bamFiles.get(x).getName() + "\t" ); } - System.out.println(); - if(OUT != null) { OUT.println(); } + printBoth( OUT, "\n" ); for(int x = 0; x < MATRIX.length; x++) { for(int y = 0; y < MATRIX.length; y++) { - System.out.print(MATRIX[x][y] + "\t"); - if(OUT != null) { OUT.print(MATRIX[x][y] + "\t"); } + printBoth( OUT, MATRIX[x][y] + "\t"); } - System.out.println(); - if(OUT != null) { OUT.println(); } + printBoth( OUT, "\n" ); } if(OUT != null) OUT.close(); - tabbedPane.addTab("Correlation Plot", HeatMap.createCorrelationHeatmap(fileID, MATRIX)); - tabbedPane.addTab("Correlation Data", makeTablePanel(MATRIX)); + HEATMAP = HeatMap.createCorrelationHeatmap(fileID, MATRIX, OUT_PNG); - //Make frame visible at completion of correlations - this.setVisible(true); - System.out.println(getTimeStamp()); + System.err.println(getTimeStamp()); } public double correlate(File exp1, File exp2) { - System.out.println("Comparing: " + exp1.getName() + "\t-\t" + exp2.getName()); + System.err.println("Comparing: " + exp1.getName() + "\t-\t" + exp2.getName()); //Reflexive pearson correlation requiring only a single pass through each genome double Sx = 0; @@ -159,7 +132,7 @@ public double correlate(File exp1, File exp2) { //Object to keep track of the chromosomal data ChromosomeWindows = new Vector(); SAMSequenceRecord seq = reader.getFileHeader().getSequence(numchrom); - //System.out.println("Analyzing: " + seq.getSequenceName()); + //System.err.println("Analyzing: " + seq.getSequenceName()); //Break chromosome into 100kb chunks and assign to independent nodes int numwindows = (int) (seq.getSequenceLength() / 100000); @@ -213,7 +186,7 @@ public double correlate(File exp1, File exp2) { denominator = Math.sqrt((Sxx - ((Sx * Sx) / count)) * (Syy - ((Sy * Sy / count)))); double correlation = numerator / denominator; - System.out.println("Correlation: " + correlation); + System.err.println("Correlation: " + correlation); return correlation; } @@ -221,13 +194,15 @@ private boolean validateBAM() throws IOException { //Check if BAI index file exists for all BAM files before we process any of them ArrayList chrName = new ArrayList(); ArrayList chrSize = new ArrayList(); - for(int x = 0; x < bamFiles.size(); x++) { - File f = new File(bamFiles.get(x) + ".bai"); + for(int x = 0; x < bamFiles.size(); x++) { + File XBAM = bamFiles.get(x); + File f = new File(XBAM + ".bai"); if(!f.exists() || f.isDirectory()) { - JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + bamFiles.get(x).getName()); + if(GUI){ JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + XBAM.getName()); } + else{ System.err.println("BAI Index File does not exist for: " + XBAM.getName()); } return false; } else { - reader = factory.open(bamFiles.get(x)); + reader = factory.open(XBAM); AbstractBAMFileIndex bai = (AbstractBAMFileIndex) reader.indexing().getIndex(); if(x == 0) { for (int z = 0; z < bai.getNumberOfReferences(); z++) { @@ -235,7 +210,8 @@ private boolean validateBAM() throws IOException { chrSize.add(reader.getFileHeader().getSequence(z).getSequenceLength()); } } else if(bai.getNumberOfReferences() != chrName.size()) { - JOptionPane.showMessageDialog(null, "Unequal number of chromosomes from previous: " + bamFiles.get(x).getName()); + if(GUI){ JOptionPane.showMessageDialog(null, "Unequal number of chromosomes from previous: " + XBAM.getName()); } + else{ System.err.println("BAI Index File does not exist for: " + XBAM.getName()); } reader.close(); bai.close(); return false; @@ -246,7 +222,8 @@ private boolean validateBAM() throws IOException { if(!chrSize.get(z).equals(reader.getFileHeader().getSequence(z).getSequenceLength())) { MATCH = false; } } if(!MATCH) { - JOptionPane.showMessageDialog(null, "File contains chromosome size/name which does not match previous: " + bamFiles.get(x).getName()); + if(GUI){ JOptionPane.showMessageDialog(null, "File contains chromosome size/name which does not match previous: " + XBAM.getName()); } + else{ System.err.println("BAI Index File does not exist for: " + XBAM.getName()); } reader.close(); bai.close(); return false; @@ -258,26 +235,10 @@ private boolean validateBAM() throws IOException { reader.close(); return true; } - - public JScrollPane makeTablePanel(double[][] MATRIX) { - JTable table = new JTable(MATRIX.length, MATRIX.length); - table.setName("Correlation Matrix"); - table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - for(int i = 0; i < MATRIX.length; i++) { - for(int j = 0; j < MATRIX.length; j++) { - if(i == j) table.setValueAt(1, i, j); - else if((i - j) >= 1) { - table.setValueAt(MATRIX[i][j], i, j); - table.setValueAt(MATRIX[j][i], j, i); - } - } - } - for(int i = 0; i < bamFiles.size(); i++) table.getColumnModel().getColumn(i).setHeaderValue(bamFiles.get(i).getName()); - table.setPreferredSize(table.getPreferredSize()); - JScrollPane pane = new JScrollPane(table); - table.setFillsViewportHeight(true); - pane.setPreferredSize(new Dimension(590, 590)); - return pane; + + private static void printBoth( PrintStream p, String line ){ + if(p!=null) p.print(line); + System.err.print(line); } private static String getTimeStamp() { @@ -285,4 +246,9 @@ private static String getTimeStamp() { String time = new Timestamp(date.getTime()).toString(); return time; } + + public double[][] getMatrix(){ return(MATRIX); } + + public ChartPanel getHeatMap(){ return(HEATMAP); } + } diff --git a/src/window_interface/BAM_Statistics/BAMGenomeCorrelationOutput.java b/src/window_interface/BAM_Statistics/BAMGenomeCorrelationOutput.java new file mode 100644 index 000000000..bce977d61 --- /dev/null +++ b/src/window_interface/BAM_Statistics/BAMGenomeCorrelationOutput.java @@ -0,0 +1,110 @@ +package window_interface.BAM_Statistics; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Vector; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.SpringLayout; + +import scripts.BAM_Statistics.BAMGenomeCorrelation; + +// Output Window wrapper for executing the script and displaying output +@SuppressWarnings("serial") +public class BAMGenomeCorrelationOutput extends JFrame { + + Vector bamFiles = null; + String[] fileID = null; + private File OUTPUT_PATH = null; + private boolean OUTPUT_STATUS = false; + File OUT = null; + private int SHIFT; + private int BIN; + private int CPU; + private int READ; + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + + public BAMGenomeCorrelationOutput(Vector input, File o, boolean out, int s, int b, int c, int r) { + setTitle("Genome Correlation"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 600); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + bamFiles = input; + fileID = new String[bamFiles.size()]; + OUTPUT_PATH = o; + OUTPUT_STATUS = out; + SHIFT = s; + BIN = b; + CPU = c; + READ = r; + } + + public void run() throws IOException { + //Open Output File + if(OUTPUT_STATUS) { + String NAME = "correlation_matrix"; + if(OUTPUT_PATH != null) { + try { OUT = new File(OUTPUT_PATH.getCanonicalPath() + File.separator + NAME); } + catch (FileNotFoundException e) { e.printStackTrace(); } + catch (IOException e) { e.printStackTrace(); } + } else { + OUT = new File(NAME); + } + } + + BAMGenomeCorrelation script_obj = new BAMGenomeCorrelation( bamFiles, OUT, OUTPUT_STATUS, SHIFT, BIN, CPU, READ ); + script_obj.getBAMGenomeCorrelation(true); + + tabbedPane.addTab("Correlation Plot", script_obj.getHeatMap()); + tabbedPane.addTab("Correlation Data", makeTablePanel(script_obj.getMatrix())); + + //Make frame visible at completion of correlations + this.setVisible(true); + } + + public JScrollPane makeTablePanel(double[][] MATRIX) { + JTable table = new JTable(MATRIX.length, MATRIX.length); + table.setName("Correlation Matrix"); + table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); + for(int i = 0; i < MATRIX.length; i++) { + for(int j = 0; j < MATRIX.length; j++) { + if(i == j) table.setValueAt(1, i, j); + else if((i - j) >= 1) { + table.setValueAt(MATRIX[i][j], i, j); + table.setValueAt(MATRIX[j][i], j, i); + } + } + } + for(int i = 0; i < bamFiles.size(); i++) table.getColumnModel().getColumn(i).setHeaderValue(bamFiles.get(i).getName()); + table.setPreferredSize(table.getPreferredSize()); + JScrollPane pane = new JScrollPane(table); + table.setFillsViewportHeight(true); + pane.setPreferredSize(new Dimension(590, 590)); + return pane; + } +} \ No newline at end of file diff --git a/src/window_interface/BAM_Statistics/BAMGenomeCorrelationWindow.java b/src/window_interface/BAM_Statistics/BAMGenomeCorrelationWindow.java index 2816fc8e6..0045e3f46 100644 --- a/src/window_interface/BAM_Statistics/BAMGenomeCorrelationWindow.java +++ b/src/window_interface/BAM_Statistics/BAMGenomeCorrelationWindow.java @@ -36,7 +36,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.BAM_Statistics.BAMGenomeCorrelation; +import window_interface.BAM_Statistics.BAMGenomeCorrelationOutput; @SuppressWarnings("serial") public class BAMGenomeCorrelationWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -89,7 +89,7 @@ public Void doInBackground() { else if(rdbtnAllReads.isSelected()) { READ = 2; } else if(rdbtnMidpoint.isSelected()) { READ = 3; } - BAMGenomeCorrelation corr = new BAMGenomeCorrelation(BAMFiles, OUTPUT_PATH, chckbxOutputStatistics.isSelected(), SHIFT, BIN, CPU, READ); + BAMGenomeCorrelationOutput corr = new BAMGenomeCorrelationOutput(BAMFiles, OUTPUT_PATH, chckbxOutputStatistics.isSelected(), SHIFT, BIN, CPU, READ); corr.addPropertyChangeListener("bam", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { int temp = (Integer) propertyChangeEvent.getNewValue(); From 8871a3582cbbc57d86630baf58c3a7e5f2e25535 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 19:21:27 -0400 Subject: [PATCH 18/43] create DNAShapefromBED command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/DNAShapefromBEDOutput class while the calculations are kept in the src/scripts/*/DNAShapefromBED class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full file basename and not just directory script/* -strip out JFrame objects -use output as file basename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Sequence_Analysis/DNAShapefromBEDCLI.java | 110 ++++- .../Sequence_Analysis/DNAShapefromBED.java | 453 ++++++++---------- .../DNAShapefromBEDOutput.java | 153 ++++++ .../DNAShapefromBEDWindow.java | 4 +- 4 files changed, 453 insertions(+), 267 deletions(-) create mode 100644 src/window_interface/Sequence_Analysis/DNAShapefromBEDOutput.java diff --git a/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java b/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java index 96985e29a..1c57d09d9 100644 --- a/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java +++ b/src/cli/Sequence_Analysis/DNAShapefromBEDCLI.java @@ -20,7 +20,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Sequence_Analysis.DNAShapefromBED; +import scripts.Sequence_Analysis.DNAShapefromBED; /** Sequence_AnalysisCLI/DNAShapefromBEDCLI @@ -32,6 +32,35 @@ exitCodeOnExecutionException = 1) public class DNAShapefromBEDCLI implements Callable { + @Parameters( index = "0", description = "reference genome FASTA file") + private File genomeFASTA; + @Parameters( index = "1", description = "the BED file of sequences to extract") + private File bedFile; + + @Option(names = {"-o", "--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 = {"--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)") + private boolean forceStrand = true; + + @ArgGroup(validate = false, heading = "Shape Options%n") + ShapeType shape = new ShapeType(); + static class ShapeType{ + @Option(names = {"-g","--groove"}, description = "output minor groove width") + private boolean groove = false; + @Option(names = {"-r","--roll"}, description = "output roll") + private boolean roll = false; + @Option(names = {"-p","--propeller"}, description = "output propeller twist") + private boolean propeller = false; + @Option(names = {"-l","--helical"}, description = "output helical twist") + private boolean helical = false; + @Option(names = {"-a","--all"}, description = "output groove, roll, propeller twist, and helical twist (equivalent to -grpl).") + private boolean all = false; + } + + private boolean[] OUTPUT_TYPE = new boolean[]{false,false,false,false}; + @Override public Integer call() throws Exception { System.err.println( ">DNAShapefromBEDCLI.call()" ); @@ -42,16 +71,85 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + // Generate Composite Plot + DNAShapefromBED script_obj = new DNAShapefromBED(genomeFASTA, bedFile, outputBasename, OUTPUT_TYPE, forceStrand, new PrintStream[]{null,null,null,null}); + script_obj.run(); - //System.err.println("Calculations Complete"); + // Print Composite Scores + try { + if(avgComposite){ + String[] headers = new String[]{"AVG_MGW","AVG_PropT","AVG_HelT","AVG_Roll"}; + for(int t=0; t BED = null; + private File BED = null; private boolean STRAND = true; private boolean INDEX = true; @@ -44,41 +40,29 @@ public class DNAShapefromBED extends JFrame { private PrintStream OUT_H = null; private PrintStream OUT_R = null; + private PrintStream[] PS = null; + static Map> STRUCTURE = null; + + double[] AVG_MGW = null; + double[] AVG_PropT = null; + double[] AVG_HelT = null; + double[] AVG_Roll = null; - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - final JTabbedPane tabbedPane_Scatterplot; - final JTabbedPane tabbedPane_Statistics; + Component chart_M = null; + Component chart_P = null; + Component chart_H = null; + Component chart_R = null; - public DNAShapefromBED(File gen, ArrayList b, File out, boolean[] type, boolean str) { - setTitle("DNA Shape Prediction Composite"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 600); - - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); - - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); - - tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("DNA Shape Plot", null, tabbedPane_Scatterplot, null); - - tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("DNA Shape Statistics", null, tabbedPane_Statistics, null); - + public DNAShapefromBED(File gen, File b, String out, boolean[] type, boolean str, PrintStream[] ps) { GENOME = gen; BED = b; - OUTPUTPATH = out; + OUTBASENAME = out; OUTPUT_TYPE = type; STRAND = str; + PS = ps; + + STRUCTURE = DNAShapeReference.InitializeStructure(); } public void run() throws IOException, InterruptedException { @@ -86,219 +70,168 @@ public void run() throws IOException, InterruptedException { //Check if FAI index file exists if(!FAI.exists() || FAI.isDirectory()) { INDEX = FASTAUtilities.buildFASTAIndex(GENOME); - } - if(INDEX) { - try{ - IndexedFastaSequenceFile QUERY = new IndexedFastaSequenceFile(GENOME); - STRUCTURE = DNAShapeReference.InitializeStructure(); - - for(int x = 0; x < BED.size(); x++) { - String NAME = BED.get(x).getName().split("\\.")[0]; - String time = getTimeStamp(); //Generate TimeStamp - JTextArea STATS_MGW = null; - JTextArea STATS_PropT = null; - JTextArea STATS_HelT = null; - JTextArea STATS_Roll = null; - if(OUTPUT_TYPE[0]) { - STATS_MGW = new JTextArea(); - STATS_MGW.setEditable(false); - STATS_MGW.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[1]) { - STATS_PropT = new JTextArea(); - STATS_PropT.setEditable(false); - STATS_PropT.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[2]) { - STATS_HelT = new JTextArea(); - STATS_HelT.setEditable(false); - STATS_HelT.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[3]) { - STATS_Roll = new JTextArea(); - STATS_Roll.setEditable(false); - STATS_Roll.append(time + "\n" + NAME + "\n"); - } - openOutputFiles(x); - ArrayList BED_Coord = loadCoord(BED.get(x)); - - double[] AVG_MGW = null; - double[] AVG_PropT = null; - double[] AVG_HelT = null; - double[] AVG_Roll = null; - - for(int y = 0; y < BED_Coord.size(); y++) { - try { - String seq = new String(QUERY.getSubsequenceAt(BED_Coord.get(y).getChrom(), BED_Coord.get(y).getStart() + 1, BED_Coord.get(y).getStop()).getBases()).toUpperCase(); - if(!seq.contains("N")) { - if(STRAND && BED_Coord.get(y).getDir().equals("-")) { seq = FASTAUtilities.RevComplement(seq); } - //Populate array for each BED file - List MGW = new ArrayList(); - List PropT = new ArrayList(); - List HelT = new ArrayList(); - List Roll = new ArrayList(); - for(int z = 0; z < seq.length() - 4; z++) { - String key = seq.substring(z, z + 5); - List SCORES = STRUCTURE.get(key); - if(OUTPUT_TYPE[0]) { MGW.add(SCORES.get(0)); } - if(OUTPUT_TYPE[1]) { PropT.add(SCORES.get(1)); } - if(OUTPUT_TYPE[2]) { - if(z == 0) { - HelT.add(SCORES.get(2)); - HelT.add(SCORES.get(3)); - } else { - HelT.set(HelT.size() - 1, (HelT.get(HelT.size() - 1) + SCORES.get(2)) / 2); - HelT.add(SCORES.get(3)); - } - } - if(OUTPUT_TYPE[3]) { - if(z == 0) { - Roll.add(SCORES.get(4)); - Roll.add(SCORES.get(5)); - } else { - Roll.set(Roll.size() - 1, (Roll.get(Roll.size() - 1) + SCORES.get(4)) / 2); - Roll.add(SCORES.get(5)); - } - } - } - - if(OUTPUT_TYPE[0]) { - if(y == 0) { - OUT_M.print("YORF\tNAME"); - for(int z = 0; z < MGW.size(); z++) { OUT_M.print("\t" + z); } - OUT_M.println(); - AVG_MGW = new double[MGW.size()]; - } - OUT_M.print(BED_Coord.get(y).getName() + "\t" + BED_Coord.get(y).getName()); - for(int z = 0; z < MGW.size(); z++) { - OUT_M.print("\t" + MGW.get(z)); - AVG_MGW[z] += MGW.get(z); - } - OUT_M.println(); - } - if(OUTPUT_TYPE[1]) { - if(y == 0) { - OUT_P.print("YORF\tNAME"); - for(int z = 0; z < PropT.size(); z++) { OUT_P.print("\t" + z); } - OUT_P.println(); - AVG_PropT = new double[PropT.size()]; - } - OUT_P.print(BED_Coord.get(y).getName() + "\t" + BED_Coord.get(y).getName()); - for(int z = 0; z < PropT.size(); z++) { - OUT_P.print("\t" + PropT.get(z)); - AVG_PropT[z] += PropT.get(z); - } - OUT_P.println(); - } - if(OUTPUT_TYPE[2]) { - if(y == 0) { - OUT_H.print("YORF\tNAME"); - for(int z = 0; z < HelT.size(); z++) { OUT_H.print("\t" + z); } - OUT_H.println(); - AVG_HelT = new double[HelT.size()]; - } - OUT_H.print(BED_Coord.get(y).getName() + "\t" + BED_Coord.get(y).getName()); - for(int z = 0; z < HelT.size(); z++) { - OUT_H.print("\t" + HelT.get(z)); - AVG_HelT[z] += HelT.get(z); - } - OUT_H.println(); + if(!INDEX){ return; } + } + + try{ + IndexedFastaSequenceFile QUERY = new IndexedFastaSequenceFile(GENOME); + + String NAME = BED.getName().split("\\.")[0]; + String time = getTimeStamp(); //Generate TimeStamp + for(int p=0; p BED_Coord = loadCoord(BED); + + for(int y = 0; y < BED_Coord.size(); y++) { + try { + String seq = new String(QUERY.getSubsequenceAt(BED_Coord.get(y).getChrom(), BED_Coord.get(y).getStart() + 1, BED_Coord.get(y).getStop()).getBases()).toUpperCase(); + if(!seq.contains("N")) { + if(STRAND && BED_Coord.get(y).getDir().equals("-")) { seq = FASTAUtilities.RevComplement(seq); } + //Populate array for each BED file + List MGW = new ArrayList(); + List PropT = new ArrayList(); + List HelT = new ArrayList(); + List Roll = new ArrayList(); + for(int z = 0; z < seq.length() - 4; z++) { + String key = seq.substring(z, z + 5); + List SCORES = STRUCTURE.get(key); + if(OUTPUT_TYPE[0]) { MGW.add(SCORES.get(0)); } + if(OUTPUT_TYPE[1]) { PropT.add(SCORES.get(1)); } + if(OUTPUT_TYPE[2]) { + if(z == 0) { + HelT.add(SCORES.get(2)); + HelT.add(SCORES.get(3)); + } else { + HelT.set(HelT.size() - 1, (HelT.get(HelT.size() - 1) + SCORES.get(2)) / 2); + HelT.add(SCORES.get(3)); } - if(OUTPUT_TYPE[3]) { - if(y == 0) { - OUT_R.print("YORF\tNAME"); - for(int z = 0; z < Roll.size(); z++) { OUT_R.print("\t" + z); } - OUT_R.println(); - AVG_Roll = new double[Roll.size()]; - } - OUT_R.print(BED_Coord.get(y).getName() + "\t" + BED_Coord.get(y).getName()); - for(int z = 0; z < Roll.size(); z++) { - OUT_R.print("\t" + Roll.get(z)); - AVG_Roll[z] += Roll.get(z); - } - OUT_R.println(); + } + if(OUTPUT_TYPE[3]) { + if(z == 0) { + Roll.add(SCORES.get(4)); + Roll.add(SCORES.get(5)); + } else { + Roll.set(Roll.size() - 1, (Roll.get(Roll.size() - 1) + SCORES.get(4)) / 2); + Roll.add(SCORES.get(5)); } } - } catch (SAMException e) { - if(OUTPUT_TYPE[0]) { STATS_MGW.append("INVALID COORDINATE: " + BED_Coord.get(y).toString() + "\n"); } - if(OUTPUT_TYPE[1]) { STATS_PropT.append("INVALID COORDINATE: " + BED_Coord.get(y).toString() + "\n"); } - if(OUTPUT_TYPE[2]) { STATS_HelT.append("INVALID COORDINATE: " + BED_Coord.get(y).toString() + "\n"); } - if(OUTPUT_TYPE[3]) { STATS_Roll.append("INVALID COORDINATE: " + BED_Coord.get(y).toString() + "\n"); } - } - } - - //Convert average and statistics to output tabs panes - if(OUTPUT_TYPE[0]) { - OUT_M.close(); - double[] DOMAIN_MGW = new double[AVG_MGW.length]; - int temp = (int) (((double)AVG_MGW.length / 2.0) + 0.5); - for(int z = 0; z < AVG_MGW.length; z++) { - DOMAIN_MGW[z] = (double)(temp - (AVG_MGW.length - z)); - AVG_MGW[z] /= BED_Coord.size(); - STATS_MGW.append(DOMAIN_MGW[z] + "\t" + AVG_MGW[z] + "\n"); + }//Move through seq by window + + if(OUTPUT_TYPE[0]) { + if(y == 0) { + OUT_M.print("YORF\tNAME"); + for(int z = 0; z < MGW.size(); z++) { OUT_M.print("\t" + z); } + OUT_M.println(); + AVG_MGW = new double[MGW.size()]; + } + AVG_MGW = printVals(BED_Coord.get(y), MGW, AVG_MGW, OUT_M); } - tabbedPane_Scatterplot.add("MGW", CompositePlot.createCompositePlot(DOMAIN_MGW, AVG_MGW, NAME + " MGW")); - STATS_MGW.setCaretPosition(0); - JScrollPane MGWpane = new JScrollPane(STATS_MGW, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("MGW", MGWpane); - } - if(OUTPUT_TYPE[1]) { - OUT_P.close(); - double[] DOMAIN_PropT = new double[AVG_PropT.length]; - int temp = (int) (((double)AVG_PropT.length / 2.0) + 0.5); - for(int z = 0; z < AVG_PropT.length; z++) { - DOMAIN_PropT[z] = (double)(temp - (AVG_PropT.length - z)); - AVG_PropT[z] /= BED_Coord.size(); - STATS_PropT.append(DOMAIN_PropT[z] + "\t" + AVG_PropT[z] + "\n"); + if(OUTPUT_TYPE[1]) { + if(y == 0) { + OUT_P.print("YORF\tNAME"); + for(int z = 0; z < PropT.size(); z++) { OUT_P.print("\t" + z); } + OUT_P.println(); + AVG_PropT = new double[PropT.size()]; + } + AVG_PropT = printVals(BED_Coord.get(y), PropT, AVG_PropT, OUT_P); } - tabbedPane_Scatterplot.add("Propeller Twist", CompositePlot.createCompositePlot(DOMAIN_PropT, AVG_PropT, NAME + " PropT")); - STATS_PropT.setCaretPosition(0); - JScrollPane PropTpane = new JScrollPane(STATS_PropT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("PropT", PropTpane); - } - if(OUTPUT_TYPE[2]) { - OUT_H.close(); - double[] DOMAIN_HelT = new double[AVG_HelT.length]; - int temp = (int) (((double)AVG_HelT.length / 2.0) + 0.5); - for(int z = 0; z < AVG_HelT.length; z++) { - DOMAIN_HelT[z] = (double)(temp - (AVG_HelT.length - z)); - AVG_HelT[z] /= BED_Coord.size(); - STATS_HelT.append(DOMAIN_HelT[z] + "\t" + AVG_HelT[z] + "\n"); + if(OUTPUT_TYPE[2]) { + if(y == 0) { + OUT_H.print("YORF\tNAME"); + for(int z = 0; z < HelT.size(); z++) { OUT_H.print("\t" + z); } + OUT_H.println(); + AVG_HelT = new double[HelT.size()]; + } + AVG_HelT = printVals(BED_Coord.get(y), HelT, AVG_HelT, OUT_H); } - tabbedPane_Scatterplot.add("Helical Twist", CompositePlot.createCompositePlot(DOMAIN_HelT, AVG_HelT, NAME + " HelT")); - STATS_HelT.setCaretPosition(0); - JScrollPane HelTpane = new JScrollPane(STATS_HelT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("HelT", HelTpane); - } - if(OUTPUT_TYPE[3]) { - OUT_R.close(); - double[] DOMAIN_Roll = new double[AVG_Roll.length]; - int temp = (int) (((double)AVG_Roll.length / 2.0) + 0.5); - for(int z = 0; z < AVG_Roll.length; z++) { - DOMAIN_Roll[z] = (double)(temp - (AVG_Roll.length - z)); - AVG_Roll[z] /= BED_Coord.size(); - STATS_Roll.append(DOMAIN_Roll[z] + "\t" + AVG_Roll[z] + "\n"); + if(OUTPUT_TYPE[3]) { + if(y == 0) { + OUT_R.print("YORF\tNAME"); + for(int z = 0; z < Roll.size(); z++) { OUT_R.print("\t" + z); } + OUT_R.println(); + AVG_Roll = new double[Roll.size()]; + } + AVG_Roll = printVals(BED_Coord.get(y), Roll, AVG_Roll, OUT_R); } - tabbedPane_Scatterplot.add("Roll", CompositePlot.createCompositePlot(DOMAIN_Roll, AVG_Roll, NAME + " Roll")); - STATS_Roll.setCaretPosition(0); - JScrollPane Rollpane = new JScrollPane(STATS_Roll, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("Roll", Rollpane); + }//if seq contains 'N' + } catch (SAMException e) { + for(int p=0; p loadCoord(File INPUT) throws FileNotFoundException { Scanner scan = new Scanner(INPUT); @@ -323,30 +256,32 @@ public ArrayList loadCoord(File INPUT) throws FileNotFoundException { return COORD; } - private void openOutputFiles(int index) { - String NAME = BED.get(index).getName().split("\\.")[0]; + private void openOutputFiles() { + if(OUTBASENAME==null){ + OUTBASENAME = BED.getName().split("\\.")[0]; + } //Open Output File - if(OUTPUTPATH != null) { - try { - if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_MGW.cdt")); } - if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_PTwist.cdt")); } - if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_HTwist.cdt")); } - if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_Roll.cdt")); } - } catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { - if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(NAME + "_MGW.cdt")); } - if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(NAME + "_PropT.cdt")); } - if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(NAME + "_HelT.cdt")); } - if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(NAME + "_Roll.cdt")); } - } catch (FileNotFoundException e) { e.printStackTrace(); } + try{ + if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(OUTBASENAME + "_MGW.cdt")); } + if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(OUTBASENAME + "_PropT.cdt")); } + if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(OUTBASENAME + "_HelT.cdt")); } + if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(OUTBASENAME + "_Roll.cdt")); } + } catch(FileNotFoundException e){ e.printStackTrace(); } + } + + private double[] printVals(BEDCoord b, List SCORES, double[] AVG, PrintStream O){ + O.print(b.getName() + "\t" + b.getName()); + for(int z = 0; z < SCORES.size(); z++) { + O.print("\t" + SCORES.get(z)); + AVG[z] += SCORES.get(z); } + O.println(); + return(AVG); } private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); return time; - } + } } \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/DNAShapefromBEDOutput.java b/src/window_interface/Sequence_Analysis/DNAShapefromBEDOutput.java new file mode 100644 index 000000000..4d7751b12 --- /dev/null +++ b/src/window_interface/Sequence_Analysis/DNAShapefromBEDOutput.java @@ -0,0 +1,153 @@ +package window_interface.Sequence_Analysis; + +import htsjdk.samtools.SAMException; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.SpringLayout; + +import objects.CustomOutputStream; +import scripts.Sequence_Analysis.DNAShapefromBED; + +@SuppressWarnings("serial") +public class DNAShapefromBEDOutput extends JFrame { + private File GENOME = null; + private File OUTPUTPATH = null; + private boolean[] OUTPUT_TYPE = null; + private ArrayList BED = null; + + private boolean STRAND = true; + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + final JTabbedPane tabbedPane_Scatterplot; + final JTabbedPane tabbedPane_Statistics; + + public DNAShapefromBEDOutput(File gen, ArrayList b, File out, boolean[] type, boolean str) { + setTitle("DNA Shape Prediction Composite"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 600); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("DNA Shape Plot", null, tabbedPane_Scatterplot, null); + + tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("DNA Shape Statistics", null, tabbedPane_Statistics, null); + + GENOME = gen; + BED = b; + OUTPUTPATH = out; + OUTPUT_TYPE = type; + STRAND = str; + } + + public void run() throws IOException, InterruptedException { + try{ + //Move through each BED File + for(int x = 0; x < BED.size(); x++) { + //Initialize TextAreas and PrintStream wrappers + JTextArea STATS_MGW = null; + JTextArea STATS_PropT = null; + JTextArea STATS_HelT = null; + JTextArea STATS_Roll = null; + PrintStream[] PS = {null, null, null, null}; + if(OUTPUT_TYPE[0]) { + STATS_MGW = new JTextArea(); + STATS_MGW.setEditable(false); + PS[0] = new PrintStream(new CustomOutputStream(STATS_MGW)); + } + if(OUTPUT_TYPE[1]) { + STATS_PropT = new JTextArea(); + STATS_PropT.setEditable(false); + PS[1] = new PrintStream(new CustomOutputStream(STATS_PropT)); + } + if(OUTPUT_TYPE[2]) { + STATS_HelT = new JTextArea(); + STATS_HelT.setEditable(false); + PS[2] = new PrintStream(new CustomOutputStream(STATS_HelT)); + } + if(OUTPUT_TYPE[3]) { + STATS_Roll = new JTextArea(); + STATS_Roll.setEditable(false); + PS[3] = new PrintStream(new CustomOutputStream(STATS_Roll)); + } + + //Open Output File + String BASENAME = BED.get(x).getName().split("\\.")[0]; + try { + if(OUTPUTPATH != null) { + BASENAME = OUTPUTPATH.getCanonicalPath() + File.separator + BASENAME; + } + } catch (FileNotFoundException e) { e.printStackTrace(); } + catch (IOException e) { e.printStackTrace(); } + + //Initialize Script Object and execute calculations + DNAShapefromBED script_obj = new DNAShapefromBED(GENOME, BED.get(x), BASENAME, OUTPUT_TYPE, STRAND, PS); + script_obj.run(); + + //Exit if FAI failed checks + if(!script_obj.getFAIstatus()) { + JOptionPane.showMessageDialog(null, "Genome FASTA file contains invalid lines!!!\n"); + break; + } + + //Convert average and statistics to output tabs panes + if(OUTPUT_TYPE[0]) { + tabbedPane_Scatterplot.add("MGW", script_obj.getChartM()); + STATS_MGW.setCaretPosition(0); + JScrollPane MGWpane = new JScrollPane(STATS_MGW, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("MGW", MGWpane); + } + if(OUTPUT_TYPE[1]) { + tabbedPane_Scatterplot.add("Propeller Twist", script_obj.getChartP()); + STATS_PropT.setCaretPosition(0); + JScrollPane PropTpane = new JScrollPane(STATS_PropT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("PropT", PropTpane); + } + if(OUTPUT_TYPE[2]) { + tabbedPane_Scatterplot.add("Helical Twist", script_obj.getChartH()); + STATS_HelT.setCaretPosition(0); + JScrollPane HelTpane = new JScrollPane(STATS_HelT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("HelT", HelTpane); + } + if(OUTPUT_TYPE[3]) { + tabbedPane_Scatterplot.add("Roll", script_obj.getChartR()); + STATS_Roll.setCaretPosition(0); + JScrollPane Rollpane = new JScrollPane(STATS_Roll, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("Roll", Rollpane); + } + + firePropertyChange("fa",x, x + 1); + } + } catch(IllegalArgumentException e) { + JOptionPane.showMessageDialog(null, e.getMessage()); + } catch(FileNotFoundException e) { + JOptionPane.showMessageDialog(null, e.getMessage()); + } catch(SAMException e) { + JOptionPane.showMessageDialog(null, e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/DNAShapefromBEDWindow.java b/src/window_interface/Sequence_Analysis/DNAShapefromBEDWindow.java index 2fdd6c66b..b3d8c7922 100644 --- a/src/window_interface/Sequence_Analysis/DNAShapefromBEDWindow.java +++ b/src/window_interface/Sequence_Analysis/DNAShapefromBEDWindow.java @@ -32,7 +32,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Sequence_Analysis.DNAShapefromBED; +import window_interface.Sequence_Analysis.DNAShapefromBEDOutput; @SuppressWarnings("serial") public class DNAShapefromBEDWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -80,7 +80,7 @@ public Void doInBackground() throws IOException { OUTPUT_TYPE[2] = chckbxHelicalTwist.isSelected(); OUTPUT_TYPE[3] = chckbxRoll.isSelected(); - DNAShapefromBED signal = new DNAShapefromBED(INPUT, BEDFiles, OUTPUT_PATH, OUTPUT_TYPE, chckbxStrand.isSelected()); + DNAShapefromBEDOutput signal = new DNAShapefromBEDOutput(INPUT, BEDFiles, OUTPUT_PATH, OUTPUT_TYPE, chckbxStrand.isSelected()); signal.addPropertyChangeListener("fa", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From 93d10a2458ee4f31e7d398d7c5f367bfd97a8b8d Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 19:31:43 -0400 Subject: [PATCH 19/43] create DNAShapefromFASTA command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/DNAShapefromFASTAOutput class while the calculations are kept in the src/scripts/*/DNAShapefromFASTA class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full file basename and not just directory script/* -strip out JFrame objects -use output as file basename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../DNAShapefromFASTACLI.java | 100 ++++- .../Sequence_Analysis/DNAShapefromFASTA.java | 413 ++++++++---------- .../DNAShapefromFASTAOutput.java | 131 ++++++ .../DNAShapefromFASTAWindow.java | 4 +- 4 files changed, 404 insertions(+), 244 deletions(-) create mode 100644 src/window_interface/Sequence_Analysis/DNAShapefromFASTAOutput.java diff --git a/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java b/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java index 91869dd72..94dc16fee 100644 --- a/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java +++ b/src/cli/Sequence_Analysis/DNAShapefromFASTACLI.java @@ -20,7 +20,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Sequence_Analysis.DNAShapefromFASTA; +import scripts.Sequence_Analysis.DNAShapefromFASTA; /** Sequence_AnalysisCLI/DNAShapefromFASTACLI @@ -32,6 +32,31 @@ exitCodeOnExecutionException = 1) public class DNAShapefromFASTACLI implements Callable { + @Parameters( index = "0", description = "FASTA sequence file") + private File fastaFile; + + @Option(names = {"-o", "--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 = {"--avg-composite"}, description = "Save average composite") + private boolean avgComposite = false; + + @ArgGroup(validate = false, heading = "Shape Options%n") + ShapeType shape = new ShapeType(); + static class ShapeType{ + @Option(names = {"-g","--groove"}, description = "output minor groove width") + private boolean groove = false; + @Option(names = {"-r","--roll"}, description = "output roll") + private boolean roll = false; + @Option(names = {"-p","--propeller"}, description = "output propeller twist") + private boolean propeller = false; + @Option(names = {"-l","--helical"}, description = "output helical twist") + private boolean helical = false; + @Option(names = {"-a","--all"}, description = "output groove, roll, propeller twist, and helical twist (equivalent to -grpl).") + private boolean all = false; + } + + private boolean[] OUTPUT_TYPE = new boolean[]{false,false,false,false}; + @Override public Integer call() throws Exception { System.err.println( ">DNAShapefromFASTACLI.call()" ); @@ -42,16 +67,79 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + // Generate Composite Plot + DNAShapefromFASTA script_obj = new DNAShapefromFASTA(fastaFile, outputBasename, OUTPUT_TYPE, new PrintStream[]{null,null,null,null}); + script_obj.run(); + + // Print Composite Scores + try { + if(avgComposite){ + String[] headers = new String[]{"AVG_MGW","AVG_PropT","AVG_HelT","AVG_Roll"}; + for(int t=0; t FASTA = null; - + private File FASTA = null; + private PrintStream OUT_M = null; private PrintStream OUT_P = null; private PrintStream OUT_H = null; private PrintStream OUT_R = null; + private PrintStream[] PS = null; + static Map> STRUCTURE = null; - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - final JTabbedPane tabbedPane_Scatterplot; - final JTabbedPane tabbedPane_Statistics; + double[] AVG_MGW = null; + double[] AVG_PropT = null; + double[] AVG_HelT = null; + double[] AVG_Roll = null; - public DNAShapefromFASTA(ArrayList b, File out, boolean[] type) { - setTitle("DNA Shape Prediction Composite"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 600); - - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); - - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); - - tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("DNA Shape Plot", null, tabbedPane_Scatterplot, null); - - tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("DNA Shape Statistics", null, tabbedPane_Statistics, null); - - FASTA = b; - OUTPUTPATH = out; + Component chart_M = null; + Component chart_P = null; + Component chart_H = null; + Component chart_R = null; + + public DNAShapefromFASTA(File fa, String out, boolean[] type, PrintStream[] ps) { + FASTA = fa; + OUTBASENAME = out; OUTPUT_TYPE = type; + PS = ps; + + STRUCTURE = DNAShapeReference.InitializeStructure(); } public void run() throws IOException, InterruptedException { - STRUCTURE = DNAShapeReference.InitializeStructure(); - - for(int x = 0; x < FASTA.size(); x++) { - String NAME = FASTA.get(x).getName().split("\\.")[0]; - String time = getTimeStamp(); //Generate TimeStamp - JTextArea STATS_MGW = null; - JTextArea STATS_PropT = null; - JTextArea STATS_HelT = null; - JTextArea STATS_Roll = null; - if(OUTPUT_TYPE[0]) { - STATS_MGW = new JTextArea(); - STATS_MGW.setEditable(false); - STATS_MGW.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[1]) { - STATS_PropT = new JTextArea(); - STATS_PropT.setEditable(false); - STATS_PropT.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[2]) { - STATS_HelT = new JTextArea(); - STATS_HelT.setEditable(false); - STATS_HelT.append(time + "\n" + NAME + "\n"); - } - if(OUTPUT_TYPE[3]) { - STATS_Roll = new JTextArea(); - STATS_Roll.setEditable(false); - STATS_Roll.append(time + "\n" + NAME + "\n"); - } - openOutputFiles(x); - - double[] AVG_MGW = null; - double[] AVG_PropT = null; - double[] AVG_HelT = null; - double[] AVG_Roll = null; - - Scanner scan = new Scanner(FASTA.get(x)); - int counter = 0; - while (scan.hasNextLine()) { - String HEADER = scan.nextLine(); - if(HEADER.contains(">")) { - HEADER = HEADER.substring(1, HEADER.length()); - String seq = scan.nextLine(); - if(!seq.contains("N")) { - //Populate array for each FASTA line - List MGW = new ArrayList(); - List PropT = new ArrayList(); - List HelT = new ArrayList(); - List Roll = new ArrayList(); - for(int z = 0; z < seq.length() - 4; z++) { - String key = seq.substring(z, z + 5); - List SCORES = STRUCTURE.get(key); - if(OUTPUT_TYPE[0]) { MGW.add(SCORES.get(0)); } - if(OUTPUT_TYPE[1]) { PropT.add(SCORES.get(1)); } - if(OUTPUT_TYPE[2]) { - if(z == 0) { - HelT.add(SCORES.get(2)); - HelT.add(SCORES.get(3)); - } else { - HelT.set(HelT.size() - 1, (HelT.get(HelT.size() - 1) + SCORES.get(2)) / 2); - HelT.add(SCORES.get(3)); - } - } - if(OUTPUT_TYPE[3]) { - if(z == 0) { - Roll.add(SCORES.get(4)); - Roll.add(SCORES.get(5)); - } else { - Roll.set(Roll.size() - 1, (Roll.get(Roll.size() - 1) + SCORES.get(4)) / 2); - Roll.add(SCORES.get(5)); - } + String NAME = FASTA.getName().split("\\.")[0]; + String time = getTimeStamp(); //Generate TimeStamp + for(int p=0; p")) { + HEADER = HEADER.substring(1, HEADER.length()); + String seq = scan.nextLine(); + if(!seq.contains("N")) { + //Populate array for each FASTA line + List MGW = new ArrayList(); + List PropT = new ArrayList(); + List HelT = new ArrayList(); + List Roll = new ArrayList(); + for(int z = 0; z < seq.length() - 4; z++) { + String key = seq.substring(z, z + 5); + List SCORES = STRUCTURE.get(key); + if(OUTPUT_TYPE[0]) { MGW.add(SCORES.get(0)); } + if(OUTPUT_TYPE[1]) { PropT.add(SCORES.get(1)); } + if(OUTPUT_TYPE[2]) { + if(z == 0) { + HelT.add(SCORES.get(2)); + HelT.add(SCORES.get(3)); + } else { + HelT.set(HelT.size() - 1, (HelT.get(HelT.size() - 1) + SCORES.get(2)) / 2); + HelT.add(SCORES.get(3)); } } - - if(OUTPUT_TYPE[0]) { - if(counter == 0) { - OUT_M.print("YORF\tNAME"); - for(int z = 0; z < MGW.size(); z++) { OUT_M.print("\t" + z); } - OUT_M.println(); - AVG_MGW = new double[MGW.size()]; - } - OUT_M.print(HEADER + "\t" + HEADER); - for(int z = 0; z < MGW.size(); z++) { - OUT_M.print("\t" + MGW.get(z)); - AVG_MGW[z] += MGW.get(z); + if(OUTPUT_TYPE[3]) { + if(z == 0) { + Roll.add(SCORES.get(4)); + Roll.add(SCORES.get(5)); + } else { + Roll.set(Roll.size() - 1, (Roll.get(Roll.size() - 1) + SCORES.get(4)) / 2); + Roll.add(SCORES.get(5)); } + } + } + + if(OUTPUT_TYPE[0]) { + if(counter == 0) { + OUT_M.print("YORF\tNAME"); + for(int z = 0; z < MGW.size(); z++) { OUT_M.print("\t" + z); } OUT_M.println(); + AVG_MGW = new double[MGW.size()]; } - if(OUTPUT_TYPE[1]) { - if(counter == 0) { - OUT_P.print("YORF\tNAME"); - for(int z = 0; z < PropT.size(); z++) { OUT_P.print("\t" + z); } - OUT_P.println(); - AVG_PropT = new double[PropT.size()]; - } - OUT_P.print(HEADER + "\t" + HEADER); - for(int z = 0; z < PropT.size(); z++) { - OUT_P.print("\t" + PropT.get(z)); - AVG_PropT[z] += PropT.get(z); - } + AVG_MGW = printVals(HEADER, MGW, AVG_MGW, OUT_M); + } + if(OUTPUT_TYPE[1]) { + if(counter == 0) { + OUT_P.print("YORF\tNAME"); + for(int z = 0; z < PropT.size(); z++) { OUT_P.print("\t" + z); } OUT_P.println(); + AVG_PropT = new double[PropT.size()]; } - if(OUTPUT_TYPE[2]) { - if(counter == 0) { - OUT_H.print("YORF\tNAME"); - for(int z = 0; z < HelT.size(); z++) { OUT_H.print("\t" + z); } - OUT_H.println(); - AVG_HelT = new double[HelT.size()]; - } - OUT_H.print(HEADER + "\t" + HEADER); - for(int z = 0; z < HelT.size(); z++) { - OUT_H.print("\t" + HelT.get(z)); - AVG_HelT[z] += HelT.get(z); - } + AVG_PropT = printVals(HEADER, PropT, AVG_PropT, OUT_P); + } + if(OUTPUT_TYPE[2]) { + if(counter == 0) { + OUT_H.print("YORF\tNAME"); + for(int z = 0; z < HelT.size(); z++) { OUT_H.print("\t" + z); } OUT_H.println(); + AVG_HelT = new double[HelT.size()]; } - if(OUTPUT_TYPE[3]) { - if(counter == 0) { - OUT_R.print("YORF\tNAME"); - for(int z = 0; z < Roll.size(); z++) { OUT_R.print("\t" + z); } - OUT_R.println(); - AVG_Roll = new double[Roll.size()]; - } - OUT_R.print(HEADER + "\t" + HEADER); - for(int z = 0; z < Roll.size(); z++) { - OUT_R.print("\t" + Roll.get(z)); - AVG_Roll[z] += Roll.get(z); - } + AVG_HelT = printVals(HEADER, HelT, AVG_HelT, OUT_H); + } + if(OUTPUT_TYPE[3]) { + if(counter == 0) { + OUT_R.print("YORF\tNAME"); + for(int z = 0; z < Roll.size(); z++) { OUT_R.print("\t" + z); } OUT_R.println(); + AVG_Roll = new double[Roll.size()]; } + AVG_Roll = printVals(HEADER, Roll, AVG_Roll, OUT_R); } - counter++; - } else { - System.out.println("ERROR: Invalid FASTA sequence\n" + HEADER); } + counter++; + } else { + System.out.println("ERROR: Invalid FASTA sequence\n" + HEADER); } - scan.close(); - - //Convert average and statistics to output tabs panes - if(OUTPUT_TYPE[0]) { - OUT_M.close(); - double[] DOMAIN_MGW = new double[AVG_MGW.length]; - int temp = (int) (((double)AVG_MGW.length / 2.0) + 0.5); - for(int z = 0; z < AVG_MGW.length; z++) { - DOMAIN_MGW[z] = (double)(temp - (AVG_MGW.length - z)); - AVG_MGW[z] /= counter; - STATS_MGW.append(DOMAIN_MGW[z] + "\t" + AVG_MGW[z] + "\n"); - } - tabbedPane_Scatterplot.add("MGW", CompositePlot.createCompositePlot(DOMAIN_MGW, AVG_MGW, NAME + " MGW")); - STATS_MGW.setCaretPosition(0); - JScrollPane MGWpane = new JScrollPane(STATS_MGW, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("MGW", MGWpane); + } + scan.close(); + + //Convert average and statistics to output tabs panes + if(OUTPUT_TYPE[0]) { + OUT_M.close(); + double[] DOMAIN_MGW = new double[AVG_MGW.length]; + int temp = (int) (((double)AVG_MGW.length / 2.0) + 0.5); + for(int z = 0; z < AVG_MGW.length; z++) { + DOMAIN_MGW[z] = (double)(temp - (AVG_MGW.length - z)); + AVG_MGW[z] /= counter; + if(PS[0]!=null){ PS[0].println(DOMAIN_MGW[z] + "\t" + AVG_MGW[z]); } } - if(OUTPUT_TYPE[1]) { - OUT_P.close(); - double[] DOMAIN_PropT = new double[AVG_PropT.length]; - int temp = (int) (((double)AVG_PropT.length / 2.0) + 0.5); - for(int z = 0; z < AVG_PropT.length; z++) { - DOMAIN_PropT[z] = (double)(temp - (AVG_PropT.length - z)); - AVG_PropT[z] /= counter; - STATS_PropT.append(DOMAIN_PropT[z] + "\t" + AVG_PropT[z] + "\n"); - } - tabbedPane_Scatterplot.add("Propeller Twist", CompositePlot.createCompositePlot(DOMAIN_PropT, AVG_PropT, NAME + " PropT")); - STATS_PropT.setCaretPosition(0); - JScrollPane PropTpane = new JScrollPane(STATS_PropT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("PropT", PropTpane); + chart_M = CompositePlot.createCompositePlot(DOMAIN_MGW, AVG_MGW, NAME + " MGW"); + } + if(OUTPUT_TYPE[1]) { + OUT_P.close(); + double[] DOMAIN_PropT = new double[AVG_PropT.length]; + int temp = (int) (((double)AVG_PropT.length / 2.0) + 0.5); + for(int z = 0; z < AVG_PropT.length; z++) { + DOMAIN_PropT[z] = (double)(temp - (AVG_PropT.length - z)); + AVG_PropT[z] /= counter; + if(PS[1]!=null){ PS[1].println(DOMAIN_PropT[z] + "\t" + AVG_PropT[z]); } } - if(OUTPUT_TYPE[2]) { - OUT_H.close(); - double[] DOMAIN_HelT = new double[AVG_HelT.length]; - int temp = (int) (((double)AVG_HelT.length / 2.0) + 0.5); - for(int z = 0; z < AVG_HelT.length; z++) { - DOMAIN_HelT[z] = (double)(temp - (AVG_HelT.length - z)); - AVG_HelT[z] /= counter; - STATS_HelT.append(DOMAIN_HelT[z] + "\t" + AVG_HelT[z] + "\n"); - } - tabbedPane_Scatterplot.add("Helical Twist", CompositePlot.createCompositePlot(DOMAIN_HelT, AVG_HelT, NAME + " HelT")); - STATS_HelT.setCaretPosition(0); - JScrollPane HelTpane = new JScrollPane(STATS_HelT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("HelT", HelTpane); + chart_P = CompositePlot.createCompositePlot(DOMAIN_PropT, AVG_PropT, NAME + " PropT"); + } + if(OUTPUT_TYPE[2]) { + OUT_H.close(); + double[] DOMAIN_HelT = new double[AVG_HelT.length]; + int temp = (int) (((double)AVG_HelT.length / 2.0) + 0.5); + for(int z = 0; z < AVG_HelT.length; z++) { + DOMAIN_HelT[z] = (double)(temp - (AVG_HelT.length - z)); + AVG_HelT[z] /= counter; + if(PS[2]!=null){ PS[2].println(DOMAIN_HelT[z] + "\t" + AVG_HelT[z]); } } - if(OUTPUT_TYPE[3]) { - OUT_R.close(); - double[] DOMAIN_Roll = new double[AVG_Roll.length]; - int temp = (int) (((double)AVG_Roll.length / 2.0) + 0.5); - for(int z = 0; z < AVG_Roll.length; z++) { - DOMAIN_Roll[z] = (double)(temp - (AVG_Roll.length - z)); - AVG_Roll[z] /= counter; - STATS_Roll.append(DOMAIN_Roll[z] + "\t" + AVG_Roll[z] + "\n"); - } - tabbedPane_Scatterplot.add("Roll", CompositePlot.createCompositePlot(DOMAIN_Roll, AVG_Roll, NAME + " Roll")); - STATS_Roll.setCaretPosition(0); - JScrollPane Rollpane = new JScrollPane(STATS_Roll, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add("Roll", Rollpane); + chart_H = CompositePlot.createCompositePlot(DOMAIN_HelT, AVG_HelT, NAME + " HelT"); + } + if(OUTPUT_TYPE[3]) { + OUT_R.close(); + double[] DOMAIN_Roll = new double[AVG_Roll.length]; + int temp = (int) (((double)AVG_Roll.length / 2.0) + 0.5); + for(int z = 0; z < AVG_Roll.length; z++) { + DOMAIN_Roll[z] = (double)(temp - (AVG_Roll.length - z)); + AVG_Roll[z] /= counter; + if(PS[3]!=null){ PS[3].println(DOMAIN_Roll[z] + "\t" + AVG_Roll[z]); } } - firePropertyChange("fa",x, x + 1); + chart_R = CompositePlot.createCompositePlot(DOMAIN_Roll, AVG_Roll, NAME + " Roll"); } } - + + public Component getChartM(){ return chart_M; } + public Component getChartP(){ return chart_P; } + public Component getChartH(){ return chart_H; } + public Component getChartR(){ return chart_R; } + + public double[] getAvg(int shapeType){ + if(shapeType==0){ return AVG_MGW; } + else if(shapeType==1){ return AVG_PropT; } + else if(shapeType==2){ return AVG_HelT; } + else if(shapeType==3){ return AVG_Roll; } + else { return null; } + } - private void openOutputFiles(int index) { - String NAME = FASTA.get(index).getName().split("\\.")[0]; + private void openOutputFiles() { + if(OUTBASENAME==null){ + OUTBASENAME = FASTA.getName().split("\\.")[0]; + } //Open Output File - if(OUTPUTPATH != null) { - try { - if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_MGW.cdt")); } - if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_PTwist.cdt")); } - if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_HTwist.cdt")); } - if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME + "_Roll.cdt")); } - } catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { - if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(NAME + "_MGW.cdt")); } - if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(NAME + "_PropT.cdt")); } - if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(NAME + "_HelT.cdt")); } - if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(NAME + "_Roll.cdt")); } - } catch (FileNotFoundException e) { e.printStackTrace(); } + try{ + if(OUTPUT_TYPE[0]) { OUT_M = new PrintStream(new File(OUTBASENAME + "_MGW.cdt")); } + if(OUTPUT_TYPE[1]) { OUT_P = new PrintStream(new File(OUTBASENAME + "_PropT.cdt")); } + if(OUTPUT_TYPE[2]) { OUT_H = new PrintStream(new File(OUTBASENAME + "_HelT.cdt")); } + if(OUTPUT_TYPE[3]) { OUT_R = new PrintStream(new File(OUTBASENAME + "_Roll.cdt")); } + } catch(FileNotFoundException e){ e.printStackTrace(); } + } + + private double[] printVals(String header, List SCORES, double[] AVG, PrintStream O){ + O.print(header + "\t" + header); + for(int z = 0; z < SCORES.size(); z++) { + O.print("\t" + SCORES.get(z)); + AVG[z] += SCORES.get(z); } + O.println(); + return(AVG); } private static String getTimeStamp() { diff --git a/src/window_interface/Sequence_Analysis/DNAShapefromFASTAOutput.java b/src/window_interface/Sequence_Analysis/DNAShapefromFASTAOutput.java new file mode 100644 index 000000000..5db8919d1 --- /dev/null +++ b/src/window_interface/Sequence_Analysis/DNAShapefromFASTAOutput.java @@ -0,0 +1,131 @@ +package window_interface.Sequence_Analysis; + +import htsjdk.samtools.SAMException; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.SpringLayout; + +import objects.CustomOutputStream; +import scripts.Sequence_Analysis.DNAShapefromFASTA; + +@SuppressWarnings("serial") +public class DNAShapefromFASTAOutput extends JFrame { + private File OUTPUTPATH = null; + private boolean[] OUTPUT_TYPE = null; + private ArrayList FASTA = null; + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + final JTabbedPane tabbedPane_Scatterplot; + final JTabbedPane tabbedPane_Statistics; + + public DNAShapefromFASTAOutput(ArrayList fa, File out, boolean[] type) { + setTitle("DNA Shape Prediction Composite"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 600); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("DNA Shape Plot", null, tabbedPane_Scatterplot, null); + + tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("DNA Shape Statistics", null, tabbedPane_Statistics, null); + + FASTA = fa; + OUTPUTPATH = out; + OUTPUT_TYPE = type; + } + + public void run() throws IOException, InterruptedException { + + for(int x = 0; x < FASTA.size(); x++) { + JTextArea STATS_MGW = null; + JTextArea STATS_PropT = null; + JTextArea STATS_HelT = null; + JTextArea STATS_Roll = null; + PrintStream[] PS = {null, null, null, null}; + if(OUTPUT_TYPE[0]) { + STATS_MGW = new JTextArea(); + STATS_MGW.setEditable(false); + PS[0] = new PrintStream(new CustomOutputStream(STATS_MGW)); + } + if(OUTPUT_TYPE[1]) { + STATS_PropT = new JTextArea(); + STATS_PropT.setEditable(false); + PS[1] = new PrintStream(new CustomOutputStream(STATS_PropT)); + } + if(OUTPUT_TYPE[2]) { + STATS_HelT = new JTextArea(); + STATS_HelT.setEditable(false); + PS[2] = new PrintStream(new CustomOutputStream(STATS_HelT)); + } + if(OUTPUT_TYPE[3]) { + STATS_Roll = new JTextArea(); + STATS_Roll.setEditable(false); + PS[3] = new PrintStream(new CustomOutputStream(STATS_Roll)); + } + + //Open Output File + String BASENAME = FASTA.get(x).getName().split("\\.")[0]; + try { + if(OUTPUTPATH != null) { + BASENAME = OUTPUTPATH.getCanonicalPath() + File.separator + BASENAME; + } + } catch (FileNotFoundException e) { e.printStackTrace(); } + catch (IOException e) { e.printStackTrace(); } + + //Initialize Script Object and execute calculations + DNAShapefromFASTA script_obj = new DNAShapefromFASTA(FASTA.get(x), BASENAME, OUTPUT_TYPE, PS); + script_obj.run(); + + //Convert average and statistics to output tabs panes + if(OUTPUT_TYPE[0]) { + tabbedPane_Scatterplot.add("MGW", script_obj.getChartM()); + STATS_MGW.setCaretPosition(0); + JScrollPane MGWpane = new JScrollPane(STATS_MGW, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("MGW", MGWpane); + } + if(OUTPUT_TYPE[1]) { + tabbedPane_Scatterplot.add("Propeller Twist", script_obj.getChartP()); + STATS_PropT.setCaretPosition(0); + JScrollPane PropTpane = new JScrollPane(STATS_PropT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("PropT", PropTpane); + } + if(OUTPUT_TYPE[2]) { + tabbedPane_Scatterplot.add("Helical Twist", script_obj.getChartH()); + STATS_HelT.setCaretPosition(0); + JScrollPane HelTpane = new JScrollPane(STATS_HelT, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("HelT", HelTpane); + } + if(OUTPUT_TYPE[3]) { + tabbedPane_Scatterplot.add("Roll", script_obj.getChartR()); + STATS_Roll.setCaretPosition(0); + JScrollPane Rollpane = new JScrollPane(STATS_Roll, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add("Roll", Rollpane); + } + firePropertyChange("fa",x, x + 1); + } + } +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/DNAShapefromFASTAWindow.java b/src/window_interface/Sequence_Analysis/DNAShapefromFASTAWindow.java index 0b9e7da7e..8c0bca728 100644 --- a/src/window_interface/Sequence_Analysis/DNAShapefromFASTAWindow.java +++ b/src/window_interface/Sequence_Analysis/DNAShapefromFASTAWindow.java @@ -32,7 +32,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Sequence_Analysis.DNAShapefromFASTA; +import window_interface.Sequence_Analysis.DNAShapefromFASTAOutput; @SuppressWarnings("serial") public class DNAShapefromFASTAWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -74,7 +74,7 @@ public Void doInBackground() throws IOException { OUTPUT_TYPE[2] = chckbxHelicalTwist.isSelected(); OUTPUT_TYPE[3] = chckbxRoll.isSelected(); - DNAShapefromFASTA signal = new DNAShapefromFASTA(FASTAFiles, OUTPUT_PATH, OUTPUT_TYPE); + DNAShapefromFASTAOutput signal = new DNAShapefromFASTAOutput(FASTAFiles, OUTPUT_PATH, OUTPUT_TYPE); signal.addPropertyChangeListener("fa", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From a64a37f439578f8c2dbe3a508b4697dc7cfbbfbd Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 19:37:04 -0400 Subject: [PATCH 20/43] create FASTAExtract command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/FASTAExtractOutput class while the calculations are kept in the src/scripts/*/FASTAExtract class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Sequence_Analysis/FASTAExtractCLI.java | 61 +++++++++++-- .../Sequence_Analysis/FASTAExtract.java | 86 +++++++----------- .../Sequence_Analysis/FASTAExtractOutput.java | 90 +++++++++++++++++++ .../Sequence_Analysis/FASTAExtractWindow.java | 4 +- 4 files changed, 179 insertions(+), 62 deletions(-) create mode 100644 src/window_interface/Sequence_Analysis/FASTAExtractOutput.java diff --git a/src/cli/Sequence_Analysis/FASTAExtractCLI.java b/src/cli/Sequence_Analysis/FASTAExtractCLI.java index fb290c9d4..ecf8e737b 100644 --- a/src/cli/Sequence_Analysis/FASTAExtractCLI.java +++ b/src/cli/Sequence_Analysis/FASTAExtractCLI.java @@ -14,7 +14,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Sequence_Analysis.FASTAExtract; +import scripts.Sequence_Analysis.FASTAExtract; /** Sequence_AnalysisCLI/FASTAExtractCLI @@ -26,6 +26,19 @@ exitCodeOnExecutionException = 1) public class FASTAExtractCLI implements Callable { + @Parameters( index = "0", description = "reference genome FASTA file") + private File genomeFASTA; + @Parameters( index = "1", description = "the BED file of sequences to extract") + private File bedFile; + + private File input; + @Option(names = {"-o", "--output"}, description = "Specify output file (default = .fa)") + private File output = null; + @Option(names = {"-c","--coord-header"}, description = "use genome coordinate for output FASTA header (default is to use bed file headers)") + private boolean bedHeader = true; + @Option(names = {"-n","--no-force"}, description = "don't force-strandedness (default is to force strandedness)") + private boolean forceStrand = true; + @Override public Integer call() throws Exception { System.err.println( ">FASTAExtractCLI.call()" ); @@ -36,16 +49,52 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + FASTAExtract script_obj = new FASTAExtract(genomeFASTA, bedFile, output, forceStrand, bedHeader, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Extraction Complete."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!genomeFASTA.exists()){ + r += "(!)FASTA genome ref file does not exist: " + genomeFASTA.getName() + "\n"; + return(r); + } + if(!bedFile.exists()){ + r += "(!)BED file does not exist: " + bedFile.getName() + "\n"; + 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(output==null){ + output = new File(ExtensionFileFilter.stripExtension(bedFile)+".fa"); + //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"; + } + } catch( NullPointerException e){ r += "(!)Output filename must have extension: use FASTA extension for output filename. Try: " + output + ".fa\n"; } + //check directory + if(output.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Sequence_Analysis/FASTAExtract.java b/src/scripts/Sequence_Analysis/FASTAExtract.java index 53330c470..0f9e5166f 100644 --- a/src/scripts/Sequence_Analysis/FASTAExtract.java +++ b/src/scripts/Sequence_Analysis/FASTAExtract.java @@ -13,93 +13,71 @@ import java.util.Arrays; import java.util.Scanner; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - import util.FASTAUtilities; @SuppressWarnings("serial") -public class FASTAExtract extends JFrame { +public class FASTAExtract { private File GENOME = null; - private File OUTPUTPATH = null; - private ArrayList BED = null; + private File OUTFILE = null; + private File BED = null; private PrintStream OUT = null; + private PrintStream PS = null; private boolean STRAND = true; private boolean HEADER = true; private boolean INDEX = true; - private JTextArea textArea; - - public FASTAExtract(File gen, ArrayList b, File out, boolean str, boolean head) { - setTitle("FASTA Extraction Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - + public FASTAExtract(File gen, File b, File out, boolean str, boolean head, PrintStream ps) { GENOME = gen; BED = b; - OUTPUTPATH = out; + OUTFILE = out; STRAND = str; HEADER = head; + PS = ps; } public void run() throws IOException, InterruptedException { + + if(PS==null) PS = System.err; + System.out.println("STRAND:" + STRAND); + System.out.println("COORD:" + HEADER); + File FAI = new File(GENOME + ".fai"); //Check if FAI index file exists if(!FAI.exists() || FAI.isDirectory()) { - textArea.append("FASTA Index file not found.\nGenerating new one...\n"); + PS.println("FASTA Index file not found.\nGenerating new one...\n"); INDEX = FASTAUtilities.buildFASTAIndex(GENOME); } if(INDEX) { try{ IndexedFastaSequenceFile QUERY = new IndexedFastaSequenceFile(GENOME); - for(int x = 0; x < BED.size(); x++) { - textArea.append("Proccessing File: " + BED.get(x).getName() + "\n"); - //Open Output File - String NAME = BED.get(x).getName().split("\\.")[0] + ".fa"; - if(OUTPUTPATH != null) { - try { OUT = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - catch (IOException e) { e.printStackTrace(); } - } else { - try { OUT = new PrintStream(new File(NAME)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - } - - ArrayList BED_Coord = loadCoord(BED.get(x)); - - for(int y = 0; y < BED_Coord.size(); y++) { - try { - String seq = new String(QUERY.getSubsequenceAt(BED_Coord.get(y).getChrom(), BED_Coord.get(y).getStart() + 1, BED_Coord.get(y).getStop()).getBases()); - if(STRAND && BED_Coord.get(y).getDir().equals("-")) { - seq = FASTAUtilities.RevComplement(seq); - } - OUT.println(">" + BED_Coord.get(y).getName() + "\n" + seq); - } catch (SAMException e) { - textArea.append("INVALID COORDINATE: " + BED_Coord.get(y).toString() + "\n"); + PS.println("Proccessing File: " + BED.getName()); + //Open Output File + OUT = new PrintStream(OUTFILE); + + ArrayList BED_Coord = loadCoord(BED); + + for(int y = 0; y < BED_Coord.size(); y++) { + try { + String seq = new String(QUERY.getSubsequenceAt(BED_Coord.get(y).getChrom(), BED_Coord.get(y).getStart() + 1, BED_Coord.get(y).getStop()).getBases()); + if(STRAND && BED_Coord.get(y).getDir().equals("-")) { + seq = FASTAUtilities.RevComplement(seq); } + OUT.println(">" + BED_Coord.get(y).getName() + "\n" + seq); + } catch (SAMException e) { + PS.println("INVALID COORDINATE: " + BED_Coord.get(y).toString()); } - OUT.close(); - firePropertyChange("fa",x, x + 1); } + OUT.close(); QUERY.close(); - textArea.append("Extraction Complete\n"); } catch(IllegalArgumentException e) { - textArea.append(e.getMessage()); + PS.println(e.getMessage()); } catch(FileNotFoundException e) { - textArea.append(e.getMessage()); + PS.println(e.getMessage()); } catch(SAMException e) { - textArea.append(e.getMessage()); + PS.println(e.getMessage()); } } else { - textArea.append("Genome FASTA file contains invalid lines!!!\n"); + PS.println("Genome FASTA file contains invalid lines!!!"); } } diff --git a/src/window_interface/Sequence_Analysis/FASTAExtractOutput.java b/src/window_interface/Sequence_Analysis/FASTAExtractOutput.java new file mode 100644 index 000000000..cc17f6422 --- /dev/null +++ b/src/window_interface/Sequence_Analysis/FASTAExtractOutput.java @@ -0,0 +1,90 @@ +package window_interface.Sequence_Analysis; + +import htsjdk.samtools.SAMException; +import htsjdk.samtools.reference.IndexedFastaSequenceFile; +import objects.CoordinateObjects.BEDCoord; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import util.FASTAUtilities; +import scripts.Sequence_Analysis.FASTAExtract; + +@SuppressWarnings("serial") +public class FASTAExtractOutput extends JFrame { + private File GENOME = null; + private File OUTPUTPATH = null; + private ArrayList BED = null; + private PrintStream OUT = null; + private boolean STRAND = true; + private boolean HEADER = true; + private boolean INDEX = true; + + private JTextArea textArea; + + public FASTAExtractOutput(File gen, ArrayList b, File out, boolean str, boolean head) { + setTitle("FASTA Extraction Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + GENOME = gen; + BED = b; + OUTPUTPATH = out; + STRAND = str; + HEADER = head; + } + + public void run() throws IOException, InterruptedException { + + PrintStream PS = new PrintStream(new CustomOutputStream(textArea)); + + if(INDEX) { + try{ + for(int x = 0; x < BED.size(); x++) { + + //Open Output File + File OUTFILE; + String NAME = BED.get(x).getName().split("\\.")[0] + ".fa"; + if(OUTPUTPATH != null) { + OUTFILE = new File(OUTPUTPATH.getCanonicalPath() + File.separator + NAME); + } else { + OUTFILE = new File(NAME); + } + + PS.println("Proccessing File: " + BED.get(x).getName()); + + //Execute Script object + FASTAExtract script_obj = new FASTAExtract(GENOME, BED.get(x), OUTFILE, STRAND, HEADER, PS); + script_obj.run(); + + firePropertyChange("fa",x, x + 1); + } + PS.println("Extraction Complete"); + } catch(IllegalArgumentException e) { + PS.println(e.getMessage()); + } catch(FileNotFoundException e) { + PS.println(e.getMessage()); + } catch(SAMException e) { + PS.println(e.getMessage()); + } + } else { + PS.println("Genome FASTA file contains invalid lines!!!"); + } + } +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/FASTAExtractWindow.java b/src/window_interface/Sequence_Analysis/FASTAExtractWindow.java index 0159a69df..46a76dbb1 100644 --- a/src/window_interface/Sequence_Analysis/FASTAExtractWindow.java +++ b/src/window_interface/Sequence_Analysis/FASTAExtractWindow.java @@ -32,7 +32,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Sequence_Analysis.FASTAExtract; +import window_interface.Sequence_Analysis.FASTAExtractOutput; @SuppressWarnings("serial") public class FASTAExtractWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -68,7 +68,7 @@ public Void doInBackground() throws IOException { JOptionPane.showMessageDialog(null, "No BAM Files Loaded!!!"); } else { setProgress(0); - FASTAExtract signal = new FASTAExtract(INPUT, BEDFiles, OUTPUT_PATH, chckbxStrand.isSelected(), rdbtnBedName.isSelected()); + FASTAExtractOutput signal = new FASTAExtractOutput(INPUT, BEDFiles, OUTPUT_PATH, chckbxStrand.isSelected(), rdbtnBedName.isSelected()); signal.addPropertyChangeListener("fa", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From 5bc52083c743c235c95f80bac2b6969fddf5e5c3 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 19:53:01 -0400 Subject: [PATCH 21/43] create RandomizeFASTA 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/*/ RandomizeFASTAOutput 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 cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Sequence_Analysis/RandomizeFASTACLI.java | 49 ++++++++++++++++--- .../Sequence_Analysis/RandomizeFASTA.java | 41 ++++++++++++++++ .../RandomizeFASTAWindow.java | 10 +++- 3 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 src/scripts/Sequence_Analysis/RandomizeFASTA.java diff --git a/src/cli/Sequence_Analysis/RandomizeFASTACLI.java b/src/cli/Sequence_Analysis/RandomizeFASTACLI.java index af90e4235..c53a87b3c 100644 --- a/src/cli/Sequence_Analysis/RandomizeFASTACLI.java +++ b/src/cli/Sequence_Analysis/RandomizeFASTACLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Sequence_Analysis.RandomizeFASTA; +import scripts.Sequence_Analysis.RandomizeFASTA; /** Sequence_AnalysisCLI/RandomizeFASTACLI @@ -24,6 +24,12 @@ exitCodeOnExecutionException = 1) public class RandomizeFASTACLI implements Callable { + @Parameters( index = "0", description = "the FASTA file ") + private File fastaFile; + + @Option(names = {"-o", "--output"}, description = "Specify basename for output files (default = _RAND.fa)") + private File output; + @Override public Integer call() throws Exception { System.err.println( ">RandomizeFASTACLI.call()" ); @@ -34,16 +40,45 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + RandomizeFASTA.randomizeFASTA(fastaFile, output); - //System.err.println("Calculations Complete"); + System.err.println("Randomization Complete."); return(0); } - + private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check input exists + if(!fastaFile.exists()){ + r += "(!)FASTA file does not exist: " + fastaFile.getName() + "\n"; + return(r); + } + //check input extension + 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(output==null){ + String NAME = ExtensionFileFilter.stripExtension(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"; + } + } catch( NullPointerException e){ r += "(!)Output filename must have extension: use \".fa\" extension for output filename. Try: " + output + ".fa\n"; } + //check directory + if(output.getParent()==null){ + // System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Sequence_Analysis/RandomizeFASTA.java b/src/scripts/Sequence_Analysis/RandomizeFASTA.java new file mode 100644 index 000000000..f11e9bf0b --- /dev/null +++ b/src/scripts/Sequence_Analysis/RandomizeFASTA.java @@ -0,0 +1,41 @@ +package scripts.Sequence_Analysis; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Random; +import java.util.Scanner; + +public class RandomizeFASTA { + + public static File randomizeFASTA(File FASTA, File RANDOUT) throws IOException { + Random randnum = new Random(); + PrintStream OUT = new PrintStream(RANDOUT); + Scanner scan = new Scanner(FASTA); + while (scan.hasNextLine()) { + String HEADER = scan.nextLine(); + OUT.println(HEADER); + if(HEADER.contains(">")) { + String[] SEQ = scan.nextLine().split(""); + ArrayList SEQ_ARRAY = new ArrayList(); + for(int x = 0; x < SEQ.length; x++) { SEQ_ARRAY.add(SEQ[x]); } + for(int x = 0; x < SEQ.length; x++) { + int randIndex = randnum.nextInt(SEQ_ARRAY.size()); + OUT.print(SEQ_ARRAY.get(randIndex)); + SEQ_ARRAY.remove(randIndex); + } + OUT.println(); + + } else { + OUT.println("ERROR - NOT FASTA FORMAT"); + System.err.println("ERROR - NOT FASTA FORMAT"); + } + } + + OUT.close(); + scan.close(); + return RANDOUT; + } + +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/RandomizeFASTAWindow.java b/src/window_interface/Sequence_Analysis/RandomizeFASTAWindow.java index b1e3a9572..3dbf87434 100644 --- a/src/window_interface/Sequence_Analysis/RandomizeFASTAWindow.java +++ b/src/window_interface/Sequence_Analysis/RandomizeFASTAWindow.java @@ -29,7 +29,8 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Sequence_Analysis.FASTARandomize; +import util.ExtensionFileFilter; +import scripts.Sequence_Analysis.RandomizeFASTA; @SuppressWarnings("serial") public class RandomizeFASTAWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -59,7 +60,12 @@ public Void doInBackground() throws IOException, InterruptedException { setProgress(0); for(int x = 0; x < FASTAFiles.size(); x++) { - FASTARandomize.randomizeFASTA(FASTAFiles.get(x), OUTPUT_PATH); + String NEWNAME = ExtensionFileFilter.stripExtension(FASTAFiles.get(x)) + "_RAND.fa"; + File RAND; + if(OUTPUT_PATH != null) { RAND = new File(OUTPUT_PATH + File.separator + NEWNAME); } + else { RAND = new File(NEWNAME); } + + RandomizeFASTA.randomizeFASTA(FASTAFiles.get(x), RAND); int percentComplete = (int)(((double)(x + 1) / FASTAFiles.size()) * 100); setProgress(percentComplete); } From aa227560a9155f60f33072e8cc41aed2185e9b0f Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 19:58:03 -0400 Subject: [PATCH 22/43] create SearchMotif command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/SearchMotifOutput class while the calculations are kept in the src/scripts/*/SearchMotif class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Sequence_Analysis/SearchMotifCLI.java | 54 +++++++- .../Sequence_Analysis/SearchMotif.java | 127 +++++++----------- .../Sequence_Analysis/SearchMotifOutput.java | 53 ++++++++ .../Sequence_Analysis/SearchMotifWindow.java | 6 +- 4 files changed, 152 insertions(+), 88 deletions(-) create mode 100644 src/window_interface/Sequence_Analysis/SearchMotifOutput.java diff --git a/src/cli/Sequence_Analysis/SearchMotifCLI.java b/src/cli/Sequence_Analysis/SearchMotifCLI.java index c0a755d5a..67dfd3667 100644 --- a/src/cli/Sequence_Analysis/SearchMotifCLI.java +++ b/src/cli/Sequence_Analysis/SearchMotifCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Sequence_Analysis.SearchMotif; +import scripts.Sequence_Analysis.SearchMotif; /** Sequence_AnalysisCLI/SearchMotifCLI @@ -24,6 +24,16 @@ exitCodeOnExecutionException = 1) public class SearchMotifCLI implements Callable { + @Parameters( index = "0", description = "The FASTA file in which to search for the motif.") + private File fastaFile; + + @Option(names = {"-o", "--output"}, description = "Specify output filename (default = _Mismatch_.bed)") + private File output = null; + @Option(names = {"-m", "--motif"}, required=true, description = "the IUPAC motif to search for") + private String motif; + @Option(names = {"-n", "--mismatches"}, description = "the number of mismatches allowed (default=0)") + private int ALLOWED_MISMATCH = 0; + @Override public Integer call() throws Exception { System.err.println( ">SearchMotifCLI.call()" ); @@ -34,16 +44,48 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + SearchMotif script_obj = new SearchMotif(fastaFile, motif, ALLOWED_MISMATCH, output, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Search Complete."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!fastaFile.exists()){ + 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(output==null){ + output = new File(motif + "_" + Integer.toString(ALLOWED_MISMATCH) + "Mismatch_" + ExtensionFileFilter.stripExtension(fastaFile) + ".bed"); + //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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //check mismatch value + if(ALLOWED_MISMATCH<0){ r += "(!)Please use a non-negative integer for allowed mismatches."; } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Sequence_Analysis/SearchMotif.java b/src/scripts/Sequence_Analysis/SearchMotif.java index 9650821e8..bcac65f7b 100644 --- a/src/scripts/Sequence_Analysis/SearchMotif.java +++ b/src/scripts/Sequence_Analysis/SearchMotif.java @@ -16,89 +16,61 @@ import java.util.List; import java.util.Map; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - @SuppressWarnings("serial") -public class SearchMotif extends JFrame{ +public class SearchMotif { private int ALLOWED_MISMATCH; private Map IUPAC_HASH = new HashMap<>(); private Map RC_HASH = new HashMap<>(); private String motif; private InputStream inputStream; - private File OUTPUTPATH = null; private String INPUTFILE = null; - private PrintStream OUT = null; - - private JTextArea textArea; - -public SearchMotif(File input, String mot, int num, File output) throws IOException { - setTitle("Motif Search Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - - ALLOWED_MISMATCH = num; - motif = mot; - inputStream = new FileInputStream(input); - INPUTFILE = input.getName(); + private PrintStream OUT; + private PrintStream PS; - OUTPUTPATH = output; - String fname = motif + "_" + Integer.toString(ALLOWED_MISMATCH) + "Mismatch_" + input.getName().substring(0, input.getName().lastIndexOf('.')) + ".bed"; - if(OUTPUTPATH != null) { - try {OUT = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + fname)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - } else { - try {OUT = new PrintStream(new File(fname)); } - catch (FileNotFoundException e) { e.printStackTrace(); } - } + public SearchMotif(File input, String mot, int num, File output, PrintStream ps) throws IOException { + ALLOWED_MISMATCH = num; + motif = mot; + inputStream = new FileInputStream(input); + INPUTFILE = input.getName(); + OUT = new PrintStream(output); + PS = ps; - IUPAC_HASH.put("A", "A"); - IUPAC_HASH.put("T", "T"); - IUPAC_HASH.put("G", "G"); - IUPAC_HASH.put("C", "C"); - IUPAC_HASH.put("R", "AG"); - IUPAC_HASH.put("Y", "CT"); - IUPAC_HASH.put("S", "GC"); - IUPAC_HASH.put("W", "AT"); - IUPAC_HASH.put("K", "GT"); - IUPAC_HASH.put("M", "AC"); - IUPAC_HASH.put("B", "CGT"); - IUPAC_HASH.put("D", "AGT"); - IUPAC_HASH.put("H", "ACT"); - IUPAC_HASH.put("V", "ACG"); - - RC_HASH.put("V", "B"); - RC_HASH.put("H", "D"); - RC_HASH.put("D", "H"); - RC_HASH.put("B", "V"); - RC_HASH.put("M", "K"); - RC_HASH.put("K", "M"); - RC_HASH.put("W", "W"); - RC_HASH.put("S", "S"); - RC_HASH.put("Y", "R"); - RC_HASH.put("R", "Y"); - RC_HASH.put("T", "A"); - RC_HASH.put("G", "C"); - RC_HASH.put("C", "G"); - RC_HASH.put("A", "T"); + IUPAC_HASH.put("A", "A"); + IUPAC_HASH.put("T", "T"); + IUPAC_HASH.put("G", "G"); + IUPAC_HASH.put("C", "C"); + IUPAC_HASH.put("R", "AG"); + IUPAC_HASH.put("Y", "CT"); + IUPAC_HASH.put("S", "GC"); + IUPAC_HASH.put("W", "AT"); + IUPAC_HASH.put("K", "GT"); + IUPAC_HASH.put("M", "AC"); + IUPAC_HASH.put("B", "CGT"); + IUPAC_HASH.put("D", "AGT"); + IUPAC_HASH.put("H", "ACT"); + IUPAC_HASH.put("V", "ACG"); + RC_HASH.put("V", "B"); + RC_HASH.put("H", "D"); + RC_HASH.put("D", "H"); + RC_HASH.put("B", "V"); + RC_HASH.put("M", "K"); + RC_HASH.put("K", "M"); + RC_HASH.put("W", "W"); + RC_HASH.put("S", "S"); + RC_HASH.put("Y", "R"); + RC_HASH.put("R", "Y"); + RC_HASH.put("T", "A"); + RC_HASH.put("G", "C"); + RC_HASH.put("C", "G"); + RC_HASH.put("A", "T"); } public void run() throws IOException, InterruptedException { - System.out.println("Searching motif: " + motif + " in " + INPUTFILE); - System.out.println("Starting: " + getTimeStamp()); - textArea.append("Searching motif: " + motif + " in " + INPUTFILE + "\n"); - textArea.append("Starting: " + getTimeStamp() + "\n"); + printPS("Searching motif: " + motif + " in " + INPUTFILE); + printPS("Starting: " + getTimeStamp()); char[] ORIG = motif.toUpperCase().toCharArray(); List MOTIF = new ArrayList<>(); @@ -117,8 +89,6 @@ public void run() throws IOException, InterruptedException RCMOTIF.add(IUPAC_HASH.get(key)); } } -// System.out.println(MOTIF.size() + "\t" + RCMOTIF.size()); -// for(int x = 0; x < MOTIF.size(); x++) { System.out.println(MOTIF.get(x) + "\t" + RCMOTIF.get(x)); } String currentChrom = ""; String currentLine = ""; @@ -134,8 +104,7 @@ public void run() throws IOException, InterruptedException currentLine = ""; currentBP = 0; currentEND = currentBP + motif.length(); - System.out.println("Proccessing: " + currentChrom); - textArea.append("Proccessing: " + currentChrom + "\n"); + printPS("Proccessing: " + currentChrom); } else { currentLine = currentLine + line; @@ -180,14 +149,9 @@ public void run() throws IOException, InterruptedException currentLine = tmp; } } - inputStream.close(); lines.close(); - System.out.println("Completing: " + getTimeStamp()); - textArea.append("Completing: " + getTimeStamp() + "\n"); - - Thread.sleep(2000); - dispose(); + printPS("Completing: " + getTimeStamp()); } private static String getTimeStamp() { @@ -195,4 +159,9 @@ private static String getTimeStamp() { String time = new Timestamp(date.getTime()).toString(); return time; } -} + + private void printPS(String message){ + if(PS!=null){ PS.println(message); } + else{ System.err.println(message); } + } +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/SearchMotifOutput.java b/src/window_interface/Sequence_Analysis/SearchMotifOutput.java new file mode 100644 index 000000000..d4e932aaf --- /dev/null +++ b/src/window_interface/Sequence_Analysis/SearchMotifOutput.java @@ -0,0 +1,53 @@ +package window_interface.Sequence_Analysis; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.Sequence_Analysis.SearchMotif; + +@SuppressWarnings("serial") +public class SearchMotifOutput extends JFrame{ + + private int ALLOWED_MISMATCH; + private String motif; + private File INPUTFILE = null; + private File OUT; + + private JTextArea textArea; + + public SearchMotifOutput(File input, String mot, int num, File output) throws IOException { + setTitle("Motif Search Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + ALLOWED_MISMATCH = num; + motif = mot; + INPUTFILE = input; + OUT = output; + } + + public void run() throws IOException, InterruptedException { + + PrintStream PS = new PrintStream(new CustomOutputStream(textArea)); + SearchMotif script_obj = new SearchMotif(INPUTFILE, motif, ALLOWED_MISMATCH, OUT, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/Sequence_Analysis/SearchMotifWindow.java b/src/window_interface/Sequence_Analysis/SearchMotifWindow.java index cd19b0db7..edf364c42 100644 --- a/src/window_interface/Sequence_Analysis/SearchMotifWindow.java +++ b/src/window_interface/Sequence_Analysis/SearchMotifWindow.java @@ -29,7 +29,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Sequence_Analysis.SearchMotif; +import window_interface.Sequence_Analysis.SearchMotifOutput; @SuppressWarnings("serial") public class SearchMotifWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -64,9 +64,9 @@ public Void doInBackground() throws IOException, InterruptedException { JOptionPane.showMessageDialog(null, "Invalid Number of Mismatches Entered!!!"); } else { setProgress(0); - SearchMotif search; + SearchMotifOutput search; for(int gfile = 0; gfile < GenomeFiles.size(); gfile++) { - search = new SearchMotif(GenomeFiles.get(gfile), txtMotif.getText(), Integer.parseInt(txtMismatch.getText()), OUTPUT_PATH); + search = new SearchMotifOutput(GenomeFiles.get(gfile), txtMotif.getText(), Integer.parseInt(txtMismatch.getText()), OUTPUT_PATH); search.setVisible(true); search.run(); counter++; From 2f31e9bd76fa13e3d08759d8c3eaa7afab2353a0 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 20:04:47 -0400 Subject: [PATCH 23/43] remove unused FASTARandomize object I meant to replace this class with the RandomizeFASTA class for consistent naming but I forgot to add it to the RandomizeFASTA command line interface commit. --- .../Sequence_Analysis/FASTARandomize.java | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/scripts/Sequence_Analysis/FASTARandomize.java diff --git a/src/scripts/Sequence_Analysis/FASTARandomize.java b/src/scripts/Sequence_Analysis/FASTARandomize.java deleted file mode 100644 index 4b772be00..000000000 --- a/src/scripts/Sequence_Analysis/FASTARandomize.java +++ /dev/null @@ -1,48 +0,0 @@ -package scripts.Sequence_Analysis; - -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Random; -import java.util.Scanner; - -public class FASTARandomize { - - public static File randomizeFASTA(File FASTA, File out) throws IOException { - String[] name = FASTA.getName().split("\\."); - String NEWNAME = ""; - for(int x = 0; x < name.length - 1; x++) { - if(x == name.length - 2) { NEWNAME += (name[x] + "_RAND.fa"); } - else { NEWNAME += (name[x] + "."); } - } - File RAND = null; - if(out != null) { RAND = new File(out + File.separator + NEWNAME); } - else { RAND = new File(NEWNAME); } - - Random randnum = new Random(); - PrintStream OUT = new PrintStream(RAND); - Scanner scan = new Scanner(FASTA); - while (scan.hasNextLine()) { - String HEADER = scan.nextLine(); - OUT.println(HEADER); - if(HEADER.contains(">")) { - String[] SEQ = scan.nextLine().split(""); - ArrayList SEQ_ARRAY = new ArrayList(); - for(int x = 0; x < SEQ.length; x++) { SEQ_ARRAY.add(SEQ[x]); } - for(int x = 0; x < SEQ.length; x++) { - int randIndex = randnum.nextInt(SEQ_ARRAY.size()); - OUT.print(SEQ_ARRAY.get(randIndex)); - SEQ_ARRAY.remove(randIndex); - } - OUT.println(); - - } else { OUT.println("ERROR - NOT FASTA FORMAT"); } - } - - OUT.close(); - scan.close(); - return RAND; - } - -} \ No newline at end of file From f8f15314ad0bd35b563cd1e80593294de4e5ad02 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 21:11:31 -0400 Subject: [PATCH 24/43] create AggregateData command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/AggregateDataOutput class while the calculations are kept in the src/scripts/*/AggregateData class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Read_Analysis/AggregateDataCLI.java | 115 +++++++++++++++++- src/scripts/Read_Analysis/AggregateData.java | 51 +++++--- .../Read_Analysis/AggregateDataWindow.java | 16 +-- 3 files changed, 148 insertions(+), 34 deletions(-) diff --git a/src/cli/Read_Analysis/AggregateDataCLI.java b/src/cli/Read_Analysis/AggregateDataCLI.java index 95834a4ee..52365e74e 100644 --- a/src/cli/Read_Analysis/AggregateDataCLI.java +++ b/src/cli/Read_Analysis/AggregateDataCLI.java @@ -14,7 +14,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Read_Analysis.AggregateData; +import scripts.Read_Analysis.AggregateData; /** Read_AnalysisCLI/AggregateDataCLI @@ -26,6 +26,43 @@ exitCodeOnExecutionException = 1) public class AggregateDataCLI implements Callable { + @Parameters( index="0..", description = "The matrix files whose statistics we want.") + private File[] matrixFiles; + + @Option(names = {"-f", "--files"}, description = "Input file list of matrix filepaths to aggregate (formatted so each path is on its own line)") + private boolean fileList = false; + @Option(names = {"-o", "--output"}, description = "Specify output file (default = _SCORES.out, matFiles = new ArrayList(); + @Override public Integer call() throws Exception { System.err.println( ">AggregateDataCLI.call()" ); @@ -36,16 +73,82 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + AggregateData script_obj = new AggregateData(matFiles, output, merge, startROW, startCOL, aggType); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println(script_obj.getMessage()); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + if(matrixFiles==null){ + r += "(!)Please indicate at least one file.\n"; + return(r); + //Import files as Vector list (scan input file if -f flag used) + }else if(fileList){ //load files from input filelist + if(matrixFiles.length>1){ + r += "(!)Please indicate only one file with matrix filepaths when using the -f flag.\n"; + return(r); + }else if(!matrixFiles[0].exists()){ + r += "(!)File of list of file inputs does not exist: " + matrixFiles[0].getCanonicalPath() + "\n"; + return(r); + }else{ + Scanner scan = new Scanner(matrixFiles[0]); + while (scan.hasNextLine()) { + matFiles.add(new File(scan.nextLine().trim())); + } + scan.close(); + } + }else{ //load input files into bam vector + for(int x=0; x INPUT = null; private File OUT_PATH = null; @@ -21,6 +20,7 @@ public class AggregateData extends JFrame { private int COLSTART = 1; private int METRIC = 0; private PrintStream OUT; + private String endMessage = ""; public AggregateData(ArrayList in, File out, boolean m, int r, int c, int index) { INPUT = in; @@ -33,9 +33,13 @@ public AggregateData(ArrayList in, File out, boolean m, int r, int c, int public void run() throws IOException { if(!MERGE) { - for(int x = 0; x < INPUT.size(); x++) { - outputFileScore(INPUT.get(x)); - firePropertyChange("file", x, x + 1); + if( !OUT_PATH.isDirectory() && INPUT.size()==1 ){ + outputFileScore(INPUT.get(0), new PrintStream(OUT_PATH)); + } else { + for(int x = 0; x < INPUT.size(); x++) { + outputFileScore(INPUT.get(x)); +// firePropertyChange("file", x, x + 1); + } } } else { ArrayList> MATRIX = new ArrayList>(); @@ -77,10 +81,11 @@ public void run() throws IOException { MATRIX.add(scorearray); MATRIXID.add(idarray); } - + String name = "ALL_SCORES.out"; - if(OUT_PATH != null) { OUT = new PrintStream(new File(OUT_PATH.getCanonicalPath() + File.separator + name)); } - else { OUT = new PrintStream(new File(name)); } + if(OUT_PATH==null) { OUT = new PrintStream(new File(name)); } + else if(!OUT_PATH.isDirectory()) { OUT = new PrintStream( OUT_PATH ); } + else { OUT = new PrintStream(new File(OUT_PATH.getCanonicalPath() + File.separator + name)); } //Check all arrays are the same size int ARRAYLENGTH = MATRIX.get(0).size(); @@ -88,10 +93,13 @@ public void run() throws IOException { for(int x = 0; x < MATRIX.size(); x++) { if(MATRIX.get(x).size() != ARRAYLENGTH || MATRIXID.get(x).size() != ARRAYLENGTH) { ALLSAME = false; - OUT.println("Different number of rows between:\n" + INPUT.get(0).getName() + "\n" + INPUT.get(x).getName()); + endMessage = "Different number of rows between:\n" + INPUT.get(0).getName() + "\n" + INPUT.get(x).getName(); + return; } } + System.err.println(getMessage()); + if(ALLSAME) { for(int x = 0; x < INPUT.size(); x++) { OUT.print("\t" + INPUT.get(x).getName()); } OUT.println(); @@ -102,22 +110,25 @@ public void run() throws IOException { } } OUT.close(); - - } + endMessage = "Data Parsed"; } + public String getMessage(){ + return(endMessage); + } + public void outputFileScore(File IN) throws FileNotFoundException, IOException { - String[] name = IN.getName().split("\\."); - String NEWNAME = ""; - for(int x = 0; x < name.length - 1; x++) { - if(x == name.length - 2) { NEWNAME += (name[x]); } - else { NEWNAME += (name[x] + "."); } - } + String NEWNAME = ExtensionFileFilter.stripExtension(IN); if(OUT_PATH != null) { OUT = new PrintStream(new File(OUT_PATH.getCanonicalPath() + File.separator + NEWNAME + "_SCORES.out")); } else { OUT = new PrintStream(new File(NEWNAME + "_SCORES.out")); } - + + outputFileScore(IN,OUT); + } + + + public void outputFileScore(File IN, PrintStream OUT) throws FileNotFoundException, IOException { if(METRIC == 0) { OUT.println("\tSum"); } else if(METRIC == 1) { OUT.println("\tAverage"); } else if(METRIC == 2) { OUT.println("\tMedian"); } @@ -157,4 +168,4 @@ public void outputFileScore(File IN) throws FileNotFoundException, IOException { scan.close(); OUT.close(); } -} +} \ No newline at end of file diff --git a/src/window_interface/Read_Analysis/AggregateDataWindow.java b/src/window_interface/Read_Analysis/AggregateDataWindow.java index 649cf6de0..988008fc1 100644 --- a/src/window_interface/Read_Analysis/AggregateDataWindow.java +++ b/src/window_interface/Read_Analysis/AggregateDataWindow.java @@ -73,17 +73,17 @@ public Void doInBackground() throws IOException { } else { AggregateData parse = new AggregateData(SUMFiles, OUTPUT_PATH, chckbxMergeToOne.isSelected(), Integer.parseInt(txtRow.getText()), Integer.parseInt(txtCol.getText()), cmbMethod.getSelectedIndex()); - parse.addPropertyChangeListener("file", new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent propertyChangeEvent) { - int temp = (Integer) propertyChangeEvent.getNewValue(); - int percentComplete = (int)(((double)(temp) / (SUMFiles.size())) * 100); - setProgress(percentComplete); - } - }); +// parse.addPropertyChangeListener("file", new PropertyChangeListener() { +// public void propertyChange(PropertyChangeEvent propertyChangeEvent) { +// int temp = (Integer) propertyChangeEvent.getNewValue(); +// int percentComplete = (int)(((double)(temp) / (SUMFiles.size())) * 100); +// setProgress(percentComplete); +// } +// }); parse.run(); setProgress(100); - JOptionPane.showMessageDialog(null, "Data Parsed"); + JOptionPane.showMessageDialog(null, parse.getMessage()); } } catch(NumberFormatException nfe){ JOptionPane.showMessageDialog(null, "Invalid Input in Fields!!!"); From 8650b5dc5ce3974c45cbf6103b6283f7f06653d2 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 21:16:20 -0400 Subject: [PATCH 25/43] create ScaleMatrix 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/*/ ScaleMatrixOutput 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 cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Read_Analysis/ScaleMatrixCLI.java | 53 ++++++++++++++++--- src/scripts/Read_Analysis/ScaleMatrix.java | 19 ++++--- .../Read_Analysis/ScaleMatrixWindow.java | 4 +- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/cli/Read_Analysis/ScaleMatrixCLI.java b/src/cli/Read_Analysis/ScaleMatrixCLI.java index c068b0a34..fdc01b772 100644 --- a/src/cli/Read_Analysis/ScaleMatrixCLI.java +++ b/src/cli/Read_Analysis/ScaleMatrixCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Read_Analysis.ScaleMatrix; +import scripts.Read_Analysis.ScaleMatrix; /** Read_AnalysisCLI/ScaleMatrixCLI @@ -24,6 +24,19 @@ exitCodeOnExecutionException = 1) public class ScaleMatrixCLI implements Callable { + @Parameters( index = "0", description = "Input matrix file") + private File matrixFile; + + @Option(names = {"-o", "--output"}, description = "Specify output file (default = _SCALE.tab)") + private File output = null; + @Option(names = {"-s", "--scaling-factor"}, description = "scaling factor (default=1)") + private double scale = 1; + @Option(names = {"-r", "--start-row"}, description = "") + private int startROW = 1; + @Option(names = {"-l", "--start-col"}, description = "") + private int startCOL = 2; + + @Override public Integer call() throws Exception { System.err.println( ">ScaleMatrixCLI.call()" ); @@ -32,18 +45,44 @@ public Integer call() throws Exception { System.err.println( validate ); System.err.println("Invalid input. Check usage using '-h' or '--help'"); System.exit(1); - } + } - //SEStats.getSEStats( output, bamFile, null ); + ScaleMatrix script_obj = new ScaleMatrix(matrixFile, output, scale, startROW, startCOL); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("All Matrices Scaled."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!matrixFile.exists()){ + r += "(!)MATRIX file does not exist: " + matrixFile.getName() + "\n"; + return(r); + } + //no check ext + //set default output filename + if(output==null){ + output = new File(ExtensionFileFilter.stripExtension(matrixFile) + "_SCALE." + ExtensionFileFilter.getExtension(matrixFile)); + //check output filename is valid + }else if( output.isDirectory() ){ + r += "(!)Must indicate file (not a directory) for your output."; + } else { + //no check ext + //check directory + if(output.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //validate row&column start indexes + if(startROW<0){ r += "(!)Row start must not be less than zero\n"; } + if(startCOL<0){ r += "(!)Column start must not be less than zero\n"; } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Read_Analysis/ScaleMatrix.java b/src/scripts/Read_Analysis/ScaleMatrix.java index a27cd6598..41c117836 100644 --- a/src/scripts/Read_Analysis/ScaleMatrix.java +++ b/src/scripts/Read_Analysis/ScaleMatrix.java @@ -12,7 +12,7 @@ public class ScaleMatrix { private File MATRIX = null; - private File OUTPUTPATH = null; + private File OUTFILE = null; private double SCALE = 0; private int ROWINDEX = 0; @@ -20,7 +20,7 @@ public class ScaleMatrix { public ScaleMatrix(File m, File o, double s, int r, int c) { MATRIX = m; - OUTPUTPATH = o; + OUTFILE = o; SCALE = s; ROWINDEX = r; @@ -29,14 +29,13 @@ public ScaleMatrix(File m, File o, double s, int r, int c) { public void run() throws IOException { //Open output file - String[] FILEID = MATRIX.getName().split("\\."); - PrintStream OUT = new PrintStream(OUTPUTPATH + File.separator + FILEID[0] + "_SCALE." + FILEID[FILEID.length - 1]); + PrintStream OUT = new PrintStream(OUTFILE); - System.out.println(getTimeStamp()); - System.out.println("Processing file:\t" + MATRIX.getName()); - System.out.println("Scaling factor:\t" + SCALE); - System.out.println("Starting row index:\t" + ROWINDEX); - System.out.println("Starting column index:\t" + COLINDEX); + System.err.println(getTimeStamp()); + System.err.println("Processing file:\t" + MATRIX.getName()); + System.err.println("Scaling factor:\t" + SCALE); + System.err.println("Starting row index:\t" + ROWINDEX); + System.err.println("Starting column index:\t" + COLINDEX); try { //Parse, scale, and output tab-delimited matrix on the fly @@ -54,7 +53,7 @@ public void run() throws IOException { OUT.println(); } counter++; - if(counter % 1000 == 0) { System.out.println("Rows processed: " + counter); } + if(counter % 1000 == 0) { System.err.println("Rows processed: " + counter); } } SCAN.close(); } catch(NumberFormatException e) { diff --git a/src/window_interface/Read_Analysis/ScaleMatrixWindow.java b/src/window_interface/Read_Analysis/ScaleMatrixWindow.java index a50930ad2..2e7f7ef54 100644 --- a/src/window_interface/Read_Analysis/ScaleMatrixWindow.java +++ b/src/window_interface/Read_Analysis/ScaleMatrixWindow.java @@ -102,7 +102,9 @@ public Void doInBackground() throws IOException { if(OUTPUTPATH == null) { OUTPUTPATH = new File(System.getProperty("user.dir")); } if(rdbtnFilespecifcScaling.isSelected()) { SCALE = Double.parseDouble(expTable.getValueAt(x, 1).toString()); } //System.out.println(SCALE); - ScaleMatrix scale = new ScaleMatrix(TABFiles.get(x), OUTPUTPATH, SCALE, Integer.parseInt(txtRow.getText()), Integer.parseInt(txtCol.getText())); + String[] FILEID = TABFiles.get(x).getName().split("\\."); + File OUT = new File(OUTPUTPATH + File.separator + FILEID[0] + "_SCALE." + FILEID[FILEID.length - 1]); + ScaleMatrix scale = new ScaleMatrix(TABFiles.get(x), OUT, SCALE, Integer.parseInt(txtRow.getText()), Integer.parseInt(txtCol.getText())); scale.run(); int percentComplete = (int)(((double)(x + 1) / TABFiles.size()) * 100); From 9a100e29b82fd7ae8a1c13044a907e069b7c67b7 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 21:28:51 -0400 Subject: [PATCH 26/43] create ScalingFactor command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/ScalingFactorOutput class while the calculations are kept in the src/scripts/*/ScalingFactor class. Note this tool's NCIS method may need deeper testing for other cases that would break the CLI. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Read_Analysis/ScalingFactorCLI.java | 108 +++++++- src/scripts/Read_Analysis/ScalingFactor.java | 256 +++++++----------- .../Read_Analysis/ScalingFactorOutput.java | 151 +++++++++++ .../Read_Analysis/ScalingFactorWindow.java | 4 +- 4 files changed, 354 insertions(+), 165 deletions(-) create mode 100644 src/window_interface/Read_Analysis/ScalingFactorOutput.java diff --git a/src/cli/Read_Analysis/ScalingFactorCLI.java b/src/cli/Read_Analysis/ScalingFactorCLI.java index 80fd06cdd..bb17662d8 100644 --- a/src/cli/Read_Analysis/ScalingFactorCLI.java +++ b/src/cli/Read_Analysis/ScalingFactorCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Read_Analysis.ScalingFactor; +import scripts.Read_Analysis.ScalingFactor; /** Read_AnalysisCLI/ScalingFactorCLI @@ -25,6 +25,35 @@ exitCodeOnExecutionException = 1) public class ScalingFactorCLI implements Callable { + @Parameters( index = "0", description = "The BAM file from which we calculate the scaling factor.") + private File bamFile; + + @Option(names = {"-o", "--output"}, description = "Specify basename for output files (default = _ScalingFactors.out") + private String outputBasename = null; + @Option(names = {"-f", "--blacklist"}, description = "specify blacklist file to filter by") + private File blacklistFilter = null; + @Option(names = {"-c", "--control"}, description = "control BAM file") + private File controlBAM = null; + + @ArgGroup(exclusive = true, heading = "Scale Options%n") + ScaleType scale = new ScaleType(); + static class ScaleType{ + @Option(names = {"-t", "--total-tag"}, description = "total tag scaling (default)") + private boolean total = false; + @Option(names = {"-n", "--ncis"}, description = "ncis normalization with window size in bp and unitless minimum fraction (default-size=500, default-fraction=0.75)" + + "%nAccording to the NCIS method from Liang & Keles (BMC Bioinf 2012). Also sets a background proportion estimate for the signal channel.") + private boolean ncis = false; + @Option(names = {"-b", "--both"}, description = "ncis with total tag (default-size=500, default-fraction=0.75)") + private boolean both = false; + } + + @Option(names = {"-w", "--window-size"}, description = "window size for NCIS-related scaling types (default=500)") + private int window = 500; + @Option(names = {"-m", "--min-fraction"}, description = "minimum fraction for NCIS-related scaling types (default=0.75)") + private double minFrac = 0.75; + + private int scaleType = 1; + @Override public Integer call() throws Exception { System.err.println( ">ScalingFactorCLI.call()" ); @@ -34,17 +63,84 @@ public Integer call() throws Exception { System.err.println("Invalid input. Check usage using '-h' or '--help'"); System.exit(1); } + System.err.println( "OUTBASE: " + outputBasename ); - //SEStats.getSEStats( output, bamFile, null ); + ScalingFactor script_obj = new ScalingFactor(bamFile, blacklistFilter, controlBAM, outputBasename, true, scaleType, window, minFrac); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println("Scaling Factor Calculated."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bamFile.exists() && bamFile!=null){ + r += "(!)BAM(input) file does not exist: " + bamFile.getName() + "\n"; + } + if(blacklistFilter!=null){ + if(!blacklistFilter.exists()){ r += "(!)Blacklist file does not exist: " + blacklistFilter.getName() + "\n"; } + } + if(controlBAM!=null){ + 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"; + } + 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"; + } + f = new File(controlBAM+".bai"); + if(!f.exists() || f.isDirectory()){ + r += "(!)BAI Index File does not exist for: " + controlBAM.getName() + "\n"; + } + } + //set default output filename + if(outputBasename==null){ + outputBasename = ExtensionFileFilter.stripExtension(bamFile); + //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"); + } else if(!new File(tempOut.getParent()).exists()){ + r += "(!)Check output directory exists: " + tempOut.getParent() + "\n"; + } + } + + //Set numeric indicator for scaling method + if(scale.ncis) { scaleType = 2; } + else if(scale.both) { scaleType = 3; } + + //NCIS-related methods must have a control file + if(controlBAM==null && scaleType!=1){ + r += "(!)Control file must be given when using NCIS-related scaling methods. Unused for total-tag scaling.\n"; + } + + //validate window + if(window<1){ + r += "(!)Window must be a positive non-zero integer\n"; + } + //validate minimum fraction + if(minFrac>1 || minFrac<0){ + r += "(!)Minimum fraction must be between 0 and 1\n"; + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Read_Analysis/ScalingFactor.java b/src/scripts/Read_Analysis/ScalingFactor.java index 3de1cec30..3c37a6780 100644 --- a/src/scripts/Read_Analysis/ScalingFactor.java +++ b/src/scripts/Read_Analysis/ScalingFactor.java @@ -1,7 +1,13 @@ package scripts.Read_Analysis; -import java.awt.BorderLayout; -import java.awt.Dimension; +import htsjdk.samtools.AbstractBAMFileIndex; +import htsjdk.samtools.SAMRecord; +import htsjdk.samtools.SAMSequenceRecord; +import htsjdk.samtools.SamReader; +import htsjdk.samtools.SamReaderFactory; +import htsjdk.samtools.ValidationStringency; +import htsjdk.samtools.util.CloseableIterator; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; @@ -17,23 +23,10 @@ import java.util.List; import java.util.Scanner; -import javax.swing.JFrame; -import javax.swing.JLayeredPane; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTable; -import javax.swing.SpringLayout; +import org.jfree.chart.ChartPanel; -import htsjdk.samtools.AbstractBAMFileIndex; -import htsjdk.samtools.SAMRecord; -import htsjdk.samtools.SAMSequenceRecord; -import htsjdk.samtools.SamReader; -import htsjdk.samtools.SamReaderFactory; -import htsjdk.samtools.ValidationStringency; -import htsjdk.samtools.util.CloseableIterator; -import objects.CoordinateObjects.BEDCoord; import charts.ScalingPlotter; +import objects.CoordinateObjects.BEDCoord; /** * NCIS code adapted from Mahony Lab @@ -42,19 +35,19 @@ */ @SuppressWarnings("serial") -public class ScalingFactor extends JFrame { +public class ScalingFactor { - ArrayList BAMFiles = null; + private File BAMFile = null; private File BLACKLISTFile = null; private File CONTROL = null; - private String OUTPUTPATH = null; + private String OUTBASENAME = null; private boolean OUTPUTSTATUS = false; private String FILEID = null; private int scaleType = -1; private int windowSize = 500; private double minFraction = 0.75; - + private List chromName = null; private List chromLength = null; @@ -64,45 +57,22 @@ public class ScalingFactor extends JFrame { private double CTagcount = 0; private HashMap> BLACKLIST = null; - private ArrayList SCALINGFACTORS = new ArrayList(); + private double SCALE = 1; - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - final JTabbedPane tabbedPane_CummulativeScatterplot; - final JTabbedPane tabbedPane_MarginalScatterplot; + private ChartPanel CC_plot; //Cumulative + private ChartPanel M_plot; //Marginal Plot - public ScalingFactor(ArrayList b, File bl, File c, String out_path, boolean out, int scale, int win, double min) { - setTitle("Scaling Factor"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 800); - - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); - - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); - - BAMFiles = b; + private String dialogMessage = null; + + public ScalingFactor(File bamFile, File bl, File c, String out_basename, boolean out, int scale, int win, double min) { + BAMFile = bamFile; BLACKLISTFile = bl; CONTROL = c; - OUTPUTPATH = out_path; + OUTBASENAME = out_basename; OUTPUTSTATUS = out; scaleType = scale; windowSize = win; minFraction = min; - - tabbedPane_CummulativeScatterplot = new JTabbedPane(JTabbedPane.TOP); - tabbedPane_MarginalScatterplot = new JTabbedPane(JTabbedPane.TOP); - if(scaleType != 1) { - tabbedPane.addTab("Cumulative Count Scaling Ratio", null, tabbedPane_CummulativeScatterplot, null); - tabbedPane.addTab("Marginal Signal/Control Ratio", null, tabbedPane_MarginalScatterplot, null); - } } public void run() throws IOException { @@ -111,85 +81,73 @@ public void run() throws IOException { //Load up the Control File once per run if(scaleType != 1) { - System.out.println(getTimeStamp() + "\nLoading control genome array..."); + System.err.println(getTimeStamp() + "\nLoading control genome array..."); initalizeGenomeMetainformation(CONTROL); Cgenome = initializeList(CONTROL, false); - System.out.println("Array loaded"); + System.err.println("Array loaded"); } - PrintStream OUT = null; - if(OUTPUTSTATUS) { OUT = new PrintStream(OUTPUTPATH + File.separator + "ScalingFactors.out"); } - - for(int z = 0; z < BAMFiles.size(); z++) { - File SAMPLE = BAMFiles.get(z); //Pull current BAM file - File f = new File(SAMPLE + ".bai"); //Generate file name for BAI index file - //Check if BAI index file exists - if(!f.exists() || f.isDirectory()) { JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + SAMPLE.getName()); } - else { - System.out.println(getTimeStamp()); - FILEID = SAMPLE.getName(); - System.out.println("Sample file:\t" + FILEID); - if(CONTROL != null) { System.out.println("Control file:\t" + CONTROL.getName()); } + File f = new File(BAMFile + ".bai"); //Generate file name for BAI index file + //Check if BAI index file exists + if(!f.exists() || f.isDirectory()) { + dialogMessage = "BAI Index File does not exist for: " + BAMFile.getName(); + System.err.println(dialogMessage); + } else { + System.err.println(getTimeStamp()); + FILEID = BAMFile.getName(); + System.err.println("Sample file:\t" + FILEID); + if(CONTROL != null) { System.err.println("Control file:\t" + CONTROL.getName()); } - double SCALE = 1; - if(scaleType == 1) { - initalizeGenomeMetainformation(SAMPLE); - Sgenome = initializeList(SAMPLE, true); - double genomeSize = 0; - for(int x = 0; x < chromLength.size(); x++) { genomeSize += chromLength.get(x); } - if(genomeSize != 0) { SCALE = genomeSize / STagcount; } - System.out.println("Sample tags: " + STagcount); - System.out.println("Genome size: " + genomeSize); - System.out.println("Total tag ratio: " + SCALE); - SCALINGFACTORS.add(SCALE); - } else { - if(verifyFiles(SAMPLE)) { - System.out.println("\nLoading sample genome array..."); - Sgenome = initializeList(SAMPLE, true); - System.out.println("Array loaded"); - System.out.println("Sample tags: " + STagcount); - System.out.println("Control tags: " + CTagcount); - System.out.println("Bin count: " + Sgenome.size()); - - if(scaleType == 2) { - System.out.println("\nCalculating NCIS scaling ratio..."); - SCALE = 1 / scalingRatioByNCIS(Sgenome, Cgenome, OUTPUTPATH, FILEID, minFraction); - System.out.println("NCIS sample scaling ratio: " + SCALE); - } else if(scaleType == 3) { - System.out.println("\nCalculating Total tag NCIS scaling ratio..."); - SCALE = 1 / scalingRatioByHitRatioAndNCIS(Sgenome, Cgenome, STagcount, CTagcount, OUTPUTPATH, FILEID, minFraction); - System.out.println("NCIS with Total Tag sample scaling ratio: " + SCALE); - } - SCALINGFACTORS.add(SCALE); - } else { - SCALINGFACTORS.add(Double.NaN); + SCALE = 1; + if(scaleType == 1) { + initalizeGenomeMetainformation(BAMFile); + Sgenome = initializeList(BAMFile, true); + double genomeSize = 0; + for(int x = 0; x < chromLength.size(); x++) { genomeSize += chromLength.get(x); } + if(genomeSize != 0) { SCALE = genomeSize / STagcount; } + System.err.println("Sample tags: " + STagcount); + System.err.println("Genome size: " + genomeSize); + System.err.println("Total tag ratio: " + SCALE); + } else { + if(verifyFiles()) { + System.err.println("\nLoading sample genome array..."); + Sgenome = initializeList(BAMFile, true); + System.err.println("Array loaded"); + System.err.println("Sample tags: " + STagcount); + System.err.println("Control tags: " + CTagcount); + System.err.println("Bin count: " + Sgenome.size()); + + if(scaleType == 2) { + System.err.println("\nCalculating NCIS scaling ratio..."); + SCALE = 1 / scalingRatioByNCIS(Sgenome, Cgenome, OUTBASENAME, FILEID, minFraction); + System.err.println("NCIS sample scaling ratio: " + SCALE); + } else if(scaleType == 3) { + System.err.println("\nCalculating Total tag NCIS scaling ratio..."); + SCALE = 1 / scalingRatioByHitRatioAndNCIS(Sgenome, Cgenome, STagcount, CTagcount, OUTBASENAME, FILEID, minFraction); + System.err.println("NCIS with Total Tag sample scaling ratio: " + SCALE); } + } else { + SCALE = Double.NaN; } - - //Output scaling factor is user-specified - if(OUTPUTSTATUS) { - OUT.println("Sample file:\t" + SAMPLE); - if(scaleType == 1) { OUT.println("Scaling type:\tTotalTag"); } - else { - OUT.println("Control file:\t" + CONTROL); - if(scaleType == 2) { OUT.println("Scaling type:\tNCIS"); } - else if(scaleType == 3) { OUT.println("Scaling type:\tTotalTag with NCIS"); } - OUT.println("Window size (bp):\t" + windowSize); - OUT.println("Minimum fraction:\t" + minFraction); - } - OUT.println("Scaling factor:\t" + SCALE); + } + + //Output scaling factor is user-specified + if(OUTPUTSTATUS) { + PrintStream OUT = new PrintStream(new File(OUTBASENAME+"_ScalingFactors.out")); + OUT.println("Sample file:\t" + BAMFile.getCanonicalPath()); + if(scaleType == 1) { OUT.println("Scaling type:\tTotalTag"); } + else { + OUT.println("Control file:\t" + CONTROL); + if(scaleType == 2) { OUT.println("Scaling type:\tNCIS"); } + else if(scaleType == 3) { OUT.println("Scaling type:\tTotalTag with NCIS"); } + OUT.println("Window size (bp):\t" + windowSize); + OUT.println("Minimum fraction:\t" + minFraction); } - System.out.println(getTimeStamp()); + OUT.println("Scaling factor:\t" + SCALE); + OUT.close(); } - firePropertyChange("scale", z, (z + 1)); + System.err.println(getTimeStamp()); } - //Close output Printstream if open - if(OUTPUTSTATUS) { OUT.close(); } - - //Make frame visible at completion of correlations if not already visible - if(!this.isVisible()) { this.setVisible(true); } - tabbedPane.addTab("Scaling Factor", makeTablePanel(SCALINGFACTORS)); - } public List initializeList(File BAM, boolean sample) { @@ -300,28 +258,28 @@ public void initalizeGenomeMetainformation(File BAM) throws IOException { Sbai.close(); } - public boolean verifyFiles(File SAMPLE) throws IOException { + public boolean verifyFiles() throws IOException { SamReaderFactory factory = SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.INCLUDE_SOURCE_IN_RECORDS, SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.SILENT); - SamReader Sreader = factory.open(SAMPLE); + SamReader Sreader = factory.open(BAMFile); SamReader Creader = factory.open(CONTROL); AbstractBAMFileIndex Sbai = (AbstractBAMFileIndex) Sreader.indexing().getIndex(); AbstractBAMFileIndex Cbai = (AbstractBAMFileIndex) Creader.indexing().getIndex(); if(Sbai.getNumberOfReferences() != Cbai.getNumberOfReferences()) { - JOptionPane.showMessageDialog(null, "Unequal number of chromosomes between sample and control!!!"); - System.err.println("Unequal number of chromosomes between sample and control!!!!"); + dialogMessage = "Unequal number of chromosomes between sample and control!!!"; + System.err.println(dialogMessage); return false; } for (int z = 0; z < Sbai.getNumberOfReferences(); z++) { SAMSequenceRecord Sseq = Sreader.getFileHeader().getSequence(z); SAMSequenceRecord Cseq = Creader.getFileHeader().getSequence(z); if(!Sseq.getSequenceName().equals(Cseq.getSequenceName())) { - JOptionPane.showMessageDialog(null, "Chromosome names do not match!!!\n" + Sseq.getSequenceName() + "\n" + Cseq.getSequenceName()); - System.err.println("Chromosome names do not match!!!\n" + Sseq.getSequenceName() + "\n" + Cseq.getSequenceName()); + dialogMessage = "Chromosome names do not match!!!\n" + Sseq.getSequenceName() + "\n" + Cseq.getSequenceName(); + System.err.println(dialogMessage); return false; } if(Sseq.getSequenceLength() != Cseq.getSequenceLength()) { - JOptionPane.showMessageDialog(null, "Chromosome lengths do not match!!!\n" + Sseq.getSequenceName() + "\t" + Sseq.getSequenceLength() + "\n" + Cseq.getSequenceName() + "\t" + Cseq.getSequenceLength()); - System.err.println("Chromosome lengths do not match!!!\n" + Sseq.getSequenceName() + "\t" + Sseq.getSequenceLength() + "\n" + Cseq.getSequenceName() + "\t" + Cseq.getSequenceLength()); + dialogMessage = "Chromosome lengths do not match!!!\n" + Sseq.getSequenceName() + "\t" + Sseq.getSequenceLength() + "\n" + Cseq.getSequenceName() + "\t" + Cseq.getSequenceLength(); + System.err.println(dialogMessage); return false; } } @@ -461,7 +419,7 @@ public int compareByTotal(PairedCounts pc){ } - public void plotGraphs(List counts, double totalAtScaling, double scalingRatio, String outpath, String fileid, String scaletype) { + public void plotGraphs(List counts, double totalAtScaling, double scalingRatio, String outbase, String fileid, String scaletype) { //Scaling plot generation //Cumulative ratio vs bin total List bintotals=new ArrayList(); @@ -496,45 +454,29 @@ public void plotGraphs(List counts, double totalAtScaling, double } } //Generate images - tabbedPane_CummulativeScatterplot.add(fileid, ScalingPlotter.generateXYplot(bintotals, ratios, totalAtScaling, scalingRatio, fileid + " " + scaletype + " plot", "Binned Total Tag Count", "Cumulative Count Scaling Ratio")); - tabbedPane_MarginalScatterplot.add(fileid, ScalingPlotter.generateXYplot(bintot, mratios, totalAtScaling, scalingRatio, fileid + " " + scaletype + " plot", "Binned Total Tag Count", "Marginal Signal/Control Ratio")); - //Make frame visible at completion of correlations if not already visible - if(!this.isVisible()) { this.setVisible(true); } + CC_plot = ScalingPlotter.generateXYplot(bintotals, ratios, totalAtScaling, scalingRatio, fileid + " " + scaletype + " plot", "Binned Total Tag Count", "Cumulative Count Scaling Ratio"); + M_plot = ScalingPlotter.generateXYplot(bintot, mratios, totalAtScaling, scalingRatio, fileid + " " + scaletype + " plot", "Binned Total Tag Count", "Marginal Signal/Control Ratio"); if(OUTPUTSTATUS) { //Print data points to files try { - FileWriter Cfout = new FileWriter(outpath + File.separator + fileid + "." + scaletype + "_scaling-ccr.count"); + FileWriter Cfout = new FileWriter(outbase + "." + scaletype + "_scaling-ccr.count"); for(int d=0; d SCALE) { - JTable table = new JTable(SCALE.size(), 2); - table.setName("Scaling Factors"); - table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - for(int i = 0; i < SCALE.size(); i++) { - table.setValueAt(BAMFiles.get(i).getName(), i, 0); - table.setValueAt(SCALE.get(i).doubleValue(), i, 1); - } - table.getColumnModel().getColumn(0).setHeaderValue("Experiment"); - table.getColumnModel().getColumn(1).setHeaderValue("Scaling Factor"); - table.setPreferredSize(table.getPreferredSize()); - // Allow for the selection of multiple OR individual cells across either rows or columns - table.setCellSelectionEnabled(true); - table.setColumnSelectionAllowed(true); - table.setRowSelectionAllowed(true); - - JScrollPane pane = new JScrollPane(table); - table.setFillsViewportHeight(true); - pane.setPreferredSize(new Dimension(590, 590)); - return pane; - } + public ChartPanel getCCPlot() {return(CC_plot);} + + public ChartPanel getMPlot() {return(M_plot);} + + public double getScalingFactor() {return(SCALE);} + + public String getDialogMessage() {return(dialogMessage);} private static String getTimeStamp() { Date date= new Date(); diff --git a/src/window_interface/Read_Analysis/ScalingFactorOutput.java b/src/window_interface/Read_Analysis/ScalingFactorOutput.java new file mode 100644 index 000000000..02d9a2300 --- /dev/null +++ b/src/window_interface/Read_Analysis/ScalingFactorOutput.java @@ -0,0 +1,151 @@ +package scripts.Read_Analysis; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; + +import javax.swing.JFrame; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTable; +import javax.swing.SpringLayout; + +import objects.CoordinateObjects.BEDCoord; +import util.ExtensionFileFilter; +import scripts.Read_Analysis.ScalingFactor; + +/** + * NCIS code adapted from Mahony Lab + * https://github.com/seqcode/seqcode-core + * NCIS algorithm from Liang & Keles (BMC Bioinformatics 2012) + */ + +@SuppressWarnings("serial") +public class ScalingFactorOutput extends JFrame { + + ArrayList BAMFiles = null; + private File BLACKLISTFile = null; + private File CONTROL = null; + private String OUTPUT_PATH = null; + private boolean OUTPUTSTATUS = false; + private String FILEID = null; + + private int scaleType = -1; + private int windowSize = 500; + private double minFraction = 0.75; + + private ArrayList SCALINGFACTORS = new ArrayList(); + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + final JTabbedPane tabbedPane_CummulativeScatterplot; + final JTabbedPane tabbedPane_MarginalScatterplot; + + public ScalingFactorOutput(ArrayList b, File bl, File c, String out_path, boolean out, int scale, int win, double min) { + setTitle("Scaling Factor"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 800); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + BAMFiles = b; + BLACKLISTFile = bl; + CONTROL = c; + OUTPUT_PATH = out_path; + OUTPUTSTATUS = out; + scaleType = scale; + windowSize = win; + minFraction = min; + + tabbedPane_CummulativeScatterplot = new JTabbedPane(JTabbedPane.TOP); + tabbedPane_MarginalScatterplot = new JTabbedPane(JTabbedPane.TOP); + if(scaleType != 1) { + tabbedPane.addTab("Cumulative Count Scaling Ratio", null, tabbedPane_CummulativeScatterplot, null); + tabbedPane.addTab("Marginal Signal/Control Ratio", null, tabbedPane_MarginalScatterplot, null); + } + } + + public void run() throws IOException { +// //Load blacklist HashMap if blacklist file uploaded by user +// if(BLACKLISTFile != null) { loadBlacklist(BLACKLISTFile); } +// +// //Load up the Control File once per run +// if(scaleType != 1) { +// System.out.println(getTimeStamp() + "\nLoading control genome array..."); +// initalizeGenomeMetainformation(CONTROL); +// Cgenome = initializeList(CONTROL, false); +// System.out.println("Array loaded"); +// } +// +// PrintStream OUT = null; +// if(OUTPUTSTATUS) { OUT = new PrintStream(new File(OUTFILE)); } + + for(int z = 0; z < BAMFiles.size(); z++) { + File SAMPLE = BAMFiles.get(z); //Pull current BAM file + FILEID = SAMPLE.getName(); + + String BASENAME = OUTPUT_PATH + File.separator + ExtensionFileFilter.stripExtension(SAMPLE); + + ScalingFactor script_obj = new ScalingFactor(SAMPLE, BLACKLISTFile, CONTROL, BASENAME, OUTPUTSTATUS, scaleType, windowSize, minFraction); + script_obj.run(); + + SCALINGFACTORS.add(script_obj.getScalingFactor()); + + if(script_obj.getDialogMessage()!=null) { + JOptionPane.showMessageDialog(null, script_obj.getDialogMessage()); + } else if(scaleType == 2) { + //Generate images + tabbedPane_CummulativeScatterplot.add(FILEID, script_obj.getCCPlot()); + tabbedPane_MarginalScatterplot.add(FILEID, script_obj.getMPlot()); + } else if(scaleType == 3) { + //Generate images + tabbedPane_CummulativeScatterplot.add(FILEID, script_obj.getCCPlot()); + tabbedPane_MarginalScatterplot.add(FILEID, script_obj.getMPlot()); + } + firePropertyChange("scale", z, (z + 1)); + } + + //Make frame visible at completion of correlations if not already visible + if(!this.isVisible()) { this.setVisible(true); } + tabbedPane.addTab("Scaling Factor", makeTablePanel(SCALINGFACTORS)); + } + + public JScrollPane makeTablePanel(ArrayList SCALE) { + JTable table = new JTable(SCALE.size(), 2); + table.setName("Scaling Factors"); + table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); + for(int i = 0; i < SCALE.size(); i++) { + table.setValueAt(BAMFiles.get(i).getName(), i, 0); + table.setValueAt(SCALE.get(i).doubleValue(), i, 1); + } + table.getColumnModel().getColumn(0).setHeaderValue("Experiment"); + table.getColumnModel().getColumn(1).setHeaderValue("Scaling Factor"); + table.setPreferredSize(table.getPreferredSize()); + // Allow for the selection of multiple OR individual cells across either rows or columns + table.setCellSelectionEnabled(true); + table.setColumnSelectionAllowed(true); + table.setRowSelectionAllowed(true); + + JScrollPane pane = new JScrollPane(table); + table.setFillsViewportHeight(true); + pane.setPreferredSize(new Dimension(590, 590)); + return pane; + } +} diff --git a/src/window_interface/Read_Analysis/ScalingFactorWindow.java b/src/window_interface/Read_Analysis/ScalingFactorWindow.java index 368bcadc6..9ea05a6f3 100644 --- a/src/window_interface/Read_Analysis/ScalingFactorWindow.java +++ b/src/window_interface/Read_Analysis/ScalingFactorWindow.java @@ -36,7 +36,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Read_Analysis.ScalingFactor; +import scripts.Read_Analysis.ScalingFactorOutput; @SuppressWarnings("serial") public class ScalingFactorWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -95,7 +95,7 @@ public Void doInBackground() throws IOException { } else if(rdbtnNCIS.isSelected()) { scaleType = 2; } else if(rdbtnNcisWithTotal.isSelected()) { scaleType = 3; } - ScalingFactor scale = new ScalingFactor(BAMFiles, BLACKLIST, CONTROL, OUTPUT_PATH.getAbsolutePath(), chckbxOutputStatistics.isSelected(), scaleType, Integer.parseInt(txtWindow.getText()), Double.parseDouble(txtFraction.getText())); + ScalingFactorOutput scale = new ScalingFactorOutput(BAMFiles, BLACKLIST, CONTROL, OUTPUT_PATH.getAbsolutePath(), chckbxOutputStatistics.isSelected(), scaleType, Integer.parseInt(txtWindow.getText()), Double.parseDouble(txtFraction.getText())); scale.addPropertyChangeListener("scale", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { int temp = (Integer) propertyChangeEvent.getNewValue(); From d3a35dd92959c8caed22c943e984ef971e07bb40 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 21:41:55 -0400 Subject: [PATCH 27/43] write up cli help message for SimilarityMatrix This tool's command line development has been skipped to reflect the GUI deactivation of the tool. I also commented out its execution in the main ScriptManager subcommand to mimic the GUI. --- src/cli/Read_Analysis/SimilarityMatrixCLI.java | 2 ++ src/main/ScriptManager.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/Read_Analysis/SimilarityMatrixCLI.java b/src/cli/Read_Analysis/SimilarityMatrixCLI.java index 5cd5cda50..0c9a88bd0 100644 --- a/src/cli/Read_Analysis/SimilarityMatrixCLI.java +++ b/src/cli/Read_Analysis/SimilarityMatrixCLI.java @@ -42,6 +42,8 @@ private String validateInput() throws IOException { String r = ""; //validate input here //append messages to the user to `r` + r += "(!)This tool is deactivated to reflect the GUI."; + return(r); } } diff --git a/src/main/ScriptManager.java b/src/main/ScriptManager.java index 9e37a732c..20448261d 100755 --- a/src/main/ScriptManager.java +++ b/src/main/ScriptManager.java @@ -202,7 +202,7 @@ class Peak_CallingCLI extends SubcommandCLI {} AggregateDataCLI.class, ScaleMatrixCLI.class, ScalingFactorCLI.class, - SimilarityMatrixCLI.class, +// SimilarityMatrixCLI.class, TagPileupCLI.class }, description = "Includes tools like AggregateDataCLI, ScaleMatrixCLI, ScalingFactorCLI, SimilarityMatrixCLI, and TagPileupCLI.") From 662fef04f4ebb8401b227416f4980f9dd51a746e Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 22:11:00 -0400 Subject: [PATCH 28/43] create TagPileup command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/TagPileupOutput class while the calculations are kept in the src/scripts/*/TagPileup class. This monster of a tool (at least compared to the others) has extra files to update and they are described following the first few files that relate to the general edit structure for tools so far. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user objects/PileupParameters -reorganized methods to put get next to set methods -added comments to annotate vars with details about what each variable is for -renamed a couple methods to be more descriptive by appending 'get' to the front of the method name -added a method that would spit out all parameters as a command line execution String. Although unused for now, it may be useful for future features. --- src/cli/Read_Analysis/TagPileupCLI.java | 285 +++++++++- src/objects/PileupParameters.java | 181 +++++-- src/scripts/Read_Analysis/TagPileup.java | 508 ++++++++---------- .../Read_Analysis/TagPileupOutput.java | 147 +++++ .../Read_Analysis/TagPileupWindow.java | 6 +- 5 files changed, 799 insertions(+), 328 deletions(-) create mode 100644 src/window_interface/Read_Analysis/TagPileupOutput.java diff --git a/src/cli/Read_Analysis/TagPileupCLI.java b/src/cli/Read_Analysis/TagPileupCLI.java index bbcadfee4..540110ec7 100644 --- a/src/cli/Read_Analysis/TagPileupCLI.java +++ b/src/cli/Read_Analysis/TagPileupCLI.java @@ -14,40 +14,311 @@ import java.io.File; import java.io.IOException; +import util.BAMUtilities; import util.ExtensionFileFilter; +import objects.PileupParameters; import objects.ToolDescriptions; -//import scripts.Read_Analysis.TagPileup; +import scripts.Read_Analysis.TagPileup; /** Read_AnalysisCLI/TagPileupCLI */ @Command(name = "tag-pileup", mixinStandardHelpOptions = true, description = ToolDescriptions.tag_pileup_description, + descriptionHeading = "%nDescription:%n%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nGeneral Options:%n", sortOptions = false, exitCodeOnInvalidInput = 1, exitCodeOnExecutionException = 1) public class TagPileupCLI implements Callable { + @Parameters( index = "0", description = "The BED file with reference coordinates to pileup on.") + private File bedFile; + @Parameters( index = "1", description = "The BAM file from which we remove duplicates. Make sure its indexed!") + private File bamFile; + + @Option(names = {"-d", "--dry-run"}, description = "print all parameters without running anything") + private boolean dryRun=false; + + //Output + @ArgGroup(validate = false, heading = "%nOutput Options:%n") + OutputOptions outputOptions = new OutputOptions(); + static class OutputOptions{ + @Option(names = {"-o", "--output-composite"}, description = "specify output file for composite values") + private String outputComposite = "composite_average.out"; + @Option(names = {"-M", "--output-matrix"}, description = "specify output basename for matrix files (files each for sense and anti will be output)", + arity="0..1") + private ArrayList outputMatrix = new ArrayList(Arrays.asList("no","matrix","output")); +// @Option(names = {"-j", "--output-jtv"}, description = "output JTV file (default=false)") +// private boolean jtv = false; + @Option(names = {"-z", "--gzip"}, description = "output compressed output (default=false)") + private boolean zip = false; + @Option(names = {"--cdt"}, description = "output matrix in cdt format (default)") + private boolean cdt = false; + @Option(names = {"--tab"}, description = "output matrix in tab format") + private boolean tab = false; + } + + //Read + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n") + ReadType readType = new ReadType(); + static class ReadType { + @Option(names = {"-1", "--read1"}, description = "pileup of read 1 (default)") + boolean read1 = false; + @Option(names = {"-2", "--read2"}, description = "pileup of read 2") + boolean read2 = false; + @Option(names = {"-a", "--all-reads"}, description = "pileup all reads") + boolean allreads = false; + @Option(names = {"-m", "--midpoint"}, description = "pile midpoint (require PE and combined, -p --combined)") + boolean midpoint = false; + int finalRead = 0; + } + + //Strand + @Option(names = {"--combined"}, description = "select output strands as combined (default separates into *_sense and *_anti)") + boolean combStatus = false; + + //Smooth + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nComposite Transformation/Smoothing Options:%n\t@|fg(red) (select no more than one of these options)|@%n") + SmoothMethod smoothType = new SmoothMethod(); + static class SmoothMethod { + @Option(names = {"-N","--no-smooth"}, description = "no smoothing applied to composite (default)") + boolean noSmooth = false; + @Option(names = {"-w", "--window-smooth"}, description = "sliding window smoothing applied to composite using default 3 bins for window size") + boolean winStatus = false; + @Option(names = {"-W", "--window-values"}, description = "sliding window smoothing applied to composite with user specified window size (in #bins)") + int winVals = -9999; + @Option(names = {"-g", "--gauss-smooth"}, description = "gauss smoothing applied to composite using default values: 5 bins and 3 standard deviations") + boolean gaussStatus = false; + @Option(names = {"-G", "--gauss-values"}, arity = "2", description = "gauss smoothing applied to composite with user specified standard deviation(SD) size (in #bins) followed by the number of SD") + int[] gaussVals = new int[]{-9999,-9999}; + } + + @ArgGroup(validate = false, heading = "%nCalculation Options:%n") + CalcOptions calcOptions = new CalcOptions(); + static class CalcOptions{ + @Option(names = {"-s", "--shift"}, description = "set a shift in bp (default=0bp)") + private int shift = 0; + @Option(names = {"-b", "--bin-size"}, description = "set a bin size for the output (default=1bp)") + private int binSize = 1; + @Option(names = {"-t", "--standard"}, description = "set tags to be equal (default=false)") + private boolean tagsEqual; + @Option(names = {"--cpu"}, description = "set number of CPUs to use (default=1)") + private int cpu = 1; + } + + @ArgGroup(validate = false, heading = "%nFilter Options:%n") + FilterOptions filterOptions = new FilterOptions(); + static class FilterOptions{ + @Option(names = {"-f", "--blacklist-filter"}, description = "specify a blacklist file to filter BED by, must use with -t flag") + private File blacklistFilter = null; + @Option(names = {"-p", "--require-pe"}, description = "require proper paired ends (default=false)\nautomatically turned on with any of flags -mnx") + private boolean requirePE = false; + @Option(names = {"-n", "--min-insert"}, description = "filter by minimum insert size in bp, require PE (default=no minimum)") + private int MIN_INSERT = -9999; + @Option(names = {"-x", "--max-insert"}, description = "filter by maximum insert size in bp, require PE (default=no maximum)") + private int MAX_INSERT = -9999; + } + + PileupParameters p; + @Override public Integer call() throws Exception { System.err.println( ">TagPileupCLI.call()" ); + p = new PileupParameters(); String validate = validateInput(); if(!validate.equals("")){ - System.err.println( validate ); + System.err.println(validate); System.err.println("Invalid input. Check usage using '-h' or '--help'"); System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + if(dryRun){ + p.printAll(); + System.err.println(outputOptions.outputMatrix.get(0)); + System.exit(1); + } + + TagPileup script_obj = new TagPileup(bedFile, bamFile, p, null, outputOptions.outputMatrix.get(0), false); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println( "Calculations complete" ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check ReadType, interpret booleans for int value + if(readType.read1){ readType.finalRead = 0; } + else if(readType.read2){ readType.finalRead = 1; } + else if(readType.allreads){ readType.finalRead = 2; } + else if(readType.midpoint){ + readType.finalRead = 3; + filterOptions.requirePE = true; + combStatus = true; + } + + //check input extensions + if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){ + r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n"; + } + if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){ + r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n"; + } + if(!r.equals("")){ return(r); } + //check inputs exist + if(!bedFile.exists()){ + r += "(!)BED file does not exist: " + bedFile.getCanonicalPath() + "\n"; + } + if(!bamFile.exists()){ + r += "(!)BAM file does not exist: " + bamFile.getCanonicalPath() + "\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"; + } + + //set default output COMPOSITE filename (done by picocli) + //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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //set default output MATRIX (if output MATRIX not to be output) + if(outputOptions.outputMatrix.size()>1){ + outputOptions.outputMatrix.set(0,null); + //set default output MATRIX basename (allow scripts/*/TagPileup to generate ret of filename) + } else if(outputOptions.outputMatrix.size()==0){ //generate default basename + String readString = "read1"; + if(readType.finalRead == 1) { readString = "read2"; } + else if(readType.finalRead == 2) { readString = "allreads"; } + else if(readType.finalRead == 3) { readString = "midpoint"; } + outputOptions.outputMatrix.add( + ExtensionFileFilter.stripExtension(new File(bedFile.getName())) + "_" + + ExtensionFileFilter.stripExtension(new File(bamFile.getName())) + "_" + readString); + //check output filename is valid + }else{ //check basename + File output = new File(outputOptions.outputMatrix.get(0)); + //no extension check b/c basename should have no extension + //check directory + if(output.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n"; + } + } + + //validate smooth params + if(smoothType.winVals!=-9999 && smoothType.winVals<1){ r += "(!)Invalid Smoothing Window Size. Must be larger than 0 bins, winSize=" + smoothType.winVals + "\n"; } + if(smoothType.gaussVals[0]!=-9999 && smoothType.gaussVals[0]<1){ r += "(!)Invalid Standard Deviation Size. Must be larger than 0 bins, stdSize=" + smoothType.gaussVals[0] + "\n"; } + if(smoothType.gaussVals[1]!=-9999 && smoothType.gaussVals[1]<1){ r += "(!)Invalid Number of Standard Deviations. Must be larger than 0 standard deviations, stdNum=" + smoothType.gaussVals[1] + "\n"; } + + //set require PE for appropriate flags + if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999){ filterOptions.requirePE = true; } + if( readType.midpoint ){ filterOptions.requirePE = true; } + + //validate shift, binSize, and CPUs + if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; } + if(calcOptions.binSize<1){ r += "(!)Invalid Bin Size! Must use at least 1bp, binSize=" + calcOptions.binSize + "\n"; } + if(calcOptions.cpu<1){ r += "(!)Invalid Number of CPU's! Must use at least 1, CPU=" + calcOptions.cpu + "\n"; } + + //validate insert sizes + if( filterOptions.MIN_INSERT<0 && filterOptions.MIN_INSERT!=-9999 ){ r += "(!)MIN_INSERT must be a positive integer value: " + p.getMinInsert() + "\n"; } + if( filterOptions.MAX_INSERT<0 && filterOptions.MAX_INSERT!=-9999 ){ r += "(!)MAX_INSERT must be a positive integer value: " + p.getMaxInsert() + "\n"; } + if( filterOptions.MIN_INSERT!=-9999 && filterOptions.MAX_INSERT!=-9999 && filterOptions.MAX_INSERT<><><><><><><><><><><><><><><><><><><>" ); + System.out.println( "private File OUTPUT = " + OUTPUT ); + System.out.println( "private String COMPOSITE = " + COMPOSITE ); + System.out.println( "private int READ = " + READ ); + System.out.println( "private int STRAND = " + STRAND ); + System.out.println( "private int TRANS = " + TRANS ); + System.out.println( "private int SHIFT = " + SHIFT ); + System.out.println( "private int BIN = " + BIN ); + System.out.println( "private int SMOOTH = " + SMOOTH ); + System.out.println( "private int STDSIZE = " + STDSIZE ); + System.out.println( "private int STDNUM = " + STDNUM ); + System.out.println( "private int CPU = " + CPU ); + System.out.println( "private int OUTTYPE = " + OUTTYPE ); + System.out.println( "private File BLACKLIST = " + BLACKLIST ); + System.out.println( "private boolean STANDARD = " + STANDARD ); + System.out.println( "private boolean outputCOMPOSITE = " + outputCOMPOSITE ); + System.out.println( "private boolean outputJTV = " + outputJTV ); + System.out.println( "private boolean outputGZIP = " + outputGZIP ); + System.out.println( "private boolean requirePE = " + requirePE ); + System.out.println( "private double STANDRATIO = " + STANDRATIO ); + System.out.println(); + System.out.println( "private int MIN_INSERT = " + MIN_INSERT ); + System.out.println( "private int MAX_INSERT = " + MAX_INSERT ); + System.out.println(); + System.out.println( "private Color Sense = " + Sense ); + System.out.println( "private Color Anti = " + Anti ); + System.out.println( "private Color Combined = " + Combined ); +// System.out.println( "" + ); +// System.out.println( "" + ); +// System.out.println( "" + ); + System.out.println( "<><><><><><><><><><><><><><><><><><><><>" ); + } + + public boolean getOutputGZIP() { return outputGZIP; } - public void setGZIPstatus(boolean status) { outputGZIP = status; } - public boolean outputJTV() { + public boolean getOutputJTV() { return outputJTV; } - public void setJTVstatus(boolean status) { outputJTV = status; } @@ -55,31 +101,27 @@ public void setJTVstatus(boolean status) { public File getBlacklist() { return BLACKLIST; } - public void setBlacklist(File black) { BLACKLIST = black; } - public void setMaxInsert(int max) { - MAX_INSERT = max; - } - public int getMaxInsert() { return MAX_INSERT; } - - public void setMinInsert(int min) { - MIN_INSERT = min; + public void setMaxInsert(int max) { + MAX_INSERT = max; } public int getMinInsert() { return MIN_INSERT; } + public void setMinInsert(int min) { + MIN_INSERT = min; + } public boolean getPErequire() { return requirePE; } - public void setPErequire(boolean status) { requirePE = status; } @@ -87,7 +129,6 @@ public void setPErequire(boolean status) { public String getCompositeFile() { return COMPOSITE; } - public void setCompositeFile(String comp) { COMPOSITE = comp; } @@ -95,7 +136,6 @@ public void setCompositeFile(String comp) { public boolean getOutputCompositeStatus() { return outputCOMPOSITE; } - public void setOutputCompositeStatus(boolean out) { outputCOMPOSITE = out; } @@ -108,58 +148,51 @@ public ArrayList getColors() { return ALL; } - public void setSenseColor(Color s) { - Sense = s; - } - public Color getSenseColor() { return Sense; } - - public void setAntiColor(Color a) { - Anti = a; + public void setSenseColor(Color s) { + Sense = s; } public Color getAntiColor() { return Anti; } - - public void setCombinedColor(Color c) { - Combined = c; + public void setAntiColor(Color a) { + Anti = a; } public Color getCombinedColor() { return Combined; } - - public void setRatio(double rat) { - STANDRATIO = rat; + public void setCombinedColor(Color c) { + Combined = c; } public double getRatio() { return STANDRATIO; } - - public void setStandard(boolean stand) { - STANDARD = stand; + public void setRatio(double rat) { + STANDRATIO = rat; } public boolean getStandard() { return STANDARD; } - - public void setOutputType(int newtype) { - OUTTYPE = newtype; + public void setStandard(boolean stand) { + STANDARD = stand; } public int getOutputType() { return OUTTYPE; } + public void setOutputType(int newtype) { + OUTTYPE = newtype; + } public File getOutput() { return OUTPUT; } - public void setOutput(File oUTPUT) { OUTPUT = oUTPUT; } @@ -167,7 +200,6 @@ public void setOutput(File oUTPUT) { public int getRead() { return READ; } - public void setRead(int rEAD) { READ = rEAD; } @@ -175,7 +207,6 @@ public void setRead(int rEAD) { public int getStrand() { return STRAND; } - public void setStrand(int sTRAND) { STRAND = sTRAND; } @@ -183,7 +214,6 @@ public void setStrand(int sTRAND) { public int getTrans() { return TRANS; } - public void setTrans(int tRANS) { TRANS = tRANS; } @@ -191,7 +221,6 @@ public void setTrans(int tRANS) { public int getShift() { return SHIFT; } - public void setShift(int sHIFT) { SHIFT = sHIFT; } @@ -199,7 +228,6 @@ public void setShift(int sHIFT) { public int getBin() { return BIN; } - public void setBin(int bIN) { BIN = bIN; } @@ -207,7 +235,6 @@ public void setBin(int bIN) { public int getSmooth() { return SMOOTH; } - public void setSmooth(int sMOOTH) { SMOOTH = sMOOTH; } @@ -215,7 +242,6 @@ public void setSmooth(int sMOOTH) { public int getStdSize() { return STDSIZE; } - public void setStdSize(int sTDSIZE) { STDSIZE = sTDSIZE; } @@ -223,7 +249,6 @@ public void setStdSize(int sTDSIZE) { public int getStdNum() { return STDNUM; } - public void setStdNum(int sTDNUM) { STDNUM = sTDNUM; } @@ -231,9 +256,67 @@ public void setStdNum(int sTDNUM) { public int getCPU() { return CPU; } - public void setCPU(int cPU) { CPU = cPU; } + + public String getCLIcmd(){ + + String cliCommand = "java -jar ScriptManager.jar read-analysis tag-pileup "; + + //Add READ + if(READ==0){ cliCommand += " -1"; } + else if(READ==1){ cliCommand += " -2"; } + else if(READ==2){ cliCommand += " -a"; } + else if(READ==3){ cliCommand += " -m"; } + else{ System.err.println("This should not print."); } + //Add STRAND + if(STRAND==0){ cliCommand += " --separate"; } + else if(STRAND==1){ cliCommand += " --combined"; } + else{ System.err.println("This should not print."); } + //Add TRANS + if(TRANS==0){ + cliCommand += " --no-smooth"; + }else if(TRANS==1){ + if(SMOOTH==3){ cliCommand += " -w"; } + else{ cliCommand += " -W " + SMOOTH; } + }else if(TRANS==2){ + if(STDSIZE==5 && STDNUM==3){ cliCommand += " -g"; } + else{ cliCommand += " -G " + STDSIZE + " " + STDNUM; } + }else{ System.err.println("This should not print."); } + + //Add SHIFT + if(SHIFT!=0){ cliCommand += " -s " + SHIFT; } + //Add BIN + if(BIN!=1){ cliCommand += " -b " + BIN; } + + //Add STANDARD + if(STANDARD==true){ cliCommand += " -t"; } + //Add BLACKLIST + if(BLACKLIST!=null){ cliCommand += " -f " + BLACKLIST; } + + //Add requirePE + if(requirePE==true){ cliCommand += " -p"; } + //Add MIN_INSERT + if(MIN_INSERT!=-9999){ cliCommand += " -n " + MIN_INSERT; } + //Add MAX_INSERT + if(MAX_INSERT!=-9999){ cliCommand += " -x " + MAX_INSERT; } + + //Add outputJTV + if(outputJTV==true){ cliCommand += " -j"; } + //Add outputGZIP + if(outputGZIP==true){ cliCommand += " -z"; } + + //Add CPU + if(CPU!=1){ cliCommand += " --cpu " + CPU; } + +// System.out.println( "private File OUTPUT = " + OUTPUT ); +// System.out.println( "private String COMPOSITE = " + COMPOSITE ); +// System.out.println( "private int OUTTYPE = " + OUTTYPE ); +// System.out.println( "private boolean outputCOMPOSITE = " + outputCOMPOSITE ); + + return(cliCommand); + } + } diff --git a/src/scripts/Read_Analysis/TagPileup.java b/src/scripts/Read_Analysis/TagPileup.java index 3a8981444..712ea71ac 100644 --- a/src/scripts/Read_Analysis/TagPileup.java +++ b/src/scripts/Read_Analysis/TagPileup.java @@ -1,6 +1,7 @@ package scripts.Read_Analysis; import java.awt.BorderLayout; +import java.awt.Component; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -19,13 +20,7 @@ import java.util.concurrent.Executors; import java.util.zip.GZIPOutputStream; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JLayeredPane; -import javax.swing.JTabbedPane; -import javax.swing.SpringLayout; +import org.jfree.chart.ChartPanel; import charts.CompositePlot; import htsjdk.samtools.AbstractBAMFileIndex; @@ -35,278 +30,247 @@ import objects.CoordinateObjects.BEDCoord; import scripts.Read_Analysis.PileupScripts.PileupExtract; import util.ArrayUtilities; -import util.BAMUtilities; import util.JTVOutput; @SuppressWarnings("serial") -public class TagPileup extends JFrame { - Vector BEDFiles = null; - Vector BAMFiles = null; +public class TagPileup { + File BED = null; + File BAM = null; PileupParameters PARAM = null; private int STRAND = 0; - private int CPU = 1; PrintStream COMPOSITE = null; // Generic print stream to accept PrintStream of GZIPOutputStream Writer OUT_S1 = null; Writer OUT_S2 = null; - final JLayeredPane layeredPane; - final JTabbedPane tabbedPane; - final JTabbedPane tabbedPane_Scatterplot; - final JTabbedPane tabbedPane_Statistics; + PrintStream PS = null; - public TagPileup(Vector be, Vector ba, PileupParameters param) { - setTitle("Tag Pileup Composite"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 800, 600); + Component compositePlot = null; + + String outMatrixBasename; + + boolean GUI = false; + + public TagPileup(File be, File ba, PileupParameters param, PrintStream outputwindow_ps, String outMat, boolean guiStatus) { + BED = be; + BAM = ba; + PARAM = param; + PS = outputwindow_ps; + outMatrixBasename = outMat; + GUI = guiStatus; + } + + public void run() throws IOException { + //Set-up Matrix output writers + int STRAND = PARAM.getStrand(); + if(PARAM.getOutputType() != 0) { + if(STRAND == 0) { + //Set FileName + String NAME0; + String NAME1; + if(outMatrixBasename==null){ + NAME0 = PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 0); + NAME1 = PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 1); + }else{ + NAME0 = generateFileName(outMatrixBasename, 0); + NAME1 = generateFileName(outMatrixBasename, 1); + } + //Build streams + if(PARAM.getOutputGZIP()) { + OUT_S1 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream( NAME0)), "UTF-8"); + OUT_S2 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream( NAME1)), "UTF-8"); + } else { + OUT_S1 = new PrintWriter(NAME0); + OUT_S2 = new PrintWriter(NAME1); + } + } else { + //Set FileName + String NAME2; + if(outMatrixBasename==null){ + NAME2 = PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 2); + }else{ + NAME2 = generateFileName(outMatrixBasename, 2); + } + if(PARAM.getOutputGZIP()) { + OUT_S1 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(NAME2)), "UTF-8"); + } else { + OUT_S1 = new PrintWriter(NAME2); + } + } + } - layeredPane = new JLayeredPane(); - getContentPane().add(layeredPane, BorderLayout.CENTER); - SpringLayout sl_layeredPane = new SpringLayout(); - layeredPane.setLayout(sl_layeredPane); + printPS(getTimeStamp()); //Timestamp process + printPS(BAM.getName()); //Label stat object with what BAM file is generating it - tabbedPane = new JTabbedPane(JTabbedPane.TOP); - sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); - sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); - layeredPane.add(tabbedPane); + //Validate and load BED coordinates + System.err.println("Validating BED: " + BED.getName()); + Vector INPUT = validateBED(loadCoord(BED), BAM); - tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("Pileup Plot", null, tabbedPane_Scatterplot, null); + //Split up job and send out to threads to process + int CPU = PARAM.getCPU(); + ExecutorService parseMaster = Executors.newFixedThreadPool(CPU); + if(INPUT.size() < CPU) CPU = INPUT.size(); + int subset = 0; + int currentindex = 0; + for(int x = 0; x < CPU; x++) { + currentindex += subset; + if(CPU == 1) { subset = INPUT.size(); } + else if(INPUT.size() % CPU == 0) { subset = INPUT.size() / CPU; } + else { + int remainder = INPUT.size() % CPU; + if(x < remainder ) subset = (int)(((double)INPUT.size() / (double)CPU) + 1); + else subset = (int)(((double)INPUT.size() / (double)CPU)); + } + //System.out.println("CPU: " + x + "\tInterval: " + currentindex + "\t" + subset); + PileupExtract extract = new PileupExtract(PARAM, BAM, INPUT, currentindex, subset); + parseMaster.execute(extract); + } + parseMaster.shutdown(); + while (!parseMaster.isTerminated()) { + } - tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); - tabbedPane.addTab("Pileup Statistics", null, tabbedPane_Statistics, null); + double[] AVG_S1 = new double[getMaxBEDSize(INPUT)]; + double[] AVG_S2 = null; + if(STRAND == 0) AVG_S2 = new double[AVG_S1.length]; + double[] DOMAIN = new double[AVG_S1.length]; - BEDFiles = be; - BAMFiles = ba; - PARAM = param; - STRAND = param.getStrand(); - CPU = param.getCPU(); + //Account for the shifted oversized window produced by binning and smoothing + int OUTSTART = 0; + if(PARAM.getTrans() == 1) { OUTSTART = PARAM.getSmooth(); } + else if(PARAM.getTrans() == 2) { OUTSTART = (PARAM.getStdSize() * PARAM.getStdNum()); } - } - - public void run() throws IOException { + //Write headers + if(PARAM.getOutputType() == 2) { + if(OUT_S1 != null) OUT_S1.write("YORF\tNAME"); + if(OUT_S2 != null) OUT_S2.write("YORF\tNAME"); + double[] tempF = INPUT.get(0).getFStrand(); + + for(int i = OUTSTART; i < tempF.length - OUTSTART; i++) { + int index = i - OUTSTART; + if(OUT_S1 != null) OUT_S1.write("\t" + index); + if(OUT_S2 != null) OUT_S2.write("\t" + index); + } + if(OUT_S1 != null) OUT_S1.write("\n"); + if(OUT_S2 != null) OUT_S2.write("\n"); + } + + //Output individual sites + for(int i = 0; i < INPUT.size(); i++) { + double[] tempF = INPUT.get(i).getFStrand(); + double[] tempR = INPUT.get(i).getRStrand(); + if(OUT_S1 != null) OUT_S1.write(INPUT.get(i).getName()); + if(OUT_S2 != null) OUT_S2.write(INPUT.get(i).getName()); + + if(PARAM.getOutputType() == 2) { + if(OUT_S1 != null) OUT_S1.write("\t" + INPUT.get(i).getName()); + if(OUT_S2 != null) OUT_S2.write("\t" + INPUT.get(i).getName()); + } + + for(int j = 0; j < tempF.length; j++) { + //Output values outside of window overhang + if(j >= OUTSTART && j < tempF.length - OUTSTART) { + if(OUT_S1 != null) OUT_S1.write("\t" + tempF[j]); + if(OUT_S2 != null) OUT_S2.write("\t" + tempR[j]); + } + //Sum positions across BED coordinates + AVG_S1[j] += tempF[j]; + if(AVG_S2 != null) AVG_S2[j] += tempR[j]; + } + if(OUT_S1 != null) OUT_S1.write("\n"); + if(OUT_S2 != null) OUT_S2.write("\n"); + } + + //Calculate average and domain here + int temp = (int) (((double)AVG_S1.length / 2.0) + 0.5); + for(int i = 0; i < AVG_S1.length; i++) { + DOMAIN[i] = (double)((temp - (AVG_S1.length - i)) * PARAM.getBin()) + 1; + AVG_S1[i] /= INPUT.size(); + if(AVG_S2 != null) AVG_S2[i] /= INPUT.size(); + } + + //Transform average given transformation parameters + if(PARAM.getTrans() == 1) { + AVG_S1 = ArrayUtilities.windowSmooth(AVG_S1, PARAM.getSmooth()); + if(AVG_S2 != null) AVG_S2 = ArrayUtilities.windowSmooth(AVG_S2, PARAM.getSmooth()); + } else if(PARAM.getTrans() == 2) { + AVG_S1 = ArrayUtilities.gaussSmooth(AVG_S1, PARAM.getStdSize(), PARAM.getStdNum()); + if(AVG_S2 != null) AVG_S2 = ArrayUtilities.gaussSmooth(AVG_S2, PARAM.getStdSize(), PARAM.getStdNum()); + } + + //Trim average here and output to statistics pane + double[] AVG_S1_trim = new double[AVG_S1.length - (OUTSTART * 2)]; + double[] AVG_S2_trim = null; + if(STRAND == 0) AVG_S2_trim = new double[AVG_S1_trim.length]; + double[] DOMAIN_trim = new double[AVG_S1_trim.length]; + for(int i = OUTSTART; i < AVG_S1.length - OUTSTART; i++) { + if(AVG_S2 != null) { + printPS(DOMAIN[i] + "\t" + AVG_S1[i] + "\t" + AVG_S2[i]); + AVG_S2_trim[i - OUTSTART] = AVG_S2[i]; + } + else { printPS(DOMAIN[i] + "\t" + AVG_S1[i]); } + AVG_S1_trim[i - OUTSTART] = AVG_S1[i]; + DOMAIN_trim[i - OUTSTART] = DOMAIN[i]; + } + AVG_S1 = AVG_S1_trim; + AVG_S2 = AVG_S2_trim; + DOMAIN = DOMAIN_trim; + + //Output composite data file setup if(PARAM.getOutputCompositeStatus()) { - try { COMPOSITE = new PrintStream(PARAM.getOutput() + File.separator + PARAM.getCompositeFile()); + try { COMPOSITE = new PrintStream(PARAM.getCompositeFile()); } catch (FileNotFoundException e) { e.printStackTrace(); } } - //Check if BAI index file exists for all BAM files - boolean[] BAMvalid = new boolean[BAMFiles.size()]; - for(int z = 0; z < BAMFiles.size(); z++) { - File BAM = BAMFiles.get(z); //Pull current BAM file - File f = new File(BAM + ".bai"); //Generate file name for BAI index file - if(!f.exists() || f.isDirectory()) { - BAMvalid[z] = false; - JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + BAM.getName()); - System.err.println("BAI Index File does not exist for: " + BAM.getName()); - } else { BAMvalid[z] = true; } + //Output composite data to tab-delimited file + if(COMPOSITE != null) { + for(int a = 0; a < DOMAIN.length; a++) { + COMPOSITE.print("\t" + DOMAIN[a]); + } + COMPOSITE.println(); + if(STRAND == 0) { + COMPOSITE.print(generateFileName(BED.getName(), BAM.getName(), 0)); + for(int a = 0; a < AVG_S1.length; a++) { + COMPOSITE.print("\t" + AVG_S1[a]); + } + COMPOSITE.println(); + COMPOSITE.print(generateFileName(BED.getName(), BAM.getName(), 1)); + for(int a = 0; a < AVG_S2.length; a++) { + COMPOSITE.print("\t" + AVG_S2[a]); + } + COMPOSITE.println(); + } else { + COMPOSITE.print(generateFileName(BED.getName(), BAM.getName(), 2)); + for(int a = 0; a < AVG_S1.length; a++) { + COMPOSITE.print("\t" + AVG_S1[a]); + } + COMPOSITE.println(); + } } - int PROGRESS = 0; - for(int z = 0; z < BAMFiles.size(); z++) { - File BAM = BAMFiles.get(z); //Pull current BAM file - if(BAMvalid[z]) { - //Code to standardize tags sequenced to genome size (1 tag / 1 bp) - if(PARAM.getStandard() && PARAM.getBlacklist() != null) { PARAM.setRatio(BAMUtilities.calculateStandardizationRatio(BAM, PARAM.getBlacklist(), PARAM.getRead())); } - else if(PARAM.getStandard()) { PARAM.setRatio(BAMUtilities.calculateStandardizationRatio(BAM, PARAM.getRead())); } - //System.out.println(PARAM.getRatio()); - - for(int BED_Index = 0; BED_Index < BEDFiles.size(); BED_Index++) { - System.out.println("Processing BAM: " + BAM.getName() + "\tCoordinate: " + BEDFiles.get(BED_Index).getName()); - - JTextArea STATS = new JTextArea(); //Generate statistics object - STATS.setEditable(false); //Make it un-editable - STATS.append(getTimeStamp() + "\n"); //Timestamp process - STATS.append(BAM.getName() + "\n"); //Label stat object with what BAM file is generating it - - if(PARAM.getOutputType() != 0) { - if(STRAND == 0) { - if(PARAM.outputGZIP()) { - try { - OUT_S1 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 0))), "UTF-8"); - OUT_S2 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 1))), "UTF-8"); - } catch (FileNotFoundException e) { e.printStackTrace(); } - } else { - try { - OUT_S1 = new PrintWriter(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 0)); - OUT_S2 = new PrintWriter(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 1)); - } catch (FileNotFoundException e) { e.printStackTrace(); } - } - } else { - if(PARAM.outputGZIP()) { - try { OUT_S1 = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 2))), "UTF-8"); - } catch (FileNotFoundException e) { e.printStackTrace(); } - } else { - try { OUT_S1 = new PrintWriter(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 2)); - } catch (FileNotFoundException e) { e.printStackTrace(); } - } - } - } - - System.out.println("Validating BED: " + BEDFiles.get(BED_Index).getName()); - Vector INPUT = validateBED(loadCoord(BEDFiles.get(BED_Index)), BAMFiles.get(z)); - - //Split up job and send out to threads to process - ExecutorService parseMaster = Executors.newFixedThreadPool(CPU); - if(INPUT.size() < CPU) CPU = INPUT.size(); - int subset = 0; - int currentindex = 0; - for(int x = 0; x < CPU; x++) { - currentindex += subset; - if(CPU == 1) { subset = INPUT.size(); } - else if(INPUT.size() % CPU == 0) { subset = INPUT.size() / CPU; } - else { - int remainder = INPUT.size() % CPU; - if(x < remainder ) subset = (int)(((double)INPUT.size() / (double)CPU) + 1); - else subset = (int)(((double)INPUT.size() / (double)CPU)); - } - //System.out.println("CPU: " + x + "\tInterval: " + currentindex + "\t" + subset); - PileupExtract extract = new PileupExtract(PARAM, BAM, INPUT, currentindex, subset); - parseMaster.execute(extract); - } - parseMaster.shutdown(); - while (!parseMaster.isTerminated()) { - } - - double[] AVG_S1 = new double[getMaxBEDSize(INPUT)]; - double[] AVG_S2 = null; - if(STRAND == 0) AVG_S2 = new double[AVG_S1.length]; - double[] DOMAIN = new double[AVG_S1.length]; - - //Account for the shifted oversized window produced by binning and smoothing - int OUTSTART = 0; - if(PARAM.getTrans() == 1) { OUTSTART = PARAM.getSmooth(); } - else if(PARAM.getTrans() == 2) { OUTSTART = (PARAM.getStdSize() * PARAM.getStdNum()); } - - if(PARAM.getOutputType() == 2) { - if(OUT_S1 != null) OUT_S1.write("YORF\tNAME"); - if(OUT_S2 != null) OUT_S2.write("YORF\tNAME"); - double[] tempF = INPUT.get(0).getFStrand(); - - for(int i = OUTSTART; i < tempF.length - OUTSTART; i++) { - int index = i - OUTSTART; - if(OUT_S1 != null) OUT_S1.write("\t" + index); - if(OUT_S2 != null) OUT_S2.write("\t" + index); - } - if(OUT_S1 != null) OUT_S1.write("\n"); - if(OUT_S2 != null) OUT_S2.write("\n"); - } - - //Output individual sites - for(int i = 0; i < INPUT.size(); i++) { - double[] tempF = INPUT.get(i).getFStrand(); - double[] tempR = INPUT.get(i).getRStrand(); - if(OUT_S1 != null) OUT_S1.write(INPUT.get(i).getName()); - if(OUT_S2 != null) OUT_S2.write(INPUT.get(i).getName()); - - if(PARAM.getOutputType() == 2) { - if(OUT_S1 != null) OUT_S1.write("\t" + INPUT.get(i).getName()); - if(OUT_S2 != null) OUT_S2.write("\t" + INPUT.get(i).getName()); - } - - for(int j = 0; j < tempF.length; j++) { - if(j >= OUTSTART && j < tempF.length - OUTSTART) { - if(OUT_S1 != null) OUT_S1.write("\t" + tempF[j]); - if(OUT_S2 != null) OUT_S2.write("\t" + tempR[j]); - } - AVG_S1[j] += tempF[j]; - if(AVG_S2 != null) AVG_S2[j] += tempR[j]; - } - if(OUT_S1 != null) OUT_S1.write("\n"); - if(OUT_S2 != null) OUT_S2.write("\n"); - } - - //Calculate average and domain here - int temp = (int) (((double)AVG_S1.length / 2.0) + 0.5); - for(int i = 0; i < AVG_S1.length; i++) { - DOMAIN[i] = (double)((temp - (AVG_S1.length - i)) * PARAM.getBin()) + 1; - AVG_S1[i] /= INPUT.size(); - if(AVG_S2 != null) AVG_S2[i] /= INPUT.size(); - } - - //Transform average given transformation parameters - if(PARAM.getTrans() == 1) { - AVG_S1 = ArrayUtilities.windowSmooth(AVG_S1, PARAM.getSmooth()); - if(AVG_S2 != null) AVG_S2 = ArrayUtilities.windowSmooth(AVG_S2, PARAM.getSmooth()); - } else if(PARAM.getTrans() == 2) { - AVG_S1 = ArrayUtilities.gaussSmooth(AVG_S1, PARAM.getStdSize(), PARAM.getStdNum()); - if(AVG_S2 != null) AVG_S2 = ArrayUtilities.gaussSmooth(AVG_S2, PARAM.getStdSize(), PARAM.getStdNum()); - } - - //Trim average here and output to statistics pane - double[] AVG_S1_trim = new double[AVG_S1.length - (OUTSTART * 2)]; - double[] AVG_S2_trim = null; - if(STRAND == 0) AVG_S2_trim = new double[AVG_S1_trim.length]; - double[] DOMAIN_trim = new double[AVG_S1_trim.length]; - for(int i = OUTSTART; i < AVG_S1.length - OUTSTART; i++) { - if(AVG_S2 != null) { - STATS.append(DOMAIN[i] + "\t" + AVG_S1[i] + "\t" + AVG_S2[i] + "\n"); - AVG_S2_trim[i - OUTSTART] = AVG_S2[i]; - } - else { STATS.append(DOMAIN[i] + "\t" + AVG_S1[i] + "\n"); } - AVG_S1_trim[i - OUTSTART] = AVG_S1[i]; - DOMAIN_trim[i - OUTSTART] = DOMAIN[i]; - } - AVG_S1 = AVG_S1_trim; - AVG_S2 = AVG_S2_trim; - DOMAIN = DOMAIN_trim; - - //Output composite data to tab-delimited file - if(COMPOSITE != null) { - for(int a = 0; a < DOMAIN.length; a++) { - COMPOSITE.print("\t" + DOMAIN[a]); - } - COMPOSITE.println(); - if(STRAND == 0) { - COMPOSITE.print(generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 0)); - for(int a = 0; a < AVG_S1.length; a++) { - COMPOSITE.print("\t" + AVG_S1[a]); - } - COMPOSITE.println(); - COMPOSITE.print(generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 1)); - for(int a = 0; a < AVG_S2.length; a++) { - COMPOSITE.print("\t" + AVG_S2[a]); - } - COMPOSITE.println(); - } else { - COMPOSITE.print(generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 2)); - for(int a = 0; a < AVG_S1.length; a++) { - COMPOSITE.print("\t" + AVG_S1[a]); - } - COMPOSITE.println(); - } - } - - if(STRAND == 0) tabbedPane_Scatterplot.add(BAM.getName(), CompositePlot.createCompositePlot(DOMAIN, AVG_S1, AVG_S2, BEDFiles.get(BED_Index).getName(), PARAM.getColors())); - else tabbedPane_Scatterplot.add(BAM.getName(), CompositePlot.createCompositePlot(DOMAIN, AVG_S1, BEDFiles.get(BED_Index).getName(), PARAM.getColors())); - - if(OUT_S1 != null) { - if(PARAM.outputJTV() && PARAM.getOutputType() == 2) { - if(STRAND == 0) JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 0), PARAM.getSenseColor()); - else JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 2), PARAM.getCombinedColor()); - } - OUT_S1.close(); - } - if(OUT_S2 != null){ - if(PARAM.outputJTV() && PARAM.getOutputType() == 2) { - JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BEDFiles.get(BED_Index).getName(), BAM.getName(), 1), PARAM.getAntiColor()); - } - OUT_S2.close(); - } - - STATS.setCaretPosition(0); - JScrollPane newpane = new JScrollPane(STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - tabbedPane_Statistics.add(BAM.getName(), newpane); - firePropertyChange("tag", PROGRESS, PROGRESS + 1); - PROGRESS++; - } + //Make composite plots + if(GUI){ + if(STRAND == 0){ compositePlot = CompositePlot.createCompositePlot(DOMAIN, AVG_S1, AVG_S2, BED.getName(), PARAM.getColors()); } + else{ compositePlot = CompositePlot.createCompositePlot(DOMAIN, AVG_S1, BED.getName(), PARAM.getColors()); } + } + + //Output JTV files + if(OUT_S1 != null) { + if(PARAM.getOutputJTV() && PARAM.getOutputType() == 2) { + if(STRAND == 0) JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 0), PARAM.getSenseColor()); + else JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 2), PARAM.getCombinedColor()); + } + OUT_S1.close(); + } + if(OUT_S2 != null){ + if(PARAM.getOutputJTV() && PARAM.getOutputType() == 2) { + JTVOutput.outputJTV(PARAM.getOutput() + File.separator + generateFileName(BED.getName(), BAM.getName(), 1), PARAM.getAntiColor()); } - } + OUT_S2.close(); + } + } //Get size of largest array for composite generation @@ -326,15 +290,6 @@ public Vector validateBED(Vector COORD, File BAM) throws IOE Vector FINAL = new Vector(); ArrayList indexFail = new ArrayList(); - //check for starts smaller than the stop - for(int x = 0; x < COORD.size(); x++) { - if(COORD.get(x).getStart() > COORD.get(x).getStop()) { - if(!indexFail.contains(new Integer(x))) { - indexFail.add(new Integer(x)); - } - } - } - //Get chromosome IDs SamReader inputSam = SamReaderFactory.makeDefault().open(BAM); AbstractBAMFileIndex bai = (AbstractBAMFileIndex) inputSam.indexing().getIndex(); @@ -345,9 +300,11 @@ public Vector validateBED(Vector COORD, File BAM) throws IOE inputSam.close(); bai.close(); - //check for bed chrom that aren't in BAM file + //check each BED coordinate... for(int x = 0; x < COORD.size(); x++) { - if(!chrom.contains(COORD.get(x).getChrom())) { + //check for (1) bed chrom that aren't in BAM file OR + // (2) starts smaller than the stop + if( (!chrom.contains(COORD.get(x).getChrom())) || (COORD.get(x).getStart() > COORD.get(x).getStop()) ) { if(!indexFail.contains(new Integer(x))) { indexFail.add(new Integer(x)); } @@ -372,18 +329,23 @@ public String generateFileName(String bed, String bam, int strandnum) { String[] bedname = bed.split("\\."); String[] bamname = bam.split("\\."); - String strand = "sense"; - if(strandnum == 1) { strand = "anti"; } - else if(strandnum == 2) { strand = "combined"; } String read = "read1"; if(PARAM.getRead() == 1) { read = "read2"; } else if(PARAM.getRead() == 2) { read = "readc"; } - String filename = bedname[0] + "_" + bamname[0] + "_" + read + "_" + strand; + return(generateFileName(bedname[0] + "_" + bamname[0] + "_" + read, strandnum)); + } + + public String generateFileName(String basename, int strandnum) { + String strand = "sense"; + if(strandnum == 1) { strand = "anti"; } + else if(strandnum == 2) { strand = "combined"; } + + String filename = basename + "_" + strand; if(PARAM.getOutputType() == 1) { filename += ".tab"; } else { filename += ".cdt"; } - if(PARAM.outputGZIP()) { filename += ".gz"; } + if(PARAM.getOutputGZIP()) { filename += ".gz"; } return filename; } @@ -411,7 +373,7 @@ public Vector loadCoord(File INPUT) throws FileNotFoundException { } else { COORD.add(new BEDCoord(temp[0], Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), "+", name)); } } else { - System.out.println("Invalid Coordinate in File!!!\n" + Arrays.toString(temp)); + System.err.println("Invalid Coordinate in File!!!\n" + Arrays.toString(temp)); } } } @@ -419,4 +381,12 @@ public Vector loadCoord(File INPUT) throws FileNotFoundException { scan.close(); return COORD; } + + public Component getCompositePlot(){ return(compositePlot); } + + private void printPS(String line){ + if(PS!=null){ PS.println(line); } + else{ System.err.println(line); } + } + } diff --git a/src/window_interface/Read_Analysis/TagPileupOutput.java b/src/window_interface/Read_Analysis/TagPileupOutput.java new file mode 100644 index 000000000..5ed9d4fc6 --- /dev/null +++ b/src/window_interface/Read_Analysis/TagPileupOutput.java @@ -0,0 +1,147 @@ +package window_interface.Read_Analysis; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.PrintWriter; +// import java.io.Writer; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.Scanner; +import java.util.Vector; +// import java.util.concurrent.ExecutorService; +// import java.util.concurrent.Executors; +// import java.util.zip.GZIPOutputStream; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JLayeredPane; +import javax.swing.JTabbedPane; +import javax.swing.SpringLayout; + +import org.jfree.chart.JFreeChart; +import charts.CompositePlot; +import htsjdk.samtools.AbstractBAMFileIndex; +// import htsjdk.samtools.SamReader; +// import htsjdk.samtools.SamReaderFactory; +import objects.PileupParameters; +import objects.CoordinateObjects.BEDCoord; +import objects.CustomOutputStream; +// import scripts.Read_Analysis.PileupScripts.PileupExtract; +import scripts.Read_Analysis.TagPileup; +import util.ArrayUtilities; +import util.BAMUtilities; +import util.JTVOutput; + +@SuppressWarnings("serial") +public class TagPileupOutput extends JFrame { + Vector BEDFiles = null; + Vector BAMFiles = null; + + PileupParameters PARAM = null; + +// private int STRAND = 0; +// private int CPU = 1; + + PrintStream COMPOSITE = null; + // Generic print stream to accept PrintStream of GZIPOutputStream +// Writer OUT_S1 = null; +// Writer OUT_S2 = null; + + final JLayeredPane layeredPane; + final JTabbedPane tabbedPane; + final JTabbedPane tabbedPane_Scatterplot; + final JTabbedPane tabbedPane_Statistics; + + public TagPileupOutput(Vector be, Vector ba, PileupParameters param) { + setTitle("Tag Pileup Composite"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 800, 600); + + layeredPane = new JLayeredPane(); + getContentPane().add(layeredPane, BorderLayout.CENTER); + SpringLayout sl_layeredPane = new SpringLayout(); + layeredPane.setLayout(sl_layeredPane); + + tabbedPane = new JTabbedPane(JTabbedPane.TOP); + sl_layeredPane.putConstraint(SpringLayout.NORTH, tabbedPane, 6, SpringLayout.NORTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.WEST, tabbedPane, 6, SpringLayout.WEST, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.SOUTH, tabbedPane, -6, SpringLayout.SOUTH, layeredPane); + sl_layeredPane.putConstraint(SpringLayout.EAST, tabbedPane, -6, SpringLayout.EAST, layeredPane); + layeredPane.add(tabbedPane); + + tabbedPane_Scatterplot = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("Pileup Plot", null, tabbedPane_Scatterplot, null); + + tabbedPane_Statistics = new JTabbedPane(JTabbedPane.TOP); + tabbedPane.addTab("Pileup Statistics", null, tabbedPane_Statistics, null); + + BEDFiles = be; + BAMFiles = ba; + PARAM = param; +// STRAND = param.getStrand(); +// CPU = param.getCPU(); + + } + + public void run() throws IOException { + if(PARAM.getOutputCompositeStatus()) { + try { COMPOSITE = new PrintStream(PARAM.getOutput() + File.separator + PARAM.getCompositeFile()); + } catch (FileNotFoundException e) { e.printStackTrace(); } + } + + //Check if BAI index file exists for all BAM files + boolean[] BAMvalid = new boolean[BAMFiles.size()]; + for(int z = 0; z < BAMFiles.size(); z++) { + File BAM = BAMFiles.get(z); //Pull current BAM file + File f = new File(BAM + ".bai"); //Generate file name for BAI index file + if(!f.exists() || f.isDirectory()) { + BAMvalid[z] = false; + JOptionPane.showMessageDialog(null, "BAI Index File does not exist for: " + BAM.getName()); + System.err.println("BAI Index File does not exist for: " + BAM.getName()); + } else { BAMvalid[z] = true; } + } + + int PROGRESS = 0; + for(int z = 0; z < BAMFiles.size(); z++) { + File BAM = BAMFiles.get(z); //Pull current BAM file + if(BAMvalid[z]) { + //Code to standardize tags sequenced to genome size (1 tag / 1 bp) + if(PARAM.getStandard() && PARAM.getBlacklist() != null) { PARAM.setRatio(BAMUtilities.calculateStandardizationRatio(BAM, PARAM.getBlacklist(), PARAM.getRead())); } + else if(PARAM.getStandard()) { PARAM.setRatio(BAMUtilities.calculateStandardizationRatio(BAM, PARAM.getRead())); } + //System.out.println(PARAM.getRatio()); + + for(int BED_Index = 0; BED_Index < BEDFiles.size(); BED_Index++) { + System.err.println("Processing BAM: " + BAM.getName() + "\tCoordinate: " + BEDFiles.get(BED_Index).getName()); + + JTextArea STATS = new JTextArea(); //Generate statistics object + STATS.setEditable(false); //Make it un-editable + PrintStream ps = new PrintStream(new CustomOutputStream(STATS)); + + //Here we add script object: 1BAM x 1BED + System.err.println("make script object..."); + TagPileup script_obj = new TagPileup(BEDFiles.get(BED_Index), BAM, PARAM, ps, null, true); + script_obj.run(); + System.err.println("script object made..."); + + tabbedPane_Scatterplot.add(BAM.getName(), script_obj.getCompositePlot()); + + STATS.setCaretPosition(0); + JScrollPane newpane = new JScrollPane(STATS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + tabbedPane_Statistics.add(BAM.getName(), newpane); + firePropertyChange("tag", PROGRESS, PROGRESS + 1); + PROGRESS++; + } + } + } + } + +} diff --git a/src/window_interface/Read_Analysis/TagPileupWindow.java b/src/window_interface/Read_Analysis/TagPileupWindow.java index eead53bb2..c909b2c3f 100644 --- a/src/window_interface/Read_Analysis/TagPileupWindow.java +++ b/src/window_interface/Read_Analysis/TagPileupWindow.java @@ -39,7 +39,7 @@ import objects.PileupParameters; import util.FileSelection; -import scripts.Read_Analysis.TagPileup; +import window_interface.Read_Analysis.TagPileupOutput; @SuppressWarnings("serial") public class TagPileupWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -168,7 +168,7 @@ public Void doInBackground() throws IOException, InterruptedException { else { param.setOutput(OUTPUT); } param.setOutputCompositeStatus(chckbxOutputCompositeData.isSelected()); //Outputs composite plots if check box is selected - if(chckbxOutputCompositeData.isSelected()) { param.setCompositeFile(txtCompositeName.getText()); } + if(chckbxOutputCompositeData.isSelected()) { param.setCompositeFile(OUTPUT + File.separator + txtCompositeName.getText()); } if(chckbxOutputData.isSelected()) { if(rdbtnTabdelimited.isSelected()) { param.setOutputType(1); } @@ -192,7 +192,7 @@ else if(rdbtnCdt.isSelected()) { param.setStdNum(Integer.parseInt(txtNumStd.getText())); param.setCPU(Integer.parseInt(txtCPU.getText())); - TagPileup pile = new TagPileup(BEDFiles, BAMFiles, param); + TagPileupOutput pile = new TagPileupOutput(BEDFiles, BAMFiles, param); pile.addPropertyChangeListener("tag", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From 0292fe10ecac73b5772b4fed504a1b6a8a396bd7 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 22:24:08 -0400 Subject: [PATCH 29/43] create MD5Checksum command line version This tool did not implement JFrame elements in the script class so with no adjustments to so the script or window classes, this tool was straightforward in implementing a CLI version. cli/* -call appropriate script class -write up picocli parsing objects -skipped validateInput() method for this tool. --- src/cli/File_Utilities/MD5ChecksumCLI.java | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/cli/File_Utilities/MD5ChecksumCLI.java b/src/cli/File_Utilities/MD5ChecksumCLI.java index 7d35b2acc..10137f9b5 100644 --- a/src/cli/File_Utilities/MD5ChecksumCLI.java +++ b/src/cli/File_Utilities/MD5ChecksumCLI.java @@ -16,7 +16,7 @@ import java.util.Date; import objects.ToolDescriptions; -//import scripts.File_Utilities.MD5Checksum; +import scripts.File_Utilities.MD5Checksum; /** File_UtilitiesCLI/MD5ChecksumCLI @@ -27,26 +27,18 @@ exitCodeOnExecutionException = 1) public class MD5ChecksumCLI implements Callable { + @Parameters( index = "0", description = "The file we want to calculate the MD5checksum for. Alternatively use md5 or md5checksum ") + private File input; + + @Option(names = {"-o", "--output"}, description = "specify output filepath") + private File output = new File("md5checksum.txt"); + @Override public Integer call() throws Exception { - System.err.println( ">MD5ChecksumCLI.call()" ); - String validate = validateInput(); - if(!validate.equals("")){ - System.err.println( validate ); - System.err.println("Invalid input. Check usage using '-h' or '--help'"); - System.exit(1); - } - - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); + String md5hash = MD5Checksum.calculateMD5(input.getAbsolutePath()); + PrintStream OUT = new PrintStream( output ); + OUT.println("MD5 (" + input.getName() + ") = " + md5hash); return(0); } - - private String validateInput() throws IOException { - String r = ""; - //validate input here - //append messages to the user to `r` - return(r); - } } + From 1fa1918a9948d8c4b7b4aad0c7667325a9d467f4 Mon Sep 17 00:00:00 2001 From: owlang Date: Sun, 20 Sep 2020 23:50:56 -0400 Subject: [PATCH 30/43] create FourColor 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/*/ FourColorPlotOutput class. As a result, only the cli/* file was affected. The script is a public static void method so super easy to implement. cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../FourColorSequenceCLI.java | 94 ++++++++++++++++++- 1 file changed, 89 insertions(+), 5 deletions(-) diff --git a/src/cli/Figure_Generation/FourColorSequenceCLI.java b/src/cli/Figure_Generation/FourColorSequenceCLI.java index ff538d82d..7ef37173f 100644 --- a/src/cli/Figure_Generation/FourColorSequenceCLI.java +++ b/src/cli/Figure_Generation/FourColorSequenceCLI.java @@ -17,7 +17,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Figure_Generation.FourColorPlot; +import scripts.Figure_Generation.FourColorPlot; /** Figure_GenerationCLI/FourColorSequenceCLI @@ -29,6 +29,18 @@ exitCodeOnExecutionException = 1) public class FourColorSequenceCLI implements Callable { + @Parameters( index = "0", description = "input FASTA file of sequences to plot") + private File fastaFile; + + @Option(names = {"-o", "--output"}, description = "specify output filename, please use PNG extension\n(default=FASTA filename with \"_4color.png\" appended to the name in working directory of ScriptManager") + private File output = null; + @Option(names = {"-c", "--colors"}, arity = "4..5", description = "For custom colors: List colors to use for ATGC[N], in that order. Type hexadecimal string to represent colors, e.g. FF0000 is hexadecimal for red.\n(default=A-red,T-green,G-yellow,C-blue,N-gray, if only 4 colors specified, N will be set to gray)\n See for some color options with their corresponding hex strings.") + private ArrayList colors = null; + @Option(names = {"-x", "--pixel-width"}, description = "pixel width (default=1)") + private int pixelWidth = 1; + @Option(names = {"-y", "--pixel-height"}, description = "pixel height (default=1)") + private int pixelHeight = 1; + @Override public Integer call() throws Exception { System.err.println( ">FourColorSequenceCLI.call()" ); @@ -38,17 +50,89 @@ public Integer call() throws Exception { System.err.println("Invalid input. Check usage using '-h' or '--help'"); System.exit(1); } + // Add colors into ArrayList + ArrayList ATCG_COLORS = new ArrayList(5); + if( colors!=null ){ + System.err.println("size:"+ Integer.toString(ATCG_COLORS.size())); + for( int c=0; c Date: Mon, 21 Sep 2020 00:03:16 -0400 Subject: [PATCH 31/43] create HeatMap command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/HeatMapOutput class while the calculations are kept in the src/scripts/*/HeatMapPlot class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Figure_Generation/HeatMapCLI.java | 112 +++++++++++++++++- .../Figure_Generation/HeatmapPlot.java | 100 +++++++--------- .../Figure_Generation/HeatMapOutput.java | 93 +++++++++++++++ .../Figure_Generation/HeatMapWindow.java | 4 +- 4 files changed, 245 insertions(+), 64 deletions(-) create mode 100644 src/window_interface/Figure_Generation/HeatMapOutput.java diff --git a/src/cli/Figure_Generation/HeatMapCLI.java b/src/cli/Figure_Generation/HeatMapCLI.java index d52527cbd..3e6e5c3ee 100644 --- a/src/cli/Figure_Generation/HeatMapCLI.java +++ b/src/cli/Figure_Generation/HeatMapCLI.java @@ -17,7 +17,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Figure_Generation.HeatmapPlot; +import scripts.Figure_Generation.HeatmapPlot; /** Figure_GenerationCLI/HeatMapCLI @@ -29,6 +29,42 @@ exitCodeOnExecutionException = 1) public class HeatMapCLI implements Callable { + @Parameters( index = "0", description = "") + private File CDT; + + @Option(names = {"-o", "--output"}, description = "specify output filename, please use PNG extension\n(default=CDT filename with \"_.png\" appended to the name in working directory of ScriptManager") + private File output = null; + @Option(names = {"-r", "--start-row"}, description = "") + private int startROW = 1; + @Option(names = {"-l", "--start-col"}, description = "") + private int startCOL = 2; + @Option(names = {"-x", "--width"}, description = "indicate a pixel width for the heatmap (default=200)") + private int pixelWidth = 200; + @Option(names = {"-y", "--height"}, description = "indicate a pixel height for the heatmap (default=600)") + private int pixelHeight = 600; + @Option(names = {"-z", "--compression"}, description = "choose an image compression type: 1=Treeview, 2=Bicubic, 3=Bilinear, 4=Nearest Neighbor (default=1Treeview)") + private int compression = 1; + @Option(names = {"-a", "--absolute-threshold"}, description = "use the specified value for contrast thresholding in the heatmap (default=10)") + private int absolute = -999; + @Option(names = {"-p", "--percentile-threshold"}, description = "use the specified percentile value for contrast thresholding in the heatmap (try .95 if unsure)") + private double percentile = -999; + + @ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect heatmap color:%n\t@|fg(red) (select no more than one of these options)|@%n") + private ColorGroup color = new ColorGroup(); + static class ColorGroup{ + @Option(names = {"--black"}, description = "Use the color black for generating the heatmap (default)") + private boolean black = false; + @Option(names = {"--red"}, description = "Use the color red for generating the heatmap") + private boolean red = false; + @Option(names = {"--blue"}, description = "Use the color blue for generating the heatmap") + private boolean blue = false; + @Option(names = {"-c", "--color"}, description = "For custom color: type hexadecimal string to represent colors (e.g. \"FF0000\" is hexadecimal for red).\n See for some color options with their corresponding hex strings.\n") + private String custom = null; + } + + String scaleType = "treeview"; + Color MAXCOLOR = Color.BLACK; + @Override public Integer call() throws Exception { System.err.println( ">HeatMapCLI.call()" ); @@ -39,16 +75,82 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + // Generate Heatmap + HeatmapPlot script_object = new HeatmapPlot( CDT, MAXCOLOR, startROW, startCOL, pixelHeight, pixelWidth, scaleType, absolute, percentile, output, true ); + script_object.run(); - //System.err.println("Calculations Complete"); + System.err.println("Image Generated."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + // Assign a scaleType based on "compression" input + if(compression==2){ scaleType = "bicubic"; } + else if(compression==3){ scaleType = "bilinear"; } + else if(compression==4){ scaleType = "neighbor"; } + + //check inputs exist + if(!CDT.exists()){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + // check compression is a valid input value + if( compression<1 || compression>4 ){ + r += "(!)Compression must be integer 1-4. Please select from the available compression types."; + } + //check that hex string is formatted properly + if(color.custom != null){ + Pattern hexColorPat = Pattern.compile("[0-9A-Fa-f]{6}"); + Matcher m = hexColorPat.matcher( color.custom ); + if(!m.matches()){ + r += "(!)Color must be formatted as a hexidecimal String!\n\tExpected input string format: \"[0-9A-Fa-f]{6}\""; + } + } + //check scaling is valid input + if( absolute==-999 && percentile==-999 ){ + absolute = 10; + } + //check pixel ranges are valid + if(pixelHeight<=0){ r += "(!)Cell height must be a positive integer value! check \"-y\" flag.\""; } + if(pixelWidth<=0) { r += "(!)Cell width must be a positive integer value! check \"-x\" flag.\""; } + //check start row/col are valid + /* */ + + + // Assign a color from the -c, --red, --blue, and --black inputs + if(color.red){ MAXCOLOR = Color.RED; } + else if(color.blue){ MAXCOLOR = Color.BLUE; } + else if(color.custom!=null){ + System.err.println("Decoding color: 0x" + color.custom); + MAXCOLOR = Color.decode("0x"+color.custom); + } + return(r); } } diff --git a/src/scripts/Figure_Generation/HeatmapPlot.java b/src/scripts/Figure_Generation/HeatmapPlot.java index f5ad836c8..fbf8addd4 100644 --- a/src/scripts/Figure_Generation/HeatmapPlot.java +++ b/src/scripts/Figure_Generation/HeatmapPlot.java @@ -21,15 +21,12 @@ import javax.imageio.ImageIO; import javax.swing.ImageIcon; -import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; @SuppressWarnings("serial") -public class HeatmapPlot extends JFrame { +public class HeatmapPlot { - protected static ArrayList SAMPLE = null; + protected static File SAMPLE = null; protected static int startROW = 1; protected static int startCOL = 2; @@ -44,21 +41,15 @@ public class HeatmapPlot extends JFrame { public static Color MAXCOLOR = new Color(255, 0, 0); protected static boolean OUTPUTSTATUS = false; - protected static File OUTPUTPATH = null; + protected static File OUTFILE = null; protected static String FILEID = null; private static ArrayList MATRIX = null; - public static double COLOR_RATIO = 1; + public static double COLOR_RATIO = 1; - JTabbedPane newpane; - - public HeatmapPlot(ArrayList in, Color c, int startR, int startC, int pHeight, int pWidth, String scale, double abs, double quant, File OUT, boolean outstatus) { - setTitle("Heatmap"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - newpane = new JTabbedPane(JTabbedPane.TOP); - this.getContentPane().add(newpane); + private JLabel picLabel = null; + + public HeatmapPlot(File in, Color c, int startR, int startC, int pHeight, int pWidth, String scale, double abs, double quant, File output, boolean outstatus) { SAMPLE = in; MAXCOLOR = c; @@ -71,53 +62,44 @@ public HeatmapPlot(ArrayList in, Color c, int startR, int startC, int pHei absolute = abs; quantile = quant; - OUTPUTPATH = OUT; + OUTFILE = output; OUTPUTSTATUS = outstatus; } - public void run() throws IOException { - for(int x = 0; x < SAMPLE.size(); x++) { - JLabel picLabel = null; - - String FILEID = SAMPLE.get(x).getName().split("\\.")[0]; - String OUTPUT = FILEID; - if(OUTPUTPATH != null) { OUTPUT = OUTPUTPATH.getCanonicalPath() + File.separator + FILEID; } + public void run() throws IOException { + + String FILEID = SAMPLE.getName().split("\\.")[0]; - System.out.println("Loading Matrix file: " + FILEID); - MATRIX = loadMatrix(SAMPLE.get(x)); - System.out.println("Matrix file loaded."); - System.out.println("Rows detected: " + MATRIX.size()); - System.out.println("Columns detected: " + MATRIX.get(0).length); + System.out.println("Loading Matrix file: " + FILEID); + MATRIX = loadMatrix(SAMPLE); + System.out.println("Matrix file loaded."); + System.out.println("Rows detected: " + MATRIX.size()); + System.out.println("Columns detected: " + MATRIX.get(0).length); + + if(scaleType.equalsIgnoreCase("treeview")) { + ArrayList newMatrix = rebinMatrix(MATRIX); + if(absolute != -999) { COLOR_RATIO = absolute; } + else { COLOR_RATIO = getQuantile(newMatrix, quantile); } - if(scaleType.equalsIgnoreCase("treeview")) { - ArrayList newMatrix = rebinMatrix(MATRIX); - if(absolute != -999) { COLOR_RATIO = absolute; } - else { COLOR_RATIO = getQuantile(newMatrix, quantile); } - - System.out.println("Contrast threshold: " + COLOR_RATIO); - BufferedImage treeMap = generateHeatMap(newMatrix); - picLabel = new JLabel(new ImageIcon(treeMap)); - //Don't output PNG if OUTPUTSTATUS is false, which is the flag for not outputing figures - if(OUTPUTSTATUS) { ImageIO.write(treeMap, "png", new File(OUTPUT + "_" + scaleType + ".png")); } - } else if(!scaleType.equalsIgnoreCase("treeview")) { - //COLOR_RATIO = 2 * getNonZeroAvg(MATRIX); - if(absolute != -999) { COLOR_RATIO = absolute; } - else { COLOR_RATIO = getQuantile(MATRIX, quantile); } - System.out.println("Contrast threshold: " + COLOR_RATIO); - - BufferedImage rawMap = generateHeatMap(MATRIX); - BufferedImage compressedMap = resize(rawMap, pixelWidth, pixelHeight); - picLabel = new JLabel(new ImageIcon(compressedMap)); - - //Don't output PNG if OUTPUTSTATUS is false, which is the flag for not outputing figures - if(OUTPUTSTATUS) { ImageIO.write(compressedMap, "png", new File(OUTPUT + "_" + scaleType + ".png")); } - } - //Output image/error to GUI - newpane.addTab(FILEID, new JScrollPane(picLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); - firePropertyChange("heat", x, x + 1); + System.out.println("Contrast threshold: " + COLOR_RATIO); + BufferedImage treeMap = generateHeatMap(newMatrix); + picLabel = new JLabel(new ImageIcon(treeMap)); + //Don't output PNG if OUTPUTSTATUS is false, which is the flag for not outputing figures + if(OUTPUTSTATUS) { ImageIO.write(treeMap, "png", OUTFILE); } + } else if(!scaleType.equalsIgnoreCase("treeview")) { + //COLOR_RATIO = 2 * getNonZeroAvg(MATRIX); + if(absolute != -999) { COLOR_RATIO = absolute; } + else { COLOR_RATIO = getQuantile(MATRIX, quantile); } + System.out.println("Contrast threshold: " + COLOR_RATIO); + + BufferedImage rawMap = generateHeatMap(MATRIX); + BufferedImage compressedMap = resize(rawMap, pixelWidth, pixelHeight); + picLabel = new JLabel(new ImageIcon(compressedMap)); + + //Don't output PNG if OUTPUTSTATUS is false, which is the flag for not outputing figures + if(OUTPUTSTATUS) { ImageIO.write(compressedMap, "png", OUTFILE); } } - System.out.println("Program Complete"); - System.out.println(getTimeStamp()); + } public static BufferedImage generateHeatMap(ArrayList matrix) throws FileNotFoundException { @@ -374,6 +356,10 @@ public static ArrayList loadMatrix(File input) throws UnsupportedEncod return matrix; } + public JLabel getImg(){ + return(picLabel); + } + private static String getTimeStamp() { Date date = new Date(); String time = new Timestamp(date.getTime()).toString(); diff --git a/src/window_interface/Figure_Generation/HeatMapOutput.java b/src/window_interface/Figure_Generation/HeatMapOutput.java new file mode 100644 index 000000000..7c6c6192d --- /dev/null +++ b/src/window_interface/Figure_Generation/HeatMapOutput.java @@ -0,0 +1,93 @@ +package window_interface.Figure_Generation; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Date; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; + +import scripts.Figure_Generation.HeatmapPlot; + +@SuppressWarnings("serial") +public class HeatMapOutput extends JFrame { + + protected static ArrayList SAMPLE = null; + + protected static int startROW = 1; + protected static int startCOL = 2; + protected static int pixelHeight = 600; + protected static int pixelWidth = 200; + + protected static String scaleType = "treeview"; + protected static double quantile = 0.9; + protected static double absolute = -999; + + public static Color MINCOLOR = new Color(255, 255, 255); + public static Color MAXCOLOR = new Color(255, 0, 0); + + protected static boolean OUTPUTSTATUS = false; + protected static File OUTPUTPATH = null; + protected static String FILEID = null; + + private static ArrayList MATRIX = null; + public static double COLOR_RATIO = 1; + + JTabbedPane newpane; + + public HeatMapOutput(ArrayList in, Color c, int startR, int startC, int pHeight, int pWidth, String scale, double abs, double quant, File OUT, boolean outstatus) { + setTitle("Heatmap"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + newpane = new JTabbedPane(JTabbedPane.TOP); + this.getContentPane().add(newpane); + + SAMPLE = in; + MAXCOLOR = c; + startROW = startR; + startCOL = startC; + pixelHeight = pHeight; + pixelWidth = pWidth; + scaleType = scale; + + absolute = abs; + quantile = quant; + + OUTPUTPATH = OUT; + OUTPUTSTATUS = outstatus; + System.out.println(OUTPUTSTATUS); + } + + public void run() throws IOException { + for(int x = 0; x < SAMPLE.size(); x++) { + + String FILEID = SAMPLE.get(x).getName().split("\\.")[0] + "_" + scaleType + ".png"; + String OUTPUT = FILEID; + if(OUTPUTPATH != null) { OUTPUT = OUTPUTPATH.getCanonicalPath() + File.separator + FILEID; } + + //Execute script + HeatmapPlot script_object = new HeatmapPlot(SAMPLE.get(x), MAXCOLOR, startROW, startCOL, pixelHeight, pixelWidth, scaleType, absolute, quantile, new File(OUTPUT), OUTPUTSTATUS ); + script_object.run(); + JLabel picLabel = script_object.getImg(); + + //Output image/error to GUI + newpane.addTab(FILEID, new JScrollPane(picLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + firePropertyChange("heat", x, x + 1); + } + System.out.println("Program Complete"); + System.out.println(getTimeStamp()); + } + + private static String getTimeStamp() { + Date date = new Date(); + String time = new Timestamp(date.getTime()).toString(); + return time; + } + +} diff --git a/src/window_interface/Figure_Generation/HeatMapWindow.java b/src/window_interface/Figure_Generation/HeatMapWindow.java index 4ee51103c..f090bd917 100644 --- a/src/window_interface/Figure_Generation/HeatMapWindow.java +++ b/src/window_interface/Figure_Generation/HeatMapWindow.java @@ -38,7 +38,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Figure_Generation.HeatmapPlot; +import window_interface.Figure_Generation.HeatMapOutput; @SuppressWarnings("serial") public class HeatMapWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -105,7 +105,7 @@ public Void doInBackground() throws IOException { double quantile = Double.parseDouble(txtPercent.getText()); //System.out.println(COLOR + "\n" + startR+ "\n" + startC+ "\n" + pHeight+ "\n" + pWidth+ "\n" + scaletype+ "\n" + absolute+ "\n" + quantile+ "\n" + OUTPUTPATH); - HeatmapPlot heat = new HeatmapPlot(txtFiles, COLOR, startR, startC, pHeight, pWidth, scaletype, absolute, quantile, OUTPUTPATH, chckbxOutputHeatmap.isSelected()); + HeatMapOutput heat = new HeatMapOutput(txtFiles, COLOR, startR, startC, pHeight, pWidth, scaletype, absolute, quantile, OUTPUTPATH, chckbxOutputHeatmap.isSelected()); heat.addPropertyChangeListener("heat", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From 1faa4fb94f41d8c7d53640830a24ae73c00d24ce Mon Sep 17 00:00:00 2001 From: owlang Date: Mon, 21 Sep 2020 00:20:32 -0400 Subject: [PATCH 32/43] create MergeHeatMap command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/MergeHeatMapOutput class while the calculations are kept in the src/scripts/*/MergeHeatMap class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Figure_Generation/MergeHeatMapCLI.java | 58 ++++++++++++-- .../Figure_Generation/MergeHeatMapPlot.java | 57 +------------- .../Figure_Generation/MergeHeatMapOutput.java | 77 +++++++++++++++++++ .../Figure_Generation/MergeHeatMapWindow.java | 4 +- 4 files changed, 134 insertions(+), 62 deletions(-) create mode 100644 src/window_interface/Figure_Generation/MergeHeatMapOutput.java diff --git a/src/cli/Figure_Generation/MergeHeatMapCLI.java b/src/cli/Figure_Generation/MergeHeatMapCLI.java index 95aa0c080..04baef008 100644 --- a/src/cli/Figure_Generation/MergeHeatMapCLI.java +++ b/src/cli/Figure_Generation/MergeHeatMapCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Figure_Generation.MergeHeatMapPlot; +import scripts.Figure_Generation.MergeHeatMapPlot; /** Figure_GenerationCLI/MergeHeatMapCLI @@ -24,6 +24,14 @@ exitCodeOnExecutionException = 1) public class MergeHeatMapCLI implements Callable { + @Parameters( index = "0", description = "First(sense) PNG heatmap to merge, input1") + private File senseFile; + @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=\"_merged.png\" appended to the name in working directory of ScriptManager") + private File output = null; + @Override public Integer call() throws Exception { System.err.println( ">MergeHeatMapCLI.call()" ); @@ -34,16 +42,52 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); + // Generate Merged HeatMap + MergeHeatMapPlot.mergePNG( senseFile, antiFile, output ); + + System.err.println("Image Generated."); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!senseFile.exists()){ + r += "(!)INPUT1 file does not exist: " + senseFile.getName() + "\n"; + } + if(!antiFile.exists()){ + r += "(!)INPUT2 file does not exist: " + antiFile.getName() + "\n"; + } + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} + +} \ No newline at end of file diff --git a/src/scripts/Figure_Generation/MergeHeatMapPlot.java b/src/scripts/Figure_Generation/MergeHeatMapPlot.java index 61f9d82d2..02ccd171a 100644 --- a/src/scripts/Figure_Generation/MergeHeatMapPlot.java +++ b/src/scripts/Figure_Generation/MergeHeatMapPlot.java @@ -4,64 +4,16 @@ import javax.imageio.ImageIO; import javax.swing.ImageIcon; -import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; import java.io.File; import java.io.IOException; import java.util.ArrayList; @SuppressWarnings("serial") -public class MergeHeatMapPlot extends JFrame { - private ArrayList pngFiles = null; - private ArrayList senseFile = null; - private ArrayList antiFile = null; - private File OUTPUT_PATH = null; +public class MergeHeatMapPlot { - JTabbedPane newpane; - - public MergeHeatMapPlot(ArrayList in, File out) { - setTitle("Merged Heatmap"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - newpane = new JTabbedPane(JTabbedPane.TOP); - this.getContentPane().add(newpane); - - pngFiles = in; - OUTPUT_PATH = out; - } - - public void run() throws IOException { - senseFile = new ArrayList(); - antiFile = new ArrayList(); - for(int x = 0; x < pngFiles.size(); x++) { - if(pngFiles.get(x).getName().toLowerCase().contains("sense")) { - senseFile.add(pngFiles.get(x)); - } else if(pngFiles.get(x).getName().toLowerCase().contains("anti")) { - antiFile.add(pngFiles.get(x)); - } - } - - for(int x = 0; x < senseFile.size(); x++) { - String name = senseFile.get(x).getName(); - String out = name.substring(0, name.lastIndexOf("sense")); - int matchIndex = -999; - for(int y = 0; y < antiFile.size(); y++) { - if(antiFile.get(y).getName().contains(out)) { matchIndex = y; } - } - out = out + "merge.png"; - if(OUTPUT_PATH != null) { out = OUTPUT_PATH.getCanonicalPath() + File.separator + out; } - - if(matchIndex != -999) { mergePNG(senseFile.get(x), antiFile.get(matchIndex), new File(out)); } - else { mergePNG(senseFile.get(x), null, new File(out)); } - firePropertyChange("merge", x, x + 1); - } - } - - public void mergePNG(File INPUT1, File INPUT2, File OUTPUT) throws IOException { + public static JLabel mergePNG(File INPUT1, File INPUT2, File OUTPUT) throws IOException { JLabel picLabel = null; if(INPUT2 == null) { picLabel = new JLabel("No match for file: " + INPUT1.getName()); @@ -108,11 +60,10 @@ public void mergePNG(File INPUT1, File INPUT2, File OUTPUT) throws IOException { } } //Output new image - ImageIO.write(combined, "PNG", OUTPUT); + if(OUTPUT!=null){ ImageIO.write(combined, "PNG", OUTPUT); } picLabel = new JLabel(new ImageIcon(combined)); } } - //Output image/error to GUI - newpane.addTab(OUTPUT.getName(), new JScrollPane(picLabel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + return(picLabel); } } \ No newline at end of file diff --git a/src/window_interface/Figure_Generation/MergeHeatMapOutput.java b/src/window_interface/Figure_Generation/MergeHeatMapOutput.java new file mode 100644 index 000000000..d9c5f8e73 --- /dev/null +++ b/src/window_interface/Figure_Generation/MergeHeatMapOutput.java @@ -0,0 +1,77 @@ +package window_interface.Figure_Generation; + +// import java.awt.image.BufferedImage; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import scripts.Figure_Generation.MergeHeatMapPlot; + +@SuppressWarnings("serial") +public class MergeHeatMapOutput extends JFrame { + private ArrayList pngFiles = null; + private ArrayList senseFile = null; + private ArrayList antiFile = null; + private File OUTPUT_PATH = null; + + JTabbedPane newpane; + + public MergeHeatMapOutput(ArrayList in, File out) { + setTitle("Merged Heatmap"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + newpane = new JTabbedPane(JTabbedPane.TOP); + this.getContentPane().add(newpane); + + pngFiles = in; + OUTPUT_PATH = out; + } + + public void run() throws IOException { + senseFile = new ArrayList(); + antiFile = new ArrayList(); + for(int x = 0; x < pngFiles.size(); x++) { + if(pngFiles.get(x).getName().toLowerCase().contains("sense")) { + senseFile.add(pngFiles.get(x)); + } else if(pngFiles.get(x).getName().toLowerCase().contains("anti")) { + antiFile.add(pngFiles.get(x)); + } + } + + for(int x = 0; x < senseFile.size(); x++) { + String name = senseFile.get(x).getName(); + String out = name.substring(0, name.lastIndexOf("sense")); + int matchIndex = -999; + for(int y = 0; y < antiFile.size(); y++) { + if(antiFile.get(y).getName().contains(out)) { matchIndex = y; } + } + out = out + "merge.png"; + if(OUTPUT_PATH != null) { out = OUTPUT_PATH.getCanonicalPath() + File.separator + out; } + + //Store results in JFrame window + File OUT = new File(out); + if(matchIndex != -999) { + //Execute script + JLabel pic = MergeHeatMapPlot.mergePNG( senseFile.get(x), antiFile.get(matchIndex), OUT ); + addImage(OUT.getName(), pic ); + } + else { + JLabel pic = MergeHeatMapPlot.mergePNG(senseFile.get(x), null, OUT); + addImage(OUT.getName(), pic); + } + firePropertyChange("merge", x, x + 1); + } + } + + private void addImage( String name, JLabel pic ){ + newpane.addTab( name , new JScrollPane(pic, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); + } + +} \ No newline at end of file diff --git a/src/window_interface/Figure_Generation/MergeHeatMapWindow.java b/src/window_interface/Figure_Generation/MergeHeatMapWindow.java index 64d5f59a5..f3790c719 100644 --- a/src/window_interface/Figure_Generation/MergeHeatMapWindow.java +++ b/src/window_interface/Figure_Generation/MergeHeatMapWindow.java @@ -28,7 +28,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Figure_Generation.MergeHeatMapPlot; +import window_interface.Figure_Generation.MergeHeatMapOutput; @SuppressWarnings("serial") public class MergeHeatMapWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -57,7 +57,7 @@ public Void doInBackground() throws IOException { OUTPUTPATH = new File(System.getProperty("user.dir")); } - MergeHeatMapPlot heat = new MergeHeatMapPlot(pngFiles, OUTPUTPATH); + MergeHeatMapOutput heat = new MergeHeatMapOutput(pngFiles, OUTPUTPATH); heat.addPropertyChangeListener("merge", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent propertyChangeEvent) { From 99a74c88605aa2b6d86fb03767b98a21a564374c Mon Sep 17 00:00:00 2001 From: owlang Date: Mon, 21 Sep 2020 00:42:32 -0400 Subject: [PATCH 33/43] create CompositePlot command line tool This tool is unlike the others in that there is no GUI version. It's a straightforward tool to plot the composite output of TagPileup that uses the existing chart/CompositePlot class as the script object. Because the GUI version outputs a composite plot, I created this to retain that functionality so that when this tool is used with the CLI TagPileup, it can do the same things as the GUI version. cli/Figure_Generation/ -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user charts/CompositePlot -createCompositePlot() method updated to reduce redundancy -createChart(3params) was made public so that this tool could take advantage of it, instead of just being an internal helper method -createChart(4params) was updated to optionally include a legend (CLI makes it an optional user-specified value) --- src/charts/CompositePlot.java | 25 +-- .../Figure_Generation/CompositePlotCLI.java | 188 +++++++++++++++++- 2 files changed, 191 insertions(+), 22 deletions(-) diff --git a/src/charts/CompositePlot.java b/src/charts/CompositePlot.java index 7360ee4b3..2c54d4624 100644 --- a/src/charts/CompositePlot.java +++ b/src/charts/CompositePlot.java @@ -55,29 +55,23 @@ public static Component createCompositePlot(double[] x, double[] y1, String name } public static Component createCompositePlot(double[] x, double[] y1, String name){ - final XYSeriesCollection dataset = new XYSeriesCollection(); - final XYSeries seriesC = new XYSeries("Data"); - for(int i = 0; i < x.length; i++) { - seriesC.add(x[i], y1[i]); - } - dataset.addSeries(seriesC); - ArrayList COLORS = new ArrayList(); COLORS.add(Color.BLACK); - final JFreeChart chart = createChart(dataset, name, COLORS); - final ChartPanel chartPanel = new ChartPanel(chart); - chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); - return chartPanel; + return(createCompositePlot(x, y1, name, COLORS)); } - private static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList COLORS) { + public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList COLORS) { + return(createChart(dataset, TITLE, COLORS, true)); + } + + public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList COLORS, boolean legend) { //Call Chart final JFreeChart chart = ChartFactory.createXYLineChart( TITLE, // chart title "Distance from Feature (bp)", // x axis label "Score", // y axis label dataset, // data - PlotOrientation.VERTICAL, true, // include legend + PlotOrientation.VERTICAL, legend, // include legend true, // tooltips false // urls ); @@ -93,9 +87,10 @@ private static JFreeChart createChart(final XYDataset dataset, String TITLE, Arr renderer.setSeriesLinesVisible(x, true); //Spline visibility renderer.setSeriesShapesVisible(x, false); //Data point dot visibility renderer.setSeriesStroke(x, new BasicStroke(3)); + renderer.setSeriesPaint(x, COLORS.get(x)); } - renderer.setSeriesPaint(0, COLORS.get(0)); - if(COLORS.size() == 2) { renderer.setSeriesPaint(1, COLORS.get(1)); } +// renderer.setSeriesPaint(0, COLORS.get(0)); +// if(COLORS.size() == 2) { renderer.setSeriesPaint(1, COLORS.get(1)); } plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... diff --git a/src/cli/Figure_Generation/CompositePlotCLI.java b/src/cli/Figure_Generation/CompositePlotCLI.java index 163bae025..ace724c9c 100644 --- a/src/cli/Figure_Generation/CompositePlotCLI.java +++ b/src/cli/Figure_Generation/CompositePlotCLI.java @@ -27,7 +27,7 @@ import charts.CompositePlot; import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Figure_Generation.MergeHeatMapPlot; +import scripts.Figure_Generation.MergeHeatMapPlot; /** Figure_GenerationCLI/CompositePlotCLI @@ -39,6 +39,56 @@ exitCodeOnExecutionException = 1) public class CompositePlotCLI implements Callable { + @Parameters( index = "0", description = "Composite data to plot. (formatted like TagPileup composite output)") + private File compositeData; + + @Option(names = {"-o", "--output"}, description = "specify output filename, please use PNG extension\n(default=Input filename with \"_compositePlot.png\" appended to the name in working directory of ScriptManager") + private File output = null; + @Option(names = {"-t", "--title"}, description = "set title (default=)") + private String title = null; + @Option(names = {"-l", "--legend"}, description = "add a legend (default=no legend)") + private boolean legend = false; + @Option(names = {"-x", "--width"}, description = "indicate a pixel width for the plot (default=500)") + private int pixelWidth = 500; + @Option(names = {"-y", "--height"}, description = "indicate a pixel height for the plot (default=270)") + private int pixelHeight = 270; + @Option(names = {"-c", "--custom-colors"}, description = "indicate colors to use for each series. Must indicate a number of colors that matches number of dataseries\n" + + "default behavior:\n" + + "if one series input, use black\n" + + "if two series input, use blue(sense) and red(anti)\n" + + "if greater than two series, cycle through a set of 20 preset colors.", + arity="1..") + private String[] colors = null; + + XYSeriesCollection xydata = null; + private ArrayList COLORS = new ArrayList(); + + //Colors copied from response on StackOverflow: + // https://stackoverflow.com/questions/470690/how-to-automatically-generate-n-distinct-colors + String[] KELLY_COLORS_HEX = { + "0xFFB300", // Vivid Yellow + "0x803E75", // Strong Purple + "0xFF6800", // Vivid Orange + "0xA6BDD7", // Very Light Blue + "0xC10020", // Vivid Red + "0xCEA262", // Grayish Yellow + "0x817066", // Medium Gray + // The following don't work well for people with defective color vision + "0x007D34", // Vivid Green + "0xF6768E", // Strong Purplish Pink + "0x00538A", // Strong Blue + "0xFF7A5C", // Strong Yellowish Pink + "0x53377A", // Strong Violet + "0xFF8E00", // Vivid Orange Yellow + "0xB32851", // Strong Purplish Red + "0xF4C800", // Vivid Greenish Yellow + "0x7F180D", // Strong Reddish Brown + "0x93AA00", // Vivid Yellowish Green + "0x593315", // Deep Yellowish Brown + "0xF13A13", // Vivid Reddish Orange + "0x232C16", // Dark Olive Green + }; + @Override public Integer call() throws Exception { System.err.println( ">CompositePlotCLI.call()" ); @@ -49,16 +99,140 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); - - //System.err.println("Calculations Complete"); + // Generate Composite Plot + JFreeChart chart = CompositePlot.createChart(xydata, title, COLORS, legend); + // Save Composite Plot + OutputStream OUT = new FileOutputStream(output); + ChartUtilities.writeChartAsPNG(OUT, chart, pixelWidth, pixelHeight); + + System.err.println( "Image Generated." ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!compositeData.exists()){ + r += "(!)Composite Data file does not exist: " + compositeData.getName() + "\n"; + return(r); + } + //check input extensions + if(!"out".equals(ExtensionFileFilter.getExtension(compositeData))){ + r += "(!)Is this a \".out\" file? Check extension: " + compositeData.getName() + "\n"; + } + //set default output filename + if(output==null){ + output = new File(ExtensionFileFilter.stripExtension(compositeData) + "_compositePlot.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: " + ExtensionFileFilter.stripExtension(output) + ".png\n"; } + //check directory + if(output.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //set default title name + if(title!=null){ title = compositeData.getName(); } + //check pixel ranges are valid + if(pixelHeight<=0){ r += "(!)Cell height must be a positive integer value! check \"-y\" flag.\""; } + if(pixelWidth<=0) { r += "(!)Cell width must be a positive integer value! check \"-x\" flag.\""; } + + // Parse Datafile + try{ + xydata = parseData(); + if(xydata==null){ r += "(!)The number of y-values don't match the number of x-values"; } + } catch (FileNotFoundException e) { e.printStackTrace(); } + + // Set Color + if(colors==null){ //set defaults based on number of dataseries (n=1 -> black, n=2 -> blue,red, n=3 -> cycle through kelly colors) + if(xydata.getSeriesCount()==1){ + //set color to black default unless otherwise indicated + COLORS.add(Color.BLACK); + } else if(xydata.getSeriesCount()==2){ + //set colors to blue and red default unless otherwise indicated + COLORS.add(Color.BLUE); + COLORS.add(Color.RED); + } else if(xydata.getSeriesCount()>2){ + //assign a diverse set of colors (as many as there are series) + for(int i=0; i Date: Mon, 21 Sep 2020 10:17:25 -0400 Subject: [PATCH 34/43] create BEDPeakAligntoRef command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/BEDPeakAligntoRefOutput class while the calculations are kept in the src/scripts/*/BEDPeakAligntoRef class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Peak_Analysis/BEDPeakAligntoRefCLI.java | 54 +++++++++++-- .../Peak_Analysis/BEDPeakAligntoRef.java | 75 +++++++------------ .../BEDPeakAligntoRefOutput.java | 55 ++++++++++++++ .../BEDPeakAligntoRefWindow.java | 15 ++-- 4 files changed, 135 insertions(+), 64 deletions(-) create mode 100644 src/window_interface/Peak_Analysis/BEDPeakAligntoRefOutput.java diff --git a/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java b/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java index 9fd78c20b..f641984ac 100644 --- a/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java +++ b/src/cli/Peak_Analysis/BEDPeakAligntoRefCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Peak_Analysis.BEDPeakAligntoRef; +import scripts.Peak_Analysis.BEDPeakAligntoRef; /** Peak_AnalysisCLI/BEDPeakAligntoRefCLI @@ -24,6 +24,14 @@ exitCodeOnExecutionException = 1) public class BEDPeakAligntoRefCLI implements Callable { + @Parameters( index = "0", description = "The BED peak file") + private File peakBED; + @Parameters( index = "1", description = "The BED reference file") + private File refBED = null; + + @Option(names = {"-o", "--output"}, description = "Specify output file (default = __Output.cdt)") + private File output = null; + @Override public Integer call() throws Exception { System.err.println( ">BEDPeakAligntoRefCLI.call()" ); @@ -34,16 +42,50 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BEDPeakAligntoRef script_obj = new BEDPeakAligntoRef(refBED, peakBED, output, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println( "Peak Align Complete." ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!peakBED.exists()){ + r += "(!)BED-peak file does not exist: " + peakBED.getName() + "\n"; + } + if(!refBED.exists()){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Peak_Analysis/BEDPeakAligntoRef.java b/src/scripts/Peak_Analysis/BEDPeakAligntoRef.java index 3ed4fcfa0..501d36504 100644 --- a/src/scripts/Peak_Analysis/BEDPeakAligntoRef.java +++ b/src/scripts/Peak_Analysis/BEDPeakAligntoRef.java @@ -1,6 +1,5 @@ package scripts.Peak_Analysis; -import java.util.List; -import java.awt.BorderLayout; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -13,52 +12,30 @@ import java.util.ArrayList; import java.util.Date; -import java.util.Map; import java.util.HashMap; - -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; +import java.util.List; +import java.util.Map; @SuppressWarnings("serial") -public class BEDPeakAligntoRef extends JFrame{ - private String peakPath = null; - private String refPath = null; - private File OUTPUTPATH = null; - private PrintStream OUT = null; - - private JTextArea textArea; - - public BEDPeakAligntoRef(File ref, File peak, File o_path) throws IOException { - setTitle("BED Align to Reference Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - +public class BEDPeakAligntoRef { + private String peakPath = null; + private String refPath = null; + private File OUTFILE = null; + private PrintStream OUT = null; + private PrintStream PS = null; + + public BEDPeakAligntoRef(File ref, File peak, File output, PrintStream ps) throws IOException { refPath = ref.getCanonicalPath(); peakPath = peak.getCanonicalPath(); - OUTPUTPATH = o_path; - if(OUTPUTPATH != null) { - try {OUT = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + peak.getName().split("\\.")[0] + "_" + ref.getName().split("\\.")[0] + "_Output.cdt")); } - - catch (FileNotFoundException e) { e.printStackTrace(); } - } else { - try {OUT = new PrintStream(new File(peak.getName().split("\\.")[0] + "_" + ref.getName().split("\\.")[0] + "_Output.cdt"));} - catch (FileNotFoundException e) { e.printStackTrace(); } - } + PS = ps; + + try {OUT = new PrintStream(output); } + catch (FileNotFoundException e) { e.printStackTrace(); } } public void run() throws IOException, InterruptedException { - System.out.println("Mapping: " + peakPath + " to " + refPath); - System.out.println("Starting: " + getTimeStamp()); - textArea.append("Mapping: " + peakPath + " to " + refPath + "\n"); - textArea.append("Starting: " + getTimeStamp() + "\n"); + printPS("Mapping: " + peakPath + " to " + refPath); + printPS("Starting: " + getTimeStamp()); int counter = 0; InputStream inputStream = new FileInputStream(peakPath); @@ -126,25 +103,23 @@ else if(Integer.parseInt(peakLine[2]) >= Integer.parseInt(str[1]) && Integer.par counter++; if(counter % 1000 == 0) { - System.out.println("Reference rows processed: " + counter); - textArea.append("Reference rows processed: " + counter + "\n"); + printPS("Reference rows processed: " + counter); } } buff.close(); inputStream.close(); - System.out.println("Completing: " + getTimeStamp()); - textArea.append("Completing: " + getTimeStamp() + "\n"); - //System.out.println(counter); - - Thread.sleep(2000); - dispose(); - + + printPS("Completing: " + getTimeStamp()); } private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); return time; - } } + private void printPS(String message){ + if(PS!=null) PS.println(message); + System.err.println(message); + } +} \ No newline at end of file diff --git a/src/window_interface/Peak_Analysis/BEDPeakAligntoRefOutput.java b/src/window_interface/Peak_Analysis/BEDPeakAligntoRefOutput.java new file mode 100644 index 000000000..0c1f62f8d --- /dev/null +++ b/src/window_interface/Peak_Analysis/BEDPeakAligntoRefOutput.java @@ -0,0 +1,55 @@ +package window_interface.Peak_Analysis; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.Peak_Analysis.BEDPeakAligntoRef; + +@SuppressWarnings("serial") +public class BEDPeakAligntoRefOutput extends JFrame{ + private File PEAK = null; + private File REF = null; + private File OUTFILE = null; + private PrintStream OUT = null; + + private JTextArea textArea; + + public BEDPeakAligntoRefOutput(File ref, File peak, File outpath) throws IOException { + setTitle("BED Align to Reference Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + REF = ref; + PEAK = peak; + + if(outpath != null) { + OUTFILE = new File(outpath.getCanonicalPath() + File.separator + PEAK.getName().split("\\.")[0] + "_" + REF.getName().split("\\.")[0] + "_Output.cdt"); + } else { + OUTFILE = new File(PEAK.getName().split("\\.")[0] + "_" + REF.getName().split("\\.")[0] + "_Output.cdt"); + } + } + + public void run() throws IOException, InterruptedException { + + PrintStream PS = new PrintStream(new CustomOutputStream(textArea)); + BEDPeakAligntoRef script_obj = new BEDPeakAligntoRef(REF, PEAK, OUTFILE, PS); + script_obj.run(); + + Thread.sleep(2000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/Peak_Analysis/BEDPeakAligntoRefWindow.java b/src/window_interface/Peak_Analysis/BEDPeakAligntoRefWindow.java index a45eb1a07..1d8005e86 100644 --- a/src/window_interface/Peak_Analysis/BEDPeakAligntoRefWindow.java +++ b/src/window_interface/Peak_Analysis/BEDPeakAligntoRefWindow.java @@ -28,7 +28,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Peak_Analysis.BEDPeakAligntoRef; +import window_interface.Peak_Analysis.BEDPeakAligntoRefOutput; @SuppressWarnings("serial") public class BEDPeakAligntoRefWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -52,7 +52,7 @@ public class BEDPeakAligntoRefWindow extends JFrame implements ActionListener, P private JLabel lblDefaultToLocal; private JProgressBar progressBar; -public Task task; + public Task task; class Task extends SwingWorker { @Override @@ -62,23 +62,22 @@ public Void doInBackground() throws IOException, InterruptedException { JOptionPane.showMessageDialog(null, "No BED Files Loaded!!!"); } else { setProgress(0); - BEDPeakAligntoRef align; + BEDPeakAligntoRefOutput align; int counter = 0; for(int r = 0; r < RefFiles.size(); r++) { for(int p=0; p < PeakFiles.size(); p++) { - align = new BEDPeakAligntoRef(RefFiles.get(r), PeakFiles.get(p), OUTPUT_PATH); - align.setVisible(true); - align.run(); - counter++; + align = new BEDPeakAligntoRefOutput(RefFiles.get(r), PeakFiles.get(p), OUTPUT_PATH); + align.setVisible(true); + align.run(); + counter++; int percentComplete = (int)(((double)(counter) / (PeakFiles.size()*RefFiles.size())) * 100); setProgress(percentComplete); } } JOptionPane.showMessageDialog(null, "Alignment Complete"); - } } catch(NumberFormatException nfe){ JOptionPane.showMessageDialog(null, "Invalid Input in Fields!!!"); From b0a813f24c097f356427aa3a396b39fdced7b687 Mon Sep 17 00:00:00 2001 From: owlang Date: Mon, 21 Sep 2020 10:38:37 -0400 Subject: [PATCH 35/43] create FilterBEDbyProximity command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/ FilterBEDbyProximityOutput class while the calculations are kept in the src/scripts/*/FilterBEDbyProximity class. window_interface/*Window -adjust import to call *Output class window_interface/*Output -adjust import to call script class -adjust output argument when initializing script class to be full filename and not just directory script/* -strip out JFrame objects -use output as filename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../FilterBEDbyProximityCLI.java | 50 ++++++- .../Peak_Analysis/FilterBEDbyProximity.java | 122 +++++++----------- .../FilterBEDbyProximityOutput.java | 58 +++++++++ .../FilterBEDbyProximityWindow.java | 6 +- 4 files changed, 150 insertions(+), 86 deletions(-) create mode 100644 src/window_interface/Peak_Analysis/FilterBEDbyProximityOutput.java diff --git a/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java b/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java index cf5a2c1a0..878e23c11 100644 --- a/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java +++ b/src/cli/Peak_Analysis/FilterBEDbyProximityCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Peak_Analysis.FilterBEDbyProximity; +import scripts.Peak_Analysis.FilterBEDbyProximity; /** Peak_AnalysisCLI/FilterBEDbyProximityCLI @@ -24,6 +24,14 @@ exitCodeOnExecutionException = 1) public class FilterBEDbyProximityCLI implements Callable { + @Parameters( index = "0", description = "The BED file we are filtering on") + private File bedFile; + + @Option(names = {"-o", "--output"}, description = "Specify basename for output files (default = _bp)") + private String outputBasename = null; + @Option(names = {"-e", "--exclusion"}, description = "exclusion distance in bp (default=100)") + private int exclusion = 100; + @Override public Integer call() throws Exception { System.err.println( ">FilterBEDbyProximityCLI.call()" ); @@ -34,16 +42,46 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + FilterBEDbyProximity script_obj = new FilterBEDbyProximity(bedFile, exclusion, outputBasename, null); + script_obj.run(); - //System.err.println("Calculations Complete"); + System.err.println( "Filter Complete." ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bedFile.exists()){ + 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){ + // System.err.println("default to current directory"); + } else if(!new File(tmpOut.getParent()).exists()){ + r += "(!)Check output directory exists: " + tmpOut.getParent() + "\n"; + } + } + + //check exclusion + if(exclusion<0){ + r += "(!)Exclusion size needs to be a positive integer.\n"; + } + return(r); - } + + } } diff --git a/src/scripts/Peak_Analysis/FilterBEDbyProximity.java b/src/scripts/Peak_Analysis/FilterBEDbyProximity.java index 1ed83b24c..908c1dd79 100644 --- a/src/scripts/Peak_Analysis/FilterBEDbyProximity.java +++ b/src/scripts/Peak_Analysis/FilterBEDbyProximity.java @@ -1,6 +1,5 @@ package scripts.Peak_Analysis; -import java.awt.BorderLayout; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -14,77 +13,43 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; import objects.CoordinateObjects.BEDCoord; - @SuppressWarnings({"serial"}) -public class FilterBEDbyProximity extends JFrame{ +public class FilterBEDbyProximity{ private int CUTOFF; private InputStream inputStream; - private File OUTPUTPATH = null; - private String INPUTFILE = null; + private String INPUTNAME = null; private PrintStream OUT_Filter = null; private PrintStream OUT_Cluster = null; + private PrintStream PS = null; - private JTextArea textArea; - - public FilterBEDbyProximity(File input, int cutoff, File output) throws IOException { - setTitle("BED File Filter Progress"); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setBounds(150, 150, 600, 800); - - JScrollPane scrollPane = new JScrollPane(); - getContentPane().add(scrollPane, BorderLayout.CENTER); - - textArea = new JTextArea(); - textArea.setEditable(false); - scrollPane.setViewportView(textArea); - + public FilterBEDbyProximity(File input, int cutoff, String outputBase, PrintStream ps) throws IOException { CUTOFF = cutoff; + PS = ps; inputStream = new FileInputStream(input); - INPUTFILE = input.getName(); - - OUTPUTPATH = output; - String fname_f = INPUTFILE.substring(0, input.getName().lastIndexOf('.')) + "_" + Integer.toString(CUTOFF) + "bp-FILTER" + ".bed"; - String fname_c = INPUTFILE.substring(0, input.getName().lastIndexOf('.')) + "_" + Integer.toString(CUTOFF) + "bp-CLUSTER" + ".bed"; - - if(OUTPUTPATH != null) - { - try - { - OUT_Filter = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + fname_f)); - OUT_Cluster = new PrintStream(new File(OUTPUTPATH.getCanonicalPath() + File.separator + fname_c)); - - } - catch (FileNotFoundException e) { e.printStackTrace(); }} - else - { - try - { - OUT_Filter = new PrintStream(new File(fname_f)); - OUT_Cluster = new PrintStream(new File(fname_c)); + INPUTNAME = input.getName(); + try{ + if(outputBase == null) { + outputBase = INPUTNAME.substring(0, input.getName().lastIndexOf('.')) + "_" + Integer.toString(CUTOFF) + "bp"; } - catch (FileNotFoundException e) { e.printStackTrace(); } - } + OUT_Filter = new PrintStream(new File(outputBase + "-FILTER" + ".bed")); + OUT_Cluster = new PrintStream(new File(outputBase + "-CLUSTER" + ".bed")); + }catch (FileNotFoundException e) { e.printStackTrace(); } } public void run() throws IOException, InterruptedException { - System.out.println("Filtering BED file with a cutoff: " + CUTOFF + " in " + INPUTFILE); - System.out.println("Starting: " + getTimeStamp()); - textArea.append("Filtering BED file with a cutoff: " + CUTOFF + " in " + INPUTFILE + "\n"); - textArea.append("Starting: " + getTimeStamp() + "\n"); - + printPS("Filtering BED file with a cutoff: " + CUTOFF + " in " + INPUTNAME); + printPS("Starting: " + getTimeStamp()); BufferedReader lines = new BufferedReader(new InputStreamReader(inputStream), 100); List bedArray = new ArrayList(); List failArray = new ArrayList(); - + + //load bed coords into bedArray String line; while((line = lines.readLine()) != null) { bedArray.add(new BEDCoord(line)); @@ -94,7 +59,9 @@ public void run() throws IOException, InterruptedException Collections.sort(bedArray, BEDCoord.PeakMidpointComparator); Collections.sort(bedArray, BEDCoord.PeakChromComparator); + //Check each coord pair for proximity for(int i = 0; i < bedArray.size(); i++) { + //check coords behind int INDEX = i - 1; if(INDEX >= 0) { while((bedArray.get(i).getChrom().equals(bedArray.get(INDEX).getChrom())) && (Math.abs(bedArray.get(i).getMid() - bedArray.get(INDEX).getMid()) <= CUTOFF)) @@ -102,7 +69,7 @@ public void run() throws IOException, InterruptedException if(bedArray.get(i).getScore() > bedArray.get(INDEX).getScore()) { failArray.set(INDEX, new Integer(1)); - } + } else if((bedArray.get(i).getScore() == bedArray.get(INDEX).getScore()) && (bedArray.get(INDEX).getMid() > bedArray.get(i).getMid())) { failArray.set(INDEX, new Integer(1)); @@ -111,31 +78,33 @@ else if((bedArray.get(i).getScore() == bedArray.get(INDEX).getScore()) && (bedAr failArray.set(i, new Integer(1)); } INDEX--; - if(INDEX < 0) { break; } + if(INDEX < 0) { break; } // To avoid redundant pair-wise checks } } + //check coords in front INDEX = i + 1; if(INDEX < bedArray.size()) { while((bedArray.get(i).getChrom().equals(bedArray.get(INDEX).getChrom())) && (Math.abs(bedArray.get(i).getMid() - bedArray.get(INDEX).getMid()) <= CUTOFF)) { - if(bedArray.get(i).getScore() > bedArray.get(INDEX).getScore()) - { - failArray.set(INDEX, new Integer(1)); - } - else if((bedArray.get(i).getScore() == bedArray.get(INDEX).getScore()) && (bedArray.get(INDEX).getMid() > bedArray.get(i).getMid())) - { - failArray.set(INDEX, new Integer(1)); - } - else - { - failArray.set(i, new Integer(1)); - } - INDEX++; - if(INDEX == bedArray.size()) {break; } + + if(bedArray.get(i).getScore() > bedArray.get(INDEX).getScore()) + { + failArray.set(INDEX, new Integer(1)); + } + else if((bedArray.get(i).getScore() == bedArray.get(INDEX).getScore()) && (bedArray.get(INDEX).getMid() > bedArray.get(i).getMid())) + { + failArray.set(INDEX, new Integer(1)); + } + else + { + failArray.set(i, new Integer(1)); + } + INDEX++; + if(INDEX == bedArray.size()){ break; } // To avoid redundant pair-wise checks } } - } - + } + //print bed coords to respective files based on fail array for(int x = 0; x < bedArray.size(); x++) { if(failArray.get(x).intValue() == 0) { OUT_Filter.println(bedArray.get(x).toString()); @@ -145,20 +114,19 @@ else if((bedArray.get(i).getScore() == bedArray.get(INDEX).getScore()) && (bedAr } OUT_Filter.close(); OUT_Cluster.close(); - - inputStream.close(); - System.out.println("Completing: " + getTimeStamp()); - textArea.append("Completing: " + getTimeStamp() + "\n"); - Thread.sleep(1000); - dispose(); + inputStream.close(); + printPS("Completing: " + getTimeStamp()); } - private static String getTimeStamp() { Date date= new Date(); String time = new Timestamp(date.getTime()).toString(); return time; } - + + private void printPS(String message){ + if(PS!=null) PS.println(message); + System.err.println(message); + } } \ No newline at end of file diff --git a/src/window_interface/Peak_Analysis/FilterBEDbyProximityOutput.java b/src/window_interface/Peak_Analysis/FilterBEDbyProximityOutput.java new file mode 100644 index 000000000..b231702cd --- /dev/null +++ b/src/window_interface/Peak_Analysis/FilterBEDbyProximityOutput.java @@ -0,0 +1,58 @@ +package window_interface.Peak_Analysis; + +import java.awt.BorderLayout; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintStream; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +import objects.CustomOutputStream; +import scripts.Peak_Analysis.FilterBEDbyProximity; + +@SuppressWarnings({"serial"}) +public class FilterBEDbyProximityOutput extends JFrame{ + + private int CUTOFF; + private File INPUT; + private String OUTBASE = null; + + private JTextArea textArea; + + public FilterBEDbyProximityOutput(File input, int cutoff, File output) throws IOException { + setTitle("BED File Filter Progress"); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(150, 150, 600, 800); + + JScrollPane scrollPane = new JScrollPane(); + getContentPane().add(scrollPane, BorderLayout.CENTER); + + textArea = new JTextArea(); + textArea.setEditable(false); + scrollPane.setViewportView(textArea); + + CUTOFF = cutoff; + INPUT = input; + + String INPUTNAME = input.getName(); + if(output!=null){ + OUTBASE = output.getCanonicalPath() + File.separator + INPUTNAME.substring(0, INPUTNAME.lastIndexOf('.')) + "_" + Integer.toString(CUTOFF) + "bp"; + }else{ + OUTBASE = INPUTNAME.substring(0, INPUTNAME.lastIndexOf('.')) + "_" + Integer.toString(CUTOFF) + "bp"; + } + } + + public void run() throws IOException, InterruptedException + { + PrintStream PS = new PrintStream(new CustomOutputStream(textArea)); + + FilterBEDbyProximity script_obj = new FilterBEDbyProximity(INPUT, CUTOFF, OUTBASE, PS); + script_obj.run(); + + Thread.sleep(1000); + dispose(); + } +} \ No newline at end of file diff --git a/src/window_interface/Peak_Analysis/FilterBEDbyProximityWindow.java b/src/window_interface/Peak_Analysis/FilterBEDbyProximityWindow.java index b72becaf7..3526b38ea 100644 --- a/src/window_interface/Peak_Analysis/FilterBEDbyProximityWindow.java +++ b/src/window_interface/Peak_Analysis/FilterBEDbyProximityWindow.java @@ -29,7 +29,7 @@ import javax.swing.border.EmptyBorder; import util.FileSelection; -import scripts.Peak_Analysis.FilterBEDbyProximity; +import window_interface.Peak_Analysis.FilterBEDbyProximityOutput; @SuppressWarnings("serial") public class FilterBEDbyProximityWindow extends JFrame implements ActionListener, PropertyChangeListener { @@ -59,9 +59,9 @@ public Void doInBackground() throws IOException, InterruptedException { JOptionPane.showMessageDialog(null, "Invalid Cutoff Value Entered!!!"); } else { setProgress(0); - FilterBEDbyProximity filter; + FilterBEDbyProximityOutput filter; for(int gfile = 0; gfile < BEDFiles.size(); gfile++) { - filter = new FilterBEDbyProximity(BEDFiles.get(gfile), Integer.parseInt(txtCutoff.getText()), OUTPUT_PATH); + filter = new FilterBEDbyProximityOutput(BEDFiles.get(gfile), Integer.parseInt(txtCutoff.getText()), OUTPUT_PATH); filter.setVisible(true); filter.run(); int percentComplete = (int)(((double)(gfile + 1) / (BEDFiles.size())) * 100); From 4e287993abb5c289ed24d5cf52a6333ccbb77e0c Mon Sep 17 00:00:00 2001 From: owlang Date: Mon, 21 Sep 2020 11:38:05 -0400 Subject: [PATCH 36/43] create RandomCoordinate 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/*/ RandomCoordinateOutput class. As a result, no need to create an Output window class so fewer edits to be made: 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 cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- .../Peak_Analysis/RandomCoordinateCLI.java | 60 +++++++++++++++++-- .../Peak_Analysis/RandomCoordinate.java | 2 +- .../Peak_Analysis/RandomCoordinateWindow.java | 12 +++- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/cli/Peak_Analysis/RandomCoordinateCLI.java b/src/cli/Peak_Analysis/RandomCoordinateCLI.java index c97b01d21..4b6d8f754 100644 --- a/src/cli/Peak_Analysis/RandomCoordinateCLI.java +++ b/src/cli/Peak_Analysis/RandomCoordinateCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Peak_Analysis.RandomCoordinate; +import scripts.Peak_Analysis.RandomCoordinate; /** Peak_AnalysisCLI/RandomCoordinateCLI @@ -24,6 +24,18 @@ exitCodeOnExecutionException = 1) public class RandomCoordinateCLI implements Callable { + @Parameters( index = "0", description = "reference genome [sacCer3_cegr|hg19|hg19_contigs|mm10]") + private String genomeName; + + @Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be random_coordinates__bp.") + private File output = null; + @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)") + private int numSites = 1000; + @Option(names = {"-w", "--window"}, description = "window size in bp (default=200)") + private int window = 200; + @Override public Integer call() throws Exception { System.err.println( ">RandomCoordinateCLI.call()" ); @@ -34,16 +46,52 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + RandomCoordinate script_obj = new RandomCoordinate(genomeName, numSites, window, formatIsBed, output); + script_obj.execute(); - //System.err.println("Calculations Complete"); + System.err.println( "Random Coordinate Generation Complete." ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check input genomes are valid + if(genomeName.equals("sacCer3_cegr") || genomeName.equals("hg19") || genomeName.equals("hg19_contigs") || genomeName.equals("mm10") ){ +// System.err.println("Input genomeName is valid"); + }else{ + r += "(!)Invalid genomeName selected(" +genomeName+ "), please select from one of the provided genomes: sacCer3_cegr, hg19, hg19_contigs, and mm10\n"; + } + String ext = "gff"; + if(formatIsBed){ ext = "bed"; } + //set default output filename + if(output==null){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //check number of sites + if( numSites<1 ){ + r += "(!)Number of sites needs to be a positive integer.\n"; + } + //check window size + if( window<1 ){ + r += "(!)Window size needs to be a positive integer.\n"; + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Peak_Analysis/RandomCoordinate.java b/src/scripts/Peak_Analysis/RandomCoordinate.java index 55380e004..dcc38f9b3 100644 --- a/src/scripts/Peak_Analysis/RandomCoordinate.java +++ b/src/scripts/Peak_Analysis/RandomCoordinate.java @@ -39,7 +39,7 @@ public void execute() throws IOException { String randomName = GENOME + "_" + numSites + "SITES_" + windowSize + "bp" + EXTENSION; PrintStream OUT = null; if(OUTPUT == null) OUT = new PrintStream(randomName); - else OUT = new PrintStream(OUTPUT + File.separator + randomName); + else OUT = new PrintStream(OUTPUT); for(int x = 0; x < numSites; x++) { GenericCoord temp = coord.generateRandomCoord(windowSize); if(BEDout) { diff --git a/src/window_interface/Peak_Analysis/RandomCoordinateWindow.java b/src/window_interface/Peak_Analysis/RandomCoordinateWindow.java index 7302d5011..99074980b 100644 --- a/src/window_interface/Peak_Analysis/RandomCoordinateWindow.java +++ b/src/window_interface/Peak_Analysis/RandomCoordinateWindow.java @@ -58,7 +58,17 @@ public Void doInBackground() throws IOException, InterruptedException { } else if(Integer.parseInt(txtSize.getText()) < 1) { JOptionPane.showMessageDialog(null, "Invalid Window Size Entered!!!"); } else { - RandomCoordinate generate = new RandomCoordinate((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSites.getText()), Integer.parseInt(txtSize.getText()), rdbtnBed.isSelected(), OUTPUT_PATH); + boolean bedStatus = rdbtnBed.isSelected(); + String randomName = (String)cmbGenome.getSelectedItem() + "_" + Integer.parseInt(txtSites.getText()) + "SITES_" + Integer.parseInt(txtSize.getText()) + "bp"; + if(bedStatus){ randomName += ".bed"; } + else{ randomName += ".gff"; } + File OUTFILE; + if(OUTPUT_PATH != null){ + OUTFILE = new File(OUTPUT_PATH + File.separator + randomName); + }else{ + OUTFILE = new File(randomName); + } + RandomCoordinate generate = new RandomCoordinate((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSites.getText()), Integer.parseInt(txtSize.getText()), bedStatus, OUTFILE); generate.execute(); JOptionPane.showMessageDialog(null, "Random Coordinate Generation Complete"); } From 932a3bf6f22fe48d102da471fa7523ab1b4b16fe Mon Sep 17 00:00:00 2001 From: owlang Date: Tue, 22 Sep 2020 17:51:03 -0400 Subject: [PATCH 37/43] create TileGenome 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/*/ TileGenomeOutput class. As a result, just the following 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 cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user --- src/cli/Peak_Analysis/TileGenomeCLI.java | 52 +++++++++++++++++-- src/scripts/Peak_Analysis/TileGenome.java | 4 +- .../Peak_Analysis/TileGenomeWindow.java | 12 ++++- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/cli/Peak_Analysis/TileGenomeCLI.java b/src/cli/Peak_Analysis/TileGenomeCLI.java index 881d66da1..01ba5f27a 100644 --- a/src/cli/Peak_Analysis/TileGenomeCLI.java +++ b/src/cli/Peak_Analysis/TileGenomeCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Peak_Analysis.TileGenome; +import scripts.Peak_Analysis.TileGenome; /** Peak_AnalysisCLI/TileGenomeCLI @@ -24,6 +24,16 @@ exitCodeOnExecutionException = 1) public class TileGenomeCLI implements Callable { + @Parameters( index = "0", description = "reference genome [sacCer3_cegr|hg19|hg19_contigs|mm10]") + private String genomeName; + + @Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be genome_tiles__bp.") + private File output = null; + @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)") + private int window = 200; + @Override public Integer call() throws Exception { System.err.println( ">TileGenomeCLI.call()" ); @@ -34,16 +44,48 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + TileGenome script_obj = new TileGenome(genomeName, window, formatIsBed, output); + script_obj.execute(); - //System.err.println("Calculations Complete"); + System.err.println( "Genomic Tiling Complete." ); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check input genomes are valid + if(genomeName.equals("sacCer3_cegr") || genomeName.equals("hg19") || genomeName.equals("hg19_contigs") || genomeName.equals("mm10") ){ +// System.err.println("Input genome is valid"); + }else{ + r += "(!)Invalid genomeName selected(" +genomeName+ "), please select from one of the provided genomes: sacCer3_cegr, hg19, hg19_contigs, and mm10\n"; + } + String ext = "gff"; + if(formatIsBed){ ext = "bed"; } + //set default output filename + if(output==null){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + + //check window size + if( window<1 ){ + r += "(!)Window size needs to be a positive integer.\n"; + } + return(r); } } diff --git a/src/scripts/Peak_Analysis/TileGenome.java b/src/scripts/Peak_Analysis/TileGenome.java index 2f70bf943..86d723ea8 100644 --- a/src/scripts/Peak_Analysis/TileGenome.java +++ b/src/scripts/Peak_Analysis/TileGenome.java @@ -29,8 +29,8 @@ public void execute() throws IOException { String fileName = GENOME + "_" + windowSize + "bp" + EXTENSION; PrintStream OUT = null; - if(OUTPUT == null) OUT = new PrintStream(fileName); - else OUT = new PrintStream(OUTPUT + File.separator + fileName); + if(OUTPUT == null) OUT = new PrintStream(new File(fileName)); + else OUT = new PrintStream(OUTPUT); for(int x = 0; x < coord.getChrom().size(); x++) { String CHROM = coord.getChrom().get(x); diff --git a/src/window_interface/Peak_Analysis/TileGenomeWindow.java b/src/window_interface/Peak_Analysis/TileGenomeWindow.java index 9c99d67da..55a41c3ba 100644 --- a/src/window_interface/Peak_Analysis/TileGenomeWindow.java +++ b/src/window_interface/Peak_Analysis/TileGenomeWindow.java @@ -53,7 +53,17 @@ public Void doInBackground() throws IOException, InterruptedException { } else if(Integer.parseInt(txtSize.getText()) < 1) { JOptionPane.showMessageDialog(null, "Invalid Window Size Entered!!!"); } else { - TileGenome generate = new TileGenome((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSize.getText()), rdbtnBed.isSelected(), OUTPUT_PATH); + boolean bedStatus = rdbtnBed.isSelected(); + String randomName = (String)cmbGenome.getSelectedItem() + "_" + Integer.parseInt(txtSize.getText()) + "bp"; + if(bedStatus){ randomName += ".bed"; } + else{ randomName += ".gff"; } + File OUTFILE; + if(OUTPUT_PATH != null){ + OUTFILE = new File(OUTPUT_PATH + File.separator + randomName); + }else{ + OUTFILE = new File(randomName); + } + TileGenome generate = new TileGenome((String)cmbGenome.getSelectedItem(), Integer.parseInt(txtSize.getText()), bedStatus, OUTFILE); generate.execute(); JOptionPane.showMessageDialog(null, "Genomic Tiling Complete"); } From 8776b45d1aa71069ce58bd130a67e97ff0c0a4f9 Mon Sep 17 00:00:00 2001 From: owlang Date: Tue, 22 Sep 2020 18:32:39 -0400 Subject: [PATCH 38/43] create ExpandBED 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/*/ ExpandBEDOutput 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 --- .../BED_Manipulation/ExpandBEDCLI.java | 82 +++++++++++++++++-- .../BED_Manipulation/ExpandBED.java | 11 ++- .../BED_Manipulation/ExpandBEDWindow.java | 9 +- 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java b/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java index 2b5ffd282..b1810eafe 100644 --- a/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java +++ b/src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.BED_Manipulation.ExpandBED; +import scripts.Coordinate_Manipulation.BED_Manipulation.ExpandBED; /** Coordinate_ManipulationCLI/ExpandBEDCLI @@ -25,6 +25,26 @@ exitCodeOnExecutionException = 1) public class ExpandBEDCLI implements Callable { + @Parameters( index = "0", description = "the BED file to expand on") + private File bedFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with coordinate info appended)") + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT") + private boolean stdout = false; + + @ArgGroup(validate = false, heading = "%nType of Expansion%n") + ExpandType expandType = new ExpandType(); + static class ExpandType { + @Option(names = {"-c", "--center"}, description = "expand from center (default, at 250bp)") + private int center = -999; + @Option(names = {"-b", "--border"}, description = "add to border") + private int border = -999; + } + + private boolean byCenter = true; + private int SIZE = 250; + @Override public Integer call() throws Exception { System.err.println( ">ExpandBEDCLI.call()" ); @@ -35,16 +55,66 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + ExpandBED.expandBEDBorders(output, bedFile, SIZE, byCenter); - //System.err.println("Calculations Complete"); + System.err.println("Expansion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bedFile.exists()){ + 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"; + } + + // Define default behavior + if(expandType.center==-999 && expandType.border==-999){ + SIZE = 250; + byCenter = true; + }else if(expandType.border==-999){ + SIZE = expandType.center; + byCenter = true; + }else if(expandType.center==-999){ + SIZE = expandType.border; + byCenter = false; + }else{ + r += "(!) Both center and border are flagged. This should have been caught by Picocli."; + } + //check size of expansion is valid + if(SIZE<=0){ + r += "(!) Invalid size input. Must be a positive integer greater than 0."; + } + + //set default output filename + if(output==null && !stdout){ + if(byCenter){ output = new File(ExtensionFileFilter.stripExtension(bedFile) + "_" + Integer.toString(SIZE) + "bp.bed"); } + else{ output = new File(ExtensionFileFilter.stripExtension(bedFile) + "_border_" + Integer.toString(SIZE) + "bp.bed"); } + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Coordinate_Manipulation/BED_Manipulation/ExpandBED.java b/src/scripts/Coordinate_Manipulation/BED_Manipulation/ExpandBED.java index 568df079c..06416b1a5 100644 --- a/src/scripts/Coordinate_Manipulation/BED_Manipulation/ExpandBED.java +++ b/src/scripts/Coordinate_Manipulation/BED_Manipulation/ExpandBED.java @@ -7,12 +7,11 @@ import java.util.Scanner; public class ExpandBED { - public static void expandBEDBorders(File out_path, File input, int SIZE, boolean ExCenter) throws IOException { - String newName = (input.getName()).substring(0,input.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.bed"; - Scanner scan = new Scanner(input); - PrintStream OUT = null; - if(out_path == null) OUT = new PrintStream(newName); - else OUT = new PrintStream(out_path + File.separator + newName); + public static void expandBEDBorders(File out_filepath, File input, int SIZE, boolean ExCenter) throws IOException { + + Scanner scan = new Scanner(input); + PrintStream OUT = System.out; + if( out_filepath != null ) OUT = new PrintStream(out_filepath); while (scan.hasNextLine()) { String[] temp = scan.nextLine().split("\t"); diff --git a/src/window_interface/Coordinate_Manipulation/BED_Manipulation/ExpandBEDWindow.java b/src/window_interface/Coordinate_Manipulation/BED_Manipulation/ExpandBEDWindow.java index f50b5e7dc..8eefb5b55 100644 --- a/src/window_interface/Coordinate_Manipulation/BED_Manipulation/ExpandBEDWindow.java +++ b/src/window_interface/Coordinate_Manipulation/BED_Manipulation/ExpandBEDWindow.java @@ -70,7 +70,14 @@ public Void doInBackground() throws IOException { } else { setProgress(0); for(int x = 0; x < BEDFiles.size(); x++) { - ExpandBED.expandBEDBorders(OUTPUT_PATH, BEDFiles.get(x), SIZE, rdbtnExpandFromCenter.isSelected()); + File XBED = BEDFiles.get(x); + // Set outfilepath + String newName = (XBED.getName()).substring(0,XBED.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.bed"; + File OUT_FILE = null; + if(OUTPUT_PATH == null) OUT_FILE = new File( newName ); + else OUT_FILE = new File( OUTPUT_PATH + File.separator + newName ); + // Execute expansion and update progress + ExpandBED.expandBEDBorders(OUT_FILE, XBED, SIZE, rdbtnExpandFromCenter.isSelected()); int percentComplete = (int)(((double)(x + 1) / BEDFiles.size()) * 100); setProgress(percentComplete); } From dd3fea770d2fb1ab4b6f7d9ffc9ed8488edce6c2 Mon Sep 17 00:00:00 2001 From: owlang Date: Fri, 25 Sep 2020 08:01:21 -0400 Subject: [PATCH 39/43] create ExpandGFF 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/*/ ExpandGFFOutput 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 --- .../GFF_Manipulation/ExpandGFFCLI.java | 82 +++++++++++++++++-- .../GFF_Manipulation/ExpandGFF.java | 12 ++- .../GFF_Manipulation/ExpandGFFWindow.java | 9 +- 3 files changed, 89 insertions(+), 14 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java index e2e0b798d..fe8cec618 100644 --- a/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFCLI.java @@ -13,7 +13,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.GFF_Manipulation.ExpandGFF; +import scripts.Coordinate_Manipulation.GFF_Manipulation.ExpandGFF; /** Coordinate_ManipulationCLI/ExpandGFFCLI @@ -25,6 +25,26 @@ exitCodeOnExecutionException = 1) public class ExpandGFFCLI implements Callable { + @Parameters( index = "0", description = "the GFF file to expand on") + private File gffFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with coordinate info appended)") + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT") + private boolean stdout = false; + + @ArgGroup(validate = false, heading = "%nType of Expansion%n") + ExpandType expandType = new ExpandType(); + static class ExpandType { + @Option(names = {"-c", "--center"}, description = "expand from center (default, at 250bp)") + private int center = -999; + @Option(names = {"-b", "--border"}, description = "add to border") + private int border = -999; + } + + private boolean byCenter = true; + private int SIZE = 250; + @Override public Integer call() throws Exception { System.err.println( ">ExpandGFFCLI.call()" ); @@ -35,16 +55,66 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + ExpandGFF.expandGFFBorders(output, gffFile, SIZE, byCenter); - //System.err.println("Calculations Complete"); + System.err.println("Expansion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!gffFile.exists()){ + r += "(!)GFF file does not exist: " + gffFile.getName() + "\n"; + return(r); + } + //check input extensions + if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){ + r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n"; + } + + // Define default behavior + if(expandType.center==-999 && expandType.border==-999){ + SIZE = 250; + byCenter = true; + }else if(expandType.border==-999){ + SIZE = expandType.center; + byCenter = false; + }else if(expandType.center==-999){ + SIZE = expandType.border; + byCenter = false; + }else{ + r += "(!) Both center and border are flagged. This should have been caught by Picocli."; + } + //check size of expansion is valid + if(SIZE<=0){ + r += "(!) Invalid size input. Must be a positive integer greater than 0."; + } + + //set default output filename + if(output==null && !stdout){ + if(byCenter){ output = new File(ExtensionFileFilter.stripExtension(gffFile) + "_" + Integer.toString(SIZE) + "bp.gff"); } + else{ output = new File(ExtensionFileFilter.stripExtension(gffFile) + "_border_" + Integer.toString(SIZE) + "bp.gff"); } + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Coordinate_Manipulation/GFF_Manipulation/ExpandGFF.java b/src/scripts/Coordinate_Manipulation/GFF_Manipulation/ExpandGFF.java index 67a6dbc59..1cc6b41d7 100644 --- a/src/scripts/Coordinate_Manipulation/GFF_Manipulation/ExpandGFF.java +++ b/src/scripts/Coordinate_Manipulation/GFF_Manipulation/ExpandGFF.java @@ -7,15 +7,13 @@ import java.util.Scanner; public class ExpandGFF { - public static void expandGFFBorders(File out_path, File input, int SIZE, boolean ExCenter) throws IOException { + public static void expandGFFBorders(File out_filepath, File input, int SIZE, boolean ExCenter) throws IOException { //GFF: chr22 TeleGene enhancer 10000000 10001000 500 + . touch1 //GFF: chr12 bed2gff chr12_384641_384659_+ 384642 384659 42.6 + . chr12_384641_384659_+; - - String newName = (input.getName()).substring(0,input.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.gff"; - Scanner scan = new Scanner(input); - PrintStream OUT = null; - if(out_path == null) OUT = new PrintStream(newName); - else OUT = new PrintStream(out_path + File.separator + newName); + + Scanner scan = new Scanner(input); + PrintStream OUT = System.out; + if( out_filepath != null ) OUT = new PrintStream(out_filepath); while (scan.hasNextLine()) { String[] temp = scan.nextLine().split("\t"); diff --git a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFWindow.java b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFWindow.java index a08872db4..cf0775563 100644 --- a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFWindow.java +++ b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/ExpandGFFWindow.java @@ -70,7 +70,14 @@ public Void doInBackground() throws IOException { } else { setProgress(0); for(int x = 0; x < GFFFiles.size(); x++) { - ExpandGFF.expandGFFBorders(OUTPUT_PATH, GFFFiles.get(x), SIZE, rdbtnExpandFromCenter.isSelected()); + File XGFF = GFFFiles.get(x); + // Set outfilepath + String newName = (XGFF.getName()).substring(0,XGFF.getName().length() - 4) + "_" + Integer.toString(SIZE) +"bp.gff"; + File OUT_FILE = null; + if(OUTPUT_PATH == null) OUT_FILE = new File( newName ); + else OUT_FILE = new File( OUTPUT_PATH + File.separator + newName ); + // Execute expansion and update progress + ExpandGFF.expandGFFBorders(OUTPUT_PATH, XGFF, SIZE, rdbtnExpandFromCenter.isSelected()); int percentComplete = (int)(((double)(x + 1) / GFFFiles.size()) * 100); setProgress(percentComplete); } From dbb3200bfd5f805b9fc9245c180421482917285a Mon Sep 17 00:00:00 2001 From: owlang Date: Fri, 25 Sep 2020 08:34:10 -0400 Subject: [PATCH 40/43] create BEDtoGFF 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/*/ BEDtoGFFOutput 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 --- .../BED_Manipulation/BEDtoGFFCLI.java | 48 +++++++++++++++++-- .../BED_Manipulation/BEDtoGFF.java | 11 ++--- .../BED_Manipulation/BEDtoGFFWindow.java | 9 +++- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java b/src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java index 991193855..bfd5207d2 100644 --- a/src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java +++ b/src/cli/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.BED_Manipulation.BEDtoGFF; +import scripts.Coordinate_Manipulation.BED_Manipulation.BEDtoGFF; /** Coordinate_ManipulationCLI/BEDtoGFFCLI @@ -24,6 +24,14 @@ exitCodeOnExecutionException = 1) public class BEDtoGFFCLI implements Callable { + @Parameters( index = "0", description = "the BED file to convert") + private File bedFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .gff ext)") + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "output gff to STDOUT") + private boolean stdout = false; + @Override public Integer call() throws Exception { System.err.println( ">BEDtoGFFCLI.call()" ); @@ -34,16 +42,46 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + BEDtoGFF.convertBEDtoGFF(output, bedFile); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bedFile.exists()){ + 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(output==null && !stdout){ + output = new File(ExtensionFileFilter.stripExtension(bedFile) + ".gff"); + //check stdout and output not both selected + }else if(stdout){ + 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 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 + ".youroutputextensionhere\n"; } + //check directory + if(output.getParent()==null){ + // System.err.println("default to current directory"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } } diff --git a/src/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java b/src/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java index 291629cd4..a5eb4d4d9 100644 --- a/src/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java +++ b/src/scripts/Coordinate_Manipulation/BED_Manipulation/BEDtoGFF.java @@ -7,13 +7,12 @@ import java.util.Scanner; public class BEDtoGFF { - public static void convertBEDtoGFF(File out_path, File input) throws IOException { + public static void convertBEDtoGFF(File out_filepath, File input) throws IOException { //chr22 TeleGene enhancer 10000000 10001000 500 + . touch1 - String gffName = (input.getName()).substring(0,input.getName().length() - 4) + ".gff"; - Scanner scan = new Scanner(input); - PrintStream OUT = null; - if(out_path == null) OUT = new PrintStream(gffName); - else OUT = new PrintStream(out_path + File.separator + gffName); + + Scanner scan = new Scanner(input); + PrintStream OUT = System.out; + if( out_filepath != null ) OUT = new PrintStream(out_filepath); while (scan.hasNextLine()) { String[] temp = scan.nextLine().split("\t"); diff --git a/src/window_interface/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFWindow.java b/src/window_interface/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFWindow.java index 3c3daa54d..c2b3a87c8 100644 --- a/src/window_interface/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFWindow.java +++ b/src/window_interface/Coordinate_Manipulation/BED_Manipulation/BEDtoGFFWindow.java @@ -55,7 +55,14 @@ class Task extends SwingWorker { public Void doInBackground() throws IOException { setProgress(0); for(int x = 0; x < BEDFiles.size(); x++) { - BEDtoGFF.convertBEDtoGFF(OUTPUT_PATH, BEDFiles.get(x)); + File XBED = BEDFiles.get(x); + // Set outfilepath + String gffName = (XBED.getName()).substring(0,XBED.getName().length() - 4) + ".gff"; + File OUT_FILE = null; + if(OUTPUT_PATH == null) OUT_FILE = new File( gffName ); + else OUT_FILE = new File( OUTPUT_PATH + File.separator + gffName ); + // Execute conversion and update progress + BEDtoGFF.convertBEDtoGFF(OUTPUT_PATH, XBED); int percentComplete = (int)(((double)(x + 1) / BEDFiles.size()) * 100); setProgress(percentComplete); } From 23fdab00a24b0ac1cc277b3783d04c1c51196d55 Mon Sep 17 00:00:00 2001 From: owlang Date: Fri, 25 Sep 2020 08:43:27 -0400 Subject: [PATCH 41/43] 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 --- .../GFF_Manipulation/GFFtoBEDCLI.java | 50 ++++++++++++++++--- .../GFF_Manipulation/GFFtoBED.java | 12 ++--- .../GFF_Manipulation/GFFtoBEDWindow.java | 11 +++- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java index 00d7a26d3..b92d72af1 100644 --- a/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDCLI.java @@ -12,7 +12,7 @@ import objects.ToolDescriptions; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.GFF_Manipulation.GFFtoBED; +import scripts.Coordinate_Manipulation.GFF_Manipulation.GFFtoBED; /** Coordinate_ManipulationCLI/GFFtoBEDCLI @@ -24,6 +24,14 @@ exitCodeOnExecutionException = 1) public class GFFtoBEDCLI implements Callable { + @Parameters( index = "0", description = "the GFF file to convert") + private File gffFile; + + @Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .bed ext)") + private File output = null; + @Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT") + private boolean stdout = false; + @Override public Integer call() throws Exception { System.err.println( ">GFFtoBEDCLI.call()" ); @@ -34,16 +42,46 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + GFFtoBED.convertGFFtoBED(output, gffFile); - //System.err.println("Calculations Complete"); + System.err.println("Conversion Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!gffFile.exists()){ + r += "(!)GFF file does not exist: " + gffFile.getName() + "\n"; + return(r); + } + //check input extensions + if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){ + r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n"; + } + //set default output filename + if(output==null && !stdout){ + output = new File(ExtensionFileFilter.stripExtension(gffFile) + ".bed"); + //check stdout and output not both selected + }else if(stdout){ + 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"); + } else if(!new File(output.getParent()).exists()){ + r += "(!)Check output directory exists: " + output.getParent() + "\n"; + } + } + return(r); } -} +} \ No newline at end of file diff --git a/src/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.java b/src/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.java index a224d589c..f41f5667d 100644 --- a/src/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.java +++ b/src/scripts/Coordinate_Manipulation/GFF_Manipulation/GFFtoBED.java @@ -7,15 +7,13 @@ import java.util.Scanner; public class GFFtoBED { - public static void convertBEDtoGFF(File out_path, File input) throws IOException { + public static void convertGFFtoBED(File out_filepath, File input) throws IOException { //GFF: chr22 TeleGene enhancer 10000000 10001000 500 + . touch1 //BED: chr12 605113 605120 region_0 0 + - - String bedName = (input.getName()).substring(0,input.getName().length() - 4) + ".bed"; - Scanner scan = new Scanner(input); - PrintStream OUT = null; - if(out_path == null) OUT = new PrintStream(bedName); - else OUT = new PrintStream(out_path + File.separator + bedName); + + Scanner scan = new Scanner(input); + PrintStream OUT = System.out; + if( out_filepath != null ) OUT = new PrintStream(out_filepath); while (scan.hasNextLine()) { String[] temp = scan.nextLine().split("\t"); diff --git a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDWindow.java b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDWindow.java index bd10f0e8e..229c74a7d 100644 --- a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDWindow.java +++ b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/GFFtoBEDWindow.java @@ -54,8 +54,15 @@ class Task extends SwingWorker { @Override public Void doInBackground() throws IOException { setProgress(0); - for(int x = 0; x < BEDFiles.size(); x++) { - GFFtoBED.convertBEDtoGFF(OUTPUT_PATH, BEDFiles.get(x)); + for(int x = 0; x < BEDFiles.size(); x++) { + File XGFF = BEDFiles.get(x); + // Set outfilepath + String bedName = (XGFF.getName()).substring(0,XGFF.getName().length() - 4) + ".bed"; + File OUT_FILE = null; + if(OUTPUT_PATH == null) OUT_FILE = new File( bedName ); + else OUT_FILE = new File( OUTPUT_PATH + File.separator + bedName ); + // Execute conversion and update progress + GFFtoBED.convertGFFtoBED(OUTPUT_PATH, XGFF); int percentComplete = (int)(((double)(x + 1) / BEDFiles.size()) * 100); setProgress(percentComplete); } From 2562bc6adbf2073b427a29ed8d720d18296a8bdf Mon Sep 17 00:00:00 2001 From: owlang Date: Tue, 29 Sep 2020 16:11:51 -0400 Subject: [PATCH 42/43] create SortGFF 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/*/ SortGFFOutput class. There is a quirk with the BEDtoGFF tool that adds a semicolon to the end of the last column with the feature ID. To make this tool compatible with the GFF output, I split the last GFF column on the semicolon and took the first token as the ID. I also moved the parseCDT method originally in the window_interface/ Coordinate_Manipulation/*/Sort* classes to the util/CDTUtilities class. The parseCDT method is used to get the number of items in a row of the input CDT file and to check the formatting for consistent row sizes. Since both the SortBED and SortGFF tools use the same method, this commit merges them into the same copy that can be referenced from a general utilities class. This will make updates easier if this method needs to be adjusted in the future. util/CDTUtilities -move parseCDT method from SortGFFWindow class to the CDTUtilities class -add properties to the class to save information on consistent row sizes -add methods to retrieve these values NOTE: static methods of this class appear to be unused or copied into another class, consider retiring window_interface/*Window -adjust output argument when initializing script class to be full file basename and not just directory -lots of differences in this commit are a matter of entabbing -rename BED related variable names to be consistent with GFF variable naming -update CDT file loading to use CDTUtilities validation method -remove parseCDT() method since using CDTUtilities version script/* -use output as file basename rather than directory name -temporary fix using String's split() method on the semicolon cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user -import CDTUtilities and parse CDT input to check consistent rows as a part of validateInput() --- .../GFF_Manipulation/SortGFFCLI.java | 86 ++++++++++++- .../GFF_Manipulation/SortGFF.java | 26 ++-- src/util/CDTUtilities.java | 38 ++++++ .../GFF_Manipulation/SortGFFWindow.java | 113 ++++++++---------- 4 files changed, 181 insertions(+), 82 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java b/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java index c8ddc2e9a..343ad317f 100644 --- a/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java +++ b/src/cli/Coordinate_Manipulation/GFF_Manipulation/SortGFFCLI.java @@ -12,8 +12,9 @@ import java.io.FileNotFoundException; import objects.ToolDescriptions; +import util.CDTUtilities; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.GFF_Manipulation.SortGFF; +import scripts.Coordinate_Manipulation.GFF_Manipulation.SortGFF; /** Coordinate_ManipulationCLI/SortGFFCLI @@ -25,6 +26,22 @@ exitCodeOnExecutionException = 1) public class SortGFFCLI implements Callable { + @Parameters( index = "0", description = "the GFF file to sort") + private File gffFile; + @Parameters( index = "1", description = "the reference CDT file to sort the input by") + private File cdtFile; + + @Option(names = {"-o", "--output"}, description = "specify output file basename with no .cdt/.gff/.jtv extension (default=_SORT") + private String outputBasename = null; + @Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)") + private int center = -999; + @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}; + + private int CDT_SIZE = -999; + private boolean byCenter = false; + @Override public Integer call() throws Exception { System.err.println( ">SortGFFCLI.call()" ); @@ -35,16 +52,73 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + if( byCenter ){ + index[0] = (CDT_SIZE / 2) - (center / 2); + index[1] = (CDT_SIZE / 2) + (center / 2); + } + + SortGFF.sortGFFbyCDT(outputBasename, gffFile, cdtFile, index[0], index[1]); - //System.err.println("Calculations Complete"); + System.err.println("Sort Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!gffFile.exists()){ + r += "(!)GFF file does not exist: " + gffFile.getName() + "\n"; + } + if(!cdtFile.exists()){ + r += "(!)CDT file does not exist: " + cdtFile.getName() + "\n"; + } + if(!"".equals(r)){ return(r); } + //check input extensions + if(!"gff".equals(ExtensionFileFilter.getExtension(gffFile))){ + r += "(!)Is this a GFF file? Check extension: " + gffFile.getName() + "\n"; + } + if(!"cdt".equals(ExtensionFileFilter.getExtension(cdtFile))){ + r += "(!)Is this a CDT file? Check extension: " + cdtFile.getName() + "\n"; + } + // validate CDT as file, with consistent row size, and save row_size value + try { + CDTUtilities cdt_obj = new CDTUtilities(); + cdt_obj.parseCDT(cdtFile); + if( cdt_obj.isValid() ){ CDT_SIZE = cdt_obj.getSize(); } + else{ r += "(!)CDT file doesn't have consistent row sizes. " + cdt_obj.getInvalidMessage(); } + }catch (FileNotFoundException e1){ e1.printStackTrace(); } + + //set default output filename + if(outputBasename==null){ + outputBasename = ExtensionFileFilter.stripExtension(gffFile) + "_SORT"; + //check output filename is valid + }else{ + //no extension check + //check directory + File BASEFILE = new File(outputBasename); + if(BASEFILE.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(BASEFILE.getParent()).exists()){ + r += "(!)Check output directory exists: " + BASEFILE.getParent() + "\n"; + } + } + + // Set Center if Index not given + if( index[0]==-999 && index[1]==-999 ) { byCenter = true; } + // Center Specified + if( byCenter ){ + if( center==-999 ){ center = 100; } + else if( center<0 ){ + r += "(!)Invalid --center input, must be a positive integer value."; + } + // Index Specified + }else{ + if( index[0]<0 || index[1]>CDT_SIZE || index[0]>index[1] ){ + r += "(!)Invalid --index value input, check that start>0, stop loadCDT(File input) throws FileNotFoundException { Vector matrix = new Vector(); Scanner scan = new Scanner(input); diff --git a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/SortGFFWindow.java b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/SortGFFWindow.java index daadb8ed1..c009c0709 100644 --- a/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/SortGFFWindow.java +++ b/src/window_interface/Coordinate_Manipulation/GFF_Manipulation/SortGFFWindow.java @@ -31,6 +31,7 @@ import javax.swing.SwingWorker; import javax.swing.border.EmptyBorder; +import util.CDTUtilities; import util.FileSelection; import scripts.Coordinate_Manipulation.GFF_Manipulation.SortGFF; @@ -74,42 +75,42 @@ public class SortGFFWindow extends JFrame implements ActionListener, PropertyCha private JLabel lblIndexStop; class Task extends SwingWorker { - @Override - public Void doInBackground() throws IOException { - try { - if(rdbtnSortbyCenter.isSelected() && Integer.parseInt(txtMid.getText()) > CDT_SIZE) { - JOptionPane.showMessageDialog(null, "Sort Size is larger than CDT File!!!"); - } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStart.getText()) < 0) { - JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); - } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStop.getText()) > CDT_SIZE) { - JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); - } else { - if(rdbtnSortbyCenter.isSelected()) { - START_INDEX = (CDT_SIZE / 2) - (Integer.parseInt(txtMid.getText()) / 2); - STOP_INDEX = (CDT_SIZE / 2) + (Integer.parseInt(txtMid.getText()) / 2); - } else { - START_INDEX = Integer.parseInt(txtStart.getText()); - STOP_INDEX = Integer.parseInt(txtStop.getText()); - } - - String OUTPUT = txtOutput.getText(); - if(OUTPUT_PATH != null) { OUTPUT = OUTPUT_PATH.getCanonicalPath() + File.separator + txtOutput.getText(); } - - setProgress(0); - SortGFF.sortGFFbyCDT(OUTPUT, GFF_File, CDT_File, START_INDEX, STOP_INDEX); + @Override + public Void doInBackground() throws IOException { + try { + if(rdbtnSortbyCenter.isSelected() && Integer.parseInt(txtMid.getText()) > CDT_SIZE) { + JOptionPane.showMessageDialog(null, "Sort Size is larger than CDT File!!!"); + } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStart.getText()) < 0) { + JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); + } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStop.getText()) > CDT_SIZE) { + JOptionPane.showMessageDialog(null, "Stop Index is larger than CDT row size!!!"); + } else { + if(rdbtnSortbyCenter.isSelected()) { + START_INDEX = (CDT_SIZE / 2) - (Integer.parseInt(txtMid.getText()) / 2); + STOP_INDEX = (CDT_SIZE / 2) + (Integer.parseInt(txtMid.getText()) / 2); + } else { + START_INDEX = Integer.parseInt(txtStart.getText()); + STOP_INDEX = Integer.parseInt(txtStop.getText()); + } + + String OUTPUT = txtOutput.getText(); + if(OUTPUT_PATH != null) { OUTPUT = OUTPUT_PATH.getCanonicalPath() + File.separator + txtOutput.getText(); } + + setProgress(0); + SortGFF.sortGFFbyCDT(OUTPUT, GFF_File, CDT_File, START_INDEX, STOP_INDEX); setProgress(100); JOptionPane.showMessageDialog(null, "Sort Complete"); - } - } catch(NumberFormatException nfe){ + } + } catch(NumberFormatException nfe){ JOptionPane.showMessageDialog(null, "Invalid Input in Fields!!!"); } return null; - } - - public void done() { - massXable(contentPane, true); - setCursor(null); //turn off the wait cursor - } + } + + public void done() { + massXable(contentPane, true); + setCursor(null); //turn off the wait cursor + } } public SortGFFWindow() { @@ -191,7 +192,7 @@ public void actionPerformed(ActionEvent e) { contentPane.add(lblSizeOfExpansion); txtOutput = new JTextField(); - sl_contentPane.putConstraint(SpringLayout.EAST, txtOutput, 0, SpringLayout.EAST, progressBar); + sl_contentPane.putConstraint(SpringLayout.EAST, txtOutput, -15, SpringLayout.EAST, contentPane); txtOutput.setEnabled(false); contentPane.add(txtOutput); txtOutput.setColumns(10); @@ -279,9 +280,9 @@ public void itemStateChanged(ItemEvent e) { sl_contentPane.putConstraint(SpringLayout.NORTH, btnLoadGFFFile, 10, SpringLayout.NORTH, contentPane); btnLoadGFFFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - File newBEDFile = FileSelection.getFile(fc,"gff"); - if(newBEDFile != null) { - GFF_File = newBEDFile; + File newGFFFile = FileSelection.getFile(fc,"gff"); + if(newGFFFile != null) { + GFF_File = newGFFFile; lblGFFFile.setText(GFF_File.getName()); txtOutput.setEnabled(true); String sortName = (GFF_File.getName()).substring(0, GFF_File.getName().length() - 4) + "_SORT"; @@ -300,11 +301,19 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { File newCDTFile = FileSelection.getFile(fc,"cdt"); if(newCDTFile != null) { - CDT_File = newCDTFile; - lblCDTFile.setText(CDT_File.getName()); - - try { CDT_VALID = parseCDTFile(CDT_File); + try { + CDT_File = newCDTFile; + lblCDTFile.setText(CDT_File.getName()); + + CDTUtilities cdt_obj = new CDTUtilities(); + cdt_obj.parseCDT(CDT_File); + CDT_SIZE = cdt_obj.getSize(); + CDT_VALID = cdt_obj.isValid(); + String message = cdt_obj.getInvalidMessage(); + System.err.println(CDT_File.getCanonicalPath() + ": " + message); + if(!message.equals("")) { JOptionPane.showMessageDialog(null, message);} } catch (FileNotFoundException e1) { e1.printStackTrace(); } + catch (IOException e2) { e2.printStackTrace(); } if(CDT_VALID) { lblColumnCount.setText("Column Count: " + CDT_SIZE); @@ -361,28 +370,4 @@ public void massXable(Container con, boolean status) { } } } - - public boolean parseCDTFile(File CDT) throws FileNotFoundException { - Scanner scan = new Scanner(CDT); - int currentSize = -999; - boolean consistentSize = true; - int currentRow = 1; - while (scan.hasNextLine()) { - String[] temp = scan.nextLine().split("\t"); - if(!temp[0].contains("YORF") && !temp[0].contains("NAME")) { - int tempsize = temp.length - 2; - if(currentSize == -999) { currentSize = tempsize; } - else if(currentSize != tempsize) { - JOptionPane.showMessageDialog(null, "Invalid Row at Index: " + currentRow); - consistentSize = false; - scan.close(); - } - currentRow++; - } - } - scan.close(); - CDT_SIZE = currentSize; - if(consistentSize) { return true; } - else { return false; } - } -} +} \ No newline at end of file From 3ab7ea026fcaea0581e3e4ed121b5e4093c350e4 Mon Sep 17 00:00:00 2001 From: owlang Date: Tue, 29 Sep 2020 17:10:30 -0400 Subject: [PATCH 43/43] create SortBED command line version Before, this tool was implemented with a JFrame script object so this commit separates out the JFrame elements for CLI implementation. JFrame elements are saved to the src/window_interface/*/SortBEDOutput class while the calculations are kept in the src/scripts/*/SortBED class. window_interface/*Window -adjust output argument when initializing script class to be full filename and not just directory -lots of differences in this commit are a matter of entabbing -rename BED related variable names to be consistent with GFF variable naming -update CDT file loading to use CDTUtilities validation method -remove parseCDT() method since using CDTUtilities version script/* -use output as file basename rather than directory name cli/* -call appropriate script class -write up picocli parsing objects -write up validateInput() method to check inputs and write messages for the user -import CDTUtilities and parse CDT input to check consistent rows as a part of validateInput() --- .../BED_Manipulation/SortBEDCLI.java | 86 ++++++++++++++- .../BED_Manipulation/SortBED.java | 27 ++--- .../BED_Manipulation/SortBEDWindow.java | 104 ++++++++---------- 3 files changed, 139 insertions(+), 78 deletions(-) diff --git a/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java b/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java index e7ceb6840..194054a88 100644 --- a/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java +++ b/src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java @@ -12,8 +12,9 @@ import java.io.FileNotFoundException; import objects.ToolDescriptions; +import util.CDTUtilities; import util.ExtensionFileFilter; -//import scripts.Coordinate_Manipulation.BED_Manipulation.SortBED; +import scripts.Coordinate_Manipulation.BED_Manipulation.SortBED; /** Coordinate_ManipulationCLI/SortBEDCLI @@ -25,6 +26,22 @@ exitCodeOnExecutionException = 1) public class SortBEDCLI implements Callable { + @Parameters( index = "0", description = "the BED file to sort") + private File bedFile; + @Parameters( index = "1", description = "the reference CDT file to sort the input by") + private File cdtFile; + + @Option(names = {"-o", "--output"}, description = "specify output file basename with no .cdt/.bed/.jtv extension (default=_SORT") + private String outputBasename = null; + @Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)") + private int center = -999; + @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}; + + private int CDT_SIZE = -999; + private boolean byCenter = false; + @Override public Integer call() throws Exception { System.err.println( ">SortBEDCLI.call()" ); @@ -35,16 +52,73 @@ public Integer call() throws Exception { System.exit(1); } - //SEStats.getSEStats( output, bamFile, null ); + if( byCenter ){ + index[0] = (CDT_SIZE / 2) - (center / 2); + index[1] = (CDT_SIZE / 2) + (center / 2); + } + + SortBED.sortBEDbyCDT(outputBasename, bedFile, cdtFile, index[0], index[1]); - //System.err.println("Calculations Complete"); + System.err.println("Sort Complete"); return(0); } private String validateInput() throws IOException { String r = ""; - //validate input here - //append messages to the user to `r` + + //check inputs exist + if(!bedFile.exists()){ + r += "(!)BED file does not exist: " + bedFile.getName() + "\n"; + } + if(!cdtFile.exists()){ + r += "(!)CDT file does not exist: " + cdtFile.getName() + "\n"; + } + if(!"".equals(r)){ return(r); } + //check input extensions + if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){ + r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n"; + } + if(!"cdt".equals(ExtensionFileFilter.getExtension(cdtFile))){ + r += "(!)Is this a CDT file? Check extension: " + cdtFile.getName() + "\n"; + } + // validate CDT as file, with consistent row size, and save row_size value + try { + CDTUtilities cdt_obj = new CDTUtilities(); + cdt_obj.parseCDT(cdtFile); + if( cdt_obj.isValid() ){ CDT_SIZE = cdt_obj.getSize(); } + else{ r += "(!)CDT file doesn't have consistent row sizes. " + cdt_obj.getInvalidMessage(); } + }catch (FileNotFoundException e1){ e1.printStackTrace(); } + + //set default output filename + if(outputBasename==null){ + outputBasename = ExtensionFileFilter.stripExtension(bedFile) + "_SORT"; + //check output filename is valid + }else{ + //no extension check + //check directory + File BASEFILE = new File(outputBasename); + if(BASEFILE.getParent()==null){ +// System.err.println("default to current directory"); + } else if(!new File(BASEFILE.getParent()).exists()){ + r += "(!)Check output directory exists: " + BASEFILE.getParent() + "\n"; + } + } + + // Set Center if Index not given + if( index[0]==-999 && index[1]==-999 ) { byCenter = true; } + // Center Specified + if( byCenter ){ + if( center==-999 ){ center = 100; } + else if( center<0 ){ + r += "(!)Invalid --center input, must be a positive integer value."; + } + // Index Specified + }else{ + if( index[0]<0 || index[1]>CDT_SIZE || index[0]>index[1] ){ + r += "(!)Invalid --index value input, check that start>0, stop { - @Override - public Void doInBackground() throws IOException { - try { - if(rdbtnSortbyCenter.isSelected() && Integer.parseInt(txtMid.getText()) > CDT_SIZE) { - JOptionPane.showMessageDialog(null, "Sort Size is larger than CDT File!!!"); - } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStart.getText()) < 0) { - JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); - } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStop.getText()) > CDT_SIZE) { - JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); - } else { - if(rdbtnSortbyCenter.isSelected()) { - START_INDEX = (CDT_SIZE / 2) - (Integer.parseInt(txtMid.getText()) / 2); - STOP_INDEX = (CDT_SIZE / 2) + (Integer.parseInt(txtMid.getText()) / 2); - } else { - START_INDEX = Integer.parseInt(txtStart.getText()); - STOP_INDEX = Integer.parseInt(txtStop.getText()); - } - - String OUTPUT = txtOutput.getText(); - if(OUTPUT_PATH != null) { OUTPUT = OUTPUT_PATH.getCanonicalPath() + File.separator + txtOutput.getText(); } - - setProgress(0); - SortBED.sortBEDbyCDT(OUTPUT, BED_File, CDT_File, START_INDEX, STOP_INDEX); + @Override + public Void doInBackground() throws IOException { + try { + if(rdbtnSortbyCenter.isSelected() && Integer.parseInt(txtMid.getText()) > CDT_SIZE) { + JOptionPane.showMessageDialog(null, "Sort Size is larger than CDT File!!!"); + } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStart.getText()) < 0) { + JOptionPane.showMessageDialog(null, "Start Index is smaller than 0!!!"); + } else if(rdbtnSortbyIndex.isSelected() && Integer.parseInt(txtStop.getText()) > CDT_SIZE) { + JOptionPane.showMessageDialog(null, "Stop Index is larger than CDT row size!!!"); + } else { + if(rdbtnSortbyCenter.isSelected()) { + START_INDEX = (CDT_SIZE / 2) - (Integer.parseInt(txtMid.getText()) / 2); + STOP_INDEX = (CDT_SIZE / 2) + (Integer.parseInt(txtMid.getText()) / 2); + } else { + START_INDEX = Integer.parseInt(txtStart.getText()); + STOP_INDEX = Integer.parseInt(txtStop.getText()); + } + + String OUTPUT = txtOutput.getText(); + if(OUTPUT_PATH != null) { OUTPUT = OUTPUT_PATH.getCanonicalPath() + File.separator + txtOutput.getText(); } + + setProgress(0); + SortBED.sortBEDbyCDT(OUTPUT, BED_File, CDT_File, START_INDEX, STOP_INDEX); setProgress(100); JOptionPane.showMessageDialog(null, "Sort Complete"); - } - } catch(NumberFormatException nfe){ + } + } catch(NumberFormatException nfe){ JOptionPane.showMessageDialog(null, "Invalid Input in Fields!!!"); } return null; - } - - public void done() { - massXable(contentPane, true); - setCursor(null); //turn off the wait cursor - } + } + + public void done() { + massXable(contentPane, true); + setCursor(null); //turn off the wait cursor + } } public SortBEDWindow() { @@ -284,7 +285,7 @@ public void actionPerformed(ActionEvent e) { BED_File = newBEDFile; lblBEDFile.setText(BED_File.getName()); txtOutput.setEnabled(true); - String sortName = (BED_File.getName()).substring(0,BED_File.getName().length() - 4) + "_SORT"; + String sortName = (BED_File.getName()).substring(0, BED_File.getName().length() - 4) + "_SORT"; txtOutput.setText(sortName); } } @@ -300,11 +301,19 @@ public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) { File newCDTFile = FileSelection.getFile(fc,"cdt"); if(newCDTFile != null) { - CDT_File = newCDTFile; - lblCDTFile.setText(CDT_File.getName()); - - try { CDT_VALID = parseCDTFile(CDT_File); + try { + CDT_File = newCDTFile; + lblCDTFile.setText(CDT_File.getName()); + + CDTUtilities cdt_obj = new CDTUtilities(); + cdt_obj.parseCDT(CDT_File); + CDT_SIZE = cdt_obj.getSize(); + CDT_VALID = cdt_obj.isValid(); + String message = cdt_obj.getInvalidMessage(); + System.err.println(CDT_File.getCanonicalPath() + ": " + message); + if(!message.equals("")) { JOptionPane.showMessageDialog(null, message);} } catch (FileNotFoundException e1) { e1.printStackTrace(); } + catch (IOException e2) { e2.printStackTrace(); } if(CDT_VALID) { lblColumnCount.setText("Column Count: " + CDT_SIZE); @@ -362,27 +371,4 @@ public void massXable(Container con, boolean status) { } } - public boolean parseCDTFile(File CDT) throws FileNotFoundException { - Scanner scan = new Scanner(CDT); - int currentSize = -999; - boolean consistentSize = true; - int currentRow = 1; - while (scan.hasNextLine()) { - String[] temp = scan.nextLine().split("\t"); - if(!temp[0].contains("YORF") && !temp[0].contains("NAME")) { - int tempsize = temp.length - 2; - if(currentSize == -999) { currentSize = tempsize; } - else if(currentSize != tempsize) { - JOptionPane.showMessageDialog(null, "Invalid Row at Index: " + currentRow); - consistentSize = false; - scan.close(); - } - currentRow++; - } - } - scan.close(); - CDT_SIZE = currentSize; - if(consistentSize) { return true; } - else { return false; } - } } \ No newline at end of file