File: ProbShared.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 (41 lines) | stat: -rwxr-xr-x 1,090 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
package fun;

public class ProbShared {

	public static void main(String args[]){
		int k=Integer.parseInt(args[0]);
		int len1=Integer.parseInt(args[1]);
		int len2=Integer.parseInt(args[2]);

		System.out.println("Cardinality 1: "+cardinality(k, len1));
		System.out.println("Cardinality 2: "+cardinality(k, len2));
		System.out.println("Probability:   "+probIntersect(k, len1, len2));
		
	}
	
	static int cardinality(int k, int seqLength){
		double space=Math.pow(4, k);
		int kmers=seqLength-k+1;
		double unique=0;
		for(int i=0; i<kmers; i++){
			double prob=(space-unique)/space;
			unique+=prob;
		}
		return (int)Math.round(unique);
	}

	static double probIntersect(int k, int len1, int len2){
		int card1=cardinality(k, len1);
		int card2=cardinality(k, len2);
		double space=Math.pow(4, k);
		double cumulativeProbUnshared=1;
		for(int i=0; i<card1; i++){
			double probShared=card2/space;
			double probUnshared=1-probShared;
			space-=probUnshared;
			cumulativeProbUnshared*=probUnshared;
		}
		return 1-cumulativeProbUnshared;
	}
	
}