diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NGSrich_0.5.5/src/_main/NGSrichSummarize.java	Mon Nov 21 08:12:19 2011 -0500
@@ -0,0 +1,106 @@
+package _main;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Scanner;
+
+import middlewares.Misc;
+import exceptions.FileFormatException;
+
+/**
+ * This is the Main-class of the summarization part of the software. This class
+ * is a wrapper class. It calls the r-script "summarize_enrichment.R" which
+ * summarizes the evaluations of multiple samples. 
+ * 
+ * @author Peter Frommolt
+ */
+
+public class NGSrichSummarize {
+
+	/**
+	 * An array of arguments containing the following option elements in the 
+	 * very same order: -i <inputIndex> -o <outDir> [-p <poor> -h <high>]
+	 * 
+	 * Required: 
+	 * <inputIndex> File with evaluation directories to be summarized, one per 
+	 * 				line.
+	 * <outDir> 	Output directory.
+	 * 
+	 * Optional:
+	 * <poor> Cutoff for poorly covered genes [default: 2].
+	 * <high> Cutoff for highly covered genes [default: 200].
+	 * 
+	 */
+	String[] args;
+	
+	public NGSrichSummarize(String[] args){
+		this.args = args;
+	}
+
+	public void summarize() throws 	FileFormatException,
+									IOException, 
+									InterruptedException{
+		int alen = args.length;
+		String[] params = new String[4];
+	
+		String usagestr="\nUsage: NGSrich summarize -i <inputIndex> -o <outDir> " +
+				"[-p <poor> -h <high>]\n\n\tRequired:\n\t<inputIndex>\tFile " +
+				"with evaluation directories to be summarized, one per line." +
+				"\n\t<outDir>\tOutput directory.\n\n\tOptional:\n\t<poor>\t\t" +
+				"Cutoff for poorly covered genes [default: 2].\n\t<high>\t\t" +
+				"Cutoff for highly covered genes [default: 200].\n";
+
+		if(alen==0){
+		    System.out.println(usagestr);
+		    System.exit(0);
+		}
+
+		boolean i=false, o=false, h=false, po=false;
+		for(int k = 0; k < alen; k=k+2){
+			if(args[k].length() == 2 && args[k].charAt(0)=='-'){
+			    char flag = args[k].charAt(1);
+			    switch(flag){
+			    case 'i': params[0]=args[k+1]; i=true; break;
+			    case 'o': params[1]=args[k+1]; o=true; break;
+			    case 'p': params[2]=args[k+1]; po=true; break;
+			    case 'h': params[3]=args[k+1]; h=true; break;
+			    }
+			}
+			else{
+			    System.out.println(usagestr);
+			    System.exit(0);
+			}
+		}
+
+		Properties p = new Properties();
+		FileInputStream stream=new FileInputStream(Misc.binDir()+Misc.slash(Misc.binDir())+"DEFAULT.properties");
+		p.load(stream); stream.close();
+				
+		String infile, outdir, poor, high;
+
+		if(!i){System.out.println("Error: Argument -i is mandatory"); System.exit(1);}
+		if(!o){System.out.println("Error: Argument -o is mandatory"); System.exit(1);}
+		infile=params[0]; outdir=params[1];
+
+		if(!po){poor=p.getProperty("poor");}
+		else{poor=params[2];}
+		
+		if(!h){high=p.getProperty("high");}
+		else{high=params[3];}
+
+		Runtime rt=Runtime.getRuntime();
+		String rScriptAbsolutePathName=Misc.binDir()+Misc.slash(Misc.binDir())+"../R/summarize_enrichment.R";
+		Process proc = rt.exec(rScriptAbsolutePathName+" "+infile+" "+outdir+" "+poor+" "+high);
+			
+		/*Scanner sc=new Scanner(proc.getInputStream()); String erg = "";
+		while(sc.hasNextLine()){erg += (sc.nextLine());}
+		sc.close();*/
+
+		Scanner stdout = new Scanner(proc.getInputStream());
+		Scanner stderr=new Scanner(proc.getErrorStream());
+		while (stdout.hasNextLine()){System.out.println(stdout.nextLine());}
+		while(stderr.hasNextLine()){System.out.println(stderr.nextLine());}
+		stdout.close(); stderr.close();
+
+	}
+}