| 1 |
package pacbio; |
| 2 |
|
| 3 |
import fileIO.ReadWrite; |
| 4 |
import fileIO.TextFile; |
| 5 |
import fileIO.TextStreamWriter; |
| 6 |
import shared.Timer; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public class PartitionFastaFile { |
| 14 |
|
| 15 |
|
| 16 |
public static void main(String[] args){ |
| 17 |
|
| 18 |
Timer t=new Timer(); |
| 19 |
String infile=args[0]; |
| 20 |
String outfile=args[1]; |
| 21 |
assert(!infile.equalsIgnoreCase(outfile)); |
| 22 |
assert(outfile.contains("#")); |
| 23 |
long partition=Integer.parseInt(args[2]); |
| 24 |
if(args.length>4){maxDataOut=Long.parseLong(args[4]);} |
| 25 |
|
| 26 |
if(ReadWrite.ZIPLEVEL<2){ReadWrite.ZIPLEVEL=2;} |
| 27 |
|
| 28 |
TextFile tf=new TextFile(infile, false); |
| 29 |
|
| 30 |
split(tf, outfile, partition); |
| 31 |
t.stop(); |
| 32 |
System.out.println("Time:\t"+t); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
public static void split(TextFile tf, String outfile, long partition) { |
| 37 |
long currentBases=0; |
| 38 |
int pnum=1; |
| 39 |
|
| 40 |
TextStreamWriter tsw=new TextStreamWriter(outfile.replace("#", ""+pnum), true, false, false); |
| 41 |
tsw.start(); |
| 42 |
|
| 43 |
String s; |
| 44 |
for(s=tf.nextLine(); s!=null && dataOut<maxDataOut; s=tf.nextLine()){ |
| 45 |
if(s.charAt(0)=='>'){ |
| 46 |
if(currentBases>=partition){ |
| 47 |
System.out.println("Ended partition "+pnum+" at "+currentBases); |
| 48 |
currentBases=0; |
| 49 |
pnum++; |
| 50 |
tsw.poison(); |
| 51 |
tsw=new TextStreamWriter(outfile.replace("#", ""+pnum), true, false, false); |
| 52 |
tsw.start(); |
| 53 |
} |
| 54 |
}else{ |
| 55 |
int x=s.length(); |
| 56 |
currentBases+=x; |
| 57 |
dataOut+=x; |
| 58 |
} |
| 59 |
tsw.println(s); |
| 60 |
} |
| 61 |
System.out.println("Ended partition "+pnum+" at "+currentBases); |
| 62 |
System.out.println("Total: "+dataOut); |
| 63 |
System.out.println("Avg: "+(dataOut)/pnum); |
| 64 |
|
| 65 |
|
| 66 |
try { |
| 67 |
synchronized(tsw){ |
| 68 |
tsw.wait(100); |
| 69 |
} |
| 70 |
} catch (InterruptedException e) { |
| 71 |
|
| 72 |
e.printStackTrace(); |
| 73 |
} |
| 74 |
tsw.poison(); |
| 75 |
} |
| 76 |
|
| 77 |
public static int MIN_CONTIG_TO_ADD=150; |
| 78 |
public static long MAX_OUTPUT_LEN=200000000000L; |
| 79 |
public static long maxDataOut=Long.MAX_VALUE; |
| 80 |
private static long dataOut=0; |
| 81 |
|
| 82 |
} |