0
|
1 package _main;
|
|
2
|
|
3 import java.io.BufferedInputStream;
|
|
4 import java.io.File;
|
|
5 import java.io.FileInputStream;
|
|
6 import java.io.FileWriter;
|
|
7 import java.io.IOException;
|
|
8 import java.sql.Time;
|
|
9 import java.util.Properties;
|
|
10 import middlewares.Misc;
|
|
11 import exceptions.ChromosomeMismatchException;
|
|
12 import exceptions.FileFormatException;
|
|
13
|
|
14 /**
|
|
15 * This is the Main-class of the evaluation part of the software. This class
|
|
16 * uses the Enrichment-class to process the phases (the parts) of the pipeline.
|
|
17 *
|
|
18 * @author Ali Abdallah
|
|
19 */
|
|
20
|
|
21 public class NGSrichEvaluate {
|
|
22
|
|
23 /**
|
|
24 * An array of arguments containing the following option elements in the
|
|
25 * following order:
|
|
26 * -r <readsFile> (-a|-g) <annotation> -t <target> [-s <sName>]
|
|
27 * [-T <tmpDir>][-o <outDir>][-p <poor> -h <high>][-no_details]
|
|
28 *
|
|
29 * Required:
|
|
30 * <readsFile> Path to read alignment file in SAM or BAM format.
|
|
31 * <annotation> UCSC genome version name.
|
|
32 * <target> Path to target file in BED format.
|
|
33 *
|
|
34 * Optional:
|
|
35 * <sName> Sample name [default: prefix of <readsFile>].
|
|
36 * <tmpDir> Temporary directory [default: '/tmp'].
|
|
37 * <outDir> Output directory [default: '<pathToReadsFile>/enrichment'].
|
|
38 * <poor> Cutoff for poor coverage [default: 2].
|
|
39 * <high> Cutoff for high coverage [default: 200].
|
|
40 */
|
|
41 String[] args;
|
|
42
|
|
43 public NGSrichEvaluate(String[] args) {
|
|
44 this.args = args;
|
|
45 }
|
|
46
|
|
47 public void evaluate() throws IOException, FileFormatException,
|
|
48 InterruptedException {
|
|
49 /**
|
|
50 * Ordered List of Parameter (left/right): readFName genomeFName
|
|
51 * targetFName tmpDir outDir
|
|
52 *
|
|
53 */
|
|
54
|
|
55 int alen = args.length;
|
|
56 String[] params = new String[10];
|
|
57
|
|
58 String usagestr =
|
|
59 "\nUsage: java NGSrich evaluate -r <readsFile> "
|
|
60 + "-u <genome-name> -t <target> [(-a|-g) "
|
|
61 + "<annotation>] [-s <sName>] [-T <tmpDir>] "
|
|
62 + "[-o <outDir>] [-p <poor> -h <high>][--no-details>]\n\n\tRequired:\n\t"
|
|
63 + "<readsFile>\tPath to read alignment file in SAM or BAM format."
|
|
64 + "\n\t<genome-name>\tUCSC genome version name.\n\t<target>\tPath "
|
|
65 + "to target file in BED format.\n\n\tOptional:\n\t<sName>\t\t"
|
|
66 + "Sample name [default: prefix of <readsFile>].\n\t<annotation>\t\t"
|
|
67 + "path of the annotation file [default: the genome is "
|
|
68 + "downloaded based on the genome version name].\n\t<tmpDir>\t"
|
|
69 + "Temporary directory [default: '/tmp'].\n\t<outDir>\tOutput "
|
|
70 + "directory [default: '<pathToReadsFile>/enrichment'].\n\t"
|
|
71 + "<poor>\t\tCutoff for poor coverage [default: 2].\n\t<high>"
|
|
72 + "\t\tCutoff for high coverage [default: 200]. \n\t--no-details\tto repress the computation of the" +
|
|
73 " evaluation details\n";
|
|
74
|
|
75 if (alen == 0) {
|
|
76 System.out.println(usagestr);
|
|
77 System.exit(0);
|
|
78 }
|
|
79
|
|
80 boolean t = false, o = false, h = false, po = false, sname = false, u = false, r = false, g = false,
|
|
81 a = false, T = false;
|
|
82 params[9] = "1";
|
|
83 for (int i = 0; i < alen; i = i + 2) {
|
|
84 if ((args[i].length() == 2 && args[i].charAt(0) == '-') || args[i].equals("--no-details")) {
|
|
85 char flag = (args[i].length()==2)?args[i].charAt(1):args[i].charAt(2);
|
|
86 switch (flag) {
|
|
87 case 'r': params[0] = args[i + 1];r = true;break;
|
|
88 case 'g': params[1] = args[i + 1];g = true;break;
|
|
89 case 'a': params[1] = args[i + 1];a = true;break;
|
|
90 case 't': params[2] = args[i + 1];t = true;break;
|
|
91 case 'T': params[3] = args[i + 1];T = true;break;
|
|
92 case 'o': params[4] = args[i + 1];o = true;break;
|
|
93 case 'p': params[5] = args[i + 1];po = true;break;
|
|
94 case 'h': params[6] = args[i + 1];h = true;break;
|
|
95 // Added by PF 2011-07-12
|
|
96 case 's': params[7] = args[i + 1];sname = true;break;
|
|
97 case 'u': params[8] = args[i+1]; u = true;break;
|
|
98 case 'n': params[9]="0";break;
|
|
99 }
|
|
100 } else {
|
|
101 System.out.println(usagestr);
|
|
102 System.exit(0);
|
|
103 }
|
|
104 }
|
|
105
|
|
106 boolean required = r && t && u;
|
|
107
|
|
108 if(!required){
|
|
109 System.out.println("Some required arguments are missing.\n");
|
|
110 System.out.println(usagestr);
|
|
111 System.exit(0);
|
|
112 }
|
|
113
|
|
114 String default_properties_file = createDefaultPropertiesFile();
|
|
115 Properties p = new Properties();
|
|
116 BufferedInputStream stream =
|
|
117 new BufferedInputStream(
|
|
118 new FileInputStream(default_properties_file));
|
|
119
|
|
120 p.load(stream);
|
|
121 stream.close();
|
|
122 if (!T)params[3] = p.getProperty("tmpDir");
|
|
123 if (!o) {
|
|
124 String oPath = p.getProperty("outDirPath");
|
|
125 if (oPath.equals(""))oPath = Misc.path(params[0]);
|
|
126 params[4] = oPath + Misc.slash(oPath) + p.getProperty("outDir");
|
|
127 new File(params[4]).mkdir();
|
|
128 }
|
|
129 if (!po)params[5] = p.getProperty("poor");
|
|
130 if (!h)params[6] = p.getProperty("high");
|
|
131 if (!sname)params[7] = "none";
|
|
132 if (!(a||g))params[1] = "none";
|
|
133
|
|
134 Enrichment ngs = new Enrichment(params);
|
|
135 // Convert BAM to SAM if necessary.
|
|
136 String infile = params[0];
|
|
137 if (infile.endsWith(".bam")) {
|
|
138 System.out.println("======================0======================");
|
|
139 System.out.println("\n>>> Found BAM file: converting to SAM\n");
|
|
140 infile = ngs.bam2sam();
|
|
141 }
|
|
142 ngs.readFileName = infile;
|
|
143
|
|
144 // File timeReport =
|
|
145 // new File(params[3] + Misc.slash(params[3])+"TimeReport.txt");
|
|
146 // FileWriter trWriter = new FileWriter(timeReport);
|
|
147
|
|
148 // Reduce the files.
|
|
149 System.out.println("======================1======================");
|
|
150 System.out.println(">>> STEP 1: reducing files\n");
|
|
151 try {
|
|
152 long start = System.currentTimeMillis();
|
|
153 ngs.reduceFiles();
|
|
154 long rtime = System.currentTimeMillis() - start;
|
|
155 Time time = new Time(rtime);
|
|
156 //trWriter.write("Reducing files took: " + time + "\n");
|
|
157
|
|
158 } catch (ChromosomeMismatchException e) {
|
|
159 e.printStackTrace();
|
|
160 }
|
|
161
|
|
162 // Compute the target coverage files.
|
|
163 System.out.println("\n======================2======================");
|
|
164 System.out.println(">>> STEP 2: computing target coverage data\n");
|
|
165 long start = System.currentTimeMillis();
|
|
166 ngs.computeTargetCoverageFiles();
|
|
167 long rtime = System.currentTimeMillis() - start;
|
|
168 Time time = new Time(rtime);
|
|
169 // trWriter.write("Computing target coverage data took: " + time + "\n");
|
|
170
|
|
171 // Evaluate enrichment.
|
|
172 System.out.println("\n======================3======================");
|
|
173 System.out.println(">>> STEP 3: evaluating enrichment files\n");
|
|
174 start = System.currentTimeMillis();
|
|
175 ngs.evaluate();
|
|
176 rtime = System.currentTimeMillis() - start;
|
|
177 time = new Time(rtime);
|
|
178 //trWriter.write("Evaluating enrichment files took: " + time + "\n");
|
|
179 Thread.sleep(10000);
|
|
180
|
|
181 // Compute the target wiggle files.
|
|
182 System.out.println("\n======================4======================");
|
|
183 System.out.println(">>> STEP 4: computing targets wiggle data\n");
|
|
184 start = System.currentTimeMillis();
|
|
185 ngs.computeWiggleFile();
|
|
186 rtime = System.currentTimeMillis() - start;
|
|
187 time = new Time(rtime);
|
|
188 //trWriter.write("Computing targets wiggle data took: " + time + "\n");
|
|
189
|
|
190 // Compute the overall wiggle files.
|
|
191 System.out.println("\n======================5======================");
|
|
192 System.out.println(">>> STEP 5: computing overall wiggle data\n");
|
|
193 ngs.computeOverallWiggleFile();
|
|
194 start = System.currentTimeMillis();
|
|
195 ngs.computeOverallWiggleFile();
|
|
196 rtime = System.currentTimeMillis() - start;
|
|
197 time = new Time(rtime);
|
|
198 //trWriter.write("Computing targets wiggle data took: " + time + "\n");
|
|
199 System.out.println("\n=============================================");
|
|
200 //trWriter.close();
|
|
201 }
|
|
202
|
|
203 private String createDefaultPropertiesFile() throws IOException {
|
|
204 String default_properties_file =
|
|
205 Misc.binDir()+Misc.slash(Misc.binDir())+"DEFAULT.properties";
|
|
206 if(!new File(default_properties_file).exists()){
|
|
207 String default_str =
|
|
208 "! Path of the temporary directory.\n" +
|
|
209 "tmpDir: /tmp\n" +
|
|
210 "! Path of the father directory of the output directory. " +
|
|
211 "When empty the output directory is placed in the directory " +
|
|
212 "containing the reads alignment file.\n" +
|
|
213 "outDirPath:\n" +
|
|
214 "! Name of the output directory (not the path).\n" +
|
|
215 "outDir: enrichment\n" +
|
|
216 "! Define poorly covered genes.\n" +
|
|
217 "poor: 2\n" +
|
|
218 "! Defines highly covered genes.\n" +
|
|
219 "high: 200";
|
|
220 FileWriter properties_writer =
|
|
221 new FileWriter(default_properties_file);
|
|
222 properties_writer.write(default_str);
|
|
223 properties_writer.close();
|
|
224 }
|
|
225 return default_properties_file;
|
|
226 }
|
|
227 } |