File: MergeCoverageOTU.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (66 lines) | stat: -rwxr-xr-x 1,576 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package driver;

import java.util.ArrayList;
import java.util.LinkedHashMap;

import fileIO.TextFile;
import fileIO.TextStreamWriter;
import jgi.CovStatsLine;

/**
 * @author Brian Bushnell
 * @date Oct 13, 2014
 *
 */
public class MergeCoverageOTU {
	
	public static void main(String[] args){
		String a=args[0];
		String b=args[1];
		String in=null, out=null;
		if(a.toLowerCase().startsWith("in=")){
			in=a.split("=")[1];
			out=b.split("=")[1];
		}else if(a.toLowerCase().startsWith("out=")){
			in=b.split("=")[1];
			out=a.split("=")[1];
		}else{
			in=a;
			out=b;
		}
		
		TextFile tf=new TextFile(in);
		LinkedHashMap<String, CovStatsLine> map=new LinkedHashMap<String, CovStatsLine>();
		int count=0;
		ArrayList<String> headers=new ArrayList<String>();
		for(String s=tf.nextLine(); s!=null; s=tf.nextLine()){
			if(count==0){
				assert(s.startsWith("#")) : "Expected a header line starting with #";
				CovStatsLine.initializeHeader(s);
			}else{
				int space=s.indexOf(' ');
				String otu=s.substring(space+1, s.indexOf('\t'));
				CovStatsLine csl=new CovStatsLine(s);
				CovStatsLine old=map.get(otu);
				if(old==null){
					map.put(otu, csl);
				}else{
					old.add(csl);
				}
			}
			count++;
		}
		tf.close();
		
		TextStreamWriter tsw=new TextStreamWriter(out, true, false, false);
		tsw.start();
		for(String s : headers){tsw.println(s);}
		for(String s : map.keySet()){
			CovStatsLine csl=map.get(s);
			csl.id=s;
			tsw.println(csl.toString());
		}
		tsw.poisonAndWait();
	}
	
}