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