├── .classpath ├── .directory ├── .gitignore ├── .idea ├── compiler.xml ├── misc.xml └── vcs.xml ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs ├── org.eclipse.ltk.core.refactoring.prefs └── org.eclipse.m2e.core.prefs ├── LICENSE ├── README.md ├── SIP.iml ├── bin ├── gui │ ├── GuiAnalysis$FileListener.class │ ├── GuiAnalysis$QuitListener.class │ ├── GuiAnalysis$RBHicListener.class │ ├── GuiAnalysis$RawDataDirectoryListener.class │ ├── GuiAnalysis$StartListener.class │ ├── GuiAnalysis$WorkDirectoryListener.class │ ├── GuiAnalysis.class │ └── Progress.class ├── test │ ├── TestCallLoopsHicFile.class │ ├── TestCallLoopsProcessedFile.class │ └── TestGui.class └── utils │ ├── ChangeImageRes.class │ ├── CoordinatesCorrection.class │ ├── DecayAnalysis.class │ ├── FindMaxima.class │ ├── Loop.class │ ├── PeakAnalysisScore.class │ └── Strip.class ├── dependency-reduced-pom.xml ├── pom.xml └── src └── main └── java ├── META-INF └── MANIFEST.MF └── plop ├── gui ├── GuiAnalysis.java └── Progress.java ├── multiProcesing ├── ProcessCoolerDumpData.java ├── ProcessDetectLoops.java ├── ProcessHicDumpData.java ├── RunnableDetectLoops.java ├── RunnableDumpDataCooler.java └── RunnableDumpDataHiC.java ├── process ├── CallLoops.java ├── CoolerDumpData.java ├── DumpData.java ├── MultiResProcess.java └── TupleFileToImage.java ├── sipMain └── Hic_main.java ├── test ├── TestCallLoopsHicFile.java ├── TestCallLoopsProcessedFile.java ├── TestCoolFormat.java ├── TestGui.java └── TestMergeLoops.java └── utils ├── CoolerExpected.java ├── CoordinatesCorrection.java ├── DecayAnalysis.java ├── FDR.java ├── FilterLoops.java ├── FindMaxima.java ├── ImageProcessingMethod.java ├── Loop.java ├── PeakAnalysisScore.java └── SIPObject.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | Timestamp=2018,5,15,18,10,47 3 | Version=3 4 | 5 | [Settings] 6 | HiddenFilesShown=true 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /plop.test/ 3 | /plop.utils/ 4 | .idea 5 | .project 6 | .directory 7 | .classpath 8 | /target/ 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SIP 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.codeComplete.argumentPrefixes= 3 | org.eclipse.jdt.core.codeComplete.argumentSuffixes= 4 | org.eclipse.jdt.core.codeComplete.fieldPrefixes= 5 | org.eclipse.jdt.core.codeComplete.fieldSuffixes= 6 | org.eclipse.jdt.core.codeComplete.localPrefixes= 7 | org.eclipse.jdt.core.codeComplete.localSuffixes= 8 | org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= 9 | org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= 10 | org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= 11 | org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= 12 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 13 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 14 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 15 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 16 | org.eclipse.jdt.core.compiler.compliance=1.8 17 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 18 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 19 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 20 | org.eclipse.jdt.core.compiler.doc.comment.support=enabled 21 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 22 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 23 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 24 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 25 | org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore 26 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled 27 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled 28 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled 29 | org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=public 30 | org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore 31 | org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled 32 | org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public 33 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag 34 | org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore 35 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled 36 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled 37 | org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public 38 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 39 | org.eclipse.jdt.core.compiler.release=disabled 40 | org.eclipse.jdt.core.compiler.source=1.8 41 | org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter 42 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | formatter_settings_version=12 3 | org.eclipse.jdt.ui.exception.name=e 4 | org.eclipse.jdt.ui.gettersetter.use.is=true 5 | org.eclipse.jdt.ui.keywordthis=false 6 | org.eclipse.jdt.ui.overrideannotation=true 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 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. 2 | 3 | # SIP 4 | 5 | 6 | 7 | # What is SIP? 8 | 9 | SIP (Significant Interaction Peak caller) is a tool to identify and analyze loops that appear as high intensity 10 | signal in Hi-C maps. This program is written in java and can be run on Linux, Windows, or MAC systems and 11 | includes either command line options or a graphical user interface. 12 | 13 | Follow the links below to get started: 14 | * [Quick Start](https://github.com/PouletAxel/SIP/wiki/SIP-Quick-Start) 15 | * [Parameter Selection Guide](https://github.com/PouletAxel/SIP/wiki/Explanations-of-Parameters) 16 | 17 | ## Citing SIP 18 | 19 | * [View the Paper](https://genome.cshlp.org/content/early/2020/03/03/gr.257832.119.long) 20 | 21 | 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. 22 | 23 | ## SIP help menu: 24 | 25 | SIP_HiC run with java 8. 26 | 27 | SIP is implemented in java and includes achoice between command line options or a graphical user interface (plop.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. 28 | 29 | 30 | #### Usage 31 | 32 | `hic [options]` 33 | 34 | `cool [options]` 35 | 36 | `processed [options]` 37 | 38 | #### Parameters: 39 | 40 | * **-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) 41 | * **-res**: resolution in bp (default 5000 bp) 42 | * **-mat**: matrix size to use for each chunk of the chromosome (default 2000 bins) 43 | * **-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). 44 | * **-g**: Gaussian filter: smoothing factor to reduce noise during primary maxima detection (default 1.5) 45 | * **-cpu**: Number of CPU used for SIP processing (default 1) 46 | * **-factor**: Multiple resolutions can be specified using: 47 | * -factor 1: run only for the input res (default) 48 | * -factor 2: res and res*2 49 | * -factor 3: res and res*5 50 | * -factor 4: res, res*2 and res*5 51 | * **-max**: Maximum filter: increases the region of high intensity (default 2) 52 | * **-min**: Minimum filter: removes the isolated high value (default 2) 53 | * **-sat**: % of staturated pixel: enhances the contrast in the image (default 0.01) 54 | * **-t**: Threshold for loops detection (default 2800 for hic) 55 | * **-nbZero**: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels surrounding the detected maxima (default 6) 56 | * **-norm**: (default KR) 57 | * **-del**: true or false, whether not to delete tif files used for loop detection (default true) 58 | * **-fdr**: Empirical FDR value for filtering based on random sites (default 0.01) 59 | * **-isDroso**: default false, if true apply extra filter to help detect loops similar to those found in D. mel cells 60 | * -h or --help print help 61 | 62 | #### Command line eg: 63 | 64 | `java -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir [options]` 65 | 66 | `java -jar SIP_HiC.jar hic pathTohicFile pathToChromosome.size OutputDir juicer_tools.jar [options]` 67 | 68 | `java -jar SIP_HiC.jar cool pathTomcoolFile pathToChromosome.size Output cooltoolsPath coolerPath [options]` 69 | 70 | 71 | ## Authors: 72 | 73 | * **Axel Poulet**: Department of Molecular, Cellular and Developmental Biology, Yale University, 165 Prospect St New Haven, CT 06511, USA. _Contact: pouletaxel@gmail.com_ 74 | * **M. Jordan Rowley**: Department of Genetics, Cell Biology and Anatomy, University of Nebraska Medical Center Omaha,NE 68198-5805. _Contact: jordan.rowley@unmc.edu_ 75 | -------------------------------------------------------------------------------- /SIP.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$FileListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$FileListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$QuitListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$QuitListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$RBHicListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$RBHicListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$RawDataDirectoryListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$RawDataDirectoryListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$StartListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$StartListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis$WorkDirectoryListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis$WorkDirectoryListener.class -------------------------------------------------------------------------------- /bin/gui/GuiAnalysis.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/GuiAnalysis.class -------------------------------------------------------------------------------- /bin/gui/Progress.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/gui/Progress.class -------------------------------------------------------------------------------- /bin/test/TestCallLoopsHicFile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/test/TestCallLoopsHicFile.class -------------------------------------------------------------------------------- /bin/test/TestCallLoopsProcessedFile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/test/TestCallLoopsProcessedFile.class -------------------------------------------------------------------------------- /bin/test/TestGui.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/test/TestGui.class -------------------------------------------------------------------------------- /bin/utils/ChangeImageRes.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/ChangeImageRes.class -------------------------------------------------------------------------------- /bin/utils/CoordinatesCorrection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/CoordinatesCorrection.class -------------------------------------------------------------------------------- /bin/utils/DecayAnalysis.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/DecayAnalysis.class -------------------------------------------------------------------------------- /bin/utils/FindMaxima.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/FindMaxima.class -------------------------------------------------------------------------------- /bin/utils/Loop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/Loop.class -------------------------------------------------------------------------------- /bin/utils/PeakAnalysisScore.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/PeakAnalysisScore.class -------------------------------------------------------------------------------- /bin/utils/Strip.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PouletAxel/SIP/6fc5be542e9609cc4f7e5ba3de01293d1a3f8b32/bin/utils/Strip.class -------------------------------------------------------------------------------- /dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | SIP 5 | SIP 6 | 1.6.6 7 | 8 | 9 | axpoulet 10 | Axel Poulet 11 | pouletaxel@gmail.com 12 | iGReD 13 | 14 | architect 15 | developer 16 | 17 | +1 18 | 19 | 20 | 21 | 22 | 23 | src/main/java/resources 24 | 25 | 26 | ${project.build.sourceDirectory} 27 | 28 | 29 | 30 | 31 | src/main/java/plop/resources 32 | 33 | 34 | ${project.build.testSourceDirectory} 35 | 36 | 37 | 38 | 39 | 40 | maven-assembly-plugin 41 | 3.0.0 42 | 43 | 44 | make-assembly 45 | package 46 | 47 | single 48 | 49 | 50 | 51 | 52 | 53 | 54 | plop.sipMain.Hic_main 55 | 56 | 57 | 58 | jar-with-dependencies 59 | 60 | 61 | 62 | 63 | maven-shade-plugin 64 | 3.2.4 65 | 66 | 67 | package 68 | 69 | shade 70 | 71 | 72 | 73 | 74 | plop.sipMain.Hic_main 75 | 76 | . 77 | 78 | 79 | 80 | 81 | 82 | *:* 83 | 84 | META-INF/*.SF 85 | META-INF/*.DSA 86 | META-INF/*.RSA 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | maven-compiler-plugin 96 | 97 | 7 98 | 7 99 | 100 | 101 | 102 | 103 | 104 | 105 | maven-shade-plugin 106 | 3.2.4 107 | 108 | 109 | maven-compiler-plugin 110 | 111 | 8 112 | 8 113 | 114 | 115 | 116 | 117 | 118 | 119 | imagej.public 120 | https://maven.imagej.net/content/groups/public 121 | 122 | 123 | gitlab-maven 124 | https://gitlab.com/api/v4/projects/22788291/packages/maven 125 | 126 | 127 | 128 | 129 | gitlab-maven 130 | Gitlab Repository 131 | https://gitlab.com/api/v4/projects/22788291/packages/maven 132 | 133 | 134 | gitlab-maven 135 | Gitlab Repository 136 | https://gitlab.com/api/v4/projects/22788291/packages/maven 137 | 138 | 139 | 140 | 7 141 | 7 142 | UTF-8 143 | UTF-8 144 | 145 | 146 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | SIP 8 | SIP 9 | 1.6.6 10 | 11 | 12 | 13 | 14 | 15 | sc.fiji 16 | imagescience 17 | 2.4.1 18 | 19 | 20 | fr.inra.ijpb 21 | MorphoLibJ_ 22 | 1.4.0 23 | 24 | 25 | 26 | 27 | net.imagej 28 | ij 29 | 1.54a 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | src/main/java/resources 41 | 42 | 43 | ${project.build.sourceDirectory} 44 | 45 | 46 | 47 | 48 | src/main/java/plop/resources 49 | 50 | 51 | ${project.build.testSourceDirectory} 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-assembly-plugin 59 | 3.0.0 60 | 61 | 62 | 63 | plop.sipMain.Hic_main 64 | 65 | 66 | 67 | jar-with-dependencies 68 | 69 | 70 | 71 | 72 | make-assembly 73 | package 74 | 75 | single 76 | 77 | 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-shade-plugin 83 | 3.2.4 84 | 85 | 86 | package 87 | 88 | shade 89 | 90 | 91 | 92 | 93 | 94 | plop.sipMain.Hic_main 95 | 96 | . 97 | 98 | 99 | 100 | 101 | 102 | 103 | *:* 104 | 105 | 106 | META-INF/*.SF 107 | META-INF/*.DSA 108 | META-INF/*.RSA 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-compiler-plugin 120 | 121 | 7 122 | 7 123 | 124 | 125 | 126 | 127 | 128 | 129 | org.apache.maven.plugins 130 | maven-shade-plugin 131 | 3.2.4 132 | 133 | 134 | org.apache.maven.plugins 135 | maven-compiler-plugin 136 | 137 | 8 138 | 8 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | axpoulet 148 | Axel Poulet 149 | pouletaxel@gmail.com 150 | iGReD 151 | 152 | architect 153 | developer 154 | 155 | +1 156 | 157 | 158 | 159 | 160 | 161 | imagej.public 162 | https://maven.imagej.net/content/groups/public 163 | 164 | 165 | gitlab-maven 166 | https://gitlab.com/api/v4/projects/22788291/packages/maven 167 | 168 | 169 | 170 | 171 | 172 | gitlab-maven 173 | Gitlab Repository 174 | https://gitlab.com/api/v4/projects/22788291/packages/maven 175 | 176 | 177 | gitlab-maven 178 | Gitlab Repository 179 | https://gitlab.com/api/v4/projects/22788291/packages/maven 180 | 181 | 182 | 183 | 184 | UTF-8 185 | UTF-8 186 | 7 187 | 7 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: plop.sipMain.Hic_main 3 | 4 | -------------------------------------------------------------------------------- /src/main/java/plop/gui/Progress.java: -------------------------------------------------------------------------------- 1 | package plop.gui; 2 | 3 | import java.awt.BorderLayout; 4 | import javax.swing.JFrame; 5 | import javax.swing.JProgressBar; 6 | 7 | /** 8 | * 9 | * @author axel poulet 10 | * 11 | *OppenClasseroom: 12 | *https://openclassrooms.com/fr/courses/26832-apprenez-a-programmer-en-java/25010-conteneurs-sliders-et-barres-de-progression 13 | */ 14 | public class Progress extends JFrame{ 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = 1L; 19 | public JProgressBar _bar; 20 | 21 | public Progress(){} 22 | 23 | public Progress(String title, int nbChromo){ 24 | this.setSize(400, 80); 25 | this.setTitle("*** "+title+" ***"); 26 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 27 | this.setLocationRelativeTo(null); 28 | this._bar = new JProgressBar(); 29 | this._bar.setMaximum(nbChromo); 30 | this._bar.setMinimum(0); 31 | this._bar.setStringPainted(true); 32 | this.getContentPane().add(this._bar, BorderLayout.CENTER); 33 | this.setVisible(true); 34 | } 35 | 36 | /** 37 | * 38 | * @param args 39 | */ 40 | public static void main(String[] args){ new Progress("plop/test", 22);} 41 | } -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/ProcessCoolerDumpData.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.Iterator; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.ThreadPoolExecutor; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import plop.gui.Progress; 12 | import plop.process.CoolerDumpData; 13 | import plop.utils.CoolerExpected; 14 | import plop.utils.SIPObject; 15 | 16 | /** 17 | * multi thread class dumping the data via juicertoolsbox.jar 18 | * and make file step by step 19 | * bed file: start1 start2 obs-expected distanceNormalizedValue 20 | * 21 | * @author axel poulet 22 | */ 23 | public class ProcessCoolerDumpData { 24 | 25 | /** progress bar if plop.gui is true*/ 26 | private Progress _p; 27 | 28 | /** 29 | * 30 | */ 31 | public ProcessCoolerDumpData(){ } 32 | 33 | /** 34 | * Run the process of cool file on different cpu, if all cpu are running, 35 | * take break else run a new one. 36 | * 37 | * @param coolTools path to coolTools 38 | * @param cooler path to coolTools 39 | * @param sip SIP object 40 | * @param coolFile input cool file 41 | * @param chrSize chromosome size file 42 | * @param nbCPU number of cpu use for the analysis 43 | * @throws InterruptedException test if the chr file exist or the cool file exist 44 | */ 45 | public void go(String coolTools, String cooler, 46 | SIPObject sip, String coolFile, 47 | HashMap chrSize,int nbCPU) 48 | throws InterruptedException { 49 | ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); 50 | Iterator chrName = chrSize.keySet().iterator(); 51 | File outDir = new File(sip.getOutputDir()); 52 | if (!outDir.exists()) 53 | outDir.mkdir(); 54 | 55 | ArrayList listFactor = sip.getListFactor(); 56 | for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { 57 | 58 | int res = sip.getResolution()*listFactor.get(indexFact); 59 | int matrixSize = sip.getMatrixSize()/listFactor.get(indexFact); 60 | CoolerExpected expected = new CoolerExpected(coolTools,coolFile, res, matrixSize, nbCPU); 61 | String resName = String.valueOf(res); 62 | resName = resName.replace("000", ""); 63 | resName = resName+"kb"; 64 | if(res < 1000){ 65 | resName = String.valueOf(res); 66 | resName = resName+"b"; 67 | } 68 | String expectedFile = sip.getOutputDir()+resName+".expected"; 69 | System.out.println("start "+expectedFile); 70 | expected.dumpExpected(expectedFile); 71 | System.out.println("!!!!!!! End "+expectedFile); 72 | } 73 | 74 | while(chrName.hasNext()){ 75 | String chr = chrName.next(); 76 | CoolerDumpData dumpData = new CoolerDumpData( cooler, coolFile); 77 | RunnableDumpDataCooler task = new RunnableDumpDataCooler(sip.getOutputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); 78 | executor.execute(task); 79 | } 80 | executor.shutdown(); 81 | int nb = 0; 82 | 83 | if(sip.isGui()){ 84 | _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); 85 | _p._bar.setValue(nb); 86 | } 87 | while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { 88 | if (nb != executor.getCompletedTaskCount()) { 89 | nb = (int) executor.getCompletedTaskCount(); 90 | if(sip.isGui()) _p._bar.setValue(nb); 91 | } 92 | } 93 | File folder = new File(sip.getOutputDir()); 94 | File[] listOfFiles = folder.listFiles(); 95 | for(int i = 0; i < listOfFiles.length;++i) { 96 | String name = listOfFiles[i].toString(); 97 | if(name.contains(".expected")) listOfFiles[i].delete(); 98 | } 99 | if(sip.isGui()) _p.dispose(); 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/ProcessDetectLoops.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | import java.io.File; 3 | import java.util.Iterator; 4 | 5 | import plop.gui.Progress; 6 | import plop.utils.SIPObject; 7 | 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.ThreadPoolExecutor; 10 | import java.util.concurrent.TimeUnit; 11 | 12 | 13 | /** 14 | * multi thread class 15 | * Construct all the RunnableDetectLoops Object and run them one by one with the available processors 16 | * 17 | * @author axel poulet 18 | * 19 | */ 20 | public class ProcessDetectLoops{ 21 | 22 | /**int: number of processors*/ 23 | static int _nbLance = 0; 24 | /** boolean: if true continue the process else take a break*/ 25 | static boolean _continuer; 26 | /** */ 27 | static int _indice = 0; 28 | /** progress bar if plop.gui is true*/ 29 | private Progress _p; 30 | 31 | /** */ 32 | public ProcessDetectLoops(){ } 33 | 34 | 35 | public void go(SIPObject sip,int nbCPU, boolean delImage, String resuFile,String resName) throws InterruptedException { 36 | ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); 37 | Iterator chrName = sip.getChrSizeHashMap().keySet().iterator(); 38 | if(sip.isProcessed()) { 39 | boolean isCool = isProcessedMcool(sip.getOutputDir()+resName+File.separator+"normVector"); 40 | //System.out.println(isCool); 41 | sip.setIsCooler(isCool); 42 | } 43 | while(chrName.hasNext()){ 44 | String chr = chrName.next(); 45 | if(sip.isCooler()){ 46 | RunnableDetectLoops task = new RunnableDetectLoops(chr, resuFile, sip, delImage); 47 | executor.execute(task); 48 | 49 | }else { 50 | String normFile = sip.getOutputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; 51 | if (sip.isProcessed()){ 52 | normFile = sip.getInputDir()+resName+File.separator+"normVector"+File.separator+chr+".norm"; 53 | } 54 | RunnableDetectLoops task = new RunnableDetectLoops(chr, resuFile, sip,normFile, delImage); 55 | executor.execute(task); 56 | } 57 | } 58 | executor.shutdown(); 59 | int nb = 0; 60 | if(sip.isGui()){ 61 | _p = new Progress(resName+" Loops Detection step",sip.getChrSizeHashMap().size()+1); 62 | _p._bar.setValue(nb); 63 | } 64 | while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { 65 | if (nb != executor.getCompletedTaskCount()) { 66 | nb = (int) executor.getCompletedTaskCount(); 67 | if(sip.isGui()) _p._bar.setValue(nb); 68 | } 69 | } 70 | if(sip.isGui()) _p.dispose(); 71 | 72 | } 73 | 74 | /** 75 | * 76 | * @param dirToTest folder to test 77 | * @return boolean 78 | */ 79 | private boolean isProcessedMcool(String dirToTest) { 80 | File test = new File (dirToTest); 81 | return !test.exists(); 82 | } 83 | } -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/ProcessHicDumpData.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.concurrent.Executors; 7 | import java.util.concurrent.ThreadPoolExecutor; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import plop.gui.Progress; 11 | import plop.process.DumpData; 12 | import plop.utils.SIPObject; 13 | 14 | 15 | /** 16 | * multi thread class dumping the data via cooler 17 | * and make file step by step 18 | * bed file: start1 start2 obs-expected distanceNormalizedValue 19 | * 20 | * @author axel poulet 21 | * 22 | */ 23 | public class ProcessHicDumpData{ 24 | /** progress bar if plop.gui is true*/ 25 | private Progress _p; 26 | 27 | /** 28 | * 29 | */ 30 | public ProcessHicDumpData(){ } 31 | 32 | /** 33 | * * run the processing on different cpu, if all cpu are running, take break else run a new one. 34 | * 35 | * @param hicFile path to the hic file 36 | * @param sip SIP object storing the parameters 37 | * @param chrSize path to the chromosome file 38 | * @param juiceBoxTools path to juicer tool 39 | * @param normJuiceBox Normalization method use for the dumped data 40 | * @param nbCPU number of cpu use for the analysis 41 | * @throws InterruptedException if input file doesn't exist throw an exception 42 | */ 43 | public void go(String hicFile, SIPObject sip, HashMap chrSize, 44 | String juiceBoxTools, String normJuiceBox,int nbCPU) throws InterruptedException { 45 | ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(nbCPU); 46 | Iterator chrName = chrSize.keySet().iterator(); 47 | File outDir = new File(sip.getOutputDir()); 48 | if (!outDir.exists()) 49 | outDir.mkdir(); 50 | while(chrName.hasNext()){ 51 | String chr = chrName.next(); 52 | DumpData dumpData = new DumpData(juiceBoxTools, hicFile, normJuiceBox); 53 | RunnableDumpDataHiC task = new RunnableDumpDataHiC(sip.getOutputDir(), chr, chrSize.get(chr), dumpData, sip.getResolution(), sip.getMatrixSize(), sip.getStep(), sip.getListFactor()); 54 | executor.execute(task); 55 | } 56 | executor.shutdown(); 57 | int nb = 0; 58 | 59 | if(sip.isGui()){ 60 | _p = new Progress("Loop Detection step",sip.getChrSizeHashMap().size()+1); 61 | _p._bar.setValue(nb); 62 | } 63 | while (!executor.awaitTermination(30, TimeUnit.SECONDS)) { 64 | if (nb != executor.getCompletedTaskCount()) { 65 | nb = (int) executor.getCompletedTaskCount(); 66 | if(sip.isGui()) _p._bar.setValue(nb); 67 | } 68 | } 69 | if(sip.isGui()) _p.dispose(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/RunnableDetectLoops.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | import plop.process.CallLoops; 3 | import plop.utils.SIPObject; 4 | import plop.utils.Loop; 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.HashMap; 8 | 9 | /** 10 | * Runnable class for loops detection 11 | * 12 | * @author axel poulet 13 | * 14 | */ 15 | public class RunnableDetectLoops extends Thread implements Runnable{ 16 | /** SIP object containing all the parameter for the loops detection*/ 17 | private SIPObject _sip; 18 | /** CallLoops object */ 19 | private CallLoops _callLoops; 20 | /** String results file*/ 21 | private String _resuFile; 22 | /** String name of the chr*/ 23 | private String _chr; 24 | /** String name of the chr*/ 25 | private boolean _delImages = true; 26 | /** norn vector table for the chr of interest*/ 27 | private HashMap _normVector = new HashMap (); 28 | /** */ 29 | private String _normVectorFile; 30 | 31 | 32 | 33 | /** 34 | * Constructor, initialize all the variables of interest 35 | * 36 | * @param chr chromosome name 37 | * @param resuFile path to the result file 38 | * @param sip SIP object 39 | * @param normVectorFile path to the normalise vector for the chromosome of interest 40 | * @param delFile true => del tif file 41 | */ 42 | public RunnableDetectLoops (String chr, String resuFile, SIPObject sip, String normVectorFile, boolean delFile){ 43 | this._sip = sip; 44 | this._callLoops = new CallLoops(sip); 45 | this._chr= chr; 46 | this._resuFile = resuFile; 47 | this._normVector = sip.getNormValueFilter(normVectorFile); 48 | this._delImages = delFile; 49 | this._normVectorFile = normVectorFile; 50 | } 51 | 52 | /** 53 | * 54 | * @param chr chromosome name 55 | * @param resuFile path to the result file 56 | * @param sip SIP object 57 | * @param delFile true => del tif file 58 | */ 59 | public RunnableDetectLoops (String chr, String resuFile, SIPObject sip, boolean delFile){ 60 | this._sip = sip; 61 | this._callLoops = new CallLoops(sip); 62 | this._chr= chr; 63 | this._resuFile = resuFile; 64 | this._delImages = delFile; 65 | } 66 | 67 | /** 68 | * Run all the process for loops detection by chr using the objet CallLoops and then save loops in 69 | * txt file with SIPObject via the method saveFile 70 | * 71 | */ 72 | public void run(){ 73 | String resName = String.valueOf(this._sip.getResolution()); 74 | resName = resName.replace("000", "")+"kb"; 75 | if(this._sip.getResolution() < 1000){ 76 | resName = String.valueOf(this._sip.getResolution()); 77 | resName = resName+"b"; 78 | } 79 | String dir = this._sip.getOutputDir()+resName+File.separator+_chr+File.separator; 80 | HashMap data = new HashMap (); 81 | if (this._sip.isProcessed()) dir = this._sip.getInputDir()+resName+File.separator+this._chr+File.separator; 82 | try { 83 | File[] listOfFiles = _sip.fillList(dir); 84 | System.out.println(dir); 85 | if (listOfFiles.length == 0) System.out.println("!!!!!!!!!! dumped directory of chromosome"+this._chr+" empty"); 86 | else{ 87 | File file = new File(this._resuFile); 88 | if(!_sip.isCooler()) { 89 | System.out.println(_normVectorFile +"normVector end loading file: "+_chr+".norm "+resName); 90 | } 91 | data = this._callLoops.detectLoops(listOfFiles,this._chr,this._normVector); 92 | synchronized(this) { 93 | if (file.length() == 0) _sip.saveFile(this._resuFile,data,false); 94 | else this._sip.saveFile(this._resuFile,data, true); 95 | } 96 | listOfFiles = _sip.fillList(dir); 97 | if(_delImages){ 98 | System.out.println("Deleting image file for "+_chr); 99 | for(int i = 0; i < listOfFiles.length;++i) { 100 | String name = listOfFiles[i].toString(); 101 | if(name.contains(".tif")) listOfFiles[i].delete(); 102 | } 103 | } 104 | } 105 | } catch (IOException e1) { e1.printStackTrace();} 106 | System.gc(); 107 | } 108 | } -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/RunnableDumpDataCooler.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | 7 | import plop.process.CoolerDumpData; 8 | import plop.utils.CoolerExpected; 9 | 10 | /** 11 | * 12 | * @author axel poulet 13 | * 14 | */ 15 | public class RunnableDumpDataCooler extends Thread implements Runnable{ 16 | /**String: path where save the dump data */ 17 | private String _outdir =""; 18 | /**String: name of the chr*/ 19 | private String _chrName = ""; 20 | /**int: chr size */ 21 | private int _chrSize = 0; 22 | /** DumpData object run juicertoolbox.jar*/ 23 | private CoolerDumpData _coolerDumpData; 24 | /**int: bin resolution*/ 25 | private int _res = 0; 26 | /**int: image Size */ 27 | private int _matrixSize = 0; 28 | /**int: size of the step to run a chr */ 29 | private int _step = 0; 30 | /** */ 31 | private ArrayList _listFactor; 32 | 33 | 34 | /** 35 | * Constructor, initialize the variables of interest 36 | * 37 | * @param outDir path to output folder 38 | * @param chrName chromosome name 39 | * @param chrSize chromosome size 40 | * @param dumpData DumpData object 41 | * @param res resolution (bin size) 42 | * @param matrixSize image size 43 | * @param step ster of teh analysis 44 | */ 45 | public RunnableDumpDataCooler (String outDir, String chrName, 46 | int chrSize, CoolerDumpData dumpData, 47 | int res, int matrixSize, int step, 48 | ArrayList listFactor){ 49 | this._outdir = outDir; 50 | this._chrName = chrName; 51 | this._chrSize = chrSize; 52 | this._res = res; 53 | this._matrixSize = matrixSize; 54 | this._step = step; 55 | this._coolerDumpData = dumpData; 56 | this._listFactor = listFactor; 57 | } 58 | 59 | /** 60 | * Dump teh data by chr 61 | */ 62 | public void run(){ 63 | boolean coolerTools; 64 | for(int indexFact = 0; indexFact < this._listFactor.size(); ++indexFact) { 65 | int res = _res*this._listFactor.get(indexFact); 66 | int matrixSize = _matrixSize/this._listFactor.get(indexFact); 67 | _step = matrixSize/2; 68 | String resName = String.valueOf(res); 69 | resName = resName.replace("000", ""); 70 | resName = resName+"kb"; 71 | if(res < 1000){ 72 | resName = String.valueOf(res); 73 | resName = resName+"b"; 74 | } 75 | String expectedFile = this._outdir+File.separator+resName+".expected"; 76 | CoolerExpected expected = new CoolerExpected(expectedFile, matrixSize); 77 | try { 78 | expected.parseExpectedFile(); 79 | ArrayList lExpected = expected.getExpected(_chrName); 80 | _coolerDumpData.setExpected(lExpected); 81 | String outdir = this._outdir+File.separator+resName+File.separator+this._chrName+File.separator; 82 | File file = new File(outdir); 83 | if (!file.exists()) 84 | file.mkdirs(); 85 | int step = this._step*res; 86 | int j = matrixSize*res; 87 | String name = outdir+this._chrName+"_0_"+j+".txt"; 88 | if (!file.exists()) 89 | file.mkdir(); 90 | System.out.println("start dump "+this._chrName+" size "+this._chrSize+" res "+ resName); 91 | if(j > this._chrSize) j = this._chrSize; 92 | for(int i = 0 ; j-1 <= this._chrSize; i+=step,j+=step){ 93 | int end =j-1; 94 | String dump = this._chrName+":"+i+"-"+end; 95 | name = outdir+this._chrName+"_"+i+"_"+end+".txt"; 96 | System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ resName); 97 | coolerTools = this._coolerDumpData.dumpObservedMExpected(dump,name,res); 98 | if (!coolerTools){ 99 | System.out.print(dump+" "+"\n"+coolerTools+"\n"); 100 | System.exit(0); 101 | } 102 | if(j+step > this._chrSize && j < this._chrSize){ 103 | j= this._chrSize; 104 | i+=step; 105 | dump = this._chrName+":"+i+"-"+j; 106 | name = outdir+this._chrName+"_"+i+"_"+j+".txt"; 107 | System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ resName); 108 | coolerTools = this._coolerDumpData.dumpObservedMExpected(dump,name,res); 109 | if (!coolerTools){ 110 | System.out.print(dump+" "+"\n"+coolerTools+"\n"); 111 | System.exit(0); 112 | } 113 | } 114 | } 115 | } catch (IOException e) { e.printStackTrace();} 116 | System.out.println("##### End dump "+this._chrName+" "+resName); 117 | System.gc(); 118 | } 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/plop/multiProcesing/RunnableDumpDataHiC.java: -------------------------------------------------------------------------------- 1 | package plop.multiProcesing; 2 | import plop.process.DumpData; 3 | 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Runnable class dumping the raw data set via juicer tool. 10 | * The data are dumped by chr and by windows size, with user's parameters choose. 11 | * Two different files will be created one for the raw value with the observed minus expected value and also with the 12 | * distance normalized value. 13 | * Then the "norm" vector is also dump in another folder. 14 | * 15 | * @author axel poulet 16 | * 17 | */ 18 | public class RunnableDumpDataHiC extends Thread implements Runnable{ 19 | /**String: path where save the dump data */ 20 | private String _outDir =""; 21 | /**String: name of the chr*/ 22 | private String _chrName = ""; 23 | /**int: chr size */ 24 | private int _chrSize = 0; 25 | /** DumpData object run juicertoolbox.jar*/ 26 | private DumpData _dumpData; 27 | /**int: bin resolution*/ 28 | private int _res = 0; 29 | /**int: image Size */ 30 | private int _matrixSize = 0; 31 | /**int: size of the step to run a chr */ 32 | private int _step = 0; 33 | /** */ 34 | private ArrayList _listFactor; 35 | 36 | 37 | /** 38 | * Constructor, initialize the variables of interest 39 | * 40 | * @param outDir output folder path 41 | * @param chrName chromosome name 42 | * @param chrSize chromosome size 43 | * @param dumpData DumpData object 44 | * @param res resolution (size of the bin) 45 | * @param matrixSize number of pixel in the image 46 | * @param step step to go through the genome 47 | */ 48 | public RunnableDumpDataHiC (String outDir, String chrName, int chrSize, DumpData dumpData,int res, int matrixSize, int step, ArrayList listFactor){ 49 | this._outDir = outDir; 50 | this._chrName = chrName; 51 | this._chrSize = chrSize; 52 | this._res = res; 53 | this._matrixSize = matrixSize; 54 | this._step = step; 55 | this._dumpData = dumpData; 56 | this._listFactor = listFactor; 57 | } 58 | 59 | /** 60 | * Dump teh data by chr 61 | */ 62 | public void run(){ 63 | boolean juicerTools; 64 | for(int indexFact = 0; indexFact < this._listFactor.size(); ++indexFact) { 65 | int res = _res*this._listFactor.get(indexFact); 66 | int matrixSize = _matrixSize/this._listFactor.get(indexFact); 67 | _step = matrixSize/2; 68 | String resName = String.valueOf(res); 69 | resName = resName.replace("000", ""); 70 | resName = resName+"kb"; 71 | if(res < 1000){ 72 | resName = String.valueOf(res); 73 | resName = resName+"b"; 74 | } 75 | String outdir = this._outDir +resName+File.separator+this._chrName+File.separator; 76 | File file = new File(outdir); 77 | if (!file.exists()) 78 | file.mkdirs(); 79 | int step = this._step*res; 80 | int j = matrixSize*res; 81 | String test = this._chrName+":0:"+j; 82 | String name = outdir+this._chrName+"_0_"+j+".txt"; 83 | this._dumpData.getExpected(test,name,res); 84 | String normOutput = this._outDir +resName+File.separator+"normVector"; 85 | file = new File(normOutput); 86 | if (!file.exists()) 87 | file.mkdir(); 88 | try { 89 | this._dumpData.getNormVector(this._chrName,normOutput+File.separator+this._chrName+".norm",res); 90 | //System.out.println("start dump "+this._chrName+" size "+this._chrSize+" res "+ resName); 91 | if(j > this._chrSize) j = this._chrSize; 92 | for(int i = 0 ; j-1 <= this._chrSize; i+=step,j+=step){ 93 | int end =j-1; 94 | String dump = this._chrName+":"+i+":"+end; 95 | name = outdir+this._chrName+"_"+i+"_"+end+".txt"; 96 | System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ resName); 97 | juicerTools = this._dumpData.dumpObservedMExpected(dump,name,res); 98 | if(j+step > this._chrSize && j < this._chrSize){ 99 | j= this._chrSize; 100 | i+=step; 101 | dump = this._chrName+":"+i+":"+j; 102 | name = outdir+this._chrName+"_"+i+"_"+j+".txt"; 103 | System.out.println("start dump "+this._chrName+" size "+this._chrSize+" dump "+dump+" res "+ resName); 104 | juicerTools = this._dumpData.dumpObservedMExpected(dump,name,res); 105 | 106 | } 107 | } 108 | System.out.println("##### End dump "+this._chrName+" "+resName); 109 | } catch (IOException | InterruptedException e) { e.printStackTrace(); } 110 | } 111 | System.gc(); 112 | } 113 | } -------------------------------------------------------------------------------- /src/main/java/plop/process/CallLoops.java: -------------------------------------------------------------------------------- 1 | package plop.process; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.HashMap; 6 | 7 | import ij.IJ; 8 | import ij.ImagePlus; 9 | import ij.io.FileSaver; 10 | import inra.ijpb.morphology.Morphology; 11 | import inra.ijpb.morphology.Strel; 12 | import plop.utils.CoordinatesCorrection; 13 | import plop.utils.FilterLoops; 14 | import plop.utils.FindMaxima; 15 | import plop.utils.SIPObject; 16 | import plop.utils.ImageProcessingMethod; 17 | import plop.utils.Loop; 18 | import plop.utils.PeakAnalysisScore; 19 | 20 | /** 21 | * Class with all the methods to call the regional maxima in the images and filter and write the output loops file list 22 | * 23 | * @author axel poulet 24 | * 25 | */ 26 | public class CallLoops { 27 | 28 | /** Strength of the gaussian filter*/ 29 | private double _gauss; 30 | /** Strength of the min filter*/ 31 | private double _min; 32 | /** Strength of the max filter*/ 33 | private double _max; 34 | /** % of saturated pixel after enhance contrast*/ 35 | private double _saturatedPixel; 36 | /** Image size*/ 37 | private int _matrixSize = 0; 38 | /** Resolution of the bin dump in base*/ 39 | private int _resolution; 40 | /** Threshold for the maxima detection*/ 41 | private int _thresholdMaxima; 42 | /** Diage size to removed maxima close to diagonal*/ 43 | private int _diagSize; 44 | /** Size of the step to process each chr (step = matrixSize/2)*/ 45 | private int _step; 46 | /** Number of pixel = 0 allowed around the loop*/ 47 | private int _nbZero = -1; 48 | /** structuring element for the MM method used (MorpholibJ)*/ 49 | private Strel _strel = Strel.Shape.SQUARE.fromRadius(40); 50 | /** image background value*/ 51 | private float _backgroudValue = (float) 0.25; 52 | private boolean _isCooler = false; 53 | 54 | /** 55 | * Constructor 56 | * 57 | * @param sip SIPObject 58 | */ 59 | public CallLoops(SIPObject sip){ 60 | this._gauss = sip.getGauss(); 61 | this._min = sip.getMin(); 62 | this._max= sip.getMax(); 63 | this._saturatedPixel = sip.getSaturatedPixel(); 64 | this._matrixSize = sip.getMatrixSize(); 65 | this._resolution = sip.getResolution(); 66 | this._thresholdMaxima = sip.getThresholdMaxima(); 67 | this._diagSize = sip.getDiagSize(); 68 | this._step = sip.getStep(); 69 | this._nbZero = sip.getNbZero(); 70 | this._isCooler = sip.isCooler(); 71 | } 72 | 73 | /** 74 | * Detect loops method, detect the loops at two different resolution, initial resolution + 2 folds bigger 75 | * call the loops first in the smaller resolution then making image with bigger resolution and fill no Zero list 76 | * Make and save image at two different resolution (m_resolution and m_resolution*2) 77 | * If there is a lot pixel at zero in the images adapt the threshold for the maxima detection. 78 | * @param fileList list of file to process 79 | * @param chr chromosome name 80 | * @param normVector normalized vector of the chromosome of interest 81 | * @return HashMap of loop 82 | * @throws IOException throw an exception 83 | */ 84 | public HashMap detectLoops(File[] fileList, String chr, 85 | HashMap normVector) 86 | throws IOException{ 87 | CoordinatesCorrection coord = new CoordinatesCorrection(); 88 | HashMap hLoop= new HashMap(); 89 | FilterLoops filterLoops = new FilterLoops(this._resolution); 90 | for(int i = 0; i < fileList.length; ++i){ 91 | if(fileList[i].toString().contains(".txt")){ 92 | TupleFileToImage tuple = new TupleFileToImage(fileList[i].toString(),this._matrixSize,this._resolution); 93 | String[] tFile = fileList[i].toString().split("_"); 94 | int numImage = Integer.parseInt(tFile[tFile.length-2])/(this._step*_resolution); 95 | System.out.println(numImage+"\t"+fileList[i]); 96 | ImagePlus imgRaw = makeImage(tuple); 97 | ImagePlus imgFilter = imgRaw.duplicate(); 98 | tuple.correctImage(imgFilter); 99 | ImageProcessingMethod m = new ImageProcessingMethod(imgFilter,this._min,this._max,this._gauss); 100 | imageProcessing(imgFilter,fileList[i].toString(), m); 101 | imgRaw.getTitle().replaceAll(".tif", "_N.tif"); 102 | ImagePlus imgNorm = IJ.openImage(imgRaw.getTitle().replaceAll(".tif", "_N.tif")); 103 | int thresh = this._thresholdMaxima; 104 | double pixelPercent = (double) (100 * tuple.getNbZero()) /(this._matrixSize*this._matrixSize); 105 | if(pixelPercent < 7) 106 | thresh = _thresholdMaxima/5; 107 | FindMaxima findLoop = new FindMaxima(imgNorm, imgFilter, chr, thresh, this._diagSize, this._resolution); 108 | HashMap temp = findLoop.findLoop(numImage, this._nbZero,imgRaw, this._backgroudValue); 109 | PeakAnalysisScore pas = new PeakAnalysisScore(imgNorm,temp); 110 | pas.computeScore(); 111 | temp = filterLoops.removedBadLoops(temp); 112 | coord.setData(hLoop); 113 | coord.imageToGenomeCoordinate(temp, numImage,_step); 114 | hLoop = coord.getData(); 115 | } 116 | } 117 | if(_isCooler) 118 | hLoop = filterLoops.removedLoopCloseToWhiteStrip(hLoop); 119 | else 120 | hLoop = filterLoops.removedLoopCloseToWhiteStrip(hLoop,normVector); 121 | 122 | System.out.println("####### End loops detection for chr "+ chr +"\t"+hLoop.size()+" loops before the FDR filter"); 123 | return hLoop; 124 | } 125 | 126 | 127 | 128 | /** 129 | * Image processing method 130 | * @param imgFilter ImagePlus to correct 131 | * @param fileName Strin file name 132 | * @param pm ProcessMethod object 133 | */ 134 | private void imageProcessing(ImagePlus imgFilter, String fileName, ImageProcessingMethod pm){ 135 | pm.enhanceContrast(this._saturatedPixel); 136 | pm.runGaussian(); 137 | imgFilter.setProcessor(Morphology.whiteTopHat(imgFilter.getProcessor(), _strel)); 138 | pm.setImg(imgFilter); 139 | pm.runGaussian(); 140 | pm.topHat(this._min, this._max); 141 | if(fileName.contains(".tif")) 142 | saveFile(imgFilter, fileName.replaceAll(".tif", "_processed.tif")); 143 | else 144 | saveFile(imgFilter, fileName.replaceAll(".txt", "_processed.tif")); 145 | } 146 | 147 | 148 | /** 149 | * Make Image 150 | * 151 | * @param readFile file to make the image 152 | * @return ImagePlus 153 | */ 154 | private ImagePlus makeImage(TupleFileToImage readFile){ 155 | String file = readFile.getInputFile(); 156 | readFile.readTupleFile(); 157 | saveFile(readFile.getNormImage(),file.replaceAll(".txt", "_N.tif")); 158 | ImagePlus imageOutput = readFile.getRawImage(); 159 | imageOutput.setTitle(file.replaceAll(".txt", ".tif")); 160 | saveFile(imageOutput,file.replaceAll(".txt", ".tif")); 161 | return imageOutput; 162 | } 163 | 164 | /** 165 | * Save the image file 166 | * 167 | * @param imagePlusInput image to save 168 | * @param pathFile path to save the image 169 | */ 170 | public void saveFile (ImagePlus imagePlusInput, String pathFile){ 171 | FileSaver fileSaver = new FileSaver(imagePlusInput); 172 | fileSaver.saveAsTiff(pathFile); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/main/java/plop/process/CoolerDumpData.java: -------------------------------------------------------------------------------- 1 | package plop.process; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | import java.nio.charset.StandardCharsets; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | import java.util.ArrayList; 14 | 15 | public class CoolerDumpData { 16 | 17 | 18 | /** String to stock the error if need of juicerbox_tools*/ 19 | private String _logError = ""; 20 | /** String for the log*/ 21 | private String _log = ""; 22 | /** path to the hic file or url link*/ 23 | private String _coolFile = ""; 24 | /** List of double to stock the expected vector*/ 25 | private ArrayList _lExpected = new ArrayList(); 26 | 27 | private String _cooler = ""; 28 | 29 | 30 | /** 31 | * Constructor of this class to initialize the different variables 32 | * 33 | * @param cooler 34 | * @param coolFile 35 | */ 36 | public CoolerDumpData(String cooler, String coolFile) { 37 | this._coolFile = coolFile; 38 | this._cooler = cooler; 39 | } 40 | /** 41 | * Method to dump the oMe matrix 42 | * 43 | * @param chr: String for the name of teh chromosome 44 | * @param output: String path of the output 45 | * @return 46 | * @throws IOException 47 | */ 48 | public boolean dumpObservedMExpected(String chr, String output, int resolution) throws IOException{ 49 | int exitValue=1; 50 | Runtime runtime = Runtime.getRuntime(); 51 | String obs = output.replaceAll(".txt", "_obs.txt"); 52 | try { 53 | String cool = this._coolFile+"::/resolutions/"+resolution; 54 | String line = this._cooler+" dump "+cool+" --balanced -r "+chr+" -r2 "+ chr+" -o "+obs +" --join --na-rep NaN"; 55 | //System.out.println(line); 56 | this._log = this._log+"\n"+obs+"\t"+line; 57 | Process process = runtime.exec(line); 58 | 59 | new ReturnFlux(process.getInputStream()).start(); 60 | new ReturnFlux(process.getErrorStream()).start(); 61 | exitValue=process.waitFor(); 62 | } 63 | catch (IOException | InterruptedException e) { 64 | e.printStackTrace(); 65 | } 66 | if(_logError!=""){ 67 | System.out.println(_logError); 68 | System.exit(0); 69 | } 70 | observedMExpected(obs,output,resolution); 71 | return exitValue==0; 72 | } 73 | 74 | /** 75 | * Compute the value observed-expected, the norm vector and also the distance normalized value 76 | * and write the output file the "tuple": x y oMe DistanceNormalized. 77 | * this method are only for the intra chromosomal interaction. 78 | * 79 | * @param obs: String path with the file of the observed value 80 | * @param chr: name of the chr 81 | * @throws IOException 82 | */ 83 | private void observedMExpected(String obs, String chr, int resolution) throws IOException{ 84 | BufferedReader br = Files.newBufferedReader(Paths.get(obs), StandardCharsets.UTF_8); 85 | BufferedWriter writer = new BufferedWriter(new FileWriter(new File(chr))); 86 | //chrom1 start1 end1 chrom2 start2 end2 count balanced 87 | //chr21 5030000 5035000 chr21 5030000 5035000 83 0.151261 88 | for (String line = null; (line = br.readLine()) != null;){ 89 | String [] tline = line.split("\t"); 90 | int dist = Math.abs((Integer.parseInt(tline[1])-Integer.parseInt(tline[4]))/resolution); 91 | if(!tline[7].equals("NaN")){ 92 | double normalizedValue = ((Double.parseDouble(tline[7])*10000+1)/(this._lExpected.get(dist)*10000+1)); 93 | double oMe = (Double.parseDouble(tline[7])*1000-this._lExpected.get(dist)*1000); 94 | writer.write(tline[1]+"\t"+tline[4]+"\t"+oMe+"\t"+normalizedValue+"\n"); 95 | } 96 | } 97 | File file = new File(obs); 98 | file.delete(); 99 | writer.close(); 100 | br.close(); 101 | } 102 | 103 | public void setExpected( ArrayList lExpected) {this._lExpected = lExpected;} 104 | 105 | /** 106 | * getter of the logerror file if necessary 107 | * 108 | * @return return the String with the error 109 | */ 110 | public String getLogError(){ return this._logError;} 111 | 112 | /** 113 | * getter of the log info if necessary 114 | * @return return a String with the log info 115 | */ 116 | public String getLog(){ return this._log;} 117 | /** 118 | * Class to run command line in java 119 | * @author axel poulet 120 | * 121 | */ 122 | public class ReturnFlux extends Thread { 123 | 124 | /** Flux to redirect */ 125 | private InputStream _flux; 126 | 127 | /** 128 | * Constructor of ReturnFlux 129 | * @param flux 130 | * flux to redirect 131 | */ 132 | public ReturnFlux(InputStream flux){this._flux = flux; } 133 | 134 | /** 135 | * 136 | */ 137 | public void run(){ 138 | try { 139 | InputStreamReader reader = new InputStreamReader(this._flux); 140 | BufferedReader br = new BufferedReader(reader); 141 | String line=null; 142 | while ( (line = br.readLine()) != null) { 143 | if(!line.contains("WARN")) _logError = _logError+line+"\n"; 144 | } 145 | } 146 | catch (IOException ioe){ 147 | ioe.printStackTrace(); 148 | } 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/main/java/plop/process/DumpData.java: -------------------------------------------------------------------------------- 1 | package plop.process; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | import java.nio.charset.StandardCharsets; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Class aims to dump the data of the hic file. this classe need juicer_toolbox.jar to obtain the raw data and does the 17 | * 2D images which will represent the HiC matrix. If some error is detected a file log is created for that. At the end 18 | * this class a file by step is created (coordinate1 coordinate2 hic_value). The file created if the oMe option is 19 | * used the subtraction Observed-Expected is done to obtain the value of the interaction between two bins. If observed 20 | * is used the value will be the observed. You can also use the option of the normalisation for the hic matrix, 21 | * the different normalisations available are these one available in juicertoolbox.jar (...). 22 | * Example of command line use: 23 | * dump observed KR ... 1:20480000:40960000 1:20480000:40960000 BP 10000 combined_10Kb.txt 24 | * Neva C. Durand, Muhammad S. Shamim, Ido Machol, Suhas S. P. Rao, Miriam H. Huntley, Eric S. Lander, 25 | * and Erez Lieberman Aiden. "Juicer provides one-click system for analyzing loop-resolution Hi-C experiments." 26 | * Cell Systems 3(1), 2016. 27 | * 28 | * @author axel poulet 29 | * 30 | */ 31 | public class DumpData { 32 | /** String to stock the error of juicertoolbox*/ 33 | private String _logError = ""; 34 | /** String for the log*/ 35 | private String _log = ""; 36 | /** String => normalisation to dump the data (NONE, KR, VC, VC_SQRT or NONE)*/ 37 | private String _normalisation= ""; 38 | /** path to the hic file or url link*/ 39 | private String _hicFile = ""; 40 | /** path to juicer_toolsbox.jars*/ 41 | private String _juiceBoxTools = ""; 42 | /** List of doucle to stock the expected vector*/ 43 | private ArrayList _lExpected = new ArrayList(); 44 | 45 | 46 | 47 | /** 48 | * Constructor of this class to iniatilise the different variables 49 | * 50 | * @param juiceboxTools: String: path of juicertoolsBox 51 | * @param hicFile: String: path to the HiC file 52 | * @param norm: String: type of normalisation 53 | */ 54 | public DumpData(String juiceboxTools,String hicFile, String norm) { 55 | this._juiceBoxTools = juiceboxTools; 56 | this._normalisation = norm; 57 | this._hicFile = hicFile; 58 | } 59 | 60 | /** 61 | * Method to dump the oMe matrix 62 | * 63 | * @param chr: String for the name of teh chromosome 64 | * @param output: String path of the output 65 | * @return 66 | * @throws IOException 67 | */ 68 | public boolean dumpObservedMExpected(String chr, String output, int resolution) throws IOException{ 69 | int exitValue=1; 70 | Runtime runtime = Runtime.getRuntime(); 71 | String obs = output.replaceAll(".txt", "_obs.txt"); 72 | try { 73 | String line = "java"+" -jar "+this._juiceBoxTools+ 74 | " dump observed "+this._normalisation+" "+ 75 | this._hicFile+" "+chr+" "+chr+" BP "+ 76 | resolution+" "+obs; 77 | //System.out.println(line); 78 | this._log = this._log+"\n"+obs+"\t"+line; 79 | Process process = runtime.exec(line); 80 | new ReturnFlux(process.getInputStream()).start(); 81 | new ReturnFlux(process.getErrorStream()).start(); 82 | exitValue=process.waitFor(); 83 | } 84 | catch (IOException | InterruptedException e) { e.printStackTrace();} 85 | observedMExpected(obs,output,resolution); 86 | if(_logError.contains("Exception")) { 87 | System.out.println(_logError); 88 | System.exit(0); 89 | } 90 | return exitValue==0; 91 | } 92 | 93 | /** 94 | * Compute the value observed-expected, the norm vector and also the distance normalized value 95 | * and write the output file the "tuple": x y oMe DistanceNormalized. 96 | * this method are only for the intra chromosomal interaction. 97 | * @param obs: String path with the file of the observed value 98 | * @param chr: name of the chr 99 | * @throws IOException 100 | */ 101 | private void observedMExpected(String obs, String chr, int resolution) throws IOException{ 102 | BufferedReader br = Files.newBufferedReader(Paths.get(obs), StandardCharsets.UTF_8); 103 | BufferedWriter writer = new BufferedWriter(new FileWriter(new File(chr))); 104 | for (String line = null; (line = br.readLine()) != null;){ 105 | String [] tLine = line.split("\t"); 106 | int dist = Math.abs((Integer.parseInt(tLine[0])-Integer.parseInt(tLine[1]))/resolution); 107 | if(!tLine[2].equals("NaN")){ 108 | double normalizedValue = (Double.parseDouble(tLine[2])+1)/(this._lExpected.get(dist)+1); 109 | double oMe = Double.parseDouble(tLine[2])-this._lExpected.get(dist); 110 | writer.write(tLine[0]+"\t"+tLine[1]+"\t"+oMe+"\t"+normalizedValue+"\n"); 111 | } 112 | } 113 | File file = new File(obs); 114 | file.delete(); 115 | writer.close(); 116 | br.close(); 117 | } 118 | 119 | 120 | /** 121 | * getter of the logerror file if necessary 122 | * @return return the String with the error 123 | */ 124 | public String getLogError(){ return this._logError;} 125 | 126 | /** 127 | * getter of the log info if necessary 128 | * @return return a String with the log info 129 | */ 130 | public String getLog(){ return this._log;} 131 | 132 | /** 133 | * getter of the expected matrix. 134 | 135 | * @param chr: String name of the chromosme 136 | * @param output: path to the output 137 | * @return 138 | */ 139 | public boolean getExpected(String chr,String output,int resolution){ 140 | int exitValue=1; 141 | Runtime runtime = Runtime.getRuntime(); 142 | String expected = output.replaceAll(".txt", "_expected.txt"); 143 | String cmd = "java"+" -jar "+this._juiceBoxTools+" dump expected "+this._normalisation+" "+this._hicFile+" "+chr+" BP "+resolution+" "+expected; 144 | System.out.println("dump expected "+this._normalisation+" "+this._hicFile+" "+chr); 145 | this._log = this._log+"\n"+expected+"\t"+cmd; 146 | Process process; 147 | try { 148 | process = runtime.exec(cmd); 149 | 150 | new ReturnFlux(process.getInputStream()).start(); 151 | new ReturnFlux(process.getErrorStream()).start(); 152 | exitValue=process.waitFor(); 153 | 154 | BufferedReader br = Files.newBufferedReader(Paths.get(expected), StandardCharsets.UTF_8); 155 | for (String line = null; (line = br.readLine()) != null;) 156 | this._lExpected.add(Double.parseDouble(line)); 157 | br.close(); 158 | File file = new File(expected); 159 | file.delete(); 160 | 161 | } catch (IOException | InterruptedException e) { 162 | e.printStackTrace(); 163 | } 164 | if(_logError.contains("Exception")){ 165 | System.out.println(_logError); 166 | System.exit(0); 167 | } 168 | return exitValue==0; 169 | } 170 | 171 | /** 172 | * getter of the expected matrix. 173 | * 174 | * @param chr: String name of the chromosme 175 | * @param output: path to the output 176 | * @return 177 | * @throws IOException 178 | * @throws InterruptedException 179 | */ 180 | public boolean getNormVector(String chr,String output,int resolution) throws IOException, InterruptedException{ 181 | int exitValue=1; 182 | Runtime runtime = Runtime.getRuntime(); 183 | String cmd = "java"+" -jar "+this._juiceBoxTools+" dump norm VC "+this._hicFile+" "+chr+" BP "+resolution+" "+output; 184 | this._log = this._log+"\n"+output+"\t"+cmd; 185 | Process process = runtime.exec(cmd); 186 | new ReturnFlux(process.getInputStream()).start(); 187 | new ReturnFlux(process.getErrorStream()).start(); 188 | process.getOutputStream(); 189 | exitValue=process.waitFor(); 190 | if(_logError!="" && !_logError.contains("Exception")){ 191 | System.out.println("VC vector not find, SIP is using "+this._normalisation+" for "+ chr+"\n"+_logError); 192 | runtime = Runtime.getRuntime(); 193 | _logError =""; 194 | cmd = "java"+" -jar "+this._juiceBoxTools+" dump norm "+this._normalisation+" "+this._hicFile+" "+chr+ 195 | " BP "+resolution+" "+output; 196 | System.out.println(cmd); 197 | process = runtime.exec(cmd); 198 | 199 | new ReturnFlux(process.getInputStream()).start(); 200 | new ReturnFlux(process.getErrorStream()).start(); 201 | exitValue=process.waitFor(); 202 | 203 | if(_logError.contains("Exception")){ 204 | System.out.println(_logError); 205 | System.out.println("juicer tool error !!!! "+ chr+" "+cmd); 206 | System.exit(0); 207 | } 208 | }else if ( _logError.contains("Exception")){ 209 | System.out.println(_logError); 210 | System.out.println("juicer tool error !!!! "+ chr+" "+cmd); 211 | System.exit(0); 212 | 213 | } 214 | //System.out.println(_logError); 215 | return exitValue==0; 216 | } 217 | 218 | /** 219 | * Class to run command line in java 220 | * @author axel poulet 221 | * 222 | */ 223 | public class ReturnFlux extends Thread { 224 | 225 | /** Flux to redirect */ 226 | private InputStream _flux; 227 | 228 | /** 229 | * Constructor of ReturnFlux 230 | * @param flux 231 | * flux to redirect 232 | */ 233 | public ReturnFlux(InputStream flux){this._flux = flux; } 234 | 235 | /** 236 | * 237 | */ 238 | public void run(){ 239 | try { 240 | InputStreamReader reader = new InputStreamReader(this._flux); 241 | BufferedReader br = new BufferedReader(reader); 242 | String line=null; 243 | while ( (line = br.readLine()) != null) { 244 | if(!line.contains("WARN") && !line.contains("INFO")) _logError = _logError+line+"\n"; 245 | } 246 | } 247 | catch (IOException ioe){ 248 | ioe.printStackTrace(); 249 | } 250 | } 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /src/main/java/plop/process/MultiResProcess.java: -------------------------------------------------------------------------------- 1 | package plop.process; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileReader; 7 | import java.io.FileWriter; 8 | import java.io.IOException; 9 | import java.time.LocalDateTime; 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.Iterator; 13 | import java.util.List; 14 | import java.util.Set; 15 | import java.util.stream.Collectors; 16 | 17 | import javax.swing.JOptionPane; 18 | 19 | 20 | import plop.multiProcesing.ProcessDetectLoops; 21 | import plop.utils.Loop; 22 | import plop.utils.SIPObject; 23 | 24 | /** 25 | * 26 | * @author axel poulet 27 | * 28 | */ 29 | public class MultiResProcess { 30 | 31 | private SIPObject _sip; 32 | /** 33 | * 34 | */ 35 | private int _nbCpu; 36 | /** 37 | * 38 | */ 39 | private boolean _delImage; 40 | private String _date; 41 | 42 | private String _doc = ("#SIP Version 1 run with java 8\n" 43 | + "\nUsage:\n" 44 | + "\thic [options]\n" 45 | + "\tcool [options]\n" 46 | + "\tprocessed [options]\n" 47 | + "\nParameters:\n" 48 | + "\t chrSizeFile: path to the chr size file, with the same name of the chr as in the hic file " + 49 | "(i.e. chr1 does not match Chr1 or 1)\n" 50 | + "\t-res: resolution in bp (default 5000 bp)\n" 51 | + "\t-mat: matrix size to use for each chunk of the chromosome (default 2000 bins)\n" 52 | + "\t-d: diagonal size in bins, remove the maxima found at this size (eg: a size of 2 at 5000 " + 53 | "bp resolution removes all maxima" 54 | + " detected at a distance inferior or equal to 10kb) (default 6 bins).\n" 55 | + "\t-g: Gaussian filter: smoothing factor to reduce noise during primary maxima detection (default 1.5)\n" 56 | + "\t-cpu: Number of CPU used for SIP processing (default 1)\n" 57 | + "\t-factor: Multiple resolutions can be specified using:\n" 58 | + "\t\t-factor 1: run only for the input res (default)\n" 59 | + "\t\t-factor 2: res and res*2\n" 60 | + "\t\t-factor 3: res and res*5\n" 61 | + "\t\t-factor 4: res, res*2 and res*5\n" 62 | + "\t-max: Maximum filter: increases the region of high intensity (default 2)\n" 63 | + "\t-min: Minimum filter: removes the isolated high value (default 2)\n" 64 | + "\t-sat: % of saturated pixel: enhances the contrast in the image (default 0.01)\n" 65 | + "\t-t Threshold for loops detection (default 2800)\n" 66 | + "\t-nbZero: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels " + 67 | "surrounding the detected maxima (default 6)\n" 68 | + "\t-norm: (default KR)\n" 69 | + "\t-del: true or false, whether not to delete tif files used for loop detection (default true)\n" 70 | + "\t-fdr: Empirical FDR value for filtering based on random sites (default 0.01)\n" 71 | + "\t-isDroso: default false, if true apply extra filter to help detect loops similar to those found" + 72 | " in D. mel cells\n" 73 | + "\t-h, --help print help\n" 74 | + "\nCommand line eg:\n" 75 | + "\tjava -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... parameters\n" 76 | + "\tjava -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar\n" 77 | + "\nAuthors:\n" 78 | + "Axel Poulet\n" 79 | + "\tDepartment of Molecular, Cellular and Developmental Biology Yale University 165 Prospect St\n" 80 | + "\tNew Haven, CT 06511, USA\n" 81 | + "M. Jordan Rowley\n" 82 | + "\tDepartment of Genetics, Cell Biology and Anatomy, University of Nebraska Medical Center Omaha," + 83 | "NE 68198-5805\n" 84 | + "\nContact: pouletaxel@gmail.com OR jordan.rowley@unmc.edu"); 85 | 86 | private String _chrFile; 87 | /** 88 | * 89 | * @param sip SIPObject with the parameters of the analysis 90 | * @param cpu number of cpu used for teh analysis 91 | * @param delImage delete the image at the end if True 92 | * @param chrSizeFile Chromosome size file 93 | */ 94 | public MultiResProcess(SIPObject sip, int cpu, boolean delImage, String chrSizeFile) { 95 | this._nbCpu = cpu; 96 | this._sip = sip; 97 | this._delImage = delImage; 98 | this._chrFile = chrSizeFile; 99 | LocalDateTime myObj = LocalDateTime.now(); 100 | this._date = myObj.toString().replaceAll(":",""); 101 | this._date = this._date.replaceAll("\\.","_"); 102 | 103 | } 104 | 105 | /** 106 | * @throws InterruptedException 107 | * @throws IOException 108 | * 109 | */ 110 | public void run() throws InterruptedException, IOException{ 111 | 112 | ArrayList listFactor = this._sip.getListFactor(); 113 | ArrayList listOfFile = new ArrayList(); 114 | File outDir = new File(_sip.getOutputDir()); 115 | if (!outDir.exists()) 116 | outDir.mkdir(); 117 | if (_sip.isProcessed()){ 118 | if(!this.testDir()){ 119 | if(_sip.isGui()) { 120 | JOptionPane.showMessageDialog(null,"Resolution problem", 121 | "Enable to find all the directories needed for SIP (-factor option)", 122 | JOptionPane.ERROR_MESSAGE); 123 | } 124 | System.out.println("!!!! It is missing one or several directories for factor parameter\n"); 125 | System.out.println(_doc); 126 | System.exit(0); 127 | } 128 | } 129 | for(int indexFact = 0; indexFact < listFactor.size(); ++indexFact) { 130 | int res = this._sip.getResolution()*listFactor.get(indexFact); 131 | String resName = String.valueOf(res); 132 | resName = resName.replace("000", "")+"kb"; 133 | if(res < 1000){ 134 | resName = String.valueOf(res); 135 | resName = resName+"b"; 136 | } 137 | String resuFile = this._sip.getOutputDir()+File.separator+resName+"Loops_"+this._date+".txt"; 138 | listOfFile.add(resuFile); 139 | File file = new File(resuFile); 140 | if(file.exists()) 141 | file.delete(); 142 | SIPObject sipTmp = new SIPObject (); 143 | if(indexFact == 0) { 144 | ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); 145 | processDetectloops.go(this._sip, this._nbCpu,this._delImage,resuFile,resName); 146 | }else { 147 | sipTmp.setInputDir(_sip.getOutputDir()); 148 | sipTmp.setOutputDir(_sip.getOutputDir()); 149 | if(this._sip.isProcessed()) { 150 | sipTmp.setInputDir(_sip.getInputDir()); 151 | sipTmp.setOutputDir(_sip.getOutputDir()); 152 | } 153 | sipTmp.setChrSizeHashMap(this._sip.getChrSizeHashMap()); 154 | sipTmp.setIsGui(_sip.isGui()); 155 | sipTmp.setDiagSize(this._sip.getDiagSize()); 156 | sipTmp.setGauss(this._sip.getGauss()/listFactor.get(indexFact)); 157 | sipTmp.setMatrixSize((int)(this._sip.getMatrixSize()/listFactor.get(indexFact))); 158 | sipTmp.setResolution(res); 159 | sipTmp.setStep(this._sip.getStep()/listFactor.get(indexFact)); 160 | sipTmp.setMax(_sip.getMax()); 161 | sipTmp.setMin(_sip.getMin()); 162 | sipTmp.setSaturatedPixel(_sip.getSaturatedPixel()); 163 | sipTmp.setThresholdMaxima(_sip.getThresholdMaxima()); 164 | sipTmp.setNbZero(_sip.getNbZero()); 165 | sipTmp.setIsProcessed(_sip.isProcessed()); 166 | sipTmp.setFdr(_sip.getFdr()); 167 | sipTmp.setIsDroso(_sip.isDroso()); 168 | sipTmp.setIsCooler(_sip.isCooler()); 169 | ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); 170 | processDetectloops.go(sipTmp, this._nbCpu,this._delImage,resuFile,resName); 171 | } 172 | } 173 | if(listOfFile.size() > 1) { 174 | System.out.println("Merging File ... "); 175 | this.mergedFile(listOfFile); 176 | System.out.println("Merging File End !!!! "); 177 | } 178 | } 179 | 180 | /** 181 | * 182 | * @return boolean if the folder tested exist 183 | */ 184 | private boolean testDir(){ 185 | String input = _sip.getInputDir(); 186 | ArrayList listFactor = this._sip.getListFactor(); 187 | for (Integer integer : listFactor) { 188 | int res = this._sip.getResolution() * integer; 189 | String resName = String.valueOf(res); 190 | resName = resName.replace("000", "") + "kb"; 191 | if(res < 1000){ 192 | resName = String.valueOf(res); 193 | resName = resName+"b"; 194 | } 195 | File inputDir = new File(input + resName); 196 | if (!inputDir.exists()) { 197 | return false; 198 | } 199 | } 200 | return true; 201 | } 202 | 203 | /** 204 | * 205 | * @param listOfFile 206 | * @throws IOException 207 | */ 208 | private void mergedFile(ArrayList listOfFile) throws IOException{ 209 | HashMap chrSize = readChrIndex(this._chrFile); 210 | Set key = chrSize.keySet(); 211 | ArrayList > data = new ArrayList >(); 212 | for (int i = 0; i < key.size();++i) { 213 | HashMap plop = new HashMap(); 214 | data.add(plop); 215 | } 216 | 217 | BufferedReader br = new BufferedReader(new FileReader(listOfFile.get(0))); 218 | StringBuilder sb = new StringBuilder(); 219 | String line = br.readLine(); 220 | String title = line; 221 | sb.append(System.lineSeparator()); 222 | line = br.readLine(); 223 | while (line != null){ 224 | sb.append(line); 225 | Loop loop = new Loop(line); 226 | String chr = loop.getChr(); 227 | int index = chrSize.get(chr); 228 | HashMap plop = data.get(index); 229 | plop.put(line, loop); 230 | data.set(index, plop); 231 | sb.append(System.lineSeparator()); 232 | line = br.readLine(); 233 | } 234 | br.close(); 235 | 236 | for (int i = 1; i < listOfFile.size();++i) { 237 | br = new BufferedReader(new FileReader((listOfFile.get(i)))); 238 | sb = new StringBuilder(); 239 | line = br.readLine(); 240 | sb.append(System.lineSeparator()); 241 | line = br.readLine(); 242 | while (line != null){ 243 | Loop loop = new Loop(line); 244 | String chr = loop.getChr(); 245 | int index = chrSize.get(chr); 246 | HashMap plop = data.get(index); 247 | if(compareLoop(plop,loop)){ 248 | plop.put(line,loop); 249 | data.set(index, plop); 250 | } 251 | sb.append(System.lineSeparator()); 252 | line = br.readLine(); 253 | } 254 | br.close(); 255 | } 256 | 257 | BufferedWriter writer; 258 | writer = new BufferedWriter(new FileWriter(new File(_sip.getOutputDir()+"finalLoops"+this._date+".txt"))); 259 | writer.write(title+"\n"); 260 | for (int i = 0; i < data.size();++i){ 261 | HashMap plop = data.get(i); 262 | Set keyBis = plop.keySet(); 263 | List output = keyBis.stream().collect(Collectors.toList()); 264 | for (int j = 0; j < output.size();++j){ 265 | writer.write(output.get(j)+"\n"); 266 | } 267 | } 268 | writer.close(); 269 | } 270 | 271 | 272 | /** 273 | * 274 | * @param loopHashMap loop collection 275 | * @param a loop tested 276 | * @return boolean if the loop is present in the hash map 277 | */ 278 | private boolean compareLoop(HashMap loopHashMap, Loop a) { 279 | Set key = loopHashMap.keySet(); 280 | Iterator it = key.iterator(); 281 | while (it.hasNext()){ 282 | String loopName = it.next(); 283 | Loop loop = loopHashMap.get(loopName); 284 | int xEnd = loop.getCoordinates().get(1); 285 | int yEnd = loop.getCoordinates().get(3); 286 | int xtest = a.getCoordinates().get(0); 287 | int xtestEnd = a.getCoordinates().get(1); 288 | int res = xtestEnd-xtest; 289 | int ytest = a.getCoordinates().get(2); 290 | int ytestEnd = a.getCoordinates().get(3); 291 | xtest = xtest-res*2; 292 | xtestEnd = xtestEnd+res*2; 293 | ytest = ytest-res*2; 294 | ytestEnd = ytestEnd+res*2; 295 | //System.out.println(x+"\t"+xEnd+"\t"+ xtestEnd); 296 | if((xtest <= xEnd && xtestEnd >= xEnd) && (ytest <= yEnd && ytestEnd >= yEnd)) 297 | return false; 298 | } 299 | return true; 300 | } 301 | 302 | 303 | /** 304 | * 305 | * @param chrSizeFile file with the chromosome size 306 | * @return hash map chr name chr size 307 | * @throws IOException throw exception if file doesn't exist 308 | */ 309 | private HashMap readChrIndex(String chrSizeFile) throws IOException{ 310 | HashMap chrSize = new HashMap(); 311 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 312 | StringBuilder sb = new StringBuilder(); 313 | String line = br.readLine(); 314 | int i = 0; 315 | while (line != null){ 316 | sb.append(line); 317 | String[] parts = line.split("\\t"); 318 | String chr = parts[0]; 319 | chrSize.put(chr, i); 320 | sb.append(System.lineSeparator()); 321 | line = br.readLine(); 322 | ++i; 323 | } 324 | br.close(); 325 | return chrSize; 326 | } 327 | 328 | } 329 | -------------------------------------------------------------------------------- /src/main/java/plop/process/TupleFileToImage.java: -------------------------------------------------------------------------------- 1 | package plop.process; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import ij.ImagePlus; 7 | import ij.process.FloatProcessor; 8 | import ij.process.ImageProcessor; 9 | import ij.process.ShortProcessor; 10 | 11 | 12 | /** 13 | * Make an image with a tuple file (x y value). Take in input the resolution the matrix size and the other parameters of the tuple 14 | * file. 15 | * 16 | * @author axel poulet 17 | * 18 | */ 19 | public class TupleFileToImage { 20 | 21 | /** Image results */ 22 | private ImagePlus _img = new ImagePlus(); 23 | /** Image results */ 24 | private ImagePlus _imgNorm = new ImagePlus(); 25 | /** Path of the tuple file*/ 26 | private String _file = ""; 27 | /** Size of the matrix*/ 28 | private int _size = 0 ; 29 | /** Resolution of the image in base*/ 30 | private int _resolution = 0 ; 31 | /** Step to split the whole chromosome*/ 32 | private int _step ; 33 | /** Image value average*/ 34 | private float _avg = 0; 35 | /** Image standard deviation */ 36 | private float _std = 0; 37 | /** number of pixe == 0 */ 38 | private int _noZeroPixel = 0; 39 | 40 | /** 41 | * TupleFileToImage constructor 42 | * 43 | * @param fileMatrix tuple file path 44 | * @param size int size of the image 45 | * @param resolution int size of the bin 46 | */ 47 | public TupleFileToImage(String fileMatrix, int size, int resolution){ 48 | this._file = fileMatrix; 49 | this._size = size; 50 | this._resolution = resolution; 51 | this._step = size/2; 52 | } 53 | 54 | 55 | /** 56 | * Method to make the image with an input tuple file return the image results 57 | * 58 | * @return ImagePlus results 59 | */ 60 | public void readTupleFile(){ 61 | BufferedReader br; 62 | ShortProcessor pRaw = new ShortProcessor(this._size,this._size); 63 | FloatProcessor pNorm = new FloatProcessor(this._size,this._size); 64 | String[] tFile = this._file.split("_"); 65 | int numImage = Integer.parseInt(tFile[tFile.length-2])/(this._step*this._resolution); 66 | try { 67 | pRaw.abs(); 68 | br = new BufferedReader(new FileReader(this._file)); 69 | StringBuilder sb = new StringBuilder(); 70 | String line = br.readLine(); 71 | while (line != null){ 72 | sb.append(line); 73 | String[] parts = line.split("\\t"); 74 | float raw = 0; 75 | float norm = 0; 76 | 77 | if(!(parts[2].equals("NAN"))){ 78 | raw =Float.parseFloat(parts[2]); 79 | if (raw < 0) raw = 0; 80 | } 81 | 82 | if(!(parts[3].equals("NAN"))){ 83 | norm =Float.parseFloat(parts[3]); 84 | if (norm < 0) norm = 0; 85 | } 86 | 87 | int correction = numImage*this._step*this._resolution; 88 | int i = (Integer.parseInt(parts[0]) - correction)/this._resolution; 89 | int j = (Integer.parseInt(parts[1]) - correction)/this._resolution; 90 | if(i < this._size && j< this._size){ 91 | pRaw.set(i, j,(int)raw); 92 | pRaw.set(j, i, (int)raw); 93 | pNorm.setf(i, j, norm); 94 | pNorm.setf(j, i, norm); 95 | } 96 | sb.append(System.lineSeparator()); 97 | line = br.readLine(); 98 | } 99 | br.close(); 100 | } catch (IOException e) { e.printStackTrace();} 101 | this._img.setProcessor(pRaw); 102 | this._imgNorm.setProcessor(pNorm); 103 | } 104 | 105 | /** 106 | * Method to correct the image, remove the high value close to the diagonal to allow 107 | * the detection of the structure of interest 108 | * @param img ImagePlus to correct 109 | */ 110 | public void correctImage(ImagePlus img){ 111 | ImageProcessor ip = img.getProcessor(); 112 | _noZeroPixel = 0; 113 | float sum = 0; 114 | for(int i = 0; i < ip.getWidth(); ++i){ 115 | for(int j = 0; j < ip.getWidth(); ++j){ 116 | if(ip.getf(i, j) > 0){ 117 | ++_noZeroPixel; 118 | sum += ip.getf(i, j); 119 | } 120 | } 121 | } 122 | _avg = sum/_noZeroPixel; 123 | _std = std(_avg,img); 124 | for(int i = 0; i < ip.getWidth(); ++i){ 125 | for(int j = 0; j < ip.getWidth(); ++j){ 126 | float a = ip.getf(i, j); 127 | if (Math.abs(j-i) <= 2 && a >= _avg+_std*2) 128 | ip.setf(i,j,_avg); 129 | } 130 | } 131 | img.setProcessor(ip); 132 | } 133 | 134 | /** 135 | * Compute the standard deviation of the pixel > 0 of m_img 136 | * @param mean average value in m_img 137 | * @param img ImagePlus 138 | * @return double satndard deivation 139 | */ 140 | private float std(float mean,ImagePlus img){ 141 | float semc = 0; 142 | ImageProcessor ip = img.getProcessor(); 143 | int noZeroPixel = 0; 144 | for(int i = 0; i < ip.getWidth(); ++i){ 145 | for(int j = 0; j < ip.getWidth(); ++j){ 146 | if(ip.getPixel(i, j) > 0){ 147 | ++noZeroPixel; 148 | semc += (ip.getf(i, j)-mean)*(ip.getf(i, j)-mean); 149 | } 150 | } 151 | } 152 | semc = (float) Math.sqrt(semc/noZeroPixel); 153 | return semc; 154 | } 155 | 156 | public int getNbZero() { return this._noZeroPixel; } 157 | /** 158 | * getter of the raw image 159 | * @return ImagePLus raw image 160 | */ 161 | public String getInputFile(){return this._file;} 162 | /** 163 | * getter of the raw image 164 | * @return ImagePLus raw image 165 | */ 166 | public ImagePlus getRawImage(){return this._img;} 167 | /** 168 | * getter of the normalized image 169 | * @return ImagePlus normalized image 170 | */ 171 | public ImagePlus getNormImage(){return this._imgNorm;} 172 | 173 | /** 174 | * setter for the raw Image 175 | * @param img ImagePlus 176 | */ 177 | public void setRawImage(ImagePlus img){this._img = img;} 178 | /** 179 | * setter of the normalized image 180 | * @param img ImagePLus 181 | */ 182 | public void setNormImage(ImagePlus img){this._imgNorm = img;} 183 | } -------------------------------------------------------------------------------- /src/main/java/plop/sipMain/Hic_main.java: -------------------------------------------------------------------------------- 1 | package plop.sipMain; 2 | import java.io.BufferedReader; 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | import java.time.LocalDateTime; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | 14 | import javax.swing.JOptionPane; 15 | 16 | import plop.gui.GuiAnalysis; 17 | import plop.multiProcesing.ProcessCoolerDumpData; 18 | import plop.multiProcesing.ProcessHicDumpData; 19 | import plop.process.MultiResProcess; 20 | import plop.utils.SIPObject; 21 | 22 | import java.time.LocalTime; // import the LocalTime class 23 | 24 | 25 | 26 | 27 | /** 28 | * 29 | * command line eg: 30 | * java -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... paramaters 31 | * java -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar 32 | * 33 | * @author axel poulet 34 | * 35 | */ 36 | public class Hic_main { 37 | /** Path of input data directory if dumped or processed data else .hic for hic option*/ 38 | private static String _input = ""; 39 | /** Path of output if not existed it is created*/ 40 | private static String _output = ""; 41 | /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ 42 | private static String _juiceBoxTools = ""; 43 | /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ 44 | private static String _cooler = ""; 45 | /** Path to the jucier_tools_box to dump the data not necessary for Processed and dumped method */ 46 | private static String _cooltools = ""; 47 | /**Normalisation method to dump the data with hic method (KR,NONE.VC,VC_SQRT)*/ 48 | private static String _juiceBoXNormalisation = "KR"; 49 | /**Size of the core for the gaussian blur filter allow to smooth the signal*/ 50 | private static double _gauss = 1.5; 51 | /**Size of the core for the Minimum filter*/ 52 | private static double _min = 2.0; 53 | /**Size of the core for the Maximum filter*/ 54 | private static double _max = 2.0; 55 | /**Matrix size: size in bins of the final image and defined the zone of interest in the hic map*/ 56 | private static int _matrixSize = 2000; 57 | /**Distance to the diagonal where the loops are ignored*/ 58 | private static int _diagonalSize = 6; 59 | /**Resolution of the matrix in bases*/ 60 | private static int _resolution = 5000; 61 | /** % of saturated pixel in the image, allow the enhancement of the contrast in the image*/ 62 | private static double _saturatedPixel = 0.01; 63 | /** Threshold to accept a maxima in the images as a loop*/ 64 | private static int _thresholdMax = 2800; 65 | /**number of pixel = 0 allowed around the loop*/ 66 | private static int _nbZero = 6; 67 | /** boolean if true run all the process (dump data + image +image processing*/ 68 | private static boolean _isHic = true; 69 | /** boolean if true run all the process (dump data + image +image processing*/ 70 | private static boolean _isCool = false; 71 | /** boolean if true run all the process (dump data + image +image processing*/ 72 | private static boolean _isDroso = false; 73 | /** factor(s) used to analyse the matrix*/ 74 | private static ArrayList _factor = new ArrayList(); 75 | /** String factor option*/ 76 | private static String _factOption = "1"; 77 | /** if true run only image Processing step*/ 78 | private static boolean _isProcessed = false; 79 | /** hash map stocking in key the name of the chr and in value the size*/ 80 | private static HashMap _chrSize = new HashMap(); 81 | /** path to the chromosome size file */ 82 | private static String _chrSizeFile; 83 | /**boolean is true supress all the image created*/ 84 | private static boolean _delImages = true; 85 | /** double FDR value for filtering */ 86 | private static double _fdr = 0.01; 87 | /** int number of cpu*/ 88 | private static int _cpu = 1; 89 | /**boolean is true supress all the image created*/ 90 | private static boolean _gui = false; 91 | private static String _logError = ""; 92 | /**String for the documentation*/ 93 | private static String _doc = ("#SIP Version 1 run with java 8\n" 94 | + "\nUsage:\n" 95 | + "\thic [options]\n" 96 | + "\tcool [options]\n" 97 | + "\tprocessed [options]\n" 98 | + "\nParameters:\n" 99 | + "\t chrSizeFile: path to the chr size file, with the same name of the chr as in the hic file" + 100 | " (i.e. chr1 does not match Chr1 or 1)\n" 101 | + "\t-res: resolution in bp (default 5000 bp)\n" 102 | + "\t-mat: matrix size to use for each chunk of the chromosome (default 2000 bins)\n" 103 | + "\t-d: diagonal size in bins, remove the maxima found at this size (eg: a size of 2 at " + 104 | "5000 bp resolution removes all maxima" 105 | + " detected at a distance inferior or equal to 10kb) (default 6 bins).\n" 106 | + "\t-g: Gaussian filter: smoothing factor to reduce noise during primary maxima detection (default 1.5)\n" 107 | + "\t-cpu: Number of CPU used for SIP processing (default 1)\n" 108 | + "\t-factor: Multiple resolutions can be specified using:\n" 109 | + "\t\t-factor 1: run only for the input res (default)\n" 110 | + "\t\t-factor 2: res and res*2\n" 111 | + "\t\t-factor 3: res and res*5\n" 112 | + "\t\t-factor 4: res, res*2 and res*5\n" 113 | + "\t-max: Maximum filter: increases the region of high intensity (default 2)\n" 114 | + "\t-min: Minimum filter: removes the isolated high value (default 2)\n" 115 | + "\t-sat: % of saturated pixel: enhances the contrast in the image (default 0.01)\n" 116 | + "\t-t Threshold for loops detection (default 2800)\n" 117 | + "\t-nbZero: number of zeros: number of pixels equal to zero that are allowed in the 24 pixels " + 118 | "surrounding the detected maxima (default 6)\n" 119 | + "\t-norm: (default KR)\n" 120 | + "\t-del: true or false, whether not to delete tif files used for loop detection (default true)\n" 121 | + "\t-fdr: Empirical FDR value for filtering based on random sites (default 0.01)\n" 122 | + "\t-isDroso: default false, if true apply extra filter to help detect loops similar to those found" + 123 | " in D. mel cells\n" 124 | + "\t-h, --help print help\n" 125 | + "\nCommand line eg:\n" 126 | + "\tjava -jar SIP_HiC.jar processed inputDirectory pathToChromosome.size OutputDir .... parameters\n" 127 | + "\tjava -jar SIP_HiC.jar hic inputDirectory pathToChromosome.size OutputDir juicer_tools.jar\n" 128 | + "\nAuthors:\n" 129 | + "Axel Poulet\n" 130 | + "\tDepartment of Molecular, Cellular and Developmental Biology Yale University 165 Prospect St\n" 131 | + "\tNew Haven, CT 06511, USA\n" 132 | + "M. Jordan Rowley\n" 133 | + "\tDepartment of Genetics, Cell Biology and Anatomy, University of Nebraska Medical Center" + 134 | " Omaha,NE 68198-5805\n" 135 | + "\nContact: pouletaxel@gmail.com OR jordan.rowley@unmc.edu"); 136 | 137 | /** 138 | * Main function to run all the process, can be run with plop.gui or in command line. 139 | * With command line with 1 or less than 5 parameter => run only the help 140 | * With zero parameter only java -jar SIP.jar => plop.gui 141 | * With more than 5 parameter => command line mode 142 | * 143 | * @param args 144 | * @throws IOException 145 | * @throws InterruptedException 146 | */ 147 | public static void main(String[] args) throws IOException, InterruptedException { 148 | _factor.add(1); 149 | if (args.length >= 1 && args.length < 4){ 150 | System.out.println(_doc); 151 | System.exit(0); 152 | }else if(args.length >= 4){ 153 | if (args[0].equals("hic") || args[0].equals("processed") || args[0].equals("cool")){ 154 | _input = args[1]; 155 | _output = args[3]; 156 | _chrSizeFile = args[2]; 157 | switch (args[0]) { 158 | case "hic": 159 | readOption(args, 5); 160 | _juiceBoxTools = args[4]; 161 | break; 162 | case "processed": 163 | _isHic = false; 164 | _isProcessed = true; 165 | readOption(args, 4); 166 | break; 167 | case "cool": 168 | _isHic = false; 169 | _isProcessed = false; 170 | _isCool = true; 171 | _cooler = args[5]; 172 | _cooltools = args[4]; 173 | readOption(args, 6); 174 | break; 175 | default: 176 | 177 | break; 178 | } 179 | }else{ 180 | System.out.println(args[0]+" not defined\n"); 181 | System.out.println(_doc); 182 | return; 183 | } 184 | 185 | }else{////////////////////////////////////////GUI parameter initialisation 186 | GuiAnalysis gui = new GuiAnalysis(); 187 | _gui =true; 188 | while( gui.isShowing()){ 189 | try {Thread.sleep(1);} 190 | catch (InterruptedException e) {e.printStackTrace();} 191 | } 192 | if (gui.isStart()){ 193 | _isCool = gui.isCool(); 194 | _chrSizeFile = gui.getChrSizeFile(); 195 | _output = gui.getOutputDir(); 196 | _input = gui.getRawDataDir(); 197 | _matrixSize = gui.getMatrixSize(); 198 | _diagonalSize = gui.getDiagSize(); 199 | _resolution = gui.getResolution(); 200 | _delImages = gui.isDeletTif(); 201 | _gauss = gui.getGaussian(); 202 | _max = gui.getMax(); 203 | _min = gui.getMin(); 204 | _isDroso= gui.isDroso(); 205 | _nbZero = gui.getNbZero(); 206 | _saturatedPixel = gui.getEnhanceSignal(); 207 | _thresholdMax = gui.getNoiseTolerance(); 208 | _fdr = gui.getFDR(); 209 | _cpu = gui.getNbCpu(); 210 | if(gui.getFactorChoice() == 2){ 211 | _factor.add(2); 212 | }else if(gui.getFactorChoice() == 4){ 213 | _factor.add(2); 214 | _factor.add(5); 215 | }else if(gui.getFactorChoice() == 3){ 216 | _factor.add(5); 217 | } 218 | _isHic = gui.isHic(); 219 | _isProcessed = gui.isProcessed(); 220 | _juiceBoxTools = gui.getJuiceBox(); 221 | _cooltools = gui.getCooltools(); 222 | _cooler = gui.getCooler(); 223 | 224 | if(gui.isNONE()) _juiceBoXNormalisation = "NONE"; 225 | else if (gui.isVC()) _juiceBoXNormalisation = "VC"; 226 | else if (gui.isScale()) _juiceBoXNormalisation = "SCALE"; 227 | else if (gui.isVC_SQRT()) _juiceBoXNormalisation = "VC_SQRT"; 228 | }else { 229 | System.out.println("SIP closed: if you want the help: -h"); 230 | return; 231 | } 232 | } 233 | File f = new File(_input); 234 | 235 | if(!f.exists() && !_input.startsWith("https")){ 236 | System.out.println(_input+" doesn't existed !!! \n\n"); 237 | System.out.println(_doc); 238 | return; 239 | } 240 | 241 | f = new File(_chrSizeFile); 242 | if(!f.exists()){ 243 | System.out.println(_chrSizeFile+" doesn't existed !!! \n\n"); 244 | System.out.println(_doc); 245 | return; 246 | } 247 | 248 | 249 | SIPObject sip; 250 | readChrSizeFile(_chrSizeFile); 251 | LocalDateTime myObj = LocalDateTime.now(); 252 | String date = myObj.toString().replaceAll(":",""); 253 | date = date.replaceAll("\\.","_"); 254 | if(_isHic){ 255 | f = new File(_juiceBoxTools); 256 | if(!f.exists()){ 257 | System.out.println(_juiceBoxTools+" doesn't existed !!! \n\n"); 258 | System.out.println(_doc); 259 | return; 260 | } 261 | System.out.println("hic mode: \n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+ "juiceBox: "+ 262 | _juiceBoxTools+"\n"+ "norm: "+ _juiceBoXNormalisation+"\n" + "gauss: "+_gauss+"\n"+ "min: "+ 263 | _min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n"+ "diag size: "+ _diagonalSize +"\n"+ 264 | "resolution: "+_resolution+"\n" + "saturated pixel: "+_saturatedPixel+"\n"+ "threshold: "+ 265 | _thresholdMax+"\n"+ "number of zero :"+_nbZero+"\n"+ "factor "+ _factOption+"\n"+ "fdr "+ 266 | _fdr+"\n"+ "del "+_delImages+"\n"+ "cpu "+ _cpu+"\n-isDroso "+_isDroso+"\n"); 267 | 268 | sip = new SIPObject(_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, 269 | _thresholdMax, _diagonalSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); 270 | sip.setIsGui(_gui); 271 | ProcessHicDumpData processDumpData = new ProcessHicDumpData(); 272 | processDumpData.go(_input, sip, _chrSize, _juiceBoxTools, _juiceBoXNormalisation, _cpu); 273 | System.out.println("########### End of the dump Step"); 274 | }else if(_isCool){ 275 | f = new File(_cooltools); 276 | if(!f.exists()){ 277 | System.out.println(_cooltools+" doesn't existed or wrong path !!! \n\n"); 278 | System.out.println(_doc); 279 | return; 280 | } 281 | f = new File(_cooler); 282 | if(!f.exists()){ 283 | System.out.println(_cooler+" doesn't existed or wrong path !!! \n\n"); 284 | System.out.println(_doc); 285 | return; 286 | } 287 | if( !testTools(_cooltools, 0, 3, 0) || !testTools(_cooler, 0, 8, 6)) { 288 | System.out.println( _cooltools +" or" + _cooler+" is not the good version for SIP (it needs cooltools " + 289 | "version >= 0.3.0 and cooler version >= 0.8.6) !!! \n\n"); 290 | System.out.println(_doc); 291 | if(_gui){ 292 | JOptionPane.showMessageDialog(null, "Error SIP program", 293 | _cooltools +" or" + _cooler+" is not the good version for SIP (it needs cooltools " + 294 | "version >= 0.3.0 and cooler version >= 0.8.6) !!!" 295 | , JOptionPane.ERROR_MESSAGE); 296 | } 297 | return; 298 | } 299 | System.out.println("cool mode: \n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+"cooltools: "+ 300 | _cooltools+"\n"+ "cooler: "+_cooler+"\n"+ "norm: "+ _juiceBoXNormalisation+"\n" + "gauss: "+ 301 | _gauss+"\n"+ "min: "+_min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n"+ 302 | "diag size: "+ _diagonalSize +"\n"+ "resolution: "+_resolution+"\n"+ "saturated pixel: "+ 303 | _saturatedPixel+ "\n"+ "threshold: "+_thresholdMax+"\n"+ "number of zero :"+_nbZero+"\n"+ 304 | "factor "+ _factOption+ "\n"+ "fdr "+_fdr+"\n" + "del "+_delImages+"\n"+ "cpu "+ _cpu+ 305 | "\n-isDroso "+_isDroso+"\n"); 306 | sip = new SIPObject(_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, _thresholdMax, 307 | _diagonalSize, _matrixSize, _nbZero, _factor,_fdr, _isProcessed,_isDroso); 308 | sip.setIsCooler(_isCool); 309 | 310 | ProcessCoolerDumpData processDumpData = new ProcessCoolerDumpData(); 311 | processDumpData.go(_cooltools, _cooler, sip, _input, _chrSize,_cpu); 312 | 313 | }else{ 314 | System.out.println("processed mode:\n"+ "input: "+_input+"\n"+ "output: "+_output+"\n"+ "juiceBox: "+ 315 | _juiceBoxTools+"\n" + "norm: "+ _juiceBoXNormalisation+"\n"+ "gauss: "+_gauss+"\n"+ "min: "+ 316 | _min+"\n"+ "max: "+_max+"\n"+ "matrix size: "+_matrixSize+"\n" + "diag size: "+ _diagonalSize + 317 | "\n"+ "resolution: "+_resolution+"\n"+ "saturated pixel: "+_saturatedPixel+"\n"+ "threshold: "+ 318 | _thresholdMax+"\n" + "isHic: "+_isHic+"\n" + "isProcessed: "+_isProcessed+"\n"+ 319 | "number of zero:"+_nbZero+"\n"+ "factor "+ _factOption+"\n"+ "fdr "+_fdr+ "\n" + "del " 320 | +_delImages+"\n"+"cpu "+ _cpu+"\n-isDroso "+_isDroso+"\n"); 321 | 322 | sip = new SIPObject(_input,_output, _chrSize, _gauss, _min, _max, _resolution, _saturatedPixel, 323 | _thresholdMax, _diagonalSize, _matrixSize, _nbZero,_factor,_fdr,_isProcessed, _isDroso); 324 | sip.setIsGui(_gui); 325 | } 326 | System.out.println("Start loop detection step"); 327 | 328 | 329 | 330 | 331 | MultiResProcess multi = new MultiResProcess(sip, _cpu, _delImages,_chrSizeFile); 332 | multi.run(); 333 | System.out.println("###########End loop detection step"); 334 | BufferedWriter writer = new BufferedWriter(new FileWriter(new 335 | File(_output+File.separator+"parameters_"+date+".txt")) 336 | ); 337 | if(_isProcessed){ 338 | writer.write("java -jar Sip_HiC.jar processed "+ _input+" "+ _chrSizeFile+" "+_output+" -g "+ 339 | _gauss+" -mat "+_matrixSize+" -d "+ _diagonalSize +" -res "+_resolution+" -t "+_thresholdMax+ 340 | " -min "+_min+" -max "+_max+" -sat "+_saturatedPixel+" -nbZero "+_nbZero+" -factor "+ 341 | _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ _cpu+" -isDroso "+_isDroso+"\n"); 342 | }else if(_isCool){ 343 | writer.write("java -jar SIP_HiC.jar hic "+_input+" "+_chrSizeFile+" "+_output+" "+_cooltools+" "+ 344 | _cooler+ " -g "+_gauss+" -min "+_min+" -max "+_max+" -mat "+_matrixSize+" -d "+ _diagonalSize + 345 | " -res "+_resolution+" -sat "+_saturatedPixel+" -t "+_thresholdMax+" -nbZero "+_nbZero+ 346 | " -factor "+ _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ _cpu+" -isDroso "+ 347 | _isDroso+"\n"); 348 | }else{ 349 | writer.write("java -jar SIP_HiC.jar hic "+_input+" "+_chrSizeFile+" "+_output+" "+_juiceBoxTools+ 350 | " -norm "+ _juiceBoXNormalisation+" -g "+_gauss+" -min "+_min+" -max "+_max+" -mat "+_matrixSize+ 351 | " -d "+ _diagonalSize +" -res "+_resolution+" -sat "+_saturatedPixel+" -t "+_thresholdMax+ 352 | " -nbZero "+_nbZero+ " -factor "+ _factOption+" -fdr "+_fdr+" -del "+_delImages+" -cpu "+ 353 | _cpu+" -isDroso "+_isDroso+"\n"); 354 | } 355 | writer.close(); 356 | 357 | if(_gui){ 358 | JOptionPane.showMessageDialog(null,"Results available: "+_output , 359 | "End of SIP program", JOptionPane.INFORMATION_MESSAGE); 360 | } 361 | System.out.println("End of SIP loops are available in "+_output+"\n Bye!!! "); 362 | System.exit(0); 363 | } 364 | 365 | /** 366 | * Run the input file and stock the info of name chr and their size in hashmap 367 | * @param chrSizeFile path chr size file 368 | * @throws IOException if file does not exist 369 | */ 370 | private static void readChrSizeFile( String chrSizeFile) throws IOException{ 371 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 372 | StringBuilder sb = new StringBuilder(); 373 | String line = br.readLine(); 374 | while (line != null){ 375 | sb.append(line); 376 | String[] parts = line.split("\\t"); 377 | String chr = parts[0]; 378 | int size = Integer.parseInt(parts[1]); 379 | _chrSize.put(chr, size); 380 | sb.append(System.lineSeparator()); 381 | line = br.readLine(); 382 | } 383 | br.close(); 384 | } 385 | 386 | /** 387 | * -res: resolution in bases (default 5000 bases) 388 | * -mat: matrix size in bins (default 2000 bins) 389 | * -d: diagonal size in bins (default 2 bins) 390 | * -g: Gaussian filter (default 1) 391 | * -max: Maximum filter: increase the region of high intensity (default 1.5) 392 | * -min: minimum filter: removed the isolated high value (default 1.5) 393 | * -sat: % of staturated pixel: enhance the contrast in the image (default 0.05) 394 | * -t Threshold for loops detection (default 3000) 395 | * -norm: only for hic option (default KR) 396 | * -nbZero: 397 | * -cpu 398 | * -del 399 | * -fdr 400 | * 401 | * @param args table of String stocking the arguments for the program 402 | * @param index table index where start to read the arguments 403 | * @throws IOException if some parameters don't exist 404 | */ 405 | private static void readOption(String args[], int index) throws IOException{ 406 | if(index < args.length){ 407 | for(int i = index; i < args.length;i+=2){ 408 | if(args[i].equals("-res")){ 409 | try{_resolution =Integer.parseInt(args[i+1]);} 410 | catch(NumberFormatException e){ returnError("-res",args[i+1],"int");} 411 | }else if(args[i].equals("-mat")){ 412 | try{_matrixSize =Integer.parseInt(args[i+1]);} 413 | catch(NumberFormatException e){ returnError("-mat",args[i+1],"int");} 414 | }else if(args[i].equals("-factor")){ 415 | int a = Integer.parseInt(args[i+1]); 416 | _factOption = args[i+1]; 417 | if(a == 2){ _factor.add(2);} 418 | else if(a == 4){ 419 | _factor.add(2); 420 | _factor.add(5); 421 | }else if(a == 3){ _factor.add(5);} 422 | else if(a != 1) returnError("-factor ",args[i+1]," int or not" + 423 | " correct choice (1, 2, 3, 4)"); 424 | }else if(args[i].equals("-d")){ 425 | try{ 426 | _diagonalSize =Integer.parseInt(args[i+1]);} 427 | catch(NumberFormatException e){ returnError("-d",args[i+1],"int");} 428 | }else if(args[i].equals("-cpu")){ 429 | try{_cpu =Integer.parseInt(args[i+1]);} 430 | catch(NumberFormatException e){ returnError("-cpu",args[i+1],"int");} 431 | if(_cpu > Runtime.getRuntime().availableProcessors() || _cpu <= 0){ 432 | System.out.println("the number of CPU "+ _cpu+" is superior of the " + 433 | "server/computer' cpu "+Runtime.getRuntime().availableProcessors()+"\n"); 434 | System.out.println(_doc); 435 | System.exit(0); 436 | } 437 | }else if(args[i].equals("-nbZero")){ 438 | try{_nbZero =Integer.parseInt(args[i+1]);} 439 | catch(NumberFormatException e){ returnError("-d",args[i+1],"int");} 440 | }else if(args[i].equals("-g")){ 441 | try{_gauss =Double.parseDouble(args[i+1]);} 442 | catch(NumberFormatException e){ returnError("-g",args[i+1],"double");} 443 | }else if(args[i].equals("-fdr")){ 444 | try{_fdr =Double.parseDouble(args[i+1]);} 445 | catch(NumberFormatException e){ returnError("-fdr",args[i+1],"double");} 446 | }else if(args[i].equals("-max")){ 447 | try{_max = Double.parseDouble(args[i+1]);} 448 | catch(NumberFormatException e){ returnError("-max",args[i+1],"double");} 449 | 450 | }else if(args[i].equals("-min")){ 451 | try{_min = Double.parseDouble(args[i+1]);} 452 | catch(NumberFormatException e){ returnError("-min",args[i+1],"double");} 453 | }else if(args[i].equals("-sat")){ 454 | try{_saturatedPixel = Double.parseDouble(args[i+1]);} 455 | catch(NumberFormatException e){ returnError("-sat",args[i+1],"double");} 456 | }else if(args[i].equals("-t")){ 457 | try{_thresholdMax =Integer.parseInt(args[i+1]);} 458 | catch(NumberFormatException e){ returnError("-t",args[i+1],"int");} 459 | }else if(args[i].equals("-norm")){ 460 | if(args[i+1].equals("NONE") || args[i+1].equals("VC") 461 | || args[i+1].equals("VC_SQRT") || args[i+1].equals("KR") || args[i+1].equals("SCALE")){ 462 | _juiceBoXNormalisation = args[i+1]; 463 | }else{ 464 | System.out.println("-norm = "+args[i+1]+", not defined\n"); 465 | System.out.println(_doc); 466 | System.exit(0); 467 | } 468 | }else if(args[i].equals("-del")){ 469 | if(args[i+1].equals("true") || args[i+1].equals("T") || args[i+1].equals("TRUE")) 470 | _delImages = true; 471 | else if(args[i+1].equals("false") || args[i+1].equals("F") || args[i+1].equals("False")) 472 | _delImages = false; 473 | else{ 474 | System.out.println("-del = "+args[i+1]+", not defined\n"); 475 | System.out.println(_doc); 476 | System.exit(0); 477 | } 478 | }else if(args[i].equals("-isDroso")){ 479 | if(args[i+1].equals("true") || args[i+1].equals("T") || args[i+1].equals("TRUE")) 480 | _isDroso = true; 481 | else if(args[i+1].equals("false") || args[i+1].equals("F") || args[i+1].equals("False")) 482 | _isDroso = false; 483 | else{ 484 | System.out.println("-_isDroso = "+args[i+1]+", not defined\n"); 485 | System.out.println(_doc); 486 | System.exit(0); 487 | } 488 | }else{ 489 | System.out.println(args[i]+" doesn't existed\n"); 490 | System.out.println(_doc); 491 | System.exit(0); 492 | } 493 | } 494 | } 495 | } 496 | 497 | /** 498 | * Return specific error on function of the argument 499 | * 500 | * @param param String name of the arugment 501 | * @param value String value of the argument 502 | * @param type Strint type of the argument 503 | */ 504 | private static void returnError(String param, String value, String type){ 505 | System.out.println(param+" has to be an integer "+value+" can't be convert in "+type+"\n"); 506 | System.out.println(_doc); 507 | System.exit(0); 508 | } 509 | 510 | 511 | public static boolean testTools(String pathTools, int first, int second, int third) { 512 | Runtime runtime = Runtime.getRuntime(); 513 | String cmd = pathTools+" --version"; 514 | Process process; 515 | try { 516 | process = runtime.exec(cmd); 517 | 518 | new ReturnFlux(process.getInputStream()).start(); 519 | new ReturnFlux(process.getErrorStream()).start(); 520 | process.waitFor(); 521 | 522 | } catch (IOException | InterruptedException e) { 523 | // TODO Auto-generated catch block 524 | e.printStackTrace(); 525 | } 526 | String [] tline = _logError.split(" "); 527 | System.out.println(_logError); 528 | _logError = ""; 529 | if(tline.length > 0){ 530 | tline = tline[tline.length-1].split("\\."); 531 | tline[2] = tline[2].replace("\n", ""); 532 | if(Integer.parseInt(tline[0]) >= first && Integer.parseInt(tline[1]) >= second) 533 | //&& Integer.parseInt(tline[2]) >= third) 534 | return true; 535 | else 536 | return false; 537 | }else 538 | return false; 539 | } 540 | 541 | public static class ReturnFlux extends Thread { 542 | 543 | /** Flux to redirect */ 544 | private InputStream _flux; 545 | 546 | /** 547 | * Constructor of ReturnFlux 548 | * @param flux 549 | * flux to redirect 550 | */ 551 | public ReturnFlux(InputStream flux){this._flux = flux; } 552 | 553 | /** 554 | * 555 | */ 556 | public void run(){ 557 | try { 558 | InputStreamReader reader = new InputStreamReader(this._flux); 559 | BufferedReader br = new BufferedReader(reader); 560 | String line=null; 561 | while ( (line = br.readLine()) != null) { 562 | if(line.contains("WARN")== false) _logError = _logError+line+"\n"; 563 | } 564 | } 565 | catch (IOException ioe){ 566 | ioe.printStackTrace(); 567 | } 568 | } 569 | } 570 | } 571 | -------------------------------------------------------------------------------- /src/main/java/plop/test/TestCallLoopsHicFile.java: -------------------------------------------------------------------------------- 1 | package plop.test; 2 | import java.io.BufferedReader; 3 | import java.io.File; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.InputStreamReader; 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | 11 | import plop.multiProcesing.ProcessHicDumpData; 12 | import plop.process.MultiResProcess; 13 | import plop.utils.SIPObject; 14 | 15 | 16 | 17 | /** 18 | * Test loops calling on Hic file 19 | * 20 | * @author Axel Poulet 21 | * 22 | */ 23 | public class TestCallLoopsHicFile{ 24 | /** 25 | * 26 | * @param args 27 | * @throws IOException 28 | * @throws InterruptedException 29 | */ 30 | static String _logError = ""; 31 | 32 | @SuppressWarnings("unused") 33 | public static void main(String[] args) throws IOException, InterruptedException { 34 | String output = "/home/plop/Desktop/testSip"; 35 | //output= "/home/plop/Bureau/SIPpaper/chr1/testNewNew"; 36 | 37 | String input = "/home/plop/Desktop/GSE255264_MegaMap_q30_hg38_juicer1.hic"; 38 | //input = "/home/plop/Bureau/SIPpaper/hicFileIer_0.hic"; //"https://hicfiles.s3.amazonaws.com/hiseq/gm12878/in-situ/combined_30.hic"; //"; 39 | //String output= "/home/plop/Bureau/DataSetImageHiC/Hichip_H3k4me1"; 40 | //String input= "/home/plop/Bureau/DataSetImageHiC/Hichip_H3k4me1/NT_H3K4me1_2Reps.cis18797450.allValidPairs.hic"; 41 | //HumanGenomeHg19/chr2.size"); 42 | //readChrSizeFile("/home/plop/Documents/Genome/HumanGenomeHg19/hg19_withoutChr.sizes"); 43 | //chrsize = readChrSizeFile("/home/plop/Documents/Genome/mammals/HumanGenomeHg19/chr1.size"); 44 | String fileChr = "/home/plop/Desktop/hg38.chr"; 45 | HashMap chrsize = readChrSizeFile(fileChr); 46 | String juiceBoxTools = "/home/plop/Tools/juicer_tools_1.13.01.jar"; 47 | int matrixSize = 2000; 48 | int resolution = 500; 49 | int diagSize = 5; 50 | double gauss = 1.5; 51 | double min = 2; 52 | double max = 2; 53 | int nbZero = 6; 54 | int thresholdMax = 2800; 55 | String juiceBoXNormalisation = "KR"; 56 | double saturatedPixel = 0.01; 57 | 58 | ArrayList factor = new ArrayList(); 59 | factor.add(1); 60 | //factor.add(2); 61 | //factor.add(5); 62 | boolean keepTif = true; 63 | int cpu = 1; 64 | 65 | System.out.println("input " + input + "\n" 66 | + "output " + output + "\n" 67 | + "juiceBox " + juiceBoxTools + "\n" 68 | + "norm " + juiceBoXNormalisation + "\n" 69 | + "gauss " + gauss + "\n" 70 | + "min " + min + "\n" 71 | + "max " + max + "\n" 72 | + "matrix size " + matrixSize + "\n" 73 | + "diag size " + diagSize + "\n" 74 | + "resolution " + resolution + "\n" 75 | + "saturated pixel " + saturatedPixel + "\n" 76 | + "threshold " + thresholdMax + "\n"); 77 | 78 | File file = new File(output); 79 | if (file.exists() == false) { 80 | file.mkdir(); 81 | } 82 | 83 | SIPObject sip = new SIPObject(output, chrsize, gauss, min, max, 84 | resolution, saturatedPixel, thresholdMax, diagSize, 85 | matrixSize, nbZero, factor, 0.01, keepTif, false); 86 | sip.setIsGui(false); 87 | ProcessHicDumpData processDumpData = new ProcessHicDumpData(); 88 | processDumpData.go(input, sip, chrsize, juiceBoxTools, juiceBoXNormalisation, cpu); 89 | 90 | //MultiResProcess multi = new MultiResProcess(sip, cpu, keepTif,fileChr); 91 | MultiResProcess multi = new MultiResProcess(sip, cpu, false, fileChr); 92 | multi.run(); 93 | //String cooler = "/home/plop/anaconda3/bin/cooler"; 94 | //String cooltools = "/home/plop/anaconda3/bin/cooltools"; 95 | 96 | 97 | System.out.println("End "); 98 | } 99 | 100 | /** 101 | * 102 | * @param chrSizeFile 103 | * @throws IOException 104 | */ 105 | @SuppressWarnings("unused") 106 | private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ 107 | HashMap chrSize = new HashMap(); 108 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 109 | StringBuilder sb = new StringBuilder(); 110 | String line = br.readLine(); 111 | while (line != null){ 112 | sb.append(line); 113 | String[] parts = line.split("\\t"); 114 | String chr = parts[0]; 115 | int size = Integer.parseInt(parts[1]); 116 | chrSize.put(chr, size); 117 | sb.append(System.lineSeparator()); 118 | line = br.readLine(); 119 | } 120 | br.close(); 121 | return chrSize; 122 | } 123 | 124 | public static boolean testTools(String pathTools, int first, int second, int third) { 125 | Runtime runtime = Runtime.getRuntime(); 126 | String cmd = pathTools+" --version"; 127 | //System.out.println(cmd); 128 | Process process; 129 | try { 130 | process = runtime.exec(cmd); 131 | 132 | new ReturnFlux(process.getInputStream()).start(); 133 | new ReturnFlux(process.getErrorStream()).start(); 134 | process.waitFor(); 135 | 136 | } catch (IOException | InterruptedException e) { 137 | // TODO Auto-generated catch block 138 | e.printStackTrace(); 139 | } 140 | String [] tline = _logError.split(" "); 141 | System.out.println(_logError); 142 | if(tline.length > 0){ 143 | //tline[tline.length-1].replaceAll(, "") 144 | 145 | tline = tline[tline.length-1].split("\\."); 146 | System.out.println("aa"+tline[tline.length-3]+"aa"); 147 | System.out.println("aa"+tline[tline.length-2]+"aa"); 148 | System.out.println("aa"+tline[tline.length-1]+"aa"); 149 | tline[tline.length-1] = tline[tline.length-1].replace("\n", ""); 150 | System.out.println("aa"+tline[tline.length-1]+"aa"); 151 | /*int a = Integer.parseInt(tline[tline.length-3]); 152 | int b = Integer.parseInt(tline[tline.length-2]); 153 | int c = Integer.parseInt(tline[tline.length-1]); 154 | if(a >= first && b >= second && c >= third) 155 | return true; 156 | else 157 | return false; 158 | }else*/ 159 | } 160 | return false; 161 | } 162 | 163 | public static class ReturnFlux extends Thread { 164 | 165 | /** Flux to redirect */ 166 | private InputStream _flux; 167 | 168 | /** 169 | * Constructor of ReturnFlux 170 | * @param flux 171 | * flux to redirect 172 | */ 173 | public ReturnFlux(InputStream flux){this._flux = flux; } 174 | 175 | /** 176 | * 177 | */ 178 | public void run(){ 179 | try { 180 | InputStreamReader reader = new InputStreamReader(this._flux); 181 | BufferedReader br = new BufferedReader(reader); 182 | String line=null; 183 | while ( (line = br.readLine()) != null) { 184 | if(line.contains("WARN")== false) _logError = _logError+line+"\n"; 185 | } 186 | } 187 | catch (IOException ioe){ 188 | ioe.printStackTrace(); 189 | } 190 | } 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/plop/test/TestCallLoopsProcessedFile.java: -------------------------------------------------------------------------------- 1 | package plop.test; 2 | import java.io.BufferedReader; 3 | import java.io.FileReader; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | 8 | import plop.process.MultiResProcess; 9 | import plop.utils.SIPObject; 10 | 11 | /** 12 | * Test of calling loops on processed files 13 | * 14 | * @author Axel Poulet 15 | * 16 | */ 17 | public class TestCallLoopsProcessedFile { 18 | 19 | /** 20 | * 21 | * @param args 22 | * @throws IOException 23 | * @throws InterruptedException 24 | */ 25 | public static void main(String[] args) throws IOException, InterruptedException { 26 | String input = "/home/plop/Desktop/testSip"; 27 | String output= "/home/plop/Desktop/testSip"; 28 | int matrixSize = 2000; 29 | int resolution = 500; 30 | int diagSize = 5; 31 | double gauss = 1.5; 32 | int thresholdMax = 2800;// 2800;//1800 33 | int nbZero = 6;//6; 34 | double min = 2;//1.5; 35 | double max = 2;//1.5; 36 | double saturatedPixel = 0.01;//0.005; 37 | //boolean keepTif = false; 38 | ArrayList factor = new ArrayList(); 39 | factor.add(1); 40 | //factor.add(2); 41 | //factor.add(5); 42 | //SIP_HiC_v1.3.6.jar hic SIP/Kc_allcombined.hic SIP/armsizes.txt SIP/Droso/ ../Tools/juicer_tools_1.13.02.jar 43 | String chrSizeFile = "/home/plop/Desktop/hg38.chr"; 44 | HashMap chrsize = readChrSizeFile(chrSizeFile); 45 | SIPObject sip = new SIPObject(input,output, chrsize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,true,false); 46 | sip.setIsGui(false); 47 | int cpu = 2; 48 | System.out.println("Processed Data\n"); 49 | System.out.println("input "+input+"\n" 50 | + "output "+output+"\n" 51 | + "gauss "+gauss+"\n" 52 | + "min "+min+"\n" 53 | + "max "+max+"\n" 54 | + "matrix size "+matrixSize+"\n" 55 | + "diag size "+diagSize+"\n" 56 | + "resolution "+resolution+"\n" 57 | + "saturated pixel "+saturatedPixel+"\n" 58 | + "threshold "+thresholdMax+"\n" 59 | + "isProcessed "+sip.isProcessed()+"\n"); 60 | System.out.println("ahhhhhhhhhhhhh\n"); 61 | MultiResProcess multi = new MultiResProcess(sip, cpu, false,chrSizeFile); 62 | multi.run(); 63 | //ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); 64 | //processDetectloops.go(sip, 2,false); 65 | //Testpb plop = new Testpb(sip, true); 66 | //plop.run(2); 67 | System.out.println("End"); 68 | } 69 | 70 | /** 71 | * 72 | * @param chrSizeFile 73 | * @return 74 | * @throws IOException 75 | */ 76 | private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ 77 | HashMap chrSize = new HashMap(); 78 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 79 | StringBuilder sb = new StringBuilder(); 80 | String line = br.readLine(); 81 | while (line != null){ 82 | sb.append(line); 83 | String[] parts = line.split("\\t"); 84 | String chr = parts[0]; 85 | int size = Integer.parseInt(parts[1]); 86 | 87 | chrSize.put(chr, size); 88 | sb.append(System.lineSeparator()); 89 | line = br.readLine(); 90 | } 91 | br.close(); 92 | return chrSize; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/plop/test/TestCoolFormat.java: -------------------------------------------------------------------------------- 1 | package plop.test; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import plop.multiProcesing.ProcessCoolerDumpData; 10 | import plop.process.CoolerDumpData; 11 | import plop.process.MultiResProcess; 12 | import plop.utils.CoolerExpected; 13 | import plop.utils.SIPObject; 14 | @SuppressWarnings("unused") 15 | public class TestCoolFormat { 16 | 17 | public static void main(String[] args) throws IOException, InterruptedException { 18 | String chr = "chr21"; 19 | //String input = "/home/plop/Desktop/SIP/testCooler/GM12878_4DNFIXP4QG5B.mcool"; 20 | String input = "//home/plop/Desktop/coolTest/MCF7_863.mcool"; 21 | String output = "/home/plop/Desktop/coolTest/test"; 22 | String expectedFile = "/home/plop/Desktop/coolTest/test/expected.txt"; 23 | String fileChr = "/home/plop/Desktop/coolTest/chr22.txt"; 24 | String cooler = "/home/plop/anaconda3/envs/cooler/bin/cooler"; 25 | String cooltools = "/home/plop/anaconda3/envs/cooler/bin/cooltools"; 26 | HashMap chrsize = readChrSizeFile(fileChr); 27 | int resolution = 40000; 28 | int matrixSize = 2000; 29 | int cpu = 5; 30 | //CoolerExpected expected = new CoolerExpected(cooltools, input, resolution, matrixSize,cpu); 31 | //expected.dumpExpected(expectedFile); 32 | //CoolerExpected expected = new CoolerExpected(expectedFile, matrixSize); 33 | //expected.parseExpectedFile(); 34 | //ArrayList plop = expected.getExpected(chr); 35 | //CoolerDumpData coolerD = new CoolerDumpData(cooler,input); 36 | //run(resolution,matrixSize,matrixSize/2,chr,output, cooler, 46709983); 37 | 38 | int diagSize = 5; 39 | double gauss = 1.5; 40 | double min = 2; 41 | double max = 2; 42 | int nbZero = 6; 43 | int thresholdMax = 2800; 44 | double saturatedPixel = 0.01; 45 | ArrayList factor = new ArrayList(); 46 | factor.add(1); 47 | //factor.add(2); 48 | //factor.add(5); 49 | boolean keepTif = true; 50 | 51 | 52 | SIPObject sip = new SIPObject(input,output, chrsize, gauss, min, max, resolution, saturatedPixel, thresholdMax, 53 | diagSize, matrixSize, nbZero,factor,0.03,keepTif,false); 54 | sip.setIsGui(false); 55 | sip.setIsCooler(true); 56 | sip.setIsProcessed(false); 57 | 58 | 59 | ProcessCoolerDumpData processDumpData = new ProcessCoolerDumpData(); 60 | //go(String coolTools, String cooler, SIPObject sip, String coolFile, HashMap chrSize,int nbCPU) 61 | processDumpData.go(cooltools, cooler, sip, input, chrsize,2); 62 | MultiResProcess multi = new MultiResProcess(sip, cpu, keepTif,fileChr); 63 | multi.run(); 64 | 65 | System.out.println("end"); 66 | 67 | } 68 | 69 | /** 70 | * 71 | * @param chrSizeFile 72 | * @return 73 | * @throws IOException 74 | */ 75 | private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ 76 | HashMap chrSize = new HashMap(); 77 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 78 | StringBuilder sb = new StringBuilder(); 79 | String line = br.readLine(); 80 | while (line != null){ 81 | sb.append(line); 82 | String[] parts = line.split("\\t"); 83 | String chr = parts[0]; 84 | int size = Integer.parseInt(parts[1]); 85 | chrSize.put(chr, size); 86 | sb.append(System.lineSeparator()); 87 | line = br.readLine(); 88 | } 89 | br.close(); 90 | return chrSize; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/plop/test/TestGui.java: -------------------------------------------------------------------------------- 1 | package plop.test; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | 9 | import plop.gui.GuiAnalysis; 10 | import plop.multiProcesing.ProcessHicDumpData; 11 | import plop.utils.SIPObject; 12 | 13 | 14 | /** 15 | * plop.test of the GUI 16 | * 17 | * @author Axel Poulet 18 | * 19 | */ 20 | public class TestGui { 21 | 22 | /** 23 | * @param args 24 | * @throws IOException 25 | * @throws InterruptedException 26 | */ 27 | public static void main(String[] args) throws IOException, InterruptedException{ 28 | SIPObject sip ; 29 | GuiAnalysis gui = new GuiAnalysis(); 30 | while( gui.isShowing()){ 31 | try {Thread.sleep(1);} 32 | catch (InterruptedException e) {e.printStackTrace();} 33 | } 34 | if (gui.isStart()){ 35 | System.out.println("plop/test"); 36 | String output = gui.getOutputDir(); 37 | String input = gui.getRawDataDir(); 38 | int matrixSize = gui.getMatrixSize(); 39 | int diagSize = gui.getDiagSize(); 40 | int resolution = gui.getResolution(); 41 | double gauss = gui.getGaussian(); 42 | double max = gui.getMax(); 43 | double min = gui.getMin(); 44 | double saturatedPixel = gui.getEnhanceSignal(); 45 | int thresholdMax = gui.getNoiseTolerance(); 46 | boolean isHic = gui.isHic(); 47 | boolean isProcessed = gui.isProcessed(); 48 | String juiceBoxTools = gui.getJuiceBox(); 49 | String juiceBoXNormalisation = "KR"; 50 | if(gui.isNONE()) juiceBoXNormalisation = "NONE"; 51 | else if (gui.isVC()) juiceBoXNormalisation = "VC"; 52 | else if (gui.isVC_SQRT()) juiceBoXNormalisation = "VC_SQRT"; 53 | int nbZero = gui.getNbZero(); 54 | 55 | ArrayList factor = new ArrayList(); 56 | factor.add(1); 57 | //factor.add(2); 58 | HashMap chrSize = readChrSizeFile(gui.getChrSizeFile()); 59 | 60 | if(gui.isProcessed()==false){ 61 | System.out.println("hic mode:\ninput: "+input+"\noutput: "+output+"\njuiceBox: "+juiceBoxTools+"\nnorm: "+ juiceBoXNormalisation+"\ngauss: "+gauss+"\n" 62 | + "min: "+min+"\nmax: "+max+"\nmatrix size: "+matrixSize+"\ndiag size: "+diagSize+"\nresolution: "+resolution+"\nsaturated pixel: "+saturatedPixel 63 | +"\nthreshold: "+thresholdMax+"\n number of zero:"+nbZero+"\n "); 64 | sip = new SIPObject(output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,gui.isProcessed(),false); 65 | sip.setIsGui(true); 66 | ProcessHicDumpData processDumpData = new ProcessHicDumpData(); 67 | processDumpData.go(input, sip, chrSize, juiceBoxTools, juiceBoXNormalisation,gui.getNbCpu()); 68 | }else{ 69 | System.out.println("processed mode:\ninput: "+input+"\noutput: "+output+"\njuiceBox: "+juiceBoxTools+"\nnorm: "+ juiceBoXNormalisation+"\ngauss: "+gauss 70 | +"\nmin: "+min+"\nmax: "+max+"\nmatrix size: "+matrixSize+"\ndiag size: "+diagSize+"\nresolution: "+resolution+"\nsaturated pixel: "+saturatedPixel 71 | +"\nthreshold: "+thresholdMax+"\nisHic: "+isHic+"\nisProcessed: "+isProcessed+"\n number of zero:" 72 | +nbZero+"\n"); 73 | sip = new SIPObject(input,output, chrSize, gauss, min, max, resolution, saturatedPixel, thresholdMax, diagSize, matrixSize, nbZero,factor,0.01,gui.isProcessed(),false); 74 | sip.setIsGui(true); 75 | } 76 | 77 | //ProcessDetectLoops processDetectloops = new ProcessDetectLoops(); 78 | //processDetectloops.go(sip, plop.gui.getNbCpu(),plop.gui.isDeletTif()); 79 | 80 | } 81 | } 82 | 83 | /** 84 | * Run the input file and stock the info of name chr and their size in hashmap 85 | * @param chrSizeFile path chr size file 86 | * @throws IOException if file does't exist 87 | */ 88 | private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ 89 | HashMap m_chrSize = new HashMap(); 90 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 91 | StringBuilder sb = new StringBuilder(); 92 | String line = br.readLine(); 93 | while (line != null){ 94 | sb.append(line); 95 | String[] parts = line.split("\\t"); 96 | String chr = parts[0]; 97 | int size = Integer.parseInt(parts[1]); 98 | m_chrSize.put(chr, size); 99 | sb.append(System.lineSeparator()); 100 | line = br.readLine(); 101 | } 102 | br.close(); 103 | return m_chrSize; 104 | } 105 | } -------------------------------------------------------------------------------- /src/main/java/plop/test/TestMergeLoops.java: -------------------------------------------------------------------------------- 1 | package plop.test; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileReader; 7 | import java.io.FileWriter; 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.HashMap; 11 | import java.util.Iterator; 12 | import java.util.List; 13 | import java.util.Set; 14 | import java.util.stream.Collectors; 15 | 16 | import plop.utils.Loop; 17 | 18 | public class TestMergeLoops { 19 | 20 | 21 | /** 22 | * 23 | * @param args 24 | * @throws IOException 25 | * @throws InterruptedException 26 | */ 27 | public static void main(String[] args) throws IOException, InterruptedException { 28 | ArrayList listOfFile = new ArrayList (); 29 | 30 | listOfFile.add("/home/plop/Desktop/chr11/5kbLoops.txt"); 31 | listOfFile.add("/home/plop/Desktop/chr11/10kbLoops.txt"); 32 | listOfFile.add("/home/plop/Desktop/chr11/25kbLoops.txt"); 33 | mergedFile(listOfFile); 34 | System.out.println("End"); 35 | } 36 | /** 37 | * @throws IOException 38 | * 39 | */ 40 | private static void mergedFile(ArrayList listOfFile) throws IOException{ 41 | //chromosome1 x1 x2 chromosome2 y1 y2 color APScoreAvg ProbabilityofEnrichment RegAPScoreAvg Avg_diffMaxNeihgboor_1 Avg_diffMaxNeihgboor_2 avg std value 42 | //22 33915000 33920000 22 34510000 34515000 0,0,0 5.228523 0.99861 2.336731 3.4115214 3.979847 3.546672 1.5443684 6.5791354 43 | //HashMap data = new HashMap(); 44 | HashMap chrsize = readChrSizeFile("/home/plop/Desktop/w_hg19.sizes"); 45 | Set key = chrsize.keySet(); 46 | ArrayList > data = new ArrayList >(); 47 | for (int i = 0; i < key.size();++i) { 48 | HashMap plop = new HashMap(); 49 | data.add(plop); 50 | } 51 | 52 | BufferedReader br = new BufferedReader(new FileReader(listOfFile.get(0))); 53 | StringBuilder sb = new StringBuilder(); 54 | String line = br.readLine(); 55 | String title = line; 56 | sb.append(System.lineSeparator()); 57 | line = br.readLine(); 58 | while (line != null){ 59 | sb.append(line); 60 | Loop loop = new Loop(line); 61 | String chr = loop.getChr(); 62 | int index = chrsize.get(chr); 63 | HashMap plop = data.get(index); 64 | plop.put(line, loop); 65 | data.set(index, plop); 66 | sb.append(System.lineSeparator()); 67 | line = br.readLine(); 68 | } 69 | br.close(); 70 | 71 | for (int i = 1; i < listOfFile.size();++i) { 72 | br = new BufferedReader(new FileReader((listOfFile.get(i)))); 73 | sb = new StringBuilder(); 74 | line = br.readLine(); 75 | sb.append(System.lineSeparator()); 76 | line = br.readLine(); 77 | while (line != null){ 78 | Loop loop = new Loop(line); 79 | String chr = loop.getChr(); 80 | int index = chrsize.get(chr); 81 | HashMap plop = data.get(index); 82 | if(compareLoop(plop,loop)){ 83 | plop.put(line,loop); 84 | data.set(index, plop); 85 | } 86 | sb.append(System.lineSeparator()); 87 | line = br.readLine(); 88 | } 89 | br.close(); 90 | } 91 | 92 | BufferedWriter writer; 93 | writer = new BufferedWriter(new FileWriter(new File("/home/plop/Desktop/chr11/finalLoops.txt"))); 94 | writer.write(title+"\n"); 95 | for (int i = 0; i < data.size();++i){ 96 | HashMap plop = data.get(i); 97 | Set keyBis = plop.keySet(); 98 | List output = keyBis.stream().collect(Collectors.toList()); 99 | 100 | for (int j = 0; j < output.size();++j){ 101 | writer.write(output.get(j)+"\n"); 102 | } 103 | } 104 | writer.close(); 105 | } 106 | 107 | 108 | 109 | private static boolean compareLoop(HashMap plop, Loop a) { 110 | Set key = plop.keySet(); 111 | Iterator it = key.iterator(); 112 | while (it.hasNext()){ 113 | String loopName = it.next(); 114 | Loop loop = plop.get(loopName); 115 | int xEnd = loop.getCoordinates().get(1); 116 | int yEnd = loop.getCoordinates().get(3); 117 | 118 | 119 | int xtest = a.getCoordinates().get(0); 120 | int xtestEnd = a.getCoordinates().get(1); 121 | 122 | int res = xtestEnd-xtest; 123 | int ytest = a.getCoordinates().get(2); 124 | int ytestEnd = a.getCoordinates().get(3); 125 | xtest = xtest-res*2; 126 | xtestEnd = xtestEnd+res*2; 127 | ytest = ytest-res*2; 128 | ytestEnd = ytestEnd+res*2; 129 | //System.out.println(x+"\t"+xEnd+"\t"+ xtestEnd); 130 | if((xtest <= xEnd && xtestEnd >= xEnd) && (ytest <= yEnd && ytestEnd >= yEnd)){ 131 | return false; 132 | 133 | } 134 | } 135 | return true; 136 | } 137 | /** 138 | * 139 | * @param chrSizeFile 140 | * @return 141 | * @throws IOException 142 | */ 143 | private static HashMap readChrSizeFile( String chrSizeFile) throws IOException{ 144 | HashMap chrSize = new HashMap(); 145 | BufferedReader br = new BufferedReader(new FileReader(chrSizeFile)); 146 | StringBuilder sb = new StringBuilder(); 147 | String line = br.readLine(); 148 | int i = 0; 149 | while (line != null){ 150 | sb.append(line); 151 | String[] parts = line.split("\\t"); 152 | String chr = parts[0]; 153 | chrSize.put(chr, i); 154 | sb.append(System.lineSeparator()); 155 | line = br.readLine(); 156 | ++i; 157 | } 158 | br.close(); 159 | return chrSize; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/CoolerExpected.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | import java.nio.charset.StandardCharsets; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | 13 | public class CoolerExpected { 14 | 15 | /** String to store the error if needed of juicerboxtool.jar*/ 16 | private String _logError = ""; 17 | /** String for the log*/ 18 | private String _log = ""; 19 | /** path to the hic file or url link*/ 20 | private String _coolFile = ""; 21 | /** List of double to stock the expected vector*/ 22 | private int _resolution = 0; 23 | private int _imgSize = 0; 24 | private String _expected; 25 | private String _coolTools = ""; 26 | private HashMap> _hashExpected = new HashMap>(); 27 | private int _cpu; 28 | 29 | 30 | public CoolerExpected(String cooltools, String coolFile, int resolution, int imageSize, int cpu){ 31 | _coolTools = cooltools; 32 | this._resolution = resolution; 33 | this._imgSize = imageSize; 34 | this._coolFile = coolFile+"::/resolutions/"+this._resolution; 35 | _cpu = cpu; 36 | } 37 | 38 | public CoolerExpected(String expectedFile, int imageSize){ 39 | this._imgSize = imageSize; 40 | this._expected = expectedFile; 41 | } 42 | 43 | /** 44 | * 45 | * @param expected 46 | * @return 47 | */ 48 | public boolean dumpExpected(String expected){ 49 | int exitValue=1; 50 | Runtime runtime = Runtime.getRuntime(); 51 | String cmd = this._coolTools+" compute-expected "+_coolFile+" -p "+_cpu+" --drop-diags 0 -o "+expected; 52 | this._log = this._log+"\n"+expected+"\t"+cmd; 53 | Process process; 54 | System.out.println("Start cooltools compute-expected"); 55 | try { 56 | process = runtime.exec(cmd); 57 | new ReturnFlux(process.getInputStream()).start(); 58 | new ReturnFlux(process.getErrorStream()).start(); 59 | exitValue=process.waitFor(); 60 | if(_logError.contains("Error") && _logError.contains("--drop-diags")){ 61 | runtime = Runtime.getRuntime(); 62 | _logError =""; 63 | System.out.println(_logError); 64 | cmd = this._coolTools+" compute-expected "+_coolFile+" -p "+_cpu+" --ignore-diags 0 -o "+expected; 65 | System.out.println(cmd); 66 | process = runtime.exec(cmd); 67 | 68 | new ReturnFlux(process.getInputStream()).start(); 69 | new ReturnFlux(process.getErrorStream()).start(); 70 | exitValue=process.waitFor(); 71 | 72 | if(_logError.contains("Error")){ 73 | System.out.println(_logError); 74 | System.out.println("cooltools error !!!!"); 75 | System.exit(0); 76 | } 77 | }else if(_logError.contains("Error") && _logError.contains("No such command")){ 78 | runtime = Runtime.getRuntime(); 79 | _logError =""; 80 | System.out.println(_logError); 81 | cmd = this._coolTools+" expected-cis "+_coolFile+" -p "+_cpu+" --ignore-diags 0 -o "+expected; 82 | System.out.println(cmd); 83 | process = runtime.exec(cmd); 84 | 85 | new ReturnFlux(process.getInputStream()).start(); 86 | new ReturnFlux(process.getErrorStream()).start(); 87 | exitValue=process.waitFor(); 88 | 89 | if(_logError.contains("Error")){ 90 | System.out.println(_logError); 91 | System.out.println("cooltools error !!!!"); 92 | System.exit(0); 93 | } 94 | } 95 | this._expected = expected; 96 | this.parseExpectedFile(); 97 | } catch (IOException | InterruptedException e) { 98 | e.printStackTrace(); 99 | } 100 | 101 | return exitValue==0; 102 | } 103 | 104 | 105 | 106 | public void parseExpectedFile() throws IOException { 107 | BufferedReader br = Files.newBufferedReader(Paths.get(_expected), StandardCharsets.UTF_8); 108 | String line = br.readLine(); 109 | for (line = null; (line = br.readLine()) != null;){ 110 | String [] tline = line.split("\t"); 111 | int a = Integer.parseInt(tline[2]); 112 | if(!tline[1].equals(tline[0])) 113 | a = Integer.parseInt(tline[2]); 114 | if(a < this._imgSize) { 115 | if(!tline[tline.length-1].equals("nan")){ 116 | if (_hashExpected.containsKey(tline[0])){ 117 | ArrayList lExpected = _hashExpected.get(tline[0]); 118 | lExpected.add(Double.parseDouble(tline[tline.length-1])); 119 | _hashExpected.put(tline[0], lExpected); 120 | }else { 121 | ArrayList lExpected = new ArrayList(); 122 | lExpected.add(Double.parseDouble(tline[tline.length-1])); 123 | _hashExpected.put(tline[0], lExpected); 124 | } 125 | }else { 126 | double value =0; 127 | if (_hashExpected.containsKey(tline[0])){ 128 | ArrayList lExpected = _hashExpected.get(tline[0]); 129 | lExpected.add(value); 130 | _hashExpected.put(tline[0], lExpected); 131 | }else { 132 | ArrayList lExpected = new ArrayList(); 133 | lExpected.add(value); 134 | _hashExpected.put(tline[0], lExpected); 135 | } 136 | } 137 | } 138 | } 139 | br.close(); 140 | } 141 | 142 | /** 143 | * getter of the expected matrix. 144 | * 145 | * @param chr 146 | * @return 147 | * @throws IOException 148 | */ 149 | public ArrayList getExpected(String chr) throws IOException{ 150 | return this._hashExpected.get(chr); 151 | 152 | } 153 | 154 | 155 | 156 | /** 157 | * getter of the logerror file if necessary 158 | * 159 | * @return return the String with the error 160 | */ 161 | public String getLogError(){ return this._logError;} 162 | 163 | /** 164 | * getter of the log info if necessary 165 | * @return return a String with the log info 166 | */ 167 | public String getLog(){ return this._log;} 168 | /** 169 | * Class to run command line in java 170 | * @author axel poulet 171 | * 172 | */ 173 | public class ReturnFlux extends Thread { 174 | 175 | /** Flux to redirect */ 176 | private InputStream _flux; 177 | 178 | /** 179 | * Constructor of ReturnFlux 180 | * @param flux 181 | * flux to redirect 182 | */ 183 | public ReturnFlux(InputStream flux){this._flux = flux; } 184 | 185 | /** 186 | * 187 | */ 188 | public void run(){ 189 | try { 190 | InputStreamReader reader = new InputStreamReader(this._flux); 191 | BufferedReader br = new BufferedReader(reader); 192 | String line=null; 193 | while ( (line = br.readLine()) != null) { 194 | if(line.contains("WARN")== false) _logError = _logError+line+"\n"; 195 | } 196 | } 197 | catch (IOException ioe){ 198 | ioe.printStackTrace(); 199 | } 200 | } 201 | } 202 | 203 | 204 | } 205 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/CoordinatesCorrection.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Iterator; 5 | import java.util.Set; 6 | 7 | /** 8 | * Class to change the image coordinate in genome coordinate, with the name of the image, the resolution, the size of the image, 9 | * the step and the size of the diagonal. 10 | * 11 | * Loops detected with white strips are removed. Furthermore the corner of the images are not take account. We plop.test also the proximal loops to avoid overlaping loops. 12 | * 13 | * @author axel poulet 14 | * 15 | */ 16 | public class CoordinatesCorrection { 17 | 18 | /** HashMap of the loops with new coordinates*/ 19 | private HashMap _data = new HashMap(); 20 | 21 | /** 22 | * 23 | */ 24 | public CoordinatesCorrection(){ } 25 | 26 | /** 27 | * change loop image coordinates in loop genomes coordinates, 28 | * 29 | * @param temp: HashMap of loops with the image coordinates 30 | * @param index: index of the image 31 | * @return HashMap: key is a string with the name of the chr start end. And value is Loop class, to stock 32 | * the loop characteristics. 33 | */ 34 | public HashMap imageToGenomeCoordinate(HashMap temp, int index,int step){ 35 | int x; 36 | int y; 37 | Set key = temp.keySet(); 38 | Iterator it = key.iterator(); 39 | while (it.hasNext()){ 40 | Loop loop = temp.get(it.next()); 41 | x = loop.getX(); 42 | y = loop.getY(); 43 | int resolution = loop.getResolution(); 44 | int diagSize = loop.getDiagonalSize()*resolution; 45 | int imageSize = loop.getMatrixSize(); 46 | 47 | int a = (x+(index*step))*resolution; 48 | int a_end = a+resolution; 49 | int b = (y+(index*step))*resolution; 50 | int b_end =b+resolution; 51 | String newName = loop.getChr()+"\t"+a+"\t"+b; 52 | if(a!=b && Math.abs(a-b) > diagSize){ 53 | if (x > 1 && y > 1 && y < imageSize-2 && x < imageSize-2){ 54 | if(!this._data.containsKey(newName)){ 55 | loop.setCoordinates(a, a_end, b, b_end); 56 | loop.setName(newName); 57 | //System.out.println(newName+" "+resolution+" "+step+" "+index+" "+x); 58 | this._data.put(newName, loop); 59 | }else{ 60 | if(loop.getPaScoreAvg()> this._data.get(newName).getPaScoreAvg()){ 61 | loop.setCoordinates(a, a_end, b, b_end); 62 | loop.setName(newName); 63 | //System.out.println("!!!!!!!! "+newName); 64 | this._data.put(newName, loop); 65 | } 66 | } 67 | } 68 | } 69 | } 70 | return this._data; 71 | } 72 | 73 | /** 74 | * getter of m_data 75 | * @return HashMap of loops 76 | */ 77 | public HashMap getData(){ return this._data;} 78 | 79 | /** 80 | * setter of m_data 81 | * @param data 82 | */ 83 | public void setData(HashMap data){ this._data = data;} 84 | } -------------------------------------------------------------------------------- /src/main/java/plop/utils/DecayAnalysis.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import ij.ImagePlus; 4 | import ij.process.ImageProcessor; 5 | 6 | /** 7 | * Class for the loop decay analysis. Take in input the raw imagePlus, and the loop coordinates. 8 | * Compute the average between the loop and the neighbourhood 8 or 24. 9 | * @author Axel Poulet 10 | * 11 | */ 12 | public class DecayAnalysis { 13 | /**raw imagePlus */ 14 | private ImagePlus _img; 15 | /** x coordinate's of the loop of interest*/ 16 | private int _x; 17 | /** y coordinate's of the loop of interest*/ 18 | private int _y; 19 | 20 | /** 21 | * DecayAnalysis constructor. 22 | * 23 | * @param img: ImagePlus the raw image 24 | * @param x: int for the x coordinate of the loop 25 | * @param y: int for the y coordinate of the loop 26 | */ 27 | public DecayAnalysis(ImagePlus img, int x, int y){ 28 | this._x = x; 29 | this._y = y; 30 | this._img = img; 31 | } 32 | 33 | /** 34 | * getter computing the average difference between the loop value and the neighbourhood 8 values 35 | * @return double stocking the average differential value of the neighbourhood 8. 36 | */ 37 | public float getNeighbourhood1(){return computeDiff(1);} 38 | 39 | /** 40 | * getter computing the average difference between the loop value and the neighbourhood 24 values (exclude 41 | * the values of the 8 neighbourhood) 42 | * @return double stocking the average differential value of the neighbourhood 24. 43 | */ 44 | public float getNeighbourhood2(){return computeDiff(2);} 45 | 46 | 47 | /** 48 | * getter computing the average difference between the loop value and the neighbourhood 24 values (exclude 49 | * the values of the 8 neighbourhood) 50 | * @return double stocking the average differential value of the neighbourhood 24. 51 | */ 52 | public float getNeighbourhood3(){return computeDiff(3);} 53 | 54 | /** 55 | * Private method computing the average difference between the loop value and the chosen neighbourhood. 56 | * @param c int; stock the choice: 1 = neighbourhood 8; 2 = neighbourhood 24 57 | * @return double differential average 58 | */ 59 | private float computeDiff (int c){ 60 | float sum = 0; 61 | ImageProcessor ip = this._img.getProcessor(); 62 | int nb = 0; 63 | for(int i = this._x-c; i <= this._x+c; ++i){ 64 | for(int j = this._y-c ; j <= this._y+c; ++j){ 65 | if((i != this._x || j != this._y) && (i-this._x == -c || j-this._y == -c || i-this._x == c || j-this._y == c)){ 66 | if(i >=0 && j>= 0 && i < ip.getWidth() && j < ip.getHeight()){ 67 | double a = ip.getf(this._x, this._y)- ip.getf(i, j); 68 | sum+= a; 69 | ++nb; 70 | } 71 | } 72 | } 73 | } 74 | sum = sum/nb; 75 | return sum; 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/java/plop/utils/FDR.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashMap; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | /** 11 | * 12 | * @author m. jordan rowley and axel poulet 13 | * 14 | */ 15 | public class FDR { 16 | /** */ 17 | private double _rFdrCutoff = 10000; 18 | /** */ 19 | private double _fdrCutoff = 10000; 20 | 21 | /** 22 | * 23 | */ 24 | public FDR(){} 25 | 26 | /** 27 | * 28 | * @param fdr 29 | * @param data 30 | */ 31 | public void run(double fdr,HashMap data){ 32 | Set key = data.keySet(); 33 | Iterator it = key.iterator(); 34 | List myFdrVals = new ArrayList(); 35 | List myRFdrVals = new ArrayList(); 36 | 37 | while (it.hasNext()) { 38 | String loopName = it.next(); 39 | Loop loop = data.get(loopName); 40 | 41 | float dubFDR = loop.getPaScoreAvgFDR(); 42 | float dubFDR2 = loop.getPaScoreAvgFDR2(); 43 | float dubFDR3 = loop.getPaScoreAvgFDR3(); 44 | 45 | if(dubFDR > 0) myFdrVals.add(dubFDR); 46 | if(dubFDR2 > 0) myFdrVals.add(dubFDR2); 47 | if(dubFDR3 > 0) myFdrVals.add(dubFDR3); 48 | 49 | 50 | float dubRFDR = loop.getRegionalPaScoreAvgFDR(); 51 | float dubRFDR2 = loop.getRegionalPaScoreAvgFDR2(); 52 | float dubRFDR3 = loop.getRegionalPaScoreAvgFDR3(); 53 | 54 | if(dubRFDR > 0) myRFdrVals.add(dubRFDR); 55 | if(dubRFDR2 > 0) myRFdrVals.add(dubRFDR2); 56 | if(dubRFDR3 > 0) myRFdrVals.add(dubRFDR3); 57 | } 58 | 59 | Collections.sort(myFdrVals); 60 | int topFDRs = (int)(myFdrVals.size()*fdr); 61 | if(topFDRs != 0){ 62 | List topFDRlist = new ArrayList(myFdrVals.subList(myFdrVals.size() -topFDRs, 63 | myFdrVals.size() -(topFDRs-1))); 64 | this._fdrCutoff = topFDRlist.get(0); 65 | Collections.sort(myRFdrVals); 66 | int topRFDRs = (int)(myRFdrVals.size()*fdr); 67 | List topRFDRlist = new ArrayList(myRFdrVals.subList(myRFdrVals.size() -topRFDRs, 68 | myRFdrVals.size() -(topRFDRs-1))); 69 | this._rFdrCutoff = topRFDRlist.get(0); 70 | } 71 | } 72 | 73 | /** 74 | * 75 | * @return 76 | */ 77 | public double getRFDRcutoff() { return _rFdrCutoff; } 78 | 79 | /** 80 | * 81 | * @return 82 | */ 83 | public double getFDRcutoff() { return _fdrCutoff; } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/FilterLoops.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.Set; 7 | 8 | /** 9 | * Method to filter the loops close to white strip or loops which don't reach the different threshold filter 10 | * @author axel poulet 11 | * 12 | */ 13 | public class FilterLoops { 14 | /** loops resolution*/ 15 | private int _resolution; 16 | 17 | 18 | /** 19 | * Constructor 20 | * @param resolution 21 | */ 22 | public FilterLoops(int resolution){ 23 | this._resolution = resolution; 24 | } 25 | 26 | 27 | /** 28 | * Remove loops which doesn't respect the rule 29 | * 30 | * @param input loop collection before correction 31 | * @return loop collection after correction 32 | */ 33 | public HashMap removedBadLoops(HashMap input){ 34 | Set key = input.keySet(); 35 | Iterator it = key.iterator(); 36 | ArrayList removed = new ArrayList(); 37 | while (it.hasNext()){ 38 | String name = it.next(); 39 | Loop loop = input.get(name); 40 | if(!(removed.contains(name))){ 41 | // filter on APA score and APA regional score 42 | if(loop.getPaScoreAvg() < 1.2 || loop.getRegionalPaScoreAvg() < 1 ) 43 | removed.add(name); 44 | else 45 | removed = removeOverlappingLoops(loop,input,removed); 46 | } 47 | } 48 | for (int i = 0; i< removed.size(); ++i) 49 | input.remove(removed.get(i)); 50 | return input; 51 | } 52 | 53 | /** 54 | * Removed loop close to white strip 55 | * 56 | * @param hLoop loop collection before correction of the loops 57 | * @return loop collection after correction of the loops 58 | */ 59 | public HashMap removedLoopCloseToWhiteStrip( 60 | HashMap hLoop, HashMap normVector){ 61 | //System.out.println("plop "+hLoop.size()+" debut Filter"); 62 | Set key = hLoop.keySet(); 63 | Iterator it = key.iterator(); 64 | ArrayList removed = new ArrayList(); 65 | while (it.hasNext()){ 66 | String name = it.next(); 67 | Loop loop = hLoop.get(name); 68 | Boolean testRemoved = removedVectoNorm(loop,normVector); 69 | boolean testBreak = false; 70 | if(testRemoved) 71 | removed.add(name); 72 | else{ 73 | String [] tname = name.split("\t"); 74 | //System.out.println(name); 75 | int x = Integer.parseInt(tname[1]); 76 | int y = Integer.parseInt(tname[2]); 77 | for(int i = x-5*this._resolution; i <= x+5*this._resolution; i+=this._resolution){ 78 | for(int j = y-5*this._resolution; j <= y+5*this._resolution; j+=this._resolution){ 79 | String test = tname[0]+"\t"+i+"\t"+j; 80 | if(!test.equals(name)){ 81 | if(hLoop.containsKey(test)){ 82 | if(hLoop.get(test).getResolution() < hLoop.get(name).getResolution()){ 83 | removed.add(name); 84 | testBreak =true; 85 | break; 86 | }else if(hLoop.get(test).getResolution() == hLoop.get(name).getResolution()){ 87 | if((Math.abs(x-hLoop.get(test).getX()) < this._resolution*3 || 88 | Math.abs(y-hLoop.get(test).getY()) < this._resolution*3)){ 89 | if(hLoop.get(test).getAvg() > hLoop.get(name).getAvg()){ 90 | removed.add(name); 91 | testBreak =true; 92 | break; 93 | }else if(hLoop.get(test).getAvg() < hLoop.get(name).getAvg()) 94 | removed.add(test); 95 | else{ 96 | if(hLoop.get(test).getPaScoreAvg() > hLoop.get(name).getPaScoreAvg()){ 97 | removed.add(name); 98 | testBreak =true; 99 | break; 100 | }else 101 | removed.add(test); 102 | } 103 | } 104 | }else 105 | removed.add(test); 106 | } 107 | } 108 | } 109 | if(testBreak) 110 | break; 111 | } 112 | } 113 | } 114 | for (int i = 0; i< removed.size(); ++i) 115 | hLoop.remove(removed.get(i)); 116 | //System.out.println("####### fin Filter "+hLoop.size()); 117 | return hLoop; 118 | } 119 | 120 | 121 | /** 122 | * Removed loop close to white strip 123 | * 124 | * @param hLoop loop collection before correction of the loops 125 | * @return loop collection sfter correction of the loops 126 | */ 127 | public HashMap removedLoopCloseToWhiteStrip(HashMap hLoop){ 128 | //System.out.println("plop "+hLoop.size()+" debut Filter"); 129 | Set key = hLoop.keySet(); 130 | Iterator it = key.iterator(); 131 | ArrayList removed = new ArrayList(); 132 | while (it.hasNext()){ 133 | String name = it.next(); 134 | //Loop loop = hLoop.get(name); 135 | boolean testBreak = false; 136 | String [] tname = name.split("\t"); 137 | //System.out.println(name); 138 | int x = Integer.parseInt(tname[1]); 139 | int y = Integer.parseInt(tname[2]); 140 | for(int i = x-5*this._resolution; i <= x+5*this._resolution; i+=this._resolution){ 141 | for(int j = y-5*this._resolution; j <= y+5*this._resolution; j+=this._resolution){ 142 | String test = tname[0]+"\t"+i+"\t"+j; 143 | if(!test.equals(name)){ 144 | if(hLoop.containsKey(test)){ 145 | if(hLoop.get(test).getResolution() < hLoop.get(name).getResolution()){ 146 | removed.add(name); 147 | testBreak =true; 148 | break; 149 | }else if(hLoop.get(test).getResolution() == hLoop.get(name).getResolution()){ 150 | if((Math.abs(x-hLoop.get(test).getX()) < this._resolution*3 || 151 | Math.abs(y-hLoop.get(test).getY()) < this._resolution*3)){ 152 | if(hLoop.get(test).getAvg() > hLoop.get(name).getAvg()){ 153 | removed.add(name); 154 | testBreak =true; 155 | break; 156 | }else if(hLoop.get(test).getAvg() < hLoop.get(name).getAvg()) 157 | removed.add(test); 158 | else{ 159 | if(hLoop.get(test).getPaScoreAvg() > hLoop.get(name).getPaScoreAvg()){ 160 | removed.add(name); 161 | testBreak =true; 162 | break; 163 | }else 164 | removed.add(test); 165 | } 166 | } 167 | }else 168 | removed.add(test); 169 | } 170 | } 171 | } 172 | if(testBreak) 173 | break; 174 | } 175 | } 176 | for (int i = 0; i< removed.size(); ++i) 177 | hLoop.remove(removed.get(i)); 178 | //System.out.println("####### fin Filter "+hLoop.size()); 179 | return hLoop; 180 | } 181 | /** 182 | * Removed loops close to biased HiC signal 183 | * @param loop Loop to plop.test 184 | * @return boolean true if loop have to be removed else false 185 | */ 186 | private boolean removedVectoNorm(Loop loop, HashMap normVector){ 187 | boolean test = false; 188 | int x = loop.getCoordinates().get(0); 189 | int y = loop.getCoordinates().get(2); 190 | //System.out.println(loop.getName()+" "+loop.getResolution()); 191 | if(loop.getResolution() == this._resolution){ 192 | if(normVector.containsKey(x) || normVector.containsKey(y)) 193 | test = true; 194 | } 195 | else if(loop.getResolution() == this._resolution*2){ 196 | if(normVector.containsKey(x) || normVector.containsKey(y) || 197 | normVector.containsKey(x+this._resolution) || normVector.containsKey(y+this._resolution)) 198 | test = true; 199 | } 200 | else if(loop.getResolution() == this._resolution*5){ 201 | for(int i = x; i <= x+5*this._resolution; i+=this._resolution){ 202 | if(normVector.containsKey(i)){ 203 | test = true; 204 | break; 205 | } 206 | for(int j = y; j <= y+5*this._resolution; j+=this._resolution){ 207 | if(normVector.containsKey(j)){ 208 | test = true; 209 | break; 210 | } 211 | } 212 | } 213 | } 214 | return test; 215 | } 216 | 217 | 218 | /** 219 | * Remove overlapping loops 220 | * @param loop loop to plop.test 221 | * @param input loop collection 222 | * @param removed arrayList of loop 223 | * @return removed arrayList of loop 224 | */ 225 | private ArrayList removeOverlappingLoops( 226 | Loop loop, HashMap input, ArrayList removed){ 227 | Set key = input.keySet(); 228 | Iterator it = key.iterator(); 229 | while (it.hasNext()){ 230 | String name = it.next(); 231 | Loop looptest = input.get(name); 232 | if(!(removed.contains(name)) && loop.getResolution() < looptest.getResolution()){ 233 | int factor = looptest.getResolution()/loop.getResolution(); 234 | int xtest = loop.getX()/factor; 235 | int ytest = loop.getY()/factor; 236 | for(int i = xtest-1; i <= xtest+1; ++i ){ 237 | for(int j = ytest-1; j <= ytest+1; ++j ){ 238 | if(i == looptest.getX() && j == looptest.getY()){ 239 | removed.add(name); 240 | } 241 | } 242 | } 243 | } 244 | } 245 | return removed; 246 | } 247 | } -------------------------------------------------------------------------------- /src/main/java/plop/utils/FindMaxima.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | 6 | import ij.ImagePlus; 7 | import ij.io.FileSaver; 8 | import ij.plugin.filter.MaximumFinder; 9 | import ij.process.ByteProcessor; 10 | import ij.process.ImageProcessor; 11 | 12 | /** 13 | * Detection of regional maxima in image. Return the HashMap, the loop can be corrected. 14 | * the class uses is the imageJ class to detect the maxima. 15 | * 16 | * @author Axel Poulet 17 | * 18 | */ 19 | public class FindMaxima{ 20 | /** raw image*/ 21 | private ImagePlus _imgNorm; 22 | /** name of the chromosome*/ 23 | private String _chr; 24 | /** Image filtered with min, max and gaussian filter*/ 25 | private ImagePlus _imgFilter; 26 | /** binary image pixel white = the maxima detected*/ 27 | private ImagePlus _imgResu = new ImagePlus(); 28 | /** threshold for the imageJ class MaximumFinder, this class is call to detect the maxima */ 29 | private double _noiseTolerance =-1; 30 | /** diagonal size in bin*/ 31 | private int _diagonalSize =-1; 32 | /** Resolution of the image in base*/ 33 | private int _resolution = -1; 34 | 35 | 36 | /** 37 | * Constructor of FindMaxima 38 | * @param img ImagePlus raw image 39 | * @param imgFilter ImagePlus filtered image 40 | * @param chr String chromosome 41 | * @param noiseTolerance double threshold to detect maxima 42 | * @param diagonal int the size of the diagonal 43 | * @param resolution int size of the pixel in base 44 | */ 45 | public FindMaxima(ImagePlus img, ImagePlus imgFilter, String chr, double noiseTolerance, int diagonal, int resolution){ 46 | this._imgNorm = img; 47 | this._imgFilter = imgFilter; 48 | this._noiseTolerance = noiseTolerance; 49 | this._chr = chr; 50 | this._diagonalSize = diagonal; 51 | this._resolution = resolution; 52 | } 53 | 54 | 55 | /** 56 | * Method to find loops in oMe image, and fill the loop collection. 57 | * 58 | * @param index int index of the image 59 | * @param nbZero int nb zero allowed around the loop 60 | * @param raw ImagePlus raw image 61 | * @param val int background value of the image 62 | * @return 63 | */ 64 | public HashMap findLoop(int index, int nbZero, ImagePlus raw, float val){ 65 | run(nbZero, raw, val); 66 | ArrayList temp = this.getMaxima(); 67 | ImageProcessor ipN = this._imgNorm.getProcessor(); 68 | HashMap data = new HashMap(); 69 | //System.out.println("size raw maxima !!!!!!!!!!!!!! "+raw.getTitle()+" "+temp.size()); 70 | for(int j = 0; j < temp.size();++j){ 71 | String[] parts = temp.get(j).split("\\t"); 72 | int x = Integer.parseInt(parts[0]); 73 | int y = Integer.parseInt(parts[1]); 74 | String name= this._chr+"\t"+temp.get(j)+"\t"+index; 75 | float avg = average(x,y); 76 | float std =standardDeviation(x,y,avg); 77 | if(avg > 1.45 && ipN.getf(x, y) >= 1.85){ // filter on the loop value and region value 78 | DecayAnalysis da = new DecayAnalysis(this._imgNorm,x,y); 79 | float n1 =da.getNeighbourhood1(); 80 | float n2 =da.getNeighbourhood2(); 81 | if(n1 < n2 && n1 >= 0.15 && n2 >= 0.25){ // filter on the neighborood for hic datatset 82 | Loop maxima = new Loop(temp.get(j),x,y,this._chr,avg,std,ipN.getf(x, y)); 83 | maxima.setNeigbhoord1(n1); 84 | maxima.setNeigbhoord2(n2); 85 | maxima.setResolution(this._resolution); 86 | //System.out.println(_resolution+" "+maxima.getResolution()); 87 | maxima.setDiagSize(this._diagonalSize); 88 | maxima.setMatrixSize(this._imgNorm.getWidth()); 89 | data.put(name, maxima); 90 | } 91 | } 92 | } 93 | //System.out.println("after filter ################# "+raw.getTitle()+" "+data.size()); 94 | return data; 95 | } 96 | 97 | /** 98 | * Detect maxima with the oMe or observed methods, call the different methods 99 | * to detect the maxima and correct them. 100 | * @param nbZero nb zero allowed around the loops 101 | * @param rawImage ImagePlus raw image 102 | * @param backgroundValue background value of the image 103 | */ 104 | private void run(int nbZero, ImagePlus rawImage, float backgroundValue){ 105 | ImagePlus temp = this._imgFilter.duplicate(); 106 | ImageProcessor ip = temp.getProcessor(); 107 | MaximumFinder mf = new MaximumFinder(); 108 | ByteProcessor bp = mf.findMaxima(ip, this._noiseTolerance, MaximumFinder.SINGLE_POINTS, true); 109 | this._imgResu.setProcessor(bp); 110 | this.putLoopLowerTriangle(); 111 | this.removedCloseMaxima(); 112 | this.correctMaxima(); 113 | this.removeMaximaCloseToZero(nbZero,rawImage, backgroundValue); 114 | } 115 | 116 | /** 117 | * Save the image 118 | * @param imagePlusInput: ImagePlus to save 119 | * @param pathFile: path file for the image 120 | */ 121 | public static void saveFile ( ImagePlus imagePlusInput, String pathFile){ 122 | FileSaver fileSaver = new FileSaver(imagePlusInput); 123 | fileSaver.saveAsTiff(pathFile); 124 | } 125 | 126 | private void putLoopLowerTriangle() { 127 | ImageProcessor ipMaxima = this._imgResu.getProcessor(); 128 | int w = ipMaxima.getWidth(); 129 | int h = ipMaxima.getHeight(); 130 | for(int i = 1; i < w-1; ++i){ 131 | for(int j= 1; j < h-1; ++j){ 132 | if(ipMaxima.getPixel(i,j) > 0){ 133 | if(j > i){ 134 | ipMaxima.set(j,i,255); 135 | ipMaxima.set(i,j,0); 136 | } 137 | } 138 | } 139 | } 140 | this._imgResu.setProcessor(ipMaxima); 141 | } 142 | 143 | /** 144 | * Correction of the maxima. Search around the detected maxima on the raw image, 145 | * To correct the shift of maxima due to the gaussian, min and max filter. 146 | */ 147 | private void correctMaxima(){ 148 | ImageProcessor rawIpNorm = this._imgNorm.getProcessor(); 149 | int w = rawIpNorm.getWidth(); 150 | int h = rawIpNorm.getHeight(); 151 | ImageProcessor ipMaxima = this._imgResu.getProcessor(); 152 | for(int i = 2; i< w-2; ++i){ 153 | for(int j = 2; j< h-2; ++j){ 154 | if (ipMaxima.getPixel(i,j) == 255 ){ 155 | double max = rawIpNorm.getf(i,j); 156 | int imax = i; 157 | int jmax =j; 158 | for(int ii=i-2; ii<=i+2; ++ii){ 159 | for(int jj = j-2; jj <= j+2; ++jj){ 160 | if(max < rawIpNorm.getf(ii, jj)){ 161 | imax = ii; 162 | jmax = jj; 163 | max = rawIpNorm.getf(ii, jj); 164 | } 165 | } 166 | } 167 | if (max > rawIpNorm.getf(i,j)){ 168 | ipMaxima.set(i,j,0); 169 | ipMaxima.set(imax,jmax,255); 170 | } 171 | } 172 | } 173 | } 174 | this._imgResu.setProcessor(ipMaxima); 175 | } 176 | 177 | /** 178 | * Test if two maxima are close removed this one which possess the smaller value. 179 | * Test a 48 neighbourhood region 180 | */ 181 | private void removedCloseMaxima(){ 182 | ImageProcessor rawIpNorm = this._imgNorm.getProcessor(); 183 | int w = rawIpNorm.getWidth(); 184 | int h = rawIpNorm.getHeight(); 185 | ImageProcessor ipMaxima = this._imgResu.getProcessor(); 186 | for(int i = 1; i < w-1; ++i){ 187 | for(int j= 1; j < h-1; ++j){ 188 | if (ipMaxima.getPixel(i,j) > 0){ 189 | for(int ii = i-2; ii <= i+2; ++ii){ 190 | for(int jj = j-2; jj <= j+2; ++jj){ 191 | if(ipMaxima.getPixel(ii,jj) > 0){ 192 | if(i != ii || j != jj){ 193 | if(rawIpNorm.getf(ii, jj) > rawIpNorm.getf(i,j)) 194 | ipMaxima.set(i,j,0); 195 | else 196 | ipMaxima.set(ii,jj,0); 197 | } 198 | } 199 | } 200 | } 201 | } 202 | } 203 | } 204 | this._imgResu.setProcessor(ipMaxima); 205 | } 206 | 207 | /** 208 | * getter of maxima 209 | * retrun the list of maxima as list of string i\tj\tvalue 210 | * @return ArrayList 211 | */ 212 | public ArrayList getMaxima(){ 213 | int w = this._imgResu.getWidth(); 214 | int h = this._imgResu.getHeight(); 215 | ImageProcessor ipResu = this._imgResu.getProcessor(); 216 | ArrayList listMaxima = new ArrayList(); 217 | for(int i = 0; i < w; ++i){ 218 | for(int j = 0; j < h; ++j){ 219 | if (ipResu.getf(i,j) > 0 )//&& i-j > 0) 220 | listMaxima.add(i+"\t"+j); 221 | } 222 | } 223 | return listMaxima; 224 | } 225 | 226 | /** 227 | * Compute the average on the neighbourhood 9 228 | * @param x int x coordinate's of the loop 229 | * @param y int y coordinate's of the loop 230 | * @return double avg around the loop on the neighbourhood 231 | */ 232 | private float average(int x, int y){ 233 | float sum = 0; 234 | int nb=0; 235 | ImageProcessor ip = this._imgNorm.getProcessor(); 236 | for(int i = x-1; i <= x+1; ++i){ 237 | for(int j = y-1; j <= y+1; ++j){ 238 | if(i < ip.getWidth() && i>0 && j < ip.getWidth() && j > 0){ 239 | sum +=ip.getf(i, j); 240 | ++nb; 241 | } 242 | } 243 | } 244 | return sum/nb; 245 | } 246 | 247 | 248 | 249 | /** 250 | * Compute standard deviation of the loop region at the neighbourhood 8. 251 | * 252 | * @param x: int the x coordinate's of the loop 253 | * @param y: int y coordinate's of the loop 254 | * @param avg: double average of the same region 255 | * @return double: teh standard deviation 256 | */ 257 | private float standardDeviation(int x, int y, double avg){ 258 | float semc = 0; 259 | int nb = 0; 260 | ImageProcessor ip = this._imgNorm.getProcessor(); 261 | for(int i = x-1; i <= x+1; ++i){ 262 | for(int j = y-1; j <= y+1; ++j){ 263 | if(i < ip.getWidth() && i>0 && j < ip.getWidth() && j > 0){ 264 | semc += (ip.getf(i, j)-avg)*(ip.getf(i, j)-avg); 265 | ++nb; 266 | } 267 | } 268 | } 269 | semc = semc/nb; 270 | return (float)Math.sqrt(semc); 271 | } 272 | 273 | /** 274 | * Removed maxima surrounded by several pixel with the 0 value. 275 | * The method search the pixel with value 0 in the 24 neighbourhood around the initial maxima. 276 | * 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. 277 | * ig the loops is closed too the diagonal the plop.test is less stringent 7 for oMe methods and 4 for observed method. 278 | * 279 | * @param nbZero nb zero allowed around the loops 280 | * @param rawImage ImagePlus raw image 281 | * @param val background value of the image 282 | */ 283 | private void removeMaximaCloseToZero(int nbZero,ImagePlus rawImage, float val){ 284 | int w = this._imgResu.getWidth(); 285 | int h = this._imgResu.getHeight(); 286 | ImageProcessor ipResu = this._imgResu.getProcessor(); 287 | ImageProcessor ip = rawImage.getProcessor(); 288 | for(int i = 2; i< w-2; ++i){ 289 | for(int j= 2;j< h-2;++j){ 290 | if(ipResu.getPixel(i, j) > 0){ 291 | int thresh = nbZero; 292 | if (j-i <= this._diagonalSize +2) 293 | thresh = thresh+1; 294 | int nb = 0; 295 | for(int ii = i-2; ii <= i+2; ++ii){ 296 | for(int jj = j-2; jj <= j+2; ++jj){ 297 | if (ip.getf(ii, jj)<= val) 298 | nb++; 299 | } 300 | if(nb >= thresh){ 301 | ipResu.set(i,j,0); 302 | break; 303 | } 304 | } 305 | } 306 | } 307 | } 308 | this._imgResu.setProcessor(ipResu); 309 | } 310 | 311 | /** 312 | * Setter of the noise tolerance parameter 313 | * @param n int the value of the new noiseTolerance 314 | */ 315 | public void setNoiseTolerance( int n){ this._noiseTolerance = n;} 316 | } 317 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/ImageProcessingMethod.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import ij.ImagePlus; 4 | import ij.plugin.ContrastEnhancer; 5 | import ij.plugin.filter.GaussianBlur; 6 | import ij.plugin.filter.RankFilters; 7 | import ij.process.ImageProcessor; 8 | 9 | /** 10 | * Method of image pre-processing before call maxima, to enhance the loops and reduce the noise 11 | * This class is using the ImageJ methode for the different filters (min, max, gaussian). 12 | * 13 | * @author axel poulet 14 | * 15 | */ 16 | public class ImageProcessingMethod{ 17 | /** Raw image*/ 18 | private ImagePlus _img; 19 | /** ImageProcessor of the raw image*/ 20 | private ImageProcessor _ip; 21 | /** value for the min filter strength*/ 22 | private double _minFilterRadius = 0; 23 | /** max filter strength*/ 24 | private double _maxFilterRadius = 0; 25 | /** gaussian filter strength*/ 26 | private double _gaussianFilterRadius = 0; 27 | /** ImageJ object to run the different filters*/ 28 | private RankFilters _rF = new RankFilters(); 29 | 30 | /** 31 | * Constructor of ProcessMethod 32 | * @param img ImagePlus, raw image 33 | * @param minFilterRad double, value of the min strength filter 34 | * @param maxFilterRad double, value of the max strength filter 35 | * @param gaussianFilterRad double, value of the gaussian strength filter 36 | */ 37 | public ImageProcessingMethod(ImagePlus img, double minFilterRad, double maxFilterRad, double gaussianFilterRad){ 38 | this._img = img; 39 | this._ip = this._img.getProcessor(); 40 | this._gaussianFilterRadius = gaussianFilterRad; 41 | this._maxFilterRadius = maxFilterRad; 42 | this._minFilterRadius = minFilterRad; 43 | } 44 | 45 | /** 46 | * Constructor of ProcessMethod 47 | * @param img ImagePlus, raw image 48 | * @param gaussianFilterRad double, value of the gaussian strength filter 49 | */ 50 | public ImageProcessingMethod(ImagePlus img, double gaussianFilterRad){ 51 | this._img = img; 52 | this._ip = this._img.getProcessor(); 53 | this._gaussianFilterRadius = gaussianFilterRad; 54 | } 55 | 56 | 57 | /** 58 | * ImageJ method to enhance the image contrats, and enhance the structures of interest 59 | * @param saturatedPixel double of the % of the saturated pixel want in the ehanced image 60 | * 61 | */ 62 | public void enhanceContrast(double saturatedPixel){ 63 | ContrastEnhancer enh = new ContrastEnhancer(); 64 | enh.setNormalize(true); 65 | enh.stretchHistogram(this._img, saturatedPixel); 66 | 67 | } 68 | 69 | /** 70 | * Minimum filter method 71 | * @param min double strength of the min filter 72 | */ 73 | public void runMin(double min){ 74 | this._rF.rank(this._ip, min, RankFilters.MIN); 75 | } 76 | 77 | 78 | /** 79 | * White "tophat" method to enhance the light structure 80 | * 81 | */ 82 | public void topHat(double min, double max){ 83 | //GaussianBlur gb = new GaussianBlur(); 84 | //gb.blurGaussian(this._ip, this._gaussianFilterRadius); 85 | this._rF.rank(this._ip, min, RankFilters.MIN); 86 | this._rF.rank(this._ip, max, RankFilters.MAX); 87 | this._rF.rank(this._ip, max, RankFilters.MAX); 88 | this._rF.rank(this._ip, min, RankFilters.MIN); 89 | } 90 | 91 | /** 92 | * Getter of the image filtered 93 | * @return ImagePlus image filtered 94 | */ 95 | public ImagePlus getImg(){ return _img;} 96 | 97 | /** 98 | * Setter of the raw image 99 | * 100 | * @param img 101 | */ 102 | public void setImg(ImagePlus img){ this._img = img;} 103 | 104 | 105 | /** 106 | * Gaussian blur method 107 | * run this methode on m_img 108 | */ 109 | public void runGaussian() { 110 | GaussianBlur gb = new GaussianBlur(); 111 | gb.blurGaussian(_ip, this._gaussianFilterRadius); 112 | } 113 | 114 | /** 115 | * 116 | * @param m_max 117 | */ 118 | public void runMax(double m_max) { 119 | _rF.rank(_ip, m_max, RankFilters.MAX); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/Loop.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Class making loops object with its coordinate, value, and parameters 7 | * 8 | * @author axel poulet 9 | * 10 | */ 11 | public class Loop { 12 | /** chromosome name.*/ 13 | private String _chr; 14 | /** loops name: chr start end value.*/ 15 | private String _name; 16 | /** x coordinate.*/ 17 | private int _x; 18 | /** y coordinate.*/ 19 | private int _y; 20 | /** loop resolution.*/ 21 | private int _resolution; 22 | /** size of the image.*/ 23 | private int _matrixSize; 24 | /** diagonal size.*/ 25 | private int _diagSize; 26 | /** x coordinate+resolution.*/ 27 | private int _xEnd; 28 | /** y coordinate+resolution.*/ 29 | private int _yEnd; 30 | /** value of the avg of the diff between loops value and the neighbourhood 8.*/ 31 | private float _neigbhoord1 = -1; 32 | /** 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.*/ 33 | private float _paScoreAvg = -1; 34 | private float _paScoreAvgdev = -1; 35 | /** 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.*/ 36 | private float _paScoreMed = -1; 37 | /** value of the avg of the differential between loops value and the neighbourhood 24.*/ 38 | private float _neigbhoord2 = -1; 39 | /** 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.*/ 40 | private float _regPaScoreMed = -1; 41 | /** 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.*/ 42 | private float _regPaScoreAvg = -1; 43 | /** Average value of the neighbourhood 9.*/ 44 | private float _avg = -1; 45 | /** Value of the loop*/ 46 | private float _peakValue = -1; 47 | /** Standard deviation value of the neighbourhood 9.*/ 48 | private float _std = -1; 49 | /** FDR score 1*/ 50 | private float _paScoreFDR = -1; 51 | /**reg fdr socre 1 */ 52 | private float _regPaScoreFDR = -1; 53 | /** FDR score 2 */ 54 | private float _paScoreFDR2 = -1; 55 | /** reg fdr socre 2 */ 56 | private float _regPaScoreFDR2 = -1; 57 | /** FDR score 3*/ 58 | private float _paScoreFDR3 = -1; 59 | /**reg fdr socre 3 */ 60 | private float _regPaScoreFDR3 = -1; 61 | 62 | /** 63 | * Loop constructor 64 | * @param name String name of the loop 65 | * @param chr String name of the chromosome 66 | * @param x int x coordinate 67 | * @param y int y coordinate 68 | */ 69 | public Loop(String name, int x, int y, String chr){ 70 | this.setName(name); 71 | this.setX(x); 72 | this.setY(y); 73 | this._chr = chr; 74 | } 75 | //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 76 | //chromosome1 x1 x2 chromosome2 y1 y2 color APScoreAvg ProbabilityofEnrichment RegAPScoreAvg Avg_diffMaxNeihgboor_1 Avg_diffMaxNeihgboor_2 avg std value 77 | 78 | public Loop(String loop){ 79 | String[] tLoop = loop.split("\t"); 80 | this._chr = tLoop[0]; 81 | this._name = loop; 82 | this._x = Integer.parseInt(tLoop[1]); 83 | this._xEnd = Integer.parseInt(tLoop[2]); 84 | this._y = Integer.parseInt(tLoop[4]); 85 | this._yEnd= Integer.parseInt(tLoop[5]); 86 | } 87 | 88 | /** 89 | * Loop constructor 90 | * @param name String name of the loop 91 | * @param x int x coordinate 92 | * @param y int y coordinate 93 | * @param chr String name of the chromosome 94 | * @param value float 95 | * @param resolution int 96 | */ 97 | public Loop(String name, int x, int y, String chr, float value, int resolution){ 98 | this.setName(name); 99 | this.setX(x); 100 | this.setY(y); 101 | this._chr = chr; 102 | this._peakValue = value; 103 | this._resolution = resolution; 104 | } 105 | 106 | /** 107 | * Loop constructor 108 | * @param name String name of the loop 109 | * @param x int x coordinate 110 | * @param y int y coordinate 111 | * @param chr String Chromosme name 112 | * @param avg float Average 113 | * @param std float Standard deviation 114 | * @param value float 115 | */ 116 | public Loop(String name, int x, int y, String chr, float avg, float std, float value){ 117 | this.setName(name); 118 | this.setX(x); 119 | this.setY(y); 120 | this._chr = chr; 121 | this._avg = avg; 122 | this._std = std; 123 | this._peakValue = value; 124 | } 125 | 126 | /** 127 | * Getter of the name loop 128 | * @return String name of the loop 129 | */ 130 | public String getName(){ return this._name; } 131 | 132 | /** 133 | * Setter of the name loop 134 | * @param name String 135 | */ 136 | public void setName(String name){ this._name = name;} 137 | 138 | /** 139 | * Getter of the x coordinate 140 | * @return int x coordinate 141 | */ 142 | public int getX(){ return this._x;} 143 | 144 | 145 | /** 146 | * 147 | * @return loop String 148 | */ 149 | public String loopToString(){ 150 | String loop = _chr+"\t"+_name+"\t"+_x+"\t"+_y+"\t"+ _resolution+"\t"+_matrixSize+"\t"+ _diagSize+"\t"+ 151 | _xEnd+"\t"+ _yEnd+"\t"+_neigbhoord1+"\t"+_paScoreAvg+"\t"+_paScoreAvgdev+"\t"+_paScoreMed 152 | +"\t"+_neigbhoord2+"\t"+_regPaScoreMed+"\t"+_regPaScoreAvg+"\t"+_avg+"\t"+_peakValue 153 | +"\t"+_std+"\t"+_paScoreFDR+"\t"+_regPaScoreFDR+"\t"+_paScoreFDR2+"\t"+_regPaScoreFDR2+"\t" 154 | +_paScoreFDR3+"\t"+_regPaScoreFDR3; 155 | return loop; 156 | } 157 | 158 | /** 159 | * Setter of the loop resolution 160 | * @param x int loop resolution 161 | */ 162 | public void setResolution(int x){ this._resolution = x; } 163 | 164 | /** 165 | * Getter of the loop resolution 166 | * @return int resolution 167 | */ 168 | public int getResolution(){ return this._resolution;} 169 | 170 | /** 171 | * Setter of the matrix size 172 | * @param x int size of the matrix 173 | */ 174 | public void setMatrixSize(int x){ this._matrixSize = x; } 175 | 176 | /** 177 | * Getter of the matrix size 178 | * @return int matrix size 179 | */ 180 | public int getMatrixSize(){ return this._matrixSize; } 181 | 182 | /** 183 | * Setter of the diagonal size 184 | * @param x int diagonal size 185 | */ 186 | public void setDiagSize(int x){ this._diagSize = x;} 187 | 188 | /** 189 | * Getter of the diagonal size 190 | * @return int diagonal size 191 | */ 192 | public int getDiagonalSize(){ return this._diagSize; } 193 | 194 | /** 195 | * Setter of x coordinate 196 | * @param x 197 | */ 198 | public void setX(int x){ this._x = x; } 199 | /** 200 | * Getter of y loop coordinate's 201 | * @return int y loop coordinate's 202 | */ 203 | public int getY(){ return this._y; } 204 | 205 | /** 206 | * Setter of the y loops coordinate's 207 | * @param y int loop coordinate's 208 | */ 209 | public void setY(int y){ this._y = y; } 210 | 211 | /** 212 | * Getter of the loop(x,y) value 213 | * @return double loop value 214 | */ 215 | public float getValue(){ return this._peakValue; } 216 | /** 217 | * Getter of the n 8 average value 218 | * @return double average of n 8 average 219 | */ 220 | public float getAvg(){ return this._avg; } 221 | 222 | /** 223 | * Getter of the n 8 standard deviation 224 | * @return double standard deviation 225 | */ 226 | public float getStd(){ return this._std; } 227 | 228 | /** 229 | * Getter of avg differential n 8 230 | * @return double of the differential avg 231 | */ 232 | public float getNeigbhoord1() { return this._neigbhoord1; } 233 | 234 | /** 235 | * Setter of avg differential n 8 236 | * @param neigbhoord1 double differential avg 237 | */ 238 | public void setNeigbhoord1(float neigbhoord1){ this._neigbhoord1 = neigbhoord1; } 239 | 240 | 241 | /** 242 | * Getter of avg differential n 24 243 | * @return double differential avg 244 | */ 245 | public float getNeigbhoord2(){ return _neigbhoord2; } 246 | 247 | /** 248 | * Setter of avg differential n 24 249 | * @param neigbhoord2 double differential avg 250 | */ 251 | public void setNeigbhoord2(float neigbhoord2){ this._neigbhoord2 = neigbhoord2;} 252 | 253 | /** 254 | * Getter of the peak analysis loop 255 | * @return double PA score 256 | */ 257 | public float getPaScoreAvg(){ return this._paScoreAvg; } 258 | public float getPaScoreAvgdev(){ return this._paScoreAvgdev; } 259 | /** 260 | * Setter of the peak analysis loop score 261 | * @param paScore double PA score 262 | */ 263 | public void setPaScoreAvg(float paScore){ this._paScoreAvg = paScore; } 264 | 265 | /** 266 | * 267 | * @param paScoredev 268 | */ 269 | public void setPaScoreAvgdev(float paScoredev){ this._paScoreAvgdev = paScoredev; } 270 | 271 | /** 272 | * Getter of the peak analysis loop 273 | * @return double PA score 274 | */ 275 | public double getPaScoreMed(){ return this._paScoreMed; } 276 | 277 | /** 278 | * Setter of the peak analysis loop score 279 | * @param paScore 280 | */ 281 | public void setPaScoreMed(float paScore){ this._paScoreMed = paScore; } 282 | 283 | /** 284 | * Setter of the loop coordinate 285 | * @param x int x coordinate 286 | * @param x_end int x end coordinate 287 | * @param y int y coordinate 288 | * @param y_end y end coordinate 289 | */ 290 | public void setCoordinates(int x, int x_end, int y, int y_end){ 291 | this._x = x; 292 | this._xEnd = x_end; 293 | this._y = y; 294 | this._yEnd =y_end; 295 | } 296 | 297 | /** 298 | * Getter of loop coordinate, return arraylist 0: x; 1: x_end; 2: y; 3: y_end 299 | * @return ArrayList of integer 300 | */ 301 | public ArrayList getCoordinates(){ 302 | ArrayList listCoord = new ArrayList(); 303 | listCoord.add(this._x); 304 | listCoord.add(this._xEnd); 305 | listCoord.add(this._y); 306 | listCoord.add(this._yEnd); 307 | return listCoord; 308 | } 309 | 310 | /** 311 | * 312 | * @return 313 | */ 314 | public float getRegionalPaScoreMed(){ return this._regPaScoreMed; } 315 | 316 | /** 317 | * 318 | * @param m_RpaScore 319 | */ 320 | public void setRegionalPaScoreMed(float m_RpaScore){ this._regPaScoreMed = m_RpaScore; } 321 | 322 | /** 323 | * Getter of regional peak analysis score 324 | * @return double regional PA score 325 | */ 326 | public float getRegionalPaScoreAvg(){ return this._regPaScoreAvg; } 327 | 328 | /** 329 | * Setter of regional PA score 330 | * @param rpaScore 331 | */ 332 | public void setRegionalPaScoreAvg(float rpaScore){ this._regPaScoreAvg = rpaScore; } 333 | 334 | /** 335 | * Getter of the name of the chromosome 336 | * @return String chr 337 | */ 338 | public String getChr(){ return this._chr; } 339 | 340 | /** 341 | * Setter of the avg of th n 8 342 | * @param avg double 343 | */ 344 | public void setAvg(float avg) { this._avg=avg; } 345 | 346 | /** 347 | * 348 | * @return 349 | */ 350 | public float getRegionalPaScoreAvgFDR(){ return this._regPaScoreFDR;} 351 | /** 352 | * 353 | * @return 354 | */ 355 | public float getRegionalPaScoreAvgFDR2(){ return this._regPaScoreFDR2; } 356 | /** 357 | * 358 | * @return 359 | */ 360 | public float getRegionalPaScoreAvgFDR3(){ return this._regPaScoreFDR3; } 361 | 362 | /** 363 | * 364 | * @param rpaScoreFDR 365 | */ 366 | public void setRegionalPaScoreAvgFDR(float rpaScoreFDR){ this._regPaScoreFDR = rpaScoreFDR; } 367 | /** 368 | * 369 | * @param rpaScoreFDR2 370 | */ 371 | public void setRegionalPaScoreAvgFDR2(float rpaScoreFDR2){ this._regPaScoreFDR2 = rpaScoreFDR2; } 372 | /** 373 | * 374 | * @param rpaScoreFDR3 375 | */ 376 | public void setRegionalPaScoreAvgFDR3(float rpaScoreFDR3){ this._regPaScoreFDR3 = rpaScoreFDR3; } 377 | /** 378 | * 379 | * @return 380 | */ 381 | public float getPaScoreAvgFDR(){ return this._paScoreFDR; } 382 | /** 383 | * 384 | * @return 385 | */ 386 | public float getPaScoreAvgFDR2(){ return this._paScoreFDR2; } 387 | /** 388 | * 389 | * @return 390 | */ 391 | public float getPaScoreAvgFDR3(){ return this._paScoreFDR3; } 392 | /** 393 | * 394 | * @param paScoreFDR 395 | */ 396 | public void setPaScoreAvgFDR(float paScoreFDR){ this._paScoreFDR = paScoreFDR; } 397 | /** 398 | * 399 | * @param paScoreFDR2 400 | */ 401 | public void setPaScoreAvgFDR2(float paScoreFDR2){ this._paScoreFDR2 = paScoreFDR2; } 402 | /** 403 | * 404 | * @param paScoreFDR3 405 | */ 406 | public void setPaScoreAvgFDR3(float paScoreFDR3){ this._paScoreFDR3 = paScoreFDR3; } 407 | 408 | } 409 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/PeakAnalysisScore.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.util.HashMap; 4 | import java.lang.Math; 5 | import java.util.Iterator; 6 | import java.util.Set; 7 | import ij.ImagePlus; 8 | import ij.process.ImageProcessor; 9 | 10 | /** 11 | * Peak analysis score. 12 | * peaks analysis score is adapted from the APA score from Rao&Huntley et al., 2014: 13 | * @author axel poulet 14 | * 15 | */ 16 | public class PeakAnalysisScore { 17 | /** Raw image of the matrix*/ 18 | private ImagePlus _imgRaw = new ImagePlus(); 19 | /** HashMap of object loops*/ 20 | private HashMap _data = new HashMap(); 21 | /** ImageProcessor of the raw ImagePlus*/ 22 | private ImageProcessor _ipRaw; 23 | 24 | /** 25 | * Constructor of PeakAnalysisScore 26 | * @param imgRaw ImagePlus raw image 27 | * @param data HashMap of loops 28 | */ 29 | public PeakAnalysisScore(ImagePlus imgRaw, HashMap data){ 30 | this._imgRaw = imgRaw; 31 | this._data = data; 32 | this._ipRaw = _imgRaw.getProcessor(); 33 | } 34 | 35 | 36 | /** 37 | * Method to compute the score of each loop. on a 11*11 square, the average of the corner (3*3) are computed. 38 | * then the ration between the loops value and this avg is computed. For the regional value, the avg of the n_8 39 | * value of the loops are done, then a ratio is computed with the avg value of the corner. This method is used for 40 | * the observed and oMe method. 41 | * 42 | */ 43 | public void computeScore(){ 44 | Set key = this._data.keySet(); 45 | Iterator it = key.iterator(); 46 | while (it.hasNext()){ 47 | String cle = it.next(); 48 | Loop loop = this._data.get(cle); 49 | int x = loop.getX(); 50 | int y = loop.getY(); 51 | float corner = 0; 52 | float center = this._ipRaw.getf(x, y); 53 | float squareCenterAvg = process3By3SquareAvg(x,y); 54 | 55 | if(x >= 12 && y >= 12 && x < this._imgRaw.getWidth()-12 && y < this._imgRaw.getHeight()-12){ 56 | corner = computeAvgCorner(x,y); 57 | loop.setPaScoreAvg(center/corner); 58 | loop.setRegionalPaScoreAvg(squareCenterAvg/corner); 59 | 60 | float probnum = 0; 61 | float factorial = 1; 62 | int countNumber = (int) (corner); 63 | for (int i = 0; i < countNumber; i++) { 64 | if (i == 0) { 65 | factorial = 1; 66 | }else { 67 | factorial = 1; 68 | for (int j = 1; j<= i; j++) factorial = factorial*j; 69 | } 70 | float tmpProbnum = (float) ((Math.pow(2.718,((center)*-1))*Math.pow((center),i))/factorial); 71 | probnum = probnum + tmpProbnum; 72 | } 73 | loop.setPaScoreAvgdev(1-probnum); 74 | 75 | int xFDR = x+10; 76 | int yFDR = y+10; 77 | if(xFDR > this._imgRaw.getWidth()-12 || yFDR > this._imgRaw.getHeight()-12){ 78 | xFDR = x-10; 79 | yFDR = y-10; 80 | } 81 | 82 | float centerFDR = this._ipRaw.getf(xFDR,yFDR); 83 | float squareCenterAvgFDR = process3By3SquareAvg(xFDR,yFDR); 84 | loop.setPaScoreAvgFDR(centerFDR/computeAvgCorner(xFDR,yFDR)); 85 | loop.setRegionalPaScoreAvgFDR(squareCenterAvgFDR/computeAvgCorner(xFDR,yFDR)); 86 | 87 | int xFDR2 = x+25; 88 | int yFDR2 = y+25; 89 | if(xFDR2 > this._imgRaw.getWidth()-12 || yFDR2 > this._imgRaw.getHeight()-12){ 90 | xFDR2 = x-25; 91 | yFDR2 = y-25; 92 | if(xFDR2 <= 0) xFDR2 = 13; 93 | if(yFDR2 <= 0) yFDR2 = 13; 94 | } 95 | //System.out.println(xFDR2+" "+yFDR2); 96 | float centerFDR2 = this._ipRaw.getf(xFDR2,yFDR2); 97 | float squareCenterAvgFDR2 = process3By3SquareAvg(xFDR2,yFDR2); 98 | loop.setPaScoreAvgFDR2(centerFDR2/computeAvgCorner(xFDR2,yFDR2)); 99 | loop.setRegionalPaScoreAvgFDR2(squareCenterAvgFDR2/computeAvgCorner(xFDR2,yFDR2)); 100 | 101 | int xFDR3 = x+40; 102 | int yFDR3 = y+40; 103 | if(xFDR3 > this._imgRaw.getWidth()-12 || yFDR3 > this._imgRaw.getHeight()-12){ 104 | xFDR3 = x-40; 105 | yFDR3 = y-40; 106 | if(xFDR3 <= 0) xFDR3 = 13; 107 | if(yFDR3 <= 0) yFDR3 = 13; 108 | } 109 | 110 | float centerFDR3 = this._ipRaw.getf(xFDR3,yFDR3); 111 | float squareCenterAvgFDR3 = process3By3SquareAvg(xFDR3,yFDR3); 112 | loop.setPaScoreAvgFDR3(centerFDR3/computeAvgCorner(xFDR3,yFDR3)); 113 | loop.setRegionalPaScoreAvgFDR3(squareCenterAvgFDR3/computeAvgCorner(xFDR3,yFDR3)); 114 | } 115 | } 116 | } 117 | 118 | /** 119 | * compute the avg of5*5 square 120 | * @param x int coordinate of the pixel center 121 | * @param y int coordinat of the pixel center 122 | * @return float average 123 | */ 124 | private float process3By3SquareAvg(int x, int y){ 125 | float sum = 0; 126 | int nb = 0; 127 | for(int i = x-2; i <= x+2; ++i){ 128 | for(int j = y-2; j <= y+2; ++j){ 129 | if(i < this._ipRaw.getWidth() && i>0 && j < this._ipRaw.getWidth() && j > 0){ 130 | sum += this._ipRaw.getf(i,j); 131 | nb++; 132 | } 133 | } 134 | } 135 | if(nb == 0) 136 | return 0; 137 | return sum/nb; 138 | } 139 | 140 | /** 141 | * 142 | * @param x 143 | * @param y 144 | * @return 145 | */ 146 | private float computeAvgCorner(int x, int y){ 147 | float corner = process3By3SquareAvg(x-10,y-10); 148 | corner += process3By3SquareAvg(x-10,y+10); 149 | corner += process3By3SquareAvg(x+10,y-10); 150 | corner += process3By3SquareAvg(x+10,y+10); 151 | if( corner == 0) corner = (float) 0.1; 152 | return corner/4; 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/plop/utils/SIPObject.java: -------------------------------------------------------------------------------- 1 | package plop.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.BufferedWriter; 5 | import java.io.File; 6 | import java.io.FileReader; 7 | import java.io.FileWriter; 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.Comparator; 11 | import java.util.HashMap; 12 | import java.util.Iterator; 13 | import java.util.Set; 14 | 15 | 16 | /** 17 | * Analyse and detect a whole genome HiC with .hic file or already processed data. 18 | * The class is used for the observed and oMe method. 19 | * MorpholibJ method used 20 | * Collection of mathematical morphology methods and plugins for ImageJ, created at the INRA-IJPB Modeling and Digital 21 | * Imaging lab. 22 | * David Legland, Ignacio Arganda-Carreras, Philippe Andrey; MorphoLibJ: integrated library and plugins for mathematical 23 | * morphology with ImageJ. 24 | * Bioinformatics 2016; 32 (22): 3532-3534. doi: 10.1093/bioinformatics/btw413 25 | * 26 | * @author axel poulet 27 | * 28 | */ 29 | public class SIPObject { 30 | /** String path of the input data*/ 31 | private String _input; 32 | /** Path of the output file*/ 33 | private String _output; 34 | /** Strength of the gaussian filter*/ 35 | private double _gauss; 36 | /** Strength of the min filter*/ 37 | private double _min; 38 | /** Strength of the max filter*/ 39 | private double _max; 40 | /** % of saturated pixel after enhance contrast*/ 41 | private double _saturatedPixel; 42 | /** Image size*/ 43 | private int _matrixSize = 0; 44 | /** Resolution of the bin dump in base*/ 45 | private int _resolution; 46 | /** Threshold for the maxima detection*/ 47 | private int _thresholdMaxima; 48 | /** HashMap of the chr size, the key = chr name, value = size of chr*/ 49 | private HashMap _chrSize = new HashMap(); 50 | /** Diagonal size to removed maxima close to diagonal*/ 51 | private int _diagonalSize; 52 | /** Size of the step to process each chr (step = matrixSize/2)*/ 53 | private int _step; 54 | /** Number of pixel = 0 allowed around the loop*/ 55 | private int _nbZero = -1; 56 | /** list of the image resolution to find loop*/ 57 | private ArrayList _listFactor = new ArrayList(); 58 | /** fdr value */ 59 | private double _fdr; 60 | /** is processed boolean*/ 61 | private boolean _isProcessed = false; 62 | /** if is plop.gui analysis*/ 63 | private boolean _isGui = false; 64 | private boolean _isDroso = false; 65 | private double _medianAP = 0; 66 | private double _medianAPReg = 0; 67 | private boolean _isCooler = false; 68 | //private HashMap _normVector = new HashMap(); 69 | 70 | 71 | public SIPObject() { 72 | 73 | } 74 | 75 | /** 76 | * 77 | * @param output 78 | * @param chrSize 79 | * @param gauss 80 | * @param min 81 | * @param max 82 | * @param resolution 83 | * @param saturatedPixel 84 | * @param thresholdMax 85 | * @param diagSize 86 | * @param matrixSize 87 | * @param nbZero 88 | * @param listFactor 89 | * @param fdr 90 | * @param isProcessed 91 | * @param rFdr 92 | */ 93 | public SIPObject(String output, HashMap chrSize, double gauss, double min, 94 | double max, int resolution, double saturatedPixel, int thresholdMax, 95 | int diagSize, int matrixSize, int nbZero,ArrayList listFactor, 96 | double fdr, boolean isProcessed, boolean rFdr) { 97 | if(!output.endsWith(File.separator)) 98 | output = output+File.separator; 99 | this._output = output; 100 | this._input = output; 101 | this._chrSize = chrSize; 102 | this._gauss = gauss; 103 | this._min = min; 104 | this._max = max; 105 | this._matrixSize = matrixSize; 106 | this._resolution = resolution; 107 | this._saturatedPixel = saturatedPixel; 108 | this._thresholdMaxima = thresholdMax; 109 | this._diagonalSize = diagSize; 110 | this._step = matrixSize/2; 111 | this._nbZero = nbZero; 112 | this._listFactor = listFactor; 113 | this._fdr = fdr; 114 | this._isProcessed = isProcessed; 115 | this._isDroso = rFdr; 116 | } 117 | 118 | /** 119 | * SIPObject constructor 120 | * 121 | * @param input 122 | * @param output 123 | * @param chrSize 124 | * @param gauss 125 | * @param min 126 | * @param max 127 | * @param resolution 128 | * @param saturatedPixel 129 | * @param thresholdMax 130 | * @param diagSize 131 | * @param matrixSize 132 | * @param nbZero 133 | * @param listFactor 134 | * @param fdr 135 | * @param isProcessed 136 | * @param rfdr 137 | */ 138 | public SIPObject(String input, String output, HashMap chrSize, double gauss, double min, 139 | double max, int resolution, double saturatedPixel, int thresholdMax, 140 | int diagSize, int matrixSize, int nbZero,ArrayList listFactor, 141 | double fdr, boolean isProcessed, boolean rfdr) { 142 | if(!output.endsWith(File.separator)) 143 | output = output+File.separator; 144 | if(!input.endsWith(File.separator)) 145 | input = input+File.separator; 146 | this._output = output; 147 | this._input = input; 148 | this._chrSize = chrSize; 149 | this._gauss = gauss; 150 | this._min = min; 151 | this._max = max; 152 | this._matrixSize = matrixSize; 153 | this._resolution = resolution; 154 | this._saturatedPixel = saturatedPixel; 155 | this._thresholdMaxima = thresholdMax; 156 | this._diagonalSize = diagSize; 157 | this._step = matrixSize/2; 158 | this._nbZero = nbZero; 159 | this._listFactor = listFactor; 160 | this._fdr = fdr; 161 | this._isProcessed = isProcessed; 162 | this._isDroso = rfdr; 163 | } 164 | 165 | 166 | /** 167 | * Save the result file in tabulated file 168 | * 169 | * @param pathFile String path for the results file 170 | * @param first boolean to know idf it is teh first chromo 171 | * @param data 172 | * @throws IOException 173 | */ 174 | public void saveFile(String pathFile, HashMap data, boolean first) throws IOException{ 175 | FDR fdrDetection = new FDR (); 176 | fdrDetection.run(this._fdr, data); 177 | double rFdrCutoff = fdrDetection.getRFDRcutoff(); 178 | double fdrCutoff = fdrDetection.getFDRcutoff(); 179 | boolean supToTen = false; 180 | if(this._isDroso){ 181 | median(data,fdrCutoff); 182 | System.out.println("Filtering value at "+this._fdr+" FDR is "+fdrCutoff+" APscore "); 183 | if(_medianAPReg > 10){ 184 | supToTen = true; 185 | _medianAPReg = _medianAPReg/4; 186 | _medianAP = _medianAP/10; 187 | } 188 | } 189 | else 190 | System.out.println("Filtering value at "+this._fdr+" FDR is "+fdrCutoff+" APscore and "+rFdrCutoff+ 191 | " RegionalAPscore\n"); 192 | BufferedWriter writer; 193 | if(first) writer = new BufferedWriter(new FileWriter(new File(pathFile), true)); 194 | else{ 195 | writer = new BufferedWriter(new FileWriter(new File(pathFile))); 196 | writer.write("chromosome1\tx1\tx2\tchromosome2\ty1\ty2\tcolor\tAPScoreAvg\tProbabilityofEnrichment\t" + 197 | "RegAPScoreAvg\tAvg_diffMaxNeihgboor_1\tAvg_diffMaxNeihgboor_2\tavg\tstd\tvalue\n"); 198 | } 199 | 200 | if(data.size()>0){ 201 | Set key = data.keySet(); 202 | Iterator it = key.iterator(); 203 | while (it.hasNext()){ 204 | String name = it.next(); 205 | Loop loop = data.get(name); 206 | ArrayList coord = loop.getCoordinates(); 207 | if(this._isDroso){ 208 | if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && 209 | loop.getPaScoreAvg() > fdrCutoff && loop.getPaScoreAvgdev() > .9 && 210 | (loop.getNeigbhoord1() > 1 || loop.getNeigbhoord2() > 1)){ 211 | if(supToTen){ 212 | if(loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.7) && 213 | loop.getRegionalPaScoreAvg() <= (_medianAPReg*2) && 214 | loop.getPaScoreAvg() <= (_medianAP*2)){ 215 | writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+ 216 | "\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0"+"\t"+loop.getPaScoreAvg()+ 217 | "\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+ 218 | "\t"+ loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+ 219 | "\t" +loop.getStd()+"\t"+loop.getValue()+"\n"); 220 | } 221 | }else{ 222 | if( loop.getRegionalPaScoreAvg() >= (_medianAPReg-_medianAPReg*0.5) && 223 | loop.getRegionalPaScoreAvg() <= (_medianAPReg*2) && 224 | loop.getPaScoreAvg() <= (_medianAP*2)){ 225 | writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+ 226 | "\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0"+"\t"+loop.getPaScoreAvg()+ 227 | "\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+ 228 | "\t"+loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg() 229 | +"\t" +loop.getStd()+"\t"+loop.getValue()+"\n"); 230 | } 231 | } 232 | } 233 | }else{ 234 | if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && 235 | loop.getPaScoreAvg() > fdrCutoff && 236 | loop.getRegionalPaScoreAvg() > rFdrCutoff && 237 | loop.getPaScoreAvgdev() > 0.9){ 238 | writer.write(loop.getChr()+"\t"+coord.get(2)+"\t"+coord.get(3)+"\t"+loop.getChr()+ 239 | "\t"+coord.get(0)+"\t"+coord.get(1)+"\t0,0,0"+"\t"+loop.getPaScoreAvg()+ 240 | "\t"+loop.getPaScoreAvgdev()+"\t"+loop.getRegionalPaScoreAvg()+ 241 | "\t"+loop.getNeigbhoord1()+"\t"+loop.getNeigbhoord2()+"\t"+loop.getAvg()+ 242 | "\t"+loop.getStd()+"\t"+loop.getValue()+"\n"); 243 | } 244 | } 245 | } 246 | writer.close(); 247 | } 248 | } 249 | 250 | 251 | /** 252 | * Full the list with file in directory 253 | * @param dir 254 | * @return 255 | * @throws IOException 256 | */ 257 | 258 | public File[] fillList(String dir) throws IOException{ 259 | File folder = new File(dir); 260 | File[] listOfFiles = folder.listFiles(); 261 | return listOfFiles; 262 | } 263 | 264 | 265 | /** 266 | * Test the normalized vector by chromosme 267 | * @param normFile 268 | */ 269 | public HashMap getNormValueFilter(String normFile){ 270 | BufferedReader br; 271 | int lineNumber = 0; 272 | HashMap vector = new HashMap(); 273 | try { 274 | br = new BufferedReader(new FileReader(normFile)); 275 | StringBuilder sb = new StringBuilder(); 276 | String line = br.readLine(); 277 | while (line != null){ 278 | sb.append(line); 279 | if((line.equals("NaN")|| line.equals("NAN") || 280 | line.equals("nan") || line.equals("na") || 281 | Double.parseDouble(line) < 0.30)){ 282 | vector.put(lineNumber*this._resolution, "plop"); 283 | } 284 | ++lineNumber; 285 | sb.append(System.lineSeparator()); 286 | line = br.readLine(); 287 | } 288 | br.close(); 289 | } catch (IOException e) { e.printStackTrace();} 290 | return vector; 291 | } 292 | 293 | 294 | /** 295 | * 296 | * @return 297 | */ 298 | private void median(HashMap data, double fdrCutoff){ 299 | Set key = data.keySet(); 300 | Iterator it = key.iterator(); 301 | ArrayList n1 = new ArrayList (); 302 | ArrayList n2 = new ArrayList (); 303 | int nb = 0; 304 | while (it.hasNext()){ 305 | String name = it.next(); 306 | Loop loop = data.get(name); 307 | if(loop.getPaScoreAvg()> 1.2 && loop.getPaScoreAvg() > 1 && 308 | loop.getPaScoreAvg() > fdrCutoff && 309 | loop.getPaScoreAvgdev() > 0.9){ 310 | n1.add(loop.getPaScoreAvg()); 311 | n2.add(loop.getRegionalPaScoreAvg()); 312 | nb++; 313 | } 314 | } 315 | if(nb>0){ 316 | n1.sort(Comparator.naturalOrder()); 317 | n2.sort(Comparator.naturalOrder()); 318 | double pos1 = Math.floor((n1.size() - 1.0) / 2.0); 319 | double pos2 = Math.ceil((n1.size() - 1.0) / 2.0); 320 | if (pos1 == pos2 ) _medianAP = n1.get((int)pos1); 321 | else _medianAP = (n1.get((int)pos1) + n1.get((int)pos2)) / 2.0 ; 322 | pos1 = Math.floor((n2.size() - 1.0) / 2.0); 323 | pos2 = Math.ceil((n2.size() - 1.0) / 2.0); 324 | if (pos1 == pos2 ) _medianAPReg = n2.get((int)pos1); 325 | else _medianAPReg = (n2.get((int)pos1) + n2.get((int)pos2)) / 2.0 ; 326 | System.out.println("AP\t"+_medianAP+"\nAPREG\t"+_medianAPReg); 327 | } 328 | } 329 | 330 | 331 | public double getFdr() { return this._fdr; } 332 | public void setFdr(double fdr) { this._fdr = fdr; } 333 | /** 334 | * Getter of the input dir 335 | * @return path of the input dir 336 | */ 337 | public String getInputDir(){ return this._input; } 338 | 339 | /** 340 | * Getter of the matrix size 341 | * 342 | * @return the size of the image 343 | */ 344 | public int getMatrixSize(){ return this._matrixSize; } 345 | 346 | 347 | /** 348 | * Getter of step 349 | * @return the step 350 | */ 351 | public int getStep(){ return this._step;} 352 | 353 | /** 354 | * Setter of the path of the input directory 355 | * @param inputDir String of the input directory 356 | */ 357 | public void setInputDir(String inputDir){ this._input = inputDir; } 358 | 359 | /** 360 | * Getter of the path of the output directory 361 | * @return path 362 | */ 363 | public String getOutputDir(){ return this._output; } 364 | 365 | /** 366 | * Setter of the path of the output directory 367 | * @param outputDir 368 | */ 369 | public void setOutputDir(String outputDir){ this._output = outputDir;} 370 | 371 | /** 372 | * Getter of the gaussian blur strength 373 | * @return double gaussian 374 | */ 375 | public double getGauss(){ return this._gauss; } 376 | 377 | /** 378 | * Setter of the gaussian blur strength 379 | * @param gauss double 380 | */ 381 | public void setGauss(double gauss){ this._gauss = gauss; } 382 | 383 | /** 384 | * Getter of diagSize 385 | * @return 386 | */ 387 | public int getDiagSize(){ return this._diagonalSize;} 388 | /** 389 | * Setter of the diagonal size 390 | * @param diagSize int of the size of the diagonal 391 | */ 392 | public void setDiagSize(int diagSize){ this._diagonalSize = diagSize; } 393 | 394 | /** 395 | * Getter of the min filter strength 396 | * @return double strength of the min filter 397 | */ 398 | public double getMin(){ return this._min;} 399 | 400 | /** 401 | * Setter of the min filter strength 402 | * @param min 403 | */ 404 | public void setMin(double min){ this._min = min;} 405 | 406 | /** 407 | * Getter of the max filter strength 408 | * @return double max filter 409 | */ 410 | public double getMax(){ return this._max; } 411 | 412 | /** 413 | * Setter of the min filter strength 414 | * @param max 415 | */ 416 | public void setMax(double max){ this._max = max;} 417 | 418 | /** 419 | * Getter % of saturated pixel for the contrast enhancement 420 | * @return double percentage of saturated 421 | */ 422 | public double getSaturatedPixel(){ return this._saturatedPixel; } 423 | 424 | /** 425 | * Setter % of saturated pixel for the contrast enhancement 426 | * @param saturatedPixel 427 | */ 428 | public void setSaturatedPixel(double saturatedPixel){ this._saturatedPixel = saturatedPixel; } 429 | 430 | /** 431 | * Getter of resolution of the bin 432 | * @return 433 | */ 434 | public int getResolution(){ return this._resolution;} 435 | 436 | /** 437 | * Setter of resolution of the bin 438 | * @param resolution 439 | */ 440 | public void setResolution(int resolution){ this._resolution = resolution;} 441 | 442 | /** 443 | * Setter of size of the matrix 444 | * @param size 445 | */ 446 | public void setMatrixSize(int size){ this._matrixSize = size; } 447 | 448 | /** 449 | * setter step between image 450 | * @param step int step 451 | */ 452 | public void setStep(int step){ this._step = step;} 453 | 454 | /** 455 | * Getter of threshold for the detction of the maxima 456 | * @return 457 | */ 458 | public int getThresholdMaxima(){ return _thresholdMaxima;} 459 | /** 460 | * Setter of threshold for the detection of the maxima 461 | * @param thresholdMaxima 462 | */ 463 | public void setThresholdMaxima(int thresholdMaxima) { this._thresholdMaxima = thresholdMaxima;} 464 | 465 | 466 | 467 | 468 | 469 | /** 470 | * Getter of getNbZero 471 | * @return 472 | */ 473 | public int getNbZero(){ return this._nbZero;} 474 | 475 | 476 | public void setNbZero(int nbZero){ this._nbZero = nbZero;} 477 | 478 | /** 479 | * 480 | * @return 481 | */ 482 | public ArrayList getListFactor() {return this._listFactor;} 483 | public void setListFactor(ArrayList listFactor) {this._listFactor = listFactor;} 484 | 485 | public boolean isDroso(){return this._isDroso;} 486 | public void setIsDroso(boolean droso){ this._isDroso = droso;} 487 | 488 | public HashMap getChrSizeHashMap(){return this._chrSize;} 489 | public void setChrSizeHashMap(HashMap chrSize){this._chrSize = chrSize;} 490 | 491 | 492 | 493 | /** 494 | * 495 | * @return 496 | */ 497 | public boolean isProcessed() { return _isProcessed;} 498 | public void setIsProcessed(boolean isProcessed) { this._isProcessed = isProcessed;} 499 | 500 | /** 501 | * 502 | * @return 503 | */ 504 | public boolean isCooler() { return _isCooler;} 505 | public void setIsCooler(boolean cool) { this._isCooler = cool;} 506 | 507 | /** 508 | * 509 | * @return 510 | */ 511 | public boolean isGui() { return _isGui;} 512 | public void setIsGui(boolean _isGui) { this._isGui = _isGui;} 513 | } --------------------------------------------------------------------------------