annotate NGSrich_0.5.5/src/_main/Enrichment.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 package _main;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 import java.io.File;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 import java.io.FileWriter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 import java.io.IOException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 import java.sql.Time;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 import java.util.Scanner;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 import middlewares.Misc;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 import converters.Read2Wig;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 import converters.ReadOnTarget2Wig;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 import exceptions.ChromosomeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 import exceptions.ChromosomeMismatchException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 import exceptions.ChromosomeNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 import exceptions.FileFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 import exceptions.GenomeAnnotationException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 import exceptions.NullOrNegativeRangeException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 import exceptions.RangeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 import exceptions.RangeLimitNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 import filters.Filter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 import filters.GenomeFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 import filters.ReadFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 import filters.TargetFilter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 * This is a scheduler for the phases of the evaluation.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 * @version 19.03.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 * @since jdk 1.6
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 public class Enrichment {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 String
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 * The name of the read alignment file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 readFileName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 * the name of the genome annotation file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 genomeFName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 * the ucsc-name of the genome (e.g. hg19).
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 genomeName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 * the name of the file of the targeted regions.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 targetFName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 * the temporary directory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 tmpDir,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 * the output directory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 outDir,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 * the xml summary file containing various overall statistics.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 xmlSummaryFile,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 * the name of the detailed coverage data file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 detailsFileName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 * the .bed file containing target-level coverage statistics data.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 beddetailsFileName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 * the process number used for unique naming.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 proc,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 * the name of the read alignment file without extension.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 prefix,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 * the extension of the read alignment file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 suffix,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 * The name of the read alignment file after the reduction.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 areadFileName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 * The name of the genome annotation file after the reduction.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 aGenomeFName,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 * the name of the file of the targeted regions after the reduction.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 aTargetFName;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 int
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 * Cutoff for poor coverage [default: 2].
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 poor,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 * Cutoff for high coverage [default: 200].
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 high,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 details;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 * Construcs an enrichment object and initializes the evaluation parameters.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 * @param args the list of all evaluation parameters.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 public Enrichment(String... args) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 readFileName = args[0];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 genomeName = args[8];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 targetFName = args[2];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 if (!targetFName.endsWith("bed")) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 System.out.println("WARNING: Target file: " + targetFName + " must be in the bed format.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119 if (args.length > 3) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 Time time = new Time(System.currentTimeMillis());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 String nano = ""+System.nanoTime();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 tmpDir = args[3] + Misc.slash(args[3]) +"Sample_From_"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124 time.getHours()+"_"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 time.getMinutes()+"_"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 time.getSeconds()+"_"+nano+ "/";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 new File(tmpDir).mkdir();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 new File(tmpDir).setReadable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 new File(tmpDir).setWritable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 outDir = args[4] + Misc.slash(args[4]);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132 if (!(new File(tmpDir).isDirectory()) && new File(tmpDir).exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 System.out.println("File " + tmpDir
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 + " is not a directory.\nProgram stopped.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 System.exit(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 } else if (!(new File(tmpDir).exists())) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 System.out.println("File " + tmpDir
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 + " not found.\nProgram stopped.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 System.exit(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 if (args.length > 5) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144 poor = Integer.parseInt(args[5]);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 high = Integer.parseInt(args[6]);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 } catch (NumberFormatException nfe) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 System.out
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 .println("Warning: poor or high must be integers.\n<poor> and <high> are set to the standard values.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 poor = 2;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 high = 200;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153 poor = 2;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 high = 200;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 genomeFName = (args[1].equals("none"))?downloadGenomeAnnotation():args[1];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 prefix = Misc.prefix(readFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160 if (args[7] != "none") {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 prefix = args[7];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 details = Integer.parseInt(args[9]);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 suffix = Misc.suffix(readFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166 proc = Misc.getHostName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 areadFileName = tmpDir + "NGSrich_" + prefix + "_" + proc + ".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 aGenomeFName = tmpDir + "NGSrich_genome_" + proc + ".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 aTargetFName = tmpDir + "NGSrich_target_" + proc + ".bed";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170 detailsFileName = tmpDir + "coverage_" + proc + ".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 xmlSummaryFile = outDir + "data/" + prefix + "_enrichment.xml";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 beddetailsFileName = outDir + "data/" + prefix + "_enrichment.bed";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 public static final String[] GENOME_NAMES = {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176 "anoGam1", "bosTau4", "cb3", "ce4", "ce6",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 "danRer5", "danRer6", "danRer7", "dm2", "dm3",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 "galGal2", "galGal3", "hg19", "hg18", "mm8",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 "mm9", "panTro3", "rn3", "rn4", "susScr2"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 };
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182 public int genomeID(String gname){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 for(int i = 0; i < GENOME_NAMES.length; i++)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 if(GENOME_NAMES[i].equals(gname))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 return i;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 return -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 * Downloads the specified genome annotation, if internet connection
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 * exists.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 * @param genome the ucsc-name of the genome. (e.g. hg18, hg19)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 * @return the very same name of the genome.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195 * @throws GenomeAnnotationException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 public String getGenomeAnnotation() throws GenomeAnnotationException{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 try{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 return downloadGenomeAnnotation();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 }catch(Exception e){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 if(genomeID(genomeName)!=-1)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 return Misc.scriptDir()+"thirdparty/annotations/"+genomeName+".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 else if(new File(genomeName).exists())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 return genomeName;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 else
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 throw new GenomeAnnotationException();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 public String getChromInfo(){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 //genomeName
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 return Misc.scriptDir()+"thirdparty/chromInfo/"+genomeName+".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 public String downloadGenomeAnnotation() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 if (genomeName.indexOf("/") == -1) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 String tmpGenomeDir = tmpDir + genomeName;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 if (!new File(tmpGenomeDir).exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 new File(tmpGenomeDir).mkdir();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223 File getGenomeScript = new File(tmpGenomeDir + Misc.slash(tmpGenomeDir) + "getGenome.sh");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 if (!getGenomeScript.exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 getGenomeScript.createNewFile();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 FileWriter fw = new FileWriter(getGenomeScript);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 getGenomeScript.setReadable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 getGenomeScript.setWritable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 getGenomeScript.setExecutable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 getGenomeScript.setExecutable(true);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233 String tmpGenomeFile = tmpGenomeDir + Misc.slash(tmpGenomeDir)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 + "refGene.txt.gz";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 fw.write("#!/bin/bash\n" + "cd " + tmpGenomeDir + "\n"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 + "wget http://hgdownload.cse.ucsc.edu/goldenPath/" + genomeName
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 + "/database/refGene.txt.gz " + "-O " + tmpGenomeFile
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 + "\n" + "gunzip " + tmpGenomeFile + "\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 fw.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 Runtime.getRuntime().exec("sh " + getGenomeScript);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 Thread.sleep(10000);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 } catch (InterruptedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 } catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 return tmpGenomeDir + Misc.slash(tmpGenomeDir) + "refGene.txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 return genomeName;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257 * A bridge method which converts a bam file to a sam file for further
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 * processing. This method assures therefore the compatibility of the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259 * software with the bam format.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261 * @return the name of the generated sam file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262 * @throws IOException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264 public String bam2sam() throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266 String[] bampath = readFileName.split("/");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267 String bamfile = bampath[bampath.length - 1];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
268 String samfile = tmpDir + bamfile.split(".bam")[0] + ".sam";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
269
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
270 File getBam2SamScript = new File(tmpDir + "bam2sam.sh");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
271 if (!getBam2SamScript.exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
272 getBam2SamScript.createNewFile();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
273 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
274 FileWriter fw = new FileWriter(getBam2SamScript);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
275 fw.write("#!/bin/bash\n" + Misc.binDir()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
276 + "/../thirdparty/samtools/0.1.16/samtools view "
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
277 + readFileName + " > " + samfile);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
278 fw.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
279
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
280 Process p = Runtime.getRuntime().exec("sh " + getBam2SamScript);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
281 // try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
282 // @SuppressWarnings("unused")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
283 // "exitstate" variable unused
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
284 //int exitstate = p.waitFor();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
285 // } catch (InterruptedException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
286 //e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
287 // }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
288
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
289 Scanner stderr=new Scanner(p.getErrorStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
290 while(stderr.hasNextLine()){System.out.println(stderr.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
291 stderr.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
292
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
293 return (samfile);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
294
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
295 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
296
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
297 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
298 * First phase of the evaluation. In this phase input files are being
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
299 * simplified for further processing.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
300 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
301 * @throws FileFormatException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
302 * @throws ChromosomeMismatchException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
303 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
304 public void reduceFiles() throws FileFormatException, ChromosomeMismatchException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
305 String aReadFileName = tmpDir+"NGSrich_"+prefix+"_"+ proc + ".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
306 String aGenomeFName = tmpDir+"NGSrich_genome_" + proc + ".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
307 String aTargetFName = tmpDir+"NGSrich_target_"+ proc+".txt";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
308
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
309
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
310 Filter[] filters = {new ReadFilter(readFileName, aReadFileName),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
311 new GenomeFilter(genomeFName, aGenomeFName),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
312 new TargetFilter(targetFName, aTargetFName)};
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
313
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
314 for(Filter f: filters) f.filter();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
315
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
316 if(!Misc.areChromosomeCompatible(new File(aReadFileName),
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
317 new File(aTargetFName)))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
318 throw new ChromosomeMismatchException();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
319
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
320 System.out.println("\nSTEP 1 successfully completed");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
321 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
322
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
323 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
324 * Second phase of the evaluation. An EnrichmentStatsComputer object is
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
325 * called with the right parameters and computation is checked for formal
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
326 * correctness.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
327 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
328 public void computeTargetCoverageFiles() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
329
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
330 File data = new File(outDir + "/data");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
331 data.mkdir();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
332 File plots = new File(outDir + "/plots");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
333 plots.mkdir();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
334
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
335 EnrichmentStatsComputer esc =
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
336 new EnrichmentStatsComputer(prefix, proc,tmpDir, outDir);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
337
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
338 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
339 esc.compute();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
340 } catch (RangeFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
341 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
342 } catch (ChromosomeFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
343 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
344 } catch (ChromosomeNotFoundException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
345 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
346 } catch (RangeLimitNotFoundException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
347 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
348 } catch (NullOrNegativeRangeException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
349 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
350 } catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
351 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
352 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
353
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
354 if (new File(detailsFileName).exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
355 System.out.println("\nSTEP 2 successfully completed");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
356 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
357 System.out.println("STEP 2 incomplete.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
358 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
359
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
360 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
361
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
362 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
363 * Third phase of the evaluation. Based on the results from phase 2, the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
364 * evaluation is further developed and evaluation data are visualized by
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
365 * calling "eval_enrichment.R" Script.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
366 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
367 public void evaluate() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
368 Runtime rt = Runtime.getRuntime();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
369 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
370 String script = Misc.scriptDir() + Misc.slash(Misc.scriptDir())+"R/eval_enrichment.R";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
371 int lastSlash = outDir.lastIndexOf("/");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
372 String outDirR = (lastSlash == outDir.length() - 1) ? outDir
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
373 .substring(0, lastSlash) : outDir;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
374
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
375 String call = "Rscript " + script + " "+ xmlSummaryFile + " " + beddetailsFileName + " "
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
376 + outDirR + " " + genomeName + " " + poor + " " + high + " " + prefix + " "
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
377 + targetFName+" "+details;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
378
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
379 Process p=rt.exec(call);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
380
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
381 Scanner stdout = new Scanner(p.getInputStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
382 Scanner stderr=new Scanner(p.getErrorStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
383 while (stdout.hasNextLine()){System.out.println(stdout.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
384 while (stderr.hasNextLine()){System.out.println(stderr.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
385 stdout.close(); stderr.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
386
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
387 if(details == 1){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
388 String chrInfoPath = getChromInfo();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
389
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
390 //System.out.println("chrInfoPath\t"+chrInfoPath);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
391 script = Misc.scriptDir() + Misc.slash(Misc.scriptDir())+"R/eval_details.R";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
392 outDirR = (lastSlash == outDir.length() - 1) ? outDir.substring(0, lastSlash) : outDir;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
393
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
394 String call2 = "Rscript "+ script + " " + xmlSummaryFile + " " + beddetailsFileName
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
395 + " " + detailsFileName + " " + chrInfoPath + " " + outDirR + " "
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
396 + genomeName;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
397 Process p2 = rt.exec(call2);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
398 stdout=new Scanner(p2.getInputStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
399 stderr=new Scanner(p2.getErrorStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
400
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
401 while(stdout.hasNextLine()){System.out.println(stdout.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
402 while(stderr.hasNextLine()){System.out.println(stderr.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
403 stdout.close(); stderr.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
404 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
405
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
406 String path = outDir+prefix+"_enrichment.html";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
407 System.out.println("Created plots and HTML summary report");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
408 if (new File(path).exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
409 System.out.println("\nSTEP 3 successfully completed");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
410 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
411 System.out.println("HTML FILE " + path + " not found");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
412 System.out.println("\nSTEP 3 unsuccessful");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
413 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
414 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
415 catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
416 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
417 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
418 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
419
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
420 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
421 * This is the fourth phase. In this phase the detailed datta from phase 2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
422 * are converted to the wiggle format. The method uses a ReadOnTarget2Wig
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
423 * object to accomplish this task.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
424 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
425 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
426 public void computeWiggleFile() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
427 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
428 System.out.println("Computing wiggle file for on-target reads");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
429 if (!new File(detailsFileName).exists())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
430 detailsFileName = tmpDir + new File(detailsFileName).getName();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
431
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
432 new ReadOnTarget2Wig(detailsFileName, prefix, outDir + "data",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
433 Misc.prefix(readFileName)+ "\nonTarget");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
434 System.out.println("Wiggle file for on-target reads created");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
435 System.out.println("Output written to " + outDir + "data/" + prefix + "_onTarget.wig");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
436 File[] outputFiles = new File(outDir + "data/")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
437 .listFiles();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
438 for (int i = 0; i < outputFiles.length; i++) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
439 if (outputFiles[i].getName().endsWith("wig")
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
440 && outputFiles[i].getName().startsWith(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
441 detailsFileName.substring(
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
442 detailsFileName.lastIndexOf("/") + 1,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
443 detailsFileName.lastIndexOf(".")))) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
444 File f = new File(outDir + "data"
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
445 + "/" + Misc.prefix(readFileName) + "_onTarget.wig");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
446 outputFiles[i].renameTo(f);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
447 break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
448 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
449 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
450 if (new File(outDir+"data/"+prefix+"_onTarget.wig").exists()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
451 System.out.println("\nSTEP 4 successfully completed.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
452 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
453 System.out.println(outDir+"data/"+ prefix
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
454 + "_onTarget.wig not found!\n\nSTEP 4 unsuccessful");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
455 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
456 } catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
457 System.err.println("Target conversion in Wig unsuccessful");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
458 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
459 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
460 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
461
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
462 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
463 * This is the fifth and last phase of the evaluation process. In contrast
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
464 * to the fourth phase, this method uses a Read2Wig object to convert the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
465 * detailed data for all reads (and not only for reads on targets) to the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
466 * wiggle format.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
467 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
468 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
469 void computeOverallWiggleFile() {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
470 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
471 System.out.println("Computing wiggle file for all reads");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
472 new Read2Wig(areadFileName, prefix, outDir + "data",
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
473 genomeFName, tmpDir);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
474 String overallWiggleFileName = prefix + ".wig";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
475 System.out.println("Wiggle file for all reads created");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
476 System.out.println("Output written to " + outDir + "data/" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
477 overallWiggleFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
478 if (new File(outDir + "data/" + overallWiggleFileName).exists()) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
479 System.out.println("\nSTEP 5 successfully completed.");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
480 } else {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
481 System.out.println(outDir + "data/" + overallWiggleFileName
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
482 + "not found\n\nSTEP 5 unsuccessful");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
483 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
484 } catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
485 System.err
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
486 .println("Creating wiggle file for all reads was unsuccessful");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
487 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
488 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
489 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
490 }