annotate NGSrich_0.5.5/src/_main/NGSrichSummarize.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 import java.io.FileInputStream;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 import java.io.IOException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 import java.util.Properties;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 import java.util.Scanner;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 import middlewares.Misc;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8 import exceptions.FileFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 * This is the Main-class of the summarization part of the software. This class
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 * is a wrapper class. It calls the r-script "summarize_enrichment.R" which
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 * summarizes the evaluations of multiple samples.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 * @author Peter Frommolt
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18 public class NGSrichSummarize {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 * An array of arguments containing the following option elements in the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 * very same order: -i <inputIndex> -o <outDir> [-p <poor> -h <high>]
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 * Required:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 * <inputIndex> File with evaluation directories to be summarized, one per
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 * line.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 * <outDir> Output directory.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 * Optional:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 * <poor> Cutoff for poorly covered genes [default: 2].
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 * <high> Cutoff for highly covered genes [default: 200].
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 String[] args;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 public NGSrichSummarize(String[] args){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 this.args = args;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 public void summarize() throws FileFormatException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41 IOException,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 InterruptedException{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43 int alen = args.length;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 String[] params = new String[4];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 String usagestr="\nUsage: NGSrich summarize -i <inputIndex> -o <outDir> " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 "[-p <poor> -h <high>]\n\n\tRequired:\n\t<inputIndex>\tFile " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 "with evaluation directories to be summarized, one per line." +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 "\n\t<outDir>\tOutput directory.\n\n\tOptional:\n\t<poor>\t\t" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 "Cutoff for poorly covered genes [default: 2].\n\t<high>\t\t" +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51 "Cutoff for highly covered genes [default: 200].\n";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 if(alen==0){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 System.out.println(usagestr);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 System.exit(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 boolean i=false, o=false, h=false, po=false;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 for(int k = 0; k < alen; k=k+2){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 if(args[k].length() == 2 && args[k].charAt(0)=='-'){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 char flag = args[k].charAt(1);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 switch(flag){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 case 'i': params[0]=args[k+1]; i=true; break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 case 'o': params[1]=args[k+1]; o=true; break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 case 'p': params[2]=args[k+1]; po=true; break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 case 'h': params[3]=args[k+1]; h=true; break;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 else{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 System.out.println(usagestr);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 System.exit(0);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 Properties p = new Properties();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 FileInputStream stream=new FileInputStream(Misc.binDir()+Misc.slash(Misc.binDir())+"DEFAULT.properties");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 p.load(stream); stream.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 String infile, outdir, poor, high;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 if(!i){System.out.println("Error: Argument -i is mandatory"); System.exit(1);}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 if(!o){System.out.println("Error: Argument -o is mandatory"); System.exit(1);}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 infile=params[0]; outdir=params[1];
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 if(!po){poor=p.getProperty("poor");}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86 else{poor=params[2];}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 if(!h){high=p.getProperty("high");}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 else{high=params[3];}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 Runtime rt=Runtime.getRuntime();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92 String rScriptAbsolutePathName=Misc.binDir()+Misc.slash(Misc.binDir())+"../R/summarize_enrichment.R";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 Process proc = rt.exec(rScriptAbsolutePathName+" "+infile+" "+outdir+" "+poor+" "+high);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 /*Scanner sc=new Scanner(proc.getInputStream()); String erg = "";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 while(sc.hasNextLine()){erg += (sc.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 sc.close();*/
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 Scanner stdout = new Scanner(proc.getInputStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 Scanner stderr=new Scanner(proc.getErrorStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 while (stdout.hasNextLine()){System.out.println(stdout.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 while(stderr.hasNextLine()){System.out.println(stderr.nextLine());}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 stdout.close(); stderr.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 }