diff --git a/.classpath b/.classpath deleted file mode 100644 index 5d379b9..0000000 --- a/.classpath +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.gitignore b/.gitignore index f080823..2d7a953 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /bin/ -/test/ -/utils/ +/java.plop.test/ +/java.plop.utils/ .idea .project .directory diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 32c94bd..3cbc689 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/.idea/libraries/Maven__sc_fiji_Auto_Threshold_1_17_2.xml b/.idea/libraries/Maven__sc_fiji_Auto_Threshold_1_17_2.xml deleted file mode 100644 index abc07ab..0000000 --- a/.idea/libraries/Maven__sc_fiji_Auto_Threshold_1_17_2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.project b/.project deleted file mode 100644 index fd2402b..0000000 --- a/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - SIP - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.m2e.core.maven2Nature - org.eclipse.jdt.core.javanature - - diff --git a/README.md b/README.md index 4ae64f5..9803c3a 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ +WARNING: We just noticed that the newest version of Juicer Tools (v1.22) interacts with SIPMeta in weird ways. Please use Juicer Tools v1.13 instead. + # SIP # What is SIP? -SIP (Significant Interaction Peak caller) is a tool to identify and analyze loops that appear as high intensity +SIP (Significant Interaction Peak caller) is a tool to identify and analyze java.plop.loops that appear as high intensity signal in Hi-C maps. This program is written in java and can be run on Linux, Windows, or MAC systems and includes either command line options or a graphical user interface. @@ -16,13 +18,13 @@ Follow the links below to get started: * [View the Paper](https://genome.cshlp.org/content/early/2020/03/03/gr.257832.119.long) -Rowley MJ, Poulet A, Nichols MH, Bixler BJ, Sanborn AL, Brouhard EA, Hermetz K, Linsenbaum H, Csankovszki G, Lieberman Aiden E, Corces G. Analysis of Hi-C data using SIP effectively identifies loops in organisms from C. elegans to mammals. Genome Research 2020. +Rowley MJ, Poulet A, Nichols MH, Bixler BJ, Sanborn AL, Brouhard EA, Hermetz K, Linsenbaum H, Csankovszki G, Lieberman Aiden E, Corces G. Analysis of Hi-C data using SIP effectively identifies java.plop.loops in organisms from C. elegans to mammals. Genome Research 2020. ## SIP help menu: SIP_HiC run with java 8. -SIP is implemented in java and includes achoice between command line options or a graphical user interface (gui) allowing for more general use. This method is intended as an alternative loop caller especially for difficult to identify loops and works in conjunction with juicebox .hic files. +SIP is implemented in java and includes achoice between command line options or a graphical user interface (java.plop.gui) allowing for more general use. This method is intended as an alternative loop caller especially for difficult to identify java.plop.loops and works in conjunction with juicebox .hic files. #### Usage @@ -49,12 +51,12 @@ SIP is implemented in java and includes achoice between command line options or * **-max**: Maximum filter: increases the region of high intensity (default 2) * **-min**: Minimum filter: removes the isolated high value (default 2) * **-sat**: % of staturated pixel: enhances the contrast in the image (default 0.01) - * **-t**: Threshold for loops detection (default 2800 for hic) + * **-t**: Threshold for java.plop.loops detection (default 2800 for hic) * **-nbZero**: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels surrounding the detected maxima (default 6) * **-norm**: (default KR) * **-del**: true or false, whether not to delete tif files used for loop detection (default true) * **-fdr**: Empirical FDR value for filtering based on random sites (default 0.01) - * **-isDroso**: default false, if true apply extra filter to help detect loops similar to those found in D. mel cells + * **-isDroso**: default false, if true apply extra filter to help detect java.plop.loops similar to those found in D. mel cells * -h or --help print help #### Command line eg: diff --git a/SIP.iml b/SIP.iml index a705397..61d8733 100644 --- a/SIP.iml +++ b/SIP.iml @@ -13,13 +13,82 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/gui/GuiAnalysis$FileListener.class b/bin/gui/GuiAnalysis$FileListener.class deleted file mode 100644 index e9272c6..0000000 Binary files a/bin/gui/GuiAnalysis$FileListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis$QuitListener.class b/bin/gui/GuiAnalysis$QuitListener.class deleted file mode 100644 index 420394d..0000000 Binary files a/bin/gui/GuiAnalysis$QuitListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis$RBHicListener.class b/bin/gui/GuiAnalysis$RBHicListener.class deleted file mode 100644 index c21b327..0000000 Binary files a/bin/gui/GuiAnalysis$RBHicListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis$RawDataDirectoryListener.class b/bin/gui/GuiAnalysis$RawDataDirectoryListener.class deleted file mode 100644 index a47692a..0000000 Binary files a/bin/gui/GuiAnalysis$RawDataDirectoryListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis$StartListener.class b/bin/gui/GuiAnalysis$StartListener.class deleted file mode 100644 index 24457dc..0000000 Binary files a/bin/gui/GuiAnalysis$StartListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis$WorkDirectoryListener.class b/bin/gui/GuiAnalysis$WorkDirectoryListener.class deleted file mode 100644 index 0790143..0000000 Binary files a/bin/gui/GuiAnalysis$WorkDirectoryListener.class and /dev/null differ diff --git a/bin/gui/GuiAnalysis.class b/bin/gui/GuiAnalysis.class deleted file mode 100644 index f77e333..0000000 Binary files a/bin/gui/GuiAnalysis.class and /dev/null differ diff --git a/bin/gui/Progress.class b/bin/gui/Progress.class deleted file mode 100644 index e3276f8..0000000 Binary files a/bin/gui/Progress.class and /dev/null differ diff --git a/bin/test/TestCallLoopsHicFile.class b/bin/test/TestCallLoopsHicFile.class deleted file mode 100644 index 3380d62..0000000 Binary files a/bin/test/TestCallLoopsHicFile.class and /dev/null differ diff --git a/bin/test/TestCallLoopsProcessedFile.class b/bin/test/TestCallLoopsProcessedFile.class deleted file mode 100644 index ca4bb57..0000000 Binary files a/bin/test/TestCallLoopsProcessedFile.class and /dev/null differ diff --git a/bin/test/TestGui.class b/bin/test/TestGui.class deleted file mode 100644 index fc1b689..0000000 Binary files a/bin/test/TestGui.class and /dev/null differ diff --git a/bin/utils/ChangeImageRes.class b/bin/utils/ChangeImageRes.class deleted file mode 100644 index a628fef..0000000 Binary files a/bin/utils/ChangeImageRes.class and /dev/null differ diff --git a/bin/utils/CoordinatesCorrection.class b/bin/utils/CoordinatesCorrection.class deleted file mode 100644 index 430aa11..0000000 Binary files a/bin/utils/CoordinatesCorrection.class and /dev/null differ diff --git a/bin/utils/DecayAnalysis.class b/bin/utils/DecayAnalysis.class deleted file mode 100644 index 918c750..0000000 Binary files a/bin/utils/DecayAnalysis.class and /dev/null differ diff --git a/bin/utils/FindMaxima.class b/bin/utils/FindMaxima.class deleted file mode 100644 index 57ec29b..0000000 Binary files a/bin/utils/FindMaxima.class and /dev/null differ diff --git a/bin/utils/Loop.class b/bin/utils/Loop.class deleted file mode 100644 index 9eee1f3..0000000 Binary files a/bin/utils/Loop.class and /dev/null differ diff --git a/bin/utils/PeakAnalysisScore.class b/bin/utils/PeakAnalysisScore.class deleted file mode 100644 index b5a6fec..0000000 Binary files a/bin/utils/PeakAnalysisScore.class and /dev/null differ diff --git a/bin/utils/Strip.class b/bin/utils/Strip.class deleted file mode 100644 index 2072611..0000000 Binary files a/bin/utils/Strip.class and /dev/null differ diff --git a/pom.xml b/pom.xml index bd7720d..731b3f9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,44 +1,227 @@ -4.0.0 - SIP - SIP - 1.3.6-SNAPSHOT - - + 4.0.0 + SIP + SIP + 0-SNAPSHOT + SIP_HiC + + - sc.fiji - Auto_Threshold - 1.17.2 + sc.fiji + imagescience + 2.4.1 net.imagej - ij - 1.51n + ij + 1.51n + fr.inra.ijpb MorphoLibJ_ 1.4.0 + + ome + bioformats_package + 6.6.0 + + - - + + commons-cli + commons-cli + 1.4 + + + gov.nist.math + jama + 1.0.3 + + + commons-io + commons-io + 2.6 + + + + commons-cli + commons-cli + 1.4 + - - - - src - - - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - + + + + + ${basedir}/src/main/resources + + + ${project.build.sourceDirectory} + + + + + ${basedir}/src/test/resources + + + ${project.build.testSourceDirectory} + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.0.0 + + + + plop.sipMain.Hic_main + + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + + plop.sipMain.Hic_main + + . + + + + + + + *:* + + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + + + axpoulet + Axel Poulet + pouletaxel@gmail.comm + plop + + architect + developer + + +1 + + + + + + imagej.public + http://maven.imagej.net/content/groups/public + + + gred-releases + https://artifacts.igred.fr/releases + + + gitlab-maven + https://gitlab.com/api/v4/projects/19044962/packages/maven + + + + + + + 7 + 7 + + \ No newline at end of file diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..ec8969f --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: plop.sipMain.Hic_main + diff --git a/src/main/java/plop/cli/CLIHelper.java b/src/main/java/plop/cli/CLIHelper.java new file mode 100644 index 0000000..425a15c --- /dev/null +++ b/src/main/java/plop/cli/CLIHelper.java @@ -0,0 +1,150 @@ +package plop.cli; + +import org.apache.commons.cli.HelpFormatter; + +public class CLIHelper { + + /** */ + private static String _version ="1.6.1"; + + /** */ + private static String _hic ="java -jar SIPHiC"+ _version +".jar hic "; + /** */ + private static String _cool ="java -jar SIPHiC"+ _version +".jar cool "; + /** */ + private static String _processed ="java -jar SIPHiC"+ _version +".jar processed "; + + /* Constructor*/ + + public CLIHelper(){ } + + + public static void main(String[] args){ + + CmdHelpProcessed(); + } + + + + /** + * Method get help for command line + * with example command line + */ + public static void CmdHelpHiC() { + String argument = "-i path/to/file.hic -c path/to/chrSizeFile.txt -o path/to/output/folder -j path/to/juicerTool.jar -lt intra "; + String[] argv = argument.split(" "); + CLIOptionHiC command = new CLIOptionHiC (argv); + String usage = _hic + argument + " [options]"; + HelpFormatter formatter = new HelpFormatter(); + + System.out.println("\nHelp for "+_hic+"!!!!!!! \n"); + formatter.printHelp(200, usage, "SIP_HiC version"+_version+"option hic: ", command.getOptions(),getAuthors()); + System.exit(1); + } + + + /** + * Method get help for command line + * with example command line + */ + public static void CmdHelpCool() { + String argument = "-i path/to/file.mcool -c path/to/chrSizeFile.txt -o path/to/output/folder -cooltools path/to/cooltools -cooler path/to/cooler -lt intra "; + String[] argv = argument.split(" "); + CLIOptionCool command = new CLIOptionCool (argv); + String usage = _cool+argument+" [options]"; + HelpFormatter formatter = new HelpFormatter(); + + System.out.println("\nHelp for "+_cool+"!!!!!!! \n"); + formatter.printHelp(200, usage, "SIP_HiC version"+_version+"option cool: ", command.getOptions(),getAuthors()); + System.exit(1); + } + + /** + * Method get help for command line + * with example command line + */ + public static void CmdHelpProcessed(){ + String argument = "-i path/to/folder/toSIP/ProcessedData -c path/to/chrSizeFile -o path/to/output/folder -lt intra "; + String[] argv = argument.split(" "); + CLIOptionProcessed command = new CLIOptionProcessed (argv); + String usage = _processed+argument+" [options]"; + HelpFormatter formatter = new HelpFormatter(); + + System.out.println("\nHelp for "+_processed+"!!!!!!! \n"); + formatter.printHelp(200, usage, "SIP_HiC option processed : ", command.getOptions(),getAuthors()); + System.exit(1); + } + + /** + * + * @return + */ + public static void getHelperInfos() { + System.out.println( "More details :\n" + + "java -jar SIPHiC"+ _version +".jar hic -h or --help \n" + + "java -jar SIPHiC-"+ _version +".jar cool -h or --help\n"+ + "java -jar SIPHiC-"+ _version +".jar processed -h or --help \n" + + "\n\nCommand line g:\n" + + "\tjava -jar SIP_HiC.jar hic -i path/to/hicFile.hic -c path/to/chrSizeFile -o path/to/output/folder -j path/to/juicerTool.jar -lt intra [options]\n" + + "\tjava -jar SIP_HiC.jar cool -i path/to/hicFile.hic -c path/to/chrSizeFile -o path/to/output/folder -cooltools path/to/cooltools -cooler path/to/cooler -lt intra [options]\n" + + "\tjava -jar SIP_HiC.jar processed -i SIP path/to/folder/SIPProcessedData -c path/to/chrSizeFile -o path/to/output/folder -lt intra [options]\n"); + System.exit(1); + + } + + + /** + * + * @return + */ + public static void getHelperAllInfos() { + System.out.println( "\nMore details :\n" + + "java -jar SIPHiC"+ _version +".jar hic -h or --help \n" + + "java -jar SIPHiC-"+ _version +".jar cool -h or --help\n"+ + "java -jar SIPHiC-"+ _version +".jar processed -h or --help \n" + + "\n\nCommand line g:\n" + + "\tjava -jar SIP_HiC.jar hic -i path/to/hicFile.hic -c path/to/chrSizeFile -o path/to/output/folder -j path/to/juicerTool.jar -lt intra [options]\n" + + "\tjava -jar SIP_HiC.jar cool -i path/to/hicFile.hic -c path/to/chrSizeFile -o path/to/output/folder -cooltools path/to/cooltools -cooler path/to/cooler -lt intra [options]\n" + + "\tjava -jar SIP_HiC.jar processed -i SIP path/to/folder/SIPProcessedData -c path/to/chrSizeFile -o path/to/output/folder -lt intra [options]\n" + + "\nAuthors:\n" + + "Axel Poulet\n" + + "Department of Molecular, Cellular and Developmental Biology Yale University \n" + + "M. Jordan Rowley\n" + + "Department of Genetics, Cell Biology and Anatomy, University of Nebraska Medical\n" + + "Contact: \npouletaxel@gmail.com OR jordan.rowley@unmc.edu\n"); + System.exit(1); + + } + + /** + * + * @return + */ + public static String getAuthors() { + return "Authors:\n" + + "Axel Poulet\n" + + "Department of Molecular, Cellular and Developmental Biology Yale University \n" + + "M. Jordan Rowley\n" + + "Department of Genetics, Cell Biology and Anatomy, University of Nebraska Medical\n" + + "Contact:\npouletaxel@gmail.com OR jordan.rowley@unmc.edu\n"; + } + + + + /** + * + * @return + */ + private String getCool() { + return "-i mcoolFile -c chrSizeFile -o Output -cooltools cooltoolsPath -cooler coolerPath -tl intra"; + } + + /** + * + * @return + */ + private String getPocessed() { + return "-i PathDirectoryWithProcessedData -c chrSizeFile --o Output -tl intra "; + } + +} diff --git a/src/main/java/plop/cli/CLIOptionCool.java b/src/main/java/plop/cli/CLIOptionCool.java new file mode 100644 index 0000000..e585ddd --- /dev/null +++ b/src/main/java/plop/cli/CLIOptionCool.java @@ -0,0 +1,74 @@ +package plop.cli; + +import org.apache.commons.cli.*; + +/** + * + */ +public class CLIOptionCool extends CLIOptionProcessed { + + /** + * + * @param args + * @throws Exception + */ + public CLIOptionCool(String [] args){ + this._options.addOption(_inputFolder); + this._options.addOption(_outputFolder); + this._options.addOption(_chrSize); + this._options.addOption(_interOrIntra); + + /*optional parameters*/ + this._options.addOption(_resolution); + this._options.addOption(_deleteImage); + this._options.addOption(_fdr); + this._options.addOption(_nbZero); + this._options.addOption(_sizeImage); + this._options.addOption(_cpu); + this._options.addOption(_gaussianStrength); + this._options.addOption(_threshold); + this._options.addOption(_diagonal); + this._options.addOption(_factor); + this._options.addOption(_max); + this._options.addOption(_min); + this._options.addOption(_saturated); + this._options.addOption(_isDroso); + + this._options.addOption(Option.builder("cooltools").longOpt("cooltools").required() + .type(String.class).desc("Path to cooltools bin\n").numberOfArgs(1).build()); + this._options.addOption(Option.builder("cooler").longOpt("cooler").required() + .type(String.class).desc("Path to cooler bin\n").numberOfArgs(1).build()); + + + try { + _cmd = _parser.parse(this._options, args,false); + } + catch (ParseException exp){ + System.out.println("\n"+exp.getMessage()+"\n"); + CLIHelper.CmdHelpCool(); + }catch (IllegalArgumentException exp){ + System.out.println( exp.getMessage()); + CLIHelper.CmdHelpCool(); + } + + } + + + + /** + * + * @return + */ + public CommandLine getCommandLine() { + return _cmd; + } + + /** + * + * @return + */ + public Options getOptions() { + return _options; + } + +} diff --git a/src/main/java/plop/cli/CLIOptionHiC.java b/src/main/java/plop/cli/CLIOptionHiC.java new file mode 100644 index 0000000..21104e1 --- /dev/null +++ b/src/main/java/plop/cli/CLIOptionHiC.java @@ -0,0 +1,66 @@ +package plop.cli; + +import org.apache.commons.cli.*; + +public class CLIOptionHiC extends CLIOptionProcessed { + + + + public CLIOptionHiC(String [] args) { + this._options.addOption(_inputFolder); + this._options.addOption(_outputFolder); + this._options.addOption(_chrSize); + this._options.addOption(_interOrIntra); + + /*optional parameters*/ + this._options.addOption(_resolution); + this._options.addOption(_deleteImage); + this._options.addOption(_fdr); + this._options.addOption(_nbZero); + this._options.addOption(_sizeImage); + this._options.addOption(_cpu); + this._options.addOption(_gaussianStrength); + this._options.addOption(_threshold); + this._options.addOption(_diagonal); + this._options.addOption(_factor); + this._options.addOption(_max); + this._options.addOption(_min); + this._options.addOption(_saturated); + this._options.addOption(_isDroso); + this._options.addOption(Option.builder("j").longOpt("juicerTool").required() + .type(String.class).desc("Path to juicerTool.jar\n").numberOfArgs(1).build()); + + this._options.addOption(Option.builder("n").longOpt("norm") + .type(String.class).desc("\n (default KR)\n").numberOfArgs(1).build()); + + try { + this._cmd = this._parser.parse(this._options, args, false); + } + catch (ParseException exp){ + System.out.println("\n"+exp.getMessage()+"\n"); + CLIHelper.CmdHelpHiC(); + }catch (IllegalArgumentException exp){ + System.out.println( exp.getMessage()); + CLIHelper.CmdHelpHiC(); + } + + + } + + + /** + * + * @return + */ + public CommandLine getCommandLine() { + return _cmd; + } + + /** + * + * @return + */ + public Options getOptions() { + return _options; + } +} diff --git a/src/main/java/plop/cli/CLIOptionProcessed.java b/src/main/java/plop/cli/CLIOptionProcessed.java new file mode 100644 index 0000000..d4f5d69 --- /dev/null +++ b/src/main/java/plop/cli/CLIOptionProcessed.java @@ -0,0 +1,159 @@ +package plop.cli; +import org.apache.commons.cli.*; + +/** + * + */ +public class CLIOptionProcessed { + + /** */ + Options _options= new Options(); + /** */ + CommandLine _cmd; + /** */ + Option _inputFolder= Option.builder("i").longOpt("input").required() + .type(String.class).desc("Path to input .hic, .mcool or SIP folder containing processed data\n") + .numberOfArgs(1).build(); + /** */ + Option _interOrIntra = Option.builder("lt").longOpt("loopsType").required() + .type(String.class).desc("value: inter or intra, call java.plop.loops inter chromosomal or intra chromosomal interactions\n") + .numberOfArgs(1).build(); + /** */ + Option _outputFolder= Option.builder("o").longOpt("output").required() + .type(String.class).desc("Path to output folder for SIP's files \n") + .numberOfArgs(1).build(); + /** */ + Option _chrSize = Option.builder("c").longOpt("chrSize").required() + .type(String.class).desc("Path to the chr size file, with the same name of the chr as in the hic file (i.e. chr1 does not match Chr1 or 1).\n") + .numberOfArgs(1).build(); + /** */ + Option _resolution = Option.builder("r").longOpt("resolution").numberOfArgs(1) + .type(Number.class).desc("Resolution in bp (default inter 5000 bp, intra 100 000 bp)\n").build(); + /** */ + Option _sizeImage = Option.builder("ms").longOpt("matrixSize") + .type(Number.class).desc("Matrix size to use for each chunk of the chromosome (default intra 2000 bins, inter 500)\n") + .numberOfArgs(1).build(); + /** */ + Option _cpu = Option.builder("cpu").longOpt("cpu") + .type(Number.class).desc("Number of CPU used for SIP processing (default 1)\n") + .numberOfArgs(1).build(); + /** */ + Option _gaussianStrength = Option.builder("g").longOpt("gaussian") + .type(Number.class).desc("Gaussian filter: smoothing factor to reduce noise during primary loop detection (default intra 1.5, inter 1)\n") + .numberOfArgs(1).build(); + /** */ + Option _threshold = Option.builder("t").longOpt("threshold") + .type(Number.class).desc("Threshold for java.plop.loops detection (default intra 2800, inter 0.9)\n") + .numberOfArgs(1).build(); + /** */ + Option _nbZero = Option.builder("nb").longOpt("nbZero") + .type(Number.class).desc("Number of zeros: number of pixels equal to zero that are allowed in the 24 pixels surrounding the detected loop (default intra 6; inter 3)\n") + .numberOfArgs(1).build(); + /** */ + Option _fdr = Option.builder("fdr").longOpt("fdr") + .type(Number.class).desc("Empirical FDR value for filtering based on random sites (default intra value: 0.01, inter value: 0.025)\n") + .numberOfArgs(1).build(); + /** */ + Option _deleteImage = Option.builder("k").longOpt("keepImage").hasArg(false) + .type(boolean.class).desc("keep tif in output folder if used\n") + .numberOfArgs(0).build(); + + /** */ + final Option _isDroso = Option.builder("isDroso").longOpt("isDroso").hasArg(false) + .type(boolean.class).desc("If option use, apply extra filter to help detect java.plop.loops similar to those found in D. mel cells (used only for intra chromosomal)\n") + .build(); + /** */ + Option _diagonal = Option.builder("d").longOpt("diagonal") + .type(Number.class).desc("diagonal size in bins, remove java.plop.loops found at this size (eg: a size of 2 at 5000 bp resolution removes all java.plop.loops\n" + + " detected at a distance inferior or equal to 10kb) (default: 6 bins, used only for intra chromosomal).\n") + .numberOfArgs(1).build(); + /** */ + Option _factor = Option.builder("f").longOpt("factor") + .type(Number.class).desc(" Multiple resolutions can be specified using (used only for intra chromosomal):\n" + + "\t\t-factor 1: run only for the input res (default)\n" + + "\t\t-factor 2: res and res*2\n" + + "\t\t-factor 3: res and res*5\n" + + "\t\t-factor 4: res, res*2 and res*5\n") + .numberOfArgs(1).build(); + + /** */ + Option _min = Option.builder("min").longOpt("minimum") + .type(Number.class).desc("Minimum filter strength (default 2, used only for intra chromosomal)\n") + .numberOfArgs(1).build(); + /** */ + Option _max = Option.builder("max").longOpt("maximum") + .type(Number.class).desc("Maximum filter strength (default 2, used only for intra chromosomal)\n") + .numberOfArgs(1).build(); + /** */ + Option _saturated = Option.builder("sat").longOpt("saturated") + .type(Number.class).desc("% of saturated pixel: enhances the contrast in the image (default 0.01, used only for intra chromosomal)\n") + .numberOfArgs(1).build(); + + /** + * Command line parser + */ + CommandLineParser _parser= new DefaultParser(); + + + public CLIOptionProcessed() { + + } + + /** + * + * @param args + * @throws Exception + */ + public CLIOptionProcessed(String[] args) { + /*required parameters*/ + this._options.addOption(_inputFolder); + this._options.addOption(_outputFolder); + this._options.addOption(_chrSize); + this._options.addOption(_interOrIntra); + + /*optional parameters*/ + this._options.addOption(_resolution); + this._options.addOption(_deleteImage); + this._options.addOption(_fdr); + this._options.addOption(_nbZero); + this._options.addOption(_sizeImage); + this._options.addOption(_cpu); + this._options.addOption(_gaussianStrength); + this._options.addOption(_threshold); + this._options.addOption(_diagonal); + this._options.addOption(_factor); + this._options.addOption(_max); + this._options.addOption(_min); + this._options.addOption(_saturated); + this._options.addOption(_isDroso); + + try { + _cmd = _parser.parse(this._options, args,false); + } + catch (ParseException exp ){ + System.out.println("\n"+exp.getMessage()+"\n"); + CLIHelper.CmdHelpProcessed(); + }catch (IllegalArgumentException exp){ + System.out.println( exp.getMessage()); + System.exit(1); + } + + } + + /** + * + * @return + */ + public CommandLine getCommandLine() { + return _cmd; + } + + /** + * + * @return + */ + public Options getOptions() { + return _options; + } + +} diff --git a/src/main/java/plop/dumpProcessing/CoolerDumpInter.java b/src/main/java/plop/dumpProcessing/CoolerDumpInter.java new file mode 100644 index 0000000..2de77c5 --- /dev/null +++ b/src/main/java/plop/dumpProcessing/CoolerDumpInter.java @@ -0,0 +1,107 @@ +package plop.dumpProcessing; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; + +/** + * dump data contained in mcool file via cooler tools + * + * https://github.com/open2c/cooler + * Abdennur, N., and Mirny, L. (2019). Cooler: scalable storage for Hi-C data and other genomically labeled arrays. Bioinformatics. doi: 10.1093/bioinformatics/btz540. + */ +public class CoolerDumpInter { + + + /** String to stock the error if need of juicerbox_tools*/ + private String _logError = ""; + /** String for the log*/ + private String _log = ""; + /** path to the hic file or url link*/ + private String _coolFile; + /** List of doucle to stock the expected vector*/ + private ArrayList _lExpected = new ArrayList(); + /** path to cooler tools*/ + private String _cooler ; + + + /** + * Constructor of this class to iniatilise the different variables + * + * @param cooler path to cooler bin + * @param coolFile path of mcool file + */ + public CoolerDumpInter(String cooler, String coolFile) { + this._coolFile = coolFile; + this._cooler = cooler; + } + /** + * Method to dump the oMe matrix + * + * @param chr: String for the name of teh chromosome + * @param output: String path of the output + * @return boolean + * @throws IOException exception + */ + public boolean dumpObserved(String chr, String chr2, String output, int resolution) throws IOException{ + int exitValue=1; + Runtime runtime = Runtime.getRuntime(); + String obs = output.replaceAll(".txt", "_obs.txt"); + try { + String cool = this._coolFile+"::/resolutions/"+resolution; + String line = this._cooler+" dump "+cool+" --balanced -r "+chr+" -r2 "+ chr2+" -o "+obs +" --join --na-rep NaN"; + System.out.println(line); + this._log = this._log+"\n"+obs+"\t"+line; + Process process = runtime.exec(line); + + new ReturnFlux(process.getInputStream()).start(); + new ReturnFlux(process.getErrorStream()).start(); + exitValue=process.waitFor(); + } + catch (IOException | InterruptedException e) { e.printStackTrace();} + if(_logError!=""){ + System.out.println(_logError); + System.exit(0); + } + return exitValue==0; + } + + + + /** + * Class to run command line in java + * @author axel poulet + * + */ + public class ReturnFlux extends Thread { + + /** Flux to redirect */ + private InputStream _flux; + + /** + * Constructor of ReturnFlux + * @param flux + * flux to redirect + */ + private ReturnFlux(InputStream flux){this._flux = flux; } + + /** + * + */ + public void run(){ + try { + InputStreamReader reader = new InputStreamReader(this._flux); + BufferedReader br = new BufferedReader(reader); + String line=null; + while ( (line = br.readLine()) != null) { + if(!line.contains("WARN")) _logError = _logError+line+"\n"; + } + } + catch (IOException ioe){ + ioe.printStackTrace(); + } + } + } +} diff --git a/src/process/CoolerDumpData.java b/src/main/java/plop/dumpProcessing/CoolerDumpIntra.java similarity index 76% rename from src/process/CoolerDumpData.java rename to src/main/java/plop/dumpProcessing/CoolerDumpIntra.java index 9e8a354..e4c3396 100644 --- a/src/process/CoolerDumpData.java +++ b/src/main/java/plop/dumpProcessing/CoolerDumpIntra.java @@ -1,4 +1,4 @@ -package process; +package plop.dumpProcessing; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -12,7 +12,13 @@ import java.nio.file.Paths; import java.util.ArrayList; -public class CoolerDumpData { +/** + * dump data contained in mcool file via cooler tools + * + * https://github.com/open2c/cooler + * Abdennur, N., and Mirny, L. (2019). Cooler: scalable storage for Hi-C data and other genomically labeled arrays. Bioinformatics. doi: 10.1093/bioinformatics/btz540. + */ +public class CoolerDumpIntra { /** String to stock the error if need of juicerbox_tools*/ @@ -20,22 +26,20 @@ public class CoolerDumpData { /** String for the log*/ private String _log = ""; /** path to the hic file or url link*/ - private String _coolFile = ""; + private String _coolFile; /** List of doucle to stock the expected vector*/ private ArrayList _lExpected = new ArrayList(); + /** path to cooler tools*/ + private String _cooler ; + - private String _cooler = ""; - - /** * Constructor of this class to iniatilise the different variables - * - * @param juiceboxTools: String: path of juicertoolsBox - * @param hicFile: String: path to the HiC file - * @param norm: String: type of normalisation - * @param resolution: int: resolution of the bins + * + * @param cooler path to cooler bin + * @param coolFile path of mcool file */ - public CoolerDumpData(String cooler, String coolFile) { + public CoolerDumpIntra(String cooler, String coolFile) { this._coolFile = coolFile; this._cooler = cooler; } @@ -44,8 +48,8 @@ public CoolerDumpData(String cooler, String coolFile) { * * @param chr: String for the name of teh chromosome * @param output: String path of the output - * @return - * @throws IOException + * @return boolean + * @throws IOException exception */ public boolean dumpObservedMExpected(String chr, String output, int resolution) throws IOException{ int exitValue=1; @@ -62,8 +66,7 @@ public boolean dumpObservedMExpected(String chr, String output, int resolution) new ReturnFlux(process.getErrorStream()).start(); exitValue=process.waitFor(); } - catch (IOException e) { e.printStackTrace();} - catch (InterruptedException e) {e.printStackTrace();} + catch (IOException | InterruptedException e) { e.printStackTrace();} if(_logError!=""){ System.out.println(_logError); System.exit(0); @@ -79,7 +82,8 @@ public boolean dumpObservedMExpected(String chr, String output, int resolution) * * @param obs: String path with the file of the observed value * @param chr: name of the chr - * @throws IOException + * @param resolution resolution of interest + * @throws IOException exception */ private void observedMExpected(String obs, String chr, int resolution) throws IOException{ BufferedReader br = Files.newBufferedReader(Paths.get(obs), StandardCharsets.UTF_8); @@ -90,8 +94,8 @@ private void observedMExpected(String obs, String chr, int resolution) throws IO String [] tline = line.split("\t"); int dist = Math.abs((Integer.parseInt(tline[1])-Integer.parseInt(tline[4]))/resolution); if(!tline[7].equals("NaN")){ - double normalizedValue = ((Double.parseDouble(tline[7])*10000+1)/(this._lExpected.get(dist)*10000+1)); - double oMe = (Double.parseDouble(tline[7])*1000-this._lExpected.get(dist)*1000); + double normalizedValue = ((Double.parseDouble(tline[7])*1000000+1)/(this._lExpected.get(dist)*1000000+1)); + double oMe = (Double.parseDouble(tline[7])*1000000-this._lExpected.get(dist)*1000000); writer.write(tline[1]+"\t"+tline[4]+"\t"+oMe+"\t"+normalizedValue+"\n"); } } @@ -100,21 +104,15 @@ private void observedMExpected(String obs, String chr, int resolution) throws IO writer.close(); br.close(); } - - public void setExpected( ArrayList lExpected) {this._lExpected = lExpected;} /** - * getter of the logerror file if necessary - * - * @return return the String with the error - */ - public String getLogError(){ return this._logError;} - - /** - * getter of the log info if necessary - * @return return a String with the log info + * setter for expected vector + * + * @param lExpected list of expected value */ - public String getLog(){ return this._log;} + public void setExpected( ArrayList lExpected) {this._lExpected = lExpected;} + + /** * Class to run command line in java * @author axel poulet @@ -130,7 +128,7 @@ public class ReturnFlux extends Thread { * @param flux * flux to redirect */ - public ReturnFlux(InputStream flux){this._flux = flux; } + private ReturnFlux(InputStream flux){this._flux = flux; } /** * @@ -141,7 +139,7 @@ public void run(){ BufferedReader br = new BufferedReader(reader); String line=null; while ( (line = br.readLine()) != null) { - if(line.contains("WARN")== false) _logError = _logError+line+"\n"; + if(!line.contains("WARN")) _logError = _logError+line+"\n"; } } catch (IOException ioe){ diff --git a/src/utils/CoolerExpected.java b/src/main/java/plop/dumpProcessing/CoolerExpected.java similarity index 85% rename from src/utils/CoolerExpected.java rename to src/main/java/plop/dumpProcessing/CoolerExpected.java index 190676e..20ae4e0 100644 --- a/src/utils/CoolerExpected.java +++ b/src/main/java/plop/dumpProcessing/CoolerExpected.java @@ -1,4 +1,4 @@ -package utils; +package plop.dumpProcessing; import java.io.BufferedReader; import java.io.IOException; @@ -10,6 +10,9 @@ import java.util.ArrayList; import java.util.HashMap; +/** + * + */ public class CoolerExpected { /** String to stock the error if need of juicerbox_tools*/ @@ -17,16 +20,28 @@ public class CoolerExpected { /** String for the log*/ private String _log = ""; /** path to the hic file or url link*/ - private String _coolFile = ""; + private String _coolFile; /** List of doucle to stock the expected vector*/ - private int _resolution = 0; - private int _imgSize = 0; + private int _resolution ; + /** */ + private int _imgSize; + /** */ private String _expected; - private String _coolTools = ""; + /** */ + private String _coolTools; + /** */ private HashMap> _hashExpected = new HashMap>(); + /** */ private int _cpu; - - + + /** + * + * @param cooltools + * @param coolFile + * @param resolution + * @param imageSize + * @param cpu + */ public CoolerExpected(String cooltools, String coolFile, int resolution, int imageSize, int cpu){ _coolTools = cooltools; this._resolution = resolution; @@ -34,15 +49,20 @@ public CoolerExpected(String cooltools, String coolFile, int resolution, int ima this._coolFile = coolFile+"::/resolutions/"+this._resolution; _cpu = cpu; } - + + /** + * + * @param expectedFile + * @param imageSize + */ public CoolerExpected(String expectedFile, int imageSize){ this._imgSize = imageSize; this._expected = expectedFile; } + /** - * - * @param output - * @param resolution + * + * @param expected * @return */ public boolean dumpExpected(String expected){ @@ -83,9 +103,12 @@ public boolean dumpExpected(String expected){ return exitValue==0; } - - - + + + /** + * + * @throws IOException + */ public void parseExpectedFile() throws IOException { BufferedReader br = Files.newBufferedReader(Paths.get(_expected), StandardCharsets.UTF_8); String line = br.readLine(); @@ -122,34 +145,16 @@ public void parseExpectedFile() throws IOException { /** * getter of the expected matrix. * - * @param chr: String name of the chromosme - * @param output: path to the output - * @throws IOException + * @param chr: String name of the chromosome + * @return arrayList of double => vector of expected value + * @throws IOException exception */ public ArrayList getExpected(String chr) throws IOException{ return this._hashExpected.get(chr); } - - - /** - * getter of the logerror file if necessary - * - * @return return the String with the error - */ - public String getLogError(){ return this._logError;} - - /** - * getter of the log info if necessary - * @return return a String with the log info - */ - public String getLog(){ return this._log;} - /** - * Class to run command line in java - * @author axel poulet - * - */ + public class ReturnFlux extends Thread { /** Flux to redirect */ @@ -160,7 +165,7 @@ public class ReturnFlux extends Thread { * @param flux * flux to redirect */ - public ReturnFlux(InputStream flux){this._flux = flux; } + private ReturnFlux(InputStream flux){this._flux = flux; } /** * @@ -171,7 +176,7 @@ public void run(){ BufferedReader br = new BufferedReader(reader); String line=null; while ( (line = br.readLine()) != null) { - if(line.contains("WARN")== false) _logError = _logError+line+"\n"; + if(!line.contains("WARN")) _logError = _logError+line+"\n"; } } catch (IOException ioe){ diff --git a/src/main/java/plop/dumpProcessing/HicDumpInter.java b/src/main/java/plop/dumpProcessing/HicDumpInter.java new file mode 100644 index 0000000..2aab81a --- /dev/null +++ b/src/main/java/plop/dumpProcessing/HicDumpInter.java @@ -0,0 +1,118 @@ +package plop.dumpProcessing; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +/** + * Class aims to dump the data of the hic file. this class need juicer_toolbox.jar to obtain the raw data and does the 2D images which will represent the HiC matrix. + * If some error is detected a file log is created for that. + * At the end this class a file by step is created (coordinate1 coordinate2 hic_value). The file created if the oMe option is chose the subtraction Observed-Expected + * is done to obtain the value of the interaction between two bins. + * If observed is used the value will be the observed. + * + * You can also chosse the option of the normalisation for the hic matrix, the different normalisations are these one available in juicertoolnox.jar + * (https://github.com/theaidenlab/juicer/wiki). + * + * eg of commad line use : dump observed KR https://hicfiles.s3.amazonaws.com/hiseq/gm12878/in-situ/combined.hic 1:20480000:40960000 1:20480000:40960000 BP 10000 combined_10Kb.txt + * + * Neva C. Durand, Muhammad S. Shamim, Ido Machol, Suhas S. P. Rao, Miriam H. Huntley, Eric S. Lander, and Erez Lieberman Aiden. "Juicer provides a + * one-click system for analyzing loop-resolution Hi-C experiments." Cell Systems 3(1), 2016. + * + * @author axel poulet + * + */ +public class HicDumpInter { + + /** path of juiceBox */ + private String _juiceBoxTools; + /** path of the hic file*/ + private String _hicFile; + /** normalization method name*/ + private String _normalisation; + /** log*/ + private String _log = ""; + /** logError*/ + private String _logError = ""; + + /** + *Constructor + * + * @param juiceboxTools path to juicer tools + * @param hicFile path to the hic file + * @param norm normalization methode used + */ + public HicDumpInter(String juiceboxTools, String hicFile, String norm) { + this._juiceBoxTools = juiceboxTools; + this._normalisation = norm; + this._hicFile = hicFile; + } + + + /** + * + * @param chr1 string containing name and coordinate of interest eg: chr2+":"+startChr2+":"+end2 + * @param chr2 string containing name and coordinate of interest eg: chr2+":"+startChr2+":"+end2 + * @param obs string path output observed create + * @param resolution bin resolution + * @return boolean + * @throws IOException exception + */ + public boolean dumpObserved(String chr1, String chr2, String obs, int resolution) throws IOException { + int exitValue=1; + Runtime runtime = Runtime.getRuntime(); + try { + String line = "java"+" -jar "+this._juiceBoxTools+" dump observed "+this._normalisation+" "+this._hicFile+" "+chr1+" "+chr2+" BP "+resolution+" "+obs; + System.out.println(line); + this._log = this._log+"\n"+obs+"\t"+line; + Process process = runtime.exec(line); + + new HicDumpInter.ReturnFlux(process.getInputStream()).start(); + new HicDumpInter.ReturnFlux(process.getErrorStream()).start(); + exitValue=process.waitFor(); + } + catch (IOException | InterruptedException e) { e.printStackTrace();} + + if(_logError.contains("Exception")) { + System.out.println(_logError); + System.exit(0); + } + return exitValue==0; + } + + /** + * Class to run command line in java + * @author axel poulet + * + */ + public class ReturnFlux extends Thread { + + /** Flux to redirect */ + private InputStream _flux; + + /** + * Constructor of ReturnFlux + * @param flux + * flux to redirect + */ + private ReturnFlux(InputStream flux){this._flux = flux; } + + /** + * + */ + public void run(){ + try { + InputStreamReader reader = new InputStreamReader(this._flux); + BufferedReader br = new BufferedReader(reader); + String line=null; + while ( (line = br.readLine()) != null) { + if(!line.contains("WARN") && !line.contains("INFO")) _logError = _logError+line+"\n"; + } + } + catch (IOException ioe){ + ioe.printStackTrace(); + } + } + } +} diff --git a/src/process/DumpData.java b/src/main/java/plop/dumpProcessing/HicDumpIntra.java similarity index 87% rename from src/process/DumpData.java rename to src/main/java/plop/dumpProcessing/HicDumpIntra.java index 7c9b505..2986956 100644 --- a/src/process/DumpData.java +++ b/src/main/java/plop/dumpProcessing/HicDumpIntra.java @@ -1,4 +1,4 @@ -package process; +package plop.dumpProcessing; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -30,17 +30,17 @@ * @author axel poulet * */ -public class DumpData { +public class HicDumpIntra { /** String to stock the error if need of juicerbox_tools*/ private String _logError = ""; /** String for the log*/ private String _log = ""; /** String => normalisation to dump the data (NONE, KR, VC, VC_SQRT or NONE)*/ - private String _normalisation= ""; + private String _normalisation; /** path to the hic file or url link*/ - private String _hicFile = ""; + private String _hicFile; /** path to juicer_toolsbox.jars*/ - private String _juiceBoxTools = ""; + private String _juiceBoxTools ; /** List of doucle to stock the expected vector*/ private ArrayList _lExpected = new ArrayList(); @@ -49,11 +49,11 @@ public class DumpData { /** * Constructor of this class to iniatilise the different variables * - * @param juiceboxTools: String: path of juicertoolsBox + * @param juiceboxTools: String: path of juicertools * @param hicFile: String: path to the HiC file * @param norm: String: type of normalisation */ - public DumpData(String juiceboxTools,String hicFile, String norm) { + public HicDumpIntra(String juiceboxTools, String hicFile, String norm) { this._juiceBoxTools = juiceboxTools; this._normalisation = norm; this._hicFile = hicFile; @@ -64,8 +64,9 @@ public DumpData(String juiceboxTools,String hicFile, String norm) { * * @param chr: String for the name of teh chromosome * @param output: String path of the output - * @return - * @throws IOException + * @param resolution resolutionn of interest + * @return boolean + * @throws IOException exception */ public boolean dumpObservedMExpected(String chr, String output, int resolution) throws IOException{ int exitValue=1; @@ -80,8 +81,7 @@ public boolean dumpObservedMExpected(String chr, String output, int resolution) new ReturnFlux(process.getErrorStream()).start(); exitValue=process.waitFor(); } - catch (IOException e) { e.printStackTrace();} - catch (InterruptedException e) {e.printStackTrace();} + catch (IOException | InterruptedException e) { e.printStackTrace();} observedMExpected(obs,output,resolution); if(_logError.contains("Exception")) { System.out.println(_logError); @@ -97,7 +97,8 @@ public boolean dumpObservedMExpected(String chr, String output, int resolution) * * @param obs: String path with the file of the observed value * @param chr: name of the chr - * @throws IOException + * @param resolution resolution of interest + * @throws IOException exception */ private void observedMExpected(String obs, String chr, int resolution) throws IOException{ BufferedReader br = Files.newBufferedReader(Paths.get(obs), StandardCharsets.UTF_8); @@ -117,26 +118,14 @@ private void observedMExpected(String obs, String chr, int resolution) throws IO br.close(); } - - /** - * getter of the logerror file if necessary - * - * @return return the String with the error - */ - public String getLogError(){ return this._logError;} - - /** - * getter of the log info if necessary - * @return return a String with the log info - */ - public String getLog(){ return this._log;} - + /** * getter of the expected matrix. * * @param chr: String name of the chromosme * @param output: path to the output - * @return + * @param resolution resolution of interest + * @return boolean */ public boolean getExpected(String chr,String output,int resolution){ int exitValue=1; @@ -175,9 +164,10 @@ public boolean getExpected(String chr,String output,int resolution){ * * @param chr: String name of the chromosme * @param output: path to the output - * @return - * @throws IOException - * @throws InterruptedException + * @param resolution resolution of interest + * @return boolean + * @throws IOException exception + * @throws InterruptedException exception */ public boolean getNormVector(String chr,String output,int resolution) throws IOException, InterruptedException{ int exitValue=1; @@ -189,7 +179,7 @@ public boolean getNormVector(String chr,String output,int resolution) throws IOE new ReturnFlux(process.getErrorStream()).start(); process.getOutputStream(); exitValue=process.waitFor(); - if(_logError!="" && _logError.contains("Exception") == false){ + if(_logError!="" && !_logError.contains("Exception")){ System.out.println("VC vector not find, SIP is using "+this._normalisation+" for "+ chr+"\n"+_logError); runtime = Runtime.getRuntime(); _logError =""; @@ -231,7 +221,7 @@ public class ReturnFlux extends Thread { * @param flux * flux to redirect */ - public ReturnFlux(InputStream flux){this._flux = flux; } + private ReturnFlux(InputStream flux){this._flux = flux; } /** * @@ -240,9 +230,9 @@ public void run(){ try { InputStreamReader reader = new InputStreamReader(this._flux); BufferedReader br = new BufferedReader(reader); - String line=null; + String line; while ( (line = br.readLine()) != null) { - if(line.contains("WARN")== false && line.contains("INFO")== false) _logError = _logError+line+"\n"; + if(!line.contains("WARN") && !line.contains("INFO")) _logError = _logError+line+"\n"; } } catch (IOException ioe){ diff --git a/src/gui/GuiAnalysis.java b/src/main/java/plop/gui/GuiAnalysis.java similarity index 78% rename from src/gui/GuiAnalysis.java rename to src/main/java/plop/gui/GuiAnalysis.java index 2b623d9..dfee24b 100644 --- a/src/gui/GuiAnalysis.java +++ b/src/main/java/plop/gui/GuiAnalysis.java @@ -1,4 +1,4 @@ -package gui; +package plop.gui; import java.awt.Color; import java.awt.Container; import java.awt.Cursor; @@ -33,9 +33,9 @@ public class GuiAnalysis extends JFrame{ /** */ private Container _container; /** */ - private JButton _jbWorkDir = new JButton("Output directory"); + private JButton _jbOutputDir = new JButton("Output directory"); /** */ - private JButton _jbRawData = new JButton("Data (.hic, .mcool or SIP)"); + private JButton _jbInputDir = new JButton("Data (.hic, .mcool or SIP)"); /** */ private JButton _jbChrSize = new JButton("Chr size file"); /** */ @@ -82,6 +82,15 @@ public class GuiAnalysis extends JFrame{ private JRadioButton _jrbVC = new JRadioButton("VC"); /** */ private JRadioButton _jrbVC_sqrt = new JRadioButton("VC SQRT"); + + /** */ + private ButtonGroup _bIntraOrInter = new ButtonGroup(); + /** */ + private JRadioButton _jrbIntra = new JRadioButton("Intra"); + /** */ + private JRadioButton _jrbInter = new JRadioButton("Inter"); + + /** */ private JFormattedTextField _jtfMatrixSize = new JFormattedTextField(Number.class); /** */ @@ -95,11 +104,11 @@ public class GuiAnalysis extends JFrame{ /** */ private JFormattedTextField _jtfMax = new JFormattedTextField(Number.class); /** */ - private JFormattedTextField _jtfEnhanceContrast = new JFormattedTextField(Number.class); + private JFormattedTextField _jtfSaturatedPixel = new JFormattedTextField(Number.class); /** */ private JFormattedTextField _jtfNbZero = new JFormattedTextField(Number.class); /** */ - private JFormattedTextField _jtfNoiseTolerance = new JFormattedTextField(Number.class); + private JFormattedTextField _jtfThresholdMaxima = new JFormattedTextField(Number.class); /** */ private boolean _start = false; /** */ @@ -117,7 +126,7 @@ public class GuiAnalysis extends JFrame{ /** - * gui main + * java.plop.gui main * * @param args */ @@ -140,6 +149,7 @@ public GuiAnalysis(){ this.setResizable(false); this.setLocationByPlatform(true); this.setBackground(Color.LIGHT_GRAY); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this._container = getContentPane(); @@ -234,7 +244,7 @@ GridBagConstraints.NONE, new Insets(110, 160, 0, 0), 0, 0 label.setFont(new java.awt.Font("arial",2,11)); this._container.add(label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(133, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(138, 20, 0, 0), 0, 0 )); this._bNorm.add(this._jrbNone); @@ -247,59 +257,59 @@ GridBagConstraints.NONE, new Insets(133, 20, 0, 0), 0, 0 this._jrbVC_sqrt.setFont(new java.awt.Font("arial",2,11)); this._container.add(this._jrbNone,new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(130, 220, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(135, 220, 0, 0), 0, 0 )); this._container.add(this._jrbKR,new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE,new Insets(130, 290, 0, 0), 0, 0 + GridBagConstraints.NONE,new Insets(135, 290, 0, 0), 0, 0 )); this._container.add(this._jrbVC, new GridBagConstraints( 0,1, 0, 0, 0.0, 0.0,GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(130, 340, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(135, 340, 0, 0), 0, 0 )); this._container.add(this._jrbVC_sqrt, new GridBagConstraints( 0,1, 0, 0, 0.0, 0.0,GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(130, 390, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(135, 390, 0, 0), 0, 0 )); this._jrbKR.setSelected(true); ///////////////////////////////////////////////////////////////////////// label = new JLabel(); - label.setText("Data and Output directories : "); + label.setText("Input and Output directories : "); label.setFont(new java.awt.Font("arial",1,12)); this._container.add( label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(150, 10, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(155, 10, 0, 0), 0, 0 )); - this._jbRawData.setPreferredSize(new java.awt.Dimension(150, 21)); - this._jbRawData.setFont(new java.awt.Font("arial",2,10)); - this._container.add ( this._jbRawData, new GridBagConstraints( + this._jbInputDir.setPreferredSize(new java.awt.Dimension(150, 21)); + this._jbInputDir.setFont(new java.awt.Font("arial",2,10)); + this._container.add ( this._jbInputDir, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(165, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(175, 20, 0, 0), 0, 0 )); this._jtfRawData.setPreferredSize(new java.awt.Dimension(280, 21)); this._jtfRawData.setFont(new java.awt.Font("arial",2,10)); this._container.add(this._jtfRawData, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(165, 190, 0, 0),0, 0 + GridBagConstraints.NONE, new Insets(175, 190, 0, 0),0, 0 )); - this._jbWorkDir.setPreferredSize(new java.awt.Dimension(150, 21)); - this._jbWorkDir.setFont(new java.awt.Font("arial",2,10)); - this._container.add(this._jbWorkDir, new GridBagConstraints( + this._jbOutputDir.setPreferredSize(new java.awt.Dimension(150, 21)); + this._jbOutputDir.setFont(new java.awt.Font("arial",2,10)); + this._container.add(this._jbOutputDir, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0,GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(195, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(205, 20, 0, 0), 0, 0 )); this._jtfWorkDir.setPreferredSize(new java.awt.Dimension(280, 21)); this._jtfWorkDir.setFont(new java.awt.Font("arial",2,10)); this._container.add( this._jtfWorkDir, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(195, 190, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(205, 190, 0, 0), 0, 0 )); ////////////////////////////////////// @@ -308,7 +318,7 @@ GridBagConstraints.NONE, new Insets(195, 190, 0, 0), 0, 0 label.setFont(new java.awt.Font("arial",1,12)); this._container.add (label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(225, 10, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(235, 10, 0, 0), 0, 0 )); this._container.setLayout (gridBagLayout); label = new JLabel(); @@ -316,29 +326,29 @@ GridBagConstraints.NONE, new Insets(225, 10, 0, 0), 0, 0 label.setFont(new java.awt.Font("arial",2,11)); this._container.add( label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(245, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(258, 20, 0, 0), 0, 0 )); this._jtfMatrixSize.setText("2000"); this._jtfMatrixSize.setPreferredSize(new java.awt.Dimension(60, 21)); this._jtfMatrixSize.setFont(new java.awt.Font("arial",2,11)); this._container.add( this._jtfMatrixSize, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(243, 170, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(260, 170, 0, 0), 0, 0 )); this._container.setLayout (gridBagLayout); label = new JLabel(); - label.setText("Diag size (in bins):"); + label.setText("Diagonal size (in bins):"); label.setFont(new java.awt.Font("arial",2,11)); this._container.add(label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(270, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(283, 20, 0, 0), 0, 0 )); this._jtfDiagSize.setText("5"); this._jtfDiagSize.setPreferredSize(new java.awt.Dimension(60, 21)); this._jtfDiagSize.setFont(new java.awt.Font("arial",2,11)); this._container.add( this._jtfDiagSize, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(268, 170, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(285, 170, 0, 0), 0, 0 )); label = new JLabel(); @@ -346,7 +356,7 @@ GridBagConstraints.NONE, new Insets(268, 170, 0, 0), 0, 0 label.setFont(new java.awt.Font("arial",2,11)); this._container.add( label, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(295, 20, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(308, 20, 0, 0), 0, 0 )); this._jtfResolution.setText("5000"); @@ -354,24 +364,25 @@ GridBagConstraints.NONE, new Insets(295, 20, 0, 0), 0, 0 this._jtfResolution.setFont(new java.awt.Font("arial",2,11)); this._container.add( this._jtfResolution, new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(293, 170, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(310, 170, 0, 0), 0, 0 )); label = new JLabel(); - label.setText(" Multi resolution loop calling:"); + label.setText("Multi resolution loop calling:"); + label.setFont(new java.awt.Font("arial",1,12)); this._container.add(label,new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(225, 250, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(235, 250, 0, 0), 0, 0 )); this._checkbox2.setFont(new java.awt.Font("arial",2,12)); this._container.add(this._checkbox2,new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(250, 300, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(260, 300, 0, 0), 0, 0 )); this._checkbox5.setFont(new java.awt.Font("arial",2,12)); this._container.add(this._checkbox5,new GridBagConstraints( 0, 1, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE,new Insets(270, 300, 0, 0), 0, 0 + GridBagConstraints.NONE,new Insets(280, 300, 0, 0), 0, 0 )); //////////////////////////////////////////////////////////////////////////////// @@ -432,10 +443,10 @@ GridBagConstraints.NONE, new Insets(127, 150, 0, 0), 0, 0 GridBagConstraints.NONE, new Insets(130, 230, 0, 0), 0, 0 )); - this._jtfNoiseTolerance.setText("2800"); - this._jtfNoiseTolerance.setPreferredSize(new java.awt.Dimension(60, 21)); - this._jtfNoiseTolerance.setFont(new java.awt.Font("arial",2,11)); - this._container.add( this._jtfNoiseTolerance, new GridBagConstraints( + this._jtfThresholdMaxima.setText("2800"); + this._jtfThresholdMaxima.setPreferredSize(new java.awt.Dimension(60, 21)); + this._jtfThresholdMaxima.setFont(new java.awt.Font("arial",2,11)); + this._container.add( this._jtfThresholdMaxima, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(127, 430, 0, 0), 0, 0 )); @@ -473,17 +484,17 @@ GridBagConstraints.NONE, new Insets(157, 350, 0, 0), 0, 0 )); label = new JLabel(); - label.setText("% of satured pixel:"); + label.setText("% of saturated pixel:"); label.setFont(new java.awt.Font("arial",2,11)); this._container.add( label, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(190, 20, 0, 0), 0, 0 )); - this._jtfEnhanceContrast.setText("0.01"); - this._jtfEnhanceContrast.setPreferredSize(new java.awt.Dimension(60, 21)); - this._jtfEnhanceContrast.setFont(new java.awt.Font("arial",2,11)); - this._container.add( this._jtfEnhanceContrast, new GridBagConstraints( + this._jtfSaturatedPixel.setText("0.01"); + this._jtfSaturatedPixel.setPreferredSize(new java.awt.Dimension(60, 21)); + this._jtfSaturatedPixel.setFont(new java.awt.Font("arial",2,11)); + this._container.add( this._jtfSaturatedPixel, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(187, 150, 0, 0), 0, 0 )); @@ -521,24 +532,48 @@ GridBagConstraints.NONE, new Insets(217, 350, 0, 0), 0, 0 )); label = new JLabel(); - label.setText("If is droso or like droso HiC map:"); + label.setText("If it is D. mel or like D. mel HiC map:"); label.setFont(new java.awt.Font("arial",1,12)); this._container.add(label, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(250, 10, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(245, 10, 0, 0), 0, 0 )); this._jCbIsDroso.setFont(new java.awt.Font("arial",2,11)); this._container.add(this._jCbIsDroso,new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE,new Insets(268, 20, 0, 0), 0, 0 + GridBagConstraints.NONE,new Insets(242, 230, 0, 0), 0, 0 )); - + + + label = new JLabel(); + label.setText("Type of java.plop.loops (inter or intra chromosomal):"); + label.setFont(new java.awt.Font("arial",1,12)); + this._container.add(label, new GridBagConstraints( + 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, new Insets(285, 10, 0, 0), 0, 0 + )); + + this._bIntraOrInter.add(this._jrbInter); + this._bIntraOrInter.add(this._jrbIntra); + this._jrbInter.setFont(new java.awt.Font("arial",2,12)); + this._jrbIntra.setFont(new java.awt.Font("arial",2,12)); + + this._container.add(this._jrbIntra,new GridBagConstraints( + 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE, new Insets(282, 270, 0, 0), 0, 0 + )); + this._container.add(this._jrbInter,new GridBagConstraints( + 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, + GridBagConstraints.NONE,new Insets(282, 340, 0, 0), 0, 0 + )); + this._jrbIntra.setSelected(true); + this._checkboxDeleteTif.setFont(new java.awt.Font("arial",1,12)); this._container.add(this._checkboxDeleteTif,new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE,new Insets(330, 10, 0, 0), 0, 0 + GridBagConstraints.NONE,new Insets(325, 260, 0, 0), 0, 0 )); label = new JLabel(); @@ -546,14 +581,14 @@ GridBagConstraints.NONE,new Insets(330, 10, 0, 0), 0, 0 label.setFont(new java.awt.Font("arial",1,12)); this._container.add( label, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(300, 10, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(330, 10, 0, 0), 0, 0 )); this._jtfCpu.setText("1"); this._jtfCpu.setPreferredSize(new java.awt.Dimension(60, 21)); this._container.add( this._jtfCpu, new GridBagConstraints( 0, 2, 0, 0, 0.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.NONE, new Insets(298, 140, 0, 0), 0, 0 + GridBagConstraints.NONE, new Insets(328, 140, 0, 0), 0, 0 )); this._jbStart.setPreferredSize(new java.awt.Dimension(120, 21)); @@ -572,8 +607,10 @@ GridBagConstraints.NONE,new Insets(365, 10, 0, 0), 0, 0 this._jrbHic.addActionListener(hic); this._jrbProcessed.addActionListener(hic); this._jrbCool.addActionListener(hic); + this._jrbInter.addActionListener(hic); + this._jrbIntra.addActionListener(hic); WorkDirectoryListener wdListener = new WorkDirectoryListener(); - this._jbWorkDir.addActionListener(wdListener); + this._jbOutputDir.addActionListener(wdListener); FileListener chr = new FileListener(this._jtfChrSize); this._jbChrSize.addActionListener(chr); FileListener juice = new FileListener(this._jtfBoxTools); @@ -583,7 +620,7 @@ GridBagConstraints.NONE,new Insets(365, 10, 0, 0), 0, 0 FileListener cooltools = new FileListener(this._jtfCoolTools); this._jbCoolTools.addActionListener(cooltools); RawDataDirectoryListener ddListener = new RawDataDirectoryListener(this,this._jtfRawData); - this._jbRawData.addActionListener(ddListener); + this._jbInputDir.addActionListener(ddListener); QuitListener quitListener = new QuitListener(this); this._jbQuit.addActionListener(quitListener); StartListener startListener = new StartListener(this); @@ -619,7 +656,7 @@ public double getMax(){ } /** - * getter of the nb of zero allow around a detected loops + * getter of the nb of zero allow around a detected java.plop.loops * @return int nb of zero */ public int getNbZero(){ @@ -649,8 +686,8 @@ public double getMin(){ * * @return double */ - public double getEnhanceSignal(){ - String x = this._jtfEnhanceContrast.getText(); + public double getSaturatedPixel(){ + String x = this._jtfSaturatedPixel.getText(); return Double.parseDouble(x.replaceAll(",", ".")); } @@ -670,8 +707,8 @@ public int getFactorChoice(){ * threshold for the regional maxima detection * @return int */ - public int getNoiseTolerance(){ - String x = this._jtfNoiseTolerance.getText(); + public int getThresholdMaxima(){ + String x = this._jtfThresholdMaxima.getText(); return Integer.parseInt(x.replaceAll(",", ".")); } /** @@ -684,7 +721,7 @@ public double getGaussian(){ } /** - * size of the diag, all the loops detected inside this size will be removed + * size of the diag, all the java.plop.loops detected inside this size will be removed * @return int diag size */ public int getDiagSize(){ @@ -703,7 +740,7 @@ public int getDiagSize(){ * getter of the input path (hic file or SIP) * @return String input path */ - public String getRawDataDir(){ return this._jtfRawData.getText();} + public String getInput(){ return this._jtfRawData.getText();} /** * getter of the chrSize file path @@ -715,7 +752,7 @@ public int getDiagSize(){ * getter of the juicerToolsBox.jar path * @return String path */ - public String getJuiceBox(){ return this._jtfBoxTools.getText();} + public String getJuicerTool(){ return this._jtfBoxTools.getText();} /** * getter of the juicerToolsBox.jar path @@ -730,7 +767,7 @@ public int getDiagSize(){ public String getCooler(){ return this._jtfCooler.getText();} /** - * boolean if true start was pushed else keep the gui active + * boolean if true start was pushed else keep the java.plop.gui active * @return */ public boolean isStart(){ return this._start;} @@ -751,6 +788,16 @@ public int getDiagSize(){ * @return */ public boolean isHic(){ return this._jrbHic.isSelected();} + /** + * + * @return + */ + public boolean isInter(){ return this._jrbInter.isSelected();} + /** + * + * @return + */ + public boolean isIntra(){ return this._jrbIntra.isSelected();} /** * @@ -824,57 +871,111 @@ class RBHicListener implements ActionListener{ * @param gui */ public RBHicListener (GuiAnalysis gui){ _gui = gui; } - + + /** + * + */ + private void changeInter(){ + _gui._jtfThresholdMaxima.setText("0.01"); + _gui._jtfFdr.setText("0.025"); + _gui._jtfResolution.setText("100000"); + _gui._jtfMatrixSize.setText("500"); + _gui._jtfGaussian.setText("1"); + _gui._jtfMax.setEditable(false); + _gui._jtfMin.setEditable(false); + _gui._jtfSaturatedPixel.setEditable(false); + _gui._jtfDiagSize.setEditable(false); + _gui._jtfSaturatedPixel.setEditable(false); + _gui._checkbox2.setEnabled(false); + _gui._checkbox5.setEnabled(false); + _gui._jCbIsDroso.setEnabled(false); + } + /** - * manage the access of the different gui element on function of the paramter choose + * + */ + private void changeIntra(){ + _gui._jtfThresholdMaxima.setText("2800"); + _gui._jtfFdr.setText("0.001"); + _gui._jtfResolution.setText("5000"); + _gui._jtfMatrixSize.setText("2000"); + _gui._jtfGaussian.setText("1.5"); + _gui._jtfMax.setEditable(true); + _gui._jtfMin.setEditable(true); + _gui._jtfSaturatedPixel.setEditable(true); + _gui._jtfDiagSize.setEditable(true); + _gui._jtfSaturatedPixel.setEditable(true); + _gui._checkbox2.setEnabled(true); + _gui._checkbox5.setEnabled(true); + _gui._jCbIsDroso.setEnabled(true); + } + + /** + * + */ + private void changeHic(){ + _gui._jrbInter.setEnabled(true); + _gui._jrbIntra.setEnabled(true); + if(_gui.isIntra())changeIntra(); + else if(_gui.isInter()) changeInter(); + _gui._jrbVC_sqrt.setEnabled(true); + _gui._jrbVC.setEnabled(true); + _gui._jrbNone.setEnabled(true); + _gui._jrbKR.setEnabled(true); + _gui._jtfBoxTools.setEnabled(true); + _gui._jbBoxTools.setEnabled(true); + _gui._jtfCoolTools.setEnabled(false); + _gui._jbCoolTools.setEnabled(false); + _gui._jtfCooler.setEnabled(false); + _gui._jbCooler.setEnabled(false); + } + + private void changeProcessed(){ + _gui._jrbInter.setEnabled(true); + _gui._jrbIntra.setEnabled(true); + if(_gui.isIntra())changeIntra(); + else if(_gui.isInter()) changeInter(); + _gui._jrbVC_sqrt.setEnabled(false); + _gui._jrbVC.setEnabled(false); + _gui._jrbNone.setEnabled(false); + _gui._jrbKR.setEnabled(false); + _gui._jtfBoxTools.setEnabled(false); + _gui._jbBoxTools.setEnabled(false); + _gui._jtfCoolTools.setEnabled(false); + _gui._jbCoolTools.setEnabled(false); + _gui._jtfCooler.setEnabled(false); + _gui._jbCooler.setEnabled(false); + } + + private void changeCool(){ + _gui._jrbIntra.isSelected(); + _gui._jrbInter.setEnabled(false); + _gui._jrbIntra.setEnabled(false); + + changeIntra(); + _gui._jrbVC_sqrt.setEnabled(false); + _gui._jrbVC.setEnabled(false); + _gui._jrbNone.setEnabled(false); + _gui._jrbKR.setEnabled(false); + _gui._jtfBoxTools.setEnabled(false); + _gui._jbBoxTools.setEnabled(false); + _gui._jtfCoolTools.setEnabled(true); + _gui._jbCoolTools.setEnabled(true); + _gui._jtfCooler.setEnabled(true); + _gui._jbCooler.setEnabled(true); + } + + /** + * manage the access of the different java.plop.gui element on function of the paramter choose */ public void actionPerformed(ActionEvent actionEvent){ - if (_gui.isHic()){ - _gui._jrbVC_sqrt.setEnabled(true); - _gui._jrbVC.setEnabled(true); - _gui._jrbNone.setEnabled(true); - _gui._jrbKR.setEnabled(true); - _gui._jtfBoxTools.setEnabled(true); - _gui._jbBoxTools.setEnabled(true); - _gui._jtfMax.setEditable(true); - _gui._jtfMin.setEditable(true); - _gui._jtfEnhanceContrast.setEditable(true); - _gui._jtfCoolTools.setEnabled(false); - _gui._jbCoolTools.setEnabled(false); - _gui._jtfCooler.setEnabled(false); - _gui._jbCooler.setEnabled(false); - }else if(_gui.isProcessed()){ - _gui._jrbVC_sqrt.setEnabled(false); - _gui._jrbVC.setEnabled(false); - _gui._jrbNone.setEnabled(false); - _gui._jrbKR.setEnabled(false); - _gui._jtfBoxTools.setEnabled(false); - _gui._jbBoxTools.setEnabled(false); - _gui._jtfCoolTools.setEnabled(false); - _gui._jbCoolTools.setEnabled(false); - _gui._jtfCooler.setEnabled(false); - _gui._jbCooler.setEnabled(false); - _gui._jtfMax.setEditable(true); - _gui._jtfNbZero.setEnabled(true); - _gui._jtfMin.setEditable(true); - _gui._jtfEnhanceContrast.setEditable(true); - }else if(_gui.isCool()){ - _gui._jrbVC_sqrt.setEnabled(false); - _gui._jrbVC.setEnabled(false); - _gui._jrbNone.setEnabled(false); - _gui._jrbKR.setEnabled(false); - _gui._jtfBoxTools.setEnabled(false); - _gui._jbBoxTools.setEnabled(false); - _gui._jtfCoolTools.setEnabled(true); - _gui._jbCoolTools.setEnabled(true); - _gui._jtfCooler.setEnabled(true); - _gui._jbCooler.setEnabled(true); - _gui._jtfMax.setEditable(true); - _gui._jtfNbZero.setEnabled(true); - _gui._jtfMin.setEditable(true); - _gui._jtfEnhanceContrast.setEditable(true); - - } + if (_gui.isHic()) { + changeHic(); + }else if(_gui.isProcessed()){ + changeProcessed(); + }else if(_gui.isCool()) { + changeCool(); + } } } @@ -894,7 +995,7 @@ class StartListener implements ActionListener { */ public StartListener (GuiAnalysis gui){ _gui = gui; } /** - * Test all the box, condition etc before to allow the program to run and dispose the gui + * Test all the box, condition etc before to allow the program to run and dispose the java.plop.gui */ public void actionPerformed(ActionEvent actionEvent){ if (_jtfWorkDir.getText().isEmpty() || _jtfRawData.getText().isEmpty() || _gui._jtfChrSize.getText().isEmpty()){ @@ -907,11 +1008,11 @@ public void actionPerformed(ActionEvent actionEvent){ null,"You did not choose a Juicer_box_tools.jar path", "Error", JOptionPane.ERROR_MESSAGE ); - }else if(_gui._jtfDiagSize.getText().matches("[a-zA-Z]") || _gui._jtfEnhanceContrast.getText().matches("[a-zA-Z]") || + }else if(_gui._jtfDiagSize.getText().matches("[a-zA-Z]") || _gui._jtfSaturatedPixel.getText().matches("[a-zA-Z]") || _gui._jtfGaussian.getText().matches("[a-zA-Z]") || _gui._jtfMatrixSize.getText().matches("[a-zA-Z]") || _gui._jtfMax.getText().matches("[a-zA-Z]") || _gui._jtfMin.getText().matches("[a-zA-Z]") || _gui._jtfResolution.getText().matches("[a-zA-Z]") || _gui._jtfNbZero.getText().matches("[a-zA-Z]") || - _gui._jtfNoiseTolerance.getText().matches("[a-zA-Z]")|| _gui._jtfCpu.getText().matches("[a-zA-Z]")){ + _gui._jtfThresholdMaxima.getText().matches("[a-zA-Z]")|| _gui._jtfCpu.getText().matches("[a-zA-Z]")){ JOptionPane.showMessageDialog( null, "some alphabetic character detected in integer or float paramters", "Error", JOptionPane.ERROR_MESSAGE @@ -943,7 +1044,7 @@ class QuitListener implements ActionListener { */ public QuitListener (GuiAnalysis gui){ _gui = gui; } /** - * dipose the gui and quit the program + * dipose the java.plop.gui and quit the program */ public void actionPerformed(ActionEvent actionEvent){ _gui.dispose(); diff --git a/src/gui/Progress.java b/src/main/java/plop/gui/Progress.java similarity index 90% rename from src/gui/Progress.java rename to src/main/java/plop/gui/Progress.java index 9ee3db4..4ca67d5 100644 --- a/src/gui/Progress.java +++ b/src/main/java/plop/gui/Progress.java @@ -1,4 +1,4 @@ -package gui; +package plop.gui; import java.awt.BorderLayout; import javax.swing.JFrame; @@ -37,5 +37,5 @@ public Progress(String title, int nbChromo){ * * @param args */ - public static void main(String[] args){ new Progress("test", 22);} + public static void main(String[] args){ new Progress("java/plop/test", 22);} } \ No newline at end of file diff --git a/src/process/CallLoops.java b/src/main/java/plop/loops/CallLoops.java similarity index 78% rename from src/process/CallLoops.java rename to src/main/java/plop/loops/CallLoops.java index 58ff415..a391489 100644 --- a/src/process/CallLoops.java +++ b/src/main/java/plop/loops/CallLoops.java @@ -1,4 +1,4 @@ -package process; +package plop.loops; import java.io.File; import java.io.IOException; @@ -9,16 +9,11 @@ import ij.io.FileSaver; import inra.ijpb.morphology.Morphology; import inra.ijpb.morphology.Strel; -import utils.CoordinatesCorrection; -import utils.FilterLoops; -import utils.FindMaxima; -import utils.SIPObject; -import utils.ImageProcessingMethod; -import utils.Loop; -import utils.PeakAnalysisScore; +import plop.sip.SIPIntra; +import plop.utils.*; /** - * Class with all the methods to call the reginal maxima in the images and filter and write the output loops file list + * Class with all the methods to call the reginal maxima in the images and filter and write the output java.plop.loops file list * * @author axel poulet * @@ -31,32 +26,33 @@ public class CallLoops { private double _min; /** Strength of the max filter*/ private double _max; - /** % of staurated pixel after enhance contrast*/ + /** % of saturated pixel after enhance contrast*/ private double _saturatedPixel; /** Image size*/ - private int _matrixSize = 0; + private int _matrixSize; /** Resolution of the bin dump in base*/ private int _resolution; /** Threshold for the maxima detection*/ - private int _thresholdMaxima; + private double _thresholdMaxima; /** Diage size to removed maxima close to diagonal*/ private int _diagSize; - /** Size of the step to process each chr (step = matrixSize/2)*/ + /** Size of the step to java.plop.process each chr (step = matrixSize/2)*/ private int _step; /** Number of pixel = 0 allowed around the loop*/ private int _nbZero = -1; /** struturing element for the MM method used (MorpholibJ)*/ private Strel _strel = Strel.Shape.SQUARE.fromRadius(40); /** image background value*/ - private float _backgroudValue = (float) 0.25; - private boolean _isCooler = false; + private float _backgroudValue; + /** boolean if true => mcool file in input */ + private boolean _isCooler; /** * Constructor * * @param sip SIPOject */ - public CallLoops(SIPObject sip){ + public CallLoops(SIPIntra sip){ this._gauss = sip.getGauss(); this._min = sip.getMin(); this._max= sip.getMax(); @@ -64,28 +60,29 @@ public CallLoops(SIPObject sip){ this._matrixSize = sip.getMatrixSize(); this._resolution = sip.getResolution(); this._thresholdMaxima = sip.getThresholdMaxima(); - this._diagSize = sip.getDiagSize(); + this._diagSize = sip.getDiagonalSize(); this._step = sip.getStep(); this._nbZero = sip.getNbZero(); this._isCooler = sip.isCooler(); + _backgroudValue = (float) 0.25; //System.out.println("gauss:"+this._gauss+" min:"+this._min+" max:"+_max+" sat:"+_saturatedPixel+ //" matrix:"+_matrixSize+" res:"+_resolution+" thresh:"+_thresholdMaxima+" diag:"+_diagSize+ //" step:"+_step+" nbZero:"+_nbZero); } /** - * Detect loops methods - * detect the loops at two different resolution, initial resolution + 2 fold bigger - * call the loops first in the smaller resolution + * Detect java.plop.loops methods + * detect the java.plop.loops at two different resolution, initial resolution + 2 fold bigger + * call the java.plop.loops first in the smaller resolution * then making image with bigger resolution and fill no Zero list * faire un gros for deguelasse por passer les faceteur de grossissement seulement si listDefacteur > 1. * make and save image at two differents resolution (m_resolution and m_resolution*2) * if there is a lot pixel at zero in the images adapt the threshold for the maxima detection - * @param fileList - * @param chr - * @param normVector - * @return - * @throws IOException + * @param fileList list of File + * @param chr chr name + * @param normVector hashMap normVector containing biased coordinate + * @return HashMap loop name => Loop Object + * @throws IOException exception */ public HashMap detectLoops(File[] fileList, String chr,HashMap normVector) throws IOException{ CoordinatesCorrection coord = new CoordinatesCorrection(); @@ -104,12 +101,12 @@ public HashMap detectLoops(File[] fileList, String chr,HashMap temp = findLoop.findloop(numImage, this._nbZero,imgRaw, this._backgroudValue); + HashMap temp = findLoop.findLoop(numImage, this._nbZero,imgRaw, this._backgroudValue); PeakAnalysisScore pas = new PeakAnalysisScore(imgNorm,temp); pas.computeScore(); @@ -123,7 +120,7 @@ public HashMap detectLoops(File[] fileList, String chr,HashMap Loop Object + * @throws IOException exception + */ + public HashMap detectLoops(File[] fileList, String chrName1, String chrName2){ + CoordinatesCorrection coord = new CoordinatesCorrection(); + //System.out.println(outdir+" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + listOfFiles.length); + HashMap hLoop = new HashMap<> (); + for (int i = 0; i col = computeSumCol(img); + ArrayList row = computeSumRow(img); + + ImagePlus imageDiff = imgDiff(img,imgPath); + FindMaxima findMaxima = new FindMaxima( imageDiff, chrName1,chrName2, _noiseTolerance, _resolution,_gaussian,_nbZero); + HashMap temp = findMaxima.findLoopInter(imgPath); + filterLoop(col,row,temp); + PeakAnalysisScore pas = new PeakAnalysisScore(img,temp); + pas.computeScore(); + coord.setData(hLoop); + coord.imageToGenomeCoordinate(temp,name[name.length-1]); + hLoop = coord.getData(); + //System.out.println(hLoop.size()+" temp "+ temp.size()); + } + } + return hLoop; + } + + /** + * Create and save the diff image. + * for each pixel compute the new value computing the average subtraction between the pixel of interest and all + * pixel inside the neighbor 3 + * + * @param imagePlusInput imagePlus raw + * @param pathFile path to the imagePlus raw + * @return the diff ImagePlus + */ + private ImagePlus imgDiff(ImagePlus imagePlusInput, String pathFile){ + + ImageProcessor ip = imagePlusInput.getProcessor(); + + + + FloatProcessor ipDiff = new FloatProcessor(ip.getWidth(), ip.getHeight()); + + int nbPixel = 48; + int x = 3; + + for(int i = 0; i < ip.getWidth(); ++i){ + for(int j = 0; j < ip.getHeight(); ++j){ + float sum = 0; + float valueA = ip.getf(i, j); + if (Double.isNaN(ip.getf(i, j))) valueA = 0; + for (int ii = i - x; ii < i + x; ++ii) { + for (int jj = j - x; jj < j + x; ++jj) { + if ((i != ii || j != jj) && ii >= 0 && jj >= 0 && ii < ip.getWidth() && jj < ip.getHeight()) { + float valueB = ip.getf(ii, jj); + if (Double.isNaN(ip.getf(ii, jj))) valueB = 0; + sum = sum + (valueA - valueB); + } + } + }ipDiff.setf(i,j,sum/nbPixel); + } + } + + ImagePlus img = new ImagePlus(); + img.setProcessor(ipDiff); + + pathFile = pathFile.replace(".tif","_diff.tif"); + saveFile(img, pathFile); + return img; + + } + + private void filterLoop(ArrayList col , ArrayList row, HashMap temp) { + + double threshLowCol = this.computeAvg(col) - this.computeStdDev(col, this.computeAvg(col)) * 1.5; + double threshHighCol = this.computeAvg(col) + this.computeStdDev(col, this.computeAvg(col)); + double threshLowRow = this.computeAvg(row) - this.computeStdDev(row, this.computeAvg(row)) * 1.5; + double threshHighRow = this.computeAvg(row) + this.computeStdDev(row, this.computeAvg(row)); + System.out.println( threshLowCol + "\t" + threshHighCol + "\t" + threshLowRow + "\t" + threshHighRow); + Set arrayKey = temp.keySet(); + Iterator it = arrayKey .iterator(); + + while (it.hasNext()) { + String key = it.next(); + Loop loop = temp.get(key); + int i = loop.getX(); + int j = loop.getY(); + if (col.get(i) > threshLowCol && col.get(i) < threshHighCol && row.get(j) > threshLowRow && row.get(j) < threshHighRow) { + } + } + } + + /** + * + * @param plop + * @return + */ + private double computeAvg(ArrayList plop){ + double sum = 0; + for(int i = 0; i < plop.size(); ++i){ + sum = sum + plop.get(i); + } + return sum/plop.size(); + } + + + /** + * + * @param plop + * @param avg + * @return + */ + private double computeStdDev(ArrayList plop, double avg){ + double sum = 0; + for(int i = 0; i < plop.size(); ++i){ + sum = sum + (plop.get(i)-avg)*(plop.get(i)-avg); + } + return Math.sqrt(sum/plop.size()); + } + + + /** + * + * @param + * @return + */ + ArrayList computeSumRow(ImagePlus img){ + ImageProcessor ip = img.getProcessor(); + ArrayList plop = new ArrayList<>(); + for(int i = 0; i < ip.getHeight(); ++i) { + double sum = 0; + for (int j = 0; j < ip.getWidth(); ++j) { + double valueA = ip.getf(j, i); + if (Double.isNaN(ip.getf(j, i))) valueA = 0; + sum = sum + valueA ; + } + plop.add(sum); + } + return plop; + } + + /** + * + * @param + * @return + */ + ArrayList computeSumCol(ImagePlus img){ + ImageProcessor ip = img.getProcessor(); + ArrayList plop = new ArrayList<>(); + for(int i = 0; i < ip.getWidth(); ++i) { + double sum = 0; + for (int j = 0; j < ip.getHeight(); ++j) { + double valueA = ip.getf(i, j); + if (Double.isNaN(ip.getf(i, j))) valueA = 0; + sum = sum + valueA ; + } + plop.add(sum); + } + return plop; + } + + /** + * Save the image file + * + * @param imagePlusInput image to save + * @param pathFile path to save the image + */ + private void saveFile ( ImagePlus imagePlusInput, String pathFile){ + FileSaver fileSaver = new FileSaver(imagePlusInput); + fileSaver.saveAsTiff(pathFile); + } + + +} diff --git a/src/utils/FilterLoops.java b/src/main/java/plop/loops/FilterLoops.java similarity index 90% rename from src/utils/FilterLoops.java rename to src/main/java/plop/loops/FilterLoops.java index 2bd3403..f83f9d6 100644 --- a/src/utils/FilterLoops.java +++ b/src/main/java/plop/loops/FilterLoops.java @@ -1,4 +1,4 @@ -package utils; +package plop.loops; import java.util.ArrayList; import java.util.HashMap; @@ -6,19 +6,18 @@ import java.util.Set; /** - * Method to filter the loops close to white strip or loops which don't reach the different threshold filter + * Method to filter the java.plop.loops close to white strip or java.plop.loops which don't reach the different threshold filter * @author axel poulet * */ public class FilterLoops { - /** loops resoluiton*/ + /** java.plop.loops resoluiton*/ private int _resolution; /** - * Constructor - * @param resolution - * @param normVector + * Constructor + * @param resolution loop resolution */ public FilterLoops(int resolution){ this._resolution = resolution; @@ -26,7 +25,7 @@ public FilterLoops(int resolution){ /** - * Remove loops which doesn't respect the rule + * Remove java.plop.loops which doesn't respect the rule * * @param input loop collection before correction * @return loop collection after correction @@ -54,8 +53,8 @@ public HashMap removedBadLoops(HashMap input){ /** * Removed loop close to white strip * - * @param hLoop loop collection before correction of the loops - * @return loop collection sfter correction of the loops + * @param hLoop loop collection before correction of the java.plop.loops + * @return loop collection sfter correction of the java.plop.loops */ public HashMap removedLoopCloseToWhiteStrip(HashMap hLoop, HashMap normVector){ //System.out.println("plop "+hLoop.size()+" debut Filter"); @@ -120,8 +119,8 @@ public HashMap removedLoopCloseToWhiteStrip(HashMap hL /** * Removed loop close to white strip * - * @param hLoop loop collection before correction of the loops - * @return loop collection sfter correction of the loops + * @param hLoop loop collection before correction of the java.plop.loops + * @return loop collection sfter correction of the java.plop.loops */ public HashMap removedLoopCloseToWhiteStrip(HashMap hLoop){ //System.out.println("plop "+hLoop.size()+" debut Filter"); @@ -177,8 +176,8 @@ public HashMap removedLoopCloseToWhiteStrip(HashMap hL return hLoop; } /** - * Removed loops close to biased HiC signal - * @param loop Loop to test + * Removed java.plop.loops close to biased HiC signal + * @param loop Loop to java.plop.test * @return boolean true if loop have to be removed else false */ private boolean removedVectoNorm(Loop loop, HashMap normVector){ @@ -213,8 +212,8 @@ else if(loop.getResolution() == this._resolution*5){ /** - * Remove overlapping loops - * @param loop loop to test + * Remove overlapping java.plop.loops + * @param loop loop to java.plop.test * @param input loop collection * @param removed arrayList of loop * @return removed arrayList of loop diff --git a/src/utils/Loop.java b/src/main/java/plop/loops/Loop.java similarity index 81% rename from src/utils/Loop.java rename to src/main/java/plop/loops/Loop.java index fd97915..7592cba 100644 --- a/src/utils/Loop.java +++ b/src/main/java/plop/loops/Loop.java @@ -1,9 +1,9 @@ -package utils; +package plop.loops; import java.util.ArrayList; /** - * Class making loops object with its coordinate, value, and parameters + * Class making java.plop.loops object with its coordinate, value, and parameters * * @author axel poulet * @@ -11,7 +11,9 @@ public class Loop { /** chromosome name.*/ private String _chr =""; - /** loops name: chr start end value.*/ + /** chromosome name.*/ + private String _chr2 =""; + /** java.plop.loops name: chr start end value.*/ private String _name; /** x coordinate.*/ private int _x; @@ -23,27 +25,31 @@ public class Loop { private int _matrixSize; /** diagonal size.*/ private int _diagSize; + /** nb of zero n = 28.*/ + private int _nbZero; /** x coordinate+resolution.*/ private int _xEnd; /** y coordinate+resolution.*/ private int _yEnd; - /** value of the avg of the diff between loops value and the neighbourhood 8.*/ + /** value of the avg of the diff between java.plop.loops value and the neighbourhood 8.*/ private float _neigbhoord1 = -1; - /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of loops.*/ + /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of java.plop.loops.*/ private float _paScoreAvg = -1; private float _paScoreAvgdev = -1; - /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of loops.*/ + /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of java.plop.loops.*/ private float _paScoreMed = -1; - /** value of the avg of the differential between loops value and the neighbourhood 24.*/ + /** value of the avg of the differential between java.plop.loops value and the neighbourhood 24.*/ private float _neigbhoord2 = -1; - /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of loops.*/ + /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of java.plop.loops.*/ private float _regPaScoreMed = -1; - /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of loops.*/ + /** value of the peak analysis value inspirate from Rao&Huntley et al., 2014, but the score is compute foreach loop and not for a set of java.plop.loops.*/ private float _regPaScoreAvg = -1; /** Average value of the neighbourhood 9.*/ private float _avg = -1; /** Value of the loop*/ private float _peakValue = -1; + /** Value of the loop*/ + private float _peakValueDiff = -1; /** Standard deviation value of the neighbourhood 9.*/ private float _std = -1; /** FDR score 1*/ @@ -84,16 +90,16 @@ public Loop(String loop){ this._y = Integer.parseInt(tLoop[4]); this._yEnd= Integer.parseInt(tLoop[5]); } - /** + + /** * Loop constructor * @param name String name of the loop - * @param chr String name of the chromosome * @param x int x coordinate * @param y int y coordinate - * @param value float - * @param int resolution + * @param chr String Chromosme name + * @param value loop value + * @param resolution loop resolution */ - public Loop(String name, int x, int y, String chr, float value, int resolution){ this.setName(name); this.setX(x); @@ -122,7 +128,29 @@ public Loop(String name, int x, int y, String chr, float avg, float std, float v this._std = std; this._peakValue = value; } - + + /** + * Loop constructor + * @param name String name of the loop + * @param x int x coordinate + * @param y int y coordinate + * @param chr String Chromosome name + * @param avg float Average + * @param std float Standard deviation + * @param value float + */ + public Loop(String name, int x, int y, String chr, String chr2, float avg, float std, float value){ + this.setName(name); + this.setX(x); + this.setY(y); + this._chr = chr; + this._chr2 = chr2; + this._avg = avg; + this._std = std; + this._peakValue = value; + } + + /** * Getter of the name loop * @return String name of the loop @@ -135,19 +163,7 @@ public Loop(String name, int x, int y, String chr, float avg, float std, float v */ public void setName(String name){ this._name = name;} - - /** - * Setter of the name loop - * @param name String - */ - public String loopToString(){ - String loop = _chr+"\t"+_name+"\t"+_x+"\t"+_y+"\t"+ _resolution+"\t"+_matrixSize+"\t"+ _diagSize+"\t"+ - _xEnd+"\t"+ _yEnd+"\t"+_neigbhoord1+"\t"+_paScoreAvg+"\t"+_paScoreAvgdev+"\t"+_paScoreMed - +"\t"+_neigbhoord2+"\t"+_regPaScoreMed+"\t"+_regPaScoreAvg+"\t"+_avg+"\t"+_peakValue - +"\t"+_std+"\t"+_paScoreFDR+"\t"+_regPaScoreFDR+"\t"+_paScoreFDR2+"\t"+_regPaScoreFDR2+"\t" - +_paScoreFDR3+"\t"+_regPaScoreFDR3; - return loop; - } + /** * Getter of the x coordinate * @return int x coordinate @@ -202,7 +218,7 @@ public String loopToString(){ public int getY(){ return this._y; } /** - * Setter of the y loops coordinate's + * Setter of the y java.plop.loops coordinate's * @param y int loop coordinate's */ public void setY(int y){ this._y = y; } @@ -212,6 +228,11 @@ public String loopToString(){ * @return double loop value */ public float getValue(){ return this._peakValue; } + /** + * Getter of the loop(x,y) value + * @return double loop value + */ + public float getValueDiff(){ return this._peakValueDiff; } /** * Getter of the n 8 average value * @return double average of n 8 average @@ -254,12 +275,29 @@ public String loopToString(){ * @return double PA score */ public float getPaScoreAvg(){ return this._paScoreAvg; } + + /** + * + * @return + */ public float getPaScoreAvgdev(){ return this._paScoreAvgdev; } + /** + * + * @return + */ + public void setValueDiff(float diff){ this._peakValueDiff = diff; } + /** * Setter of the peak analysis loop score - * @param m_paScore double PA score + * + * @param paScore */ public void setPaScoreAvg(float paScore){ this._paScoreAvg = paScore; } + + /** + * + * @param paScoredev + */ public void setPaScoreAvgdev(float paScoredev){ this._paScoreAvgdev = paScoredev; } /** @@ -270,7 +308,8 @@ public String loopToString(){ /** * Setter of the peak analysis loop score - * @param m_paScore double PA score + * + * @param paScore */ public void setPaScoreMed(float paScore){ this._paScoreMed = paScore; } @@ -293,7 +332,7 @@ public void setCoordinates(int x, int x_end, int y, int y_end){ * @return ArrayList of integer */ public ArrayList getCoordinates(){ - ArrayList listCoord = new ArrayList(); + ArrayList listCoord = new ArrayList<>(); listCoord.add(this._x); listCoord.add(this._xEnd); listCoord.add(this._y); @@ -301,27 +340,17 @@ public ArrayList getCoordinates(){ return listCoord; } - /** - * - * @return - */ - public float getRegionalPaScoreMed(){ return this._regPaScoreMed; } - /** - * - * @param m_RpaScore - */ - public void setRegionalPaScoreMed(float m_RpaScore){ this._regPaScoreMed = m_RpaScore; } /** * Getter of regional peak analysis score * @return doubl reginal PA score */ public float getRegionalPaScoreAvg(){ return this._regPaScoreAvg; } - + /** - * Setter of regional PA score - * @param m_RpaScore double + * + * @param rpaScore */ public void setRegionalPaScoreAvg(float rpaScore){ this._regPaScoreAvg = rpaScore; } @@ -332,10 +361,11 @@ public ArrayList getCoordinates(){ public String getChr(){ return this._chr; } /** - * Setter of the avg of th n 8 - * @param avg double + * Getter of the name of the chromosome + * @return String chr */ - public void setAvg(float avg) { this._avg=avg; } + public String getChr2(){ return this._chr2; } + /** * @@ -398,5 +428,17 @@ public ArrayList getCoordinates(){ * @param paScoreFDR3 */ public void setPaScoreAvgFDR3(float paScoreFDR3){ this._paScoreFDR3 = paScoreFDR3; } + /** + * + * @param nbOfZero + */ + public void setNbOfZero(int nbOfZero){ this._nbZero = nbOfZero; } + + /** + * getter of the nb of zero + * + * @return int the number of zero around the loop + */ + public int getNbOfZero(){ return this._nbZero; } } diff --git a/src/main/java/plop/multiProcessing/ProcessDetectLoops.java b/src/main/java/plop/multiProcessing/ProcessDetectLoops.java new file mode 100644 index 0000000..f5e8ac9 --- /dev/null +++ b/src/main/java/plop/multiProcessing/ProcessDetectLoops.java @@ -0,0 +1,134 @@ +package plop.multiProcessing; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import plop.gui.Progress; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + + +/** + * multi thread class for the SIP loop calling step + * + * + * @author axel poulet + * + */ +public class ProcessDetectLoops{ + + /** progress bar if java.plop.gui is true*/ + private Progress _p; + + /** */ + public ProcessDetectLoops(){ } + + + /** + * multiprocessing method for SIP intra chromosomal interaction + * + * @param sip SIPIntra + * @param resuFile path to results file + * @param resName name of the resolution used + * @throws InterruptedException exception + */ + public void go(SIPIntra sip, String resuFile, String resName) throws InterruptedException { + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sip.getCpu()); + Iterator chrName = sip.getChrSizeHashMap().keySet().iterator(); + if(sip.isProcessed()) { + boolean isCool = isProcessedMcool(sip.getInputDir()+resName+File.separator+"normVector"); + //System.out.println(isCool); + sip.setIsCooler(isCool); + } + while(chrName.hasNext()){ + String chr = chrName.next(); + if(sip.isCooler()){ + RunnableDetectIntraLoops task = new RunnableDetectIntraLoops(chr, resuFile, sip); + executor.execute(task); + + }else { + String normFile = sip.getInputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; + /*if (java.plop.sip.isProcessed()){ + normFile = java.plop.sip.getInputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; + }*/ + RunnableDetectIntraLoops task = new RunnableDetectIntraLoops(chr, resuFile, sip,normFile); + executor.execute(task); + } + } + executor.shutdown(); + int nb = 0; + if(sip.isGui()){ + _p = new Progress(resName+" Loops Detection step",sip.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sip.isGui()) _p._bar.setValue(nb); + } + } + if(sip.isGui()) _p.dispose(); + + } + + /** + * multiprocessing for java.plop.sip on inter-chromosomal interaction + * for each couple of chromosome, RunnableDetectInterLoop is call. + * @param sipInter SIPInter object + * @param resuFile path to results file + * @throws InterruptedException exception + */ + public void go(SIPInter sipInter, String resuFile) throws InterruptedException { + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sipInter.getCpu()); + HashMap chrSize = sipInter.getChrSizeHashMap(); + ArrayList chrName = sipInter.getChrList(); + + File outDir = new File(sipInter.getInputDir()); + System.out.println("dans pdl.go out "+sipInter.getOutputDir()); + System.out.println("dans pdl.go in "+sipInter.getInputDir()); + + if (!outDir.exists()) outDir.mkdir(); + for(int i = 0; i < chrName.size();++i){ + String chr1 = chrName.get(i); + for(int j = i+1; j < chrName.size();++j){ + String chr2 = chrName.get(j); + int size1 = chrSize.get(chr1); + int size2 = chrSize.get(chr2); + System.out.println(chr1+"\t"+size1+"\t"+chr2+"\t"+size2); + RunnableDetectInterLoops task = new RunnableDetectInterLoops(chr1, chr2, resuFile, sipInter); + executor.execute(task); + } + } + + executor.shutdown(); + int nb = 0; + + if(sipInter.isGui()){ + _p = new Progress("Loop Detection step",sipInter.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sipInter.isGui()) _p._bar.setValue(nb); + } + } + if(sipInter.isGui()) _p.dispose(); + + } + /** + * + * @param dirToTest path to java.plop.test if it is existing + * @return boolean + */ + private boolean isProcessedMcool(String dirToTest) { + File test = new File (dirToTest); + boolean b = !test.exists(); + return b; + } +} \ No newline at end of file diff --git a/src/main/java/plop/multiProcessing/ProcessDumpCooler.java b/src/main/java/plop/multiProcessing/ProcessDumpCooler.java new file mode 100644 index 0000000..599f75c --- /dev/null +++ b/src/main/java/plop/multiProcessing/ProcessDumpCooler.java @@ -0,0 +1,153 @@ +package plop.multiProcessing; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import plop.dumpProcessing.CoolerDumpIntra; +import plop.dumpProcessing.CoolerDumpInter; +import plop.gui.Progress; +import plop.dumpProcessing.CoolerExpected; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; + +/** + * multi thread class dumping the data via juicertoolsbox.jar + * and make file step by step + * bed file: start1 start2 obs-expected distanceNormalizedValue + * + * @author axel poulet + */ +public class ProcessDumpCooler { + + /** progress bar if java.plop.gui is true*/ + private Progress _p; + + /** + * Constructor + */ + public ProcessDumpCooler(){ } + + /** + * run the processing on different cpu, if all cpu are running, take break else run a new one. + *for each chromosome the normalized data and expected data will be dump via cooler and cooltool. + * the SIP are produce in this step allowing later, the creation of the images and the java.plop.loops calling step. + * + * if java.plop.gui is true a progress bar will pop up. + * + * + * @param coolTools String coolTools path + * @param cooler String cooler path + * @param sip SIPIntra + * @param coolFile path mcool file + * @throws InterruptedException exception + */ + public void go(String coolTools, String cooler, SIPIntra sip, String coolFile) throws InterruptedException { + HashMap chrSize= sip.getChrSizeHashMap(); + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sip.getCpu()); + Iterator chrName = chrSize.keySet().iterator(); + File outDir = new File(sip.getOutputDir()); + if (!outDir.exists()) outDir.mkdir(); + + ArrayList listFactor = sip.getListFactor(); + for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { + + int res = sip.getResolution()*listFactor.get(indexFact); + int matrixSize = sip.getMatrixSize()/listFactor.get(indexFact); + CoolerExpected expected = new CoolerExpected(coolTools,coolFile, res, matrixSize,sip.getCpu()); + String nameRes = String.valueOf(res); + nameRes = nameRes.replace("000", ""); + nameRes = nameRes+"kb"; + String expectedFile = sip.getOutputDir()+nameRes+".expected"; + System.out.println("start "+expectedFile); + expected.dumpExpected(expectedFile); + System.out.println("!!!!!!! End "+expectedFile); + } + + while(chrName.hasNext()){ + String chr = chrName.next(); + CoolerDumpIntra dumpData = new CoolerDumpIntra( cooler, coolFile); + RunnableDumpCoolerIntra task = new RunnableDumpCoolerIntra(sip.getOutputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); + executor.execute(task); + } + executor.shutdown(); + int nb = 0; + + if(sip.isGui()){ + _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sip.isGui()) _p._bar.setValue(nb); + } + } + File folder = new File(sip.getOutputDir()); + File[] listOfFiles = folder.listFiles(); + for(int i = 0; i < listOfFiles.length;++i) { + String name = listOfFiles[i].toString(); + if(name.contains(".expected")) listOfFiles[i].delete(); + } + if(sip.isGui()) _p.dispose(); + } + + + /** + * + * @param cooler + * @param sipInter + * @param coolFile + * @throws InterruptedException + * @throws IOException + */ + public void go(String cooler, SIPInter sipInter, String coolFile) throws InterruptedException, IOException { + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sipInter.getCpu()); + HashMap chrSize = sipInter.getChrSizeHashMap(); + ArrayList chrName = sipInter.getChrList(); + + if (chrName.size() < 2){ + System.out.println("Error: !!! only one chromosome in"+ sipInter.getChrSizeFile() +", you need at least 2 chromosome in your file.\n"); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(sipInter.getOutputDir()+File.separator+"log.txt"))); + writer.write("Error: !!! only one chromosome in"+ sipInter.getChrSizeFile() +", you need at least 2 chromosome in your file.\n"); + writer.close(); + System.exit(1); + } + for(int i = 0; i < chrName.size();++i){ + String chr1 = chrName.get(i); + for(int j = i+1; j < chrName.size();++j){ + String chr2 = chrName.get(j); + int size1 = chrSize.get(chr1); + int size2 = chrSize.get(chr2); + System.out.println(chr1+"\t"+size1+"\t"+chr2+"\t"+size2); + CoolerDumpInter coolerDumpInter= new CoolerDumpInter(cooler, coolFile); + + RunnableDumpCoolerInter task = new RunnableDumpCoolerInter(sipInter.getOutputDir(), chr1, chrSize.get(chr1), + chr2, chrSize.get(chr2), coolerDumpInter, sipInter.getResolution(), sipInter.getMatrixSize()); + executor.execute(task); + } + } + + executor.shutdown(); + int nb = 0; + + if(sipInter.isGui()){ + _p = new Progress("Loop Detection step",sipInter.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sipInter.isGui()) _p._bar.setValue(nb); + } + } + if(sipInter.isGui()) _p.dispose(); + } +} diff --git a/src/main/java/plop/multiProcessing/ProcessDumpHic.java b/src/main/java/plop/multiProcessing/ProcessDumpHic.java new file mode 100644 index 0000000..1b8479b --- /dev/null +++ b/src/main/java/plop/multiProcessing/ProcessDumpHic.java @@ -0,0 +1,125 @@ +package plop.multiProcessing; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import plop.dumpProcessing.HicDumpIntra; +import plop.dumpProcessing.HicDumpInter; +import plop.gui.Progress; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; + + +/** + * multi thread class dumping the data via cooler + * and make file step by step + * bed file: start1 start2 obs-expected distanceNormalizedValue + * + * @author axel poulet + * + */ +public class ProcessDumpHic { + /** progress bar if java.plop.gui is true*/ + private Progress _p; + + /** + * + */ + public ProcessDumpHic(){ } + + /** + * run SiP for intra chr java.plop.loops + * + * @param hicFile Sting input file path + * @param sip SIPIntra with all the paramters needed + * @param juiceBoxTools juicerTools.jar path + * @param normJuiceBox String normalization method + * @throws InterruptedException exception + */ + public void go(String hicFile, SIPIntra sip, String juiceBoxTools, String normJuiceBox) throws InterruptedException { + HashMap chrSize = sip.getChrSizeHashMap(); + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sip.getCpu()); + Iterator chrName = chrSize.keySet().iterator(); + File outDir = new File(sip.getInputDir()); + if (!outDir.exists()) outDir.mkdir(); + while(chrName.hasNext()){ + String chr = chrName.next(); + HicDumpIntra dumpData = new HicDumpIntra(juiceBoxTools, hicFile, normJuiceBox); + RunnableDumpHicIntra task = new RunnableDumpHicIntra(sip.getInputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); + executor.execute(task); + } + executor.shutdown(); + int nb = 0; + + if(sip.isGui()){ + _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sip.isGui()) _p._bar.setValue(nb); + } + } + if(sip.isGui()) _p.dispose(); + } + + /** + * run SiP for inter chr java.plop.loops + * + * @param hicFile Sting input file path + * @param sipInter SIPInter object with all the parameters needed + * @param juiceBoxTools juicerTools.jar path + * @param normJuiceBox String normalization method + * @throws InterruptedException exception + */ + public void go(String hicFile, SIPInter sipInter, String juiceBoxTools, String normJuiceBox) throws InterruptedException, IOException { + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(sipInter.getCpu()); + HashMap chrSize = sipInter.getChrSizeHashMap(); + ArrayList chrName = sipInter.getChrList(); + if (chrName.size() < 2){ + System.out.println("Error: !!! only one chromosome in"+ sipInter.getChrSizeFile() +", you need at least 2 chromosome in your file.\n"); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(sipInter.getOutputDir()+File.separator+"log.txt"))); + writer.write("Error: !!! only one chromosome in"+ sipInter.getChrSizeFile() +", you need at least 2 chromosome in your file.\n"); + writer.close(); + System.exit(1); + } + for(int i = 0; i < chrName.size();++i){ + String chr1 = chrName.get(i); + for(int j = i+1; j < chrName.size();++j){ + String chr2 = chrName.get(j); + int size1 = chrSize.get(chr1); + int size2 = chrSize.get(chr2); + System.out.println(chr1+"\t"+size1+"\t"+chr2+"\t"+size2); + HicDumpInter DumpInterChromosomal = new HicDumpInter(juiceBoxTools, hicFile, normJuiceBox); + RunnableDumpHicInter task = new RunnableDumpHicInter(sipInter.getInputDir(), chr1, chrSize.get(chr1), + chr2, chrSize.get(chr2),DumpInterChromosomal, sipInter.getResolution(), sipInter.getMatrixSize()); + executor.execute(task); + } + } + + executor.shutdown(); + int nb = 0; + + if(sipInter.isGui()){ + _p = new Progress("Loop Detection step",sipInter.getChrSizeHashMap().size()+1); + _p._bar.setValue(nb); + } + while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { + if (nb != executor.getCompletedTaskCount()) { + nb = (int) executor.getCompletedTaskCount(); + if(sipInter.isGui()) _p._bar.setValue(nb); + } + } + if(sipInter.isGui()) _p.dispose(); + } + +} \ No newline at end of file diff --git a/src/main/java/plop/multiProcessing/RunnableDetectInterLoops.java b/src/main/java/plop/multiProcessing/RunnableDetectInterLoops.java new file mode 100644 index 0000000..89a1e12 --- /dev/null +++ b/src/main/java/plop/multiProcessing/RunnableDetectInterLoops.java @@ -0,0 +1,95 @@ +package plop.multiProcessing; + +import plop.loops.CallLoopsInter; +import plop.loops.Loop; +import plop.sip.SIPInter; + + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +/** + * runnable class for inter java.plop.loops detection + * + */ +public class RunnableDetectInterLoops extends Thread implements Runnable { + + /*** SIP object containing all the parameter for the java.plop.loops detection */ + private SIPInter _sipInter; + /** CallLoops object */ + private CallLoopsInter _callLoopsInter; + /** String results file */ + private String _resuFile; + /** String name of the chr1 */ + private String _chr1; + /** String chr name 2 */ + private String _chr2; + + + /** + * Construtor, initialize all the variables of interest + * + * @param chr1 chr1 name + * @param chr2 chr2 name + * @param resuFile path output file + * @param sip SIPInter object + */ + public RunnableDetectInterLoops(String chr1, String chr2, String resuFile, SIPInter sip) { + this._sipInter = sip; + this._callLoopsInter = new CallLoopsInter(_sipInter); + this._chr1 = chr1; + this._chr2 = chr2; + this._resuFile = resuFile; + } + + + + + /** + * Run all the java.plop.process for java.plop.loops detection by chr using the objet CallLoops and then save java.plop.loops in + * txt file with SIPIntra via he method saveFile + */ + public void run() { + String resName = String.valueOf(this._sipInter.getResolution()); + resName = resName.replace("000", "")+"kb"; + String dir = this._sipInter.getInputDir()+resName+File.separator+_chr1+"_"+_chr2+File.separator; + HashMap data; + if (this._sipInter.isProcessed()) dir = this._sipInter.getInputDir()+resName+File.separator+_chr1+"_"+_chr2+File.separator; + try { + File folder = new File(dir); + + File[] listOfFiles = folder.listFiles(); + if(folder.exists()){ + System.out.println("yupyup !!!"+dir); + }else{ + System.out.println("yupyup !!!"+folder.toString()); + } + System.out.println(dir+" "+listOfFiles.length); + if (listOfFiles.length == 0) System.out.println("!!!!!!!!!! dumped directory of chromosome"+this._chr1+"_"+_chr2+"empty"); + else{ + File file = new File(this._resuFile); + /* if(_sipInter.isCooler() == false) { + System.out.println(_normvectorFile+"normVector end loading file: "+_chr+".norm "+resName); + }*/ + data = this._callLoopsInter.detectLoops(listOfFiles,this._chr1, this._chr2); + System.out.println(data.size()+"!!!!!!!!!!!!!!!! "+this._chr1+" "+this._chr2); + synchronized(this) { + if (file.length() == 0) _sipInter.writeResu(this._resuFile,data,false); + else this._sipInter.writeResu(this._resuFile,data,true); + } + folder = new File(dir); + listOfFiles = folder.listFiles(); + if(_sipInter.isDelImage()){ + System.out.println("Deleting image file for "+_chr1+"_"+_chr2); + for(int i = 0; i < listOfFiles.length;++i) { + String name = listOfFiles[i].toString(); + if(name.contains(".tif")) listOfFiles[i].delete(); + } + } + } + } catch (IOException e1) { e1.printStackTrace();} + System.gc(); + + } +} diff --git a/src/multiProcesing/RunnableDetectLoops.java b/src/main/java/plop/multiProcessing/RunnableDetectIntraLoops.java similarity index 53% rename from src/multiProcesing/RunnableDetectLoops.java rename to src/main/java/plop/multiProcessing/RunnableDetectIntraLoops.java index 41bd0c6..4fbbec6 100644 --- a/src/multiProcesing/RunnableDetectLoops.java +++ b/src/main/java/plop/multiProcessing/RunnableDetectIntraLoops.java @@ -1,65 +1,71 @@ -package multiProcesing; -import process.CallLoops; -import utils.SIPObject; -import utils.Loop; +package plop.multiProcessing; + +import plop.loops.CallLoops; +import plop.sip.SIPIntra; +import plop.loops.Loop; import java.io.File; import java.io.IOException; import java.util.HashMap; /** - * Runnable class for loops detcetion + * Runnable class for java.plop.loops detection * * @author axel poulet * */ -public class RunnableDetectLoops extends Thread implements Runnable{ - /** SIP object containing all the parameter for the loops detection*/ - private SIPObject _sip; +public class RunnableDetectIntraLoops extends Thread implements Runnable{ + /** SIP object containing all the parameter for the java.plop.loops detection*/ + private SIPIntra _sip; /** CallLoops object */ private CallLoops _callLoops; /** String results file*/ private String _resuFile; /** String name of the chr*/ private String _chr; - /** String name of the chr*/ - private boolean _delImages = true; /** norn vector table for the chr of interest*/ private HashMap _normVector = new HashMap (); - /** */ - private String _normvectorFile; + /** path of Normalized vector from juicer tools dump for each chr by SIP*/ + private String _normVectorFile; /** - * Construtor, initialize all the variables of interest + * Constructor, initialize all the variables needed for runnableDetectLoop, for hic file * - * @param chr - * @param callLoops - * @param resuFile - * @param sip - * @param normVector + * + * @param chr String chromosome name + * @param resuFile path to the result file + * @param sip SIPIntra + * @param normVectorFile path to normalized vector + * */ - public RunnableDetectLoops (String chr, String resuFile, SIPObject sip, String normVectorFile, boolean delFile){ + public RunnableDetectIntraLoops(String chr, String resuFile, SIPIntra sip, String normVectorFile){ this._sip = sip; this._callLoops = new CallLoops(sip); this._chr= chr; this._resuFile = resuFile; this._normVector = sip.getNormValueFilter(normVectorFile); - this._delImages = delFile; - this._normvectorFile = normVectorFile; + this._normVectorFile = normVectorFile; } - - public RunnableDetectLoops (String chr, String resuFile, SIPObject sip, boolean delFile){ + + /** + * Constructor, initialize all the variables needed for runnableDetectLoop, for mcool file + * + * @param chr String chromosome name + * @param resuFile path to the result file + * @param sip SIPIntra + * + */ + public RunnableDetectIntraLoops(String chr, String resuFile, SIPIntra sip){ this._sip = sip; this._callLoops = new CallLoops(sip); this._chr= chr; this._resuFile = resuFile; - this._delImages = delFile; } /** - * Run all the process for loops detection by chr using the objet CallLoops and then save loops in - * txt file with SIPObject via he method saveFile + * Run all the java.plop.process for java.plop.loops detection by chr using the objet CallLoops and then save java.plop.loops in + * txt file with SIPIntra via he method saveFile * */ public void run(){ @@ -69,21 +75,25 @@ public void run(){ HashMap data = new HashMap (); if (this._sip.isProcessed()) dir = this._sip.getInputDir()+resName+File.separator+this._chr+File.separator; try { - File[] listOfFiles = _sip.fillList(dir); + File folder = new File(dir); + File[] listOfFiles = folder.listFiles(); + System.out.println(dir); if (listOfFiles.length == 0) System.out.println("!!!!!!!!!! dumped directory of chromosome"+this._chr+" empty"); else{ File file = new File(this._resuFile); - if(_sip.isCooler() == false) { - System.out.println(_normvectorFile+"normVector end loading file: "+_chr+".norm "+resName); + if(!_sip.isCooler()) { + System.out.println(_normVectorFile +"normVector end loading file: "+_chr+".norm "+resName); } + System.out.println(dir); data = this._callLoops.detectLoops(listOfFiles,this._chr,this._normVector); synchronized(this) { if (file.length() == 0) _sip.saveFile(this._resuFile,data,false); else this._sip.saveFile(this._resuFile,data, true); } - listOfFiles = _sip.fillList(dir); - if(_delImages){ + folder = new File(dir); + listOfFiles = folder.listFiles(); + if(_sip.isDelImage()){ System.out.println("Deleting image file for "+_chr); for(int i = 0; i < listOfFiles.length;++i) { String name = listOfFiles[i].toString(); diff --git a/src/main/java/plop/multiProcessing/RunnableDumpCoolerInter.java b/src/main/java/plop/multiProcessing/RunnableDumpCoolerInter.java new file mode 100644 index 0000000..e44a00b --- /dev/null +++ b/src/main/java/plop/multiProcessing/RunnableDumpCoolerInter.java @@ -0,0 +1,112 @@ +package plop.multiProcessing; + +import java.io.File; +import java.io.IOException; + +import plop.dumpProcessing.CoolerDumpInter; + +/** + * + * @author axel poulet + * + */ +public class RunnableDumpCoolerInter extends Thread implements Runnable{ + /** path outdir */ + private String _outDir; + /** chr1 name */ + private String _chr1; + /** chr2 name*/ + private String _chr2; + /** size chr1*/ + private int _sizeChr1; + /** size chr2 */ + private int _sizeChr2; + /** Object HicDumpInter*/ + private CoolerDumpInter _dumpInter; + /** bin size*/ + private int _resolution; + /** image size*/ + private int _matrixSize; + + + /** + * Constructor, initialize the variables of interest + */ + public RunnableDumpCoolerInter(String outputDir, String chr1, int sizeChr1, String chr2, int sizeChr2, CoolerDumpInter dumpData, int res, int matrixSize){ + this._outDir = outputDir; + this._sizeChr1 = sizeChr1; + this._sizeChr2 = sizeChr2; + this._chr1 = chr1; + this._chr2 = chr2; + this._resolution = res; + this._matrixSize = matrixSize; + this._dumpInter = dumpData; + } + + /** + * Dump the data by chr for mcool data + * using cooler and cooltools + */ + public void run(){ + int step = _matrixSize; + String nameRes = String.valueOf(_resolution); + nameRes = nameRes.replace("000", ""); + nameRes = nameRes+"kb"; + String outdir = _outDir+nameRes+ File.separator+_chr1+"_"+_chr2+File.separator; + File file = new File(outdir); + if (!file.exists()) + file.mkdirs(); + step = step*_resolution; + System.out.println("start dump "+_chr1+" size "+_sizeChr1+" "+_chr2+" size "+_sizeChr2+" res "+ nameRes); + int endChr1 = _matrixSize*_resolution; + if(endChr1 > _sizeChr1) endChr1 = _sizeChr1; + try { + for(int startChr1 = 0 ; endChr1-1 <= _sizeChr1; startChr1+=step,endChr1+=step){ + int endChr2 = _matrixSize*_resolution; + if(endChr2 > _sizeChr2) endChr2 = _sizeChr2; + int end1 =endChr1-1; + + //hgdhdhgd + String dump1 = _chr1+":"+startChr1+"-"+end1; + for(int startChr2 = 0 ; endChr2-1 <= _sizeChr2; startChr2+=step,endChr2+=step) { + int end2 =endChr2-1; + // + String dump2 = _chr2+":"+startChr2+"-"+end2; + String name = outdir + _chr1 +"_" + startChr1 + "_" + end1 +"_" +_chr2 +"_" + startChr2 + "_" + end2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + if (endChr2 + step > _sizeChr2 && endChr2 < _sizeChr2) { + endChr2 = _sizeChr2-1; + startChr2 += step; + dump2 = _chr2+":"+startChr2+"-"+endChr2; + name = outdir + _chr1 +"_" + startChr1 + "_" + end1 +"_" +_chr2 +"_" + startChr2 + "_" + endChr2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + } + } + if (endChr1 + step > _sizeChr1 && endChr1 < _sizeChr1) { + endChr1 = _sizeChr1-1; + startChr1 += step; + dump1 = _chr1+":"+startChr1+"-"+endChr1; + endChr2 = _matrixSize*_resolution; + for(int startChr2 = 0 ; endChr2-1 <= _sizeChr2; startChr2+=step,endChr2+=step) { + int end2 =endChr2-1; + String dump2 = _chr2+":"+startChr2+"-"+end2; + String name = outdir + _chr1 +"_" + startChr1 + "_" + endChr1 +"_" +_chr2 +"_" + startChr2 + "_" + end2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + if (endChr2 + step > _sizeChr2 && endChr2 < _sizeChr2) { + endChr2 = _sizeChr2-1; + startChr2 += step; + dump2 = _chr2+":"+startChr2+"-"+endChr2; + name = outdir + _chr1 +"_" + startChr1 + "_" + endChr1 +"_" +_chr2 +"_" + startChr2 + "_" + endChr2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + } + } + } + } + System.gc(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/multiProcesing/RunnableDumpDataCooler.java b/src/main/java/plop/multiProcessing/RunnableDumpCoolerIntra.java similarity index 70% rename from src/multiProcesing/RunnableDumpDataCooler.java rename to src/main/java/plop/multiProcessing/RunnableDumpCoolerIntra.java index 194e7d8..b957291 100644 --- a/src/multiProcesing/RunnableDumpDataCooler.java +++ b/src/main/java/plop/multiProcessing/RunnableDumpCoolerIntra.java @@ -1,48 +1,49 @@ -package multiProcesing; +package plop.multiProcessing; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import process.CoolerDumpData; -import utils.CoolerExpected; +import plop.dumpProcessing.CoolerDumpIntra; +import plop.dumpProcessing.CoolerExpected; /** * * @author axel poulet * */ -public class RunnableDumpDataCooler extends Thread implements Runnable{ +public class RunnableDumpCoolerIntra extends Thread implements Runnable{ /**String: path where save the dump data */ - private String _outdir =""; + private String _outdir ; /**String: name of the chr*/ - private String _chrName = ""; + private String _chrName; /**int: chr size */ - private int _chrSize = 0; - /** DumpData object run juicertoolbox.jar*/ - private CoolerDumpData _coolerDumpData; + private int _chrSize; + /** HicDumpIntra object run juicertoolbox.jar*/ + private CoolerDumpIntra _coolerDumpData; /**int: bin resolution*/ - private int _res = 0; + private int _res; /**int: image Size */ - private int _matrixSize = 0; + private int _matrixSize; /**int: size of the step to run a chr */ - private int _step = 0; - /** */ + private int _step; + /** List of integer for multi-resolution loop calling*/ private ArrayList _listFactor; /** * Constructor, initialize the variables of interest * - * @param outdir - * @param chrName - * @param chrSize - * @param dumpData - * @param res - * @param matrixSize - * @param step + * @param outdir string path outdir + * @param chrName string chr name + * @param chrSize int chr size + * @param dumpData CoolerDumpIntra Object + * @param res bin size + * @param matrixSize image size + * @param step step between each image + * @param listFactor List of integer for multi-resolution loop calling */ - public RunnableDumpDataCooler (String outdir, String chrName, int chrSize, CoolerDumpData dumpData,int res, int matrixSize, int step, ArrayList listFactor){ + public RunnableDumpCoolerIntra(String outdir, String chrName, int chrSize, CoolerDumpIntra dumpData, int res, int matrixSize, int step, ArrayList listFactor){ this._outdir = outdir; this._chrName = chrName; this._chrSize = chrSize; @@ -54,7 +55,8 @@ public RunnableDumpDataCooler (String outdir, String chrName, int chrSize, Coole } /** - * Dump teh data by chr + * Dump the data by chr for mcool data + * using cooler and cooltools */ public void run(){ boolean coolerTools; @@ -73,11 +75,11 @@ public void run(){ _coolerDumpData.setExpected(lExpected); String outdir = this._outdir+File.separator+nameRes+File.separator+this._chrName+File.separator; File file = new File(outdir); - if (file.exists()==false) file.mkdirs(); + if (!file.exists()) file.mkdirs(); int step = this._step*res; int j = matrixSize*res; String name = outdir+this._chrName+"_0_"+j+".txt"; - if (file.exists()==false) file.mkdir(); + if (!file.exists()) file.mkdir(); System.out.println("start dump "+this._chrName+" size "+this._chrSize+" res "+ nameRes); if(j > this._chrSize) j = this._chrSize; for(int i = 0 ; j-1 <= this._chrSize; i+=step,j+=step){ @@ -86,7 +88,7 @@ public void run(){ name = outdir+this._chrName+"_"+i+"_"+end+".txt"; System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ nameRes); coolerTools = this._coolerDumpData.dumpObservedMExpected(dump,name,res); - if (coolerTools == false){ + if (!coolerTools){ System.out.print(dump+" "+"\n"+coolerTools+"\n"); System.exit(0); } @@ -97,7 +99,7 @@ public void run(){ name = outdir+this._chrName+"_"+i+"_"+j+".txt"; System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ nameRes); coolerTools = this._coolerDumpData.dumpObservedMExpected(dump,name,res); - if (coolerTools == false){ + if (!coolerTools){ System.out.print(dump+" "+"\n"+coolerTools+"\n"); System.exit(0); } diff --git a/src/main/java/plop/multiProcessing/RunnableDumpHicInter.java b/src/main/java/plop/multiProcessing/RunnableDumpHicInter.java new file mode 100644 index 0000000..b3528c3 --- /dev/null +++ b/src/main/java/plop/multiProcessing/RunnableDumpHicInter.java @@ -0,0 +1,117 @@ +package plop.multiProcessing; + +import plop.dumpProcessing.HicDumpInter; + +import java.io.File; +import java.io.IOException; + + +/** + * + */ +public class RunnableDumpHicInter extends Thread implements Runnable{ + /** path outdir */ + private String _outDir; + /** chr1 name */ + private String _chr1; + /** chr2 name*/ + private String _chr2; + /** size chr1*/ + private int _sizeChr1; + /** size chr2 */ + private int _sizeChr2; + /** Object HicDumpInter*/ + private HicDumpInter _dumpInter; + /** bin size*/ + private int _resolution; + /** image size*/ + private int _matrixSize; + + /** + * + * @param outputDir String path for the output dir + * @param chr1 String chr1 name + * @param sizeChr1 int chr1 size + * @param chr2 String chr2 name + * @param sizeChr2 int chr2 size + * @param dumpInterChromosomal HicDumpInter object dumping the data of interest + * @param resolution int resolution == size of the bins to dump + * @param matrixSize int size of the ImagePlus + */ + public RunnableDumpHicInter(String outputDir, String chr1, int sizeChr1, String chr2, int sizeChr2, + HicDumpInter dumpInterChromosomal, int resolution, int matrixSize) { + + _outDir = outputDir; + _chr1 = chr1; + _chr2 = chr2; + _sizeChr1 = sizeChr1; + _sizeChr2 = sizeChr2; + _dumpInter = dumpInterChromosomal; + _resolution = resolution; + _matrixSize = matrixSize; + + } + + /** + * define the name and the region to dump for each chr + */ + public void run(){ + int step = _matrixSize; + String nameRes = String.valueOf(_resolution); + nameRes = nameRes.replace("000", ""); + nameRes = nameRes+"kb"; + String outdir = _outDir+nameRes+ File.separator+_chr1+"_"+_chr2+File.separator; + File file = new File(outdir); + if (!file.exists()) + file.mkdirs(); + step = step*_resolution; + + System.out.println(file.toString()+" "+file.exists()+" start dump "+_chr1+" size "+_sizeChr1+" "+_chr2+" size "+_sizeChr2+" res "+ nameRes); + int endChr1 = _matrixSize*_resolution; + if(endChr1 > _sizeChr1) endChr1 = _sizeChr1; + try { + for(int startChr1 = 0 ; endChr1-1 <= _sizeChr1; startChr1+=step,endChr1+=step){ + int endChr2 = _matrixSize*_resolution; + if(endChr2 > _sizeChr2) endChr2 = _sizeChr2; + int end1 =endChr1-1; + String dump1 = _chr1+":"+startChr1+":"+end1; + for(int startChr2 = 0 ; endChr2-1 <= _sizeChr2; startChr2+=step,endChr2+=step) { + int end2 =endChr2-1; + String dump2 = _chr2+":"+startChr2+":"+end2; + String name = outdir + _chr1 +"_" + startChr1 + "_" + end1 +"_" +_chr2 +"_" + startChr2 + "_" + end2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + if (endChr2 + step > _sizeChr2 && endChr2 < _sizeChr2) { + endChr2 = _sizeChr2-1; + startChr2 += step; + dump2 = _chr2+":"+startChr2+":"+endChr2; + name = outdir + _chr1 +"_" + startChr1 + "_" + end1 +"_" +_chr2 +"_" + startChr2 + "_" + endChr2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + } + } + if (endChr1 + step > _sizeChr1 && endChr1 < _sizeChr1) { + endChr1 = _sizeChr1-1; + startChr1 += step; + dump1 = _chr1+":"+startChr1+":"+endChr1; + endChr2 = _matrixSize*_resolution; + for(int startChr2 = 0 ; endChr2-1 <= _sizeChr2; startChr2+=step,endChr2+=step) { + int end2 =endChr2-1; + String dump2 = _chr2+":"+startChr2+":"+end2; + String name = outdir + _chr1 +"_" + startChr1 + "_" + endChr1 +"_" +_chr2 +"_" + startChr2 + "_" + end2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + if (endChr2 + step > _sizeChr2 && endChr2 < _sizeChr2) { + endChr2 = _sizeChr2-1; + startChr2 += step; + dump2 = _chr2+":"+startChr2+":"+endChr2; + name = outdir + _chr1 +"_" + startChr1 + "_" + endChr1 +"_" +_chr2 +"_" + startChr2 + "_" + endChr2 + ".txt"; + _dumpInter.dumpObserved(dump1, dump2, name, _resolution); + } + } + } + } + System.gc(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/src/multiProcesing/RunnableDumpDataHiC.java b/src/main/java/plop/multiProcessing/RunnableDumpHicIntra.java similarity index 72% rename from src/multiProcesing/RunnableDumpDataHiC.java rename to src/main/java/plop/multiProcessing/RunnableDumpHicIntra.java index f4b8b90..ce72986 100644 --- a/src/multiProcesing/RunnableDumpDataHiC.java +++ b/src/main/java/plop/multiProcessing/RunnableDumpHicIntra.java @@ -1,5 +1,5 @@ -package multiProcesing; -import process.DumpData; +package plop.multiProcessing; +import plop.dumpProcessing.HicDumpIntra; import java.io.File; import java.io.IOException; @@ -10,42 +10,43 @@ * The data are dumped by chr and by windows size, with user's parameters choose. * * two sorts of file file will be created one for the raw value with the observed minus expected value and also with the diatnce normalized value. - * Then the "norm" vector is also dump in an other deirectory. + * Then the "norm" vector is also dump in an other directory. * * @author axel poulet * */ -public class RunnableDumpDataHiC extends Thread implements Runnable{ +public class RunnableDumpHicIntra extends Thread implements Runnable{ /**String: path where save the dump data */ - private String _outdir =""; + private String _outdir; /**String: name of the chr*/ - private String _chrName = ""; + private String _chrName; /**int: chr size */ - private int _chrSize = 0; - /** DumpData object run juicertoolbox.jar*/ - private DumpData _dumpData; + private int _chrSize; + /** HicDumpIntra object run juicertoolbox.jar*/ + private HicDumpIntra _dumpData; /**int: bin resolution*/ - private int _res = 0; + private int _res; /**int: image Size */ - private int _matrixSize = 0; + private int _matrixSize; /**int: size of the step to run a chr */ - private int _step = 0; - /** */ + private int _step ; + /** List of integer for multi-resolution loop calling*/ private ArrayList _listFactor; /** * Constructor, initialize the variables of interest - * - * @param outdir - * @param chrName - * @param chrSize - * @param dumpData - * @param res - * @param matrixSize - * @param step + * + * @param outdir string path outdir + * @param chrName string chr name + * @param chrSize int chr size + * @param dumpData CoolerDumpIntra Object + * @param res bin size + * @param matrixSize image size + * @param step step between each image + * @param listFactor List of integer for multi-resolution loop calling */ - public RunnableDumpDataHiC (String outdir, String chrName, int chrSize, DumpData dumpData,int res, int matrixSize, int step, ArrayList listFactor){ + public RunnableDumpHicIntra(String outdir, String chrName, int chrSize, HicDumpIntra dumpData, int res, int matrixSize, int step, ArrayList listFactor){ this._outdir = outdir; this._chrName = chrName; this._chrSize = chrSize; @@ -57,7 +58,8 @@ public RunnableDumpDataHiC (String outdir, String chrName, int chrSize, DumpData } /** - * Dump teh data by chr + * Dump th data by chr for hic file + * using juicer tools */ public void run(){ boolean juicerTools; @@ -70,7 +72,7 @@ public void run(){ nameRes = nameRes+"kb"; String outdir = this._outdir+nameRes+File.separator+this._chrName+File.separator; File file = new File(outdir); - if (file.exists()==false) file.mkdirs(); + if (!file.exists()) file.mkdirs(); int step = this._step*res; int j = matrixSize*res; String test = this._chrName+":0:"+j; @@ -78,7 +80,7 @@ public void run(){ this._dumpData.getExpected(test,name,res); String normOutput = this._outdir+nameRes+File.separator+"normVector"; file = new File(normOutput); - if (file.exists()==false) file.mkdir(); + if (!file.exists()) file.mkdir(); try { this._dumpData.getNormVector(this._chrName,normOutput+File.separator+this._chrName+".norm",res); System.out.println("start dump "+this._chrName+" size "+this._chrSize+" res "+ nameRes); diff --git a/src/main/java/plop/process/Cool.java b/src/main/java/plop/process/Cool.java new file mode 100644 index 0000000..b752637 --- /dev/null +++ b/src/main/java/plop/process/Cool.java @@ -0,0 +1,298 @@ +package plop.process; + + +import plop.cli.CLIOptionCool; +import plop.gui.GuiAnalysis; +import plop.multiProcessing.ProcessDumpCooler; +import plop.multiProcessing.ProcessDetectLoops; +import org.apache.commons.cli.CommandLine; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; +import plop.utils.MultiResProcess; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + +/** + * + */ +public class Cool { + /** */ + private SIPIntra _sipIntra; + /** */ + private SIPInter _sipInter; + /** */ + private CommandLine _cmd; + + /** */ + private String _input; + /** */ + private String _output; + /** */ + private String _chrSizeFile; + + /** */ + private int _nbZero; + /** */ + private boolean _delImages; + /** */ + private int _cpu; + /** */ + private boolean _isGui; + /** */ + private GuiAnalysis _guiAnalysis; + /** */ + private String _coolTool; + /** */ + private String _interOrIntra; + /** */ + private ParametersCheck _parameterCheck; + /** */ + private String _cooler; + /** */ + String _log; + + /** + * + * @param args + * @throws Exception + */ + public Cool(String args []){ + _isGui = false; + CLIOptionCool cli = new CLIOptionCool(args); + _cmd = cli.getCommandLine(); + _input = _cmd.getOptionValue("input"); + _output = _cmd.getOptionValue("output"); + _log = _output+File.separator+"log.txt"; + _delImages = true; + _nbZero = 6; + _cpu = 1; + } + + /** + * + * @param guiAnalysis + */ + public Cool(GuiAnalysis guiAnalysis ){ + _isGui = true; + _guiAnalysis = guiAnalysis; + _input = this._guiAnalysis.getInput(); + _output = this._guiAnalysis.getOutputDir(); + _log = _output+File.separator+"log.txt"; + _delImages = true; + _nbZero = 6; + _cpu = 1; + } + /** + * + * Normalisation method to dump the the data with hic method (KR,NONE.VC,VC_SQRT) + * + * + * @throws IOException + * @throws InterruptedException + */ + public void run() throws IOException, InterruptedException { + + String allParam; + + if(_isGui) { + _cooler = this._guiAnalysis.getCooler(); + if(this._guiAnalysis.isInter()) _interOrIntra = "inter"; + else _interOrIntra = "intra"; + _chrSizeFile = this._guiAnalysis.getChrSizeFile(); + _coolTool = this._guiAnalysis.getCooltools(); + _nbZero = this._guiAnalysis.getNbZero(); + _delImages = this._guiAnalysis.isDeletTif(); + _cpu = this._guiAnalysis.getNbCpu(); + }else { + /* common required parameters*/ + + _cooler = _cmd.getOptionValue("cooler"); + _coolTool = _cmd.getOptionValue("cooltools"); + _interOrIntra = _cmd.getOptionValue("lt"); + _chrSizeFile = _cmd.getOptionValue("chrSize"); + /* common optional parameters */ + if (_cmd.hasOption("nbZero")) _nbZero = Integer.parseInt(_cmd.getOptionValue("nbZero")); + if (_cmd.hasOption("delete"))_delImages = Boolean.parseBoolean(_cmd.getOptionValue("delImages")); + if (_cmd.hasOption("cpu")) _cpu = Integer.parseInt(_cmd.getOptionValue("cpu")); + } + File file = new File(_output); + if(!file.exists()) file.mkdir(); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(_log))); + + _parameterCheck = new ParametersCheck(_input, _chrSizeFile, _interOrIntra, writer,false); + + _parameterCheck.testCoolOption(_coolTool, _cooler); + + if(_interOrIntra.equals("intra")) + allParam = runIntra(); + else + allParam = runInter(); + + + writer.write(allParam); + writer.close(); + } + + /** + * + * @return + * @throws IOException + * @throws InterruptedException + */ + private String runIntra() throws IOException, InterruptedException { + /* Param spe intra chromosomal loop*/ + if(_isGui) + this.setSipIntraGUI(); + else + this.setSipIntraCLI(); + + _sipIntra.setIsGui(_isGui); + _sipIntra.setIsProcessed(false); + _sipIntra.setIsCooler(true); + + ProcessDumpCooler processDumpData = new ProcessDumpCooler(); + String allParam = "SIPHiC hic: \n" + + "input: "+_input+"\n" + + "output: "+_output+"\n"+ + "cooler: "+ _cooler +"\n"+ + "cooltools: "+ _coolTool +"\n" + + "inter or intra chromosomal: "+ _interOrIntra +"\n" + + "gauss: "+this._sipIntra.getGauss()+"\n"+ + "min: "+this._sipIntra.getMin()+"\n"+ + "max: "+this._sipIntra.getMax()+"\n"+ + "matrix size: "+this._sipIntra.getMatrixSize()+"\n"+ + "diagonal size: "+this._sipIntra.getDiagonalSize()+"\n"+ + "resolution: "+this._sipIntra.getResolution()+"\n"+ + "saturated pixel: "+this._sipIntra.getSaturatedPixel()+"\n"+ + "threshold: "+this._sipIntra.getThresholdMaxima()+"\n"+ + "number of zero: "+this._nbZero+"\n"+ + "factor: "+ _sipIntra.getFactor() +"\n"+ + "fdr: "+this._sipIntra.getFdr()+"\n"+ + "delete images: "+_delImages+"\n"+ + "cpu: "+ _cpu+"\n" + + "isDroso: "+this._sipIntra.isDroso()+"\n"; + + System.out.println("########### Starting dump Step inter chromosomal interactions"); + + _parameterCheck.optionalParametersValidity(_sipIntra); + _parameterCheck.speOption(_sipIntra); + + processDumpData.go(_coolTool,_cooler, _sipIntra, _input); + System.out.println("########### End of the dump step\n"); + + System.out.println("########### Start loop detection\n"); + MultiResProcess multi = new MultiResProcess(_sipIntra, _chrSizeFile); + multi.run(); + System.out.println("###########End loop detection step\n"); + return allParam; + } + + + /** + * + * @throws IOException + */ + private String runInter() throws IOException, InterruptedException { + ProcessDumpCooler processDumpData = new ProcessDumpCooler(); + + this.setSipInter(); + _sipInter.setIsGui(_isGui); + _sipInter.setIsProcessed(false); + _sipInter.setIsCooler(true); + + _parameterCheck.optionalParametersValidity(_sipInter); + System.out.println("########### Starting dump Step inter chromosomal interactions"); + processDumpData.go(_cooler, _sipInter, _input); + System.out.println("########### !!! End dump Step inter chromosomal interactions"); + String loopFileRes = _sipInter.getOutputDir()+"finalLoops.txt"; + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(loopFileRes))); + ProcessDetectLoops detectLoops = new ProcessDetectLoops(); + + System.out.println("########### Starting loop detection"); + detectLoops.go(_sipInter, loopFileRes); + System.out.println("########### !!!!!!! end java.plop.loops detection"); + return "SIPHiC hic: \n" + "input: "+_input+"\n" + "output: "+_output+"\n"+ "cooler: "+ _cooler +"\n"+ + "inter or intra chromosomal: "+ _interOrIntra +"\n" + + "gauss: "+this._sipInter.getGauss()+"\n"+ "matrix size: "+this._sipInter.getMatrixSize()+"\n"+ + "resolution: "+this._sipInter.getResolution()+"\n"+ "threshold: "+this._sipInter.getThresholdMaxima()+"\n"+ + "number of zero :"+_sipInter.getNbZero()+"\n"+ "fdr "+this._sipInter.getFdr()+"\n"+ "delete images "+_delImages+"\n"+ + "cpu "+ _cpu+"\n"; + } + + + /** + * + */ + private void setSipIntraCLI() throws IOException { + double min = 2.0; + double max = 2.0; + double gauss = 1.5; + int matrixSize = 2000; + double thresholdMax = 2800; + double fdr = 0.01; + int resolution = 5000; + int diagSize = 6; + double saturatedPixel = 0.01; + boolean isDroso = false; + int factorParam = 1; + + if (_cmd.hasOption("min")) min = Double.parseDouble(_cmd.getOptionValue("min")); + if (_cmd.hasOption("max")) max = Double.parseDouble(_cmd.getOptionValue("max")); + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + if (_cmd.hasOption("diagonal")) diagSize = Integer.parseInt(_cmd.getOptionValue("diagonal")); + if (_cmd.hasOption("saturated")) saturatedPixel = Double.parseDouble(_cmd.getOptionValue("saturated")); + if (_cmd.hasOption("isDroso")) isDroso = Boolean.parseBoolean(_cmd.getOptionValue("isDroso")); + if (_cmd.hasOption("factor")){ + factorParam = Integer.parseInt(_cmd.getOptionValue("factor")); + _parameterCheck.checkFactor(factorParam); + } + + _sipIntra = new SIPIntra(_output, _chrSizeFile, gauss, min, max, resolution, saturatedPixel, + thresholdMax, diagSize, matrixSize, _nbZero, factorParam, fdr, isDroso,_delImages, _cpu); + } + /** + * + * + */ + private void setSipIntraGUI(){ + _sipIntra = new SIPIntra(_output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getMin(), + _guiAnalysis.getMax(), _guiAnalysis.getResolution(), _guiAnalysis.getSaturatedPixel(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getDiagSize(), _guiAnalysis.getMatrixSize(), + _nbZero, _guiAnalysis.getFactorChoice(), _guiAnalysis.getFDR(), _guiAnalysis.isDroso(),_delImages, _cpu); + } + + /** + * + * + */ + private void setSipInter(){ + + if(_isGui){ + _sipInter = new SIPInter(_output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getResolution(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getMatrixSize(), _nbZero, _guiAnalysis.getFDR(), _delImages,_cpu); + + }else{ + double gauss = 1; + int matrixSize = 500; + double thresholdMax = 10; + double fdr = 0.025; + int resolution = 100000; + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + _sipInter = new SIPInter(_output, _chrSizeFile, gauss, resolution, thresholdMax, matrixSize, _nbZero, fdr, _delImages,_cpu); + } + + + } +} diff --git a/src/main/java/plop/process/HiC.java b/src/main/java/plop/process/HiC.java new file mode 100644 index 0000000..ec4cbd3 --- /dev/null +++ b/src/main/java/plop/process/HiC.java @@ -0,0 +1,283 @@ +package plop.process; + + +import plop.cli.CLIHelper; +import plop.cli.CLIOptionHiC; +import plop.gui.GuiAnalysis; +import plop.multiProcessing.ProcessDetectLoops; +import plop.multiProcessing.ProcessDumpHic; +import org.apache.commons.cli.CommandLine; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; +import plop.utils.MultiResProcess; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + + +/** + * + */ +public class HiC { + /** */ + private SIPIntra _sipIntra; + /** */ + private SIPInter _sipInter; + /** */ + private CommandLine _cmd; + /** */ + private String _input; + /** */ + private String _output; + /** */ + private String _chrSizeFile; + /** */ + private boolean _delImages = true; + /** */ + private int _cpu =1; + /** */ + private boolean _isGui; + /** */ + private GuiAnalysis _guiAnalysis; + /** */ + private String _juicerTool; + /** */ + private String _interOrIntra; + /** */ + private ParametersCheck _parameterCheck; + /** */ + private String _juicerNorm = "KR"; + /** */ + private String _log; + + /** + * + * @param args + * @throws Exception + */ + public HiC(String args []){ + _isGui = false; + CLIOptionHiC cli = new CLIOptionHiC(args); + _cmd = cli.getCommandLine(); + _input = _cmd.getOptionValue("input"); + _output = _cmd.getOptionValue("output"); + System.out.println(_input+"\n"+_output+"\n"+_cmd.getOptionValue("j")); + _log = _output+File.separator+"log.txt"; + } + + /** + * + * @param guiAnalysis + */ + public HiC(GuiAnalysis guiAnalysis ){ + _isGui = true; + _guiAnalysis = guiAnalysis; + _input = this._guiAnalysis.getInput(); + _output = this._guiAnalysis.getOutputDir(); + _log = _output+File.separator+"log.txt"; + } + /** + * + * Normalisation method to dump the the data with hic method (KR,NONE.VC,VC_SQRT) + * + * + * @throws IOException + * @throws InterruptedException + */ + public void run() throws IOException, InterruptedException { + String allParam; + if(_isGui) { + _juicerTool = this._guiAnalysis.getJuicerTool(); + if(this._guiAnalysis.isInter()) _interOrIntra = "inter"; + else _interOrIntra = "intra"; + _chrSizeFile = this._guiAnalysis.getChrSizeFile(); + if(this._guiAnalysis.isNONE()) _juicerNorm = "NONE"; + else if (this._guiAnalysis.isVC()) _juicerNorm = "VC"; + else if (this._guiAnalysis.isVC_SQRT()) _juicerNorm = "VC_SQRT"; + _delImages = this._guiAnalysis.isDeletTif(); + _cpu = this._guiAnalysis.getNbCpu(); + }else { + /* common required parameters*/ + _juicerTool = _cmd.getOptionValue("juicerTool"); + _interOrIntra = _cmd.getOptionValue("lt"); + System.out.println(_interOrIntra); + _chrSizeFile = _cmd.getOptionValue("chrSize"); + /* common optional parameters */ + if (_cmd.hasOption("norm")) _juicerNorm = _cmd.getOptionValue("norm"); + if (_cmd.hasOption("keepImage"))_delImages = false; + if (_cmd.hasOption("cpu")) _cpu = Integer.parseInt(_cmd.getOptionValue("cpu")); + } + + File file = new File(_output); + if(!file.exists()) file.mkdir(); + + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(_log))); + + _parameterCheck = new ParametersCheck(_input, _chrSizeFile, _interOrIntra, writer,false); + _parameterCheck.testHiCOption(_juicerTool, _juicerNorm); + + if(_interOrIntra.equals("intra")) + allParam = runIntra(); + else + allParam = runInter(); + + ; + writer.write(allParam); + writer.close(); + } + + /** + * + * @return + * @throws IOException + * @throws InterruptedException + */ + private String runIntra() throws IOException, InterruptedException { + /* Param spe intra chromosomal loop*/ + if(_isGui) this.setSipIntraGUI(); + else this.setSipIntraCLI(); + + _sipIntra.setIsGui(_isGui); + _sipIntra.setIsProcessed(false); + _sipIntra.setIsCooler(false); + + + _parameterCheck.optionalParametersValidity(_sipIntra); + _parameterCheck.speOption(_sipIntra); + System.out.println("########### Starting dump Step inter chromosomal interactions"); + ProcessDumpHic processDumpData = new ProcessDumpHic(); + processDumpData.go(_input, _sipIntra, _juicerTool, _juicerNorm); + System.out.println("########### End of the dump step\n"); + + System.out.println("########### Start loop detection\n"); + MultiResProcess multi = new MultiResProcess(_sipIntra, _chrSizeFile); + multi.run(); + System.out.println("###########End loop detection step\n"); + + // System.out.println(allParam); + return "SIPHiC hic: \n" + "input: "+_input+"\n" + "output: "+_output+"\n"+ "juiceBox: "+ _juicerTool +"\n"+ + "norm: "+ _juicerNorm +"\n" + "inter or intra chromosomal: "+ _interOrIntra +"\n" + "gauss: "+this._sipIntra.getGauss()+"\n"+ + "min: "+this._sipIntra.getMin()+"\n"+ "max: "+this._sipIntra.getMax()+"\n"+ "matrix size: "+this._sipIntra.getMatrixSize()+"\n"+ + "diagonal size: "+this._sipIntra.getDiagonalSize()+"\n"+ "resolution: "+this._sipIntra.getResolution()+"\n"+ "saturated pixel: "+this._sipIntra.getSaturatedPixel()+"\n"+ + "threshold: "+this._sipIntra.getThresholdMaxima()+"\n"+ "number of zero: "+this._sipIntra.getNbZero()+"\n"+ "factor: "+ _sipIntra.getFactor() +"\n"+ + "fdr: "+this._sipIntra.getFdr()+"\n"+ "delete images: "+_delImages+"\n"+ "cpu: "+ _cpu+"\n" + "isDroso: "+this._sipIntra.isDroso()+"\n"; + } + + + /** + * + * @throws IOException + */ + private String runInter() throws IOException, InterruptedException { + ProcessDumpHic processDumpData = new ProcessDumpHic(); + + this.setSipInter(); + _sipInter.setIsGui(_isGui); + _sipInter.setIsProcessed(false); + _sipInter.setIsCooler(false); + + _parameterCheck.optionalParametersValidity(_sipInter); + System.out.println("########### Starting dump Step inter chromosomal interactions"); + processDumpData.go(_input,_sipInter, _juicerTool, _juicerNorm); + System.out.println("########### !!! End dump Step inter chromosomal interactions"); + String loopFileRes = _sipInter.getOutputDir()+"finalLoops.txt"; + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(loopFileRes))); + ProcessDetectLoops detectLoops = new ProcessDetectLoops(); + + System.out.println("########### Starting loop detection"); + detectLoops.go(_sipInter, loopFileRes); + System.out.println("########### !!!!!!! end java.plop.loops detection"); + return "SIPHiC hic: \n" + "input: "+_input+"\n" + "output: "+_output+"\n"+ "juiceBox: "+ _juicerTool +"\n"+ + "norm: "+ _juicerNorm +"\n" + "inter or intra chromosomal: "+ _interOrIntra +"\n" + + "gauss: "+this._sipInter.getGauss()+"\n"+ "matrix size: "+this._sipInter.getMatrixSize()+"\n"+ + "resolution: "+this._sipInter.getResolution()+"\n"+ "threshold: "+this._sipInter.getThresholdMaxima()+"\n"+ + "number of zero :"+_sipInter.getNbZero()+"\n"+ "fdr "+this._sipInter.getFdr()+"\n"+ "delete images "+_delImages+"\n"+ + "cpu "+ _cpu+"\n"; + + } + + + /** + * + */ + private void setSipIntraCLI(){ + double min = 2.0; + double max = 2.0; + double gauss = 1.5; + int matrixSize = 2000; + double thresholdMax = 2800; + double fdr = 0.01; + int resolution = 5000; + int diagSize = 6; + double saturatedPixel = 0.01; + boolean isDroso = false; + int factorParam = 1; + int nbZero = 6; + try { + if (_cmd.hasOption("min")) min = Double.parseDouble(_cmd.getOptionValue("min")); + if (_cmd.hasOption("max")) max = Double.parseDouble(_cmd.getOptionValue("max")); + if (_cmd.hasOption("nbZero")) nbZero = Integer.parseInt(_cmd.getOptionValue("nbZero")); + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + if (_cmd.hasOption("diagonal")) diagSize = Integer.parseInt(_cmd.getOptionValue("diagonal")); + if (_cmd.hasOption("saturated")) saturatedPixel = Double.parseDouble(_cmd.getOptionValue("saturated")); + if (_cmd.hasOption("isDroso")){ isDroso = true; } + if (_cmd.hasOption("factor")){ + factorParam = Integer.parseInt(_cmd.getOptionValue("factor")); + _parameterCheck.checkFactor(factorParam); + } + _sipIntra = new SIPIntra(_output, _chrSizeFile, gauss, min, max, resolution, saturatedPixel, + thresholdMax, diagSize, matrixSize, nbZero, factorParam, fdr, isDroso,_delImages, _cpu); + }catch (NumberFormatException ex) { + System.out.println("\n!!!!!! Error number is needed : \n"+ex.toString()+"\n"); + CLIHelper.getHelperAllInfos(); + } catch (IOException e) { e.printStackTrace(); } + } + /** + * + * + */ + private void setSipIntraGUI(){ + + _sipIntra = new SIPIntra(_output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getMin(), + _guiAnalysis.getMax(), _guiAnalysis.getResolution(), _guiAnalysis.getSaturatedPixel(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getDiagSize(), _guiAnalysis.getMatrixSize(), + this._guiAnalysis.getNbZero(), _guiAnalysis.getFactorChoice(), _guiAnalysis.getFDR(), _guiAnalysis.isDroso(),_delImages, _cpu); + + + } + + /** + * + * + */ + private void setSipInter(){ + + if(_isGui){ + _sipInter = new SIPInter(_output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getResolution(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getMatrixSize(), _guiAnalysis.getNbZero(), _guiAnalysis.getFDR(), _delImages,_cpu); + + }else{ + double gauss = 1; + int matrixSize = 500; + double thresholdMax = 0.9; + double fdr = 0.025; + int resolution = 100000; + int nbZero = 3; + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("nbZero")) nbZero = Integer.parseInt(_cmd.getOptionValue("nbZero")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + _sipInter = new SIPInter(_output, _chrSizeFile, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr, _delImages,_cpu); + } + + + } +} diff --git a/src/main/java/plop/process/ParametersCheck.java b/src/main/java/plop/process/ParametersCheck.java new file mode 100644 index 0000000..9c82d9e --- /dev/null +++ b/src/main/java/plop/process/ParametersCheck.java @@ -0,0 +1,297 @@ +package plop.process; + + +import plop.cli.CLIHelper; +import plop.sip.SIPIntra; +import plop.sip.SIPObject; + +import java.io.*; + + +public class ParametersCheck { + + /** + * + */ + BufferedWriter _logwWriter; + + /** + * + */ + + String _logError; + + /** + * + * @param input + * @param chrSizeFile + * @param interOrIntra + */ + public ParametersCheck(String input, String chrSizeFile, String interOrIntra, BufferedWriter log, boolean processed) throws IOException { + _logwWriter = log; + File file = new File(input); + + if(processed && !file.isDirectory()){ + System.out.println("\nDirectory problem !!!!\n-i "+input+": need to be a directory with processed data from SIP !!! \n\n"); + _logwWriter.write("\nDirectory problem !!!!\n-i "+input+": need to be a directory with processed data from SIP !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + if(!file.exists() && !input.startsWith("https")){ + System.out.println("\nFile problem !!!!\n-i "+input+": this file doesn't existed !!! \n\n"); + _logwWriter.write("\nFile problem !!!!\n-i "+input+": this file doesn't existed !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + file = new File(chrSizeFile); + if(!file.exists()){ + System.out.println("\nFile problem !!!!\n-c "+chrSizeFile+": this file doesn't existed !!! \n\n"); + _logwWriter.write("\nFile problem !!!!\n-c "+chrSizeFile+": this file doesn't existed !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + if(!interOrIntra.equals("inter") && !interOrIntra.equals("intra")){ + System.out.println("\nParameter value error !!!!\n-tl "+interOrIntra+", wrong value, choose inter or intra !!! \n\n"); + _logwWriter.write("\nParameter value error !!!!\n-tl "+interOrIntra+", wrong value, choose inter or intra !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + } + + /** + * + * @param sip + */ + public void optionalParametersValidity(SIPObject sip) throws IOException { + if(sip.getResolution() <= 0 ){ + _logwWriter.write("Parameter value error !!!!\n-r "+sip.getResolution()+", resolution need to be a >= 0 !!! \n\n"); + _logwWriter.close(); + System.out.println("Parameter value error !!!!\n-r "+sip.getResolution()+", resolution need to be a >= 0 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + + + if (sip.getNbZero() > 24|| sip.getNbZero() < 0) { + _logwWriter.write("\nParameter value error !!!!\n-nb "+ sip.getNbZero() +" value invalid: choose an integer value between 0 and 24\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-nb "+ sip.getNbZero() +" value invalid: choose an integer value between 0 and 24\n"); + CLIHelper.getHelperInfos(); + } + + if(sip.getCpu() > Runtime.getRuntime().availableProcessors() || sip.getCpu() <= 0){ + System.out.println("\nParameter value error !!!!\n-cpu "+ sip.getCpu() +" is superior to server/computer' cpu "+Runtime.getRuntime().availableProcessors()+"\n"); + _logwWriter.write("\nParameter value error !!!!\n-cpu "+ sip.getCpu() +" is superior to server/computer' cpu "+Runtime.getRuntime().availableProcessors()+"\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + if(sip.getFdr() < 0 ){ + System.out.println("\nParameter value error !!!!\n-fdr "+sip.getFdr()+", fdr need to be a >= 0 !!! \n\n"); + _logwWriter.write("\nParameter value error !!!!\n-fdr "+sip.getFdr()+", fdr need to be a >= 0 !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + if(sip.getMatrixSize() < 0 ){ + System.out.println("Parameter value error !!!!\n-ms "+sip.getMatrixSize()+", matrix size need to be a > 0 !!! \n\n"); + _logwWriter.write("Parameter value error !!!!\n-ms "+sip.getMatrixSize()+", matrix size need to be a > 0 !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + if(sip.getGauss() < 0 ){ + System.out.println("\nParameter value error !!!!\n-g "+sip.getGauss()+", gaussian strength filter need to be a > 0 !!! \n\n"); + _logwWriter.write("\nParameter value error !!!!\n-g "+sip.getGauss()+", gaussian strength filter need to be a > 0 !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + + if(sip.getThresholdMaxima() < 0 ){ + System.out.println("\nParameter value error !!!!\n-t "+sip.getThresholdMaxima()+", threshold for java.plop.loops detection need to be a > 0 !!! \n\n"); + _logwWriter.write("\nParameter value error !!!!\n-t "+sip.getThresholdMaxima()+", threshold for java.plop.loops detection need to be a > 0 !!! \n\n"); + _logwWriter.close(); + CLIHelper.getHelperInfos(); + } + } + + + + /** + * + * @param coolTool + * @param cooler + */ + public void testCoolOption(String coolTool, String cooler) throws IOException { + + File f = new File(coolTool); + if(!f.exists()){ + System.out.println("File problem !!!!\n-coolTool "+coolTool+" doesn't existed or wrong path !!! \n\n"); + _logwWriter.write("\nFile problem !!!!\n-coolTool "+coolTool+" doesn't existed or wrong path !!! \n\n"); + _logwWriter.close(); + CLIHelper.CmdHelpCool(); + } + + f = new File(cooler); + if(!f.exists()){ + _logwWriter.write("\nFile problem !!!!\n-cooler "+cooler+" doesn't existed or wrong path !!! \n\n"); + _logwWriter.close(); + System.out.println("\nFile problem !!!!\n-cooler "+cooler+" doesn't existed or wrong path !!! \n\n"); + CLIHelper.CmdHelpCool(); + } + + if(!testTools(coolTool, 0, 3, 0) || !testTools(cooler, 0, 8, 6)) { + System.out.println("\nVersioning problem !!!!\n"+coolTool + " or" + cooler + + " version is not the good one for SIP (it needs cooltool version >= 0.3.0 and cooler version >= 0.8.6) !!! \n\n"); + _logwWriter.write("\nVersioning problem !!!!\n"+coolTool +" or" + cooler + + " version is not the good one for SIP (it needs cooltool version >= 0.3.0 and cooler version >= 0.8.6) !!! \n\n"); + _logwWriter.close(); + CLIHelper.CmdHelpCool(); + } + + } + + /** + * + * @param juicerTool + * @param juicerNorm + */ + public void testHiCOption(String juicerTool, String juicerNorm) throws IOException { + if (!juicerNorm.equals("KR") && !juicerNorm.equals("NONE") && !juicerNorm.equals("VC") && !juicerNorm.equals("VC_SQRT")) { + _logwWriter.write("\nParameter value error !!!!\n-norm = "+juicerNorm+", not defined for SIP, available norm: KR,NONE.VC,VC_SQRT\n Check the presence of this norm method in your hic file\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-norm = "+juicerNorm+", not defined for SIP, available norm: KR,NONE.VC,VC_SQRT\n Check the presence of this norm method in your hic file\n"); + CLIHelper.CmdHelpHiC(); + } + + File file = new File(juicerTool); + if(!file.exists()){ + _logwWriter.write("\nFile problem !!!!\n-j "+juicerTool+": this file doesn't existed !!! \n\n"); + _logwWriter.close(); + System.out.println("\nFile problem !!!!\n-j "+juicerTool+": this file doesn't existed !!! \n\n"); + CLIHelper.CmdHelpHiC(); + } + } + + /** + * + * @param factor + */ + public void checkFactor(int factor) throws IOException { + + if(factor < 1 || factor > 4 ){ + _logwWriter.write("\nParameter value error !!!!\n-f "+factor+", value for factor are 1, 2, 3 or 4 !!! \n\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-f "+factor+", value for factor are 1, 2, 3 or 4 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + } + + /** + * + * @param sipIntra + */ + public void speOption(SIPIntra sipIntra) throws IOException { + + if(sipIntra.getDiagonalSize() < 0 ){ + _logwWriter.write("\nParameter value error !!!!\n-d "+sipIntra.getDiagonalSize()+", diagonal size need to be a > 0 !!! \n\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-d "+sipIntra.getDiagonalSize()+", diagonal size need to be a > 0 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + + if(sipIntra.getMin() < 0 ){ + _logwWriter.write("\nParameter value error !!!!\n-min "+sipIntra.getMin()+", min strength filter need to be a > 0 !!! \n\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-min "+sipIntra.getMin()+", min strength filter need to be a > 0 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + + if(sipIntra.getMax() < 0 ){ + _logwWriter.write("\"Parameter value error !!!!\n-max "+sipIntra.getMax()+", max strength filter need to be a > 0 !!! \n\n"); + _logwWriter.close(); + System.out.println("\"Parameter value error !!!!\n-max "+sipIntra.getMax()+", max strength filter need to be a > 0 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + + if(sipIntra.getSaturatedPixel() < 0 ){ + _logwWriter.write("\nParameter value error !!!!\n-sat "+sipIntra.getSaturatedPixel()+", max strength filter need to be a > 0 !!! \n\n"); + _logwWriter.close(); + System.out.println("\nParameter value error !!!!\n-sat "+sipIntra.getSaturatedPixel()+", max strength filter need to be a > 0 !!! \n\n"); + CLIHelper.getHelperInfos(); + } + + } + + + /** + * + * @param pathTools + * @param first + * @param second + * @param third + * @return + */ + public boolean testTools(String pathTools, int first, int second, int third) { + Runtime runtime = Runtime.getRuntime(); + String cmd = pathTools+" --version"; + Process process; + try { + process = runtime.exec(cmd); + + new ReturnFlux(process.getInputStream()).start(); + new ReturnFlux(process.getErrorStream()).start(); + process.waitFor(); + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + String [] tline = _logError.split(" "); + System.out.println(_logError); + _logError = ""; + if(tline.length > 0){ + tline = tline[tline.length-1].split("\\."); + tline[2] = tline[2].replace("\n", ""); + if(Integer.parseInt(tline[0]) >= first && Integer.parseInt(tline[1]) >= second) //&& Integer.parseInt(tline[2]) >= third) + return true; + else + return false; + }else + return false; + } + + /** + * + */ + public class ReturnFlux extends Thread { + + /** Flux to redirect */ + private InputStream _flux; + + /** + * Constructor of ReturnFlux + * @param flux + * flux to redirect + */ + public ReturnFlux(InputStream flux){this._flux = flux; } + + /** + * + */ + public void run(){ + try { + InputStreamReader reader = new InputStreamReader(this._flux); + BufferedReader br = new BufferedReader(reader); + String line=null; + while ( (line = br.readLine()) != null) { + if(!line.contains("WARN")) _logError = _logError+line+"\n"; + } + } + catch (IOException ioe){ + ioe.printStackTrace(); + } + } + } + +} diff --git a/src/main/java/plop/process/Processed.java b/src/main/java/plop/process/Processed.java new file mode 100644 index 0000000..37336fc --- /dev/null +++ b/src/main/java/plop/process/Processed.java @@ -0,0 +1,260 @@ +package plop.process; + + +import plop.cli.CLIOptionProcessed; +import plop.gui.GuiAnalysis; +import plop.multiProcessing.ProcessDetectLoops; +import org.apache.commons.cli.CommandLine; +import plop.sip.SIPInter; +import plop.sip.SIPIntra; +import plop.utils.MultiResProcess; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +/** + * + */ +public class Processed { + /** */ + private SIPIntra _sipIntra; + /** */ + private SIPInter _sipInter; + /** */ + private CommandLine _cmd; + /** */ + private String _input; + /** */ + private String _output; + /** */ + private String _chrSizeFile; + /** */ + private boolean _delImages = true; + /** */ + private int _cpu = 1; + /** */ + private boolean _isGui; + /** */ + private GuiAnalysis _guiAnalysis; + /** */ + private String _interOrIntra; + /** */ + private ParametersCheck _parameterCheck; + /** */ + String _log; + + /** + * + * @param args + * @throws Exception + */ + public Processed(String args []){ + _isGui = false; + CLIOptionProcessed cli = new CLIOptionProcessed(args); + _cmd = cli.getCommandLine(); + _input = _cmd.getOptionValue("input"); + _output = _cmd.getOptionValue("output"); + _log = _output+File.separator+"log.txt"; + + } + + /** + * + * @param guiAnalysis + */ + public Processed(GuiAnalysis guiAnalysis ){ + _isGui = true; + _guiAnalysis = guiAnalysis; + _input = this._guiAnalysis.getInput(); + _output = this._guiAnalysis.getOutputDir(); + _log = _output+File.separator+"log.txt"; + } + /** + * + * Normalisation method to dump the the data with hic method (KR,NONE.VC,VC_SQRT) + * + * + * @throws IOException + * @throws InterruptedException + */ + public void run() throws IOException, InterruptedException { + + String allParam; + + if(_isGui) { + if(this._guiAnalysis.isInter()) _interOrIntra = "inter"; + else _interOrIntra = "intra"; + _chrSizeFile = this._guiAnalysis.getChrSizeFile(); + _delImages = this._guiAnalysis.isDeletTif(); + _cpu = this._guiAnalysis.getNbCpu(); + }else { + /* common required parameters*/ + _interOrIntra = _cmd.getOptionValue("lt"); + _chrSizeFile = _cmd.getOptionValue("chrSize"); + /* common optional parameters */ + if (_cmd.hasOption("keepImage"))_delImages = false; + if (_cmd.hasOption("cpu")) _cpu = Integer.parseInt(_cmd.getOptionValue("cpu")); + } + File file = new File(_output); + if(!file.exists()) file.mkdir(); + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(_log))); + + _parameterCheck = new ParametersCheck(_input, _chrSizeFile, _interOrIntra, writer,true); + + if(_interOrIntra.equals("intra")) + allParam = runIntra(); + else + allParam = runInter(); + + + writer.write(allParam); + writer.close(); + + + } + + /** + * + * @return + * @throws IOException + * @throws InterruptedException + */ + private String runIntra() throws IOException, InterruptedException { + /* Param spe intra chromosomal loop*/ + if(_isGui) + this.setSipIntraGUI(); + else + this.setSipIntraCLI(); + + _sipIntra.setIsGui(_isGui); + _sipIntra.setIsProcessed(true); + _sipIntra.setIsCooler(false); + + + _parameterCheck.optionalParametersValidity(_sipIntra); + _parameterCheck.speOption(_sipIntra); + + System.out.println("########### Start loop detection\n"); + MultiResProcess multi = new MultiResProcess(_sipIntra, _chrSizeFile); + multi.run(); + System.out.println("###########End loop detection step\n"); + return "SIPHiC processed: \n" + "input: "+_input+"\n" + "output: "+_output+"\n"+ + "inter or intra chromosomal: "+ _interOrIntra +"\n" + "gauss: "+this._sipIntra.getGauss()+"\n"+ + "min: "+this._sipIntra.getMin()+"\n"+ "max: "+this._sipIntra.getMax()+"\n"+ "matrix size: "+this._sipIntra.getMatrixSize()+"\n"+ + "diagonal size: "+this._sipIntra.getDiagonalSize()+"\n"+ "resolution: "+this._sipIntra.getResolution()+"\n"+ + "saturated pixel: "+this._sipIntra.getSaturatedPixel()+"\n"+ "threshold: "+this._sipIntra.getThresholdMaxima()+"\n"+ + "number of zero: "+this._sipIntra.getNbZero()+"\n"+ "factor: "+ _sipIntra.getFactor() +"\n"+ "fdr: "+this._sipIntra.getFdr()+"\n"+ "delete images: "+_delImages+"\n"+ + "cpu: "+ _cpu+"\n" + "isDroso: "+this._sipIntra.isDroso()+"\n"; + } + + + /** + * + * @throws IOException + */ + private String runInter() throws IOException, InterruptedException { + + + this.setSipInter(); + _sipInter.setIsGui(_isGui); + _sipInter.setIsProcessed(true); + _sipInter.setIsCooler(false); + + _parameterCheck.optionalParametersValidity(_sipInter); + + String loopFileRes = _sipInter.getOutputDir()+"finalLoops.txt"; + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(loopFileRes))); + + System.out.println("########### Start loop detection\n"); + ProcessDetectLoops detectLoops = new ProcessDetectLoops(); + detectLoops.go(_sipInter, loopFileRes); + System.out.println("###########End loop detection step\n"); + + return "SIPHiC processed: \n" + "input: "+_input+"\n" + "output: "+_output+"\n"+ "inter or intra chromosomal: "+ _interOrIntra +"\n" + + "gauss: "+this._sipInter.getGauss()+"\n"+ "matrix size: "+this._sipInter.getMatrixSize()+"\n"+ "resolution: "+this._sipInter.getResolution()+"\n"+ + "threshold: "+this._sipInter.getThresholdMaxima()+"\n"+ "number of zero :"+_sipInter.getNbZero()+"\n"+"fdr "+this._sipInter.getFdr()+"\n"+ "delete images "+_delImages+"\n"+ + "cpu "+ _cpu+"\n"; + + } + + + /** + * + */ + private void setSipIntraCLI() throws IOException { + double min = 2.0; + double max = 2.0; + double gauss = 1.5; + int matrixSize = 2000; + double thresholdMax = 2800; + double fdr = 0.01; + int resolution = 5000; + int diagSize = 6; + double saturatedPixel = 0.01; + boolean isDroso = false; + int factorParam = 1; + int nbZero = 6; + + if (_cmd.hasOption("min")) min = Double.parseDouble(_cmd.getOptionValue("min")); + if (_cmd.hasOption("max")) max = Double.parseDouble(_cmd.getOptionValue("max")); + if (_cmd.hasOption("nbZero")) nbZero = Integer.parseInt(_cmd.getOptionValue("nbZero")); + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + if (_cmd.hasOption("diagonal")) diagSize = Integer.parseInt(_cmd.getOptionValue("diagonal")); + if (_cmd.hasOption("saturated")) saturatedPixel = Double.parseDouble(_cmd.getOptionValue("saturated")); + if (_cmd.hasOption("isDroso")) isDroso = true; + if (_cmd.hasOption("factor")){ + factorParam = Integer.parseInt(_cmd.getOptionValue("factor")); + _parameterCheck.checkFactor(factorParam); + } + + _sipIntra = new SIPIntra(_input,_output, _chrSizeFile, gauss, min, max, resolution, saturatedPixel, + thresholdMax, diagSize, matrixSize, nbZero, factorParam, fdr, isDroso,_delImages, _cpu); + } + /** + * + * + */ + private void setSipIntraGUI(){ + _sipIntra = new SIPIntra(_input, _output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getMin(), + _guiAnalysis.getMax(), _guiAnalysis.getResolution(), _guiAnalysis.getSaturatedPixel(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getDiagSize(), _guiAnalysis.getMatrixSize(), + this._guiAnalysis.getNbZero(), _guiAnalysis.getFactorChoice(), _guiAnalysis.getFDR(), _guiAnalysis.isDroso(),_delImages, _cpu); + + + } + + /** + * + * + */ + private void setSipInter() { + + if(_isGui){ + _sipInter = new SIPInter(_input,_output, _chrSizeFile, _guiAnalysis.getGaussian(), _guiAnalysis.getResolution(), + _guiAnalysis.getThresholdMaxima(), _guiAnalysis.getMatrixSize(), this._guiAnalysis.getNbZero(), _guiAnalysis.getFDR(), _delImages,_cpu); + + }else{ + double gauss = 1; + int matrixSize = 500; + double thresholdMax = 0.01; + double fdr = 0.025; + int resolution = 1000000; + int nbZero = 3; + if (_cmd.hasOption("gaussian")) gauss = Double.parseDouble(_cmd.getOptionValue("gaussian")); + if (_cmd.hasOption("matrixSize")) matrixSize = Integer.parseInt(_cmd.getOptionValue("matrixSize")); + if (_cmd.hasOption("threshold")) thresholdMax = Double.parseDouble(_cmd.getOptionValue("threshold")); + if (_cmd.hasOption("fdr")) fdr = Double.parseDouble(_cmd.getOptionValue("fdr")); + if (_cmd.hasOption("resolution")) resolution = Integer.parseInt(_cmd.getOptionValue("resolution")); + if (_cmd.hasOption("nbZero")) nbZero = Integer.parseInt(_cmd.getOptionValue("nbZero")); + _sipInter = new SIPInter(_input,_output, _chrSizeFile, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr, _delImages,_cpu); + } + + + } +} diff --git a/src/main/java/plop/sip/SIPInter.java b/src/main/java/plop/sip/SIPInter.java new file mode 100644 index 0000000..9242d89 --- /dev/null +++ b/src/main/java/plop/sip/SIPInter.java @@ -0,0 +1,99 @@ +package plop.sip; + +import plop.utils.FDR; +import plop.loops.Loop; + +import java.io.*; +import java.util.*; + +/** + * + * + * @author axel poulet + * + */ + +public class SIPInter extends SIPObject { + + + /** + * + * constructor for hic file + * + * @param output output path + * @param chrSize chr size path + * @param gauss gaussian filter strength + * @param resolution bins size + * @param thresholdMax threshold value for java.plop.loops detection + * @param matrixSize image size + * @param nbZero nb of zero allowed around a loop + * @param fdr fdr value for the final java.plop.loops filter + */ + public SIPInter(String output,String chrSize, double gauss, int resolution, double thresholdMax, int matrixSize, int nbZero,double fdr, + boolean delTif, int cpu) { + super(output, gauss, resolution, thresholdMax,matrixSize, nbZero, fdr,chrSize, delTif, cpu) ; + + } + + /** + * constructor for processed data + * + * @param input input file with SIP file + * @param output output path + * @param chrSize chr size path + * @param gauss gaussian filter strength + * @param resolution bins size + * @param thresholdMax threshold value for java.plop.loops detection + * @param matrixSize image size + * @param nbZero nb of zero allowed around a loop + * @param fdr fdr value for the final java.plop.loops filter + * @throws IOException exception + */ + public SIPInter(String input,String output,String chrSize, double gauss, int resolution, + double thresholdMax, int matrixSize, int nbZero, double fdr, boolean delTif, int cpu){ + + super(input, output, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr, chrSize, delTif, cpu); + + + } + + /** + * Write detected java.plop.loops after filtering via the fdr value + * @param pathFile path for the output file + * @param hLoop hashmap loopsName => Loop object + * @param first boolean if true it is the first results so need to write the header + * @throws IOException exception + */ + public void writeResu(String pathFile, HashMap hLoop, boolean first) throws IOException { + double fdr = this.getFdr(); + FDR fdrDetection = new FDR (fdr, hLoop); + fdrDetection.run(); + double RFDRcutoff = fdrDetection.getRFDRCutoff(); + double FDRcutoff = fdrDetection.getFDRCutoff(); + System.out.println("Filtering value at "+fdr+" FDR is "+FDRcutoff+" APscore and "+RFDRcutoff+" RegionalAPscore\n"); + BufferedWriter writer; + + if(first) writer = new BufferedWriter(new FileWriter(new File(pathFile), true)); + else{ + writer = new BufferedWriter(new FileWriter(new File(pathFile))); + writer.write("chromosome1\tx1\tx2\tchromosome2\ty1\ty2\tcolor\tAPScoreAvg\tAPRegScoreAvg\tAvg_diffMaxNeighbour_1\tAvg_diffMaxNeighbour_2\tavg\tstd\tvalue\tvalueDiff\tnbOfZero\tProbabilityofEnrichment\n"); + } + + if(hLoop.size()>0) { + Set key = hLoop.keySet(); + Iterator it = key.iterator(); + while (it.hasNext()) { + Loop loop = hLoop.get(it.next()); + ArrayList coord = loop.getCoordinates(); + if (loop.getPaScoreAvg() > FDRcutoff && loop.getRegionalPaScoreAvg() > RFDRcutoff ){//&& loop.getValue() >= 8 && loop.getValueDiff() > 1.3){//){//&& loop.getValueDiff() > 1.3 && loop.getValue() >= 8) { + writer.write(loop.getChr() + "\t" + coord.get(0) + "\t" + coord.get(1) + "\t" + loop.getChr2() + "\t" + coord.get(2) + "\t" + coord.get(3) + "\t0,0,0" + + "\t" + loop.getPaScoreAvg() + "\t" + loop.getRegionalPaScoreAvg() + "\t" + loop.getNeigbhoord1() + "\t" + loop.getNeigbhoord2() + "\t" + loop.getAvg() + "\t" + + loop.getStd() + "\t" + loop.getValue() + "\t" +loop.getValueDiff() + "\t" + loop.getNbOfZero() +"\t"+loop.getPaScoreAvgdev()+"\n"); + } + } + } + writer.close(); + } +} + + diff --git a/src/main/java/plop/sip/SIPIntra.java b/src/main/java/plop/sip/SIPIntra.java new file mode 100644 index 0000000..4f25e1c --- /dev/null +++ b/src/main/java/plop/sip/SIPIntra.java @@ -0,0 +1,374 @@ +package plop.sip; + +import plop.utils.FDR; +import plop.loops.Loop; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + + +/** + * Analyse and detect a whole genome HiC with .hic file or already processed data. + * The class is used for the observed and oMe method. + * + * MorpholibJ method used + * + * Collection of mathematical morphology methods and plugins for ImageJ, created at the INRA-IJPB Modeling and Digital Imaging lab. + * David Legland, Ignacio Arganda-Carreras, Philippe Andrey; MorphoLibJ: integrated library and plugins for mathematical morphology with ImageJ. + * Bioinformatics 2016; 32 (22): 3532-3534. doi: 10.1093/bioinformatics/btw413 + * + * @author axel poulet + * + */ +public class SIPIntra extends SIPObject { + + private double _min; + /** Strength of the max filter*/ + private double _max; + /** % of staurated pixel after enhance contrast*/ + private double _saturatedPixel; + /** Diage size to removed maxima close to diagonal*/ + private int _diagonalSize; + /** Size of the step to java.plop.process each chr (step = matrixSize/2)*/ + private int _step; + /** list of the image resolution to find loop*/ + private ArrayList _listFactor = new ArrayList(); + /** if true regional fdr will be not used*/ + private boolean _isDroso = false; + /** median of loop AP score */ + private double _medianAP = 0; + /** median of loop regional AP score */ + private double _medianAPReg = 0; + private int _factor = 0; + + + /** + * + */ + public SIPIntra() { } + + /** + * SIPIntra constructor for hic or mcool file + * + * + * @param output path file with the file created by the first step of SIP + * @param gauss gaussian filter strength + * @param min minimum filter strength + * @param max maximum filter strength + * @param resolution bin size + * @param saturatedPixel percentage of saturated pixel for image histogram normalization + * @param thresholdMax threshold for loop detection with findMaxima + * @param diagonalSize size of the diagonal, where the value will be not use + * @param matrixSize size of the image + * @param nbZero number of zero allowed around java.plop.loops + * @param factor multi resolution calling java.plop.loops used this list of factor + * @param fdr fdr value for final java.plop.loops filtering + * @param isDroso false if it isn't drosophila input + */ + public SIPIntra(String output, String chrFile, double gauss, double min, + double max, int resolution, double saturatedPixel, double thresholdMax, + int diagonalSize, int matrixSize, int nbZero, int factor, + double fdr, boolean isDroso, boolean delImage, int cpu) { + + super( output, output, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr, chrFile, delImage, cpu); + + + + this._min = min; + this._max = max; + this._saturatedPixel = saturatedPixel; + this._diagonalSize = diagonalSize; + this._step = matrixSize/2; + this._isDroso = isDroso; + this._factor = factor; + _listFactor.add(1); + if (_factor == 2) _listFactor.add(2); + else if (_factor == 4) { + _listFactor.add(2); + _listFactor.add(5); + } else if(_factor == 3) _listFactor.add(5); + } + + /** + * SIPIntra constructor for processed SIP data + * + * @param input path file with the file created by the first step of SIP + * @param output path file for the results + * @param chrSize hashMap name chr => chr size + * @param gauss gaussian filter strength + * @param min minimum filter strength + * @param max maximum filter strength + * @param resolution bin size + * @param saturatedPixel percentage of saturated pixel for image histogram normalization + * @param thresholdMax threshold for loop detection with findMaxima + * @param diagonalSize size of the diagonal, where the value will be not use + * @param matrixSize size of the image + * @param nbZero number of zero allowed around java.plop.loops + * @param factor multi resolution calling java.plop.loops used this list of factor + * @param fdr fdr value for final java.plop.loops filtering + */ + public SIPIntra(String input, String output, String chrSize, double gauss, double min, + double max, int resolution, double saturatedPixel, double thresholdMax, + int diagonalSize, int matrixSize, int nbZero, int factor, + double fdr, boolean isDroso, boolean delImage, int cpu) { + + super( input, output, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr, chrSize, delImage,cpu ); + + + this._min = min; + this._max = max; + this._saturatedPixel = saturatedPixel; + this._diagonalSize = diagonalSize; + this._step = matrixSize/2; + this._isDroso = isDroso; + this._factor = factor; + _listFactor.add(1); + if (_factor == 2) _listFactor.add(2); + else if (_factor == 4) { + _listFactor.add(2); + _listFactor.add(5); + } else if(_factor == 3) _listFactor.add(5); + + + } + + + /** + * Save the result file in tabulated file + * + * @param pathFile String path for the results file + * @param first boolean to know idf it is teh first chromo + * @param data hashMap loop name => Loop object + * @throws IOException exception + */ + public void saveFile(String pathFile, HashMap data, boolean first) throws IOException{ + double fdr = this.getFdr(); + FDR fdrDetection = new FDR (fdr, data); + fdrDetection.run(); + double RFDRcutoff = fdrDetection.getRFDRCutoff(); + double FDRcutoff = fdrDetection.getFDRCutoff(); + boolean supToTen = false; + if(this._isDroso){ + median(data,FDRcutoff); + System.out.println("Filtering value at "+fdr+" FDR is "+FDRcutoff+" APscore "); + if(_medianAPReg > 10){ + supToTen = true; + _medianAPReg = _medianAPReg/4; + _medianAP = _medianAP/10; + } + } + else + System.out.println("Filtering value at "+fdr+" FDR is "+FDRcutoff+" APscore and "+RFDRcutoff+" RegionalAPscore\n"); + BufferedWriter writer; + if(first) writer = new BufferedWriter(new FileWriter(new File(pathFile), true)); + else{ + writer = new BufferedWriter(new FileWriter(new File(pathFile))); + writer.write("chromosome1\tx1\tx2\tchromosome2\ty1\ty2\tcolor\tAPScoreAvg\tProbabilityofEnrichment\tRegAPScoreAvg\tAvg_diffMaxNeihgboor_1\tAvg_diffMaxNeihgboor_2\tavg\tstd\tvalue\n"); + } + + if(data.size()>0){ + Set key = data.keySet(); + Iterator it = key.iterator(); + while (it.hasNext()){ + String name = it.next(); + Loop loop = data.get(name); + ArrayList coord = loop.getCoordinates(); + if(this._isDroso){ + if(loop.getPaScoreAvg() > FDRcutoff && loop.getPaScoreAvgdev() > .9 && (loop.getNeigbhoord1() > 1 || loop.getNeigbhoord2() > 1)){ + if(supToTen){ + if(loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.7) && loop.getRegionalPaScoreAvg() <= (_medianAPReg*2)&& loop.getPaScoreAvg() <= (_medianAP*2)){ + writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" + +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" + +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" + +loop.getStd()+"\t"+loop.getValue()+"\n"); + } + }else{ + if( loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.5) && loop.getRegionalPaScoreAvg() <= (_medianAPReg*2)&& loop.getPaScoreAvg() <= (_medianAP*2)){ + writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" + +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" + +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" + +loop.getStd()+"\t"+loop.getValue()+"\n"); + } + } + } + }else{ + if(loop.getPaScoreAvg() > FDRcutoff && loop.getRegionalPaScoreAvg() > RFDRcutoff && loop.getPaScoreAvgdev() > .9){ + writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" + +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" + +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" + +loop.getStd()+"\t"+loop.getValue()+"\n"); + } + } + } + writer.close(); + } + } + + + /** + * Test the normalized vector by chromosome and return a hashMap with biased coordinate. + * if java.plop.loops is detected around this region in theis hashMap the loop will be deleted + * + * @param normFile normalized file + */ + public HashMap getNormValueFilter(String normFile){ + BufferedReader br; + int lineNumber = 0; + HashMap vector = new HashMap(); + try { + br = new BufferedReader(new FileReader(normFile)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null){ + sb.append(line); + if((line.equals("NaN")|| line.equals("NAN") || line.equals("nan") || line.equals("na") || Double.parseDouble(line) < 0.30)){ + vector.put(lineNumber*this.getResolution(), "plop"); + } + ++lineNumber; + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + } catch (IOException e) { e.printStackTrace();} + return vector; + } + + + /** + * compute median of pa score and regional pa score for a set of java.plop.loops + * + * @param data hashMap java.plop.loops name=> Loop object + * @param fdrCutoff fdr cutoff + */ + private void median(HashMap data, double fdrCutoff){ + Set key = data.keySet(); + Iterator it = key.iterator(); + ArrayList n1 = new ArrayList (); + ArrayList n2 = new ArrayList (); + int nb = 0; + while (it.hasNext()){ + String name = it.next(); + Loop loop = data.get(name); + if(loop.getPaScoreAvg() > fdrCutoff && loop.getPaScoreAvgdev() > .9){ + n1.add(loop.getPaScoreAvg()); + n2.add(loop.getRegionalPaScoreAvg()); + nb++; + } + } + if(nb>0){ + n1.sort(Comparator.naturalOrder()); + n2.sort(Comparator.naturalOrder()); + double pos1 = Math.floor((n1.size() - 1.0) / 2.0); + double pos2 = Math.ceil((n1.size() - 1.0) / 2.0); + if (pos1 == pos2 ) _medianAP = n1.get((int)pos1); + else _medianAP = (n1.get((int)pos1) + n1.get((int)pos2)) / 2.0 ; + pos1 = Math.floor((n2.size() - 1.0) / 2.0); + pos2 = Math.ceil((n2.size() - 1.0) / 2.0); + if (pos1 == pos2 ) _medianAPReg = n2.get((int)pos1); + else _medianAPReg = (n2.get((int)pos1) + n2.get((int)pos2)) / 2.0 ; + System.out.println("AP\t"+_medianAP+"\nAPREG\t"+_medianAPReg); + } + } + + + /** + * Getter of step + * @return the step + */ + public int getStep(){ return this._step;} + + + + /** + * Getter of diagonalSize + * @return integer size of diagonal + */ + public int getDiagonalSize(){ return this._diagonalSize;} + /** + * Setter of the diagonal size + * @param diagonalSize int of the size of the diagonal + */ + public void setDiagonalSize(int diagonalSize){ this._diagonalSize = diagonalSize; } + + /** + * Getter of the min filter strength + * @return double strength of the min filter + */ + public double getMin(){ return this._min;} + + /** + * Setter of the min filter strength + * @param min new filter min strength + */ + public void setMin(double min){ this._min = min;} + + /** + * Getter of the max filter strength + * @return double max filter + */ + public double getMax(){ return this._max; } + + /** + * Setter of the min filter strength + * @param max double max filter + */ + public void setMax(double max){ this._max = max;} + + /** + * Getter % of saturated pixel for the contrast enhancement + * @return double percentage of saturated pixel + */ + public double getSaturatedPixel(){ return this._saturatedPixel; } + + /** + * Setter % of saturated pixel for the contrast enhancement + * @param saturatedPixel double percentage of saturated pixel + */ + public void setSaturatedPixel(double saturatedPixel){ this._saturatedPixel = saturatedPixel; } + + + + /** + * setter step between image + * @param step int step + */ + public void setStep(int step){ this._step = step;} + + + /** + * Getter of list of integer for multi resolution loop calling + * @return list of integer + */ + public ArrayList getListFactor() {return this._listFactor;} + + /** + * boolean isDroso + * @return boolean + */ + public boolean isDroso(){return this._isDroso;} + + /** + * setter + * @param droso boolean + */ + public void setIsDroso(boolean droso){ this._isDroso = droso;} + + /** + * Getter of list of integer for multi resolution loop calling + * @return list of integer + */ + public int getFactor() {return this._factor;} + + + + +} \ No newline at end of file diff --git a/src/main/java/plop/sip/SIPObject.java b/src/main/java/plop/sip/SIPObject.java new file mode 100644 index 0000000..c3ecc21 --- /dev/null +++ b/src/main/java/plop/sip/SIPObject.java @@ -0,0 +1,331 @@ +package plop.sip; + + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Analyse and detect a whole genome HiC with .hic file or already processed data. + * The class is used for the observed and oMe method. + * + * + * @author axel poulet + * + */ +public class SIPObject { + + + /** String path of the input data*/ + private String _input; + /** Path of the output file*/ + private String _output; + /** Strength of the gaussian filter*/ + private double _gauss; + /** double fdr value choose by the user*/ + private double _fdr; + /** Image size*/ + private int _matrixSize; + /** Resolution of the bin dump in base*/ + private int _resolution; + /** Threshold for the maxima detection*/ + private double _thresholdMaxima; + /** Number of pixel = 0 allowed around the loop*/ + private int _nbZero; + /** is processed booelan*/ + private boolean _isProcessed; + /** if is java.plop.gui analysis*/ + private boolean _isGui; + /** if data set is mcool format*/ + private boolean _isCooler; + /** */ + private boolean _delImage; + /** HashMap of the chr size, the key = chr name, value = size of chr*/ + private HashMap _chrSizeHashMap = new HashMap(); + /** */ + private String _chrSizeFile; + /** */ + private ArrayList _listChr = new ArrayList<>(); + private int _cpu; + + /** + * + * @param input + * @param output + * @param gauss + * @param resolution + * @param thresholdMax + * @param matrixSize + * @param nbZero + * @param fdr + */ + public SIPObject (String input, String output, double gauss, int resolution, double thresholdMax, int matrixSize, int nbZero, double fdr, String chrSizeFile, + boolean delTif, int cpu){ + if(!output.endsWith(File.separator)) output = output+File.separator; + if(!input.endsWith(File.separator)) input = input+File.separator; + this._input = input; + this._output = output; + System.out.println("dans SIPObject: "+output); + this._gauss = gauss; + this._resolution = resolution; + this._thresholdMaxima = thresholdMax; + this._matrixSize = matrixSize; + this._nbZero = nbZero; + this._fdr = fdr; + this._chrSizeFile = chrSizeFile; + setChrSize(this._chrSizeFile); + this._delImage = delTif; + this._cpu = cpu; + } + + /** + * + * @param output + * @param gauss + * @param resolution + * @param thresholdMax + * @param matrixSize + * @param nbZero + * @param fdr + */ + public SIPObject ( String output, double gauss, int resolution, double thresholdMax, int matrixSize, int nbZero, double fdr, String chrSizeFile, + boolean delTif, int cpu){ + if(!output.endsWith(File.separator)) output = output+File.separator; + this._input = output; + this._gauss = gauss; + this._resolution = resolution; + this._thresholdMaxima = thresholdMax; + this._matrixSize = matrixSize; + this._nbZero = nbZero; + _fdr = fdr; + this._chrSizeFile = chrSizeFile; + setChrSize(this._chrSizeFile); + this._delImage = delTif; + this._cpu = cpu; + + + + } + + public SIPObject(){ + + } + + + /** + * getter of cpu parameter + * @return nb of cpu + */ + public String getChrSizeFile() { return this._chrSizeFile; } + + /** + * getter of cpu parameter + * @return nb of cpu + */ + public int getCpu() { return this._cpu; } + + /** + * setter of cpu number + * @param cpu number + * + */ + public void setCpu(int cpu) { this._cpu = cpu; } + + + + /** + * getter of fdr parameter + * @return fdr value + */ + public double getFdr() { return this._fdr; } + + /** + * setter of fdr value + * @param fdr new fdr value + * + */ + public void setFdr(double fdr) { this._fdr = fdr; } + /** + * Getter of the input dir + * @return path of the input dir + */ + public String getInputDir(){ return this._input; } + + /** + * Getter of the matrix size + * @return the size of the image + */ + public int getMatrixSize(){ return this._matrixSize; } + + /** + * Setter of the path of the input directory + * @param inputDir String of the input directory + */ + public void setInputDir(String inputDir){ this._input = inputDir; } + + /** + * Getter of the path of the output directory + * @return path + */ + public String getOutputDir(){ return this._output; } + + /** + * Setter of the path of the output directory + * @param outputDir path of output directory + */ + public void setOutputDir(String outputDir){ this._output = outputDir;} + + /** + * Getter of the gaussian blur strength + * @return double gaussian filter strength + */ + public double getGauss(){ return this._gauss; } + + /** + * Setter of the gaussian blur strength + * @param gauss new gaussian filter strength + */ + public void setGauss(double gauss){ this._gauss = gauss; } + + /** + * Getter of resolution of the bin + * @return bin size + */ + public int getResolution(){ return this._resolution;} + + /** + * Setter of resolution of the bin + * @param resolution bin size + */ + public void setResolution(int resolution){ this._resolution = resolution;} + + /** + * Setter of size of the matrix + * @param size image size + */ + public void setMatrixSize(int size){ this._matrixSize = size; } + + /** + * Getter of threshold for the loop detection + * @return threshold + */ + public double getThresholdMaxima(){ return _thresholdMaxima;} + /** + * Setter of threshold for the detection of the maxima + * @param thresholdMaxima threshold + */ + public void setThresholdMaxima(double thresholdMaxima) { this._thresholdMaxima = thresholdMaxima;} + + /** + * Getter of getNbZero + * @return int nb of zero allowed around the java.plop.loops + */ + public int getNbZero(){ return this._nbZero;} + + /** + * setter of nb of zero + * @param nbZero int nb of zero allowed around the java.plop.loops + */ + public void setNbZero(int nbZero){ this._nbZero = nbZero;} + + /** + * getter boolean isProcessed + * true input is SIP processed dat + * @return boolean + */ + public boolean isProcessed() { return _isProcessed;} + + /** + * setter boolean isProcessed + * @param isProcessed boolean + */ + public void setIsProcessed(boolean isProcessed) { this._isProcessed = isProcessed;} + + /** + * getter isCooler + * true: input is mcool dataset + * @return boolean + */ + public boolean isCooler() { return _isCooler;} + + /** + * setter isCooler + * @param cool boolean + */ + public void setIsCooler(boolean cool) { this._isCooler = cool;} + + /** + * getter isGui + * true: program run with GUI + * @return boolean + */ + public boolean isGui() { return _isGui;} + + /** + * setter isGui + * @param _isGui boolean + */ + + public void setIsGui(boolean _isGui) { this._isGui = _isGui;} + + + + + /** + * getter of chrSize hashMap + * @return hashMap chr name => chr size + */ + public HashMap getChrSizeHashMap(){return this._chrSizeHashMap;} + + /** + * getter of chrSize hashMap + * @return hashMap chr name => chr size + */ + public ArrayList getChrList(){return this._listChr;} + + + /** + * getter of chrSize hashMap + * @return hashMap chr name => chr size + */ + public void setChrSizeHashMap(HashMap chrSize){this._chrSizeHashMap = chrSize;} + + /** + * Initialize chrSize hashMap + * + * @param chrSizeFile path to the chrFile + */ + public void setChrSize(String chrSizeFile) { + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(chrSizeFile)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null){ + sb.append(line); + String[] parts = line.split("\\t"); + String chr = parts[0]; + int size = Integer.parseInt(parts[1]); + _listChr.add(chr); + _chrSizeHashMap.put(chr, size); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * + * @param keepTif + */ + public void setDelImage(boolean keepTif) { + this._delImage = keepTif; + } + public boolean isDelImage() { return _delImage; } +} diff --git a/src/main/java/plop/sipMain/Hic_main.java b/src/main/java/plop/sipMain/Hic_main.java new file mode 100644 index 0000000..8723fc6 --- /dev/null +++ b/src/main/java/plop/sipMain/Hic_main.java @@ -0,0 +1,133 @@ +package plop.sipMain; +import java.io.IOException; +import java.util.Arrays; + +import plop.cli.CLIHelper; +import plop.gui.GuiAnalysis; +import plop.process.HiC; +import plop.process.Cool; +import plop.process.Processed; + +/** + * + * command line eg: + * java -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... paramaters + * java -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar + * + * @author axel poulet + * + */ +public class Hic_main { + + + /** + * Main function to run all the java.plop.process, can be run with java.plop.gui or in command line. + * With command line with 1 or less than 5 parameter => run only the help + * With zero parameter only java -jar SIP.jar => java.plop.gui + * With more than 5 paramter => command line mode + * + * @param args table with parameters for command line + * @throws IOException exception + * @throws InterruptedException exception + */ + public static void main(String[] args) throws IOException, InterruptedException { + + + //command line java.plop.test: + // hic -i /home/plop/Desktop/SIP/GSE104333_Rao-2017-treated_6hr_combined_30.hic -o /home/plop/Desktop/java.plop.test -j /home/plop/Tools/juicer_tools_1.19.02.jar -c /home/plop/Desktop/SIP/testSize.tab -lt intra + /*CLI */ + if(args.length == 1) { + CLIHelper.getHelperAllInfos(); + }else if(args.length > 1) { + String [] argsSubset = Arrays.copyOfRange(args, 1, args.length); + if (args[0].equals("hic")) { + if(args[1].equals("-h") || args[1].equals("--help")) { + CLIHelper.CmdHelpHiC(); + }else if(args.length > 2){ + HiC hic = new HiC(argsSubset); + hic.run(); + }else{ + CLIHelper.CmdHelpHiC(); + } + + }else if (args[0].equals("processed")) { + if(args[1].equals("-h") || args[1].equals("--help")) { + CLIHelper.CmdHelpProcessed(); + }else if(args.length > 2){ + Processed processed = new Processed(argsSubset); + processed.run(); + }else{ + CLIHelper.CmdHelpProcessed(); + } + }else if (args[0].equals("cool")) { + if(args[1].equals("-h") || args[1].equals("--help")) { + CLIHelper.CmdHelpCool(); + }else if(args.length > 2){ + Cool cool = new Cool(argsSubset); + cool.run(); + }else{ + CLIHelper.CmdHelpCool(); + } + }else + CLIHelper.getHelperAllInfos(); + } + /*GUI */ + else{ + GuiAnalysis gui = new GuiAnalysis(); + while( gui.isShowing()){ + try {Thread.sleep(1);} + catch (InterruptedException e) {e.printStackTrace();} + } + if (gui.isStart()){ + if(gui.isHic()) { + HiC hic = new HiC(gui); + hic.run(); + }else if(gui.isCool()){ + Cool cool = new Cool(args); + cool.run(); + + }else if(gui.isProcessed()){ + Processed processed = new Processed(gui); + processed.run(); + } + }else { + System.out.println("\nSIP closed: "); + CLIHelper.getHelperAllInfos(); + } + } + +/* + + SIPIntra java.plop.sip; + if(_isHic){ + java.plop.sip = new SIPIntra(_output, _chrSizeFile, _gauss, _min, _max, _resolution, _saturatedPixel, + _thresholdMax, _diagSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); + java.plop.sip.setIsGui(_gui); + ProcessDumpHic processDumpData = new ProcessDumpHic(); + processDumpData.go(_input, java.plop.sip, _juiceBoxTools, _juiceBoXNormalisation, _cpu); + System.out.println("########### End of the dump Step"); + }else if(_isCool){ + java.plop.sip = new SIPIntra(_output, _chrSizeFile, _gauss, _min, _max, _resolution, _saturatedPixel, _thresholdMax, _diagSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); + java.plop.sip.setIsCooler(_isCool); + + ProcessDumpCooler processDumpData = new ProcessDumpCooler(); + processDumpData.go(_cooltools, _cooler, java.plop.sip, _input, _cpu); + + }else{ + + java.plop.sip = new SIPIntra(_input,_output, _chrSizeFile, _gauss, _min, _max, _resolution, _saturatedPixel, _thresholdMax, + _diagSize, _matrixSize, _nbZero,_factor,_fdr); + java.plop.sip.setIsDroso(_isDroso); + java.plop.sip.setIsProcessed(_isProcessed); + java.plop.sip.setIsGui(_gui); + } + System.out.println("Start loop detction step"); + MultiResProcess multi = new MultiResProcess(java.plop.sip, _cpu, _delImages,_chrSizeFile); + multi.run(); + System.out.println("###########End loop detction step"); + + */ + } + + +} diff --git a/src/test/TestCallLoopsHicFile.java b/src/main/java/plop/test/TestCallLoopsHicFile.java similarity index 74% rename from src/test/TestCallLoopsHicFile.java rename to src/main/java/plop/test/TestCallLoopsHicFile.java index 93f5920..e906fa2 100644 --- a/src/test/TestCallLoopsHicFile.java +++ b/src/main/java/plop/test/TestCallLoopsHicFile.java @@ -1,21 +1,19 @@ -package test; +package plop.test; + + import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; - -import multiProcesing.ProcessHicDumpData; -import process.MultiResProcess; -import utils.SIPObject; +import plop.multiProcessing.ProcessDumpHic; +import plop.utils.MultiResProcess; +import plop.sip.SIPIntra; /** - * Test loops calling on Hic file + * Test java.plop.loops calling on Hic file * * @author Axel Poulet * @@ -42,7 +40,6 @@ public static void main(String[] args) throws IOException, InterruptedException //readChrSizeFile("/home/plop/Documents/Genome/HumanGenomeHg19/hg19_withoutChr.sizes"); //chrsize = readChrSizeFile("/home/plop/Documents/Genome/mammals/HumanGenomeHg19/chr1.size"); String fileChr = "/home/plop/Desktop/SIP/Erics/hg19_chromSizes.txt"; - HashMap chrsize = readChrSizeFile(fileChr); String juiceBoxTools = "/home/plop/Tools/juicer_tools_1.19.02.jar"; int matrixSize = 2000; int resolution = 10000; @@ -55,8 +52,8 @@ public static void main(String[] args) throws IOException, InterruptedException String juiceBoXNormalisation = "KR"; double saturatedPixel = 0.01; - ArrayList factor = new ArrayList(); - factor.add(1); + + int factor = 1; //factor.add(2); //factor.add(5); boolean keepTif = true; @@ -76,14 +73,14 @@ public static void main(String[] args) throws IOException, InterruptedException + "threshold "+thresholdMax+"\n"); File file = new File(output); - if (file.exists()==false){file.mkdir();} + if (!file.exists()){file.mkdir();} - SIPObject sip = new SIPObject(output, chrsize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,keepTif,false); + SIPIntra sip = new SIPIntra(output, fileChr, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,false, keepTif,cpu ); sip.setIsGui(false); - ProcessHicDumpData processDumpData = new ProcessHicDumpData(); - processDumpData.go(input, sip, chrsize, juiceBoxTools, juiceBoXNormalisation,cpu); + ProcessDumpHic processDumpData = new ProcessDumpHic(); + processDumpData.go(input, sip, juiceBoxTools, juiceBoXNormalisation); - MultiResProcess multi = new MultiResProcess(sip, cpu, keepTif,fileChr); + MultiResProcess multi = new MultiResProcess(sip, fileChr); multi.run(); //String cooler = "/home/plop/anaconda3/bin/cooler"; //String cooltools = "/home/plop/anaconda3/bin/cooltools"; @@ -92,29 +89,7 @@ public static void main(String[] args) throws IOException, InterruptedException //System.out.println("End "+testTools(cooltools,0,3,0)); } - /** - * - * @param chrSizeFile - * @throws IOException - */ - @SuppressWarnings("unused") - private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ - HashMap chrSize = new HashMap(); - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - int size = Integer.parseInt(parts[1]); - chrSize.put(chr, size); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - return chrSize; - } + public static boolean testTools(String pathTools, int first, int second, int third) { Runtime runtime = Runtime.getRuntime(); diff --git a/src/main/java/plop/test/TestCallLoopsProcessedFile.java b/src/main/java/plop/test/TestCallLoopsProcessedFile.java new file mode 100644 index 0000000..421065e --- /dev/null +++ b/src/main/java/plop/test/TestCallLoopsProcessedFile.java @@ -0,0 +1,68 @@ +package main.java.plop.test; + +import java.io.IOException; + +import plop.utils.MultiResProcess; +import plop.sip.SIPIntra; + +/** + * Test of calling java.plop.loops on processed files + * + * @author Axel Poulet + * + */ +public class TestCallLoopsProcessedFile { + + /** + * + * @param args + * @throws IOException + * @throws InterruptedException + */ + public static void main(String[] args) throws IOException, InterruptedException { + String input = "/home/plop/Desktop/Cool"; + String output= "/home/plop/Desktop/Bis"; + int matrixSize = 500; + int resolution = 25000; + int diagSize = 2; + double gauss = 1.5; + int thresholdMax = 2800;// 2800;//1800 + int nbZero = 8;//6; + double min = 2;//1.5; + double max = 2;//1.5; + double saturatedPixel = 0.01;//0.005; + //boolean keepTif = false; + + int factor = 1; + //factor.add(2); + //factor.add(5); + //SIP_HiC_v1.3.6.jar hic SIP/Kc_allcombined.hic SIP/armsizes.txt SIP/Droso/ ../Tools/juicer_tools_1.13.02.jar + String chrSizeFile = "/home/plop/Desktop/SIP/hg38_small.size"; + SIPIntra sip = new SIPIntra(input,output, chrSizeFile, gauss, min, max, resolution, saturatedPixel, + thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,false,false,2); + sip.setIsGui(false); + sip.setIsProcessed(true); + int cpu = 2; + System.out.println("Processed Data\n"); + System.out.println("input "+input+"\n" + + "output "+output+"\n" + + "gauss "+gauss+"\n" + + "min "+min+"\n" + + "max "+max+"\n" + + "matrix size "+matrixSize+"\n" + + "diag size "+diagSize+"\n" + + "resolution "+resolution+"\n" + + "saturated pixel "+saturatedPixel+"\n" + + "threshold "+thresholdMax+"\n" + + "isProcessed "+sip.isProcessed()+"\n"); + System.out.println("ahhhhhhhhhhhhh\n"); + MultiResProcess multi = new MultiResProcess(sip, chrSizeFile); + multi.run(); + //ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); + //processDetectloops.go(java.plop.sip, 2,false); + //Testpb plop = new Testpb(java.plop.sip, true); + //plop.run(2); + System.out.println("End"); + } + +} diff --git a/src/main/java/plop/test/TestCoolFormat.java b/src/main/java/plop/test/TestCoolFormat.java new file mode 100644 index 0000000..dede103 --- /dev/null +++ b/src/main/java/plop/test/TestCoolFormat.java @@ -0,0 +1,71 @@ +package plop.test; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import plop.multiProcessing.ProcessDetectLoops; +import plop.multiProcessing.ProcessDumpCooler; +import plop.sip.SIPInter; + +@SuppressWarnings("unused") +public class TestCoolFormat { + + public static void main(String[] args) throws IOException, InterruptedException { + String chr = "chr21"; + //String input = "/home/plop/Desktop/SIP/testCooler/GM12878_4DNFIXP4QG5B.mcool"; + String input = "/home/plop/Desktop/SIP/hicData/4DNFIFLDVASC.mcool"; + String output = "/home/plop/Desktop/CoolTest"; + //String expectedFile = "/home/plop/Desktop/chr21Cooler/expected.txt"; + String chrSizeFile = "/home/plop/Desktop/SIP/hg38.sizes"; + String cooler = "/home/plop/anaconda3/bin/cooler"; + String cooltools = "/home/plop/anaconda3/bin/cooltools"; + + int resolution = 100000; + int matrixSize = 500; + //CoolerExpected expected = new CoolerExpected(input, resolution, matrixSize); + //expected.dumpExpected(expectedFile); + //CoolerExpected expected = new CoolerExpected(expectedFile, matrixSize); + //expected.parseExpectedFile(); + //ArrayList plop = expected.getExpected(chr); + //CoolerDumpIntra cooler = new CoolerDumpIntra(input, resolution, plop); + //run(resolution,matrixSize,matrixSize/2,chr,output, cooler, 46709983); + + int diagSize = 3; + double gauss = 1; + double min = 2; + double max = 2; + int nbZero = 6; + double thresholdMax = 10; + double saturatedPixel = 0.01; + int factor = 1; + double fdr =0.025; + boolean keepTif = true; + int cpu = 1; + + //SIPIntra java.plop.sip = new SIPIntra(output, chrSizeFile, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.03,false,keepTif,cpu); + SIPInter sip = new SIPInter(output, chrSizeFile, gauss, resolution, thresholdMax, matrixSize, nbZero, fdr , true,2); + sip.setIsGui(false); + sip.setIsCooler(true); + sip.setIsProcessed(false); + + + ProcessDumpCooler processDumpData = new ProcessDumpCooler(); + processDumpData.go(cooler, sip, input); + System.out.println("########### End of the dump step\n"); + System.out.println("########### Start loop detection\n"); + String loopFileRes = sip.getOutputDir()+"finalLoops.txt"; + BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(loopFileRes))); + ProcessDetectLoops detectLoops = new ProcessDetectLoops(); + + System.out.println("########### Starting loop detection"); + detectLoops.go(sip, loopFileRes); + System.out.println("########### !!!!!!! end java.plop.loops detection"); + + System.out.println("end"); + + } + + +} diff --git a/src/test/TestGui.java b/src/main/java/plop/test/TestGui.java similarity index 50% rename from src/test/TestGui.java rename to src/main/java/plop/test/TestGui.java index 5e769f4..7ccd0ee 100644 --- a/src/test/TestGui.java +++ b/src/main/java/plop/test/TestGui.java @@ -1,18 +1,14 @@ -package test; +package plop.test; -import java.io.BufferedReader; -import java.io.FileReader; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import gui.GuiAnalysis; -import multiProcesing.ProcessHicDumpData; -import utils.SIPObject; +import plop.gui.GuiAnalysis; +import plop.multiProcessing.ProcessDumpHic; +import plop.sip.SIPIntra; /** - * test of the GUI + * java.plop.test of the GUI * * @author Axel Poulet * @@ -25,81 +21,60 @@ public class TestGui { * @throws InterruptedException */ public static void main(String[] args) throws IOException, InterruptedException{ - SIPObject sip ; + SIPIntra sip ; GuiAnalysis gui = new GuiAnalysis(); while( gui.isShowing()){ try {Thread.sleep(1);} catch (InterruptedException e) {e.printStackTrace();} } if (gui.isStart()){ - System.out.println("test"); + System.out.println("java/plop/test"); String output = gui.getOutputDir(); - String input = gui.getRawDataDir(); + String input = gui.getInput(); int matrixSize = gui.getMatrixSize(); int diagSize = gui.getDiagSize(); int resolution = gui.getResolution(); double gauss = gui.getGaussian(); double max = gui.getMax(); double min = gui.getMin(); - double saturatedPixel = gui.getEnhanceSignal(); - int thresholdMax = gui.getNoiseTolerance(); + double saturatedPixel = gui.getSaturatedPixel(); + int thresholdMax = gui.getThresholdMaxima(); boolean isHic = gui.isHic(); boolean isProcessed = gui.isProcessed(); - String juiceBoxTools = gui.getJuiceBox(); + String juiceBoxTools = gui.getJuicerTool(); String juiceBoXNormalisation = "KR"; if(gui.isNONE()) juiceBoXNormalisation = "NONE"; else if (gui.isVC()) juiceBoXNormalisation = "VC"; else if (gui.isVC_SQRT()) juiceBoXNormalisation = "VC_SQRT"; int nbZero = gui.getNbZero(); - - ArrayList factor = new ArrayList(); - factor.add(1); + + int factor = 1; //factor.add(2); - HashMap chrSize = readChrSizeFile(gui.getChrSizeFile()); + String chrSize = gui.getChrSizeFile(); if(gui.isProcessed()==false){ System.out.println("hic mode:\ninput: "+input+"\noutput: "+output+"\njuiceBox: "+juiceBoxTools+"\nnorm: "+ juiceBoXNormalisation+"\ngauss: "+gauss+"\n" + "min: "+min+"\nmax: "+max+"\nmatrix size: "+matrixSize+"\ndiag size: "+diagSize+"\nresolution: "+resolution+"\nsaturated pixel: "+saturatedPixel +"\nthreshold: "+thresholdMax+"\n number of zero:"+nbZero+"\n "); - sip = new SIPObject(output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,gui.isProcessed(),false); + sip = new SIPIntra(output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,false,true,2); sip.setIsGui(true); - ProcessHicDumpData processDumpData = new ProcessHicDumpData(); - processDumpData.go(input, sip, chrSize, juiceBoxTools, juiceBoXNormalisation,gui.getNbCpu()); + ProcessDumpHic processDumpData = new ProcessDumpHic(); + processDumpData.go(input, sip, juiceBoxTools, juiceBoXNormalisation); }else{ System.out.println("processed mode:\ninput: "+input+"\noutput: "+output+"\njuiceBox: "+juiceBoxTools+"\nnorm: "+ juiceBoXNormalisation+"\ngauss: "+gauss +"\nmin: "+min+"\nmax: "+max+"\nmatrix size: "+matrixSize+"\ndiag size: "+diagSize+"\nresolution: "+resolution+"\nsaturated pixel: "+saturatedPixel +"\nthreshold: "+thresholdMax+"\nisHic: "+isHic+"\nisProcessed: "+isProcessed+"\n number of zero:" +nbZero+"\n"); - sip = new SIPObject(input,output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,gui.isProcessed(),false); + sip = new SIPIntra(input,output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, + diagSize, matrixSize, nbZero,factor,0.01,false, true ,2); + + sip.setIsProcessed(gui.isProcessed()); sip.setIsGui(true); } //ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); - //processDetectloops.go(sip, gui.getNbCpu(),gui.isDeletTif()); + //processDetectloops.go(java.plop.sip, java.plop.gui.getNbCpu(),java.plop.gui.isDeletTif()); } } - - /** - * Run the input file and stock the info of name chr and their size in hashmap - * @param chrSizeFile path chr size file - * @throws IOException if file does't exist - */ - private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ - HashMap m_chrSize = new HashMap(); - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - int size = Integer.parseInt(parts[1]); - m_chrSize.put(chr, size); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - return m_chrSize; - } } \ No newline at end of file diff --git a/src/main/java/plop/test/TestInter.java b/src/main/java/plop/test/TestInter.java new file mode 100644 index 0000000..fed1329 --- /dev/null +++ b/src/main/java/plop/test/TestInter.java @@ -0,0 +1,48 @@ +package plop.test; + + +import plop.multiProcessing.ProcessDetectLoops; +import plop.sip.SIPInter; + +import java.io.IOException; +import java.util.ArrayList; + +public class TestInter { + + static ArrayList _chr= new ArrayList(); + + public static void main(String[] args) throws IOException, InterruptedException { + //String chr = "chr21"; + // hic -i SIP/GSE104333_Rao-2017-treated_6hr_combined_30.hic -c SIP/testSize.tab -o /home/plop/Desktop/interTreatedP -j /home/plop/Tools/juicer_tools_1.19.02.jar -lt inter -cpu 2 -r 50000 -ms 500 + //processed -i /home/plop/Desktop/interTreatedP/ -c /home/plop/Desktop/SIP/testSize.tab -o /home/plop/Desktop/re -lt inter -cpu 2 -r 50000 -ms 500 -t 0.001 --nbZero 6 -k -fdr 1 -g 1 + //String input = "/home/plop/Desktop/testInter/"; + String input = "/home/plop/Desktop/SIP/hicData/4DNFILIM6FDL.hic"; + String output = "/home/plop/Desktop/testInter/"; + String fileChr = "/home/plop/Desktop/SIP/hg38_small.size"; + String juicerTools = "/home/plop/Tools/juicer_tools_1.19.02.jar"; + int resolution = 100000; + int matrixSize = 500; + double gauss = 1; + + int nbZero = 3; + double thresholdMax = 0.6; + double fdr =0.025; + + boolean delTif = false; + int cpu = 2; + + SIPInter sipInter = new SIPInter(output, fileChr, gauss, resolution, thresholdMax, matrixSize, nbZero,fdr,delTif,cpu); + //ProcessDumpHic java.plop.process = new ProcessDumpHic(); + //java.plop.process.go(input,sipInter,juicerTools,"KR"); + System.out.println("dans Test out : "+sipInter.getOutputDir()); + System.out.println("dans Test in : "+sipInter.getInputDir()); + ProcessDetectLoops detectLoops = new ProcessDetectLoops(); + detectLoops.go(sipInter, "/home/plop/Desktop/testInter/loopsBis.txt"); + + + System.out.println("end"); + + } + + +} diff --git a/src/test/TestMergeLoops.java b/src/main/java/plop/test/TestMergeLoops.java similarity index 99% rename from src/test/TestMergeLoops.java rename to src/main/java/plop/test/TestMergeLoops.java index a60faf7..a40709d 100644 --- a/src/test/TestMergeLoops.java +++ b/src/main/java/plop/test/TestMergeLoops.java @@ -1,4 +1,4 @@ -package test; +package plop.test; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -13,7 +13,7 @@ import java.util.Set; import java.util.stream.Collectors; -import utils.Loop; +import plop.loops.Loop; public class TestMergeLoops { diff --git a/src/utils/CoordinatesCorrection.java b/src/main/java/plop/utils/CoordinatesCorrection.java similarity index 57% rename from src/utils/CoordinatesCorrection.java rename to src/main/java/plop/utils/CoordinatesCorrection.java index 01ac5de..29b583a 100644 --- a/src/utils/CoordinatesCorrection.java +++ b/src/main/java/plop/utils/CoordinatesCorrection.java @@ -1,4 +1,6 @@ -package utils; +package plop.utils; + +import plop.loops.Loop; import java.util.HashMap; import java.util.Iterator; @@ -8,15 +10,15 @@ * Class to change the image coordinate in genome coordinate, with the name of the image, the resolution, the size of the image, * the step and the size of the diagonal. * - * Loops detected with white strips are removed. Furthermore the corner of the images are not take account. We test also the proximal loops to avoid overlaping loops. + * Loops detected with white strips are removed. Furthermore the corner of the images are not take account. We java.plop.test also the proximal java.plop.loops to avoid overlaping java.plop.loops. * * @author axel poulet * */ public class CoordinatesCorrection { - /** HashMap of the loops with new coordinates*/ - private HashMap _data = new HashMap(); + /** HashMap of the java.plop.loops with new coordinates*/ + private HashMap _data = new HashMap(); /** * @@ -26,7 +28,7 @@ public CoordinatesCorrection(){ } /** * change loop image coordinates in loop genomes coordinates, * - * @param temp: HashMap of loops with the image coordinates + * @param temp: HashMap of java.plop.loops with the image coordinates * @param index: index of the image * @return HashMap: key is a string with the name of the chr start end. And value is Loop class, to stock * the loop characteristics. @@ -51,7 +53,7 @@ public HashMap imageToGenomeCoordinate(HashMap temp, i String newName = loop.getChr()+"\t"+a+"\t"+b; if(a!=b && Math.abs(a-b) > diagSize){ if (x > 1 && y > 1 && y < imageSize-2 && x < imageSize-2){ - if(this._data.containsKey(newName) == false){ + if(!this._data.containsKey(newName)){ loop.setCoordinates(a, a_end, b, b_end); loop.setName(newName); //System.out.println(newName+" "+resolution+" "+step+" "+index+" "+x); @@ -70,15 +72,47 @@ public HashMap imageToGenomeCoordinate(HashMap temp, i return this._data; } + /** + * For loop inter chromosomal + * @param temp hashMap name loop > loop object + * @param rawImageName raw image name + * @return HashMAp with new coordinate + */ + public HashMap imageToGenomeCoordinate(HashMap temp, String rawImageName) { + //4_0_49999999_6_0_49999999.tif + String[] chrCoord = rawImageName.split("_"); + int chr1Start = Integer.parseInt(chrCoord[1]); + int chr2Start = Integer.parseInt(chrCoord[4]); + int x; + int y; + Set key = temp.keySet(); + Iterator it = key.iterator(); + while (it.hasNext()) { + Loop loop = temp.get(it.next()); + x = loop.getX(); + y = loop.getY(); + int resolution = loop.getResolution(); + int a = (x * resolution) + chr1Start; + int a_end = a + resolution; + int b = (y * resolution) + chr2Start; + ; + int b_end = b + resolution; + String newName = loop.getChr() + "\t" + loop.getChr2() + a + "\t" + b; + loop.setCoordinates(a, a_end, b, b_end); + loop.setName(newName); + _data.put(newName, loop); + } + return _data; + } /** * getter of m_data - * @return HashMap of loops + * @return HashMap of java.plop.loops */ public HashMap getData(){ return this._data;} /** * setter of m_data - * @param data + * @param data setter java.plop.loops hashMAp */ public void setData(HashMap data){ this._data = data;} } \ No newline at end of file diff --git a/src/utils/DecayAnalysis.java b/src/main/java/plop/utils/DecayAnalysis.java similarity index 93% rename from src/utils/DecayAnalysis.java rename to src/main/java/plop/utils/DecayAnalysis.java index 7ff7f32..3300580 100644 --- a/src/utils/DecayAnalysis.java +++ b/src/main/java/plop/utils/DecayAnalysis.java @@ -1,4 +1,4 @@ -package utils; +package plop.utils; import ij.ImagePlus; import ij.process.ImageProcessor; @@ -63,8 +63,11 @@ private float computeDiff (int c ){ for(int j = this._y-c ; j <= this._y+c; ++j){ if((i != this._x || j != this._y) && (i-this._x == -c || j-this._y == -c || i-this._x == c || j-this._y == c)){ if(i >=0 && j>= 0 && i < ip.getWidth() && j < ip.getHeight()){ - double a = ip.getf(this._x, this._y)- ip.getf(i, j); - sum+= a; + double valueA = 0; + if(!Double.isNaN(ip.getf(i, j))){ + valueA = ip.getf(i, j); + } + sum+= ip.getf(this._x, this._y)- valueA; ++nb; } } diff --git a/src/main/java/plop/utils/FDR.java b/src/main/java/plop/utils/FDR.java new file mode 100644 index 0000000..58c8cf7 --- /dev/null +++ b/src/main/java/plop/utils/FDR.java @@ -0,0 +1,94 @@ +package plop.utils; + +import plop.loops.Loop; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * + * Compute the cut off for AP and Regional AP score for java.plop.loops gave in input + * + * @author axel poulet and m. jordan rowley + * + */ +public class FDR { + /** double regional fdr cutoff */ + private double _RFDRCutoff = 10000; + /** double fdr cutoff */ + private double _FDRCutoff = 10000; + /** fdr value*/ + private double _fdr; + /** hashmap of loop loopName=> Loop object*/ + private HashMap _data; + + /** + * Constructor + * @param fdr fdr value use to compute the two cutoff + * @param data java.plop.loops data + */ + public FDR(double fdr,HashMap data){ + this._fdr = fdr; + this._data = data; + } + + /** + * + */ + public void run(){ + Set key = _data.keySet(); + Iterator it = key.iterator(); + List myFDRValues = new ArrayList(); + List myRFDRValues = new ArrayList(); + + while (it.hasNext()) { + String loopName = it.next(); + Loop loop = _data.get(loopName); + + float dubFDR = loop.getPaScoreAvgFDR(); + float dubFDR2 = loop.getPaScoreAvgFDR2(); + float dubFDR3 = loop.getPaScoreAvgFDR3(); + + + if(dubFDR > 0) myFDRValues.add(dubFDR); + if(dubFDR2 > 0) myFDRValues.add(dubFDR2); + if(dubFDR3 > 0) myFDRValues.add(dubFDR3); + + + float dubRFDR = loop.getRegionalPaScoreAvgFDR(); + float dubRFDR2 = loop.getRegionalPaScoreAvgFDR2(); + float dubRFDR3 = loop.getRegionalPaScoreAvgFDR3(); + + if(dubRFDR > 0) myRFDRValues.add(dubRFDR); + if(dubRFDR2 > 0) myRFDRValues.add(dubRFDR2); + if(dubRFDR3 > 0) myRFDRValues.add(dubRFDR3); + } + + Collections.sort(myFDRValues); + int topFDRs = (int)(myFDRValues.size()*_fdr); + if(topFDRs != 0){ + List topFDRList = new ArrayList(myFDRValues.subList(myFDRValues.size() -topFDRs, myFDRValues.size() -(topFDRs-1))); + this._FDRCutoff = topFDRList.get(0); + Collections.sort(myRFDRValues); + int topRFDRs = (int)(myRFDRValues.size()*_fdr); + List topRFDRList = new ArrayList(myRFDRValues.subList(myRFDRValues.size() -topRFDRs, myRFDRValues.size() -(topRFDRs-1))); + this._RFDRCutoff = topRFDRList.get(0); + } + } + + /** + * getter of regional fdr cutoff + * @return regional fdr cutoff + */ + public double getRFDRCutoff() { return _RFDRCutoff; } + + /** + * getter of regional fdr cutoff + * @return fdr cutoff + */ + public double getFDRCutoff() { return _FDRCutoff; } +} diff --git a/src/utils/FindMaxima.java b/src/main/java/plop/utils/FindMaxima.java similarity index 57% rename from src/utils/FindMaxima.java rename to src/main/java/plop/utils/FindMaxima.java index 277cfc1..a10f868 100644 --- a/src/utils/FindMaxima.java +++ b/src/main/java/plop/utils/FindMaxima.java @@ -1,13 +1,16 @@ -package utils; +package plop.utils; import java.util.ArrayList; import java.util.HashMap; +import ij.IJ; import ij.ImagePlus; import ij.io.FileSaver; +import ij.plugin.filter.GaussianBlur; import ij.plugin.filter.MaximumFinder; import ij.process.ByteProcessor; import ij.process.ImageProcessor; +import plop.loops.Loop; /** * Detection of regional maxima in image. Return the HashMap, the loop can be corrected. @@ -21,53 +24,83 @@ public class FindMaxima{ private ImagePlus _imgNorm; /** name of the chromosome*/ private String _chr; + /** name of the chromosome2*/ + private String _chr2; /** Image fileterred with min, max and gaussian filter*/ private ImagePlus _imgFilter; /** binary image pixel white = the maxima detected*/ private ImagePlus _imgResu = new ImagePlus(); /** threshold for the imageJ class MaximumFinder, this class is call to detecte the maxima */ - private double _noiseTolerance =-1; + private double _thresholdMaxima; /** diagonal size in bin*/ - private int _diagSize =-1; + private int _diagonalSize; /** Resolution of the image in base*/ - private int _resolution = -1; + private int _resolution; + /** gaussian Filter strength*/ + private double _gaussian; + /** gaussian Filter strength*/ + private int _nbZero; /** - * Constructor of FindMaxima + * Constructor of FindMaxima for intra chromosomal method + * * @param img ImagePlus raw image * @param imgFilter ImagePlus filtered image * @param chr String chromosome - * @param noiseTolerance double threshold to detect maxima - * @param diag int the size of the diagonal + * @param thresholdMaxima double threshold to detect maxima + * @param diagonalSize int the size of the diagonal * @param resolution int size of the pixel in base */ - public FindMaxima(ImagePlus img, ImagePlus imgFilter, String chr, double noiseTolerance, int diag, int resolution){ + public FindMaxima(ImagePlus img, ImagePlus imgFilter, String chr, double thresholdMaxima, int diagonalSize, int resolution){ this._imgNorm = img; this._imgFilter = imgFilter; - this._noiseTolerance = noiseTolerance; + this._thresholdMaxima = thresholdMaxima; this._chr = chr; - this._diagSize = diag; + this._diagonalSize = diagonalSize; this._resolution = resolution; } - - + /** - * Method to find loops in oMe image, and fill the loop collection. - * - * @param hichip - * @param index int index of the image - * @param nbZero int nb zero allowed around the loop + * Constructor of FindMaxima for inter chromosomal method + * @param imgDiff ImagePlus image diff + * @param chr1 chr1 name + * @param chr2 chr2 name + * @param thresholdMaxima double threshold to detect maxima + * @param resolution int size of the pixel in base + * @param gaussian gaussian filter strength + */ + public FindMaxima( ImagePlus imgDiff, String chr1,String chr2, double thresholdMaxima, int resolution, double gaussian, int nbZero){ + this._imgFilter = imgDiff; + this._thresholdMaxima = thresholdMaxima; + this._chr2 = chr2; + this._chr = chr1; + this._resolution = resolution; + this._gaussian = gaussian; + this._nbZero = nbZero; + } + + + /** + * findLoop for intra chromosomal interaction + * call ImageJ findMaxima method + * filter java.plop.loops with low value in oMe image and normalize image + * if the java.plop.loops didn't possess a decay => suppress + * Loop correction: => avoid overlapping java.plop.loops, correct also the coordinate if higher value pixel is in the java.plop.loops + * neighbor + * + * @param index image index + * @param nbZero nb zeor allowe around the loop * @param raw ImagePlus raw image - * @param val int background value of the image - * @param factor - * @return + * @param val value used as min in the image + * @return HashMap loop loop name => Loop object */ - public HashMap findloop(int index, int nbZero, ImagePlus raw, float val){ + + public HashMap findLoop(int index, int nbZero, ImagePlus raw, float val){ run(nbZero, raw, val); ArrayList temp = this.getMaxima(); ImageProcessor ipN = this._imgNorm.getProcessor(); - HashMap data = new HashMap(); + HashMap data = new HashMap(); //System.out.println("size raw maxima !!!!!!!!!!!!!! "+raw.getTitle()+" "+temp.size()); for(int j = 0; j < temp.size();++j){ String[] parts = temp.get(j).split("\\t"); @@ -79,14 +112,14 @@ public HashMap findloop(int index, int nbZero, ImagePlus raw, float if(avg > 1.45 && ipN.getf(x, y) >= 1.85){ // filter on the loop value and region value DecayAnalysis da = new DecayAnalysis(this._imgNorm,x,y); float n1 =da.getNeighbourhood1(); - float n2 =da.getNeighbourhood2(); + float n2 =da.getNeighbourhood2(); if(n1 < n2 && n1 >= 0.15 && n2 >= 0.25){ // filter on the neighborood for hic datatset Loop maxima = new Loop(temp.get(j),x,y,this._chr,avg,std,ipN.getf(x, y)); maxima.setNeigbhoord1(n1); maxima.setNeigbhoord2(n2); maxima.setResolution(this._resolution); //System.out.println(_resolution+" "+maxima.getResolution()); - maxima.setDiagSize(this._diagSize); + maxima.setDiagSize(this._diagonalSize); maxima.setMatrixSize(this._imgNorm.getWidth()); data.put(name, maxima); } @@ -95,25 +128,118 @@ public HashMap findloop(int index, int nbZero, ImagePlus raw, float //System.out.println("after filter ################# "+raw.getTitle()+" "+data.size()); return data; } - + + /** + * findLoop for inter chromosomal interaction + * call ImageJ findMaxima method + * filter java.plop.loops with more than the nb of zero allowed in its neighbor + * if the java.plop.loops didn't possess a decay => suppress + * Loop correction: correct also the coordinate if higher value pixel is in the java.plop.loops + * neighbor + * @param pathRaw path to the raw image + * @return HashMap loop loop name => Loop object + */ + public HashMap findLoopInter(String pathRaw){ + ImagePlus raw = IJ.openImage(pathRaw); + ImageProcessor ipFilter = _imgFilter.getProcessor(); + runInter(raw); + ArrayList temp = this.getMaxima(); + ImageProcessor ipRaw = raw.getProcessor(); + HashMap data = new HashMap<>(); + //System.out.println("size raw maxima !!!!!!!!!!!!!! "+raw.getTitle()+" "+temp.size()); + for(int j = 0; j < temp.size();++j){ + String[] parts = temp.get(j).split("\\t"); + int x = Integer.parseInt(parts[0]); + int y = Integer.parseInt(parts[1]); + String name= this._chr+"\t"+this._chr2+"\t"+temp.get(j); + float avg = average(x,y); + float std = standardDeviation(x,y,avg); + int nbOfZero = detectNbOfZero(x,y,1); + if(nbOfZero <= this._nbZero ){//&& nbOfZero > 0){ // filter on the loop value and region value + //System.out.print("loop "+nbOfZero+" ref "+_nbZero+" "+ipFilter.getf(x,y)+"\n"); + DecayAnalysis da = new DecayAnalysis(raw,x,y); + float n1 =da.getNeighbourhood1(); + float n2 =da.getNeighbourhood2(); + if(n2>n1 && n1 > 0 && n2 > 0){ // filter on the neighborood for hic datatset + Loop maxima = new Loop(temp.get(j),x,y,this._chr,this._chr2,avg,std,ipRaw.getf(x, y)); + maxima.setValueDiff(ipFilter.getf(x,y)); + maxima.setNeigbhoord1(n1); + maxima.setNeigbhoord2(n2); + maxima.setResolution(this._resolution); + maxima.setNbOfZero(nbOfZero); + maxima.setMatrixSize(raw.getWidth()); + data.put(name, maxima); + } + } + } + //System.out.println("after filter ################# "+raw.getTitle()+" "+data.size()); + return data; + } + /** * Detect maxima with the oMe or observed methods, call the different methods * to detect the maxima and correct them. - * @param nbZero nb zero allowed around the loops + * @param nbZero nb zero allowed around the java.plop.loops * @param rawImage ImagePlus raw image * @param backgroundValue background value of the image */ private void run(int nbZero, ImagePlus rawImage, float backgroundValue){ ImagePlus temp = this._imgFilter.duplicate(); ImageProcessor ip = temp.getProcessor(); - MaximumFinder mf = new MaximumFinder(); - ByteProcessor bp = mf.findMaxima(ip, this._noiseTolerance, MaximumFinder.SINGLE_POINTS, true); + MaximumFinder mf = new MaximumFinder(); + ByteProcessor bp = mf.findMaxima(ip, this._thresholdMaxima, MaximumFinder.SINGLE_POINTS, true); this._imgResu.setProcessor(bp); this.putLoopLowerTriangle(); this.removedCloseMaxima(); this.correctMaxima(); this.removeMaximaCloseToZero(nbZero,rawImage, backgroundValue); } + + + /** + * Detect maxima with the oMe or observed methods, call the different methods + * to detect the maxima and correct them. + * @param rawImage ImagePlus raw image + */ + private void runInter(ImagePlus rawImage){ + ImagePlus temp = this._imgFilter.duplicate(); + ImageProcessor ip = temp.getProcessor(); + GaussianBlur gb = new GaussianBlur(); + gb.blurGaussian(ip, this._gaussian); + MaximumFinder mf = new MaximumFinder(); + ByteProcessor bp = mf.findMaxima(ip, this._thresholdMaxima, MaximumFinder.SINGLE_POINTS, true); + this._imgResu.setProcessor(bp); + this._imgNorm = rawImage; + this.correctMaxima(); + } + + + /** + * + * @param x + * @param y + * @param val + * @return + */ + private int detectNbOfZero(int x, int y, float val){ + int w = this._imgNorm.getWidth(); + int h = this._imgNorm.getHeight(); + ImageProcessor ip = _imgNorm.getProcessor(); + int nbZero = -1; + if(x >= 3 && x <= w-3 && y >= 3 && y <= h-3) { + nbZero = 0; + for (int i = x - 2; i <= x + 2; ++i) { + for (int j = y - 2; j <= y + 2; ++j) { + if (ip.getf(i, j) <= val) { + nbZero++; + } else if (Double.isNaN(ip.getf(i, j))) { + nbZero++; + } + } + } + } + return nbZero; + } /** * Save the image @@ -125,6 +251,9 @@ public static void saveFile ( ImagePlus imagePlusInput, String pathFile){ fileSaver.saveAsTiff(pathFile); } + /** + * + */ private void putLoopLowerTriangle() { ImageProcessor ipMaxima = this._imgResu.getProcessor(); int w = ipMaxima.getWidth(); @@ -238,7 +367,9 @@ private float average(int x, int y){ for(int i = x-1; i <= x+1; ++i){ for(int j = y-1; j <= y+1; ++j){ if(i < ip.getWidth() && i>0 && j < ip.getWidth() && j > 0){ - sum +=ip.getf(i, j); + if( Double.isNaN(ip.getf(i, j))){ + sum +=0; + }else{ sum +=ip.getf(i, j);} ++nb; } } @@ -263,7 +394,9 @@ private float standardDeviation(int x, int y, double avg){ for(int i = x-1; i <= x+1; ++i){ for(int j = y-1; j <= y+1; ++j){ if(i < ip.getWidth() && i>0 && j < ip.getWidth() && j > 0){ - semc += (ip.getf(i, j)-avg)*(ip.getf(i, j)-avg); + if( Double.isNaN(ip.getf(i, j))){ + semc += (0-avg)*(0-avg); + }else{ semc += (ip.getf(i, j)-avg)*(ip.getf(i, j)-avg);} ++nb; } } @@ -275,10 +408,10 @@ private float standardDeviation(int x, int y, double avg){ /** * Removed maxima surrounded by several pixel with the 0 value. * The method search the pixel with value 0 in the 24 neighbourhood around the initial maxima. - * for the oMe method if the loops is suurounded by more than 6 0 the loops will be removed. For observed the thsreshold is smaller, 3. - * ig the loops is closed too the diagonal the test is less stringent 7 for oMe methods and 4 for observed method. + * for the oMe method if the java.plop.loops is suurounded by more than 6 0 the java.plop.loops will be removed. For observed the thsreshold is smaller, 3. + * ig the java.plop.loops is closed too the diagonal the java.plop.test is less stringent 7 for oMe methods and 4 for observed method. * - * @param nbZero nb zero allowed around the loops + * @param nbZero nb zero allowed around the java.plop.loops * @param rawImage ImagePlus raw image * @param val background value of the image */ @@ -291,7 +424,7 @@ private void removeMaximaCloseToZero(int nbZero,ImagePlus rawImage, float val){ for(int j= 2;j< h-2;++j){ if(ipResu.getPixel(i, j) > 0){ int thresh = nbZero; - if (j-i <= this._diagSize+2) + if (j-i <= this._diagonalSize +2) thresh = thresh+1; int nb = 0; for(int ii = i-2; ii <= i+2; ++ii){ @@ -309,10 +442,4 @@ private void removeMaximaCloseToZero(int nbZero,ImagePlus rawImage, float val){ } this._imgResu.setProcessor(ipResu); } - - /** - * Setter of the noise tolerance parameter - * @param n int the value of the new noiseTolerance - */ - public void setNoiseTolerance( int n){ this._noiseTolerance = n;} } diff --git a/src/utils/ImageProcessingMethod.java b/src/main/java/plop/utils/ImageProcessingMethod.java similarity index 77% rename from src/utils/ImageProcessingMethod.java rename to src/main/java/plop/utils/ImageProcessingMethod.java index b02388e..9d2953a 100644 --- a/src/utils/ImageProcessingMethod.java +++ b/src/main/java/plop/utils/ImageProcessingMethod.java @@ -1,4 +1,4 @@ -package utils; +package plop.utils; import ij.ImagePlus; import ij.plugin.ContrastEnhancer; @@ -7,7 +7,7 @@ import ij.process.ImageProcessor; /** - * Method of image pre-processing before call maxima, to enhance the loops and reduce the noise + * Method of image pre-processing before call maxima, to enhance the java.plop.loops and reduce the noise * This class is using the ImageJ methode for the different filters (min, max, gaussian). * * @author axel poulet @@ -73,30 +73,11 @@ public void enhanceContrast(double saturatedPixel){ public void runMin(double min){ this._rF.rank(this._ip, min, RankFilters.MIN); } - - - /** - * White "tophat" method to enhance the light structure - * - */ - public void topHat(){ - GaussianBlur gb = new GaussianBlur(); - gb.blurGaussian(this._ip, this._gaussianFilterRadius); - this._rF.rank(this._ip, this._minFilterRadius, RankFilters.MIN); - this._rF.rank(this._ip, this._maxFilterRadius, RankFilters.MAX); - this._rF.rank(this._ip, this._maxFilterRadius, RankFilters.MAX); - this._rF.rank(this._ip, this._minFilterRadius, RankFilters.MIN); - } - - /** - * Getter of the image filtered - * @return ImagePlus image filtered - */ - public ImagePlus getImg(){ return _img;} + /** * Setter of the raw image - * @param _img raw Image + * @param img raw Image */ public void setImg(ImagePlus img){ this._img = img;} @@ -112,9 +93,9 @@ public void runGaussian() { /** * - * @param m_min + * @param max max filter strength */ - public void runMax(double m_max) { - _rF.rank(_ip, m_max, RankFilters.MAX); + public void runMax(double max) { + _rF.rank(_ip, max, RankFilters.MAX); } } diff --git a/src/main/java/plop/utils/MultiResProcess.java b/src/main/java/plop/utils/MultiResProcess.java new file mode 100644 index 0000000..e1514e1 --- /dev/null +++ b/src/main/java/plop/utils/MultiResProcess.java @@ -0,0 +1,271 @@ +package plop.utils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + + +import plop.cli.CLIHelper; +import plop.multiProcessing.ProcessDetectLoops; +import plop.loops.Loop; +import plop.sip.SIPIntra; + +/** + * Class allowing the multi resolution loop calling + * + * @author axel poulet + * + */ +public class MultiResProcess { + + /** SIP object*/ + private SIPIntra _sip; + + + /** path to chr size file*/ + private String _chrFile; + + /** + * Constructor + * + * @param sip SIPIntra + * @param chrSizeFile path of chrSize file + */ + public MultiResProcess(SIPIntra sip, String chrSizeFile) { + this._sip = sip; + this._chrFile = chrSizeFile; + } + + /** + * + * for each resolution used run the same java.plop.process to otain the loop at the resolution of interest + * at each resolution the input parameters will be adapted to the resolution used + * @throws InterruptedException exception + * @throws IOException exception + * + */ + public void run() throws InterruptedException, IOException{ + ArrayList listFactor = this._sip.getListFactor(); + ArrayList listOfFile = new ArrayList(); + if (_sip.isProcessed()){ + if(!this.testDir()){ + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(_sip.getOutputDir()+"log.txt"), true)); + writer.write("!!!! It is missing one or several directories for factor parameter\nEnable to find all the directories needed for SIP (-factor option)\n\n"); + System.out.println("!!!! It is missing one or several directories for factor parameter\n"); + CLIHelper.CmdHelpProcessed(); + } + } + + for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { + int res = this._sip.getResolution()*listFactor.get(indexFact); + String resName = String.valueOf(res); + resName = resName.replace("000", "")+"kb"; + String resuFile = this._sip.getOutputDir()+File.separator+resName+"Loops.txt"; + listOfFile.add(resuFile); + File file = new File(resuFile); + if(file.exists()) + file.delete(); + if(indexFact == 0) { + //System.out.println("plopi"); + ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); + processDetectloops.go(this._sip, resuFile,resName); + }else { + SIPIntra sipTmp = setSIPIntraTmp(listFactor.get(indexFact)); + ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); + processDetectloops.go(sipTmp,resuFile,resName); + } + } + if(listOfFile.size() > 1) { + System.out.println("Merging File ... "); + this.mergedFile(listOfFile); + System.out.println("Merging File End !!!! "); + } + } + + + /** + * + * @param factor + * @return + */ + private SIPIntra setSIPIntraTmp(int factor){ + int res = this._sip.getResolution()*factor; + int matrixSizeTpm = this._sip.getMatrixSize()/factor; + double gaussTpm = this._sip.getGauss()/factor; + SIPIntra sipTmp = new SIPIntra(_sip.getOutputDir(), _sip.getChrSizeFile(), gaussTpm, + _sip.getMin(), _sip.getMax(), res, _sip.getSaturatedPixel(),_sip.getThresholdMaxima(), + _sip.getDiagonalSize(), matrixSizeTpm, _sip.getNbZero(), _sip.getFactor(), + _sip.getFdr(), _sip.isDroso(), _sip.isDelImage(), _sip.getCpu()); + + if(this._sip.isProcessed()) { + sipTmp = new SIPIntra(_sip.getInputDir(),_sip.getOutputDir(), _sip.getChrSizeFile(), gaussTpm, + _sip.getMin(), _sip.getMax(), res, _sip.getSaturatedPixel(),_sip.getThresholdMaxima(), + _sip.getDiagonalSize(), matrixSizeTpm, _sip.getNbZero(), _sip.getFactor(), + _sip.getFdr(), _sip.isDroso(), _sip.isDelImage(), _sip.getCpu()); + } + sipTmp.setIsGui(_sip.isGui()); + sipTmp.setStep(this._sip.getStep()/factor); + sipTmp.setIsProcessed(_sip.isProcessed()); + sipTmp.setIsCooler(_sip.isCooler()); + return sipTmp; + + } + + + /** + * java.plop.test the data organization + * @return boolean if yes the dir of interest is existing + */ + private boolean testDir(){ + String input = _sip.getInputDir(); + ArrayList listFactor = this._sip.getListFactor(); + for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact){ + int res = this._sip.getResolution()*listFactor.get(indexFact); + String resName = String.valueOf(res); + resName = resName.replace("000", "")+"kb"; + File inputDir = new File(input+resName); + if(!inputDir.exists()) { + return false; + } + } + return true; + } + + /** + * merge java.plop.loops from different resolution + * java.plop.test if java.plop.loops are present at different resolution if yes keep this one at smaller resolution + * + * @param listOfFile list of of llops file + * @throws IOException exception + */ + private void mergedFile(ArrayList listOfFile) throws IOException{ + HashMap chrSize = readChrIndex(this._chrFile); + Set key = chrSize.keySet(); + ArrayList > arrayListLoop = new ArrayList >(); + for (int i = 0; i < key.size();++i) { + HashMap loopHashMap = new HashMap(); + arrayListLoop.add(loopHashMap); + } + + BufferedReader br = new BufferedReader(new FileReader(listOfFile.get(0))); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + String title = line; + sb.append(System.lineSeparator()); + line = br.readLine(); + while (line != null){ + sb.append(line); + Loop loop = new Loop(line); + String chr = loop.getChr(); + int index = chrSize.get(chr); + HashMap loopHashMap = arrayListLoop.get(index); + loopHashMap.put(line, loop); + arrayListLoop.set(index, loopHashMap); + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + + for (int i = 1; i < listOfFile.size();++i) { + br = new BufferedReader(new FileReader((listOfFile.get(i)))); + sb = new StringBuilder(); + line = br.readLine(); + sb.append(System.lineSeparator()); + line = br.readLine(); + while (line != null){ + Loop loop = new Loop(line); + String chr = loop.getChr(); + int index = chrSize.get(chr); + HashMap loopHashMap = arrayListLoop.get(index); + if(compareLoop(loopHashMap,loop)){ + loopHashMap.put(line,loop); + arrayListLoop.set(index, loopHashMap); + } + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + } + + BufferedWriter writer; + writer = new BufferedWriter(new FileWriter(new File(_sip.getOutputDir()+"finalLoops.txt"))); + writer.write(title+"\n"); + for (int i = 0; i < arrayListLoop.size();++i){ + HashMap loopHashMap = arrayListLoop.get(i); + Set keyBis = loopHashMap.keySet(); + List output = keyBis.stream().collect(Collectors.toList()); + for (int j = 0; j < output.size();++j){ + writer.write(output.get(j)+"\n"); + } + } + writer.close(); + } + + + /** + * java.plop.test if the loop is existing at other resolution, if yes keep it if it is the smaller reolution + * + * @param loopHashMap hashmap loop name => Loop object + * @param loopOfInterest Loop to java.plop.test + * @return boolean true or false + */ + private boolean compareLoop(HashMap loopHashMap, Loop loopOfInterest) { + Set key = loopHashMap.keySet(); + Iterator it = key.iterator(); + while (it.hasNext()){ + String loopName = it.next(); + Loop loop = loopHashMap.get(loopName); + int xEnd = loop.getCoordinates().get(1); + int yEnd = loop.getCoordinates().get(3); + int xtest = loopOfInterest.getCoordinates().get(0); + int xtestEnd = loopOfInterest.getCoordinates().get(1); + int res = xtestEnd-xtest; + int ytest = loopOfInterest.getCoordinates().get(2); + int ytestEnd = loopOfInterest.getCoordinates().get(3); + xtest = xtest-res*2; + xtestEnd = xtestEnd+res*2; + ytest = ytest-res*2; + ytestEnd = ytestEnd+res*2; + //System.out.println(x+"\t"+xEnd+"\t"+ xtestEnd); + if((xtest <= xEnd && xtestEnd >= xEnd) && (ytest <= yEnd && ytestEnd >= yEnd)) + return false; + } + return true; + } + + + /** + * Read chr index file and return HashMap of chr name and size + * @param chrSizeFile path to the chr size file + * @return hashMap chrName => chrSize + * @throws IOException exception + */ + private HashMap readChrIndex( String chrSizeFile) throws IOException{ + HashMap chrSize = new HashMap(); + BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + int i = 0; + while (line != null){ + sb.append(line); + String[] parts = line.split("\\t"); + String chr = parts[0]; + chrSize.put(chr, i); + sb.append(System.lineSeparator()); + line = br.readLine(); + ++i; + } + br.close(); + return chrSize; + } + +} diff --git a/src/main/java/plop/utils/PeakAnalysisScore.java b/src/main/java/plop/utils/PeakAnalysisScore.java new file mode 100644 index 0000000..093b797 --- /dev/null +++ b/src/main/java/plop/utils/PeakAnalysisScore.java @@ -0,0 +1,158 @@ +package plop.utils; + +import java.util.HashMap; +import java.lang.Math; +import java.util.Iterator; +import java.util.Set; +import ij.ImagePlus; +import ij.process.ImageProcessor; +import plop.loops.Loop; + +/** + * Peak analysis score. + * peaks analysis score is adapted from the APA score from Rao&Huntley et al., 2014: + * @author axel poulet + * + */ +public class PeakAnalysisScore { + /** Raw image of the matrix*/ + private ImagePlus _imgRaw = new ImagePlus(); + /** HashMap of object java.plop.loops*/ + private HashMap _data = new HashMap(); + /** ImageProcessor of the raw ImagePlus*/ + private ImageProcessor _ipRaw; + + /** + * Constructor of PeakAnalysisScore + * @param imgRaw ImagePlus raw image + * @param data HashMap of java.plop.loops + */ + public PeakAnalysisScore(ImagePlus imgRaw, HashMap data){ + this._imgRaw = imgRaw; + this._data = data; + this._ipRaw = _imgRaw.getProcessor(); + } + + + /** + * Method to compute the score of each loop. on a 11*11 square, the average of the corner (3*3) are computed. then the ration between the java.plop.loops value and this avg is computed. + * For the regional value, the avg of the n_8 value of the java.plop.loops are done, then a ratio is computed with the avg value of the corner, + * This method is used for the observed and oMe method. + * + */ + public void computeScore(){ + Set key = this._data.keySet(); + Iterator it = key.iterator(); + while (it.hasNext()){ + String cle = it.next(); + Loop loop = this._data.get(cle); + int x = loop.getX(); + int y = loop.getY(); + float corner = 0; + float center = this._ipRaw.getf(x, y); + float squareCenterAvg = process3By3SquareAvg(x,y); + corner = computeAvgCorner(x,y); + loop.setPaScoreAvg(center/corner); + loop.setRegionalPaScoreAvg(squareCenterAvg/corner); + + float probnum = 0; + float factorial = 1; + int countnumber = (int) (corner); + for (int i = 0; i < countnumber; i++) { + if (i == 0) { + factorial = 1; + }else { + factorial = 1; + for (int j = 1; j<= i; j++) factorial = factorial*j; + } + float tmpprobnum = (float) ((Math.pow(2.718,((center)*-1))*Math.pow((center),i))/factorial); + probnum = probnum + tmpprobnum; + } + loop.setPaScoreAvgdev(1-probnum); + + int xFDR = x+10; + int yFDR = y+10; + if(xFDR > this._imgRaw.getWidth()-12 || yFDR > this._imgRaw.getHeight()-12){ + xFDR = x-10; + yFDR = y-10; + if(xFDR <= 0) xFDR = 13; + if(yFDR <= 0) yFDR = 13; + } + + float centerFDR = this._ipRaw.getf(xFDR,yFDR); + float squareCenterAvgFDR = process3By3SquareAvg(xFDR,yFDR); + loop.setPaScoreAvgFDR(centerFDR/computeAvgCorner(xFDR,yFDR)); + loop.setRegionalPaScoreAvgFDR(squareCenterAvgFDR/computeAvgCorner(xFDR,yFDR)); + + int xFDR2 = x+25; + int yFDR2 = y+25; + if(xFDR2 > this._imgRaw.getWidth()-12 || yFDR2 > this._imgRaw.getHeight()-12){ + xFDR2 = x-25; + yFDR2 = y-25; + if(xFDR2 <= 0) xFDR2 = 13; + if(yFDR2 <= 0) yFDR2 = 13; + } + float centerFDR2 = this._ipRaw.getf(xFDR2,yFDR2); + float squareCenterAvgFDR2 = process3By3SquareAvg(xFDR2,yFDR2); + loop.setPaScoreAvgFDR2(centerFDR2/computeAvgCorner(xFDR2,yFDR2)); + loop.setRegionalPaScoreAvgFDR2(squareCenterAvgFDR2/computeAvgCorner(xFDR2,yFDR2)); + + int xFDR3 = x+40; + int yFDR3 = y+40; + if(xFDR3 > this._imgRaw.getWidth()-12 || yFDR3 > this._imgRaw.getHeight()-12){ + xFDR3 = x-40; + yFDR3 = y-40; + if(xFDR3 <= 0) xFDR3 = 13; + if(yFDR3 <= 0) yFDR3 = 13; + } + + float centerFDR3 = this._ipRaw.getf(xFDR3,yFDR3); + float squareCenterAvgFDR3 = process3By3SquareAvg(xFDR3,yFDR3); + loop.setPaScoreAvgFDR3(centerFDR3/computeAvgCorner(xFDR3,yFDR3)); + loop.setRegionalPaScoreAvgFDR3(squareCenterAvgFDR3/computeAvgCorner(xFDR3,yFDR3)); + } + } + + + /** + * compute the avg of5*5 square + * @param x int coordinate of the pixel center + * @param y int coordinat of the pixel center + * @return float average + */ + private float process3By3SquareAvg(int x, int y){ + float sum = 0; + int nb = 0; + for(int i = x-1; i <= x+1; ++i){ + for(int j = y-1; j <= y+1; ++j){ + if(i < this._ipRaw.getWidth() && i>0 && j < this._ipRaw.getHeight() && j > 0){ + if( Double.isNaN(this._ipRaw.getf(i, j))){ + sum += 0; + }else{ + sum += this._ipRaw.getf(i,j); + } + nb++; + } + } + } + if(nb == 0) + return 0; + return sum/nb; + } + + /** + * + * @param x + * @param y + * @return + */ + private float computeAvgCorner(int x, int y){ + float corner = process3By3SquareAvg(x-10,y-10); + corner += process3By3SquareAvg(x-10,y+10); + corner += process3By3SquareAvg(x+10,y-10); + corner += process3By3SquareAvg(x+10,y+10); + //System.out.println(corner+" dans avgCorner"); + if( corner == 0) corner = (float) 0.1; + return corner/4; + } +} diff --git a/src/process/TupleFileToImage.java b/src/main/java/plop/utils/TupleFileToImage.java similarity index 54% rename from src/process/TupleFileToImage.java rename to src/main/java/plop/utils/TupleFileToImage.java index c40b40d..c2bfe1b 100644 --- a/src/process/TupleFileToImage.java +++ b/src/main/java/plop/utils/TupleFileToImage.java @@ -1,4 +1,4 @@ -package process; +package plop.utils; import java.io.BufferedReader; import java.io.FileReader; @@ -23,17 +23,13 @@ public class TupleFileToImage { /** Image results */ private ImagePlus _imgNorm = new ImagePlus(); /** Path of the tuple file*/ - private String _file = ""; + private String _file; /** Size of the matrix*/ - private int _size = 0 ; + private int _size; /** Resolution of the image in base*/ - private int _resolution = 0 ; - /** Step to process the whole chromosme*/ + private int _resolution; + /** Step to java.plop.process the whole chromosme*/ private int _step ; - /** Image value average*/ - private float _avg = 0; - /** Image standard deviation */ - private float _std = 0; /** number of pixe == 0 */ private int _noZeroPixel = 0; @@ -53,9 +49,8 @@ public TupleFileToImage(String fileMatrix, int size, int resolution){ /** - * Method to make the image with an input tuple file return the image results - * - * @return ImagePlus results + * Method to make the image with an input tuple file from intra chromosomal java.plop.process + * */ public void readTupleFile(){ BufferedReader br; @@ -119,18 +114,118 @@ public void correctImage(ImagePlus img){ } } } - _avg = sum/_noZeroPixel; - _std = std(_avg,img); + /** Image value average*/ + float _avg = sum / _noZeroPixel; + /** Image standard deviation */ + float _std = std(_avg, img); for(int i = 0; i < ip.getWidth(); ++i){ for(int j = 0; j < ip.getWidth(); ++j){ float a = ip.getf(i, j); - if (Math.abs(j-i) <= 2 && a >= _avg+_std*2) - ip.setf(i,j,_avg); + if (Math.abs(j-i) <= 2 && a >= _avg + _std *2) + ip.setf(i,j, _avg); } } img.setProcessor(ip); } - + + /** + * Method to make the image with an input tuple file from inter chromosomal java.plop.process + * @return ImagePlus + */ + public ImagePlus readTupleFileInter(){ + ImagePlus img = new ImagePlus(); + BufferedReader br; + + String[] tfile = _file.split("_"); + //0 1 2 3 4 5 + //4_0_191154275_6_0_171115066 + int size = tfile.length; + + int numImageX = Integer.parseInt(tfile[size-5])/(_size*_resolution); + int numImageY = Integer.parseInt(tfile[size-2])/(_size*_resolution); + int x = (((Integer.parseInt(tfile[size-4])-Integer.parseInt(tfile[size-5])))/_resolution)+1; + tfile[size-1] = tfile[size-1].replace(".txt",""); + int y = (((Integer.parseInt(tfile[size-1])-Integer.parseInt(tfile[size-2])))/_resolution)+1; + System.out.println(_file+" "+x+" "+y); + FloatProcessor pRaw = new FloatProcessor(x, y); + try { + pRaw.abs(); + br = new BufferedReader(new FileReader(_file)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null){ + sb.append(line); + String[] parts = line.split("\\t"); + float raw = 0; + + if(!(parts[2].equals("NAN"))){ + raw =Float.parseFloat(parts[2]); + if (raw < 0) raw = 0; + } + + int correctionX = numImageX*_size*_resolution; + int correctionY = numImageY*_size*_resolution; + int i = (Integer.parseInt(parts[0]) - correctionX)/_resolution; + int j = (Integer.parseInt(parts[1]) - correctionY)/_resolution; + if(i < x && j< y){ + pRaw.setf(i, j, raw); + } + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + img.setProcessor(pRaw); + } catch (IOException e) { e.printStackTrace();} + catch(NumberFormatException ex){ + img = readTupleFileInterCool(); + } + + return img; + } + + /** + * Method to make the image with an input tuple file from inter chromosomal java.plop.process + * @return ImagePlus + */ + public ImagePlus readTupleFileInterCool(){ + ImagePlus img = new ImagePlus(); + BufferedReader br; + FloatProcessor pRaw = new FloatProcessor(_size, _size); + String[] tfile = _file.split("_"); + //chr3 150000000 150100000 chr4 150000000 150100000 2 1.31032e-05 + int numImageX = Integer.parseInt(tfile[tfile.length-5])/(_size*_resolution); + int numImageY = Integer.parseInt(tfile[tfile.length-2])/(_size*_resolution); + try { + pRaw.abs(); + br = new BufferedReader(new FileReader(_file)); + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + while (line != null){ + sb.append(line); + String[] parts = line.split("\\t"); + float raw = 0; + + if(!(parts[2].equals("NAN"))){ + raw =Float.parseFloat(parts[7])*1000000; + if (raw < 0) raw = 0; + } + + int correctionX = numImageX*_size*_resolution; + int correctionY = numImageY*_size*_resolution; + int i = (Integer.parseInt(parts[1]) - correctionX)/_resolution; + int j = (Integer.parseInt(parts[4]) - correctionY)/_resolution; + if(i < _size && j< _size){ + pRaw.setf(i, j, raw); + } + sb.append(System.lineSeparator()); + line = br.readLine(); + } + br.close(); + img.setProcessor(pRaw); + } catch (IOException e) { e.printStackTrace();} + return img; + } + /** * Compute the standard deviation of the pixel non zero values of m_img * @param mean average value in m_img @@ -169,15 +264,5 @@ private float std(float mean,ImagePlus img){ * @return ImagePlus normalized image */ public ImagePlus getNormImage(){return this._imgNorm;} - - /** - * setter for the raw Image - * @param img ImagePlus - */ - public void setRawImage(ImagePlus img){this._img = img;} - /** - * setter of the normalized image - * @param img ImagePLus - */ - public void setNormImage(ImagePlus img){this._imgNorm = img;} + } \ No newline at end of file diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index 075ae79..0000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: sipMain.Hic_main - diff --git a/src/multiProcesing/ProcessCoolerDumpData.java b/src/multiProcesing/ProcessCoolerDumpData.java deleted file mode 100644 index ea3028e..0000000 --- a/src/multiProcesing/ProcessCoolerDumpData.java +++ /dev/null @@ -1,93 +0,0 @@ -package multiProcesing; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import gui.Progress; -import process.CoolerDumpData; -import utils.CoolerExpected; -import utils.SIPObject; - -/** - * multi thread class dumping the data via juicertoolsbox.jar - * and make file step by step - * bed file: start1 start2 obs-expected distanceNormalizedValue - * - * @author axel poulet - */ -public class ProcessCoolerDumpData { - - /** progress bar if gui is true*/ - private Progress _p; - - /** - * - */ - public ProcessCoolerDumpData(){ } - - /** - * * run the processing on different cpu, if all cpu are running, take break else run a new one. - * - * @param hicFile - * @param sip - * @param chrSize - * @param juiceBoxTools - * @param normJuiceBox - * @param nbCPU - * @throws InterruptedException - */ - public void go(String coolTools, String cooler, SIPObject sip, String coolFile, HashMap chrSize,int nbCPU) throws InterruptedException { - ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); - Iterator chrName = chrSize.keySet().iterator(); - File outDir = new File(sip.getOutputDir()); - if (outDir.exists()==false) outDir.mkdir(); - - ArrayList listFactor = sip.getListFactor(); - for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { - - int res = sip.getResolution()*listFactor.get(indexFact); - int matrixSize = sip.getMatrixSize()/listFactor.get(indexFact); - CoolerExpected expected = new CoolerExpected(coolTools,coolFile, res, matrixSize, nbCPU); - String nameRes = String.valueOf(res); - nameRes = nameRes.replace("000", ""); - nameRes = nameRes+"kb"; - String expectedFile = sip.getOutputDir()+nameRes+".expected"; - System.out.println("start "+expectedFile); - expected.dumpExpected(expectedFile); - System.out.println("!!!!!!! End "+expectedFile); - } - - while(chrName.hasNext()){ - String chr = chrName.next(); - CoolerDumpData dumpData = new CoolerDumpData( cooler, coolFile); - RunnableDumpDataCooler task = new RunnableDumpDataCooler(sip.getOutputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); - executor.execute(task); - } - executor.shutdown(); - int nb = 0; - - if(sip.isGui()){ - _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); - _p._bar.setValue(nb); - } - while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { - if (nb != executor.getCompletedTaskCount()) { - nb = (int) executor.getCompletedTaskCount(); - if(sip.isGui()) _p._bar.setValue(nb); - } - } - File folder = new File(sip.getOutputDir()); - File[] listOfFiles = folder.listFiles(); - for(int i = 0; i < listOfFiles.length;++i) { - String name = listOfFiles[i].toString(); - if(name.contains(".expected")) listOfFiles[i].delete(); - } - if(sip.isGui()) _p.dispose(); - - } -} diff --git a/src/multiProcesing/ProcessDetectLoops.java b/src/multiProcesing/ProcessDetectLoops.java deleted file mode 100644 index a712aca..0000000 --- a/src/multiProcesing/ProcessDetectLoops.java +++ /dev/null @@ -1,86 +0,0 @@ -package multiProcesing; -import java.io.File; -import java.util.Iterator; - -import gui.Progress; -import utils.SIPObject; - -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - - -/** - * multi thread class - * Construct all the RunnableDetectLoops Object and run them sequencily with the available processors - * - * @author axel poulet - * - */ -public class ProcessDetectLoops{ - - /**int: number of processus*/ - static int _nbLance = 0; - /** boolean: if true continue the process else take a break*/ - static boolean _continuer; - /** */ - static int _indice = 0; - /** progress bar if gui is true*/ - private Progress _p; - - /** */ - public ProcessDetectLoops(){ } - - - public void go(SIPObject sip,int nbCPU, boolean delImage, String resuFile,String resName) throws InterruptedException { - ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); - Iterator chrName = sip.getChrSizeHashMap().keySet().iterator(); - if(sip.isProcessed()) { - boolean isCool = isProcessedMcool(sip.getOutputDir()+resName+File.separator+"normVector"); - //System.out.println(isCool); - sip.setIsCooler(isCool); - } - while(chrName.hasNext()){ - String chr = chrName.next(); - if(sip.isCooler()){ - RunnableDetectLoops task = new RunnableDetectLoops(chr, resuFile, sip, delImage); - executor.execute(task); - - }else { - String normFile = sip.getOutputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; - if (sip.isProcessed()){ - normFile = sip.getInputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; - } - RunnableDetectLoops task = new RunnableDetectLoops(chr, resuFile, sip,normFile, delImage); - executor.execute(task); - } - } - executor.shutdown(); - int nb = 0; - if(sip.isGui()){ - _p = new Progress(resName+" Loops Detection step",sip.getChrSizeHashMap().size()+1); - _p._bar.setValue(nb); - } - while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { - if (nb != executor.getCompletedTaskCount()) { - nb = (int) executor.getCompletedTaskCount(); - if(sip.isGui()) _p._bar.setValue(nb); - } - } - if(sip.isGui()) _p.dispose(); - - } - - /** - * - * @param dirToTest - * @return - */ - private boolean isProcessedMcool(String dirToTest) { - File test = new File (dirToTest); - if (test.exists() == false) - return true; - else - return false; - } -} \ No newline at end of file diff --git a/src/multiProcesing/ProcessHicDumpData.java b/src/multiProcesing/ProcessHicDumpData.java deleted file mode 100644 index e248ebe..0000000 --- a/src/multiProcesing/ProcessHicDumpData.java +++ /dev/null @@ -1,69 +0,0 @@ -package multiProcesing; - -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import gui.Progress; -import process.DumpData; -import utils.SIPObject; - - -/** - * multi thread class dumping the data via cooler - * and make file step by step - * bed file: start1 start2 obs-expected distanceNormalizedValue - * - * @author axel poulet - * - */ -public class ProcessHicDumpData{ - /** progress bar if gui is true*/ - private Progress _p; - - /** - * - */ - public ProcessHicDumpData(){ } - - /** - * * run the processing on different cpu, if all cpu are running, take break else run a new one. - * - * @param hicFile - * @param sip - * @param chrSize - * @param juiceBoxTools - * @param normJuiceBox - * @param nbCPU - * @throws InterruptedException - */ - public void go(String hicFile, SIPObject sip, HashMap chrSize, String juiceBoxTools, String normJuiceBox,int nbCPU) throws InterruptedException { - ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); - Iterator chrName = chrSize.keySet().iterator(); - File outDir = new File(sip.getOutputDir()); - if (outDir.exists()==false) outDir.mkdir(); - while(chrName.hasNext()){ - String chr = chrName.next(); - DumpData dumpData = new DumpData(juiceBoxTools, hicFile, normJuiceBox); - RunnableDumpDataHiC task = new RunnableDumpDataHiC(sip.getOutputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); - executor.execute(task); - } - executor.shutdown(); - int nb = 0; - - if(sip.isGui()){ - _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); - _p._bar.setValue(nb); - } - while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { - if (nb != executor.getCompletedTaskCount()) { - nb = (int) executor.getCompletedTaskCount(); - if(sip.isGui()) _p._bar.setValue(nb); - } - } - if(sip.isGui()) _p.dispose(); - } -} \ No newline at end of file diff --git a/src/process/MultiResProcess.java b/src/process/MultiResProcess.java deleted file mode 100644 index 2c511ff..0000000 --- a/src/process/MultiResProcess.java +++ /dev/null @@ -1,305 +0,0 @@ -package process; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import javax.swing.JOptionPane; - - -import multiProcesing.ProcessDetectLoops; -import utils.Loop; -import utils.SIPObject; - -/** - * - * @author axel poulet - * - */ -public class MultiResProcess { - - private SIPObject _sip; - /** - * - */ - private int _nbCpu; - /** - * - */ - private boolean _delImage; - - private String _doc = ("#SIP Version 1 run with java 8\n" - + "\nUsage:\n" - + "\thic [options]\n" - + "\tcool [options]\n" - + "\tprocessed [options]\n" - + "\nParameters:\n" - + "\t chrSizeFile: path to the chr size file, with the same name of the chr as in the hic file (i.e. chr1 does not match Chr1 or 1)\n" - + "\t-res: resolution in bp (default 5000 bp)\n" - + "\t-mat: matrix size to use for each chunk of the chromosome (default 2000 bins)\n" - + "\t-d: diagonal size in bins, remove the maxima found at this size (eg: a size of 2 at 5000 bp resolution removes all maxima" - + " detected at a distance inferior or equal to 10kb) (default 6 bins).\n" - + "\t-g: Gaussian filter: smoothing factor to reduce noise during primary maxima detection (default 1.5)\n" - + "\t-cpu: Number of CPU used for SIP processing (default 1)\n" - + "\t-factor: Multiple resolutions can be specified using:\n" - + "\t\t-factor 1: run only for the input res (default)\n" - + "\t\t-factor 2: res and res*2\n" - + "\t\t-factor 3: res and res*5\n" - + "\t\t-factor 4: res, res*2 and res*5\n" - + "\t-max: Maximum filter: increases the region of high intensity (default 2)\n" - + "\t-min: Minimum filter: removes the isolated high value (default 2)\n" - + "\t-sat: % of saturated pixel: enhances the contrast in the image (default 0.01)\n" - + "\t-t Threshold for loops detection (default 2800)\n" - + "\t-nbZero: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels surrounding the detected maxima (default 6)\n" - + "\t-norm: (default KR)\n" - + "\t-del: true or false, whether not to delete tif files used for loop detection (default true)\n" - + "\t-fdr: Empirical FDR value for filtering based on random sites (default 0.01)\n" - + "\t-isDroso: default false, if true apply extra filter to help detect loops similar to those found in D. mel cells\n" - + "\t-h, --help print help\n" - + "\nCommand line eg:\n" - + "\tjava -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... paramaters\n" - + "\tjava -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar\n" - + "\nAuthors:\n" - + "Axel Poulet\n" - + "\tDepartment of Molecular, Cellular and Developmental Biology Yale University 165 Prospect St\n" - + "\tNew Haven, CT 06511, USA\n" - + "M. Jordan Rowley\n" - + "\tDepartment of Genetics, Cell Biology and Anatomy, University of Nebraska Medical Center Omaha,NE 68198-5805\n" - + "\nContact: pouletaxel@gmail.com OR jordan.rowley@unmc.edu"); - - private String _chrFile; - /** - * - * @param sip - * @param cpu - * @param delImage - * @param chrSizeFile - */ - public MultiResProcess(SIPObject sip, int cpu, boolean delImage, String chrSizeFile) { - this._nbCpu = cpu; - this._sip = sip; - this._delImage = delImage; - this._chrFile = chrSizeFile; - } - - /** - * @throws InterruptedException - * @throws IOException - * - */ - public void run() throws InterruptedException, IOException{ - ArrayList listFactor = this._sip.getListFactor(); - ArrayList listOfFile = new ArrayList(); - File outDir = new File(_sip.getOutputDir()); - if (outDir.exists()==false) outDir.mkdir(); - if (_sip.isProcessed()){ - if(this.testDir()==false){ - if(_sip.isGui()) { - JOptionPane.showMessageDialog(null,"Resolution problem", "Enable to find all the directories needed for SIP (-factor option)", JOptionPane.ERROR_MESSAGE); - } - System.out.println("!!!! It is missing one or several directories for factor paramter\n"); - System.out.println(_doc); - System.exit(0); - } - } - for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { - int res = this._sip.getResolution()*listFactor.get(indexFact); - String resName = String.valueOf(res); - resName = resName.replace("000", "")+"kb"; - String resuFile = this._sip.getOutputDir()+File.separator+resName+"Loops.txt"; - listOfFile.add(resuFile); - File file = new File(resuFile); - if(file.exists()) - file.delete(); - SIPObject sipTmp = new SIPObject (); - if(indexFact == 0) { - ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); - processDetectloops.go(this._sip, this._nbCpu,this._delImage,resuFile,resName); - }else { - sipTmp.setInputDir(_sip.getOutputDir()); - sipTmp.setOutputDir(_sip.getOutputDir()); - if(this._sip.isProcessed()) { - sipTmp.setInputDir(_sip.getInputDir()); - sipTmp.setOutputDir(_sip.getOutputDir()); - } - sipTmp.setChrSizeHashMap(this._sip.getChrSizeHashMap()); - sipTmp.setIsGui(_sip.isGui()); - sipTmp.setDiagSize(this._sip.getDiagSize()); - sipTmp.setGauss(this._sip.getGauss()/listFactor.get(indexFact)); - sipTmp.setMatrixSize((int)(this._sip.getMatrixSize()/listFactor.get(indexFact))); - sipTmp.setResolution(res); - sipTmp.setStep(this._sip.getStep()/listFactor.get(indexFact)); - sipTmp.setMax(_sip.getMax()); - sipTmp.setMin(_sip.getMin()); - sipTmp.setSaturatedPixel(_sip.getSaturatedPixel()); - sipTmp.setThresholdMaxima(_sip.getThresholdMaxima()); - sipTmp.setNbZero(_sip.getNbZero()); - sipTmp.setIsProcessed(_sip.isProcessed()); - sipTmp.setFdr(_sip.getFdr()); - sipTmp.setIsDroso(_sip.isDroso()); - sipTmp.setIsCooler(_sip.isCooler()); - ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); - processDetectloops.go(sipTmp, this._nbCpu,this._delImage,resuFile,resName); - } - } - if(listOfFile.size() > 1) { - System.out.println("Merging File ... "); - this.mergedFile(listOfFile); - System.out.println("Merging File End !!!! "); - } - } - - /** - * - * @return - */ - private boolean testDir(){ - String input = _sip.getInputDir(); - ArrayList listFactor = this._sip.getListFactor(); - for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact){ - int res = this._sip.getResolution()*listFactor.get(indexFact); - String resName = String.valueOf(res); - resName = resName.replace("000", "")+"kb"; - File inputDir = new File(input+resName); - if(inputDir.exists()== false) { - return false; - } - } - return true; - } - - /** - * - * @param listOfFile - * @throws IOException - */ - private void mergedFile(ArrayList listOfFile) throws IOException{ - HashMap chrsize = readChrIndex(this._chrFile); - Set key = chrsize.keySet(); - ArrayList > data = new ArrayList >(); - for (int i = 0; i < key.size();++i) { - HashMap plop = new HashMap(); - data.add(plop); - } - - BufferedReader br = new BufferedReader(new FileReader(listOfFile.get(0))); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - String title = line; - sb.append(System.lineSeparator()); - line = br.readLine(); - while (line != null){ - sb.append(line); - Loop loop = new Loop(line); - String chr = loop.getChr(); - int index = chrsize.get(chr); - HashMap plop = data.get(index); - plop.put(line, loop); - data.set(index, plop); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - - for (int i = 1; i < listOfFile.size();++i) { - br = new BufferedReader(new FileReader((listOfFile.get(i)))); - sb = new StringBuilder(); - line = br.readLine(); - sb.append(System.lineSeparator()); - line = br.readLine(); - while (line != null){ - Loop loop = new Loop(line); - String chr = loop.getChr(); - int index = chrsize.get(chr); - HashMap plop = data.get(index); - if(compareLoop(plop,loop)){ - plop.put(line,loop); - data.set(index, plop); - } - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - } - - BufferedWriter writer; - writer = new BufferedWriter(new FileWriter(new File(_sip.getOutputDir()+"finalLoops.txt"))); - writer.write(title+"\n"); - for (int i = 0; i < data.size();++i){ - HashMap plop = data.get(i); - Set keyBis = plop.keySet(); - List output = keyBis.stream().collect(Collectors.toList()); - for (int j = 0; j < output.size();++j){ - writer.write(output.get(j)+"\n"); - } - } - writer.close(); - } - - - /** - * - * @param plop - * @param a - * @return - */ - private boolean compareLoop(HashMap plop, Loop a) { - Set key = plop.keySet(); - Iterator it = key.iterator(); - while (it.hasNext()){ - String loopName = it.next(); - Loop loop = plop.get(loopName); - int xEnd = loop.getCoordinates().get(1); - int yEnd = loop.getCoordinates().get(3); - int xtest = a.getCoordinates().get(0); - int xtestEnd = a.getCoordinates().get(1); - int res = xtestEnd-xtest; - int ytest = a.getCoordinates().get(2); - int ytestEnd = a.getCoordinates().get(3); - xtest = xtest-res*2; - xtestEnd = xtestEnd+res*2; - ytest = ytest-res*2; - ytestEnd = ytestEnd+res*2; - //System.out.println(x+"\t"+xEnd+"\t"+ xtestEnd); - if((xtest <= xEnd && xtestEnd >= xEnd) && (ytest <= yEnd && ytestEnd >= yEnd)) - return false; - } - return true; - } - - - /** - * - * @param chrSizeFile - * @return - * @throws IOException - */ - private HashMap readChrIndex( String chrSizeFile) throws IOException{ - HashMap chrSize = new HashMap(); - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - int i = 0; - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - chrSize.put(chr, i); - sb.append(System.lineSeparator()); - line = br.readLine(); - ++i; - } - br.close(); - return chrSize; - } - -} diff --git a/src/sipMain/Hic_main.java b/src/sipMain/Hic_main.java deleted file mode 100644 index ef5808a..0000000 --- a/src/sipMain/Hic_main.java +++ /dev/null @@ -1,526 +0,0 @@ -package sipMain; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; - -import javax.swing.JOptionPane; - -import gui.GuiAnalysis; -import multiProcesing.ProcessCoolerDumpData; -import multiProcesing.ProcessHicDumpData; -import process.MultiResProcess; -import utils.SIPObject; - -/** - * - * command line eg: - * java -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... paramaters - * java -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar - * - * @author axel poulet - * - */ -public class Hic_main { - /** Path of input data directory if dumped or processed data else .hic for hic option*/ - private static String _input = ""; - /** Path of output if not existed it is created*/ - private static String _output = ""; - /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ - private static String _juiceBoxTools = ""; - /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ - private static String _cooler = ""; - /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ - private static String _cooltools = ""; - /**Normalisation method to dump the the data with hic method (KR,NONE.VC,VC_SQRT)*/ - private static String _juiceBoXNormalisation = "KR"; - /**Size of the core for the gaussian blur filter allow to smooth the signal*/ - private static double _gauss = 1.5; - /**Size of the core for the Minimum filter*/ - private static double _min = 2.0; - /**Size of the core for the Maximum filter*/ - private static double _max = 2.0; - /**Matrix size: size in bins of the final image and defined the zone of interest in the hic map*/ - private static int _matrixSize = 2000; - /**Distance to the diagonal where the loops are ignored*/ - private static int _diagSize = 6; - /**Resolution of the matric in bases*/ - private static int _resolution = 5000; - /** % of saturated pixel in the image, allow the enhancement of the contrast in the image*/ - private static double _saturatedPixel = 0.01; - /** Threshold to accepet a maxima in the images as a loop*/ - private static int _thresholdMax = 2800; - /**number of pixel = 0 allowed around the loop*/ - private static int _nbZero = 6; - /** boolean if true run all the process (dump data + image +image processing*/ - private static boolean _isHic = true; - /** boolean if true run all the process (dump data + image +image processing*/ - private static boolean _isCool = false; - /** boolean if true run all the process (dump data + image +image processing*/ - private static boolean _isDroso = false; - /** factor(s) used to nalyse the matrix*/ - private static ArrayList _factor = new ArrayList(); - /** String factor option*/ - private static String _factOption = "1"; - /** if true run only image Processing step*/ - private static boolean _isProcessed = false; - /** hash map stocking in key the name of the chr and in value the size*/ - private static HashMap _chrSize = new HashMap(); - /** path to the chromosome size file */ - private static String _chrSizeFile; - /**boolean is true supress all the image created*/ - private static boolean _delImages = true; - /** double FDR value for filtering */ - private static double _fdr = 0.01; - /** int number of cpu*/ - private static int _cpu = 1; - /**boolean is true supress all the image created*/ - private static boolean _gui = false; - private static String _logError = ""; - /**String for the documentation*/ - private static String _doc = ("#SIP Version 1 run with java 8\n" - + "\nUsage:\n" - + "\thic [options]\n" - + "\tcool [options]\n" - + "\tprocessed [options]\n" - + "\nParameters:\n" - + "\t chrSizeFile: path to the chr size file, with the same name of the chr as in the hic file (i.e. chr1 does not match Chr1 or 1)\n" - + "\t-res: resolution in bp (default 5000 bp)\n" - + "\t-mat: matrix size to use for each chunk of the chromosome (default 2000 bins)\n" - + "\t-d: diagonal size in bins, remove the maxima found at this size (eg: a size of 2 at 5000 bp resolution removes all maxima" - + " detected at a distance inferior or equal to 10kb) (default 6 bins).\n" - + "\t-g: Gaussian filter: smoothing factor to reduce noise during primary maxima detection (default 1.5)\n" - + "\t-cpu: Number of CPU used for SIP processing (default 1)\n" - + "\t-factor: Multiple resolutions can be specified using:\n" - + "\t\t-factor 1: run only for the input res (default)\n" - + "\t\t-factor 2: res and res*2\n" - + "\t\t-factor 3: res and res*5\n" - + "\t\t-factor 4: res, res*2 and res*5\n" - + "\t-max: Maximum filter: increases the region of high intensity (default 2)\n" - + "\t-min: Minimum filter: removes the isolated high value (default 2)\n" - + "\t-sat: % of saturated pixel: enhances the contrast in the image (default 0.01)\n" - + "\t-t Threshold for loops detection (default 2800)\n" - + "\t-nbZero: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels surrounding the detected maxima (default 6)\n" - + "\t-norm: (default KR)\n" - + "\t-del: true or false, whether not to delete tif files used for loop detection (default true)\n" - + "\t-fdr: Empirical FDR value for filtering based on random sites (default 0.01)\n" - + "\t-isDroso: default false, if true apply extra filter to help detect loops similar to those found in D. mel cells\n" - + "\t-h, --help print help\n" - + "\nCommand line eg:\n" - + "\tjava -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... paramaters\n" - + "\tjava -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar\n" - + "\nAuthors:\n" - + "Axel Poulet\n" - + "\tDepartment of Molecular, Cellular and Developmental Biology Yale University 165 Prospect St\n" - + "\tNew Haven, CT 06511, USA\n" - + "M. Jordan Rowley\n" - + "\tDepartment of Genetics, Cell Biology and Anatomy, University of Nebraska Medical Center Omaha,NE 68198-5805\n" - + "\nContact: pouletaxel@gmail.com OR jordan.rowley@unmc.edu"); - - /** - * Main function to run all the process, can be run with gui or in command line. - * With command line with 1 or less than 5 parameter => run only the help - * With zero parameter only java -jar SIP.jar => gui - * With more than 5 paramter => command line mode - * - * @param args - * @throws IOException - * @throws InterruptedException - */ - public static void main(String[] args) throws IOException, InterruptedException { - _factor.add(1); - if (args.length >= 1 && args.length < 4){ - System.out.println(_doc); - System.exit(0); - }else if(args.length >= 4){ - if (args[0].equals("hic") || args[0].equals("processed") || args[0].equals("cool")){ - _input = args[1]; - _output = args[3]; - _chrSizeFile = args[2]; - if (args[0].equals("hic")){ - readOption(args,5); - _juiceBoxTools = args[4]; - }else if(args[0].equals("processed")){ - _isHic = false; - _isProcessed = true; - readOption(args,4); - }else if(args[0].equals("cool")){ - _isHic = false; - _isProcessed = false; - _isCool = true; - _cooler = args[5]; - _cooltools = args[4]; - readOption(args,6); - } - }else{ - System.out.println(args[0]+" not defined\n"); - System.out.println(_doc); - return; - } - - }else{////////////////////////////////////////GUI parameter initialisation - GuiAnalysis gui = new GuiAnalysis(); - _gui =true; - while( gui.isShowing()){ - try {Thread.sleep(1);} - catch (InterruptedException e) {e.printStackTrace();} - } - if (gui.isStart()){ - _isCool = gui.isCool(); - _chrSizeFile = gui.getChrSizeFile(); - _output = gui.getOutputDir(); - _input = gui.getRawDataDir(); - _matrixSize = gui.getMatrixSize(); - _diagSize = gui.getDiagSize(); - _resolution = gui.getResolution(); - _delImages = gui.isDeletTif(); - _gauss = gui.getGaussian(); - _max = gui.getMax(); - _min = gui.getMin(); - _isDroso= gui.isDroso(); - _nbZero = gui.getNbZero(); - _saturatedPixel = gui.getEnhanceSignal(); - _thresholdMax = gui.getNoiseTolerance(); - _fdr = gui.getFDR(); - _cpu = gui.getNbCpu(); - if(gui.getFactorChoice() == 2){ - _factor.add(2); - }else if(gui.getFactorChoice() == 4){ - _factor.add(2); - _factor.add(5); - }else if(gui.getFactorChoice() == 3){ - _factor.add(5); - } - _isHic = gui.isHic(); - _isProcessed = gui.isProcessed(); - _juiceBoxTools = gui.getJuiceBox(); - _cooltools = gui.getCooltools(); - _cooler = gui.getCooler(); - - if(gui.isNONE()) _juiceBoXNormalisation = "NONE"; - else if (gui.isVC()) _juiceBoXNormalisation = "VC"; - else if (gui.isVC_SQRT()) _juiceBoXNormalisation = "VC_SQRT"; - }else { - System.out.println("SIP closed: if you want the help: -h"); - return; - } - } - File f = new File(_input); - - if(f.exists()==false && _input.startsWith("https")==false){ - System.out.println(_input+" doesn't existed !!! \n\n"); - System.out.println(_doc); - return; - } - - f = new File(_chrSizeFile); - if(f.exists()==false ){ - System.out.println(_chrSizeFile+" doesn't existed !!! \n\n"); - System.out.println(_doc); - return; - } - - - SIPObject sip; - readChrSizeFile(_chrSizeFile); - if(_isHic){ - f = new File(_juiceBoxTools); - if(f.exists()==false){ - System.out.println(_juiceBoxTools+" doesn't existed !!! \n\n"); - System.out.println(_doc); - return; - } - System.out.println("hic mode: \n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+ "juiceBox: "+_juiceBoxTools+"\n"+ "norm: "+ _juiceBoXNormalisation+"\n" - + "gauss: "+_gauss+"\n"+ "min: "+_min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n"+ "diag size: "+_diagSize+"\n"+ "resolution: "+_resolution+"\n" - + "saturated pixel: "+_saturatedPixel+"\n"+ "threshold: "+_thresholdMax+"\n"+ "number of zero :"+_nbZero+"\n"+ "factor "+ _factOption+"\n"+ "fdr "+_fdr+"\n" - + "del "+_delImages+"\n"+ "cpu "+ _cpu+"\n-isDroso "+_isDroso+"\n"); - - sip = new SIPObject(_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, - _thresholdMax, _diagSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); - sip.setIsGui(_gui); - ProcessHicDumpData processDumpData = new ProcessHicDumpData(); - processDumpData.go(_input, sip, _chrSize, _juiceBoxTools, _juiceBoXNormalisation, _cpu); - System.out.println("########### End of the dump Step"); - }else if(_isCool){ - f = new File(_cooltools); - if(f.exists()==false){ - System.out.println(_cooltools+" doesn't existed or wrong path !!! \n\n"); - System.out.println(_doc); - return; - } - f = new File(_cooler); - if(f.exists()==false){ - System.out.println(_cooler+" doesn't existed or wrong path !!! \n\n"); - System.out.println(_doc); - return; - } - if( testTools(_cooltools,0,3,0) == false || testTools(_cooler,0,8,6) == false) { - System.out.println( _cooltools +" or" + _cooler+" is not the good version for SIP (it needs cooltools version >= 0.3.0 and cooler version >= 0.8.6) !!! \n\n"); - System.out.println(_doc); - if(_gui){ - JOptionPane.showMessageDialog(null, "Error SIP program", _cooltools +" or" + _cooler+" is not the good version for SIP (it needs cooltools version >= 0.3.0 and cooler version >= 0.8.6) !!!" - , JOptionPane.ERROR_MESSAGE); - } - return; - } - System.out.println("cool mode: \n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+"cooltools: "+_cooltools+"\n"+ "cooler: "+_cooler+"\n"+ "norm: "+ _juiceBoXNormalisation+"\n" - + "gauss: "+_gauss+"\n"+ "min: "+_min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n"+ "diag size: "+_diagSize+"\n"+ "resolution: "+_resolution+"\n" - + "saturated pixel: "+_saturatedPixel+"\n"+ "threshold: "+_thresholdMax+"\n"+ "number of zero :"+_nbZero+"\n"+ "factor "+ _factOption+"\n"+ "fdr "+_fdr+"\n" - + "del "+_delImages+"\n"+ "cpu "+ _cpu+"\n-isDroso "+_isDroso+"\n"); - sip = new SIPObject(_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, _thresholdMax, _diagSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); - sip.setIsCooler(_isCool); - - ProcessCoolerDumpData processDumpData = new ProcessCoolerDumpData(); - processDumpData.go(_cooltools, _cooler, sip, _input, _chrSize,_cpu); - - }else{ - System.out.println("processed mode:\n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+ "juiceBox: "+_juiceBoxTools+"\n" - + "norm: "+ _juiceBoXNormalisation+"\n"+ "gauss: "+_gauss+"\n"+ "min: "+_min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n" - + "diag size: "+_diagSize+"\n"+ "resolution: "+_resolution+"\n"+ "saturated pixel: "+_saturatedPixel+"\n"+ "threshold: "+_thresholdMax+"\n" - + "isHic: "+_isHic+"\n" + "isProcessed: "+_isProcessed+"\n"+ "number of zero:"+_nbZero+"\n"+ "factor "+ _factOption+"\n"+ "fdr "+_fdr+ "\n" - + "del "+_delImages+"\n"+"cpu "+ _cpu+"\n-isDroso "+_isDroso+"\n"); - - sip = new SIPObject(_input,_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, _thresholdMax, - _diagSize, _matrixSize, _nbZero,_factor,_fdr,_isProcessed, _isDroso); - sip.setIsGui(_gui); - } - System.out.println("Start loop detction step"); - - MultiResProcess multi = new MultiResProcess(sip, _cpu, _delImages,_chrSizeFile); - multi.run(); - System.out.println("###########End loop detction step"); - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(_output+File.separator+"parameters.txt"))); - if(_isProcessed){ - writer.write("java -jar Sip_HiC.jar processed "+ _input+" "+ _chrSizeFile+" "+_output+" -g "+_gauss+" -mat "+_matrixSize+" -d "+_diagSize - +" -res "+_resolution+" -t "+_thresholdMax+" -min "+_min+" -max "+_max+" -sat "+_saturatedPixel+" -nbZero "+_nbZero - +" -factor "+ _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ _cpu+" -isDroso "+_isDroso+"\n"); - - }else if(_isCool){ - writer.write("java -jar SIP_HiC.jar hic "+_input+" "+_chrSizeFile+" "+_output+" "+_cooltools+" "+_cooler+ - " -g "+_gauss+" -min "+_min+" -max "+_max+" -mat "+_matrixSize+ - " -d "+_diagSize+" -res "+_resolution+" -sat "+_saturatedPixel+" -t "+_thresholdMax+" -nbZero "+_nbZero+ - " -factor "+ _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ _cpu+" -isDroso "+_isDroso+"\n"); - }else{ - writer.write("java -jar SIP_HiC.jar hic "+_input+" "+_chrSizeFile+" "+_output+" "+_juiceBoxTools+ - " -norm "+ _juiceBoXNormalisation+" -g "+_gauss+" -min "+_min+" -max "+_max+" -mat "+_matrixSize+ - " -d "+_diagSize+" -res "+_resolution+" -sat "+_saturatedPixel+" -t "+_thresholdMax+" -nbZero "+_nbZero+ - " -factor "+ _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ _cpu+" -isDroso "+_isDroso+"\n"); - } - writer.close(); - - if(_gui){ - JOptionPane.showMessageDialog(null,"Results available: "+_output , "End of SIP program", JOptionPane.INFORMATION_MESSAGE); - } - System.out.println("End of SIP loops are available in "+_output); - } - - /** - * Run the input file and stock the info of name chr and their size in hashmap - * @param chrSizeFile path chr size file - * @throws IOException if file does't exist - */ - private static void readChrSizeFile( String chrSizeFile) throws IOException{ - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - int size = Integer.parseInt(parts[1]); - _chrSize.put(chr, size); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - } - - /** - * -res: resolution in bases (default 5000 bases) - * -mat: matrix size in bins (default 2000 bins) - * -d: diagonal size in bins (default 2 bins) - * -g: Gaussian filter (default 1) - * -max: Maximum filter: increase the region of high intensity (default 1.5) - * -min: minimum filter: removed the isolated high value (default 1.5) - * -sat: % of staturated pixel: enhance the contrast in the image (default 0.05) - * -t Threshold for loops detection (default 3000) - * -norm: only for hic option (default KR) - * -nbZero: - * -cpu - * -del - * -fdr - * - * @param args table of String stocking the arguments for the program - * @param index table index where start to read the arguments - * @throws IOException if some parameters don't exist - */ - private static void readOption(String args[], int index) throws IOException{ - if(index < args.length){ - for(int i = index; i < args.length;i+=2){ - if(args[i].equals("-res")){ - try{_resolution =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-res",args[i+1],"int");} - }else if(args[i].equals("-mat")){ - try{_matrixSize =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-mat",args[i+1],"int");} - }else if(args[i].equals("-factor")){ - int a = Integer.parseInt(args[i+1]); - _factOption = args[i+1]; - if(a == 2){ _factor.add(2);} - else if(a == 4){ - _factor.add(2); - _factor.add(5); - }else if(a == 3){ _factor.add(5);} - else if(a != 1) returnError("-factor ",args[i+1]," int or not correct choice (1, 2, 3, 4)"); - }else if(args[i].equals("-d")){ - try{_diagSize =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-d",args[i+1],"int");} - }else if(args[i].equals("-cpu")){ - try{_cpu =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-cpu",args[i+1],"int");} - if(_cpu > Runtime.getRuntime().availableProcessors() || _cpu <= 0){ - System.out.println("the number of CPU "+ _cpu+" is superior of the server/computer' cpu "+Runtime.getRuntime().availableProcessors()+"\n"); - System.out.println(_doc); - System.exit(0); - } - }else if(args[i].equals("-nbZero")){ - try{_nbZero =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-d",args[i+1],"int");} - }else if(args[i].equals("-g")){ - try{_gauss =Double.parseDouble(args[i+1]);} - catch(NumberFormatException e){ returnError("-g",args[i+1],"double");} - }else if(args[i].equals("-fdr")){ - try{_fdr =Double.parseDouble(args[i+1]);} - catch(NumberFormatException e){ returnError("-fdr",args[i+1],"double");} - }else if(args[i].equals("-max")){ - try{_max = Double.parseDouble(args[i+1]);} - catch(NumberFormatException e){ returnError("-max",args[i+1],"double");} - - }else if(args[i].equals("-min")){ - try{_min = Double.parseDouble(args[i+1]);} - catch(NumberFormatException e){ returnError("-min",args[i+1],"double");} - }else if(args[i].equals("-sat")){ - try{_saturatedPixel = Double.parseDouble(args[i+1]);} - catch(NumberFormatException e){ returnError("-sat",args[i+1],"double");} - }else if(args[i].equals("-t")){ - try{_thresholdMax =Integer.parseInt(args[i+1]);} - catch(NumberFormatException e){ returnError("-t",args[i+1],"int");} - }else if(args[i].equals("-norm")){ - if(args[i+1].equals("NONE") || args[i+1].equals("VC") - || args[i+1].equals("VC_SQRT") || args[i+1].equals("KR")){ - _juiceBoXNormalisation = args[i+1]; - }else{ - System.out.println("-norm = "+args[i+1]+", not defined\n"); - System.out.println(_doc); - System.exit(0); - } - }else if(args[i].equals("-del")){ - if(args[i+1].equals("true") || args[i+1].equals("T") || args[i+1].equals("TRUE")) - _delImages = true; - else if(args[i+1].equals("false") || args[i+1].equals("F") || args[i+1].equals("False")) - _delImages = false; - else{ - System.out.println("-del = "+args[i+1]+", not defined\n"); - System.out.println(_doc); - System.exit(0); - } - }else if(args[i].equals("-isDroso")){ - if(args[i+1].equals("true") || args[i+1].equals("T") || args[i+1].equals("TRUE")) - _isDroso = true; - else if(args[i+1].equals("false") || args[i+1].equals("F") || args[i+1].equals("False")) - _isDroso = false; - else{ - System.out.println("-_isDroso = "+args[i+1]+", not defined\n"); - System.out.println(_doc); - System.exit(0); - } - }else{ - System.out.println(args[i]+" doesn't existed\n"); - System.out.println(_doc); - System.exit(0); - } - } - } - } - - /** - * Return specifci error on function of thearugnent problems - * - * @param param String name of the arugment - * @param value String value of the argument - * @param type Strint type of the argument - */ - private static void returnError(String param, String value, String type){ - System.out.println(param+" has to be an integer "+value+" can't be convert in "+type+"\n"); - System.out.println(_doc); - System.exit(0); - } - - - public static boolean testTools(String pathTools, int first, int second, int third) { - Runtime runtime = Runtime.getRuntime(); - String cmd = pathTools+" --version"; - Process process; - try { - process = runtime.exec(cmd); - - new ReturnFlux(process.getInputStream()).start(); - new ReturnFlux(process.getErrorStream()).start(); - process.waitFor(); - - } catch (IOException | InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - String [] tline = _logError.split(" "); - System.out.println(_logError); - _logError = ""; - if(tline.length > 0){ - tline = tline[tline.length-1].split("\\."); - tline[2] = tline[2].replace("\n", ""); - if(Integer.parseInt(tline[0]) >= first && Integer.parseInt(tline[1]) >= second) //&& Integer.parseInt(tline[2]) >= third) - return true; - else - return false; - }else - return false; - } - - public static class ReturnFlux extends Thread { - - /** Flux to redirect */ - private InputStream _flux; - - /** - * Constructor of ReturnFlux - * @param flux - * flux to redirect - */ - public ReturnFlux(InputStream flux){this._flux = flux; } - - /** - * - */ - public void run(){ - try { - InputStreamReader reader = new InputStreamReader(this._flux); - BufferedReader br = new BufferedReader(reader); - String line=null; - while ( (line = br.readLine()) != null) { - if(line.contains("WARN")== false) _logError = _logError+line+"\n"; - } - } - catch (IOException ioe){ - ioe.printStackTrace(); - } - } - } - - -} diff --git a/src/test/TestCallLoopsProcessedFile.java b/src/test/TestCallLoopsProcessedFile.java deleted file mode 100644 index 72e989e..0000000 --- a/src/test/TestCallLoopsProcessedFile.java +++ /dev/null @@ -1,94 +0,0 @@ -package test; -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; - -import process.MultiResProcess; -import utils.SIPObject; - -/** - * Test of calling loops on processed files - * - * @author Axel Poulet - * - */ -public class TestCallLoopsProcessedFile { - - /** - * - * @param args - * @throws IOException - * @throws InterruptedException - */ - public static void main(String[] args) throws IOException, InterruptedException { - String input = "/home/plop/Desktop/GM12878TestBis"; - String output= "/home/plop/Desktop/testChr"; - int matrixSize = 2000; - int resolution = 5000; - int diagSize = 5; - double gauss = 1.5; - int thresholdMax = 2800;// 2800;//1800 - int nbZero = 6;//6; - double min = 2;//1.5; - double max = 2;//1.5; - double saturatedPixel = 0.01;//0.005; - //boolean keepTif = false; - ArrayList factor = new ArrayList(); - factor.add(1); - //factor.add(2); - //factor.add(5); - //SIP_HiC_v1.3.6.jar hic SIP/Kc_allcombined.hic SIP/armsizes.txt SIP/Droso/ ../Tools/juicer_tools_1.13.02.jar - String chrSizeFile = "/home/plop/Desktop/w_hg19.sizes"; - HashMap chrsize = readChrSizeFile(chrSizeFile); - SIPObject sip = new SIPObject(input,output, chrsize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,true,false); - sip.setIsGui(false); - int cpu = 2; - System.out.println("Processed Data\n"); - System.out.println("input "+input+"\n" - + "output "+output+"\n" - + "gauss "+gauss+"\n" - + "min "+min+"\n" - + "max "+max+"\n" - + "matrix size "+matrixSize+"\n" - + "diag size "+diagSize+"\n" - + "resolution "+resolution+"\n" - + "saturated pixel "+saturatedPixel+"\n" - + "threshold "+thresholdMax+"\n" - + "isProcessed "+sip.isProcessed()+"\n"); - System.out.println("ahhhhhhhhhhhhh\n"); - MultiResProcess multi = new MultiResProcess(sip, cpu, false,chrSizeFile); - multi.run(); - //ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); - //processDetectloops.go(sip, 2,false); - //Testpb plop = new Testpb(sip, true); - //plop.run(2); - System.out.println("End"); - } - - /** - * - * @param chrSizeFile - * @return - * @throws IOException - */ - private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ - HashMap chrSize = new HashMap(); - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - int size = Integer.parseInt(parts[1]); - - chrSize.put(chr, size); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - return chrSize; - } -} diff --git a/src/test/TestCoolFormat.java b/src/test/TestCoolFormat.java deleted file mode 100644 index f21045c..0000000 --- a/src/test/TestCoolFormat.java +++ /dev/null @@ -1,92 +0,0 @@ -package test; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; - -import multiProcesing.ProcessCoolerDumpData; -import multiProcesing.ProcessHicDumpData; -import process.CoolerDumpData; -import process.MultiResProcess; -import utils.CoolerExpected; -import utils.SIPObject; -@SuppressWarnings("unused") -public class TestCoolFormat { - - public static void main(String[] args) throws IOException, InterruptedException { - String chr = "chr21"; - //String input = "/home/plop/Desktop/SIP/testCooler/GM12878_4DNFIXP4QG5B.mcool"; - String input = "/home/plop/Desktop/CoolTest21"; - String output = "/home/plop/Desktop/CoolTest21Bis"; - String expectedFile = "/home/plop/Desktop/chr21Cooler/expected.txt"; - String fileChr = "/home/plop/Desktop/w_hg19.sizes"; - String cooler = "/home/plop/anaconda3/bin/cooler"; - String cooltools = "/home/plop/anaconda3/bin/cooltools"; - HashMap chrsize = readChrSizeFile(fileChr); - int resolution = 5000; - int matrixSize = 2000; - //CoolerExpected expected = new CoolerExpected(input, resolution, matrixSize); - //expected.dumpExpected(expectedFile); - //CoolerExpected expected = new CoolerExpected(expectedFile, matrixSize); - //expected.parseExpectedFile(); - //ArrayList plop = expected.getExpected(chr); - //CoolerDumpData cooler = new CoolerDumpData(input, resolution, plop); - //run(resolution,matrixSize,matrixSize/2,chr,output, cooler, 46709983); - - int diagSize = 5; - double gauss = 1.5; - double min = 2; - double max = 2; - int nbZero = 6; - int thresholdMax = 2800; - double saturatedPixel = 0.01; - ArrayList factor = new ArrayList(); - factor.add(1); - factor.add(2); - factor.add(5); - boolean keepTif = false; - int cpu = 1; - - SIPObject sip = new SIPObject(input,output, chrsize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.03,keepTif,false); - sip.setIsGui(false); - sip.setIsCooler(true); - sip.setIsProcessed(true); - - - //ProcessCoolerDumpData processDumpData = new ProcessCoolerDumpData(); - // go(String coolTools, String cooler, SIPObject sip, String coolFile, HashMap chrSize,int nbCPU) - //processDumpData.go(cooltools, cooler, sip, input, chrsize,2); - MultiResProcess multi = new MultiResProcess(sip, cpu, keepTif,fileChr); - multi.run(); - - System.out.println("end"); - - } - - /** - * - * @param chrSizeFile - * @return - * @throws IOException - */ - private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ - HashMap chrSize = new HashMap(); - BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - String[] parts = line.split("\\t"); - String chr = parts[0]; - int size = Integer.parseInt(parts[1]); - chrSize.put(chr, size); - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - return chrSize; - } -} diff --git a/src/utils/FDR.java b/src/utils/FDR.java deleted file mode 100644 index 60d95be..0000000 --- a/src/utils/FDR.java +++ /dev/null @@ -1,82 +0,0 @@ -package utils; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * - * @author m. jordan rowley and axel poulet - * - */ -public class FDR { - /** */ - private double _RFDRcutoff = 10000; - /** */ - private double _FDRcutoff = 10000; - - /** - * - */ - public FDR(){} - - /** - * - * @param fdr - * @param data - */ - public void run(double fdr,HashMap data){ - Set key = data.keySet(); - Iterator it = key.iterator(); - List myFDRvals = new ArrayList(); - List myRFDRvals = new ArrayList(); - - while (it.hasNext()) { - String loopName = it.next(); - Loop loop = data.get(loopName); - - float dubFDR = loop.getPaScoreAvgFDR(); - float dubFDR2 = loop.getPaScoreAvgFDR2(); - float dubFDR3 = loop.getPaScoreAvgFDR3(); - - if(dubFDR > 0) myFDRvals.add(dubFDR); - if(dubFDR2 > 0) myFDRvals.add(dubFDR2); - if(dubFDR3 > 0) myFDRvals.add(dubFDR3); - - - float dubRFDR = loop.getRegionalPaScoreAvgFDR(); - float dubRFDR2 = loop.getRegionalPaScoreAvgFDR2(); - float dubRFDR3 = loop.getRegionalPaScoreAvgFDR3(); - - if(dubRFDR > 0) myRFDRvals.add(dubRFDR); - if(dubRFDR2 > 0) myRFDRvals.add(dubRFDR2); - if(dubRFDR3 > 0) myRFDRvals.add(dubRFDR3); - } - - Collections.sort(myFDRvals); - int topFDRs = (int)(myFDRvals.size()*fdr); - if(topFDRs != 0){ - List topFDRlist = new ArrayList(myFDRvals.subList(myFDRvals.size() -topFDRs, myFDRvals.size() -(topFDRs-1))); - this._FDRcutoff = topFDRlist.get(0); - Collections.sort(myRFDRvals); - int topRFDRs = (int)(myRFDRvals.size()*fdr); - List topRFDRlist = new ArrayList(myRFDRvals.subList(myRFDRvals.size() -topRFDRs, myRFDRvals.size() -(topRFDRs-1))); - this._RFDRcutoff = topRFDRlist.get(0); - } - } - - /** - * - * @return - */ - public double getRFDRcutoff() { return _RFDRcutoff; } - - /** - * - * @return - */ - public double getFDRcutoff() { return _FDRcutoff; } -} diff --git a/src/utils/PeakAnalysisScore.java b/src/utils/PeakAnalysisScore.java deleted file mode 100644 index fed9eb8..0000000 --- a/src/utils/PeakAnalysisScore.java +++ /dev/null @@ -1,153 +0,0 @@ -package utils; - -import java.util.HashMap; -import java.lang.Math; -import java.util.Iterator; -import java.util.Set; -import ij.ImagePlus; -import ij.process.ImageProcessor; - -/** - * Peak analysis score. - * peaks analysis score is adapted from the APA score from Rao&Huntley et al., 2014: - * @author axel poulet - * - */ -public class PeakAnalysisScore { - /** Raw image of the matrix*/ - private ImagePlus _imgRaw = new ImagePlus(); - /** HashMap of object loops*/ - private HashMap _data = new HashMap(); - /** ImageProcessor of the raw ImagePlus*/ - private ImageProcessor _ipRaw; - - /** - * Constructor of PeakAnalysisScore - * @param imgRaw ImagePlus raw image - * @param data HashMap of loops - */ - public PeakAnalysisScore(ImagePlus imgRaw, HashMap data){ - this._imgRaw = imgRaw; - this._data = data; - this._ipRaw = _imgRaw.getProcessor(); - } - - - /** - * Method to compute the score of each loop. on a 11*11 square, the average of the corner (3*3) are computed. then the ration between the loops value and this avg is computed. - * For the regional value, the avg of the n_8 value of the loops are done, then a ratio is computed with the avg value of the corner, - * This method is used for the observed and oMe method. - * - */ - public void computeScore(){ - Set key = this._data.keySet(); - Iterator it = key.iterator(); - while (it.hasNext()){ - String cle = it.next(); - Loop loop = this._data.get(cle); - int x = loop.getX(); - int y = loop.getY(); - float corner = 0; - float center = this._ipRaw.getf(x, y); - float squareCenterAvg = process3By3SquareAvg(x,y); - - if(x >= 12 && y >= 12 && x < this._imgRaw.getWidth()-12 && y < this._imgRaw.getHeight()-12){ - corner = computeAvgCorner(x,y); - loop.setPaScoreAvg(center/corner); - loop.setRegionalPaScoreAvg(squareCenterAvg/corner); - - float probnum = 0; - float factorial = 1; - int countnumber = (int) (corner); - for (int i = 0; i < countnumber; i++) { - if (i == 0) { - factorial = 1; - }else { - factorial = 1; - for (int j = 1; j<= i; j++) factorial = factorial*j; - } - float tmpprobnum = (float) ((Math.pow(2.718,((center)*-1))*Math.pow((center),i))/factorial); - probnum = probnum + tmpprobnum; - } - loop.setPaScoreAvgdev(1-probnum); - - int xFDR = x+10; - int yFDR = y+10; - if(xFDR > this._imgRaw.getWidth()-12 || yFDR > this._imgRaw.getHeight()-12){ - xFDR = x-10; - yFDR = y-10; - } - - float centerFDR = this._ipRaw.getf(xFDR,yFDR); - float squareCenterAvgFDR = process3By3SquareAvg(xFDR,yFDR); - loop.setPaScoreAvgFDR(centerFDR/computeAvgCorner(xFDR,yFDR)); - loop.setRegionalPaScoreAvgFDR(squareCenterAvgFDR/computeAvgCorner(xFDR,yFDR)); - - int xFDR2 = x+25; - int yFDR2 = y+25; - if(xFDR2 > this._imgRaw.getWidth()-12 || yFDR2 > this._imgRaw.getHeight()-12){ - xFDR2 = x-25; - yFDR2 = y-25; - if(xFDR2 <= 0) xFDR2 = 13; - if(yFDR2 <= 0) yFDR2 = 13; - } - //System.out.println(xFDR2+" "+yFDR2); - float centerFDR2 = this._ipRaw.getf(xFDR2,yFDR2); - float squareCenterAvgFDR2 = process3By3SquareAvg(xFDR2,yFDR2); - loop.setPaScoreAvgFDR2(centerFDR2/computeAvgCorner(xFDR2,yFDR2)); - loop.setRegionalPaScoreAvgFDR2(squareCenterAvgFDR2/computeAvgCorner(xFDR2,yFDR2)); - - int xFDR3 = x+40; - int yFDR3 = y+40; - if(xFDR3 > this._imgRaw.getWidth()-12 || yFDR3 > this._imgRaw.getHeight()-12){ - xFDR3 = x-40; - yFDR3 = y-40; - if(xFDR3 <= 0) xFDR3 = 13; - if(yFDR3 <= 0) yFDR3 = 13; - } - - float centerFDR3 = this._ipRaw.getf(xFDR3,yFDR3); - float squareCenterAvgFDR3 = process3By3SquareAvg(xFDR3,yFDR3); - loop.setPaScoreAvgFDR3(centerFDR3/computeAvgCorner(xFDR3,yFDR3)); - loop.setRegionalPaScoreAvgFDR3(squareCenterAvgFDR3/computeAvgCorner(xFDR3,yFDR3)); - } - } - } - - /** - * compute the avg of5*5 square - * @param x int coordinate of the pixel center - * @param y int coordinat of the pixel center - * @return float average - */ - private float process3By3SquareAvg(int x, int y){ - float sum = 0; - int nb = 0; - for(int i = x-2; i <= x+2; ++i){ - for(int j = y-2; j <= y+2; ++j){ - if(i < this._ipRaw.getWidth() && i>0 && j < this._ipRaw.getWidth() && j > 0){ - sum += this._ipRaw.getf(i,j); - nb++; - } - } - } - if(nb == 0) - return 0; - return sum/nb; - } - - /** - * - * @param x - * @param y - * @return - */ - private float computeAvgCorner(int x, int y){ - float corner = process3By3SquareAvg(x-10,y-10); - corner += process3By3SquareAvg(x-10,y+10); - corner += process3By3SquareAvg(x+10,y-10); - corner += process3By3SquareAvg(x+10,y+10); - if( corner == 0) corner = (float) 0.1; - return corner/4; - } -} diff --git a/src/utils/SIPObject.java b/src/utils/SIPObject.java deleted file mode 100644 index 48f78ec..0000000 --- a/src/utils/SIPObject.java +++ /dev/null @@ -1,496 +0,0 @@ -package utils; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Set; - - -/** - * Analyse and detect a whole genome HiC with .hic file or already processed data. - * The class is used for the observed and oMe method. - * - * MorpholibJ method used - * - * Collection of mathematical morphology methods and plugins for ImageJ, created at the INRA-IJPB Modeling and Digital Imaging lab. - * David Legland, Ignacio Arganda-Carreras, Philippe Andrey; MorphoLibJ: integrated library and plugins for mathematical morphology with ImageJ. - * Bioinformatics 2016; 32 (22): 3532-3534. doi: 10.1093/bioinformatics/btw413 - * - * @author axel poulet - * - */ -public class SIPObject { - /** String path of the input data*/ - private String _input; - /** Path of the output file*/ - private String _output; - /** Strength of the gaussian filter*/ - private double _gauss; - /** Strength of the min filter*/ - private double _min; - /** Strength of the max filter*/ - private double _max; - /** % of staurated pixel after enhance contrast*/ - private double _saturatedPixel; - /** Image size*/ - private int _matrixSize = 0; - /** Resolution of the bin dump in base*/ - private int _resolution; - /** Threshold for the maxima detection*/ - private int _thresholdMaxima; - /** HashMap of the chr size, the key = chr name, value = size of chr*/ - private HashMap _chrSize = new HashMap(); - /** Diage size to removed maxima close to diagonal*/ - private int _diagSize; - /** Size of the step to process each chr (step = matrixSize/2)*/ - private int _step; - /** Number of pixel = 0 allowed around the loop*/ - private int _nbZero = -1; - /** list of the image resolution to find loop*/ - private ArrayList _listFactor = new ArrayList(); - /** fdr value */ - private double _fdr; - /** is processed booelan*/ - private boolean _isProcessed = false; - /** if is gui analysis*/ - private boolean _isGui = false; - /** if rfdr*/ - private boolean _isDroso = false; - private double _medianAP = 0; - private double _medianAPReg = 0; - private boolean _isCooler = false; - //private HashMap _normVector = new HashMap(); - - - public SIPObject() { - - } - /** - * SIPObject constructor - * - * @param output - * @param chrSize - * @param gauss - * @param min - * @param max - * @param resolution - * @param saturatedPixel - * @param thresholdMax - * @param diagSize - * @param matrixSize - * @param nbZero - * @param listFactor - * @param fdr - * @param isProcessed - * @param isHichip - */ - public SIPObject(String output, HashMap chrSize, double gauss, double min, - double max, int resolution, double saturatedPixel, int thresholdMax, - int diagSize, int matrixSize, int nbZero,ArrayList listFactor, - double fdr, boolean isProcessed, boolean rfdr) { - if(output.endsWith(File.separator) == false) - output = output+File.separator; - this._output = output; - this._input = output; - this._chrSize = chrSize; - this._gauss = gauss; - this._min = min; - this._max = max; - this._matrixSize = matrixSize; - this._resolution = resolution; - this._saturatedPixel = saturatedPixel; - this._thresholdMaxima = thresholdMax; - this._diagSize = diagSize; - this._step = matrixSize/2; - this._nbZero = nbZero; - this._listFactor = listFactor; - this._fdr = fdr; - this._isProcessed = isProcessed; - this._isDroso = rfdr; - } - - /** - * SIPObject constructor - * @param input - * @param output - * @param chrSize - * @param gauss - * @param min - * @param max - * @param resolution - * @param saturatedPixel - * @param thresholdMax - * @param diagSize - * @param matrixSize - * @param nbZero - * @param listFactor - * @param fdr - * @param isProcessed - * @param isHichip - */ - public SIPObject(String input, String output, HashMap chrSize, double gauss, double min, - double max, int resolution, double saturatedPixel, int thresholdMax, - int diagSize, int matrixSize, int nbZero,ArrayList listFactor, - double fdr, boolean isProcessed, boolean rfdr) { - if(output.endsWith(File.separator) == false) - output = output+File.separator; - if(input.endsWith(File.separator) == false) - input = input+File.separator; - this._output = output; - this._input = input; - this._chrSize = chrSize; - this._gauss = gauss; - this._min = min; - this._max = max; - this._matrixSize = matrixSize; - this._resolution = resolution; - this._saturatedPixel = saturatedPixel; - this._thresholdMaxima = thresholdMax; - this._diagSize = diagSize; - this._step = matrixSize/2; - this._nbZero = nbZero; - this._listFactor = listFactor; - this._fdr = fdr; - this._isProcessed = isProcessed; - this._isDroso = rfdr; - } - - - /** - * Save the result file in tabulated file - * - * @param pathFile String path for the results file - * @param first boolean to know idf it is teh first chromo - * @param data - * @throws IOException - */ - public void saveFile(String pathFile, HashMap data, boolean first) throws IOException{ - FDR fdrDetection = new FDR (); - fdrDetection.run(this._fdr, data); - double RFDRcutoff = fdrDetection.getRFDRcutoff(); - double FDRcutoff = fdrDetection.getFDRcutoff(); - boolean supToTen = false; - if(this._isDroso){ - median(data,FDRcutoff); - System.out.println("Filtering value at "+this._fdr+" FDR is "+FDRcutoff+" APscore "); - if(_medianAPReg > 10){ - supToTen = true; - _medianAPReg = _medianAPReg/4; - _medianAP = _medianAP/10; - } - } - else - System.out.println("Filtering value at "+this._fdr+" FDR is "+FDRcutoff+" APscore and "+RFDRcutoff+" RegionalAPscore\n"); - BufferedWriter writer; - if(first) writer = new BufferedWriter(new FileWriter(new File(pathFile), true)); - else{ - writer = new BufferedWriter(new FileWriter(new File(pathFile))); - writer.write("chromosome1\tx1\tx2\tchromosome2\ty1\ty2\tcolor\tAPScoreAvg\tProbabilityofEnrichment\tRegAPScoreAvg\tAvg_diffMaxNeihgboor_1\tAvg_diffMaxNeihgboor_2\tavg\tstd\tvalue\n"); - } - - if(data.size()>0){ - Set key = data.keySet(); - Iterator it = key.iterator(); - while (it.hasNext()){ - String name = it.next(); - Loop loop = data.get(name); - ArrayList coord = loop.getCoordinates(); - if(this._isDroso){ - if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && loop.getPaScoreAvg() > FDRcutoff && loop.getPaScoreAvgdev() > .9 && (loop.getNeigbhoord1() > 1 || loop.getNeigbhoord2() > 1)){ - if(supToTen){ - if(loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.7) && loop.getRegionalPaScoreAvg() <= (_medianAPReg*2)&& loop.getPaScoreAvg() <= (_medianAP*2)){ - writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" - +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" - +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" - +loop.getStd()+"\t"+loop.getValue()+"\n"); - } - }else{ - if( loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.5) && loop.getRegionalPaScoreAvg() <= (_medianAPReg*2)&& loop.getPaScoreAvg() <= (_medianAP*2)){ - writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" - +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" - +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" - +loop.getStd()+"\t"+loop.getValue()+"\n"); - } - } - } - }else{ - if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && loop.getPaScoreAvg() > FDRcutoff && loop.getRegionalPaScoreAvg() > RFDRcutoff && loop.getPaScoreAvgdev() > .9){ - writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+"\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0" - +"\t"+loop.getPaScoreAvg()+"\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+"\t" - +loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+"\t" - +loop.getStd()+"\t"+loop.getValue()+"\n"); - } - } - } - writer.close(); - } - } - - - - /** - * Full the list with file in directory - * @param dir - * @return - * @throws IOException - */ - - public File[] fillList(String dir) throws IOException{ - File folder = new File(dir); - File[] listOfFiles = folder.listFiles(); - return listOfFiles; - } - - - /** - * Test the normalized vector by chromosme - * @param normFile - */ - public HashMap getNormValueFilter(String normFile){ - BufferedReader br; - int lineNumber = 0; - HashMap vector = new HashMap(); - try { - br = new BufferedReader(new FileReader(normFile)); - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - while (line != null){ - sb.append(line); - if((line.equals("NaN")|| line.equals("NAN") || line.equals("nan") || line.equals("na") || Double.parseDouble(line) < 0.30)){ - vector.put(lineNumber*this._resolution, "plop"); - } - ++lineNumber; - sb.append(System.lineSeparator()); - line = br.readLine(); - } - br.close(); - } catch (IOException e) { e.printStackTrace();} - return vector; - } - - - /** - * - * @return - */ - private void median(HashMap data, double fdrCutoff){ - Set key = data.keySet(); - Iterator it = key.iterator(); - ArrayList n1 = new ArrayList (); - ArrayList n2 = new ArrayList (); - int nb = 0; - while (it.hasNext()){ - String name = it.next(); - Loop loop = data.get(name); - if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && loop.getPaScoreAvg() > fdrCutoff && loop.getPaScoreAvgdev() > .9){ - n1.add(loop.getPaScoreAvg()); - n2.add(loop.getRegionalPaScoreAvg()); - nb++; - } - } - if(nb>0){ - n1.sort(Comparator.naturalOrder()); - n2.sort(Comparator.naturalOrder()); - double pos1 = Math.floor((n1.size() - 1.0) / 2.0); - double pos2 = Math.ceil((n1.size() - 1.0) / 2.0); - if (pos1 == pos2 ) _medianAP = n1.get((int)pos1); - else _medianAP = (n1.get((int)pos1) + n1.get((int)pos2)) / 2.0 ; - pos1 = Math.floor((n2.size() - 1.0) / 2.0); - pos2 = Math.ceil((n2.size() - 1.0) / 2.0); - if (pos1 == pos2 ) _medianAPReg = n2.get((int)pos1); - else _medianAPReg = (n2.get((int)pos1) + n2.get((int)pos2)) / 2.0 ; - System.out.println("AP\t"+_medianAP+"\nAPREG\t"+_medianAPReg); - } - } - - - public double getFdr() { return this._fdr; } - public void setFdr(double fdr) { this._fdr = fdr; } - /** - * Getter of the input dir - * @return path of the input dir - */ - public String getInputDir(){ return this._input; } - - /** - * Getter of the matrix size - * - * @return the size of the image - */ - public int getMatrixSize(){ return this._matrixSize; } - - - /** - * Getter of step - * @return the step - */ - public int getStep(){ return this._step;} - - /** - * Setter of the path of the input directory - * @param inputDir String of the input directory - */ - public void setInputDir(String inputDir){ this._input = inputDir; } - - /** - * Getter of the path of the output directory - * @return path - */ - public String getOutputDir(){ return this._output; } - - /** - * Setter of the path of the output directory - * @param outputDir - */ - public void setOutputDir(String outputDir){ this._output = outputDir;} - - /** - * Getter of the gaussian blur strength - * @return double gaussian - */ - public double getGauss(){ return this._gauss; } - - /** - * Setter of the gaussian blur strength - * @param gauss double - */ - public void setGauss(double gauss){ this._gauss = gauss; } - - /** - * Getter of diagSize - * @return - */ - public int getDiagSize(){ return this._diagSize;} - /** - * Setter of the diagonal size - * @param diagSize int of the size of the diagonal - */ - public void setDiagSize(int diagSize){ this._diagSize = diagSize; } - - /** - * Getter of the min filter strength - * @return double strength of the min filter - */ - public double getMin(){ return this._min;} - - /** - * Setter of the min filter strength - * @param min - */ - public void setMin(double min){ this._min = min;} - - /** - * Getter of the max filter strength - * @return double max filter - */ - public double getMax(){ return this._max; } - - /** - * Setter of the min filter strength - * @param max - */ - public void setMax(double max){ this._max = max;} - - /** - * Getter % of saturated pixel for the contrast enhancement - * @return double percentage of saturated - */ - public double getSaturatedPixel(){ return this._saturatedPixel; } - - /** - * Setter % of saturated pixel for the contrast enhancement - * @param saturatedPixel - */ - public void setSaturatedPixel(double saturatedPixel){ this._saturatedPixel = saturatedPixel; } - - /** - * Getter of resolution of the bin - * @return - */ - public int getResolution(){ return this._resolution;} - - /** - * Setter of resolution of the bin - * @param resolution - */ - public void setResolution(int resolution){ this._resolution = resolution;} - - /** - * Setter of size of the matrix - * @param size - */ - public void setMatrixSize(int size){ this._matrixSize = size; } - - /** - * setter step between image - * @param step int step - */ - public void setStep(int step){ this._step = step;} - - /** - * Getter of threshold for the detction of the maxima - * @return - */ - public int getThresholdMaxima(){ return _thresholdMaxima;} - /** - * Setter of threshold for the detection of the maxima - * @param thresholdMaxima - */ - public void setThresholdMaxima(int thresholdMaxima) { this._thresholdMaxima = thresholdMaxima;} - - - - - - /** - * Getter of getNbZero - * @return - */ - public int getNbZero(){ return this._nbZero;} - - - public void setNbZero(int nbZero){ this._nbZero = nbZero;} - - /** - * - * @return - */ - public ArrayList getListFactor() {return this._listFactor;} - public void setListFactor(ArrayList listFactor) {this._listFactor = listFactor;} - - public boolean isDroso(){return this._isDroso;} - public void setIsDroso(boolean droso){ this._isDroso = droso;} - - public HashMap getChrSizeHashMap(){return this._chrSize;} - public void setChrSizeHashMap(HashMap chrSize){this._chrSize = chrSize;} - - - - /** - * - * @return - */ - public boolean isProcessed() { return _isProcessed;} - public void setIsProcessed(boolean isProcessed) { this._isProcessed = isProcessed;} - - /** - * - * @return - */ - public boolean isCooler() { return _isCooler;} - public void setIsCooler(boolean cool) { this._isCooler = cool;} - - /** - * - * @return - */ - public boolean isGui() { return _isGui;} - public void setIsGui(boolean _isGui) { this._isGui = _isGui;} -} \ No newline at end of file