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

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
//import java.util.*;

/**
 *
 * @author Rahul Semwal
 */
public class MotifKmer {

    /**
     * @param args the command line arguments
     * @throws java.lang.Exception
     */
    public static void main(String[] args) throws Exception
    {
       int KmerLength =8;
       FileIo io = new FileIo();
       String Filename = "<INPUT FILE NAME>";
       double frequency [] =new double[26];
       String a[]=io.totalSequence(Filename,KmerLength,frequency).split(",");
       int n=Integer.parseInt(a[0]);
       int maxKmer=Integer.parseInt(a[1]);
       System.out.println("Start Sequence procesing............\n"+"It will take several miniutes...........");
       BinList BIN= io.parseFile(KmerLength, n,io,frequency,maxKmer);
       BinNode head =BIN.getHead();
       System.out.println("Motif Processing Start.................\nWait for a while...........");
       long startTime = System.nanoTime();
       TreeMap<Double,String> output = new TreeMap<>(Collections.reverseOrder());
       while(head!=null)
       {
           LinkedHashMap<String,KMER> CurrentBin =head.getCurrentBin();
           Iterator it = CurrentBin.entrySet().iterator();
           System.out.println("Main earlier    "+CurrentBin);
           while (it.hasNext())
           {
               Map.Entry me = (Map.Entry)it.next();
               output=MotifExtraction.motifTour((KMER)me.getValue(), head.getBinNumber(), KmerLength, io, n,frequency,output);
               it.remove(); 
           }
           head=head.next;
       }
       Iterator it=output.entrySet().iterator();
       while(it.hasNext())
       {
             Map.Entry me = (Map.Entry)it.next();
             System.out.println(me.getValue() +"    Fitness Score =  " + me.getKey());
             it.remove();
       }
       long duration = System.nanoTime() - startTime;
       System.out.println("Time taken by program in sec="+(duration/1000000000.0));
       
    }
    
}
