/*
 * 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 motifkmer;

/**
 *
 * @author Rahul Semwal
 */
import java.util.TreeMap;
public class KMER 
{
    private int Weight;
    private int Cover;
    @SuppressWarnings("FieldMayBeFinal")
    private LinkList<Integer> Index;
    @SuppressWarnings("FieldMayBeFinal")
    private TreeMap<Integer,LinkList<Integer>> Connection;
    private TreeMap<Integer,LinkList<Integer>> Score;
    public TreeMap<Integer, Integer> prob;
    public boolean valid;
    private TreeMap<Integer,LinkList<Integer>> updatedIndex;
    private TreeMap<Integer,LinkList<Integer>> updatedConection;
    public KMER(int start)
    {
        this.Weight=0;
        this.Cover=1;
        this.Index= new LinkList<>();
        this.Index.addNode(start);
        Connection = new TreeMap<>();
        Score=new TreeMap<>();
        this.prob=new TreeMap<>();
        this.valid=true;
        this.updatedIndex=null;
        this.updatedConection=null;
    }

    /**
     *
     */
    @Override
    public void finalize()
    {
        this.Weight=0;
        this.Cover=0;
        this.Index.deleteNode();
        Connection.keySet().forEach((i) -> {Connection.get(i).deleteNode();});
        Connection.clear();
        //this.prob.clear();
    }
    public void updateWeight(int SimValue)
    {
        this.Weight += SimValue;
    }
    
    public void updateCoverage()
    {
        this.Cover++;
    }
    
    public void updateConnection(int BinNumber,int Kmer,int score)
    {
        if(Connection.containsKey(BinNumber))
        {
            LinkList<Integer> l = Connection.get(BinNumber);
            LinkList<Integer> s = Score.get(BinNumber);
            s.addNode(score);
            l.addNode(Kmer);
        }
        else
        {
            LinkList<Integer> node = new LinkList<>();
            LinkList<Integer> scorenode = new LinkList<>();
            node.addNode(Kmer);
            scorenode.addNode(score);
            Connection.put(BinNumber, node);
            Score.put(BinNumber,scorenode);
        }
    }
    
    public void updateIndex(int Start)
    {
        this.Index.addNode(Start);
    }
    
    public LinkList<Integer> getIndex()
    {
        return(this.Index);
    }
    
    public TreeMap<Integer,LinkList<Integer>> getConnection()
    {
        return(this.Connection);
    }
    public TreeMap<Integer,LinkList<Integer>> getScore()
    {
        return(this.Score);
    }
    public int getWeight()
    {
        return(this.Weight);
    }
    
    public int getCoverage()
    {
        return(this.Cover);
    }
    public void deleteIndex()
    {
        this.Index.deleteNode();
        this.Index= new LinkList<>();
    }
    
    
    public TreeMap<Integer,LinkList<Integer>> getUpdateIndex()
    {
        return(updatedIndex);
    }
    public TreeMap<Integer,LinkList<Integer>> getUpdateConnection()
    {
        return(updatedConection);
    }
    public void AddNewIndex(int seq, LinkList<Integer> tmp, LinkList<Integer> tmpIndex)
    {
        if(updatedIndex==null)
        {
            updatedIndex=new TreeMap<>();
            updatedConection=new TreeMap<>();
        }
        updatedIndex.put(seq, tmp);
        updatedConection.put(seq, tmpIndex);
    }
    
    
    
    public void updateIndexByConnection(int Start)
    {
        this.Index.addNode(Start);
    }
    public void setProbability(int score)
    {
        if(this.prob.containsKey(score))
            this.prob.put(score, this.prob.get(score)+1);
        else
            this.prob.put(score, 1);
    }
    public void deleteScore()
    {
        this.Score.clear();
        this.Score=null;
    }
    
}
