| 1 | package driver; |
| 2 | |
| 3 | import fileIO.ReadWrite; |
| 4 | import fileIO.TextFile; |
| 5 | |
| 6 | public class TransposeTextFile { |
| 7 | |
| 8 | public static void main(String[] args){ |
| 9 | |
| 10 | int skipLines=args.length>1 ? Integer.parseInt(args[1]) : 0; |
| 11 | |
| 12 | int minChrom=1; |
| 13 | int maxChrom=22; |
| 14 | |
| 15 | for(int i=minChrom; i<=maxChrom; i++){ |
| 16 | if(args[0].contains("#")){ |
| 17 | process(args[0].replace("#", ""+i), skipLines); |
| 18 | }else{ |
| 19 | process(args[0], skipLines); |
| 20 | break; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | } |
| 25 | |
| 26 | public static void process(String fname, int skipLines){ |
| 27 | TextFile tf=new TextFile(fname, false); |
| 28 | String[] lines=tf.toStringLines(); |
| 29 | tf.close(); |
| 30 | String[][] lines2=TextFile.doublesplitWhitespace(lines, true); |
| 31 | |
| 32 | StringBuilder sb=new StringBuilder(4096); |
| 33 | |
| 34 | int columns=lines2[skipLines].length; |
| 35 | |
| 36 | for(int column=0; column<columns; column++){ |
| 37 | String tab=""; |
| 38 | for(int row=skipLines; row<lines.length; row++){ |
| 39 | sb.append(tab); |
| 40 | sb.append(lines2[row][column]); |
| 41 | tab="\t"; |
| 42 | } |
| 43 | sb.append("\n"); |
| 44 | } |
| 45 | |
| 46 | ReadWrite.writeString(sb, fname+".transposed"); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | } |