/*
 * 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.io.File;
import java.util.Scanner;
import java.util.TreeMap;

/**
 *
 * @author Rahul Semwal
 */

 
public class Manager 
{ 
    @SuppressWarnings("UnnecessaryContinue")
    public void  ConnctionBuilder(String kmer,String currentSequence, int kmerLength,Score s,KMER kmerptr)throws Exception
    {
        File file = new File("/home/rahul/NetBeansProjects/MotifKmer/Files/OutputKmer.txt");
        TreeMap<Integer,LinkList<Integer>> con;
        double score=(s.getKmerScore(kmer, kmer)*0.65);
        try (Scanner scan = new Scanner(file)) 
        {
            int sc=0;
            String data;
            while (scan.hasNextLine())
            {
                data =scan.nextLine();
                if(data.compareTo(currentSequence)==0)
                {
                    sc++;
                    continue;
                }
                else
                {
                    boolean cover=false;
                    int match=0;
                    String Testkmer;
                    int div=data.length()-kmerLength+1;
                    for(int i=0;i<data.length();i++)
                    {
                        if((i+kmerLength)<=data.length())
                        {
                            Testkmer = data.substring(i,i+kmerLength);
                           double [] hit=s.getScore(kmer,Testkmer,kmerptr);              
                            if(hit[0]>=score)
                            {   match++; 
                                if(!cover)
                                {
                                    cover=true;
                                    kmerptr.updateCoverage();
                                }
                                kmerptr.updateConnection(sc, i,(int)hit[0]);
                                kmerptr.updateWeight(1);
                            }
                        }
                    }
                    con=kmerptr.getConnection();
                    if(!con.containsKey(sc))
                    {
                        kmerptr.valid=false;
                        break;
                    }
                    sc++;
                }
            }
        }catch (Exception e){}
        file=null;
    }
    
}
