/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package representation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author nikos
 */
public class BaselineBagOfWords {
    
    private final HashMap<String, Integer> BowMap;
    private final HashMap<String, Integer> BaselineBowMap;
    private ArrayList<String> possibleSequences;

    public BaselineBagOfWords() {
        BowMap = new HashMap<String, Integer>();
        
        String alpha = "ACGT";
        char[] seq = alpha.toCharArray();

        int length = 3;
        possibleSequences = generatePossibleStrings(length, alpha, seq);
        BaselineBowMap = new HashMap<String, Integer>();
    }
    
    
    public BaselineBagOfWords(String sequence) {
        
        BowMap = new HashMap<String, Integer>();
        BaselineBowMap = new HashMap<String, Integer>();
        
        String alpha = "ACGT";
        char[] seq = alpha.toCharArray();

        int length = 3;
        possibleSequences = generatePossibleStrings(length, alpha, seq);
        
        for(int i = 0; i < sequence.length()-2; i++) {
            String key = sequence.substring(i, i+3);
            if(!BowMap.containsKey(key))
                BowMap.put(key, 1);
            else
                BowMap.put(key, BowMap.get(key)+1);
        }
        
        for(String s : possibleSequences) {
            if(!BowMap.containsKey(s))
                BaselineBowMap.put(s, 0);
            else
                BaselineBowMap.put(s, BowMap.get(s));
        }
    }

    public HashMap<String, Integer> getBaselineBowMap() {
        return BaselineBowMap;
    }

    private ArrayList<String> generatePossibleStrings(int length, String alphabet, char[] sequence) {
        StringBuilder builder = new StringBuilder("   ");
        
        possibleSequences = new ArrayList<>();

        int[] pos = new int[length];
        int total = (int) Math.pow(alphabet.length(), length);
        for (int i = 0; i < total; i++) {
            for (int x = 0; x < length; x++) {
                if (pos[x] == sequence.length) {
                    pos[x] = 0;
                    if (x + 1 < length) {
                        pos[x + 1]++;
                    }
                }
                builder.setCharAt(x, sequence[pos[x]]);
            }
            pos[0]++;

            possibleSequences.add(builder.toString());
        }
        
        return possibleSequences;
    }

    HashMap<String, Integer> getBowMap() {
        return BowMap;
    }
    
     
}

@@ -432,23 +432,22 @@
 String, 
-Integer
+Double
 %3E Baseli
@@ -806,39 +806,38 @@
 HashMap%3CString, 
-Integer
+Double
 %3E();%0A    %7D%0A    %0A
@@ -891,32 +891,241 @@
 nce) %7B%0A        %0A
+        double A_count = 14317.0;%0A        double T_count = 14320.0;%0A        double C_count = 7436.0;%0A        double G_count = 7545.0;%0A        double sum_count = A_count + T_count + C_count + G_count;%0A        %0A
         BowMap =
@@ -1194,39 +1194,38 @@
 HashMap%3CString, 
-Integer
+Double
 %3E();%0A        %0A  
@@ -1510,16 +1510,55 @@
 , i+3);%0A
+            //System.out.println(key);%0A
         
@@ -1706,32 +1706,41 @@
      %7D%0A        %0A
+        %0A
         for(Stri
@@ -1771,36 +1771,143 @@
 ) %7B%0A            
-if(!
+//System.out.println(s);%0A            //System.out.println(BowMap.toString());%0A            //System.out.println(
 BowMap.containsK
@@ -1912,16 +1912,17 @@
 sKey(s))
+;
 %0A       
@@ -1930,34 +1930,107 @@
     
+%0A       
     
-Baseline
+ if(BowMap.containsKey(s)) %7B%0A                double freq = (double)(
 BowMap.
-put(s, 
+get(s) / 64.
 0);%0A
@@ -2033,36 +2033,467 @@
 0);%0A            
-else
+    for(int i = 0; i %3C s.length(); i++) %7B%0A                    if(s.charAt(i) == 'A')%0A                        freq /= A_count / sum_count;%0A                    else if(s.charAt(i) == 'T')%0A                        freq /= T_count / sum_count;%0A                    else if(s.charAt(i) == 'C')%0A                        freq /= C_count / sum_count;%0A                    else%0A                        freq /= G_count / sum_count;%0A                %7D
 %0A               
@@ -2515,29 +2515,67 @@
 .put(s, 
+freq);%0A            %7D else Baseline
 BowMap.
-get(s)
+put(s, 0.0
 );%0A     
@@ -2609,31 +2609,30 @@
 Map%3CString, 
-Integer
+Double
 %3E getBaselin
@@ -2635,32 +2635,41 @@
 elineBowMap() %7B%0A
+        %0A
         return B
@@ -3590,8 +3590,9 @@
      %0A%7D%0A
+%0A

Update BaselineBagOfWords.java