File: PartitionFastaFile.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 (82 lines) | stat: -rwxr-xr-x 2,073 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package pacbio;

import fileIO.ReadWrite;
import fileIO.TextFile;
import fileIO.TextStreamWriter;
import shared.Timer;

/**
 * @author Brian Bushnell
 * @date Jul 10, 2012
 *
 */
public class PartitionFastaFile {
	
	
	public static void main(String[] args){
		
		Timer t=new Timer();
		String infile=args[0];
		String outfile=args[1];
		assert(!infile.equalsIgnoreCase(outfile));
		assert(outfile.contains("#"));
		long partition=Integer.parseInt(args[2]);
		if(args.length>4){maxDataOut=Long.parseLong(args[4]);}
		
		if(ReadWrite.ZIPLEVEL<2){ReadWrite.ZIPLEVEL=2;}
		
		TextFile tf=new TextFile(infile, false);
		
		split(tf, outfile, partition);
		t.stop();
		System.out.println("Time:\t"+t);
		
	}
	
	public static void split(TextFile tf, String outfile, long partition) {
		long currentBases=0;
		int pnum=1;

		TextStreamWriter tsw=new TextStreamWriter(outfile.replace("#", ""+pnum), true, false, false);
		tsw.start();
		
		String s;
		for(s=tf.nextLine(); s!=null && dataOut<maxDataOut; s=tf.nextLine()){
			if(s.charAt(0)=='>'){
				if(currentBases>=partition){
					System.out.println("Ended partition "+pnum+" at "+currentBases);
					currentBases=0;
					pnum++;
					tsw.poison();
					tsw=new TextStreamWriter(outfile.replace("#", ""+pnum), true, false, false);
					tsw.start();
				}
			}else{
				int x=s.length();
				currentBases+=x;
				dataOut+=x;
			}
			tsw.println(s);
		}
		System.out.println("Ended partition "+pnum+" at "+currentBases);
		System.out.println("Total: "+dataOut);
		System.out.println("Avg:   "+(dataOut)/pnum);
//		System.out.println("\n"+s+"\n"+dataOut+"\n"+maxDataOut);
		
		try {
			synchronized(tsw){
				tsw.wait(100);
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tsw.poison();
	}
	
	public static int MIN_CONTIG_TO_ADD=150; //Not currently used
	public static long MAX_OUTPUT_LEN=200000000000L;
	public static long maxDataOut=Long.MAX_VALUE;
	private static long dataOut=0;
	
}