/* Author: Amay Agrawal
 * Project: Bacteria Cloud
 * Mentor: Prof. Manish K Gupta
 */
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException {
		String line = null;
		String line1 = null;
		String [] parts;
		String check [] = new String[200];
		int counter = 0;
		int counter5 = 0;
		int counter10 = 0;
		int counter11 = 0;
		int k=0;
		int plasmidlength=0;

		File file = new File("C:\\Users\\HP\\Desktop\\Plasmids\\output.txt");
		BufferedWriter bw = null;
		int counter2=0;
		int arr[] = new int[200];
		for(int m=0;m<199;m++){
			arr[m] = 100000;
		}
		// TODO Auto-generated method stub
		try {
			
			FileWriter fw = new FileWriter(file);
			  bw = new BufferedWriter(fw);
			BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\HP\\Desktop\\Plasmids\\pBR322.txt"));
			BufferedReader bufferedReader1 = new BufferedReader(new FileReader("C:\\Users\\HP\\Desktop\\Plasmids\\Unique 6+ Cutters.txt"));
			while ((line = bufferedReader.readLine()) != null){
				plasmidlength=line.length();
				//System.out.println(line.substring(2109, 2117));
				while ((line1 = bufferedReader1.readLine()) != null){
						parts = line1.split(" ");
						int length = parts[1].length();
						int abc = Integer.parseInt(parts[2]);
						for(int i=0;i<=(line.length() - length);i++){
							String ab = line.substring(i,i+length);
							for(int h=0;h<length;h++){
								if(parts[1].charAt(h) == 'N'){
									//System.out.println(parts[1]);
									counter++;
									continue;
								}
								else{
									if(ab.charAt(h) == parts[1].charAt(h)){
										counter++;
									}
									else{
										break;
									}
								}
							}
							if(counter == length){
								arr[k] = i+abc;
								check[k++] = parts[0];
								bw.write((i+abc)+" "+parts[0]+" "+parts[2]+" "+parts[1]+"\n");
								//System.out.println("i = "+(i+abc)+" enzyme = "+parts[0]);
							}
							counter=0;
						}
				}
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println("jkkkj"+arr[0]);
		int arr2 []= new int[k];
		for(int m=0;m<k;m++){
			arr2[m]=arr[m];
		}
		Arrays.sort(arr2);
		for(int m=0;m<k;m++){
			if(!(counter10 == arr2[m])){
				counter11++;
			}
			counter10 = arr2[m];
		}
		System.out.println("jbjbjhhhhhh "+counter11);
		int arr1[] = new int[counter11];
		
		for(int m=0;m<k;m++){
			if(!(counter2 == arr2[m])){
			arr1[counter5]=arr2[m];
			System.out.println(arr1[counter5++]);
			}
			counter2 = arr2[m];
			
		}
		String check1[] = new String[counter5];
		System.out.println("kuhkujk "+arr1[1]);
		for(int g=0;g<counter11;g++){
			int f = arr1[g];
			for(int h=0;h<k;h++){
				if(arr[h] == f){
					check1[g] = check[h];
					break;
				}
			}
		}
		String finalstring[][] = new String[counter5][2];
		for(int g=0;g<counter5;g++){
			//System.out.println(arr1[g]+" "+check1[g]);
			finalstring[g][0] = Integer.toString(arr1[g]);
			finalstring[g][1] = check1[g];
		}
		for(int h=0;h<counter5;h++){
			System.out.println(finalstring[h][0]+" "+finalstring[h][1]);
		}
		
		
		try {
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//Circle c = new Circle(arr1,check1,k,plasmidlength,"hhh","hhh");
        //c.amay();
        //Circle2 c1 = new Circle2();
        //c1.amay();
		for(int h=0;h<40;h++){
			System.out.println("jjjj"+arr[h]);
		}
		Data_insertion1 d = new Data_insertion1(finalstring);
		d.insertsequence();
	}

}
