File: TransposeTextFile.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 (53 lines) | stat: -rwxr-xr-x 1,091 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
package driver;

import fileIO.ReadWrite;
import fileIO.TextFile;

public class TransposeTextFile {
	
	public static void main(String[] args){
		
		int skipLines=args.length>1 ? Integer.parseInt(args[1]) : 0;
		
		int minChrom=1;
		int maxChrom=22;
		
		for(int i=minChrom; i<=maxChrom; i++){
			if(args[0].contains("#")){
				process(args[0].replace("#", ""+i), skipLines);
			}else{
				process(args[0], skipLines);
				break;
			}
		}
		
	}
	
	public static void process(String fname, int skipLines){
		TextFile tf=new TextFile(fname, false);
		String[] lines=tf.toStringLines();
		tf.close();
		String[][] lines2=TextFile.doublesplitWhitespace(lines, true);
		
		StringBuilder sb=new StringBuilder(4096);
		
		int columns=lines2[skipLines].length;

		for(int column=0; column<columns; column++){
			String tab="";
			for(int row=skipLines; row<lines.length; row++){
				sb.append(tab);
				sb.append(lines2[row][column]);
				tab="\t";
			}
			sb.append("\n");
		}
		
		ReadWrite.writeString(sb, fname+".transposed");
		
	}
	
	
	
	
}