Mercurial > repos > rliterman > csp2
annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fun/ProbShared.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
rev | line source |
---|---|
jpayne@68 | 1 package fun; |
jpayne@68 | 2 |
jpayne@68 | 3 public class ProbShared { |
jpayne@68 | 4 |
jpayne@68 | 5 public static void main(String args[]){ |
jpayne@68 | 6 int k=Integer.parseInt(args[0]); |
jpayne@68 | 7 int len1=Integer.parseInt(args[1]); |
jpayne@68 | 8 int len2=Integer.parseInt(args[2]); |
jpayne@68 | 9 |
jpayne@68 | 10 System.out.println("Cardinality 1: "+cardinality(k, len1)); |
jpayne@68 | 11 System.out.println("Cardinality 2: "+cardinality(k, len2)); |
jpayne@68 | 12 System.out.println("Probability: "+probIntersect(k, len1, len2)); |
jpayne@68 | 13 |
jpayne@68 | 14 } |
jpayne@68 | 15 |
jpayne@68 | 16 static int cardinality(int k, int seqLength){ |
jpayne@68 | 17 double space=Math.pow(4, k); |
jpayne@68 | 18 int kmers=seqLength-k+1; |
jpayne@68 | 19 double unique=0; |
jpayne@68 | 20 for(int i=0; i<kmers; i++){ |
jpayne@68 | 21 double prob=(space-unique)/space; |
jpayne@68 | 22 unique+=prob; |
jpayne@68 | 23 } |
jpayne@68 | 24 return (int)Math.round(unique); |
jpayne@68 | 25 } |
jpayne@68 | 26 |
jpayne@68 | 27 static double probIntersect(int k, int len1, int len2){ |
jpayne@68 | 28 int card1=cardinality(k, len1); |
jpayne@68 | 29 int card2=cardinality(k, len2); |
jpayne@68 | 30 double space=Math.pow(4, k); |
jpayne@68 | 31 double cumulativeProbUnshared=1; |
jpayne@68 | 32 for(int i=0; i<card1; i++){ |
jpayne@68 | 33 double probShared=card2/space; |
jpayne@68 | 34 double probUnshared=1-probShared; |
jpayne@68 | 35 space-=probUnshared; |
jpayne@68 | 36 cumulativeProbUnshared*=probUnshared; |
jpayne@68 | 37 } |
jpayne@68 | 38 return 1-cumulativeProbUnshared; |
jpayne@68 | 39 } |
jpayne@68 | 40 |
jpayne@68 | 41 } |