| 1 | package fun; |
| 2 | |
| 3 | public class ProbShared { |
| 4 | |
| 5 | public static void main(String args[]){ |
| 6 | int k=Integer.parseInt(args[0]); |
| 7 | int len1=Integer.parseInt(args[1]); |
| 8 | int len2=Integer.parseInt(args[2]); |
| 9 | |
| 10 | System.out.println("Cardinality 1: "+cardinality(k, len1)); |
| 11 | System.out.println("Cardinality 2: "+cardinality(k, len2)); |
| 12 | System.out.println("Probability: "+probIntersect(k, len1, len2)); |
| 13 | |
| 14 | } |
| 15 | |
| 16 | static int cardinality(int k, int seqLength){ |
| 17 | double space=Math.pow(4, k); |
| 18 | int kmers=seqLength-k+1; |
| 19 | double unique=0; |
| 20 | for(int i=0; i<kmers; i++){ |
| 21 | double prob=(space-unique)/space; |
| 22 | unique+=prob; |
| 23 | } |
| 24 | return (int)Math.round(unique); |
| 25 | } |
| 26 | |
| 27 | static double probIntersect(int k, int len1, int len2){ |
| 28 | int card1=cardinality(k, len1); |
| 29 | int card2=cardinality(k, len2); |
| 30 | double space=Math.pow(4, k); |
| 31 | double cumulativeProbUnshared=1; |
| 32 | for(int i=0; i<card1; i++){ |
| 33 | double probShared=card2/space; |
| 34 | double probUnshared=1-probShared; |
| 35 | space-=probUnshared; |
| 36 | cumulativeProbUnshared*=probUnshared; |
| 37 | } |
| 38 | return 1-cumulativeProbUnshared; |
| 39 | } |
| 40 | |
| 41 | } |